This repository was archived by the owner on Feb 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSideNav.tsx
69 lines (63 loc) · 1.66 KB
/
SideNav.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
65
66
67
68
69
"use client";
import { tv } from "tailwind-variants";
import { AccordionItem, NavItem, InternalSideNavProps } from "@/components/SideNav";
import { cn } from "@/lib/utils";
/**
* Tailwind variants for side navigation hover states
*/
export const sideNavVariants = tv({
variants: {
hover: {
white: "hover:bg-white",
grey: "hover:bg-grey-50",
black: "hover:bg-black",
},
},
defaultVariants: {
hover: "white",
},
});
/**
* Renders a recursive side navigation component with support for nested items and accordions.
* @param props InternalSideNavProps
* @returns React component
*/
export const SideNav = ({
items,
className,
hoverVariant = "grey",
accordionProps,
isRecursive = false,
onClick,
activeId,
}: InternalSideNavProps) => {
const hoverVariantClass = sideNavVariants({ hover: hoverVariant });
return (
<div className={cn("relative flex flex-col gap-4", className)}>
{items?.map((item, index) => {
const isActive = item.id === activeId;
return (
<div key={`sidenav-item-${index}`}>
{item.items && item.items.length > 0 ? (
<AccordionItem
item={item}
onClick={onClick}
hoverVariant={hoverVariant}
accordionProps={accordionProps}
activeId={activeId}
/>
) : (
<NavItem
item={item}
isRecursive={isRecursive}
hoverVariantClass={hoverVariantClass}
onClick={onClick}
isActive={isActive}
/>
)}
</div>
);
})}
</div>
);
};