2022-11-28 16:39:13 -05:00
|
|
|
import { Theme } from '@mui/material/styles';
|
|
|
|
import Box from '@mui/material/Box';
|
|
|
|
import Drawer from '@mui/material/Drawer';
|
|
|
|
import SwipeableDrawer from '@mui/material/SwipeableDrawer';
|
|
|
|
import Toolbar from '@mui/material/Toolbar';
|
|
|
|
import useMediaQuery from '@mui/material/useMediaQuery';
|
|
|
|
import React, { FC, useCallback } from 'react';
|
|
|
|
|
|
|
|
import browser from 'scripts/browser';
|
|
|
|
|
2023-09-27 02:07:40 -04:00
|
|
|
export const DRAWER_WIDTH = 240;
|
2022-11-28 16:39:13 -05:00
|
|
|
|
|
|
|
export interface ResponsiveDrawerProps {
|
2023-09-27 02:07:40 -04:00
|
|
|
hasSecondaryToolBar?: boolean
|
2022-11-28 16:39:13 -05:00
|
|
|
open: boolean
|
|
|
|
onClose: () => void
|
|
|
|
onOpen: () => void
|
|
|
|
}
|
|
|
|
|
|
|
|
const ResponsiveDrawer: FC<ResponsiveDrawerProps> = ({
|
|
|
|
children,
|
2023-09-27 02:07:40 -04:00
|
|
|
hasSecondaryToolBar = false,
|
2022-11-28 16:39:13 -05:00
|
|
|
open = false,
|
|
|
|
onClose,
|
|
|
|
onOpen
|
|
|
|
}) => {
|
|
|
|
const isSmallScreen = useMediaQuery((theme: Theme) => theme.breakpoints.up('sm'));
|
|
|
|
const isLargeScreen = useMediaQuery((theme: Theme) => theme.breakpoints.up('lg'));
|
|
|
|
|
|
|
|
const getToolbarStyles = useCallback((theme: Theme) => ({
|
2023-09-27 02:07:40 -04:00
|
|
|
marginBottom: (hasSecondaryToolBar && !isLargeScreen) ? theme.spacing(6) : 0
|
|
|
|
}), [ hasSecondaryToolBar, isLargeScreen ]);
|
2022-11-28 16:39:13 -05:00
|
|
|
|
|
|
|
return ( isSmallScreen ? (
|
|
|
|
/* DESKTOP DRAWER */
|
|
|
|
<Drawer
|
|
|
|
sx={{
|
|
|
|
width: DRAWER_WIDTH,
|
|
|
|
flexShrink: 0,
|
|
|
|
'& .MuiDrawer-paper': {
|
|
|
|
width: DRAWER_WIDTH,
|
|
|
|
boxSizing: 'border-box'
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
variant='persistent'
|
|
|
|
anchor='left'
|
|
|
|
open={open}
|
|
|
|
>
|
|
|
|
<Toolbar
|
|
|
|
variant='dense'
|
|
|
|
sx={getToolbarStyles}
|
|
|
|
/>
|
|
|
|
{children}
|
|
|
|
</Drawer>
|
|
|
|
) : (
|
|
|
|
/* MOBILE DRAWER */
|
|
|
|
<SwipeableDrawer
|
|
|
|
anchor='left'
|
|
|
|
open={open}
|
|
|
|
onClose={onClose}
|
|
|
|
onOpen={onOpen}
|
|
|
|
// Disable swipe to open on iOS since it interferes with back navigation
|
|
|
|
disableDiscovery={browser.iOS}
|
|
|
|
ModalProps={{
|
|
|
|
keepMounted: true // Better open performance on mobile.
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Toolbar
|
|
|
|
variant='dense'
|
|
|
|
sx={getToolbarStyles}
|
|
|
|
/>
|
|
|
|
<Box
|
|
|
|
role='presentation'
|
|
|
|
// Close the drawer when the content is clicked
|
|
|
|
onClick={onClose}
|
|
|
|
onKeyDown={onClose}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</Box>
|
|
|
|
</SwipeableDrawer>
|
|
|
|
));
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ResponsiveDrawer;
|