forked from module-federation/module-federation-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppDrawer.js
More file actions
105 lines (98 loc) · 2.39 KB
/
AppDrawer.js
File metadata and controls
105 lines (98 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import React from "react";
import {
makeStyles,
Divider,
Drawer,
IconButton,
List,
ListItem,
ListItemIcon,
ListItemText,
} from "@material-ui/core";
import {
ChevronLeft as ChevronLeftIcon,
Dashboard as DashboardIcon,
ShoppingCart as ShoppingCartIcon,
Person as UserIcon,
} from "@material-ui/icons";
import clsx from "clsx";
import { Link, useMatch } from "react-router-dom";
const useStyles = makeStyles((theme) => ({
toolbarIcon: {
display: "flex",
alignItems: "center",
justifyContent: "flex-end",
padding: "0 8px",
...theme.mixins.toolbar,
},
drawerPaper: {
position: "relative",
whiteSpace: "nowrap",
width: 240,
transition: theme.transitions.create("width", {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.enteringScreen,
}),
},
drawerPaperClose: {
overflowX: "hidden",
transition: theme.transitions.create("width", {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.leavingScreen,
}),
width: theme.spacing(7),
[theme.breakpoints.up("sm")]: {
width: theme.spacing(9),
},
},
}));
function ListItemLink(props) {
const selected = useMatch(props.to);
const CustomLink = React.useMemo(
() =>
React.forwardRef((linkProps, ref) => (
<Link ref={ref} to={props.to} {...linkProps} />
)),
[props.to]
);
return (
<li>
<ListItem selected={selected} button component={CustomLink}>
<ListItemIcon>{props.icon}</ListItemIcon>
<ListItemText primary={props.text} />
</ListItem>
</li>
);
}
function Menu() {
return (
<List>
<ListItemLink to="dashboard" icon={<DashboardIcon />} text="Dashboard" />
<ListItemLink to="orders" icon={<ShoppingCartIcon />} text="Orders" />
<ListItemLink to="profile" icon={<UserIcon />} text="Profile" />
</List>
);
}
export default function AppDrawer(props) {
const classes = useStyles();
return (
<Drawer
variant="permanent"
classes={{
paper: clsx(
classes.drawerPaper,
!props.drawer.open && classes.drawerPaperClose
),
}}
open={props.open}
>
<div className={classes.toolbarIcon}>
<IconButton onClick={props.drawer.closeDrawer}>
<ChevronLeftIcon />
</IconButton>
</div>
<Divider />
<Menu />
</Drawer>
);
}