|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import Link from 'next/link'; |
| 4 | +import { LucideIcon } from 'lucide-react'; |
| 5 | + |
| 6 | +import { cn } from '@/lib/utils'; |
| 7 | +import { Tooltip, TooltipContent, TooltipTrigger } from './tooltip'; |
| 8 | +import { buttonVariants } from './button'; |
| 9 | + |
| 10 | +interface NavProps { |
| 11 | + isCollapsed: boolean; |
| 12 | + links: { |
| 13 | + title: string; |
| 14 | + label?: string; |
| 15 | + icon: LucideIcon; |
| 16 | + variant: 'default' | 'ghost'; |
| 17 | + }[]; |
| 18 | +} |
| 19 | + |
| 20 | +export function Nav({ links, isCollapsed }: NavProps) { |
| 21 | + return ( |
| 22 | + <div data-collapsed={isCollapsed} className="group flex flex-col gap-4 py-2 data-[collapsed=true]:py-2"> |
| 23 | + <nav className="grid gap-1 px-2 group-[[data-collapsed=true]]:justify-center group-[[data-collapsed=true]]:px-2"> |
| 24 | + {links.map((link, index) => |
| 25 | + isCollapsed ? ( |
| 26 | + <Tooltip key={index} delayDuration={0}> |
| 27 | + <TooltipTrigger asChild> |
| 28 | + <Link |
| 29 | + href="#" |
| 30 | + className={cn( |
| 31 | + buttonVariants({ variant: link.variant, size: 'icon' }), |
| 32 | + 'h-9 w-9', |
| 33 | + link.variant === 'default' && |
| 34 | + 'dark:bg-muted dark:text-muted-foreground dark:hover:bg-muted dark:hover:text-white', |
| 35 | + )} |
| 36 | + > |
| 37 | + <link.icon className="h-4 w-4" /> |
| 38 | + <span className="sr-only">{link.title}</span> |
| 39 | + </Link> |
| 40 | + </TooltipTrigger> |
| 41 | + <TooltipContent side="right" className="flex items-center gap-4"> |
| 42 | + {link.title} |
| 43 | + {link.label && <span className="ml-auto text-muted-foreground">{link.label}</span>} |
| 44 | + </TooltipContent> |
| 45 | + </Tooltip> |
| 46 | + ) : ( |
| 47 | + <Link |
| 48 | + key={index} |
| 49 | + href="#" |
| 50 | + className={cn( |
| 51 | + buttonVariants({ variant: link.variant, size: 'sm' }), |
| 52 | + link.variant === 'default' && 'dark:bg-muted dark:text-white dark:hover:bg-muted dark:hover:text-white', |
| 53 | + 'justify-start', |
| 54 | + )} |
| 55 | + > |
| 56 | + <link.icon className="mr-2 h-4 w-4" /> |
| 57 | + {link.title} |
| 58 | + {link.label && ( |
| 59 | + <span className={cn('ml-auto', link.variant === 'default' && 'text-background dark:text-white')}> |
| 60 | + {link.label} |
| 61 | + </span> |
| 62 | + )} |
| 63 | + </Link> |
| 64 | + ), |
| 65 | + )} |
| 66 | + </nav> |
| 67 | + </div> |
| 68 | + ); |
| 69 | +} |
0 commit comments