-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdashboard-nav.tsx
91 lines (86 loc) · 2.84 KB
/
dashboard-nav.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import Link from "next/link";
import { usePathname } from "next/navigation";
import { Icons } from "@/components/icons";
import { cn } from "@/lib/utils";
import { NavItem } from "@/types";
import { Dispatch, SetStateAction } from "react";
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "@/components/ui/tooltip";
interface DashboardNavProps {
items: NavItem[];
setOpen?: Dispatch<SetStateAction<boolean>>;
isCollapsed?: boolean; // Make it optional
}
export function DashboardNav({
items,
setOpen,
isCollapsed,
}: DashboardNavProps) {
const path = usePathname();
if (!items?.length) {
return null;
}
return (
<TooltipProvider delayDuration={50}>
<nav className="grid items-start gap-2">
{items.map((item, index) => {
const Icon = Icons[item.icon || "arrowRight"];
const isHome = item.href === "/dashboard" && path === "/dashboard";
const isActive =
item.href !== "/dashboard" && path.startsWith(item.href ?? "");
const link = (
<Link
key={index}
href={item.disabled ? "/" : item.href!} // Use the non-null assertion operator here
onClick={() => setOpen?.(false)}
>
<span
className={cn(
"text-muted-foreground group flex items-center rounded-md px-3 py-2 text-sm font-medium hover:bg-primary/10",
isHome || isActive
? "text-secondary bg-primary hover:bg-primary rounded-md justify-start"
: "transparent",
item.disabled && "cursor-not-allowed opacity-80"
)}
>
<Icon className="icon-element h-5 w-4" />
{isCollapsed ? null : (
<span className="text-element ml-2 h-5">{item.title}</span>
)}
{isCollapsed
? null
: item.count && (
<span className="text-element ml-auto text-xs font-semibold">
{item.count}
</span>
)}
{isCollapsed
? null
: item.tag && (
<span className="text-element ml-auto bg-[#50e3c1] text-black text-xs px-2 rounded-md">
{item.tag}
</span>
)}
</span>
</Link>
);
return (
item.href &&
(isCollapsed ? (
<Tooltip key={index}>
<TooltipTrigger asChild>{link}</TooltipTrigger>
<TooltipContent side="right">{item.title}</TooltipContent>
</Tooltip>
) : (
link
))
);
})}
</nav>
</TooltipProvider>
);
}