Skip to content

Commit

Permalink
feat: replace drawer with slide to prevent content being under header
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-Torrent committed Sep 27, 2021
1 parent b10a887 commit 8b704d4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 55 deletions.
75 changes: 22 additions & 53 deletions src/components/common/PinnedItems.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from 'react';
import clsx from 'clsx';
import PropTypes from 'prop-types'
import { makeStyles, useTheme } from '@material-ui/core/styles';
import Drawer from '@material-ui/core/Drawer';
import { Box, Slide } from '@material-ui/core';
import IconButton from '@material-ui/core/IconButton';
import MenuIcon from '@material-ui/icons/Menu';
import VisibilityIcon from '@material-ui/icons/Visibility';
import ChevronLeftIcon from '@material-ui/icons/ChevronLeft';
import ChevronRightIcon from '@material-ui/icons/ChevronRight';

Expand All @@ -13,39 +14,14 @@ const useStyles = makeStyles((theme) => ({
root: {
display: 'flex',
},
appBar: {
transition: theme.transitions.create(['margin', 'width'], {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.leavingScreen,
}),
},
appBarShift: {
width: `calc(100% - ${drawerWidth}px)`,
transition: theme.transitions.create(['margin', 'width'], {
easing: theme.transitions.easing.easeOut,
duration: theme.transitions.duration.enteringScreen,
}),
marginRight: drawerWidth,
},
title: {
flexGrow: 1,
},
hide: {
display: 'none',
},
drawer: {
width: drawerWidth,
flexShrink: 0,
},
drawerPaper: {
width: drawerWidth,
},
drawerHeader: {
display: 'flex',
alignItems: 'center',
padding: theme.spacing(0, 1),
// necessary for content to be below app bar
...theme.mixins.toolbar,
justifyContent: 'flex-start',
},
content: {
Expand All @@ -55,7 +31,6 @@ const useStyles = makeStyles((theme) => ({
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.leavingScreen,
}),
marginRight: -drawerWidth,
},
contentShift: {
transition: theme.transitions.create('margin', {
Expand All @@ -66,8 +41,7 @@ const useStyles = makeStyles((theme) => ({
},
}));

// eslint-disable-next-line react/prop-types
export default function PersistentDrawerRight({ children, content }) {
export default function PersistentDrawerRight({ children, sideContent }) {
const classes = useStyles();
const theme = useTheme();
const [open, setOpen] = React.useState(false);
Expand All @@ -80,6 +54,7 @@ export default function PersistentDrawerRight({ children, content }) {
setOpen(false);
};


return (
<div className={classes.root}>
<main
Expand All @@ -93,35 +68,29 @@ export default function PersistentDrawerRight({ children, content }) {
edge="end"
onClick={handleDrawerOpen}
>
<MenuIcon />
<VisibilityIcon />
</IconButton>

<div className={classes.drawerHeader} />
{content}
{children}
</main>
<Drawer
className={classes.drawer}
variant="persistent"
anchor="right"
open={open}
classes={{
paper: classes.drawerPaper,
}}
>
<div className={classes.drawerHeader}>
<IconButton onClick={handleDrawerClose}>
{theme.direction === 'rtl' ? <ChevronLeftIcon /> : <ChevronRightIcon />}
</IconButton>
</div>

<div className={classes.drawerHeader}>
<IconButton onClick={handleDrawerClose}>
{theme.direction === 'rtl' ? <ChevronLeftIcon /> : <ChevronRightIcon />}
</IconButton>
</div>
<Slide anchor="right" direction="left" in={open} mountOnEnter unmountOnExit>
<Box className={classes.drawer}>
<div className={classes.drawerHeader}>
<IconButton onClick={handleDrawerClose}>
{theme.direction === 'rtl' ? <ChevronLeftIcon /> : <ChevronRightIcon />}
</IconButton>
</div>

{children}
</Drawer>
{sideContent}
</Box>
</Slide>
</div>
);
}

PersistentDrawerRight.propTypes = {
children: PropTypes.arrayOf(PropTypes.element).isRequired,
sideContent: PropTypes.arrayOf(PropTypes.element).isRequired,
}
4 changes: 2 additions & 2 deletions src/components/main/MainScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ const MainScreen = () => {
headerLeftContent={leftContent}
headerRightContent={<HeaderRightContent id={mainId} />}
>
<PinnedItems content={content}>
<Item id={parentId} pinnedOnly />
<PinnedItems sideContent={<Item id={parentId} pinnedOnly />}>
{content}
</PinnedItems>
</Main>
);
Expand Down

0 comments on commit 8b704d4

Please sign in to comment.