1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/src/components/ResponsiveDrawer.tsx

69 lines
1.9 KiB
TypeScript
Raw Normal View History

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';
2024-06-02 20:58:11 +03:00
import React, { type FC, type PropsWithChildren } from 'react';
2022-11-28 16:39:13 -05:00
import browser from 'scripts/browser';
export const DRAWER_WIDTH = 240;
2022-11-28 16:39:13 -05:00
export interface ResponsiveDrawerProps {
open: boolean
onClose: () => void
onOpen: () => void
}
2024-06-02 20:58:11 +03:00
const ResponsiveDrawer: FC<PropsWithChildren<ResponsiveDrawerProps>> = ({
2022-11-28 16:39:13 -05:00
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,
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;