-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSideNav.tsx
More file actions
108 lines (103 loc) · 2.26 KB
/
Copy pathSideNav.tsx
File metadata and controls
108 lines (103 loc) · 2.26 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
106
107
108
import {
Box,
Divider,
Drawer,
List,
ListItem,
ListItemButton,
ListItemIcon,
ListItemText,
Toolbar,
Tooltip,
} from "@mui/material";
import { NavLink } from "react-router-dom";
import type { Section, SectionGroup } from "./Router";
import type React from "react";
import { Fragment } from "react";
interface SideNavProps {
navigation: SectionGroup[];
open: boolean;
}
export function SideNav({ navigation, open }: SideNavProps) {
const width = open ? 256 : 72;
return (
<Drawer
variant="permanent"
sx={{
width: width,
flexShrink: 0,
[`& .MuiDrawer-paper`]: {
width: width,
boxSizing: "border-box",
},
}}
>
<Toolbar /> {/* spacer equal to the AppBar's height*/}
<Box sx={{ overflow: "auto" }}>
<List
sx={{
p: 1,
flexDirection: "column",
}}
>
{navigation.map((group, groupIndex) => (
<Fragment key={groupIndex}>
{groupIndex > 0 && <Divider />}
{group.sections.map((route) => (
<Entry key={route.path} route={route} open={open} />
))}
</Fragment>
))}
</List>
</Box>
</Drawer>
);
}
interface EntryProps {
route: Section;
open: boolean;
}
function Entry(props: EntryProps) {
const route = props.route;
const icon = (
<ListItemIcon
sx={{
minWidth: 0,
mr: 2,
}}
>
{route.icon}
</ListItemIcon>
);
return (
<ListItem disablePadding>
<ListItemButton
component={NavLink as React.ElementType}
to={route.path}
sx={{
"&.active": {
bgcolor: "action.selected",
},
}}
aria-label={route.name}
>
{props.open ? (
icon
) : (
<Tooltip title={route.name} placement="right">
{icon}
</Tooltip>
)}
<ListItemText // always render but conditionally hide
primary={route.name}
sx={{
opacity: props.open ? 1 : 0,
width: props.open ? "auto" : 0,
overflow: "hidden",
transition: "0.2s",
}}
/>
</ListItemButton>
</ListItem>
);
}