Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] Add ExpansionPanels TypeScript Demo #15162

Merged
merged 32 commits into from
Apr 4, 2019
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c7efe77
docs: Add breadcrumbs Typescript Demo
Adherentman Apr 1, 2019
fa9aacf
docs: yarn prettier breadcrumbs demo
Adherentman Apr 1, 2019
86ba604
docs: format ts demo
Adherentman Apr 1, 2019
7704ab5
docs: format code
Adherentman Apr 1, 2019
851676d
docs: fix eslint
Adherentman Apr 1, 2019
926b451
Merge branch 'next' of github.com:mui-org/material-ui into next
Adherentman Apr 1, 2019
611b951
docs: format js
Adherentman Apr 1, 2019
fea3313
docs: update ts file
Adherentman Apr 1, 2019
248dd19
docs: fix js file
Adherentman Apr 1, 2019
fc727d2
fix ts import order
Adherentman Apr 1, 2019
169bfd3
docs: fix ts demo
Adherentman Apr 2, 2019
755f00e
docs: yarn docs:typescript:formatted
Adherentman Apr 2, 2019
a9ec856
docs: fix lint
Adherentman Apr 2, 2019
30faf84
docs: fix lint
Adherentman Apr 2, 2019
5795fd7
fix lint
Adherentman Apr 2, 2019
97bb2ac
fix link error
Adherentman Apr 2, 2019
ae018fe
docs: fix eslint and ts type error
Adherentman Apr 2, 2019
b750901
Merge branch 'next' of github.com:mui-org/material-ui into next
Adherentman Apr 2, 2019
2a6602f
docs: fix ts and js
Adherentman Apr 2, 2019
c406f0d
docs: Add ExpansionPanels TypeScript Demo
Adherentman Apr 2, 2019
a3559c0
docs: prettier tsx
Adherentman Apr 2, 2019
7465dc6
docs: fix routerBreadcrumbs propTypes and list component
Adherentman Apr 2, 2019
63eb35b
docs: yarn docs:typescript:formatted
Adherentman Apr 2, 2019
b250068
docs: fix ControlledExpansionPanels useState types
Adherentman Apr 2, 2019
94050f4
Update docs/src/pages/demos/expansion-panels/ControlledExpansionPanel…
eps1lon Apr 3, 2019
29f3ca4
docs: pull and yarn docs:typescript:formatted
Adherentman Apr 3, 2019
df45611
docs: Add ExpansionPanels TypeScript Demo
Adherentman Apr 2, 2019
0e579a2
docs: prettier tsx
Adherentman Apr 2, 2019
01c0dc6
docs: fix ControlledExpansionPanels useState types
Adherentman Apr 2, 2019
4328f5e
Update docs/src/pages/demos/expansion-panels/ControlledExpansionPanel…
eps1lon Apr 3, 2019
908c876
docs: pull and yarn docs:typescript:formatted
Adherentman Apr 3, 2019
b254a2c
Merge branch 'expansion-panels-ts' of github.com:Adherentman/material…
Adherentman Apr 3, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions docs/src/pages/demos/breadcrumbs/CollapsedBreadcrumbs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* eslint-disable jsx-a11y/anchor-is-valid */

import React from 'react';
import PropTypes from 'prop-types';
import { withStyles, Theme, createStyles, WithStyles } from '@material-ui/core/styles';
import Paper from '@material-ui/core/Paper';
import Breadcrumbs from '@material-ui/core/Breadcrumbs';
import Typography from '@material-ui/core/Typography';
import Link from '@material-ui/core/Link';

interface CollapsedBreadcrumbsProps extends WithStyles<typeof styles> {}

const styles = (theme: Theme) =>
createStyles({
root: {
justifyContent: 'center',
flexWrap: 'wrap',
},
paper: {
padding: theme.spacing(1, 2),
},
});

function handleClick(event: React.MouseEvent<HTMLAnchorElement, MouseEvent>) {
event.preventDefault();
alert('You clicked a breadcrumb.'); // eslint-disable-line no-alert
}

function CollapsedBreadcrumbs(props: CollapsedBreadcrumbsProps) {
const { classes } = props;

return (
<Paper elevation={0} className={classes.paper}>
<Breadcrumbs maxItems={2} aria-label="Breadcrumb">
<Link color="inherit" href="#" onClick={handleClick}>
Home
</Link>
<Link color="inherit" href="#" onClick={handleClick}>
Catalog
</Link>
<Link color="inherit" href="#" onClick={handleClick}>
Accessories
</Link>
<Link color="inherit" href="#" onClick={handleClick}>
New Collection
</Link>
<Typography color="textPrimary">Belts</Typography>
</Breadcrumbs>
</Paper>
);
}

CollapsedBreadcrumbs.propTypes = {
classes: PropTypes.object.isRequired,
} as any;

export default withStyles(styles)(CollapsedBreadcrumbs);
76 changes: 76 additions & 0 deletions docs/src/pages/demos/breadcrumbs/CustomSeparator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles, Theme, createStyles, WithStyles } from '@material-ui/core/styles';
import Paper from '@material-ui/core/Paper';
import Breadcrumbs from '@material-ui/core/Breadcrumbs';
import Typography from '@material-ui/core/Typography';
import Link from '@material-ui/core/Link';
import NavigateNextIcon from '@material-ui/icons/NavigateNext';

interface CustomSeparatorProps extends WithStyles<typeof styles> {}

const styles = (theme: Theme) =>
createStyles({
root: {
justifyContent: 'center',
flexWrap: 'wrap',
},
paper: {
padding: theme.spacing(1, 2),
},
});

function handleClick(event: React.MouseEvent<HTMLAnchorElement, MouseEvent>) {
event.preventDefault();
alert('You clicked a breadcrumb.'); // eslint-disable-line no-alert
}

function CustomSeparator(props: CustomSeparatorProps) {
const { classes } = props;

return (
<div className={classes.root}>
<Paper elevation={0} className={classes.paper}>
<Breadcrumbs separator="›" aria-label="Breadcrumb">
<Link color="inherit" href="/" onClick={handleClick}>
Material-UI
</Link>
<Link color="inherit" href="/getting-started/installation/" onClick={handleClick}>
Core
</Link>
<Typography color="textPrimary">Breadcrumb</Typography>
</Breadcrumbs>
</Paper>
<br />
<Paper elevation={0} className={classes.paper}>
<Breadcrumbs separator="-" aria-label="Breadcrumb">
<Link color="inherit" href="/" onClick={handleClick}>
Material-UI
</Link>
<Link color="inherit" href="/getting-started/installation/" onClick={handleClick}>
Core
</Link>
<Typography color="textPrimary">Breadcrumb</Typography>
</Breadcrumbs>
</Paper>
<br />
<Paper elevation={0} className={classes.paper}>
<Breadcrumbs separator={<NavigateNextIcon fontSize="small" />} aria-label="Breadcrumb">
<Link color="inherit" href="/" onClick={handleClick}>
Material-UI
</Link>
<Link color="inherit" href="/getting-started/installation/" onClick={handleClick}>
Core
</Link>
<Typography color="textPrimary">Breadcrumb</Typography>
</Breadcrumbs>
</Paper>
</div>
);
}

CustomSeparator.propTypes = {
classes: PropTypes.object.isRequired,
} as any;

export default withStyles(styles)(CustomSeparator);
89 changes: 89 additions & 0 deletions docs/src/pages/demos/breadcrumbs/CustomizedBreadcrumbs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles, Theme, createStyles, WithStyles } from '@material-ui/core/styles';
import { emphasize } from '@material-ui/core/styles/colorManipulator';
import Paper from '@material-ui/core/Paper';
import Breadcrumbs from '@material-ui/core/Breadcrumbs';
import Chip from '@material-ui/core/Chip';
import Avatar from '@material-ui/core/Avatar';
import HomeIcon from '@material-ui/icons/Home';
import ExpandMoreIcon from '@material-ui/icons/ExpandMore';

interface CustomBreadcrumbProps extends WithStyles<typeof styles> {}

interface CustomizedBreadcrumbsProps extends WithStyles<typeof styles> {}

const styles = (theme: Theme) =>
createStyles({
root: {
padding: theme.spacing(1),
},
chip: {
backgroundColor: theme.palette.grey[100],
height: 24,
color: theme.palette.grey[800],
fontWeight: theme.typography.fontWeightRegular,
'&:hover, &:focus': {
backgroundColor: theme.palette.grey[300],
},
'&:active': {
boxShadow: theme.shadows[1],
backgroundColor: emphasize(theme.palette.grey[300], 0.12),
},
},
avatar: {
background: 'none',
marginRight: -theme.spacing(1.5),
},
});

function handleClick(event: React.MouseEvent<HTMLAnchorElement, MouseEvent>) {
event.preventDefault();
alert('You clicked a breadcrumb.'); // eslint-disable-line no-alert
}

function CustomBreadcrumb(props: CustomBreadcrumbProps) {
const { classes, ...rest } = props;
return <Chip className={classes.chip} {...rest} />;
}

CustomBreadcrumb.propTypes = {
classes: PropTypes.object.isRequired,
} as any;

const StyledBreadcrumb = withStyles(styles)(CustomBreadcrumb);

function CustomizedBreadcrumbs(props: CustomizedBreadcrumbsProps) {
const { classes } = props;

return (
<Paper elevation={0} className={classes.root}>
<Breadcrumbs aria-label="Breadcrumb">
<StyledBreadcrumb
component="a"
href="#"
label="Home"
avatar={
<Avatar className={classes.avatar}>
<HomeIcon />
</Avatar>
}
onClick={handleClick}
/>
<StyledBreadcrumb component="a" href="#" label="Catalog" onClick={handleClick} />
<StyledBreadcrumb
label="Accessories"
deleteIcon={<ExpandMoreIcon />}
onClick={handleClick}
onDelete={handleClick}
/>
</Breadcrumbs>
</Paper>
);
}

CustomizedBreadcrumbs.propTypes = {
classes: PropTypes.object.isRequired,
} as any;

export default withStyles(styles)(CustomizedBreadcrumbs);
65 changes: 65 additions & 0 deletions docs/src/pages/demos/breadcrumbs/IconBreadcrumbs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles, Theme, createStyles, WithStyles } from '@material-ui/core/styles';
import Paper from '@material-ui/core/Paper';
import Typography from '@material-ui/core/Typography';
import Breadcrumbs from '@material-ui/core/Breadcrumbs';
import Link from '@material-ui/core/Link';
import HomeIcon from '@material-ui/icons/Home';
import WhatshotIcon from '@material-ui/icons/Whatshot';
import GrainIcon from '@material-ui/icons/Grain';

interface IconBreadcrumbsProps extends WithStyles<typeof styles> {}

const styles = (theme: Theme) =>
createStyles({
root: {
padding: theme.spacing(1, 2),
},
link: {
display: 'flex',
},
icon: {
marginRight: theme.spacing(0.5),
width: 20,
height: 20,
},
});

function handleClick(event: React.MouseEvent<HTMLAnchorElement, MouseEvent>) {
event.preventDefault();
alert('You clicked a breadcrumb.'); // eslint-disable-line no-alert
}

function IconBreadcrumbs(props: IconBreadcrumbsProps) {
const { classes } = props;
return (
<Paper elevation={0} className={classes.root}>
<Breadcrumbs aria-label="Breadcrumb">
<Link color="inherit" href="/" onClick={handleClick} className={classes.link}>
<HomeIcon className={classes.icon} />
Material-UI
</Link>
<Link
color="inherit"
href="/getting-started/installation/"
onClick={handleClick}
className={classes.link}
>
<WhatshotIcon className={classes.icon} />
Core
</Link>
<Typography color="textPrimary" className={classes.link}>
<GrainIcon className={classes.icon} />
Breadcrumb
</Typography>
</Breadcrumbs>
</Paper>
);
}

IconBreadcrumbs.propTypes = {
classes: PropTypes.object.isRequired,
} as any;

export default withStyles(styles)(IconBreadcrumbs);
12 changes: 7 additions & 5 deletions docs/src/pages/demos/breadcrumbs/RouterBreadcrumbs.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ const styles = theme => ({
},
});

const LinkRouter = props => <Link {...props} component={RouterLink} />;

class RouterBreadcrumbs extends React.Component {
state = {
open: true,
Expand All @@ -81,9 +83,9 @@ class RouterBreadcrumbs extends React.Component {

return (
<Breadcrumbs aria-label="Breadcrumb">
<Link component={RouterLink} color="inherit" to="/">
<LinkRouter color="inherit" to="/">
Home
</Link>
</LinkRouter>
{pathnames.map((value, index) => {
const last = index === pathnames.length - 1;
const to = `/${pathnames.slice(0, index + 1).join('/')}`;
Expand All @@ -93,9 +95,9 @@ class RouterBreadcrumbs extends React.Component {
{breadcrumbNameMap[to]}
</Typography>
) : (
<Link component={RouterLink} color="inherit" to={to} key={to}>
<LinkRouter color="inherit" to={to} key={to}>
{breadcrumbNameMap[to]}
</Link>
</LinkRouter>
);
})}
</Breadcrumbs>
Expand All @@ -106,7 +108,7 @@ class RouterBreadcrumbs extends React.Component {
<List component="nav">
<ListItemLink to="/inbox" open={this.state.open} onClick={this.handleClick} />
<Collapse in={this.state.open} timeout="auto" unmountOnExit>
<List component="div" disablePadding>
<List component={'div'} disablePadding>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something we could improve in the TypeScript to JavaScript logic generation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to change the js file directly, but I can't pass this ci. what should i do?
WX20190402-234503@2x

Copy link
Member

@oliviertassinari oliviertassinari Apr 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a topic for a different pull request. I was only raising the potential.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's fine with prettier it's fine with me

<ListItemLink to="/inbox/important" className={classes.nested} />
</List>
</Collapse>
Expand Down
Loading