-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
Copy pathnavigation.tsx
64 lines (59 loc) · 1.42 KB
/
navigation.tsx
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
/* SPDX-FileCopyrightText: 2014-present Kriasoft */
/* SPDX-License-Identifier: MIT */
import {
AssignmentTurnedInRounded,
ChatRounded,
Dashboard,
} from "@mui/icons-material";
import {
List,
ListItem,
ListItemButton,
ListItemContent,
ListItemDecorator,
ListProps,
} from "@mui/joy";
import { ReactNode, memo } from "react";
import { Link, useMatch } from "react-router-dom";
export const Navigation = memo(function Navigation(
props: NavigationProps,
): JSX.Element {
const { sx, ...other } = props;
return (
<List
sx={{ "--ListItem-radius": "4px", ...sx }}
size="sm"
role="navigation"
{...other}
>
<NavItem path="/dashboard" label="Dashboard" icon={<Dashboard />} />
<NavItem
path="/tasks"
label="Tasks"
icon={<AssignmentTurnedInRounded />}
/>
<NavItem path="/messages" label="Messages" icon={<ChatRounded />} />
</List>
);
});
function NavItem(props: NavItemProps): JSX.Element {
return (
<ListItem>
<ListItemButton
component={Link}
selected={!!useMatch(props.path)}
to={props.path}
aria-current="page"
>
<ListItemDecorator children={props.icon} />
<ListItemContent>{props.label}</ListItemContent>
</ListItemButton>
</ListItem>
);
}
type NavigationProps = Omit<ListProps, "children">;
type NavItemProps = {
path: string;
label: string;
icon: ReactNode;
};