forked from Shiloh/remnantchat
refactor(shell): de-DRY DrawerHeader
This commit is contained in:
parent
257737c65c
commit
37ed65df9a
@ -1,6 +1,7 @@
|
|||||||
import { PropsWithChildren, useContext } from 'react'
|
import { PropsWithChildren, useContext } from 'react'
|
||||||
import { Link } from 'react-router-dom'
|
import { Link } from 'react-router-dom'
|
||||||
import { Theme } from '@mui/material/styles'
|
import { Theme } from '@mui/material/styles'
|
||||||
|
import Box from '@mui/material/Box'
|
||||||
import MuiDrawer from '@mui/material/Drawer'
|
import MuiDrawer from '@mui/material/Drawer'
|
||||||
import List from '@mui/material/List'
|
import List from '@mui/material/List'
|
||||||
import MuiLink from '@mui/material/Link'
|
import MuiLink from '@mui/material/Link'
|
||||||
@ -24,8 +25,6 @@ import GitInfo from 'react-git-info/macro'
|
|||||||
import { routes } from 'config/routes'
|
import { routes } from 'config/routes'
|
||||||
import { SettingsContext } from 'contexts/SettingsContext'
|
import { SettingsContext } from 'contexts/SettingsContext'
|
||||||
|
|
||||||
import { DrawerHeader } from './DrawerHeader'
|
|
||||||
|
|
||||||
const { commit } = GitInfo()
|
const { commit } = GitInfo()
|
||||||
|
|
||||||
export const drawerWidth = 240
|
export const drawerWidth = 240
|
||||||
@ -59,7 +58,16 @@ export const Drawer = ({ isDrawerOpen, onDrawerClose, theme }: DrawerProps) => {
|
|||||||
anchor="left"
|
anchor="left"
|
||||||
open={isDrawerOpen}
|
open={isDrawerOpen}
|
||||||
>
|
>
|
||||||
<DrawerHeader>
|
<Box
|
||||||
|
sx={theme => ({
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
padding: theme.spacing(0, 1),
|
||||||
|
// necessary for drawer content to be pushed below app bar
|
||||||
|
...theme.mixins.toolbar,
|
||||||
|
justifyContent: 'flex-end',
|
||||||
|
})}
|
||||||
|
>
|
||||||
<IconButton onClick={onDrawerClose} aria-label="Close menu">
|
<IconButton onClick={onDrawerClose} aria-label="Close menu">
|
||||||
{theme.direction === 'ltr' ? (
|
{theme.direction === 'ltr' ? (
|
||||||
<ChevronLeftIcon />
|
<ChevronLeftIcon />
|
||||||
@ -67,7 +75,7 @@ export const Drawer = ({ isDrawerOpen, onDrawerClose, theme }: DrawerProps) => {
|
|||||||
<ChevronRightIcon />
|
<ChevronRightIcon />
|
||||||
)}
|
)}
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</DrawerHeader>
|
</Box>
|
||||||
<Divider />
|
<Divider />
|
||||||
<List role="navigation">
|
<List role="navigation">
|
||||||
<Link to={routes.ROOT}>
|
<Link to={routes.ROOT}>
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
import { styled } from '@mui/material/styles'
|
|
||||||
|
|
||||||
export const DrawerHeader = styled('div')(({ theme }) => ({
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
padding: theme.spacing(0, 1),
|
|
||||||
// necessary for content to be below app bar
|
|
||||||
...theme.mixins.toolbar,
|
|
||||||
justifyContent: 'flex-end',
|
|
||||||
}))
|
|
@ -3,11 +3,10 @@ import Box from '@mui/material/Box'
|
|||||||
import Collapse from '@mui/material/Collapse'
|
import Collapse from '@mui/material/Collapse'
|
||||||
import { styled } from '@mui/material/styles'
|
import { styled } from '@mui/material/styles'
|
||||||
|
|
||||||
import { DrawerHeader } from './DrawerHeader'
|
|
||||||
import { drawerWidth } from './Drawer'
|
import { drawerWidth } from './Drawer'
|
||||||
import { peerListWidth } from './PeerList'
|
import { peerListWidth } from './PeerList'
|
||||||
|
|
||||||
const Main = styled('main', {
|
const StyledMain = styled('main', {
|
||||||
shouldForwardProp: prop =>
|
shouldForwardProp: prop =>
|
||||||
prop !== 'isDrawerOpen' && prop !== 'isPeerListOpen',
|
prop !== 'isDrawerOpen' && prop !== 'isPeerListOpen',
|
||||||
})<{
|
})<{
|
||||||
@ -49,7 +48,7 @@ export const RouteContent = ({
|
|||||||
showAppBar,
|
showAppBar,
|
||||||
}: RouteContentProps) => {
|
}: RouteContentProps) => {
|
||||||
return (
|
return (
|
||||||
<Main
|
<StyledMain
|
||||||
isDrawerOpen={isDrawerOpen}
|
isDrawerOpen={isDrawerOpen}
|
||||||
isPeerListOpen={isPeerListOpen}
|
isPeerListOpen={isPeerListOpen}
|
||||||
sx={{
|
sx={{
|
||||||
@ -58,10 +57,17 @@ export const RouteContent = ({
|
|||||||
width: '100%',
|
width: '100%',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
{/*
|
||||||
|
This Collapse acts as a spacer to allow the controls to hide behind the AppBar.
|
||||||
|
*/}
|
||||||
<Collapse in={showAppBar} sx={{ flex: 'none' }}>
|
<Collapse in={showAppBar} sx={{ flex: 'none' }}>
|
||||||
<DrawerHeader />
|
<Box
|
||||||
|
sx={theme => ({
|
||||||
|
...theme.mixins.toolbar,
|
||||||
|
})}
|
||||||
|
/>
|
||||||
</Collapse>
|
</Collapse>
|
||||||
<Box sx={{ overflow: 'auto', flexGrow: 1 }}>{children}</Box>
|
<Box sx={{ overflow: 'auto', flexGrow: 1 }}>{children}</Box>
|
||||||
</Main>
|
</StyledMain>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user