generated from plutack/nextjsauth-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdashboard-nav.tsx
77 lines (73 loc) · 2.29 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
'use client';
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 { useSidebar } from '@/hooks/useSidebar';
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger
} from '@/components/ui/tooltip';
interface DashboardNavProps {
items: NavItem[];
setOpen?: Dispatch<SetStateAction<boolean>>;
isMobileNav?: boolean;
}
export function DashboardNav({
items,
setOpen,
isMobileNav = false
}: DashboardNavProps) {
const path = usePathname();
const { isMinimized } = useSidebar();
if (!items?.length) {
return null;
}
return (
<nav className="grid items-start gap-2">
<TooltipProvider>
{items.map((item, index) => {
const Icon = Icons[item.icon || 'arrowRight'];
return (
item.href && (
<Tooltip key={index}>
<TooltipTrigger asChild>
<Link
href={item.disabled ? '/' : item.href}
className={cn(
'flex items-center gap-2 overflow-hidden rounded-md py-2 text-sm font-medium hover:bg-accent hover:text-accent-foreground',
path === item.href ? 'bg-accent' : 'transparent',
item.disabled && 'cursor-not-allowed opacity-80'
)}
onClick={() => {
if (setOpen) setOpen(false);
}}
>
<Icon className={`ml-3 size-5 flex-none`} />
{isMobileNav || (!isMinimized && !isMobileNav) ? (
<span className="mr-2 truncate">{item.title}</span>
) : (
''
)}
</Link>
</TooltipTrigger>
<TooltipContent
align="center"
side="right"
sideOffset={8}
className={!isMinimized ? 'hidden' : 'inline-block'}
>
{item.title}
</TooltipContent>
</Tooltip>
)
);
})}
</TooltipProvider>
</nav>
);
}