Skip to content

Commit

Permalink
Toggle drawer
Browse files Browse the repository at this point in the history
  • Loading branch information
jcardus committed Nov 14, 2024
1 parent 62f6da1 commit 15b0e38
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
28 changes: 23 additions & 5 deletions src/common/components/PageLayout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
} from '@mui/material';
import makeStyles from '@mui/styles/makeStyles';
import ArrowBackIcon from '@mui/icons-material/ArrowBack';
import ChevronLeftIcon from '@mui/icons-material/ChevronLeft';
import ChevronRightIcon from '@mui/icons-material/ChevronRight';
import MenuIcon from '@mui/icons-material/Menu';
import { useNavigate } from 'react-router-dom';
import { useTranslation } from './LocalizationProvider';
Expand All @@ -27,7 +29,11 @@ const useStyles = makeStyles((theme) => ({
flexDirection: 'column',
},
desktopDrawer: {
width: theme.dimensions.drawerWidthDesktop,
width: (props) => (props.miniVariant ? theme.dimensions.miniDrawerWidthDesktop : theme.dimensions.drawerWidthDesktop),
transition: theme.transitions.create('width', {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.enteringScreen,
}),
},
mobileDrawer: {
width: theme.dimensions.drawerWidthTablet,
Expand Down Expand Up @@ -66,14 +72,19 @@ const PageTitle = ({ breadcrumbs }) => {
};

const PageLayout = ({ menu, breadcrumbs, children }) => {
const classes = useStyles();
const [miniVariant, setMiniVariant] = useState(false);
const classes = useStyles({ miniVariant });
const theme = useTheme();
const navigate = useNavigate();

const desktop = useMediaQuery(theme.breakpoints.up('md'));

const [openDrawer, setOpenDrawer] = useState(false);

const toggleDrawer = () => {
setMiniVariant(!miniVariant);
};

return desktop ? (
<div className={classes.desktopRoot}>
<Drawer
Expand All @@ -82,10 +93,17 @@ const PageLayout = ({ menu, breadcrumbs, children }) => {
classes={{ paper: classes.desktopDrawer }}
>
<Toolbar>
<IconButton color="inherit" edge="start" sx={{ mr: 2 }} onClick={() => navigate('/')}>
<ArrowBackIcon />
{!miniVariant && (
<>
<IconButton color="inherit" edge="start" sx={{ mr: 2 }} onClick={() => navigate('/')}>
<ArrowBackIcon />
</IconButton>
<PageTitle breadcrumbs={breadcrumbs} />
</>
)}
<IconButton color="inherit" edge="start" sx={{ ml: miniVariant ? -2 : 'auto' }} onClick={toggleDrawer}>
{miniVariant ? <ChevronRightIcon /> : <ChevronLeftIcon />}
</IconButton>
<PageTitle breadcrumbs={breadcrumbs} />
</Toolbar>
<Divider />
{menu}
Expand Down
1 change: 1 addition & 0 deletions src/common/theme/dimensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export default {
sidebarWidth: '28%',
sidebarWidthTablet: '52px',
drawerWidthDesktop: '360px',
miniDrawerWidthDesktop: '56px',
drawerWidthTablet: '320px',
drawerHeightPhone: '250px',
filterFormWidth: '160px',
Expand Down
2 changes: 1 addition & 1 deletion src/reports/components/ReportsMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const MenuItem = ({
}) => (
<ListItemButton key={link} component={Link} to={link} selected={selected}>
<ListItemIcon>{icon}</ListItemIcon>
<ListItemText primary={title} />
<ListItemText primary={title} sx={{ whiteSpace: 'nowrap' }} />
</ListItemButton>
);

Expand Down
2 changes: 1 addition & 1 deletion src/settings/components/SettingsMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const MenuItem = ({
}) => (
<ListItemButton key={link} component={Link} to={link} selected={selected}>
<ListItemIcon>{icon}</ListItemIcon>
<ListItemText primary={title} />
<ListItemText primary={title} sx={{ whiteSpace: 'nowrap' }} />
</ListItemButton>
);

Expand Down

0 comments on commit 15b0e38

Please sign in to comment.