diff --git a/src/layouts/default.tsx b/src/layouts/default.tsx index f76bd13..9e39d56 100644 --- a/src/layouts/default.tsx +++ b/src/layouts/default.tsx @@ -1,10 +1,10 @@ import React, { FC } from "react"; import clsx from "clsx"; -import { useTheme, Theme } from "@mui/material/styles"; -import createStyles from '@mui/styles/createStyles'; -import makeStyles from '@mui/styles/makeStyles'; +import { useTheme, Theme, CSSObject, styled } from "@mui/material/styles"; +import createStyles from "@mui/styles/createStyles"; +import makeStyles from "@mui/styles/makeStyles"; import Drawer from "@mui/material/Drawer"; -import AppBar from "@mui/material/AppBar"; +import AppBar, { AppBarProps } from "@mui/material/AppBar"; import Toolbar from "@mui/material/Toolbar"; import List from "@mui/material/List"; import CssBaseline from "@mui/material/CssBaseline"; @@ -17,76 +17,83 @@ import ChevronRightIcon from "@mui/icons-material/ChevronRight"; import ListItem from "@mui/material/ListItem"; import ListItemIcon from "@mui/material/ListItemIcon"; import ListItemText from "@mui/material/ListItemText"; -import { AddCircle, Description, LocalOffer } from '@mui/icons-material'; -import { Link } from '@curi/react-dom'; +import { AddCircle, Description, LocalOffer } from "@mui/icons-material"; +import { Link } from "@curi/react-dom"; +import { Box } from "@mui/system"; const drawerWidth = 240; -const useStyles = makeStyles((theme: Theme) => - createStyles({ - root: { - display: "flex", - }, - appBar: { - zIndex: theme.zIndex.drawer + 1, - transition: theme.transitions.create(["width", "margin"], { - easing: theme.transitions.easing.sharp, - duration: theme.transitions.duration.leavingScreen, - }), - }, - appBarShift: { - marginLeft: drawerWidth, - width: `calc(100% - ${drawerWidth}px)`, - transition: theme.transitions.create(["width", "margin"], { - easing: theme.transitions.easing.sharp, - duration: theme.transitions.duration.enteringScreen, - }), - }, - menuButton: { - marginRight: 36, - }, - hide: { - display: "none", - }, - drawer: { - width: drawerWidth, - flexShrink: 0, - whiteSpace: "nowrap", - }, - drawerOpen: { - width: drawerWidth, - transition: theme.transitions.create("width", { - easing: theme.transitions.easing.sharp, - duration: theme.transitions.duration.enteringScreen, - }), - }, - drawerClose: { - transition: theme.transitions.create("width", { - easing: theme.transitions.easing.sharp, - duration: theme.transitions.duration.leavingScreen, - }), - overflowX: "hidden", - width: theme.spacing(7) + 1, - [theme.breakpoints.up("sm")]: { - width: theme.spacing(9) + 1, - }, - }, - toolbar: { - display: "flex", - alignItems: "center", - justifyContent: "flex-end", - padding: theme.spacing(0, 1), - // necessary for content to be below app bar - ...theme.mixins.toolbar, - }, - content: { - flexGrow: 1, - padding: theme.spacing(3), - }, - }) -); +const openedMixin = (theme: Theme): CSSObject => ({ + width: drawerWidth, + transition: theme.transitions.create("width", { + easing: theme.transitions.easing.sharp, + duration: theme.transitions.duration.enteringScreen, + }), + overflowX: "hidden", +}); -export const DefaultLayout: FC = ({children}) => { - const classes = useStyles(); +const closedMixin = (theme: Theme): CSSObject => ({ + transition: theme.transitions.create("width", { + easing: theme.transitions.easing.sharp, + duration: theme.transitions.duration.leavingScreen, + }), + overflowX: "hidden", + width: `calc(${theme.spacing(7)} + 1px)`, +}); + +const DrawerHeader = styled("div")(({ theme }) => ({ + display: "flex", + alignItems: "center", + justifyContent: "flex-end", + padding: theme.spacing(0, 1), + // necessary for content to be below app bar + ...theme.mixins.toolbar, +})); + +const Main = styled("main")(({ theme }) => ({ + padding: theme.spacing(2, 2), + [theme.breakpoints.up("md")]: { + padding: theme.spacing(4, 3), + }, + width: "100%", + marginTop: theme.mixins.toolbar.minHeight, +})); + +const StyledAppBar = styled(AppBar, { + shouldForwardProp: (prop) => prop !== "open", +})(({ theme, open }) => ({ + zIndex: theme.zIndex.drawer + 1, + transition: theme.transitions.create(["width", "margin"], { + easing: theme.transitions.easing.sharp, + duration: theme.transitions.duration.leavingScreen, + }), + ...(open && { + marginLeft: drawerWidth, + width: `calc(100% - ${drawerWidth}px)`, + transition: theme.transitions.create(["width", "margin"], { + easing: theme.transitions.easing.sharp, + duration: theme.transitions.duration.enteringScreen, + }), + }), +})); + +const StyledDrawer = styled(Drawer, { + shouldForwardProp: (prop) => prop !== "open", +})(({ theme, open }) => ({ + width: drawerWidth, + flexShrink: 0, + whiteSpace: "nowrap", + boxSizing: "border-box", + ...(open && { + ...openedMixin(theme), + "& .MuiDrawer-paper": openedMixin(theme), + }), + ...(!open && { + ...closedMixin(theme), + "& .MuiDrawer-paper": closedMixin(theme), + }), +})); + +export const DefaultLayout: FC = ({ children }) => { const theme = useTheme(); const [open, setOpen] = React.useState(false); @@ -99,86 +106,68 @@ export const DefaultLayout: FC = ({children}) => { }; return ( -
- - - - - - - - Mini variant drawer - - - - -
- - {theme.direction === "rtl" ? ( - - ) : ( - - )} - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-
- { children } -
-
+ + + + + + + + + Mini variant drawer + + + + + + + {theme.direction === "rtl" ? ( + + ) : ( + + )} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{children}
+
); -} +};