Fix sidebar positiion
This commit is contained in:
parent
da0677ca42
commit
e8a69cd9fc
2 changed files with 66 additions and 48 deletions
|
@ -1,6 +1,7 @@
|
||||||
import ClickAwayListener from "@material-ui/core/ClickAwayListener";
|
import ClickAwayListener from "@material-ui/core/ClickAwayListener";
|
||||||
import Paper from "@material-ui/core/Paper";
|
import Paper from "@material-ui/core/Paper";
|
||||||
import Popper from "@material-ui/core/Popper";
|
import Popper from "@material-ui/core/Popper";
|
||||||
|
import { fade } from "@material-ui/core/styles/colorManipulator";
|
||||||
import makeStyles from "@material-ui/core/styles/makeStyles";
|
import makeStyles from "@material-ui/core/styles/makeStyles";
|
||||||
import Typography from "@material-ui/core/Typography";
|
import Typography from "@material-ui/core/Typography";
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
|
@ -16,6 +17,9 @@ export interface MenuItemProps {
|
||||||
onClick: (url: string, event: React.MouseEvent) => void;
|
onClick: (url: string, event: React.MouseEvent) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const menuWidth = 210;
|
||||||
|
export const shrunkMenuWidth = 72;
|
||||||
|
|
||||||
const useStyles = makeStyles(
|
const useStyles = makeStyles(
|
||||||
theme => ({
|
theme => ({
|
||||||
hideLabel: {
|
hideLabel: {
|
||||||
|
@ -58,7 +62,7 @@ const useStyles = makeStyles(
|
||||||
border: "none",
|
border: "none",
|
||||||
borderBottomRightRadius: 100,
|
borderBottomRightRadius: 100,
|
||||||
borderTopRightRadius: 100,
|
borderTopRightRadius: 100,
|
||||||
color: theme.palette.text.disabled,
|
color: fade(theme.palette.text.primary, 0.6),
|
||||||
cursor: "pointer",
|
cursor: "pointer",
|
||||||
display: "flex",
|
display: "flex",
|
||||||
height: 56,
|
height: 56,
|
||||||
|
@ -66,7 +70,7 @@ const useStyles = makeStyles(
|
||||||
overflow: "hidden",
|
overflow: "hidden",
|
||||||
padding: theme.spacing(2, 3, 2, 3.5),
|
padding: theme.spacing(2, 3, 2, 3.5),
|
||||||
transition: theme.transitions.duration.shortest + "ms",
|
transition: theme.transitions.duration.shortest + "ms",
|
||||||
width: 72
|
width: shrunkMenuWidth
|
||||||
},
|
},
|
||||||
rootActive: {
|
rootActive: {
|
||||||
"&$root": {
|
"&$root": {
|
||||||
|
@ -76,7 +80,7 @@ const useStyles = makeStyles(
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
rootExpanded: {
|
rootExpanded: {
|
||||||
width: 210
|
width: menuWidth
|
||||||
},
|
},
|
||||||
subMenuLabel: {
|
subMenuLabel: {
|
||||||
"&$label": {
|
"&$label": {
|
||||||
|
@ -89,7 +93,7 @@ const useStyles = makeStyles(
|
||||||
},
|
},
|
||||||
background: "none",
|
background: "none",
|
||||||
border: "none",
|
border: "none",
|
||||||
color: theme.palette.text.disabled
|
color: fade(theme.palette.text.primary, 0.6)
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,13 +5,14 @@ import { configurationMenuUrl } from "@saleor/configuration";
|
||||||
import { User } from "@saleor/fragments/types/User";
|
import { User } from "@saleor/fragments/types/User";
|
||||||
import useLocalStorage from "@saleor/hooks/useLocalStorage";
|
import useLocalStorage from "@saleor/hooks/useLocalStorage";
|
||||||
import { sectionNames } from "@saleor/intl";
|
import { sectionNames } from "@saleor/intl";
|
||||||
|
import classNames from "classnames";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import SVG from "react-inlinesvg";
|
import SVG from "react-inlinesvg";
|
||||||
import { useIntl } from "react-intl";
|
import { useIntl } from "react-intl";
|
||||||
|
|
||||||
import { IMenuItem } from "../AppLayout/menuStructure";
|
import { IMenuItem } from "../AppLayout/menuStructure";
|
||||||
import ExpandButton from "./ExpandButton";
|
import ExpandButton from "./ExpandButton";
|
||||||
import MenuItem from "./MenuItem";
|
import MenuItem, { menuWidth, shrunkMenuWidth } from "./MenuItem";
|
||||||
import { isMenuActive } from "./utils";
|
import { isMenuActive } from "./utils";
|
||||||
|
|
||||||
const useStyles = makeStyles(
|
const useStyles = makeStyles(
|
||||||
|
@ -19,11 +20,18 @@ const useStyles = makeStyles(
|
||||||
expandButton: {
|
expandButton: {
|
||||||
marginLeft: theme.spacing(2)
|
marginLeft: theme.spacing(2)
|
||||||
},
|
},
|
||||||
|
float: {
|
||||||
|
position: "fixed"
|
||||||
|
},
|
||||||
logo: {
|
logo: {
|
||||||
margin: `36px 0 ${theme.spacing(3)}px ${theme.spacing(3)}px`
|
margin: `36px 0 ${theme.spacing(3)}px ${theme.spacing(3)}px`
|
||||||
},
|
},
|
||||||
root: {
|
root: {
|
||||||
transition: "width 0.5s ease"
|
transition: "width 0.5s ease",
|
||||||
|
width: menuWidth
|
||||||
|
},
|
||||||
|
rootShrink: {
|
||||||
|
width: shrunkMenuWidth
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
|
@ -57,55 +65,61 @@ const SideBar: React.FC<SideBarProps> = ({
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classes.root}>
|
<div
|
||||||
<div className={classes.logo}>
|
className={classNames(classes.root, {
|
||||||
<SVG src={logoLight} />
|
[classes.rootShrink]: isShrunk
|
||||||
</div>
|
})}
|
||||||
{menuItems.map(menuItem => {
|
>
|
||||||
const isActive = isMenuActive(location, menuItem);
|
<div className={classes.float}>
|
||||||
|
<div className={classes.logo}>
|
||||||
|
<SVG src={logoLight} />
|
||||||
|
</div>
|
||||||
|
{menuItems.map(menuItem => {
|
||||||
|
const isActive = isMenuActive(location, menuItem);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
menuItem.permission &&
|
menuItem.permission &&
|
||||||
!user.userPermissions
|
!user.userPermissions
|
||||||
.map(perm => perm.code)
|
.map(perm => perm.code)
|
||||||
.includes(menuItem.permission)
|
.includes(menuItem.permission)
|
||||||
) {
|
) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<MenuItem
|
||||||
|
active={isActive}
|
||||||
|
isMenuShrunk={isShrunk}
|
||||||
|
menuItem={menuItem}
|
||||||
|
onClick={onMenuItemClick}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
{renderConfigure && (
|
||||||
<MenuItem
|
<MenuItem
|
||||||
active={isActive}
|
active={
|
||||||
|
!menuItems.reduce(
|
||||||
|
(acc, menuItem) => acc || isMenuActive(location, menuItem),
|
||||||
|
false
|
||||||
|
)
|
||||||
|
}
|
||||||
isMenuShrunk={isShrunk}
|
isMenuShrunk={isShrunk}
|
||||||
menuItem={menuItem}
|
menuItem={{
|
||||||
|
ariaLabel: "configure",
|
||||||
|
icon: configurationIcon,
|
||||||
|
label: intl.formatMessage(sectionNames.configuration),
|
||||||
|
testingContextId: "configure",
|
||||||
|
url: configurationMenuUrl
|
||||||
|
}}
|
||||||
onClick={onMenuItemClick}
|
onClick={onMenuItemClick}
|
||||||
/>
|
/>
|
||||||
);
|
)}
|
||||||
})}
|
<ExpandButton
|
||||||
{renderConfigure && (
|
className={classes.expandButton}
|
||||||
<MenuItem
|
isShrunk={isShrunk}
|
||||||
active={
|
onClick={() => setShrink(!isShrunk)}
|
||||||
!menuItems.reduce(
|
|
||||||
(acc, menuItem) => acc || isMenuActive(location, menuItem),
|
|
||||||
false
|
|
||||||
)
|
|
||||||
}
|
|
||||||
isMenuShrunk={isShrunk}
|
|
||||||
menuItem={{
|
|
||||||
ariaLabel: "configure",
|
|
||||||
icon: configurationIcon,
|
|
||||||
label: intl.formatMessage(sectionNames.configuration),
|
|
||||||
testingContextId: "configure",
|
|
||||||
url: configurationMenuUrl
|
|
||||||
}}
|
|
||||||
onClick={onMenuItemClick}
|
|
||||||
/>
|
/>
|
||||||
)}
|
</div>
|
||||||
<ExpandButton
|
|
||||||
className={classes.expandButton}
|
|
||||||
isShrunk={isShrunk}
|
|
||||||
onClick={() => setShrink(!isShrunk)}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue