-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize drawer width to reduce wasted space in reports and settings #1295
Changes from 4 commits
15b0e38
547dafb
f4cef90
736f6fd
5e2b79a
9161274
613e7ec
21e598e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
|
@@ -27,7 +29,11 @@ const useStyles = makeStyles((theme) => ({ | |
flexDirection: 'column', | ||
}, | ||
desktopDrawer: { | ||
width: theme.dimensions.drawerWidthDesktop, | ||
width: (props) => (props.miniVariant ? `calc(${theme.spacing(7)} + 1px)` : theme.dimensions.drawerWidthDesktop), | ||
transition: theme.transitions.create('width', { | ||
easing: theme.transitions.easing.sharp, | ||
duration: theme.transitions.duration.enteringScreen, | ||
}), | ||
}, | ||
mobileDrawer: { | ||
width: theme.dimensions.drawerWidthTablet, | ||
|
@@ -66,14 +72,17 @@ 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 | ||
|
@@ -82,10 +91,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}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this needs to be reformatted. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. which part? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. got it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should probably apply classes here as well for readability. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I followed the same pattern as the upper IconButton |
||
{miniVariant ? <ChevronRightIcon /> : <ChevronLeftIcon />} | ||
</IconButton> | ||
<PageTitle breadcrumbs={breadcrumbs} /> | ||
</Toolbar> | ||
<Divider /> | ||
{menu} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,20 +17,30 @@ import HelpIcon from '@mui/icons-material/Help'; | |
import CampaignIcon from '@mui/icons-material/Campaign'; | ||
import { Link, useLocation } from 'react-router-dom'; | ||
import { useSelector } from 'react-redux'; | ||
import makeStyles from '@mui/styles/makeStyles'; | ||
import { useTranslation } from '../../common/components/LocalizationProvider'; | ||
import { | ||
useAdministrator, useManager, useRestriction, | ||
} from '../../common/util/permissions'; | ||
import useFeatures from '../../common/util/useFeatures'; | ||
|
||
const useStyles = makeStyles({ | ||
menuItemText: { | ||
whiteSpace: 'nowrap', | ||
}, | ||
}); | ||
|
||
const MenuItem = ({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can extract it as a common component to avoid duplication? |
||
title, link, icon, selected, | ||
}) => ( | ||
<ListItemButton key={link} component={Link} to={link} selected={selected}> | ||
<ListItemIcon>{icon}</ListItemIcon> | ||
<ListItemText primary={title} /> | ||
</ListItemButton> | ||
); | ||
}) => { | ||
const classes = useStyles(); | ||
return ( | ||
<ListItemButton key={link} component={Link} to={link} selected={selected}> | ||
<ListItemIcon>{icon}</ListItemIcon> | ||
<ListItemText primary={title} className={classes.menuItemText} /> | ||
</ListItemButton> | ||
); | ||
}; | ||
|
||
const SettingsMenu = () => { | ||
const t = useTranslation(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
calc(${theme.spacing(7)} + 1px)
doesn't seem right. I know there is a version of a collapsed sidebar. Can we somehow use the size from there?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe even use it as is instead of implementing our own thing.
https://mui.com/material-ui/react-drawer/#mini-variant-drawer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's exactly where that was taken from
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But can we re-use the component instead of just copy-pasting the style?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not a component, it's an example how to do the mini variant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I didn't realize that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I used the size they use for small screens (spacing(7)) in the example because using the other (spacing(8)) our icons wouldn't be centered. To use the mui example we should use spacing(8). Here's the difference:
using 7:
using 8: