| 1 | "use client"; |
| 2 | |
| 3 | import { Settings, UserRound |
| 4 | import Link from "next/link |
| 5 | import { usePathname } |
| 6 | |
| 7 | import { cn } |
| 8 | |
| 9 | // Icons are components, which cannot cross from a server layout; the layout names one instead. |
| 10 | const icons = { |
| 11 | settings: Settings, |
| 12 | users: Users, |
| 13 | teams: UsersRound, |
| 14 | outside: UserRound, |
| 15 | }; |
| 16 | |
| 17 | export type SettingsLink |
| 18 | href: string |
| 19 | label: string |
| 20 | icon: keyof |
| 21 | }; |
| 22 | |
| 23 | export function SettingsNav({ |
| 24 | label, |
| 25 | links, |
| 26 | }: { |
| 27 | /** What the settings are for, for screen readers. */ |
| 28 | label: string |
| 29 | links: SettingsLink |
| 30 | }) { |
| 31 | const pathname = |
| 32 | |
| 33 | return ( |
| 34 | <nav |
| 35 | aria-label={label} |
| 36 | className="-mx-1 flex gap-1 overflow-x-auto md:mx-0 md:flex-col" |
| 37 | > |
| 38 | {links.map(( |
| 39 | const Icon = |
| 40 | const active = |
| 41 | return ( |
| 42 | <Link |
| 43 | key={href} |
| 44 | href={href} |
| 45 | aria-current={active ? |
| 46 | className={cn( |
| 47 | "flex items-center gap-2 whitespace-nowrap rounded-md px-3 py-2 text-sm text-muted-foreground transition-colors hover:bg-muted hover:text-foreground", |
| 48 | active && "bg-muted font-medium text-foreground" |
| 49 | )} |
| 50 | > |
| 51 | <Icon className=" |
| 52 | {label} |
| 53 | </Link> |
| 54 | ); |
| 55 | })} |
| 56 | </nav> |
| 57 | ); |
| 58 | } |