Main.js
1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { makeStyles, useTheme } from '@material-ui/styles';
import { useMediaQuery } from '@material-ui/core';
import { Sidebar, Topbar, Footer } from './components';
const useStyles = makeStyles(theme => ({
root: {
paddingTop: 56,
height: '100%',
[theme.breakpoints.up('sm')]: {
paddingTop: 64
}
},
shiftContent: {
paddingLeft: 240
},
content: {
height: '100%'
}
}));
const Main = props => {
const { children } = props;
const classes = useStyles();
const theme = useTheme();
const isDesktop = useMediaQuery(theme.breakpoints.up('lg'), {
defaultMatches: true
});
const [openSidebar, setOpenSidebar] = useState(false);
const handleSidebarOpen = () => {
setOpenSidebar(true);
};
const handleSidebarClose = () => {
setOpenSidebar(false);
};
const shouldOpenSidebar = isDesktop ? true : openSidebar;
return (
<div
className={clsx({
[classes.root]: true,
[classes.shiftContent]: isDesktop
})}
>
<Topbar onSidebarOpen={handleSidebarOpen} />
<Sidebar
onClose={handleSidebarClose}
open={shouldOpenSidebar}
variant={isDesktop ? 'persistent' : 'temporary'}
/>
<main className={classes.content}>
{children}
<Footer />
</main>
</div>
);
};
Main.propTypes = {
children: PropTypes.node
};
export default Main;