|
| 1 | +import React, { Component } from 'react'; |
| 2 | +import { withStyles, CssBaseline } from '@material-ui/core'; |
| 3 | +import { BrowserRouter, Route, Switch, Redirect } from 'react-router-dom'; |
| 4 | +import classnames from 'classnames'; |
| 5 | + |
| 6 | +import Header from '../Header'; |
| 7 | +import Sidebar from '../Sidebar'; |
| 8 | + |
| 9 | +// pages |
| 10 | +import Dashboard from '../../pages/dashboard'; |
| 11 | +import Typography from '../../pages/typography'; |
| 12 | +import Notifications from '../../pages/notifications'; |
| 13 | +import Maps from '../../pages/maps'; |
| 14 | +import Tables from '../../pages/tables'; |
| 15 | +import Icons from '../../pages/icons'; |
| 16 | +import Charts from '../../pages/charts'; |
| 17 | + |
| 18 | +const Layout = ({ classes, isSidebarOpened, toggleSidebar }) => ( |
| 19 | + <div className={classes.root}> |
| 20 | + <CssBaseline /> |
| 21 | + <BrowserRouter> |
| 22 | + <React.Fragment> |
| 23 | + <Header /> |
| 24 | + <Sidebar /> |
| 25 | + <div className={classnames(classes.content, { [classes.contentShift]: isSidebarOpened })}> |
| 26 | + <div className={classes.fakeToolbar} /> |
| 27 | + <Switch> |
| 28 | + <Route path="/app/dashboard" component={Dashboard} /> |
| 29 | + <Route path="/app/typography" component={Typography} /> |
| 30 | + <Route path="/app/tables" component={Tables} /> |
| 31 | + <Route path="/app/notifications" component={Notifications} /> |
| 32 | + <Route exact path="/app/ui" render={() => <Redirect to="/app/ui/icons" />} /> |
| 33 | + <Route path="/app/ui/maps" component={Maps} /> |
| 34 | + <Route path="/app/ui/icons" component={Icons} /> |
| 35 | + <Route path="/app/ui/charts" component={Charts} /> |
| 36 | + </Switch> |
| 37 | + </div> |
| 38 | + </React.Fragment> |
| 39 | + </BrowserRouter> |
| 40 | + </div> |
| 41 | +); |
| 42 | + |
| 43 | +const styles = theme => ({ |
| 44 | + root: { |
| 45 | + display: 'flex', |
| 46 | + maxWidth: '100vw', |
| 47 | + overflowX: 'hidden', |
| 48 | + }, |
| 49 | + content: { |
| 50 | + flexGrow: 1, |
| 51 | + padding: theme.spacing.unit * 3, |
| 52 | + width: `calc(100vw - 240px)`, |
| 53 | + minHeight: '100vh', |
| 54 | + }, |
| 55 | + contentShift: { |
| 56 | + width: `calc(100vw - ${240 + theme.spacing.unit * 6}px)`, |
| 57 | + transition: theme.transitions.create(['width', 'margin'], { |
| 58 | + easing: theme.transitions.easing.sharp, |
| 59 | + duration: theme.transitions.duration.enteringScreen, |
| 60 | + }), |
| 61 | + }, |
| 62 | + fakeToolbar: { |
| 63 | + ...theme.mixins.toolbar, |
| 64 | + } |
| 65 | +}); |
| 66 | + |
| 67 | +export default withStyles(styles)(Layout); |
0 commit comments