Advertisement
Guest User

Untitled

a guest
Jul 17th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.11 KB | None | 0 0
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import classNames from 'classnames';
  4.  
  5. import { withStyles } from '@material-ui/core/styles';
  6.  
  7. import Drawer from '@material-ui/core/Drawer';
  8. import Collapse from '@material-ui/core/Collapse';
  9. import AppBar from '@material-ui/core/AppBar';
  10. import Toolbar from '@material-ui/core/Toolbar';
  11. import Typography from '@material-ui/core/Typography';
  12. import IconButton from '@material-ui/core/IconButton';
  13. import MenuIcon from '@material-ui/icons/Menu';
  14. import ChevronLeftIcon from '@material-ui/icons/ChevronLeft';
  15. import ChevronRightIcon from '@material-ui/icons/ChevronRight';
  16. import Divider from '@material-ui/core/Divider';
  17. import List from '@material-ui/core/List';
  18. import ListItem from '@material-ui/core/ListItem';
  19. import ListItemIcon from '@material-ui/core/ListItemIcon';
  20. import ListItemText from '@material-ui/core/ListItemText';
  21. import ExpandLess from '@material-ui/icons/ExpandLess';
  22. import ExpandMore from '@material-ui/icons/ExpandMore';
  23. import StarBorder from '@material-ui/icons/StarBorder';
  24. import {
  25. Send as SendIcon,
  26. Drafts as DraftsIcon,
  27. Inbox as InboxIcon } from '@material-ui/icons';
  28.  
  29. const drawerWidth = 240;
  30.  
  31. const styles = theme => ({
  32. root: {
  33. flexGrow: 1,
  34. height: '100%',
  35. zIndex: 1,
  36. overflow: 'hidden',
  37. position: 'relative',
  38. display: 'flex',
  39. },
  40. appBar: {
  41. zIndex: theme.zIndex.drawer + 1,
  42. transition: theme.transitions.create(['width', 'margin'], {
  43. easing: theme.transitions.easing.sharp,
  44. duration: theme.transitions.duration.leavingScreen,
  45. }),
  46. },
  47. appBarShift: {
  48. marginLeft: drawerWidth,
  49. width: `calc(100% - ${drawerWidth}px)`,
  50. transition: theme.transitions.create(['width', 'margin'], {
  51. easing: theme.transitions.easing.sharp,
  52. duration: theme.transitions.duration.enteringScreen,
  53. }),
  54. },
  55. menuButton: {
  56. marginLeft: 12,
  57. marginRight: 36,
  58. },
  59. hide: {
  60. display: 'none',
  61. },
  62. pageContent: {
  63. top: '120px',
  64. width: 'calc(100% - 72px)',
  65. left: '72px',
  66. position: 'relative',
  67. },
  68. drawerPaper: {
  69. position: 'absolute',
  70. whiteSpace: 'nowrap',
  71. width: drawerWidth,
  72. transition: theme.transitions.create('width', {
  73. easing: theme.transitions.easing.sharp,
  74. duration: theme.transitions.duration.enteringScreen,
  75. }),
  76. },
  77. drawerPaperClose: {
  78. overflowX: 'hidden',
  79. transition: theme.transitions.create('width', {
  80. easing: theme.transitions.easing.sharp,
  81. duration: theme.transitions.duration.leavingScreen,
  82. }),
  83. width: theme.spacing.unit * 7,
  84. [theme.breakpoints.up('sm')]: {
  85. width: theme.spacing.unit * 9,
  86. },
  87. },
  88. toolbar: {
  89. display: 'flex',
  90. alignItems: 'center',
  91. justifyContent: 'flex-end',
  92. padding: '0 8px',
  93. ...theme.mixins.toolbar,
  94. },
  95. content: {
  96. flexGrow: 1,
  97. backgroundColor: theme.palette.background.default,
  98. padding: theme.spacing.unit * 3,
  99. },
  100. nested: {
  101. paddingLeft: theme.spacing.unit * 4,
  102. },
  103. });
  104.  
  105. class App extends React.PureComponent {
  106. state = {
  107. open: false,
  108. openInbox: false,
  109. };
  110.  
  111. handleClick = () => {
  112. this.setState(state => ({ openInbox: !state.openInbox }));
  113. };
  114.  
  115. handleDrawer = () => {
  116. this.setState(state => ({ open: !state.open }));
  117. };
  118.  
  119. render() {
  120. const { classes, theme, title } = this.props;
  121.  
  122. return (
  123. <React.Fragment>
  124. <AppBar
  125. position="absolute"
  126. className={classNames(classes.appBar, this.state.open && classes.appBarShift)}
  127. >
  128. <Toolbar disableGutters={!this.state.open}>
  129. <IconButton
  130. color="inherit"
  131. aria-label="open drawer"
  132. onClick={this.handleDrawer}
  133. className={classNames(classes.menuButton, this.state.open && classes.hide)}
  134. >
  135. <MenuIcon />
  136. </IconButton>
  137. <Typography variant="title" color="inherit" noWrap>
  138. {
  139. title || 'Agoralys Dashboard'
  140. }
  141. </Typography>
  142. </Toolbar>
  143. </AppBar>
  144. <Drawer
  145. variant="permanent"
  146. classes={{
  147. paper: classNames(classes.drawerPaper, !this.state.open && classes.drawerPaperClose),
  148. }}
  149. open={this.state.open}
  150. >
  151. <div className={classes.toolbar}>
  152. <IconButton onClick={this.handleDrawer}>
  153. {theme.direction === 'rtl' ? <ChevronRightIcon /> : <ChevronLeftIcon />}
  154. </IconButton>
  155. </div>
  156. <Divider />
  157. <List>
  158. <ListItem button>
  159. <ListItemIcon>
  160. <SendIcon />
  161. </ListItemIcon>
  162. <ListItemText inset primary="Sent mail" />
  163. </ListItem>
  164. <ListItem button>
  165. <ListItemIcon>
  166. <DraftsIcon />
  167. </ListItemIcon>
  168. <ListItemText inset primary="Drafts" />
  169. </ListItem>
  170. <ListItem button onClick={this.handleClick}>
  171. <ListItemIcon>
  172. <InboxIcon />
  173. </ListItemIcon>
  174. <ListItemText inset primary="Inbox" />
  175. {this.state.openInbox ? <ExpandLess /> : <ExpandMore />}
  176. </ListItem>
  177. <Collapse in={this.state.openInbox} timeout="auto" unmountOnExit>
  178. <List component="div" disablePadding>
  179. <ListItem button className={classes.nested}>
  180. <ListItemIcon>
  181. <StarBorder />
  182. </ListItemIcon>
  183. <ListItemText inset primary="Starred" />
  184. </ListItem>
  185. </List>
  186. </Collapse>
  187. </List>
  188. </Drawer>
  189. </React.Fragment>
  190. );
  191. }
  192. }
  193.  
  194. App.propTypes = {
  195. children: PropTypes.oneOfType([
  196. PropTypes.arrayOf(PropTypes.node),
  197. PropTypes.node,
  198. ]).isRequired,
  199. classes: PropTypes.object.isRequired,
  200. theme: PropTypes.object.isRequired,
  201. title: PropTypes.string,
  202. };
  203.  
  204. export default withStyles(styles, { withTheme: true })(App);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement