-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSideNav.tsx
More file actions
36 lines (30 loc) · 952 Bytes
/
SideNav.tsx
File metadata and controls
36 lines (30 loc) · 952 Bytes
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
import * as React from "react";
import * as SideNavItem from "./SideNavItem";
type NavProps = JSX.IntrinsicElements["nav"];
interface SideNavProps extends NavProps {
items: SideNavItem.Props[];
}
interface TreeItemProps {
items: SideNavItem.Props[];
depth: number;
}
const TreeItem = (props: TreeItemProps) => {
const elements = props.items.map((itemProps, idx) => {
const childItems = itemProps.items;
const children = childItems ? <TreeItem {...{ items: childItems, depth: props.depth + 1 }} /> : undefined;
return (
<SideNavItem.Component key={`SideNavItem-${props.depth}-${idx}`} {...itemProps} depth={props.depth}>
{children}
</SideNavItem.Component>
);
});
return <>{elements}</>;
};
const SideNav = ({ items, ...props }: SideNavProps) => {
return (
<nav {...props}>
<TreeItem {...{ items, depth: 0 }} />
</nav>
);
};
export { SideNav as Component, SideNavProps as Props };