| 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 | webhooks: Webhook, |
| 16 | }; |
| 17 | |
| 18 | export type SettingsLink |
| 19 | href: string |
| 20 | label: string |
| 21 | icon: keyof |
| 22 | }; |
| 23 | |
| 24 | export function SettingsNav({ |
| 25 | label, |
| 26 | links, |
| 27 | }: { |
| 28 | /** What the settings are for, for screen readers. */ |
| 29 | label: string |
| 30 | links: SettingsLink |
| 31 | }) { |
| 32 | const pathname = |
| 33 | |
| 34 | return ( |
| 35 | <nav |
| 36 | aria-label={label} |
| 37 | className="-mx-1 flex gap-1 overflow-x-auto md:mx-0 md:flex-col" |
| 38 | > |
| 39 | {links.map(( |
| 40 | const Icon = |
| 41 | // A nested page, such as one webhook, lights up its section; the first link is the parent of every section. |
| 42 | const active = |
| 43 | pathname === href |
| 44 | (href !== links[ |
| 45 | return ( |
| 46 | <Link |
| 47 | key={href} |
| 48 | href={href} |
| 49 | aria-current={active ? |
| 50 | className={cn( |
| 51 | "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", |
| 52 | active && "bg-muted font-medium text-foreground" |
| 53 | )} |
| 54 | > |
| 55 | <Icon className=" |
| 56 | {label} |
| 57 | </Link> |
| 58 | ); |
| 59 | })} |
| 60 | </nav> |
| 61 | ); |
| 62 | } |