Projekt

Obecné

Profil

Stáhnout (4.97 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 Typography from '@mui/material/Typography'
9
import IconButton from '@mui/material/IconButton'
10
import MenuIcon from '@mui/icons-material/Menu'
11
import { Fragment, FunctionComponent } from 'react'
12
import NavigationMenu from './NavigationMenu'
13
import { Paper, Stack } from '@mui/material'
14
import { useDispatch, useSelector } from 'react-redux'
15
import { toggleTheme } from '../Theme/themeSlice'
16
import { RootState } from '../redux/store'
17

    
18
import DarkModeIcon from '@mui/icons-material/DarkMode'
19
import LightModeIcon from '@mui/icons-material/LightMode'
20

    
21
const drawerWidth = 240
22

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

    
42
interface AppBarProps extends MuiAppBarProps {
43
    open?: boolean
44
}
45

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

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

    
72
export interface DrawerProps {
73
    children: React.ReactNode
74
}
75

    
76
const PersistentDrawerLeft: FunctionComponent<DrawerProps> = ({ children }) => {
77
    const [open, setOpen] = React.useState(false)
78

    
79
    const onOpenDrawer = () => {
80
        setOpen(true)
81
    }
82

    
83
    const colorThemeMode = useSelector(
84
        (state: RootState) => state.theme.paletteMode
85
    )
86

    
87
    const dispatch = useDispatch()
88

    
89
    const onToggleTheme = () => {
90
        dispatch(toggleTheme())
91
    }
92

    
93
    return (
94
        <Fragment>
95
            <Paper style={{ minHeight: '100vh', borderRadius: 0 }}>
96
                <Box sx={{ display: 'flex' }}>
97
                    {/* <CssBaseline /> */}
98
                    <AppBar position="fixed" open={open}>
99
                        <Toolbar>
100
                            <IconButton
101
                                color="inherit"
102
                                aria-label="open drawer"
103
                                onClick={onOpenDrawer}
104
                                edge="start"
105
                                sx={{ ...(open && { display: 'none' }) }}
106
                            >
107
                                <MenuIcon />
108
                            </IconButton>
109
                            {/* <Box> */}
110
                                <Typography variant="h6" noWrap component="div">
111
                                    Assyrian Toponyms App Prototype
112
                                </Typography>
113
                                <Stack sx={{ml: 'auto'}} alignItems="flex-end">
114
                                {colorThemeMode === 'dark' ? (
115
                                    <IconButton onClick={onToggleTheme}>
116
                                        <LightModeIcon />
117
                                    </IconButton>
118
                                ) : (
119
                                    <IconButton onClick={onToggleTheme}>
120
                                        <DarkModeIcon />
121
                                    </IconButton>
122
                                )}
123
                                </Stack>
124
                            {/* </Box> */}
125
                        </Toolbar>
126
                    </AppBar>
127
                    <NavigationMenu
128
                        open={open}
129
                        drawerWidth={drawerWidth}
130
                        setOpen={setOpen}
131
                    />
132
                    <Main open={open} sx={{ mt: 2 }}>
133
                        <DrawerHeader />
134
                        {children}
135
                    </Main>
136
                </Box>
137
            </Paper>
138
        </Fragment>
139
    )
140
}
141

    
142
export default PersistentDrawerLeft
(1-1/3)