-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docs] Add most Drawer TypeScript demos (#15119)
- Loading branch information
1 parent
a3fed3c
commit 650ddda
Showing
8 changed files
with
1,241 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
import React from 'react'; | ||
import clsx from 'clsx'; | ||
import { makeStyles, useTheme, Theme } from '@material-ui/core/styles'; | ||
import Drawer from '@material-ui/core/Drawer'; | ||
import AppBar from '@material-ui/core/AppBar'; | ||
import Toolbar from '@material-ui/core/Toolbar'; | ||
import List from '@material-ui/core/List'; | ||
import CssBaseline from '@material-ui/core/CssBaseline'; | ||
import Typography from '@material-ui/core/Typography'; | ||
import Divider from '@material-ui/core/Divider'; | ||
import IconButton from '@material-ui/core/IconButton'; | ||
import MenuIcon from '@material-ui/icons/Menu'; | ||
import ChevronLeftIcon from '@material-ui/icons/ChevronLeft'; | ||
import ChevronRightIcon from '@material-ui/icons/ChevronRight'; | ||
import ListItem from '@material-ui/core/ListItem'; | ||
import ListItemIcon from '@material-ui/core/ListItemIcon'; | ||
import ListItemText from '@material-ui/core/ListItemText'; | ||
import InboxIcon from '@material-ui/icons/MoveToInbox'; | ||
import MailIcon from '@material-ui/icons/Mail'; | ||
|
||
const drawerWidth = 240; | ||
|
||
const useStyles = makeStyles((theme: Theme) => ({ | ||
root: { | ||
display: 'flex', | ||
}, | ||
appBar: { | ||
zIndex: theme.zIndex.drawer + 1, | ||
transition: theme.transitions.create(['width', 'margin'], { | ||
easing: theme.transitions.easing.sharp, | ||
duration: theme.transitions.duration.leavingScreen, | ||
}), | ||
}, | ||
appBarShift: { | ||
marginLeft: drawerWidth, | ||
width: `calc(100% - ${drawerWidth}px)`, | ||
transition: theme.transitions.create(['width', 'margin'], { | ||
easing: theme.transitions.easing.sharp, | ||
duration: theme.transitions.duration.enteringScreen, | ||
}), | ||
}, | ||
menuButton: { | ||
marginRight: 36, | ||
}, | ||
hide: { | ||
display: 'none', | ||
}, | ||
drawer: { | ||
width: drawerWidth, | ||
flexShrink: 0, | ||
whiteSpace: 'nowrap', | ||
}, | ||
drawerOpen: { | ||
width: drawerWidth, | ||
transition: theme.transitions.create('width', { | ||
easing: theme.transitions.easing.sharp, | ||
duration: theme.transitions.duration.enteringScreen, | ||
}), | ||
}, | ||
drawerClose: { | ||
transition: theme.transitions.create('width', { | ||
easing: theme.transitions.easing.sharp, | ||
duration: theme.transitions.duration.leavingScreen, | ||
}), | ||
overflowX: 'hidden', | ||
width: theme.spacing(7) + 1, | ||
[theme.breakpoints.up('sm')]: { | ||
width: theme.spacing(9) + 1, | ||
}, | ||
}, | ||
toolbar: { | ||
display: 'flex', | ||
alignItems: 'center', | ||
justifyContent: 'flex-end', | ||
padding: '0 8px', | ||
...theme.mixins.toolbar, | ||
}, | ||
content: { | ||
flexGrow: 1, | ||
padding: theme.spacing(3), | ||
}, | ||
})); | ||
|
||
function MiniDrawer() { | ||
const classes = useStyles(); | ||
const theme: Theme = useTheme(); | ||
const [open, setOpen] = React.useState(false); | ||
|
||
function handleDrawerOpen() { | ||
setOpen(true); | ||
} | ||
|
||
function handleDrawerClose() { | ||
setOpen(false); | ||
} | ||
|
||
return ( | ||
<div className={classes.root}> | ||
<CssBaseline /> | ||
<AppBar | ||
position="fixed" | ||
className={clsx(classes.appBar, { | ||
[classes.appBarShift]: open, | ||
})} | ||
> | ||
<Toolbar> | ||
<IconButton | ||
color="inherit" | ||
aria-label="Open drawer" | ||
onClick={handleDrawerOpen} | ||
edge="start" | ||
className={clsx(classes.menuButton, { | ||
[classes.hide]: open, | ||
})} | ||
> | ||
<MenuIcon /> | ||
</IconButton> | ||
<Typography variant="h6" color="inherit" noWrap> | ||
Mini variant drawer | ||
</Typography> | ||
</Toolbar> | ||
</AppBar> | ||
<Drawer | ||
variant="permanent" | ||
className={clsx(classes.drawer, { | ||
[classes.drawerOpen]: open, | ||
[classes.drawerClose]: !open, | ||
})} | ||
classes={{ | ||
paper: clsx({ | ||
[classes.drawerOpen]: open, | ||
[classes.drawerClose]: !open, | ||
}), | ||
}} | ||
open={open} | ||
> | ||
<div className={classes.toolbar}> | ||
<IconButton onClick={handleDrawerClose}> | ||
{theme.direction === 'rtl' ? <ChevronRightIcon /> : <ChevronLeftIcon />} | ||
</IconButton> | ||
</div> | ||
<Divider /> | ||
<List> | ||
{['Inbox', 'Starred', 'Send email', 'Drafts'].map((text, index) => ( | ||
<ListItem button key={text}> | ||
<ListItemIcon>{index % 2 === 0 ? <InboxIcon /> : <MailIcon />}</ListItemIcon> | ||
<ListItemText primary={text} /> | ||
</ListItem> | ||
))} | ||
</List> | ||
<Divider /> | ||
<List> | ||
{['All mail', 'Trash', 'Spam'].map((text, index) => ( | ||
<ListItem button key={text}> | ||
<ListItemIcon>{index % 2 === 0 ? <InboxIcon /> : <MailIcon />}</ListItemIcon> | ||
<ListItemText primary={text} /> | ||
</ListItem> | ||
))} | ||
</List> | ||
</Drawer> | ||
<main className={classes.content}> | ||
<div className={classes.toolbar} /> | ||
<Typography paragraph> | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt | ||
ut labore et dolore magna aliqua. Rhoncus dolor purus non enim praesent elementum | ||
facilisis leo vel. Risus at ultrices mi tempus imperdiet. Semper risus in hendrerit | ||
gravida rutrum quisque non tellus. Convallis convallis tellus id interdum velit laoreet id | ||
donec ultrices. Odio morbi quis commodo odio aenean sed adipiscing. Amet nisl suscipit | ||
adipiscing bibendum est ultricies integer quis. Cursus euismod quis viverra nibh cras. | ||
Metus vulputate eu scelerisque felis imperdiet proin fermentum leo. Mauris commodo quis | ||
imperdiet massa tincidunt. Cras tincidunt lobortis feugiat vivamus at augue. At augue eget | ||
arcu dictum varius duis at consectetur lorem. Velit sed ullamcorper morbi tincidunt. Lorem | ||
donec massa sapien faucibus et molestie ac. | ||
</Typography> | ||
<Typography paragraph> | ||
Consequat mauris nunc congue nisi vitae suscipit. Fringilla est ullamcorper eget nulla | ||
facilisi etiam dignissim diam. Pulvinar elementum integer enim neque volutpat ac | ||
tincidunt. Ornare suspendisse sed nisi lacus sed viverra tellus. Purus sit amet volutpat | ||
consequat mauris. Elementum eu facilisis sed odio morbi. Euismod lacinia at quis risus sed | ||
vulputate odio. Morbi tincidunt ornare massa eget egestas purus viverra accumsan in. In | ||
hendrerit gravida rutrum quisque non tellus orci ac. Pellentesque nec nam aliquam sem et | ||
tortor. Habitant morbi tristique senectus et. Adipiscing elit duis tristique sollicitudin | ||
nibh sit. Ornare aenean euismod elementum nisi quis eleifend. Commodo viverra maecenas | ||
accumsan lacus vel facilisis. Nulla posuere sollicitudin aliquam ultrices sagittis orci a. | ||
</Typography> | ||
</main> | ||
</div> | ||
); | ||
} | ||
|
||
export default MiniDrawer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { createStyles, withStyles, Theme, WithStyles } from '@material-ui/core/styles'; | ||
import Drawer from '@material-ui/core/Drawer'; | ||
import CssBaseline from '@material-ui/core/CssBaseline'; | ||
import AppBar from '@material-ui/core/AppBar'; | ||
import Toolbar from '@material-ui/core/Toolbar'; | ||
import List from '@material-ui/core/List'; | ||
import Typography from '@material-ui/core/Typography'; | ||
import Divider from '@material-ui/core/Divider'; | ||
import ListItem from '@material-ui/core/ListItem'; | ||
import ListItemIcon from '@material-ui/core/ListItemIcon'; | ||
import ListItemText from '@material-ui/core/ListItemText'; | ||
import InboxIcon from '@material-ui/icons/MoveToInbox'; | ||
import MailIcon from '@material-ui/icons/Mail'; | ||
|
||
const drawerWidth = 240; | ||
|
||
const styles = (theme: Theme) => | ||
createStyles({ | ||
root: { | ||
display: 'flex', | ||
}, | ||
appBar: { | ||
width: `calc(100% - ${drawerWidth}px)`, | ||
marginLeft: drawerWidth, | ||
}, | ||
drawer: { | ||
width: drawerWidth, | ||
flexShrink: 0, | ||
}, | ||
drawerPaper: { | ||
width: drawerWidth, | ||
}, | ||
toolbar: theme.mixins.toolbar, | ||
content: { | ||
flexGrow: 1, | ||
backgroundColor: theme.palette.background.default, | ||
padding: theme.spacing(3), | ||
}, | ||
}); | ||
|
||
export interface Props extends WithStyles<typeof styles> {} | ||
|
||
function PermanentDrawerLeft(props: Props) { | ||
const { classes } = props; | ||
|
||
return ( | ||
<div className={classes.root}> | ||
<CssBaseline /> | ||
<AppBar position="fixed" className={classes.appBar}> | ||
<Toolbar> | ||
<Typography variant="h6" color="inherit" noWrap> | ||
Permanent drawer | ||
</Typography> | ||
</Toolbar> | ||
</AppBar> | ||
<Drawer | ||
className={classes.drawer} | ||
variant="permanent" | ||
classes={{ | ||
paper: classes.drawerPaper, | ||
}} | ||
anchor="left" | ||
> | ||
<div className={classes.toolbar} /> | ||
<Divider /> | ||
<List> | ||
{['Inbox', 'Starred', 'Send email', 'Drafts'].map((text, index) => ( | ||
<ListItem button key={text}> | ||
<ListItemIcon>{index % 2 === 0 ? <InboxIcon /> : <MailIcon />}</ListItemIcon> | ||
<ListItemText primary={text} /> | ||
</ListItem> | ||
))} | ||
</List> | ||
<Divider /> | ||
<List> | ||
{['All mail', 'Trash', 'Spam'].map((text, index) => ( | ||
<ListItem button key={text}> | ||
<ListItemIcon>{index % 2 === 0 ? <InboxIcon /> : <MailIcon />}</ListItemIcon> | ||
<ListItemText primary={text} /> | ||
</ListItem> | ||
))} | ||
</List> | ||
</Drawer> | ||
<main className={classes.content}> | ||
<div className={classes.toolbar} /> | ||
<Typography paragraph> | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt | ||
ut labore et dolore magna aliqua. Rhoncus dolor purus non enim praesent elementum | ||
facilisis leo vel. Risus at ultrices mi tempus imperdiet. Semper risus in hendrerit | ||
gravida rutrum quisque non tellus. Convallis convallis tellus id interdum velit laoreet id | ||
donec ultrices. Odio morbi quis commodo odio aenean sed adipiscing. Amet nisl suscipit | ||
adipiscing bibendum est ultricies integer quis. Cursus euismod quis viverra nibh cras. | ||
Metus vulputate eu scelerisque felis imperdiet proin fermentum leo. Mauris commodo quis | ||
imperdiet massa tincidunt. Cras tincidunt lobortis feugiat vivamus at augue. At augue eget | ||
arcu dictum varius duis at consectetur lorem. Velit sed ullamcorper morbi tincidunt. Lorem | ||
donec massa sapien faucibus et molestie ac. | ||
</Typography> | ||
<Typography paragraph> | ||
Consequat mauris nunc congue nisi vitae suscipit. Fringilla est ullamcorper eget nulla | ||
facilisi etiam dignissim diam. Pulvinar elementum integer enim neque volutpat ac | ||
tincidunt. Ornare suspendisse sed nisi lacus sed viverra tellus. Purus sit amet volutpat | ||
consequat mauris. Elementum eu facilisis sed odio morbi. Euismod lacinia at quis risus sed | ||
vulputate odio. Morbi tincidunt ornare massa eget egestas purus viverra accumsan in. In | ||
hendrerit gravida rutrum quisque non tellus orci ac. Pellentesque nec nam aliquam sem et | ||
tortor. Habitant morbi tristique senectus et. Adipiscing elit duis tristique sollicitudin | ||
nibh sit. Ornare aenean euismod elementum nisi quis eleifend. Commodo viverra maecenas | ||
accumsan lacus vel facilisis. Nulla posuere sollicitudin aliquam ultrices sagittis orci a. | ||
</Typography> | ||
</main> | ||
</div> | ||
); | ||
} | ||
|
||
PermanentDrawerLeft.propTypes = { | ||
classes: PropTypes.object.isRequired, | ||
} as any; | ||
|
||
export default withStyles(styles)(PermanentDrawerLeft); |
Oops, something went wrong.