Main Navigation
nswds-ui/main-navFreeComponent
The full-width NSW site navigation bar with mega-menu panels, current-page marking and 13 token-based surface colours, built on the navigation-menu component.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/digitalnsw/nswds-ui/main/apps/registry/public/r/main-nav.jsonSource
1'use client'23import { cva, type VariantProps } from 'class-variance-authority'4import React from 'react'56import { IconEast } from '@/icons/east'7import { cn } from '@/lib/utils'89import {10 NavigationMenu,11 NavigationMenuContent,12 NavigationMenuItem,13 NavigationMenuLink,14 NavigationMenuList,15 NavigationMenuTrigger,16} from '@/components/navigation-menu'1718/**19 * Surface colours the main navigation can be themed with — exactly the20 * Footer's thirteen-name vocabulary, so a service that themes its footer21 * `primary-800` writes the same word here. Each name is the LIGHT-mode22 * surface; dark mode deepens it onto the same family's dark steps (see the23 * `color` variants below), so `color` expresses tonal weight rather than a24 * literal colour.25 *26 * The bar's text/background pairs are identical to the Footer's, so its27 * contrast conclusions carry over verbatim: every light pair clears WCAG 2.228 * AA (1.4.3, 4.5:1) for the bar's text and 11 of the 13 also clear AAA29 * (1.4.6, 7:1). The two AA-only pairs are `primary-600` (4.57:1) and30 * `accent-600` (5.18:1), both with white ink; prefer the `-800` steps when a31 * service is held to AAA. In dark mode all thirteen clear AAA (worst 13.6:1).32 *33 * The mega panels always render on the house popup surface (`bg-popover`),34 * matching the nswds-app source where every dropdown was white regardless of35 * bar colour — only the panel's accent ink follows the colour family.36 */37const mainNavColors = [38 'primary-800',39 'primary-600',40 'primary-400',41 'primary-200',42 'grey-800',43 'grey-600',44 'grey-400',45 'grey-200',46 'accent-800',47 'accent-600',48 'accent-400',49 'accent-200',50 'white',51] as const5253type MainNavColor = (typeof mainNavColors)[number]5455// Shared by cva's defaultVariants, the data-color attribute and the panel56// variant lookup, so the three can't drift apart.57const DEFAULT_MAIN_NAV_COLOR: MainNavColor = 'white'5859const mainNavVariants = cva(60 [61 'w-full',62 // Every derived colour on the bar resolves from a single --main-nav-ink63 // token, so a colour variant only has to declare the surface utilities and64 // that one value — this replaces the nswds-app source's hand-written65 // 13-variant × 8-slot style table. The border derivation is written66 // literally here (once) rather than per-variant: Tailwind scans source67 // text for class names, so a template-built arbitrary property would68 // never be emitted. Hover/active halos are not derived here — the69// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from @nswds/ui
All 46 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Aspect Ratioaspect-ratio | @nswds/ui | Components | Free | 2 deps · 2 files | |
| Badgebadge | @nswds/ui | Components | Free | 4 deps · 2 files | |
| Buttonbutton | @nswds/ui | Components | Free | 4 deps · 2 files | |
| Cardcard | @nswds/ui | Components | Free | 2 deps · 2 files | |
| Collapsiblecollapsible | @nswds/ui | Components | Free | 1 dep | |
| Drawerdrawer | @nswds/ui | Components | Free | 3 deps · 2 files | |
| Expandable Searchexpandable-search | @nswds/ui | Components | Free | 3 deps · 2 files | |
| Fieldfield | @nswds/ui | Components | Free | 4 deps · 2 files |
