Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.28 KB | None | 0 0
  1. export default withStyles(DashboardLayout.styles)(DashboardLayout);
  2.  
  3. import PropTypes from 'prop-types';
  4. import classNames from 'classnames';
  5. import { withStyles } from '@material-ui/core/styles';
  6. import CssBaseline from '@material-ui/core/CssBaseline';
  7. import Drawer from '@material-ui/core/Drawer';
  8. import AppBar from '@material-ui/core/AppBar';
  9. import Toolbar from '@material-ui/core/Toolbar';
  10. import List from '@material-ui/core/List';
  11. import Typography from '@material-ui/core/Typography';
  12. import Divider from '@material-ui/core/Divider';
  13. import IconButton from '@material-ui/core/IconButton';
  14. import Badge from '@material-ui/core/Badge';
  15. import MenuIcon from '@material-ui/icons/Menu';
  16. import ChevronLeftIcon from '@material-ui/icons/ChevronLeft';
  17. import NotificationsIcon from '@material-ui/icons/Notifications';
  18. import { mainListItems, secondaryListItems } from './listItems';
  19.  
  20. const drawerWidth = 240;
  21.  
  22. const styles = theme => ({
  23. root: {
  24. display: 'flex',
  25. },
  26. toolbar: {
  27. paddingRight: 24, // keep right padding when drawer closed
  28. },
  29. toolbarIcon: {
  30. display: 'flex',
  31. alignItems: 'center',
  32. justifyContent: 'flex-end',
  33. padding: '0 8px',
  34. ...theme.mixins.toolbar,
  35. },
  36. appBar: {
  37. zIndex: theme.zIndex.drawer + 1,
  38. transition: theme.transitions.create(['width', 'margin'], {
  39. easing: theme.transitions.easing.sharp,
  40. duration: theme.transitions.duration.leavingScreen,
  41. }),
  42. },
  43. appBarShift: {
  44. marginLeft: drawerWidth,
  45. width: `calc(100% - ${drawerWidth}px)`,
  46. transition: theme.transitions.create(['width', 'margin'], {
  47. easing: theme.transitions.easing.sharp,
  48. duration: theme.transitions.duration.enteringScreen,
  49. }),
  50. },
  51. menuButton: {
  52. marginLeft: 12,
  53. marginRight: 36,
  54. },
  55. menuButtonHidden: {
  56. display: 'none',
  57. },
  58. title: {
  59. flexGrow: 1,
  60. },
  61. drawerPaper: {
  62. position: 'relative',
  63. whiteSpace: 'nowrap',
  64. width: drawerWidth,
  65. transition: theme.transitions.create('width', {
  66. easing: theme.transitions.easing.sharp,
  67. duration: theme.transitions.duration.enteringScreen,
  68. }),
  69. },
  70. drawerPaperClose: {
  71. overflowX: 'hidden',
  72. transition: theme.transitions.create('width', {
  73. easing: theme.transitions.easing.sharp,
  74. duration: theme.transitions.duration.leavingScreen,
  75. }),
  76. width: theme.spacing.unit * 7,
  77. [theme.breakpoints.up('sm')]: {
  78. width: theme.spacing.unit * 9,
  79. },
  80. },
  81. appBarSpacer: theme.mixins.toolbar,
  82. content: {
  83. flexGrow: 1,
  84. padding: theme.spacing.unit * 3,
  85. height: '100vh',
  86. overflow: 'auto',
  87. },
  88. chartContainer: {
  89. marginLeft: -22,
  90. },
  91. tableContainer: {
  92. height: 320,
  93. },
  94. h5: {
  95. marginBottom: theme.spacing.unit * 2,
  96. },
  97. });
  98.  
  99. class DashboardLayout extends React.Component {
  100. state = {
  101. open: true,
  102. };
  103.  
  104. handleDrawerToggle = () => {
  105. this.setState({ open: !this.state.open });
  106. };
  107.  
  108. render() {
  109. const { classes, children } = this.props;
  110.  
  111. return (
  112. <div className={classes.root}>
  113. <CssBaseline />
  114. <AppBar
  115. position="absolute"
  116. className={classNames(classes.appBar, this.state.open && classes.appBarShift)}
  117. >
  118. <Toolbar disableGutters={!this.state.open} className={classes.toolbar}>
  119. <IconButton
  120. color="inherit"
  121. aria-label="Open drawer"
  122. onClick={this.handleDrawerToggle}
  123. className={classNames(
  124. classes.menuButton,
  125. this.state.open && classes.menuButtonHidden,
  126. )}
  127. >
  128. <MenuIcon />
  129. </IconButton>
  130. <Typography
  131. component="h1"
  132. variant="h6"
  133. color="inherit"
  134. noWrap
  135. className={classes.title}
  136. >
  137. Dashboard
  138. </Typography>
  139. <IconButton color="inherit">
  140. <Badge badgeContent={4} color="secondary">
  141. <NotificationsIcon />
  142. </Badge>
  143. </IconButton>
  144. </Toolbar>
  145. </AppBar>
  146. <Drawer
  147. variant="permanent"
  148. classes={{
  149. paper: classNames(classes.drawerPaper, !this.state.open && classes.drawerPaperClose),
  150. }}
  151. open={this.state.open}
  152. >
  153. <div className={classes.toolbarIcon}>
  154. <IconButton onClick={this.handleDrawerToggle}>
  155. <ChevronLeftIcon />
  156. </IconButton>
  157. </div>
  158. <Divider />
  159. <List>{mainListItems}</List>
  160. <Divider />
  161. </Drawer>
  162. <main className={classes.content}>
  163. { this.props.children }
  164. <div> Children </div>
  165. </main>
  166. </div>
  167. );
  168. }
  169. }
  170.  
  171. DashboardLayout.propTypes = {
  172. classes: PropTypes.object.isRequired,
  173. };
  174.  
  175. export default withStyles(styles)(DashboardLayout);
  176.  
  177. const theme = createMuiTheme({
  178. drawerWidth: 200
  179. });
  180.  
  181. function Root() {
  182. return (
  183. <MuiThemeProvider theme={theme}>
  184. <App/>
  185. </MuiThemeProvider>
  186. );
  187. }
  188.  
  189. // your appbar's own style
  190. const styles = theme => ({
  191. appBar: {
  192. width: `calc(100% - ${theme.drawerWidth}px)`,
  193. marginLeft: theme.drawerWidth
  194. }
  195. })
  196.  
  197. // your drawer's own style
  198. const styles = theme => ({
  199. drawer: {
  200. width: theme.drawerWidth,
  201. flexShrink: 0
  202. },
  203. drawerPaper: {
  204. width: theme.drawerWidth
  205. }
  206. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement