Projekt

Obecné

Profil

Stáhnout (4.26 KB) Statistiky
| Větev: | Tag: | Revize:
1
import * as React from 'react'
2
import { styled, useTheme } from '@mui/material/styles'
3
import Box from '@mui/material/Box'
4
import Drawer from '@mui/material/Drawer'
5
import CssBaseline from '@mui/material/CssBaseline'
6
import MuiAppBar, { AppBarProps as MuiAppBarProps } from '@mui/material/AppBar'
7
import Toolbar from '@mui/material/Toolbar'
8
import List from '@mui/material/List'
9
import Typography from '@mui/material/Typography'
10
import Divider from '@mui/material/Divider'
11
import IconButton from '@mui/material/IconButton'
12
import MenuIcon from '@mui/icons-material/Menu'
13
import ChevronLeftIcon from '@mui/icons-material/ChevronLeft'
14
import ChevronRightIcon from '@mui/icons-material/ChevronRight'
15
import ListItem from '@mui/material/ListItem'
16
import ListItemIcon from '@mui/material/ListItemIcon'
17
import ListItemText from '@mui/material/ListItemText'
18
import InboxIcon from '@mui/icons-material/MoveToInbox'
19
import MailIcon from '@mui/icons-material/Mail'
20
import { Fragment, FunctionComponent } from 'react'
21
import NavigationMenu from './NavigationMenu'
22
import { Paper } from '@mui/material'
23

    
24
const drawerWidth = 240
25

    
26
const Main = styled('main', { shouldForwardProp: (prop) => prop !== 'open' })<{
27
    open?: boolean
28
}>(({ theme, open }) => ({
29
    flexGrow: 1,
30
    // padding: theme.spacing(3),
31
    transition: theme.transitions.create('margin', {
32
        easing: theme.transitions.easing.sharp,
33
        duration: theme.transitions.duration.leavingScreen,
34
    }),
35
    marginLeft: `-${drawerWidth}px`,
36
    ...(open && {
37
        transition: theme.transitions.create('margin', {
38
            easing: theme.transitions.easing.easeOut,
39
            duration: theme.transitions.duration.enteringScreen,
40
        }),
41
        marginLeft: 0,
42
    }),
43
}))
44

    
45
interface AppBarProps extends MuiAppBarProps {
46
    open?: boolean
47
}
48

    
49
const AppBar = styled(MuiAppBar, {
50
    shouldForwardProp: (prop) => prop !== 'open',
51
})<AppBarProps>(({ theme, open }) => ({
52
    transition: theme.transitions.create(['margin', 'width'], {
53
        easing: theme.transitions.easing.sharp,
54
        duration: theme.transitions.duration.leavingScreen,
55
    }),
56
    ...(open && {
57
        width: `calc(100% - ${drawerWidth}px)`,
58
        marginLeft: `${drawerWidth}px`,
59
        transition: theme.transitions.create(['margin', 'width'], {
60
            easing: theme.transitions.easing.easeOut,
61
            duration: theme.transitions.duration.enteringScreen,
62
        }),
63
    }),
64
}))
65

    
66
const DrawerHeader = styled('div')(({ theme }) => ({
67
    display: 'flex',
68
    alignItems: 'center',
69
    padding: theme.spacing(0, 1),
70
    // necessary for content to be below app bar
71
    ...theme.mixins.toolbar,
72
    justifyContent: 'flex-end',
73
}))
74

    
75
export interface DrawerProps {
76
    children: React.ReactNode
77
}
78

    
79
const PersistentDrawerLeft: FunctionComponent<DrawerProps> = ({ children }) => {
80
    const [open, setOpen] = React.useState(false)
81

    
82
    const onOpenDrawer = () => {
83
        setOpen(true)
84
    }
85

    
86
    return (
87
        <Fragment>
88
            <Paper style={{ minHeight: '100vh', borderRadius: 0 }}>
89
                <Box sx={{ display: 'flex' }}>
90
                    {/* <CssBaseline /> */}
91
                    <AppBar position="fixed" open={open}>
92
                        <Toolbar>
93
                            <IconButton
94
                                color="inherit"
95
                                aria-label="open drawer"
96
                                onClick={onOpenDrawer}
97
                                edge="start"
98
                                sx={{ ...(open && { display: 'none' }) }}
99
                            >
100
                                <MenuIcon />
101
                            </IconButton>
102
                            <Typography variant="h6" noWrap component="div">
103
                                Assyrian Toponyms App Prototype
104
                            </Typography>
105
                        </Toolbar>
106
                    </AppBar>
107
                    <NavigationMenu
108
                        open={open}
109
                        drawerWidth={drawerWidth}
110
                        setOpen={setOpen}
111
                    />
112
                    <Main open={open} sx={{ mt: 2 }}>
113
                        <DrawerHeader />
114
                        {children}
115
                    </Main>
116
                </Box>
117
            </Paper>
118
        </Fragment>
119
    )
120
}
121

    
122
export default PersistentDrawerLeft
(1-1/3)