2023-11-28 10:26:14 -05:00
|
|
|
import type { Theme } from '@mui/material/styles';
|
2022-11-28 16:39:13 -05:00
|
|
|
import Box from '@mui/material/Box';
|
|
|
|
import Drawer from '@mui/material/Drawer';
|
|
|
|
import SwipeableDrawer from '@mui/material/SwipeableDrawer';
|
|
|
|
import useMediaQuery from '@mui/material/useMediaQuery';
|
2023-11-28 10:26:14 -05:00
|
|
|
import React, { FC } from 'react';
|
2022-11-28 16:39:13 -05:00
|
|
|
|
|
|
|
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 {
|
|
|
|
open: boolean
|
|
|
|
onClose: () => void
|
|
|
|
onOpen: () => void
|
|
|
|
}
|
|
|
|
|
|
|
|
const ResponsiveDrawer: FC<ResponsiveDrawerProps> = ({
|
|
|
|
children,
|
|
|
|
open = false,
|
|
|
|
onClose,
|
|
|
|
onOpen
|
|
|
|
}) => {
|
2024-01-07 02:48:29 -05:00
|
|
|
const isMediumScreen = useMediaQuery((theme: Theme) => theme.breakpoints.up('md'));
|
2022-11-28 16:39:13 -05:00
|
|
|
|
2024-01-07 02:48:29 -05:00
|
|
|
return ( isMediumScreen ? (
|
2022-11-28 16:39:13 -05:00
|
|
|
/* DESKTOP DRAWER */
|
|
|
|
<Drawer
|
|
|
|
sx={{
|
|
|
|
width: DRAWER_WIDTH,
|
|
|
|
flexShrink: 0,
|
|
|
|
'& .MuiDrawer-paper': {
|
|
|
|
width: DRAWER_WIDTH,
|
2024-04-24 00:49:53 -04:00
|
|
|
paddingBottom: '4.2rem', // Padding for now playing bar
|
2022-11-28 16:39:13 -05:00
|
|
|
boxSizing: 'border-box'
|
|
|
|
}
|
|
|
|
}}
|
2023-11-28 10:26:14 -05:00
|
|
|
variant='permanent'
|
2022-11-28 16:39:13 -05:00
|
|
|
anchor='left'
|
|
|
|
>
|
|
|
|
{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.
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Box
|
|
|
|
role='presentation'
|
|
|
|
// Close the drawer when the content is clicked
|
|
|
|
onClick={onClose}
|
|
|
|
onKeyDown={onClose}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</Box>
|
|
|
|
</SwipeableDrawer>
|
|
|
|
));
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ResponsiveDrawer;
|