@nswds/ui 4.7.0 → 4.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -4
- package/dist/components/badge.d.ts +1 -1
- package/dist/components/badge.js +1 -1
- package/dist/components/badge.js.map +1 -1
- package/dist/components/button.d.ts +3 -3
- package/dist/components/button.js +1 -1
- package/dist/components/button.js.map +1 -1
- package/dist/components/expandable-search.js +2 -2
- package/dist/components/expandable-search.js.map +1 -1
- package/dist/components/field.js +1 -1
- package/dist/components/field.js.map +1 -1
- package/dist/components/footer.js +11 -8
- package/dist/components/footer.js.map +1 -1
- package/dist/components/header.d.ts +1 -1
- package/dist/components/header.js +9 -6
- package/dist/components/header.js.map +1 -1
- package/dist/components/input.js +1 -1
- package/dist/components/input.js.map +1 -1
- package/dist/components/link.d.ts +1 -1
- package/dist/components/link.js +1 -1
- package/dist/components/link.js.map +1 -1
- package/dist/components/main-nav.js +4 -4
- package/dist/components/main-nav.js.map +1 -1
- package/dist/components/masthead.d.ts +1 -1
- package/dist/components/navigation-menu.js +7 -7
- package/dist/components/navigation-menu.js.map +1 -1
- package/dist/components/push-menu.d.ts +5 -5
- package/dist/components/push-menu.js +2 -2
- package/dist/components/push-menu.js.map +1 -1
- package/dist/components/side-nav.js +5 -5
- package/dist/components/side-nav.js.map +1 -1
- package/dist/components/site-search.js +2 -2
- package/dist/components/site-search.js.map +1 -1
- package/dist/components/skip-link.d.ts +1 -1
- package/dist/components/skip-link.js +1 -1
- package/dist/components/skip-link.js.map +1 -1
- package/dist/components/spinner.js +1 -1
- package/dist/components/spinner.js.map +1 -1
- package/dist/components/step-indicator.js +5 -5
- package/dist/components/step-indicator.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +3 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/navigation-menu.tsx"],"names":["NavigationMenuPrimitive"],"mappings":";;;;;;;AAiCA,MAAM,iBAAA,GAAo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AAAA,OACF;AAAA,MACA,MAAA,kBAAQ,GAAA,CAAC,IAAA,EAAA,EAAK,OAAA,EAAQ,YAAW,IAAA,EAAY,CAAA;AAAA,MAC5C,GAAG;AAAA;AAAA,GACN;AAEJ","file":"navigation-menu.js","sourcesContent":["'use client'\n\nimport { NavigationMenu as NavigationMenuPrimitive } from '@base-ui/react/navigation-menu'\nimport { cva } from 'class-variance-authority'\nimport type * as React from 'react'\n\nimport { IconKeyboardArrowDown } from '../icons/keyboard-arrow-down.js'\nimport { cn } from '../lib/utils.js'\n\nimport { Link, type LinkProps } from '../components/link.js'\n\n// ─── Shared motion + ink tokens ───────────────────────────────────────────────\n\n// One easing curve — ease-[cubic-bezier(0.22,1,0.36,1)] — is written literally\n// on every animated part (positioner glide, popup resize, content cross-fade,\n// chevron flip) so the menu reads as a single surface in motion, not four\n// independent animations. It is Base UI's documented nav-menu curve: a strong\n// ease-out that settles without overshoot. Written out per-use rather than\n// composed from a shared const so every class stays a literal for Tailwind's\n// source-text scanner.\n\n// Every interactive tint in the menu derives from a single --nav-menu-ink\n// token via color-mix, mirroring the --footer-ink / --link-color pattern\n// (see footer.tsx, link.tsx): a restyle only has to swap the one ink value and\n// the resting/active halos follow. The derivations are written literally\n// (not template-built) because Tailwind scans source text for class names —\n// a computed string would never be emitted.\n//\n// Ink values use the RAW masterbrand tokens (--primary-800 / --primary-200)\n// rather than Tailwind's --color-* bridge aliases: Tailwind v4 tree-shakes\n// unreferenced @theme keys, and a reference from inside an arbitrary property\n// is not a usage signal. The raw tokens are plain :root declarations from\n// @nswds/tokens and always resolve.\nconst navigationMenuInk = [\n '[--nav-menu-ink:var(--primary-800)] dark:[--nav-menu-ink:var(--primary-200)]',\n '[--nav-menu-halo:color-mix(in_oklch,var(--nav-menu-ink)_10%,transparent)]',\n '[--nav-menu-halo-active:color-mix(in_oklch,var(--nav-menu-ink)_18%,transparent)]',\n]\n\n// ─── Trigger styling (exported for reuse) ─────────────────────────────────────\n\n/**\n * Trigger chrome, exported as a cva so siblings (e.g. a main-nav pattern) and\n * plain links that should sit visually beside triggers can reuse or extend it —\n * the app source's `Contact` item renders an `<a>` with exactly these classes.\n *\n * The 10% ink halo marks hover/open and the 18% mix marks pressed; both are\n * backgrounds behind unchanged text, so text contrast is untouched. The\n * keyboard focus indicator is a 2px outline in the ink colour itself\n * (primary-800 on light surfaces, primary-200 in dark mode) — well above the\n * 3:1 non-text contrast minimum of WCAG 2.2 SC 1.4.11 against the white/dark\n * popover surfaces, and offset so it is never obscured (SC 2.4.7, 2.4.11).\n */\nconst navigationMenuTriggerVariants = cva([\n ...navigationMenuInk,\n // Layout — h-9 keeps the row compact; the halo box is the pointer target.\n // mb-2 pairs with the list's bottom hairline, matching the app source.\n 'group mb-2 inline-flex h-9 w-max cursor-pointer items-center justify-center gap-1 rounded-sm px-4 py-2 text-sm font-medium whitespace-nowrap select-none',\n 'bg-transparent text-foreground',\n 'transition-colors motion-reduce:transition-none',\n // Resting halo on hover/focus/open. `focus:` (not focus-visible) is\n // deliberate for the tint — like Button, triggers give click feedback —\n // while the *outline* below stays keyboard-only.\n 'hover:bg-(--nav-menu-halo) focus:bg-(--nav-menu-halo) active:bg-(--nav-menu-halo-active)',\n // Base UI marks the trigger whose popup is open with data-popup-open.\n 'data-popup-open:bg-(--nav-menu-halo)',\n 'outline-none focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--nav-menu-ink)',\n 'disabled:pointer-events-none disabled:opacity-50',\n])\n\n// ─── Root ─────────────────────────────────────────────────────────────────────\n\ntype NavigationMenuProps = Omit<NavigationMenuPrimitive.Root.Props, 'className'> &\n Pick<\n NavigationMenuPrimitive.Positioner.Props,\n 'side' | 'sideOffset' | 'align' | 'alignOffset' | 'collisionPadding' | 'collisionAvoidance'\n > & {\n className?: string\n /** Extra classes for the shared popup surface (sizing, width caps, …). */\n popupClassName?: string\n /**\n * Inline styles for the shared popup surface. The popup normally sizes\n * itself from Base UI's `--popup-width`/`--popup-height`, which are\n * measured ONCE when a section activates — geometry that must track\n * something that can change while the menu is open (MainNav's\n * container-width panels, say) goes stale there. An inline style wins\n * over the measured vars and stays reactive to re-renders.\n */\n popupStyle?: React.CSSProperties\n }\n\n/**\n * Top-level navigation menu — a menubar of triggers whose panels open into one\n * shared, animated popup.\n *\n * INTERNAL to MainNav — not exported from the package barrel, not a registry\n * item, no stories. It began as a public generic wrapper but was pulled from\n * the public API: bare primitive wrappers are not the nswds-ui style (the\n * design system publishes NSW-branded components, not shadcn-alikes), and\n * MainNav is the supported way to get this behaviour. The file ships inside\n * the main-nav registry item, and the module remains reachable through the\n * package's undocumented `components/navigation-menu` export subpath purely\n * as a build artefact — treat that as private API with no stability promise.\n * (The package name is deliberately not written out here: this comment ships\n * in registry content, and the alias-leak guard rejects any occurrence of the\n * package-prefixed import form.)\n *\n * Consumers only write `List > Item > (Trigger + Content)` pairs; the popup\n * plumbing Base UI requires (Portal → Positioner → Popup → Viewport, rendered\n * once at root level, into which every `Content` teleports) is composed here so\n * it cannot be assembled wrong. Positioning knobs (`side`, `sideOffset`,\n * `align`, `collisionPadding`, `collisionAvoidance`) pass through to the\n * internal Positioner.\n *\n * Accessibility is inherited from Base UI: the root renders a `<nav>` landmark\n * (pass `aria-label` when a page has more than one), triggers are real buttons\n * wired with `aria-expanded`/`aria-controls`, ArrowDown/Enter open from the\n * keyboard, arrow keys move along the list, and Escape or focus-out closes\n * (WAI-ARIA disclosure navigation pattern). Do not add ARIA by hand.\n *\n * Departure from the nswds-app source: that wrapper was Radix-based with an\n * optional inline viewport (`viewport` prop); Base UI's model has exactly one\n * viewport, so the prop is gone. Radix's `delayDuration`/`skipDelayDuration`\n * map to Base UI's `delay`/`closeDelay` (both default 50ms).\n */\nfunction NavigationMenu({\n className,\n children,\n side,\n sideOffset = 8,\n align,\n alignOffset,\n // Keep a gutter between the popup and the viewport edge on small screens.\n collisionPadding = 20,\n // Nav panels should never flip beside their menubar — cap size instead.\n collisionAvoidance = { side: 'none' },\n popupClassName,\n popupStyle,\n ...props\n}: NavigationMenuProps) {\n return (\n <NavigationMenuPrimitive.Root\n data-slot='navigation-menu'\n className={cn(\n 'group/navigation-menu relative flex max-w-max flex-1 items-center justify-center',\n className,\n )}\n {...props}\n >\n {children}\n <NavigationMenuPrimitive.Portal>\n <NavigationMenuPrimitive.Positioner\n data-slot='navigation-menu-positioner'\n side={side}\n sideOffset={sideOffset}\n align={align}\n alignOffset={alignOffset}\n collisionPadding={collisionPadding}\n collisionAvoidance={collisionAvoidance}\n className={cn(\n // Base UI reports its measured geometry through these vars; sizing\n // the box from them lets top/left glide between triggers.\n 'isolate z-50 box-border h-[var(--positioner-height)] w-[var(--positioner-width)] max-w-[var(--available-width)]',\n 'transition-[top,left,right,bottom] duration-300 ease-[cubic-bezier(0.22,1,0.36,1)]',\n // data-instant: Base UI disables the glide (e.g. keyboard re-anchor).\n 'data-instant:transition-none motion-reduce:transition-none',\n )}\n >\n <NavigationMenuPrimitive.Popup\n data-slot='navigation-menu-popup'\n className={cn(\n // House popup surface (see popover.tsx / sheet.tsx).\n 'relative rounded-lg bg-popover text-popover-foreground shadow-md ring-1 ring-foreground/10',\n // Width/height track the active Content's size (Base UI measures\n // it into --popup-*), so switching sections morphs the surface\n // instead of jump-cutting.\n 'h-[var(--popup-height)] w-[var(--popup-width)] max-w-[var(--available-width)] origin-(--transform-origin)',\n 'transition-[opacity,transform,width,height,scale,translate] duration-300 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none',\n // Open/close via Base UI transition attributes.\n 'data-starting-style:scale-95 data-starting-style:opacity-0',\n 'data-ending-style:scale-95 data-ending-style:opacity-0',\n popupClassName,\n )}\n style={popupStyle}\n >\n <NavigationMenuPrimitive.Viewport\n data-slot='navigation-menu-viewport'\n // Clips the outgoing/incoming Content pair during a section\n // switch; rounded to match the popup so corners don't leak.\n className='relative size-full overflow-hidden rounded-lg'\n />\n </NavigationMenuPrimitive.Popup>\n </NavigationMenuPrimitive.Positioner>\n </NavigationMenuPrimitive.Portal>\n </NavigationMenuPrimitive.Root>\n )\n}\n\n// ─── List / Item ──────────────────────────────────────────────────────────────\n\ntype NavigationMenuListProps = Omit<NavigationMenuPrimitive.List.Props, 'className'> & {\n className?: string\n}\n\n/**\n * The menubar row of triggers. Base UI renders a `<ul>` and manages roving\n * arrow-key focus between the items.\n *\n * Carries the app source's bottom hairline (tokenised from raw grey utilities\n * to the semantic `border-border`, which already flips for dark mode) and its\n * hidden-scrollbar overflow so a long menu can pan on narrow screens.\n */\nfunction NavigationMenuList({ className, ...props }: NavigationMenuListProps) {\n return (\n <NavigationMenuPrimitive.List\n data-slot='navigation-menu-list'\n className={cn(\n 'group flex flex-1 list-none items-center justify-center gap-1',\n '[scrollbar-width:none] border-b border-border whitespace-nowrap [&::-webkit-scrollbar]:hidden',\n className,\n )}\n {...props}\n />\n )\n}\n\ntype NavigationMenuItemProps = Omit<NavigationMenuPrimitive.Item.Props, 'className'> & {\n className?: string\n}\n\n/**\n * One menubar entry (`<li>`), pairing a `NavigationMenuTrigger` with its\n * `NavigationMenuContent` — or holding a bare `NavigationMenuLink` for items\n * with no panel. Pass `value` when controlling the open item programmatically.\n */\nfunction NavigationMenuItem({ className, ...props }: NavigationMenuItemProps) {\n return (\n <NavigationMenuPrimitive.Item\n data-slot='navigation-menu-item'\n className={cn('relative', className)}\n {...props}\n />\n )\n}\n\n// ─── Trigger ──────────────────────────────────────────────────────────────────\n\ntype NavigationMenuTriggerProps = Omit<NavigationMenuPrimitive.Trigger.Props, 'className'> & {\n className?: string\n}\n\n/**\n * Opens the item's panel. Renders a real `<button>` (never an anchor — the\n * trigger discloses content, it doesn't navigate), which Base UI wires with\n * `aria-expanded`/`aria-controls` and hover/click/keyboard open behaviour.\n *\n * The trailing chevron rides Base UI's Icon part, which mirrors the trigger's\n * `data-popup-open` attribute — the 180° flip is pure CSS off that attribute\n * (no JS state), and is suppressed for reduced-motion users (WCAG 2.3.3).\n * The chevron is decorative, so the Icon part is `aria-hidden`: it never\n * enters the button's accessible name, and the open state it hints at is\n * already conveyed programmatically via `aria-expanded` (SC 4.1.2).\n */\nfunction NavigationMenuTrigger({ className, children, ...props }: NavigationMenuTriggerProps) {\n return (\n <NavigationMenuPrimitive.Trigger\n data-slot='navigation-menu-trigger'\n className={cn(navigationMenuTriggerVariants(), className)}\n {...props}\n >\n {children}\n <NavigationMenuPrimitive.Icon\n data-slot='navigation-menu-icon'\n aria-hidden='true'\n className='flex transition-transform duration-300 ease-[cubic-bezier(0.22,1,0.36,1)] data-popup-open:rotate-180 motion-reduce:transition-none'\n >\n <IconKeyboardArrowDown className='size-5' />\n </NavigationMenuPrimitive.Icon>\n </NavigationMenuPrimitive.Trigger>\n )\n}\n\n// ─── Content ──────────────────────────────────────────────────────────────────\n\ntype NavigationMenuContentProps = Omit<NavigationMenuPrimitive.Content.Props, 'className'> & {\n className?: string\n}\n\n/**\n * The panel for one item. Authored inline next to its Trigger, but rendered\n * (teleported by Base UI) into the shared root-level Viewport while active —\n * so panel-to-panel switches cross-fade inside one popup surface.\n *\n * The directional slide keys off `data-activation-direction` (which adjacent\n * trigger the user came from), matching the app source's from-start/from-end\n * motion. Set `keepMounted` to keep the panel in the DOM for SSR crawlers.\n */\nfunction NavigationMenuContent({ className, ...props }: NavigationMenuContentProps) {\n return (\n <NavigationMenuPrimitive.Content\n data-slot='navigation-menu-content'\n className={cn(\n 'h-full w-max max-w-[var(--available-width)] p-2',\n 'transition-[opacity,translate] duration-300 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none',\n 'data-ending-style:opacity-0 data-starting-style:opacity-0',\n // Slide with the direction of travel between adjacent triggers.\n 'data-starting-style:data-[activation-direction=left]:-translate-x-1/2',\n 'data-starting-style:data-[activation-direction=right]:translate-x-1/2',\n 'data-ending-style:data-[activation-direction=left]:translate-x-1/2',\n 'data-ending-style:data-[activation-direction=right]:-translate-x-1/2',\n className,\n )}\n {...props}\n />\n )\n}\n\n// ─── Link ─────────────────────────────────────────────────────────────────────\n\ntype NavigationMenuLinkProps = Omit<\n NavigationMenuPrimitive.Link.Props,\n 'className' | 'render' | 'href'\n> & {\n className?: string\n /**\n * Link target. Accepts the same string-or-UrlObject union as `Link`, since\n * the rendered element may be a framework link injected via `LinkProvider`.\n */\n href: LinkProps['href']\n}\n\n/**\n * A navigation link inside (or beside) the menu. Composes the design system's\n * `Link` through Base UI's `render` prop: Base UI keeps the behaviour —\n * roving focus, focus-out closing, `aria-current='page'` when `active`, close\n * on click — while `Link` supplies the element, so a `LinkProvider` framework\n * component (e.g. next/link) is injected automatically. `Link` renders with\n * `variant='unstyled'`; this component owns the visual treatment (same ink\n * halo/outline contract as the trigger — see `navigationMenuTriggerVariants`).\n *\n * Departure from Base UI's default: `closeOnClick` defaults to **true** here.\n * In an SPA a client-side navigation doesn't reload the document, so a menu\n * that stays open after choosing a destination reads as broken; pass\n * `closeOnClick={false}` for in-page links that should keep the panel open.\n *\n * Set `active` for the current page (the app source's `usePathname` check is\n * a framework API this package must not import — compare in the consumer and\n * pass the result down): it sets `aria-current='page'` (WCAG 2.4.8 support)\n * and the persistent halo via `data-active`.\n */\nfunction NavigationMenuLink({\n className,\n href,\n closeOnClick = true,\n ...props\n}: NavigationMenuLinkProps) {\n return (\n <NavigationMenuPrimitive.Link\n data-slot='navigation-menu-link'\n closeOnClick={closeOnClick}\n className={cn(\n navigationMenuInk,\n 'flex flex-col gap-1 rounded-sm p-2 text-sm text-foreground',\n 'transition-colors motion-reduce:transition-none',\n 'hover:bg-(--nav-menu-halo) focus:bg-(--nav-menu-halo) active:bg-(--nav-menu-halo-active)',\n // Persistent tint for the current page (`active` prop → data-active).\n 'data-active:bg-(--nav-menu-halo)',\n 'outline-none focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--nav-menu-ink)',\n // Unsized inline icons default to text scale and muted ink; explicit\n // size-*/text-* classes on the icon win.\n \"[&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground\",\n className,\n )}\n render={<Link variant='unstyled' href={href} />}\n {...props}\n />\n )\n}\n\nexport {\n NavigationMenu,\n NavigationMenuContent,\n NavigationMenuItem,\n NavigationMenuLink,\n NavigationMenuList,\n NavigationMenuTrigger,\n navigationMenuTriggerVariants,\n}\nexport type {\n NavigationMenuContentProps,\n NavigationMenuItemProps,\n NavigationMenuLinkProps,\n NavigationMenuListProps,\n NavigationMenuProps,\n NavigationMenuTriggerProps,\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/components/navigation-menu.tsx"],"names":["NavigationMenuPrimitive"],"mappings":";;;;;;;AAiCA,MAAM,iBAAA,GAAoB;AAAA,EACxB,8EAAA;AAAA,EACA,2EAAA;AAAA,EACA;AACF,CAAA;AAgBA,MAAM,gCAAgC,GAAA,CAAI;AAAA,EACxC,GAAG,iBAAA;AAAA;AAAA;AAAA,EAGH,0JAAA;AAAA,EACA,gCAAA;AAAA,EACA,+BAAA;AAAA;AAAA;AAAA;AAAA,EAIA,0FAAA;AAAA;AAAA,EAEA,sCAAA;AAAA,EACA,kIAAA;AAAA,EACA;AACF,CAAC;AAyDD,SAAS,cAAA,CAAe;AAAA,EACtB,SAAA;AAAA,EACA,QAAA;AAAA,EACA,IAAA;AAAA,EACA,UAAA,GAAa,CAAA;AAAA,EACb,KAAA;AAAA,EACA,WAAA;AAAA;AAAA,EAEA,gBAAA,GAAmB,EAAA;AAAA;AAAA,EAEnB,kBAAA,GAAqB,EAAE,IAAA,EAAM,MAAA,EAAO;AAAA,EACpC,cAAA;AAAA,EACA,UAAA;AAAA,EACA,GAAG;AACL,CAAA,EAAwB;AACtB,EAAA,uBACE,IAAA;AAAA,IAACA,gBAAA,CAAwB,IAAA;AAAA,IAAxB;AAAA,MACC,WAAA,EAAU,iBAAA;AAAA,MACV,SAAA,EAAW,EAAA;AAAA,QACT,kFAAA;AAAA,QACA;AAAA,OACF;AAAA,MACC,GAAG,KAAA;AAAA,MAEH,QAAA,EAAA;AAAA,QAAA,QAA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,EAC1B,SAAA;AAAA,EACA,IAAA;AAAA,EACA,YAAA,GAAe,IAAA;AAAA,EACf,GAAG;AACL,CAAA,EAA4B;AAC1B,EAAA,uBACE,GAAA;AAAA,IAACA,gBAAA,CAAwB,IAAA;AAAA,IAAxB;AAAA,MACC,WAAA,EAAU,sBAAA;AAAA,MACV,YAAA;AAAA,MACA,SAAA,EAAW,EAAA;AAAA,QACT,iBAAA;AAAA,QACA,4DAAA;AAAA,QACA,+BAAA;AAAA,QACA,0FAAA;AAAA;AAAA,QAEA,kCAAA;AAAA,QACA,kIAAA;AAAA;AAAA;AAAA,QAGA,0FAAA;AAAA,QACA;AAAA,OACF;AAAA,MACA,MAAA,kBAAQ,GAAA,CAAC,IAAA,EAAA,EAAK,OAAA,EAAQ,YAAW,IAAA,EAAY,CAAA;AAAA,MAC5C,GAAG;AAAA;AAAA,GACN;AAEJ","file":"navigation-menu.js","sourcesContent":["'use client'\n\nimport { NavigationMenu as NavigationMenuPrimitive } from '@base-ui/react/navigation-menu'\nimport { cva } from 'class-variance-authority'\nimport type * as React from 'react'\n\nimport { IconKeyboardArrowDown } from '../icons/keyboard-arrow-down.js'\nimport { cn } from '../lib/utils.js'\n\nimport { Link, type LinkProps } from '../components/link.js'\n\n// ─── Shared motion + ink tokens ───────────────────────────────────────────────\n\n// One easing curve — ease-[cubic-bezier(0.22,1,0.36,1)] — is written literally\n// on every animated part (positioner glide, popup resize, content cross-fade,\n// chevron flip) so the menu reads as a single surface in motion, not four\n// independent animations. It is Base UI's documented nav-menu curve: a strong\n// ease-out that settles without overshoot. Written out per-use rather than\n// composed from a shared const so every class stays a literal for Tailwind's\n// source-text scanner.\n\n// Every interactive tint in the menu derives from a single --nav-menu-ink\n// token via color-mix, mirroring the --footer-ink / --link-color pattern\n// (see footer.tsx, link.tsx): a restyle only has to swap the one ink value and\n// the resting/active halos follow. The derivations are written literally\n// (not template-built) because Tailwind scans source text for class names —\n// a computed string would never be emitted.\n//\n// Ink values use the RAW masterbrand tokens (--primary-800 / --primary-200)\n// rather than Tailwind's --color-* bridge aliases: Tailwind v4 tree-shakes\n// unreferenced @theme keys, and a reference from inside an arbitrary property\n// is not a usage signal. The raw tokens are plain :root declarations from\n// @nswds/tokens and always resolve.\nconst navigationMenuInk = [\n '[--nav-menu-ink:var(--primary-800)] dark:[--nav-menu-ink:var(--primary-200)]',\n '[--nav-menu-halo:color-mix(in_oklch,var(--nav-menu-ink)_10%,transparent)]',\n '[--nav-menu-halo-active:color-mix(in_oklch,var(--nav-menu-ink)_18%,transparent)]',\n]\n\n// ─── Trigger styling (exported for reuse) ─────────────────────────────────────\n\n/**\n * Trigger chrome, exported as a cva so siblings (e.g. a main-nav pattern) and\n * plain links that should sit visually beside triggers can reuse or extend it —\n * the app source's `Contact` item renders an `<a>` with exactly these classes.\n *\n * The 10% ink halo marks hover/open and the 18% mix marks pressed; both are\n * backgrounds behind unchanged text, so text contrast is untouched. The\n * keyboard focus indicator is a 2px outline in the ink colour itself\n * (primary-800 on light surfaces, primary-200 in dark mode) — well above the\n * 3:1 non-text contrast minimum of WCAG 2.2 SC 1.4.11 against the white/dark\n * popover surfaces, and offset so it is never obscured (SC 2.4.7, 2.4.11).\n */\nconst navigationMenuTriggerVariants = cva([\n ...navigationMenuInk,\n // Layout — h-9 keeps the row compact; the halo box is the pointer target.\n // mb-2 pairs with the list's bottom hairline, matching the app source.\n 'group mb-2 inline-flex h-9 w-max cursor-pointer items-center justify-center gap-1 rounded-sm px-4 py-2 text-sm font-medium whitespace-nowrap select-none',\n 'bg-transparent text-foreground',\n 'motion-safe:transition-colors',\n // Resting halo on hover/focus/open. `focus:` (not focus-visible) is\n // deliberate for the tint — like Button, triggers give click feedback —\n // while the *outline* below stays keyboard-only.\n 'hover:bg-(--nav-menu-halo) focus:bg-(--nav-menu-halo) active:bg-(--nav-menu-halo-active)',\n // Base UI marks the trigger whose popup is open with data-popup-open.\n 'data-popup-open:bg-(--nav-menu-halo)',\n 'outline-none focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--nav-menu-ink)',\n 'disabled:pointer-events-none disabled:opacity-50',\n])\n\n// ─── Root ─────────────────────────────────────────────────────────────────────\n\ntype NavigationMenuProps = Omit<NavigationMenuPrimitive.Root.Props, 'className'> &\n Pick<\n NavigationMenuPrimitive.Positioner.Props,\n 'side' | 'sideOffset' | 'align' | 'alignOffset' | 'collisionPadding' | 'collisionAvoidance'\n > & {\n className?: string\n /** Extra classes for the shared popup surface (sizing, width caps, …). */\n popupClassName?: string\n /**\n * Inline styles for the shared popup surface. The popup normally sizes\n * itself from Base UI's `--popup-width`/`--popup-height`, which are\n * measured ONCE when a section activates — geometry that must track\n * something that can change while the menu is open (MainNav's\n * container-width panels, say) goes stale there. An inline style wins\n * over the measured vars and stays reactive to re-renders.\n */\n popupStyle?: React.CSSProperties\n }\n\n/**\n * Top-level navigation menu — a menubar of triggers whose panels open into one\n * shared, animated popup.\n *\n * INTERNAL to MainNav — not exported from the package barrel, not a registry\n * item, no stories. It began as a public generic wrapper but was pulled from\n * the public API: bare primitive wrappers are not the nswds-ui style (the\n * design system publishes NSW-branded components, not shadcn-alikes), and\n * MainNav is the supported way to get this behaviour. The file ships inside\n * the main-nav registry item, and the module remains reachable through the\n * package's undocumented `components/navigation-menu` export subpath purely\n * as a build artefact — treat that as private API with no stability promise.\n * (The package name is deliberately not written out here: this comment ships\n * in registry content, and the alias-leak guard rejects any occurrence of the\n * package-prefixed import form.)\n *\n * Consumers only write `List > Item > (Trigger + Content)` pairs; the popup\n * plumbing Base UI requires (Portal → Positioner → Popup → Viewport, rendered\n * once at root level, into which every `Content` teleports) is composed here so\n * it cannot be assembled wrong. Positioning knobs (`side`, `sideOffset`,\n * `align`, `collisionPadding`, `collisionAvoidance`) pass through to the\n * internal Positioner.\n *\n * Accessibility is inherited from Base UI: the root renders a `<nav>` landmark\n * (pass `aria-label` when a page has more than one), triggers are real buttons\n * wired with `aria-expanded`/`aria-controls`, ArrowDown/Enter open from the\n * keyboard, arrow keys move along the list, and Escape or focus-out closes\n * (WAI-ARIA disclosure navigation pattern). Do not add ARIA by hand.\n *\n * Departure from the nswds-app source: that wrapper was Radix-based with an\n * optional inline viewport (`viewport` prop); Base UI's model has exactly one\n * viewport, so the prop is gone. Radix's `delayDuration`/`skipDelayDuration`\n * map to Base UI's `delay`/`closeDelay` (both default 50ms).\n */\nfunction NavigationMenu({\n className,\n children,\n side,\n sideOffset = 8,\n align,\n alignOffset,\n // Keep a gutter between the popup and the viewport edge on small screens.\n collisionPadding = 20,\n // Nav panels should never flip beside their menubar — cap size instead.\n collisionAvoidance = { side: 'none' },\n popupClassName,\n popupStyle,\n ...props\n}: NavigationMenuProps) {\n return (\n <NavigationMenuPrimitive.Root\n data-slot='navigation-menu'\n className={cn(\n 'group/navigation-menu relative flex max-w-max flex-1 items-center justify-center',\n className,\n )}\n {...props}\n >\n {children}\n <NavigationMenuPrimitive.Portal>\n <NavigationMenuPrimitive.Positioner\n data-slot='navigation-menu-positioner'\n side={side}\n sideOffset={sideOffset}\n align={align}\n alignOffset={alignOffset}\n collisionPadding={collisionPadding}\n collisionAvoidance={collisionAvoidance}\n className={cn(\n // Base UI reports its measured geometry through these vars; sizing\n // the box from them lets top/left glide between triggers.\n 'isolate z-50 box-border h-[var(--positioner-height)] w-[var(--positioner-width)] max-w-[var(--available-width)]',\n 'duration-300 ease-[cubic-bezier(0.22,1,0.36,1)] motion-safe:transition-[top,left,right,bottom]',\n // data-instant: Base UI disables the glide (e.g. keyboard re-anchor).\n 'data-instant:transition-none',\n )}\n >\n <NavigationMenuPrimitive.Popup\n data-slot='navigation-menu-popup'\n className={cn(\n // House popup surface (see popover.tsx / sheet.tsx).\n 'relative rounded-lg bg-popover text-popover-foreground shadow-md ring-1 ring-foreground/10',\n // Width/height track the active Content's size (Base UI measures\n // it into --popup-*), so switching sections morphs the surface\n // instead of jump-cutting.\n 'h-[var(--popup-height)] w-[var(--popup-width)] max-w-[var(--available-width)] origin-(--transform-origin)',\n 'duration-300 ease-[cubic-bezier(0.22,1,0.36,1)] motion-safe:transition-[opacity,transform,width,height,scale,translate]',\n // Open/close via Base UI transition attributes.\n 'data-starting-style:scale-95 data-starting-style:opacity-0',\n 'data-ending-style:scale-95 data-ending-style:opacity-0',\n popupClassName,\n )}\n style={popupStyle}\n >\n <NavigationMenuPrimitive.Viewport\n data-slot='navigation-menu-viewport'\n // Clips the outgoing/incoming Content pair during a section\n // switch; rounded to match the popup so corners don't leak.\n className='relative size-full overflow-hidden rounded-lg'\n />\n </NavigationMenuPrimitive.Popup>\n </NavigationMenuPrimitive.Positioner>\n </NavigationMenuPrimitive.Portal>\n </NavigationMenuPrimitive.Root>\n )\n}\n\n// ─── List / Item ──────────────────────────────────────────────────────────────\n\ntype NavigationMenuListProps = Omit<NavigationMenuPrimitive.List.Props, 'className'> & {\n className?: string\n}\n\n/**\n * The menubar row of triggers. Base UI renders a `<ul>` and manages roving\n * arrow-key focus between the items.\n *\n * Carries the app source's bottom hairline (tokenised from raw grey utilities\n * to the semantic `border-border`, which already flips for dark mode) and its\n * hidden-scrollbar overflow so a long menu can pan on narrow screens.\n */\nfunction NavigationMenuList({ className, ...props }: NavigationMenuListProps) {\n return (\n <NavigationMenuPrimitive.List\n data-slot='navigation-menu-list'\n className={cn(\n 'group flex flex-1 list-none items-center justify-center gap-1',\n '[scrollbar-width:none] border-b border-border whitespace-nowrap [&::-webkit-scrollbar]:hidden',\n className,\n )}\n {...props}\n />\n )\n}\n\ntype NavigationMenuItemProps = Omit<NavigationMenuPrimitive.Item.Props, 'className'> & {\n className?: string\n}\n\n/**\n * One menubar entry (`<li>`), pairing a `NavigationMenuTrigger` with its\n * `NavigationMenuContent` — or holding a bare `NavigationMenuLink` for items\n * with no panel. Pass `value` when controlling the open item programmatically.\n */\nfunction NavigationMenuItem({ className, ...props }: NavigationMenuItemProps) {\n return (\n <NavigationMenuPrimitive.Item\n data-slot='navigation-menu-item'\n className={cn('relative', className)}\n {...props}\n />\n )\n}\n\n// ─── Trigger ──────────────────────────────────────────────────────────────────\n\ntype NavigationMenuTriggerProps = Omit<NavigationMenuPrimitive.Trigger.Props, 'className'> & {\n className?: string\n}\n\n/**\n * Opens the item's panel. Renders a real `<button>` (never an anchor — the\n * trigger discloses content, it doesn't navigate), which Base UI wires with\n * `aria-expanded`/`aria-controls` and hover/click/keyboard open behaviour.\n *\n * The trailing chevron rides Base UI's Icon part, which mirrors the trigger's\n * `data-popup-open` attribute — the 180° flip is pure CSS off that attribute\n * (no JS state), and is suppressed for reduced-motion users (WCAG 2.3.3).\n * The chevron is decorative, so the Icon part is `aria-hidden`: it never\n * enters the button's accessible name, and the open state it hints at is\n * already conveyed programmatically via `aria-expanded` (SC 4.1.2).\n */\nfunction NavigationMenuTrigger({ className, children, ...props }: NavigationMenuTriggerProps) {\n return (\n <NavigationMenuPrimitive.Trigger\n data-slot='navigation-menu-trigger'\n className={cn(navigationMenuTriggerVariants(), className)}\n {...props}\n >\n {children}\n <NavigationMenuPrimitive.Icon\n data-slot='navigation-menu-icon'\n aria-hidden='true'\n className='flex duration-300 ease-[cubic-bezier(0.22,1,0.36,1)] data-popup-open:rotate-180 motion-safe:transition-transform'\n >\n <IconKeyboardArrowDown className='size-5' />\n </NavigationMenuPrimitive.Icon>\n </NavigationMenuPrimitive.Trigger>\n )\n}\n\n// ─── Content ──────────────────────────────────────────────────────────────────\n\ntype NavigationMenuContentProps = Omit<NavigationMenuPrimitive.Content.Props, 'className'> & {\n className?: string\n}\n\n/**\n * The panel for one item. Authored inline next to its Trigger, but rendered\n * (teleported by Base UI) into the shared root-level Viewport while active —\n * so panel-to-panel switches cross-fade inside one popup surface.\n *\n * The directional slide keys off `data-activation-direction` (which adjacent\n * trigger the user came from), matching the app source's from-start/from-end\n * motion. Set `keepMounted` to keep the panel in the DOM for SSR crawlers.\n */\nfunction NavigationMenuContent({ className, ...props }: NavigationMenuContentProps) {\n return (\n <NavigationMenuPrimitive.Content\n data-slot='navigation-menu-content'\n className={cn(\n 'h-full w-max max-w-[var(--available-width)] p-2',\n 'duration-300 ease-[cubic-bezier(0.22,1,0.36,1)] motion-safe:transition-[opacity,translate]',\n 'data-ending-style:opacity-0 data-starting-style:opacity-0',\n // Slide with the direction of travel between adjacent triggers.\n 'data-starting-style:data-[activation-direction=left]:-translate-x-1/2',\n 'data-starting-style:data-[activation-direction=right]:translate-x-1/2',\n 'data-ending-style:data-[activation-direction=left]:translate-x-1/2',\n 'data-ending-style:data-[activation-direction=right]:-translate-x-1/2',\n className,\n )}\n {...props}\n />\n )\n}\n\n// ─── Link ─────────────────────────────────────────────────────────────────────\n\ntype NavigationMenuLinkProps = Omit<\n NavigationMenuPrimitive.Link.Props,\n 'className' | 'render' | 'href'\n> & {\n className?: string\n /**\n * Link target. Accepts the same string-or-UrlObject union as `Link`, since\n * the rendered element may be a framework link injected via `LinkProvider`.\n */\n href: LinkProps['href']\n}\n\n/**\n * A navigation link inside (or beside) the menu. Composes the design system's\n * `Link` through Base UI's `render` prop: Base UI keeps the behaviour —\n * roving focus, focus-out closing, `aria-current='page'` when `active`, close\n * on click — while `Link` supplies the element, so a `LinkProvider` framework\n * component (e.g. next/link) is injected automatically. `Link` renders with\n * `variant='unstyled'`; this component owns the visual treatment (same ink\n * halo/outline contract as the trigger — see `navigationMenuTriggerVariants`).\n *\n * Departure from Base UI's default: `closeOnClick` defaults to **true** here.\n * In an SPA a client-side navigation doesn't reload the document, so a menu\n * that stays open after choosing a destination reads as broken; pass\n * `closeOnClick={false}` for in-page links that should keep the panel open.\n *\n * Set `active` for the current page (the app source's `usePathname` check is\n * a framework API this package must not import — compare in the consumer and\n * pass the result down): it sets `aria-current='page'` (WCAG 2.4.8 support)\n * and the persistent halo via `data-active`.\n */\nfunction NavigationMenuLink({\n className,\n href,\n closeOnClick = true,\n ...props\n}: NavigationMenuLinkProps) {\n return (\n <NavigationMenuPrimitive.Link\n data-slot='navigation-menu-link'\n closeOnClick={closeOnClick}\n className={cn(\n navigationMenuInk,\n 'flex flex-col gap-1 rounded-sm p-2 text-sm text-foreground',\n 'motion-safe:transition-colors',\n 'hover:bg-(--nav-menu-halo) focus:bg-(--nav-menu-halo) active:bg-(--nav-menu-halo-active)',\n // Persistent tint for the current page (`active` prop → data-active).\n 'data-active:bg-(--nav-menu-halo)',\n 'outline-none focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--nav-menu-ink)',\n // Unsized inline icons default to text scale and muted ink; explicit\n // size-*/text-* classes on the icon win.\n \"[&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground\",\n className,\n )}\n render={<Link variant='unstyled' href={href} />}\n {...props}\n />\n )\n}\n\nexport {\n NavigationMenu,\n NavigationMenuContent,\n NavigationMenuItem,\n NavigationMenuLink,\n NavigationMenuList,\n NavigationMenuTrigger,\n navigationMenuTriggerVariants,\n}\nexport type {\n NavigationMenuContentProps,\n NavigationMenuItemProps,\n NavigationMenuLinkProps,\n NavigationMenuListProps,\n NavigationMenuProps,\n NavigationMenuTriggerProps,\n}\n"]}
|
|
@@ -10,9 +10,9 @@ import React__default from 'react';
|
|
|
10
10
|
* schedule focus restoration). Do not override the custom property directly —
|
|
11
11
|
* that changes only the visual duration while the state machine still settles
|
|
12
12
|
* on `durationMs`, desyncing the two; pass `durationMs` instead. Under
|
|
13
|
-
* `prefers-reduced-motion` the slide is skipped (
|
|
14
|
-
*
|
|
15
|
-
* menu is simply "settled early" for those users, never broken.
|
|
13
|
+
* `prefers-reduced-motion` the slide is skipped (the transition is applied
|
|
14
|
+
* under `motion-safe:` only) but the state machine still waits the full
|
|
15
|
+
* duration; the menu is simply "settled early" for those users, never broken.
|
|
16
16
|
*/
|
|
17
17
|
declare const PUSH_MENU_DURATION_MS = 300;
|
|
18
18
|
/** A node in the menu tree. Items with `links` drill in; items with `href` navigate. */
|
|
@@ -126,8 +126,8 @@ type PushMenuProps = Omit<React__default.ComponentPropsWithoutRef<'nav'>, 'child
|
|
|
126
126
|
* - During the slide, rows get `pointer-events-none` and the state machine
|
|
127
127
|
* ignores re-entrant navigation, but nothing is ever `disabled` — disabling
|
|
128
128
|
* the focused Back button mid-animation would eject keyboard focus.
|
|
129
|
-
* - Slides are CSS transforms
|
|
130
|
-
*
|
|
129
|
+
* - Slides are CSS transforms applied under `motion-safe:`, replacing the app's
|
|
130
|
+
* inline transition strings (which ignored reduced motion).
|
|
131
131
|
*
|
|
132
132
|
* Departures from the nswds-app source, beyond the above:
|
|
133
133
|
*
|
|
@@ -65,7 +65,7 @@ const itemBaseClassName = [
|
|
|
65
65
|
// min-h-11 guarantees the 44px minimum target size (WCAG 2.2, 2.5.8 Target
|
|
66
66
|
// Size) even for single-line rows with compact padding overrides.
|
|
67
67
|
"relative flex min-h-11 w-full cursor-pointer items-center justify-between gap-x-6 border-l p-4 text-left text-base",
|
|
68
|
-
"
|
|
68
|
+
"motion-safe:transition-colors",
|
|
69
69
|
"hover:border-primary-800 hover:bg-primary-800/10 dark:hover:border-primary-200 dark:hover:bg-primary-200/10",
|
|
70
70
|
// Inset outline (negative offset): the levels scroll inside an
|
|
71
71
|
// overflow-hidden root, so an outward offset would be clipped on the first
|
|
@@ -233,7 +233,7 @@ function PushMenu({
|
|
|
233
233
|
inert: !isActiveLevel,
|
|
234
234
|
className: cn(
|
|
235
235
|
"absolute inset-0 flex h-full w-full flex-col bg-popover will-change-transform",
|
|
236
|
-
isSliding ? "
|
|
236
|
+
isSliding ? "duration-(--push-menu-duration) ease-out motion-safe:transition-transform" : "transition-none"
|
|
237
237
|
),
|
|
238
238
|
style: { transform: `translateX(${translateX}%)`, zIndex: index + 1 },
|
|
239
239
|
children: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/push-menu.tsx"],"names":[],"mappings":";;;;;;;;;AA0BA,MAAM,qBAAA,GAAwB;AA2B9B,SAAS,aAAa,IAAA,EAAwB;AAC5C,EAAA,OAAO,CAAA,MAAA,EAAS,KAAK,MAAA,GAAS,CAAA,GA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EA7CK,KAAK,EA+Cd,CAAA;AAAA,gBAEJ,CAAC,GACH,CAAA,EACF;AAAA;AAAA,aAAA;AAAA,YA7HK,KAAA,CAAM;AAAA,WA8Hb;AAAA,QAEJ,CAAC;AAAA;AAAA;AAAA,GACH;AAEJ","file":"push-menu.js","sourcesContent":["'use client'\n\nimport React from 'react'\n\nimport { cn } from '../lib/utils.js'\n\nimport { Button } from '../components/button.js'\nimport { Link } from '../components/link.js'\nimport { IconChevronRight } from '../icons/chevron-right.js'\nimport { IconClose } from '../icons/close.js'\nimport { IconWest } from '../icons/west.js'\n\n/**\n * Default slide duration for level transitions, in milliseconds — the default\n * of the `durationMs` prop.\n *\n * COUPLING: `durationMs` drives BOTH the `--push-menu-duration` custom\n * property (set inline on the root, read by the CSS transition) and the state\n * machine's `setTimeout`s (which settle the animation state, pop levels, and\n * schedule focus restoration). Do not override the custom property directly —\n * that changes only the visual duration while the state machine still settles\n * on `durationMs`, desyncing the two; pass `durationMs` instead. Under\n * `prefers-reduced-motion` the slide is skipped (`motion-reduce:\n * transition-none`) but the state machine still waits the full duration; the\n * menu is simply \"settled early\" for those users, never broken.\n */\nconst PUSH_MENU_DURATION_MS = 300\n\n/** A node in the menu tree. Items with `links` drill in; items with `href` navigate. */\ntype PushMenuItem = {\n /** Unique across the whole tree — level ids and focus restoration track items by id. */\n id: string\n /** Visible label. */\n title: string\n /** Navigation target for leaf items. Ignored for drilling when `links` is non-empty. */\n href?: string\n /** Child items. A non-empty array makes this item a drill-in button, not a link. */\n links?: PushMenuItem[]\n}\n\n/** One entry in the level stack — the root level plus one per drill-in. */\ntype PushMenuLevel = {\n id: string\n title: string\n /** 1 for the root level, incrementing per drill-in. */\n depth: number\n items: PushMenuItem[]\n /** The item whose activation opened this level. Absent on the root level. */\n parentItem?: PushMenuItem\n}\n\ntype PushMenuAnimationState = 'idle' | 'sliding-forward' | 'sliding-backward'\n\nfunction buildLevelId(path: string[]): string {\n return `level-${path.length > 0 ? path.join('--') : 'root'}`\n}\n\n/**\n * Collapses a trail of level titles into a single \"A › B › C\" string, keeping\n * the ends and eliding the middle once it outgrows `maxLength`. Exported so an\n * app can render the same trail outside the menu (e.g. in a sheet header).\n * Prefixed with \"PushMenu\" to avoid colliding with a future breadcrumb\n * component in the package barrel.\n */\nfunction generatePushMenuBreadcrumb(levels: { title: string }[], maxLength = 50): string {\n const first = levels[0]\n if (levels.length <= 1) {\n return first?.title ?? 'Menu'\n }\n\n const full = levels.map((level) => level.title).join(' › ')\n if (full.length <= maxLength) {\n return full\n }\n\n const last = levels.at(-1)\n const secondLast = levels.at(-2)\n if (levels.length > 3 && first && last && secondLast) {\n return `${first.title} › … › ${secondLast.title} › ${last.title}`\n }\n\n return `${full.slice(0, maxLength - 1)}…`\n}\n\n/**\n * Dev-only guard, mirroring `warnIfIconButtonUnlabelled` in button.tsx. It\n * replaces the nswds-app source's rendered \"Navigation Error\" fallback panel:\n * malformed navigation data is a programming error, not a runtime state a user\n * should ever see, so the design system surfaces it to the developer console\n * and renders what it can instead of shipping error chrome. No-op in\n * production.\n */\nfunction warnIfNavigationMalformed(navigation: PushMenuItem[]) {\n if (process.env.NODE_ENV === 'production') {\n return\n }\n if (!Array.isArray(navigation) || navigation.length === 0) {\n console.warn('[nswds/ui] PushMenu received no navigation items — the menu renders empty.')\n return\n }\n const seen = new Set<string>()\n const visit = (items: PushMenuItem[]) => {\n for (const item of items) {\n if (!item?.id || !item.title) {\n console.warn('[nswds/ui] PushMenu navigation item is missing an `id` or `title`:', item)\n continue\n }\n if (seen.has(item.id)) {\n console.warn(\n `[nswds/ui] PushMenu navigation contains duplicate id \"${item.id}\" — level ids and focus restoration track items by id, so ids must be unique across the whole tree.`,\n )\n }\n seen.add(item.id)\n if (!item.href && !item.links?.length) {\n console.warn(\n `[nswds/ui] PushMenu item \"${item.id}\" has neither an href nor children — it renders as a button that only fires onItemClick.`,\n )\n }\n if (item.links?.length) {\n visit(item.links)\n }\n }\n }\n visit(navigation)\n}\n\n// One treatment for every row — drill-in buttons and leaf links alike — so the\n// two read as a single list. Tokenized from the nswds-app source's\n// border-l + primary-800 active pattern, with dark-mode equivalents the app\n// lacked (its grey-800-on-white text disappeared in dark mode).\nconst itemBaseClassName = [\n // min-h-11 guarantees the 44px minimum target size (WCAG 2.2, 2.5.8 Target\n // Size) even for single-line rows with compact padding overrides.\n 'relative flex min-h-11 w-full cursor-pointer items-center justify-between gap-x-6 border-l p-4 text-left text-base',\n 'transition-colors motion-reduce:transition-none',\n 'hover:border-primary-800 hover:bg-primary-800/10 dark:hover:border-primary-200 dark:hover:bg-primary-200/10',\n // Inset outline (negative offset): the levels scroll inside an\n // overflow-hidden root, so an outward offset would be clipped on the first\n // and last rows (WCAG 2.2, 2.4.13 Focus Appearance).\n 'focus-visible:outline focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-primary-800 dark:focus-visible:outline-primary-200',\n].join(' ')\n\nconst itemActiveClassName =\n 'border-primary-800 bg-primary-800/10 font-semibold text-primary-800 dark:border-primary-200 dark:bg-primary-200/10 dark:text-primary-200'\n\nconst itemInactiveClassName = 'border-transparent text-popover-foreground'\n\ntype PushMenuProps = Omit<React.ComponentPropsWithoutRef<'nav'>, 'children' | 'title'> & {\n /** The menu tree. Item ids must be unique across the whole tree. */\n navigation: PushMenuItem[]\n /**\n * The app's current pathname. Leaf links whose `href` matches get\n * `aria-current=\"page\"` and the active treatment. Replaces the nswds-app\n * source's `usePathname()` — the design system is framework-free, so the\n * router value is passed in rather than read from next/navigation.\n */\n currentHref?: string\n /** Root level title, shown in the header row. Also the default `aria-label`. */\n title?: string\n /** Fired when a leaf item (link or child-less button) is activated. */\n onItemClick?: (item: PushMenuItem) => void\n /** Fired after a forward/back slide settles on a level. */\n onNavigate?: (level: PushMenuLevel, history: PushMenuLevel[]) => void\n /**\n * Renders a close button in the header row when provided. Unlike the\n * nswds-app source — which only offered close on sub-levels, leaving the\n * root level uncloseable — the button renders on every level.\n */\n onClose?: () => void\n /** Show the \"A › B › C\" trail under the header on sub-levels. Defaults to `true`. */\n showBreadcrumbs?: boolean\n /**\n * Slide duration in milliseconds, defaulting to `PUSH_MENU_DURATION_MS`\n * (300). Drives both the `--push-menu-duration` custom property and the\n * state machine's timeouts — tune the slide here, never by overriding the\n * custom property (see the coupling note on the constant).\n */\n durationMs?: number\n /** Label for the Back button on sub-levels. Defaults to `'Back'`. */\n backLabel?: string\n /** Accessible label for the close button. Defaults to `'Close menu'`. */\n closeLabel?: string\n /**\n * Heading level for the per-level title, following `FooterNavColumn`'s\n * precedent (the nswds-app source used a `Heading` component this package\n * does not ship). Defaults to `2`; `1` is excluded because a menu panel\n * title is never the page's own title.\n */\n headingLevel?: 2 | 3 | 4 | 5 | 6\n ref?: React.Ref<HTMLElement>\n}\n\n/**\n * Multi-level slide-in-place drill-down menu (\"push menu\") for mobile\n * navigation, ported from nswds-app's `MultiLevelPushMenu`. Items with\n * children render as buttons that slide a new level in from the right; leaf\n * items render as links through `Link`, so apps can inject their framework\n * link component via `LinkProvider`. Fill height from its container — compose\n * it inside `SheetContent side=\"left\"` for the classic mobile drawer.\n *\n * Accessibility contract (all improvements over the nswds-app source, which\n * got several of these wrong):\n *\n * - The root is a `nav` landmark named by `title` (override with `aria-label`).\n * - Non-current levels carry the `inert` attribute, so a hidden level's links\n * are neither tabbable nor exposed to assistive tech. The app left every\n * mounted level in the tab order, letting keyboard users tab into invisible\n * history levels (WCAG 2.2, 2.4.3 Focus Order).\n * - Focus moves with the level change (2.4.3): drilling forward focuses the\n * new level's Back button; going back focuses the item that opened the\n * level just left, tracked by item id and restored after the slide settles.\n * Without this, `inert` on the old level would silently drop focus to\n * `<body>`. The Back button is the only route back (the breadcrumb is\n * decorative), so it always renders on sub-levels — hiding it would make\n * drill-down one-way.\n * - A single visually-hidden `aria-live=\"polite\"` region at the root announces\n * the current level's title, suffixed with the level number below the root.\n * A live attribute on the per-level headings would not work: each level's\n * heading is freshly mounted, and newly-mounted live regions are not\n * reliably announced.\n * - Level lists are `<ul role=\"list\">` — `list-style: none` strips list\n * semantics in some screen reader/browser pairings (notably VoiceOver), and\n * the explicit role restores them.\n * - Every row is at least 44px tall (2.5.8 Target Size); Back/close buttons\n * inherit `Button`'s 44px touch target.\n * - During the slide, rows get `pointer-events-none` and the state machine\n * ignores re-entrant navigation, but nothing is ever `disabled` — disabling\n * the focused Back button mid-animation would eject keyboard focus.\n * - Slides are CSS transforms with `motion-reduce:transition-none`, replacing\n * the app's inline transition strings (which ignored reduced motion).\n *\n * Departures from the nswds-app source, beyond the above:\n *\n * - The footer/stats block (Level N, item counts, progress dots, lucide\n * icons) is cut, along with its `showStats`/`showFooter` props: it was demo\n * chrome for the sandbox, not part of a navigation component's job. The\n * breadcrumb trail it hosted moves under the header row.\n * - The rendered \"Navigation Error\" fallback for malformed data is replaced\n * by a dev-only console warning (`warnIfNavigationMalformed`), mirroring\n * button.tsx's `warnIfIconButtonUnlabelled`.\n * - The breadcrumb trail is `aria-hidden`: it repeats what the heading and\n * live region already announce, and \"›\" separators read poorly in AT.\n *\n * The level stack is seeded from `navigation`/`title` on mount; pass a `key`\n * to remount (and reset to the root level) if either changes at runtime.\n */\nfunction PushMenu({\n navigation,\n currentHref,\n title = 'Menu',\n onItemClick,\n onNavigate,\n onClose,\n showBreadcrumbs = true,\n durationMs = PUSH_MENU_DURATION_MS,\n backLabel = 'Back',\n closeLabel = 'Close menu',\n headingLevel = 2,\n className,\n style,\n 'aria-label': ariaLabel,\n ref,\n ...props\n}: PushMenuProps) {\n const [navigationHistory, setNavigationHistory] = React.useState<PushMenuLevel[]>(() => [\n { items: navigation, title, depth: 1, id: buildLevelId([]) },\n ])\n const [animationState, setAnimationState] = React.useState<PushMenuAnimationState>('idle')\n const [isAnimationStarted, setIsAnimationStarted] = React.useState(false)\n\n const containerRef = React.useRef<HTMLElement | null>(null)\n const timeoutRef = React.useRef<number | null>(null)\n // Focus target applied by the effect below, after React commits the level\n // change — the target element must exist and must no longer be inert.\n const pendingFocusRef = React.useRef<{ levelId: string; itemId?: string } | null>(null)\n\n warnIfNavigationMalformed(navigation)\n\n React.useEffect(() => {\n return () => {\n if (timeoutRef.current !== null) {\n window.clearTimeout(timeoutRef.current)\n }\n }\n }, [])\n\n // Layout effect, not a passive one: the same commit that queues a focus\n // move can also flip the previously-focused element inert (drilling turns\n // the old level inert; going back turns the departing level inert), and the\n // browser blurs an element the moment it becomes inert. Applying the new\n // focus before paint means AT never observes the intermediate\n // focus-on-body state, and a containing dialog's focus guards (Base UI\n // Sheet) see focus already inside the popup when their async handlers run.\n React.useLayoutEffect(() => {\n const pending = pendingFocusRef.current\n if (!pending) {\n return\n }\n pendingFocusRef.current = null\n const level = containerRef.current?.querySelector<HTMLElement>(\n `[data-level-id=\"${CSS.escape(pending.levelId)}\"]`,\n )\n if (!level) {\n return\n }\n const target = pending.itemId\n ? level.querySelector<HTMLElement>(`[data-item-id=\"${CSS.escape(pending.itemId)}\"]`)\n : (level.querySelector<HTMLElement>('[data-slot=\"push-menu-back-button\"]') ??\n level.querySelector<HTMLElement>(\n '[data-slot=\"push-menu-item\"], [data-slot=\"push-menu-link\"]',\n ))\n // preventScroll: a level mid-slide sits at translateX(100%) inside an\n // overflow-hidden root; letting focus scroll it into view would desync the\n // container's scroll position from the transform.\n target?.focus({ preventScroll: true })\n // animationState is a dependency because back-navigation queues its focus\n // move on the slide START (an animationState commit), not on the level\n // pop — see navigateBack.\n }, [navigationHistory, animationState])\n\n const breadcrumb = React.useMemo(\n // During a back slide the trail already excludes the departing level —\n // the breadcrumb tracks the level the user is arriving at (see\n // activeIndex below), same as the live region.\n () =>\n generatePushMenuBreadcrumb(\n animationState === 'sliding-backward' ? navigationHistory.slice(0, -1) : navigationHistory,\n ),\n [navigationHistory, animationState],\n )\n\n function navigateToSubmenu(item: PushMenuItem) {\n if (!item.links?.length || animationState !== 'idle') {\n return\n }\n const levelPath = [\n ...navigationHistory.flatMap((level) => (level.parentItem ? [level.parentItem.id] : [])),\n item.id,\n ]\n const currentDepth = navigationHistory.at(-1)?.depth ?? 1\n const newLevel: PushMenuLevel = {\n items: item.links,\n title: item.title,\n parentItem: item,\n depth: currentDepth + 1,\n id: buildLevelId(levelPath),\n }\n const newHistory = [...navigationHistory, newLevel]\n\n // Focus moves as soon as the new level commits (see the effect above):\n // waiting for the slide to finish would leave focus on the old level,\n // which turns inert in the same commit and would eject focus to <body>.\n pendingFocusRef.current = { levelId: newLevel.id }\n setNavigationHistory(newHistory)\n setAnimationState('sliding-forward')\n setIsAnimationStarted(false)\n\n // Two-step start: the new level mounts at translateX(100%) with no\n // transition, then flips to 0 with the transition on. The layout read in\n // between is LOAD-BEARING: without it, nothing forces the browser to\n // compute styles for the mounted-at-100% frame, and when both states land\n // in one style recalc there is no transition — the panel snaps into\n // place instead of sliding (an intermittent, timing-dependent jump).\n // Reading layout inside the rAF forces that recalc deterministically.\n requestAnimationFrame(() => {\n containerRef.current?.getBoundingClientRect()\n setIsAnimationStarted(true)\n })\n\n timeoutRef.current = window.setTimeout(() => {\n setAnimationState('idle')\n setIsAnimationStarted(false)\n onNavigate?.(newLevel, newHistory)\n }, durationMs)\n }\n\n function navigateBack() {\n if (navigationHistory.length <= 1 || animationState !== 'idle') {\n return\n }\n const popped = navigationHistory.at(-1)\n const revealed = navigationHistory.at(-2)\n if (!revealed) {\n return\n }\n\n // Focus moves at slide START, symmetric with drilling forward: the\n // 'sliding-backward' commit un-inerts the revealed level (see the\n // activeIndex logic below) and the effect above focuses the item that\n // opened the departing level. Restoring focus at the POP instead — while\n // focus still sat on the departing level's Back button — meant the\n // focused node was removed from a live dialog, and Base UI's focus\n // containment would re-grab focus to the dialog popup a frame after our\n // restoration, silently overriding it (observed inside Sheet).\n pendingFocusRef.current = { levelId: revealed.id, itemId: popped?.parentItem?.id }\n setAnimationState('sliding-backward')\n\n timeoutRef.current = window.setTimeout(() => {\n const newHistory = navigationHistory.slice(0, -1)\n setNavigationHistory(newHistory)\n setAnimationState('idle')\n onNavigate?.(revealed, newHistory)\n }, durationMs)\n }\n\n const currentLevel = navigationHistory.at(-1)\n if (!currentLevel) {\n return null\n }\n\n const isAnimating = animationState !== 'idle'\n // The level the user is arriving AT — the stack top, except during a back\n // slide, where the user's intent has already committed to the level being\n // revealed underneath. data-current, inert, the live region and the\n // breadcrumb all follow this index so focus can land on the revealed level\n // at slide start and AT hears the destination, not the departing level.\n const activeIndex =\n animationState === 'sliding-backward'\n ? navigationHistory.length - 2\n : navigationHistory.length - 1\n const activeLevel = navigationHistory[activeIndex] ?? currentLevel\n const HeadingTag = `h${headingLevel}` as const\n\n return (\n <nav\n data-slot='push-menu'\n aria-label={ariaLabel ?? title}\n // Present while a slide is running (matches header's present-or-absent\n // data-scrolled convention). Consumers can style the transition off it;\n // tests use it to wait for the state machine to go idle — clicks during\n // a slide are dropped by design, and pointer-events-none does not stop\n // a programmatic .click().\n data-animating={isAnimating || undefined}\n {...props}\n className={cn(\n 'relative isolate h-full overflow-hidden bg-popover text-popover-foreground',\n className,\n )}\n // The slide duration custom property is set from durationMs so the CSS\n // transition and the setTimeout state machine can never disagree — see\n // the coupling note on PUSH_MENU_DURATION_MS.\n style={{ ...style, '--push-menu-duration': `${durationMs}ms` } as React.CSSProperties}\n ref={(node) => {\n containerRef.current = node\n if (typeof ref === 'function') {\n ref(node)\n } else if (ref) {\n ;(ref as React.RefObject<HTMLElement | null>).current = node\n }\n }}\n >\n {/* Persistent live region: announces level changes to AT without\n stealing focus from the managed focus moves. The level number is\n appended below the root because live regions only re-announce when\n their content actually changes — navigating between identically-\n titled levels would otherwise announce nothing. Consecutive levels\n always differ in depth, so consecutive announcements always differ. */}\n <div data-slot='push-menu-live-region' aria-live='polite' className='sr-only'>\n {activeLevel.depth > 1\n ? `${activeLevel.title}, level ${activeLevel.depth}`\n : activeLevel.title}\n </div>\n\n {navigationHistory.map((level, index) => {\n // The stack top is the level that MOVES (slides in forward, slides\n // out backward); the active level is the one the user is arriving at\n // — they differ only during a back slide.\n const isTopLevel = index === navigationHistory.length - 1\n const isActiveLevel = index === activeIndex\n // Always shown below the root: the Back button is the ONLY route back\n // (the breadcrumb is aria-hidden and there is no keyboard binding or\n // imperative API), so making it optional would strand users.\n const shouldShowBackButton = level.depth > 1\n\n let translateX = 0\n if (animationState === 'sliding-forward') {\n translateX = isTopLevel ? (isAnimationStarted ? 0 : 100) : 0\n } else if (animationState === 'sliding-backward') {\n translateX = isTopLevel ? 100 : 0\n }\n\n // Only the moving (top) level transitions; forward slides wait for\n // the second frame so the mount position is applied untransitioned.\n const isSliding =\n isTopLevel &&\n (animationState === 'sliding-backward' ||\n (animationState === 'sliding-forward' && isAnimationStarted))\n\n return (\n <div\n key={level.id}\n data-slot='push-menu-level'\n data-level-id={level.id}\n data-current={isActiveLevel || undefined}\n // Non-active levels must be invisible to keyboard and AT, not\n // just to the eye. Keying this on the ACTIVE level (not the stack\n // top) un-inerts the revealed level at back-slide start, so focus\n // can move there immediately — and the focused Back button is\n // never removed from a live dialog while still focused.\n inert={!isActiveLevel}\n className={cn(\n 'absolute inset-0 flex h-full w-full flex-col bg-popover will-change-transform',\n isSliding\n ? 'transition-transform duration-(--push-menu-duration) ease-out motion-reduce:transition-none'\n : 'transition-none',\n )}\n style={{ transform: `translateX(${translateX}%)`, zIndex: index + 1 }}\n >\n <div\n data-slot='push-menu-header'\n className='flex min-h-11 items-center gap-1 border-b border-border px-2 py-2'\n >\n {shouldShowBackButton && (\n <Button\n data-slot='push-menu-back-button'\n variant='ghost'\n color='primary'\n size='sm'\n leadingVisual={IconWest}\n onClick={navigateBack}\n className={cn(isAnimating && 'pointer-events-none')}\n >\n {backLabel}\n </Button>\n )}\n <HeadingTag\n data-slot='push-menu-title'\n className='min-w-0 flex-1 truncate px-2 text-base font-semibold'\n >\n {level.title}\n </HeadingTag>\n {onClose && (\n <Button\n data-slot='push-menu-close-button'\n variant='ghost'\n color='grey'\n size='icon'\n aria-label={closeLabel}\n leadingVisual={IconClose}\n onClick={onClose}\n />\n )}\n </div>\n\n {showBreadcrumbs && isActiveLevel && level.depth > 1 && (\n // aria-hidden: the trail repeats what the heading and live\n // region already announce, and \"›\" separators read poorly in AT.\n <p\n data-slot='push-menu-breadcrumb'\n aria-hidden='true'\n className='truncate border-b border-border px-4 py-2 text-xs text-muted-foreground'\n >\n {breadcrumb}\n </p>\n )}\n\n <div data-slot='push-menu-items' className='flex-1 overflow-y-auto'>\n {/* role='list' restores list semantics stripped by list-none. */}\n <ul role='list' className='m-0 list-none divide-y divide-border p-0'>\n {level.items.map((item) => {\n const hasChildren = Boolean(item.links?.length)\n const isActive = item.href != null && item.href === currentHref\n\n return (\n <li key={item.id}>\n {hasChildren ? (\n <button\n type='button'\n data-slot='push-menu-item'\n data-item-id={item.id}\n onClick={() => navigateToSubmenu(item)}\n className={cn(\n itemBaseClassName,\n isActive ? itemActiveClassName : itemInactiveClassName,\n isAnimating && 'pointer-events-none',\n )}\n >\n <span className='min-w-0 flex-1 truncate'>{item.title}</span>\n <IconChevronRight aria-hidden='true' className='size-5 shrink-0' />\n </button>\n ) : item.href ? (\n <Link\n variant='unstyled'\n data-slot='push-menu-link'\n data-item-id={item.id}\n href={item.href}\n aria-current={isActive ? 'page' : undefined}\n onClick={() => onItemClick?.(item)}\n className={cn(\n itemBaseClassName,\n isActive ? itemActiveClassName : itemInactiveClassName,\n isAnimating && 'pointer-events-none',\n )}\n >\n <span className='min-w-0 flex-1 truncate'>{item.title}</span>\n </Link>\n ) : (\n <button\n type='button'\n data-slot='push-menu-item'\n data-item-id={item.id}\n onClick={() => onItemClick?.(item)}\n className={cn(\n itemBaseClassName,\n itemInactiveClassName,\n isAnimating && 'pointer-events-none',\n )}\n >\n <span className='min-w-0 flex-1 truncate'>{item.title}</span>\n </button>\n )}\n </li>\n )\n })}\n </ul>\n </div>\n </div>\n )\n })}\n </nav>\n )\n}\n\nexport { generatePushMenuBreadcrumb, PUSH_MENU_DURATION_MS, PushMenu }\nexport type { PushMenuItem, PushMenuLevel, PushMenuProps }\n"]}
|
|
1
|
+
{"version":3,"sources":["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AA;AAAA,wBACA,WAAA,IAAe;AAAA,uBACjB;AAAA,sBAEA,QAAA,kBAAA,GAAA,CAAC,MAAA,EAAA,EAAK,SAAA,EAAU,yBAAA,EAA2B,eAAK,KAAA,EAAM;AAAA;AAAA,mBACxD,EAAA,EA7CK,KAAK,EA+Cd,CAAA;AAAA,gBAEJ,CAAC,GACH,CAAA,EACF;AAAA;AAAA,aAAA;AAAA,YA7HK,KAAA,CAAM;AAAA,WA8Hb;AAAA,QAEJ,CAAC;AAAA;AAAA;AAAA,GACH;AAEJ","file":"push-menu.js","sourcesContent":["'use client'\n\nimport React from 'react'\n\nimport { cn } from '../lib/utils.js'\n\nimport { Button } from '../components/button.js'\nimport { Link } from '../components/link.js'\nimport { IconChevronRight } from '../icons/chevron-right.js'\nimport { IconClose } from '../icons/close.js'\nimport { IconWest } from '../icons/west.js'\n\n/**\n * Default slide duration for level transitions, in milliseconds — the default\n * of the `durationMs` prop.\n *\n * COUPLING: `durationMs` drives BOTH the `--push-menu-duration` custom\n * property (set inline on the root, read by the CSS transition) and the state\n * machine's `setTimeout`s (which settle the animation state, pop levels, and\n * schedule focus restoration). Do not override the custom property directly —\n * that changes only the visual duration while the state machine still settles\n * on `durationMs`, desyncing the two; pass `durationMs` instead. Under\n * `prefers-reduced-motion` the slide is skipped (the transition is applied\n * under `motion-safe:` only) but the state machine still waits the full\n * duration; the menu is simply \"settled early\" for those users, never broken.\n */\nconst PUSH_MENU_DURATION_MS = 300\n\n/** A node in the menu tree. Items with `links` drill in; items with `href` navigate. */\ntype PushMenuItem = {\n /** Unique across the whole tree — level ids and focus restoration track items by id. */\n id: string\n /** Visible label. */\n title: string\n /** Navigation target for leaf items. Ignored for drilling when `links` is non-empty. */\n href?: string\n /** Child items. A non-empty array makes this item a drill-in button, not a link. */\n links?: PushMenuItem[]\n}\n\n/** One entry in the level stack — the root level plus one per drill-in. */\ntype PushMenuLevel = {\n id: string\n title: string\n /** 1 for the root level, incrementing per drill-in. */\n depth: number\n items: PushMenuItem[]\n /** The item whose activation opened this level. Absent on the root level. */\n parentItem?: PushMenuItem\n}\n\ntype PushMenuAnimationState = 'idle' | 'sliding-forward' | 'sliding-backward'\n\nfunction buildLevelId(path: string[]): string {\n return `level-${path.length > 0 ? path.join('--') : 'root'}`\n}\n\n/**\n * Collapses a trail of level titles into a single \"A › B › C\" string, keeping\n * the ends and eliding the middle once it outgrows `maxLength`. Exported so an\n * app can render the same trail outside the menu (e.g. in a sheet header).\n * Prefixed with \"PushMenu\" to avoid colliding with a future breadcrumb\n * component in the package barrel.\n */\nfunction generatePushMenuBreadcrumb(levels: { title: string }[], maxLength = 50): string {\n const first = levels[0]\n if (levels.length <= 1) {\n return first?.title ?? 'Menu'\n }\n\n const full = levels.map((level) => level.title).join(' › ')\n if (full.length <= maxLength) {\n return full\n }\n\n const last = levels.at(-1)\n const secondLast = levels.at(-2)\n if (levels.length > 3 && first && last && secondLast) {\n return `${first.title} › … › ${secondLast.title} › ${last.title}`\n }\n\n return `${full.slice(0, maxLength - 1)}…`\n}\n\n/**\n * Dev-only guard, mirroring `warnIfIconButtonUnlabelled` in button.tsx. It\n * replaces the nswds-app source's rendered \"Navigation Error\" fallback panel:\n * malformed navigation data is a programming error, not a runtime state a user\n * should ever see, so the design system surfaces it to the developer console\n * and renders what it can instead of shipping error chrome. No-op in\n * production.\n */\nfunction warnIfNavigationMalformed(navigation: PushMenuItem[]) {\n if (process.env.NODE_ENV === 'production') {\n return\n }\n if (!Array.isArray(navigation) || navigation.length === 0) {\n console.warn('[nswds/ui] PushMenu received no navigation items — the menu renders empty.')\n return\n }\n const seen = new Set<string>()\n const visit = (items: PushMenuItem[]) => {\n for (const item of items) {\n if (!item?.id || !item.title) {\n console.warn('[nswds/ui] PushMenu navigation item is missing an `id` or `title`:', item)\n continue\n }\n if (seen.has(item.id)) {\n console.warn(\n `[nswds/ui] PushMenu navigation contains duplicate id \"${item.id}\" — level ids and focus restoration track items by id, so ids must be unique across the whole tree.`,\n )\n }\n seen.add(item.id)\n if (!item.href && !item.links?.length) {\n console.warn(\n `[nswds/ui] PushMenu item \"${item.id}\" has neither an href nor children — it renders as a button that only fires onItemClick.`,\n )\n }\n if (item.links?.length) {\n visit(item.links)\n }\n }\n }\n visit(navigation)\n}\n\n// One treatment for every row — drill-in buttons and leaf links alike — so the\n// two read as a single list. Tokenized from the nswds-app source's\n// border-l + primary-800 active pattern, with dark-mode equivalents the app\n// lacked (its grey-800-on-white text disappeared in dark mode).\nconst itemBaseClassName = [\n // min-h-11 guarantees the 44px minimum target size (WCAG 2.2, 2.5.8 Target\n // Size) even for single-line rows with compact padding overrides.\n 'relative flex min-h-11 w-full cursor-pointer items-center justify-between gap-x-6 border-l p-4 text-left text-base',\n 'motion-safe:transition-colors',\n 'hover:border-primary-800 hover:bg-primary-800/10 dark:hover:border-primary-200 dark:hover:bg-primary-200/10',\n // Inset outline (negative offset): the levels scroll inside an\n // overflow-hidden root, so an outward offset would be clipped on the first\n // and last rows (WCAG 2.2, 2.4.13 Focus Appearance).\n 'focus-visible:outline focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-primary-800 dark:focus-visible:outline-primary-200',\n].join(' ')\n\nconst itemActiveClassName =\n 'border-primary-800 bg-primary-800/10 font-semibold text-primary-800 dark:border-primary-200 dark:bg-primary-200/10 dark:text-primary-200'\n\nconst itemInactiveClassName = 'border-transparent text-popover-foreground'\n\ntype PushMenuProps = Omit<React.ComponentPropsWithoutRef<'nav'>, 'children' | 'title'> & {\n /** The menu tree. Item ids must be unique across the whole tree. */\n navigation: PushMenuItem[]\n /**\n * The app's current pathname. Leaf links whose `href` matches get\n * `aria-current=\"page\"` and the active treatment. Replaces the nswds-app\n * source's `usePathname()` — the design system is framework-free, so the\n * router value is passed in rather than read from next/navigation.\n */\n currentHref?: string\n /** Root level title, shown in the header row. Also the default `aria-label`. */\n title?: string\n /** Fired when a leaf item (link or child-less button) is activated. */\n onItemClick?: (item: PushMenuItem) => void\n /** Fired after a forward/back slide settles on a level. */\n onNavigate?: (level: PushMenuLevel, history: PushMenuLevel[]) => void\n /**\n * Renders a close button in the header row when provided. Unlike the\n * nswds-app source — which only offered close on sub-levels, leaving the\n * root level uncloseable — the button renders on every level.\n */\n onClose?: () => void\n /** Show the \"A › B › C\" trail under the header on sub-levels. Defaults to `true`. */\n showBreadcrumbs?: boolean\n /**\n * Slide duration in milliseconds, defaulting to `PUSH_MENU_DURATION_MS`\n * (300). Drives both the `--push-menu-duration` custom property and the\n * state machine's timeouts — tune the slide here, never by overriding the\n * custom property (see the coupling note on the constant).\n */\n durationMs?: number\n /** Label for the Back button on sub-levels. Defaults to `'Back'`. */\n backLabel?: string\n /** Accessible label for the close button. Defaults to `'Close menu'`. */\n closeLabel?: string\n /**\n * Heading level for the per-level title, following `FooterNavColumn`'s\n * precedent (the nswds-app source used a `Heading` component this package\n * does not ship). Defaults to `2`; `1` is excluded because a menu panel\n * title is never the page's own title.\n */\n headingLevel?: 2 | 3 | 4 | 5 | 6\n ref?: React.Ref<HTMLElement>\n}\n\n/**\n * Multi-level slide-in-place drill-down menu (\"push menu\") for mobile\n * navigation, ported from nswds-app's `MultiLevelPushMenu`. Items with\n * children render as buttons that slide a new level in from the right; leaf\n * items render as links through `Link`, so apps can inject their framework\n * link component via `LinkProvider`. Fill height from its container — compose\n * it inside `SheetContent side=\"left\"` for the classic mobile drawer.\n *\n * Accessibility contract (all improvements over the nswds-app source, which\n * got several of these wrong):\n *\n * - The root is a `nav` landmark named by `title` (override with `aria-label`).\n * - Non-current levels carry the `inert` attribute, so a hidden level's links\n * are neither tabbable nor exposed to assistive tech. The app left every\n * mounted level in the tab order, letting keyboard users tab into invisible\n * history levels (WCAG 2.2, 2.4.3 Focus Order).\n * - Focus moves with the level change (2.4.3): drilling forward focuses the\n * new level's Back button; going back focuses the item that opened the\n * level just left, tracked by item id and restored after the slide settles.\n * Without this, `inert` on the old level would silently drop focus to\n * `<body>`. The Back button is the only route back (the breadcrumb is\n * decorative), so it always renders on sub-levels — hiding it would make\n * drill-down one-way.\n * - A single visually-hidden `aria-live=\"polite\"` region at the root announces\n * the current level's title, suffixed with the level number below the root.\n * A live attribute on the per-level headings would not work: each level's\n * heading is freshly mounted, and newly-mounted live regions are not\n * reliably announced.\n * - Level lists are `<ul role=\"list\">` — `list-style: none` strips list\n * semantics in some screen reader/browser pairings (notably VoiceOver), and\n * the explicit role restores them.\n * - Every row is at least 44px tall (2.5.8 Target Size); Back/close buttons\n * inherit `Button`'s 44px touch target.\n * - During the slide, rows get `pointer-events-none` and the state machine\n * ignores re-entrant navigation, but nothing is ever `disabled` — disabling\n * the focused Back button mid-animation would eject keyboard focus.\n * - Slides are CSS transforms applied under `motion-safe:`, replacing the app's\n * inline transition strings (which ignored reduced motion).\n *\n * Departures from the nswds-app source, beyond the above:\n *\n * - The footer/stats block (Level N, item counts, progress dots, lucide\n * icons) is cut, along with its `showStats`/`showFooter` props: it was demo\n * chrome for the sandbox, not part of a navigation component's job. The\n * breadcrumb trail it hosted moves under the header row.\n * - The rendered \"Navigation Error\" fallback for malformed data is replaced\n * by a dev-only console warning (`warnIfNavigationMalformed`), mirroring\n * button.tsx's `warnIfIconButtonUnlabelled`.\n * - The breadcrumb trail is `aria-hidden`: it repeats what the heading and\n * live region already announce, and \"›\" separators read poorly in AT.\n *\n * The level stack is seeded from `navigation`/`title` on mount; pass a `key`\n * to remount (and reset to the root level) if either changes at runtime.\n */\nfunction PushMenu({\n navigation,\n currentHref,\n title = 'Menu',\n onItemClick,\n onNavigate,\n onClose,\n showBreadcrumbs = true,\n durationMs = PUSH_MENU_DURATION_MS,\n backLabel = 'Back',\n closeLabel = 'Close menu',\n headingLevel = 2,\n className,\n style,\n 'aria-label': ariaLabel,\n ref,\n ...props\n}: PushMenuProps) {\n const [navigationHistory, setNavigationHistory] = React.useState<PushMenuLevel[]>(() => [\n { items: navigation, title, depth: 1, id: buildLevelId([]) },\n ])\n const [animationState, setAnimationState] = React.useState<PushMenuAnimationState>('idle')\n const [isAnimationStarted, setIsAnimationStarted] = React.useState(false)\n\n const containerRef = React.useRef<HTMLElement | null>(null)\n const timeoutRef = React.useRef<number | null>(null)\n // Focus target applied by the effect below, after React commits the level\n // change — the target element must exist and must no longer be inert.\n const pendingFocusRef = React.useRef<{ levelId: string; itemId?: string } | null>(null)\n\n warnIfNavigationMalformed(navigation)\n\n React.useEffect(() => {\n return () => {\n if (timeoutRef.current !== null) {\n window.clearTimeout(timeoutRef.current)\n }\n }\n }, [])\n\n // Layout effect, not a passive one: the same commit that queues a focus\n // move can also flip the previously-focused element inert (drilling turns\n // the old level inert; going back turns the departing level inert), and the\n // browser blurs an element the moment it becomes inert. Applying the new\n // focus before paint means AT never observes the intermediate\n // focus-on-body state, and a containing dialog's focus guards (Base UI\n // Sheet) see focus already inside the popup when their async handlers run.\n React.useLayoutEffect(() => {\n const pending = pendingFocusRef.current\n if (!pending) {\n return\n }\n pendingFocusRef.current = null\n const level = containerRef.current?.querySelector<HTMLElement>(\n `[data-level-id=\"${CSS.escape(pending.levelId)}\"]`,\n )\n if (!level) {\n return\n }\n const target = pending.itemId\n ? level.querySelector<HTMLElement>(`[data-item-id=\"${CSS.escape(pending.itemId)}\"]`)\n : (level.querySelector<HTMLElement>('[data-slot=\"push-menu-back-button\"]') ??\n level.querySelector<HTMLElement>(\n '[data-slot=\"push-menu-item\"], [data-slot=\"push-menu-link\"]',\n ))\n // preventScroll: a level mid-slide sits at translateX(100%) inside an\n // overflow-hidden root; letting focus scroll it into view would desync the\n // container's scroll position from the transform.\n target?.focus({ preventScroll: true })\n // animationState is a dependency because back-navigation queues its focus\n // move on the slide START (an animationState commit), not on the level\n // pop — see navigateBack.\n }, [navigationHistory, animationState])\n\n const breadcrumb = React.useMemo(\n // During a back slide the trail already excludes the departing level —\n // the breadcrumb tracks the level the user is arriving at (see\n // activeIndex below), same as the live region.\n () =>\n generatePushMenuBreadcrumb(\n animationState === 'sliding-backward' ? navigationHistory.slice(0, -1) : navigationHistory,\n ),\n [navigationHistory, animationState],\n )\n\n function navigateToSubmenu(item: PushMenuItem) {\n if (!item.links?.length || animationState !== 'idle') {\n return\n }\n const levelPath = [\n ...navigationHistory.flatMap((level) => (level.parentItem ? [level.parentItem.id] : [])),\n item.id,\n ]\n const currentDepth = navigationHistory.at(-1)?.depth ?? 1\n const newLevel: PushMenuLevel = {\n items: item.links,\n title: item.title,\n parentItem: item,\n depth: currentDepth + 1,\n id: buildLevelId(levelPath),\n }\n const newHistory = [...navigationHistory, newLevel]\n\n // Focus moves as soon as the new level commits (see the effect above):\n // waiting for the slide to finish would leave focus on the old level,\n // which turns inert in the same commit and would eject focus to <body>.\n pendingFocusRef.current = { levelId: newLevel.id }\n setNavigationHistory(newHistory)\n setAnimationState('sliding-forward')\n setIsAnimationStarted(false)\n\n // Two-step start: the new level mounts at translateX(100%) with no\n // transition, then flips to 0 with the transition on. The layout read in\n // between is LOAD-BEARING: without it, nothing forces the browser to\n // compute styles for the mounted-at-100% frame, and when both states land\n // in one style recalc there is no transition — the panel snaps into\n // place instead of sliding (an intermittent, timing-dependent jump).\n // Reading layout inside the rAF forces that recalc deterministically.\n requestAnimationFrame(() => {\n containerRef.current?.getBoundingClientRect()\n setIsAnimationStarted(true)\n })\n\n timeoutRef.current = window.setTimeout(() => {\n setAnimationState('idle')\n setIsAnimationStarted(false)\n onNavigate?.(newLevel, newHistory)\n }, durationMs)\n }\n\n function navigateBack() {\n if (navigationHistory.length <= 1 || animationState !== 'idle') {\n return\n }\n const popped = navigationHistory.at(-1)\n const revealed = navigationHistory.at(-2)\n if (!revealed) {\n return\n }\n\n // Focus moves at slide START, symmetric with drilling forward: the\n // 'sliding-backward' commit un-inerts the revealed level (see the\n // activeIndex logic below) and the effect above focuses the item that\n // opened the departing level. Restoring focus at the POP instead — while\n // focus still sat on the departing level's Back button — meant the\n // focused node was removed from a live dialog, and Base UI's focus\n // containment would re-grab focus to the dialog popup a frame after our\n // restoration, silently overriding it (observed inside Sheet).\n pendingFocusRef.current = { levelId: revealed.id, itemId: popped?.parentItem?.id }\n setAnimationState('sliding-backward')\n\n timeoutRef.current = window.setTimeout(() => {\n const newHistory = navigationHistory.slice(0, -1)\n setNavigationHistory(newHistory)\n setAnimationState('idle')\n onNavigate?.(revealed, newHistory)\n }, durationMs)\n }\n\n const currentLevel = navigationHistory.at(-1)\n if (!currentLevel) {\n return null\n }\n\n const isAnimating = animationState !== 'idle'\n // The level the user is arriving AT — the stack top, except during a back\n // slide, where the user's intent has already committed to the level being\n // revealed underneath. data-current, inert, the live region and the\n // breadcrumb all follow this index so focus can land on the revealed level\n // at slide start and AT hears the destination, not the departing level.\n const activeIndex =\n animationState === 'sliding-backward'\n ? navigationHistory.length - 2\n : navigationHistory.length - 1\n const activeLevel = navigationHistory[activeIndex] ?? currentLevel\n const HeadingTag = `h${headingLevel}` as const\n\n return (\n <nav\n data-slot='push-menu'\n aria-label={ariaLabel ?? title}\n // Present while a slide is running (matches header's present-or-absent\n // data-scrolled convention). Consumers can style the transition off it;\n // tests use it to wait for the state machine to go idle — clicks during\n // a slide are dropped by design, and pointer-events-none does not stop\n // a programmatic .click().\n data-animating={isAnimating || undefined}\n {...props}\n className={cn(\n 'relative isolate h-full overflow-hidden bg-popover text-popover-foreground',\n className,\n )}\n // The slide duration custom property is set from durationMs so the CSS\n // transition and the setTimeout state machine can never disagree — see\n // the coupling note on PUSH_MENU_DURATION_MS.\n style={{ ...style, '--push-menu-duration': `${durationMs}ms` } as React.CSSProperties}\n ref={(node) => {\n containerRef.current = node\n if (typeof ref === 'function') {\n ref(node)\n } else if (ref) {\n ;(ref as React.RefObject<HTMLElement | null>).current = node\n }\n }}\n >\n {/* Persistent live region: announces level changes to AT without\n stealing focus from the managed focus moves. The level number is\n appended below the root because live regions only re-announce when\n their content actually changes — navigating between identically-\n titled levels would otherwise announce nothing. Consecutive levels\n always differ in depth, so consecutive announcements always differ. */}\n <div data-slot='push-menu-live-region' aria-live='polite' className='sr-only'>\n {activeLevel.depth > 1\n ? `${activeLevel.title}, level ${activeLevel.depth}`\n : activeLevel.title}\n </div>\n\n {navigationHistory.map((level, index) => {\n // The stack top is the level that MOVES (slides in forward, slides\n // out backward); the active level is the one the user is arriving at\n // — they differ only during a back slide.\n const isTopLevel = index === navigationHistory.length - 1\n const isActiveLevel = index === activeIndex\n // Always shown below the root: the Back button is the ONLY route back\n // (the breadcrumb is aria-hidden and there is no keyboard binding or\n // imperative API), so making it optional would strand users.\n const shouldShowBackButton = level.depth > 1\n\n let translateX = 0\n if (animationState === 'sliding-forward') {\n translateX = isTopLevel ? (isAnimationStarted ? 0 : 100) : 0\n } else if (animationState === 'sliding-backward') {\n translateX = isTopLevel ? 100 : 0\n }\n\n // Only the moving (top) level transitions; forward slides wait for\n // the second frame so the mount position is applied untransitioned.\n const isSliding =\n isTopLevel &&\n (animationState === 'sliding-backward' ||\n (animationState === 'sliding-forward' && isAnimationStarted))\n\n return (\n <div\n key={level.id}\n data-slot='push-menu-level'\n data-level-id={level.id}\n data-current={isActiveLevel || undefined}\n // Non-active levels must be invisible to keyboard and AT, not\n // just to the eye. Keying this on the ACTIVE level (not the stack\n // top) un-inerts the revealed level at back-slide start, so focus\n // can move there immediately — and the focused Back button is\n // never removed from a live dialog while still focused.\n inert={!isActiveLevel}\n className={cn(\n 'absolute inset-0 flex h-full w-full flex-col bg-popover will-change-transform',\n isSliding\n ? 'duration-(--push-menu-duration) ease-out motion-safe:transition-transform'\n : 'transition-none',\n )}\n style={{ transform: `translateX(${translateX}%)`, zIndex: index + 1 }}\n >\n <div\n data-slot='push-menu-header'\n className='flex min-h-11 items-center gap-1 border-b border-border px-2 py-2'\n >\n {shouldShowBackButton && (\n <Button\n data-slot='push-menu-back-button'\n variant='ghost'\n color='primary'\n size='sm'\n leadingVisual={IconWest}\n onClick={navigateBack}\n className={cn(isAnimating && 'pointer-events-none')}\n >\n {backLabel}\n </Button>\n )}\n <HeadingTag\n data-slot='push-menu-title'\n className='min-w-0 flex-1 truncate px-2 text-base font-semibold'\n >\n {level.title}\n </HeadingTag>\n {onClose && (\n <Button\n data-slot='push-menu-close-button'\n variant='ghost'\n color='grey'\n size='icon'\n aria-label={closeLabel}\n leadingVisual={IconClose}\n onClick={onClose}\n />\n )}\n </div>\n\n {showBreadcrumbs && isActiveLevel && level.depth > 1 && (\n // aria-hidden: the trail repeats what the heading and live\n // region already announce, and \"›\" separators read poorly in AT.\n <p\n data-slot='push-menu-breadcrumb'\n aria-hidden='true'\n className='truncate border-b border-border px-4 py-2 text-xs text-muted-foreground'\n >\n {breadcrumb}\n </p>\n )}\n\n <div data-slot='push-menu-items' className='flex-1 overflow-y-auto'>\n {/* role='list' restores list semantics stripped by list-none. */}\n <ul role='list' className='m-0 list-none divide-y divide-border p-0'>\n {level.items.map((item) => {\n const hasChildren = Boolean(item.links?.length)\n const isActive = item.href != null && item.href === currentHref\n\n return (\n <li key={item.id}>\n {hasChildren ? (\n <button\n type='button'\n data-slot='push-menu-item'\n data-item-id={item.id}\n onClick={() => navigateToSubmenu(item)}\n className={cn(\n itemBaseClassName,\n isActive ? itemActiveClassName : itemInactiveClassName,\n isAnimating && 'pointer-events-none',\n )}\n >\n <span className='min-w-0 flex-1 truncate'>{item.title}</span>\n <IconChevronRight aria-hidden='true' className='size-5 shrink-0' />\n </button>\n ) : item.href ? (\n <Link\n variant='unstyled'\n data-slot='push-menu-link'\n data-item-id={item.id}\n href={item.href}\n aria-current={isActive ? 'page' : undefined}\n onClick={() => onItemClick?.(item)}\n className={cn(\n itemBaseClassName,\n isActive ? itemActiveClassName : itemInactiveClassName,\n isAnimating && 'pointer-events-none',\n )}\n >\n <span className='min-w-0 flex-1 truncate'>{item.title}</span>\n </Link>\n ) : (\n <button\n type='button'\n data-slot='push-menu-item'\n data-item-id={item.id}\n onClick={() => onItemClick?.(item)}\n className={cn(\n itemBaseClassName,\n itemInactiveClassName,\n isAnimating && 'pointer-events-none',\n )}\n >\n <span className='min-w-0 flex-1 truncate'>{item.title}</span>\n </button>\n )}\n </li>\n )\n })}\n </ul>\n </div>\n </div>\n )\n })}\n </nav>\n )\n}\n\nexport { generatePushMenuBreadcrumb, PUSH_MENU_DURATION_MS, PushMenu }\nexport type { PushMenuItem, PushMenuLevel, PushMenuProps }\n"]}
|
|
@@ -8,8 +8,8 @@ import { IconChevronRight } from '../icons/chevron-right.js';
|
|
|
8
8
|
|
|
9
9
|
const sideNavRowVariants = cva(
|
|
10
10
|
[
|
|
11
|
-
"w-full cursor-pointer rounded-r-sm border-l border-transparent py-1 pr-2 pl-4 text-left text-base/8 sm:text-sm/6",
|
|
12
|
-
"
|
|
11
|
+
"w-full cursor-pointer rounded-r-sm border-l border-transparent py-1 pr-2 pl-4 text-left max-sm:text-base/8 sm:text-sm/6",
|
|
12
|
+
"motion-safe:transition-colors",
|
|
13
13
|
"hover:border-grey-950 hover:bg-primary-800/10 hover:font-semibold hover:text-grey-950",
|
|
14
14
|
"dark:text-grey-400 dark:hover:border-grey-400 dark:hover:text-white",
|
|
15
15
|
"focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-current"
|
|
@@ -59,7 +59,7 @@ function SideNavList({ items, currentHref, onNavigate, nested = false }) {
|
|
|
59
59
|
"data-slot": "side-nav-list",
|
|
60
60
|
className: cn(
|
|
61
61
|
"flex flex-col border-l border-grey-400 dark:border-grey-200/15",
|
|
62
|
-
nested ? "mt-2 ml-5 gap-1" : "
|
|
62
|
+
nested ? "mt-2 ml-5 gap-1" : "gap-2 max-lg:mt-2 lg:mt-4"
|
|
63
63
|
),
|
|
64
64
|
children: items.map((item) => /* @__PURE__ */ jsx(
|
|
65
65
|
SideNavRow,
|
|
@@ -90,7 +90,7 @@ function SideNavRow({ item, currentHref, onNavigate }) {
|
|
|
90
90
|
IconChevronRight,
|
|
91
91
|
{
|
|
92
92
|
"aria-hidden": "true",
|
|
93
|
-
className: "ml-2 size-5 shrink-0
|
|
93
|
+
className: "ml-2 size-5 shrink-0 duration-200 group-data-panel-open:rotate-90 motion-safe:transition-transform"
|
|
94
94
|
}
|
|
95
95
|
)
|
|
96
96
|
]
|
|
@@ -147,7 +147,7 @@ function SideNav({
|
|
|
147
147
|
"data-slot": "side-nav",
|
|
148
148
|
...props,
|
|
149
149
|
"aria-label": ariaLabel,
|
|
150
|
-
className: cn("text-
|
|
150
|
+
className: cn("text-grey-800 max-lg:text-base lg:text-sm dark:text-grey-400", className),
|
|
151
151
|
ref,
|
|
152
152
|
children: /* @__PURE__ */ jsx("ul", { role: "list", "data-slot": "side-nav-sections", className: "flex flex-col gap-9", children: sections.map((section) => /* @__PURE__ */ jsx("li", { "data-slot": "side-nav-section", children: section.links ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
153
153
|
/* @__PURE__ */ jsx(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/side-nav.tsx"],"names":[],"mappings":";;;;;;;AAoDA,MAAM,kBAAA,GAAqB,GAAA;AAAA,EACzB;AAAA,IACE,kHAAA;AAAA,IACA,iDAAA;AAAA,IACA,uFAAA;AAAA,IACA,qEAAA;AAAA,IACA;AAAA,GACF;AAAA,EACA;AAAA,IACE,QAAA,EAAU;AAAA,MACR,OAAA,EAAS;AAAA,QACP,IAAA,EAAM,oHAAA;AAAA,QACN,KAAA,EAAO;AAAA;AACT,KACF;AAAA,IACA,eAAA,EAAiB;AAAA,MACf,OAAA,EAAS;AAAA;AACX;AAEJ;AAOA,SAAS,yBAAA,CAA0B,MAAmB,WAAA,EAA0C;AAC9F,EAAA,IAAI,gBAAgB,MAAA,EAAW;AAC7B,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,IAAI,IAAA,CAAK,SAAS,WAAA,EAAa;AAC7B,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,OAAO,IAAA,CAAK,OAAO,IAAA,CAAK,CAAC,UAAU,yBAAA,CAA0B,KAAA,EAAO,WAAW,CAAC,CAAA,IAAK,KAAA;AACvF;AASA,SAAS,oBAAoB,IAAA,EAAmB;AAC9C,EAAA,IAAI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,EACrD,QAAA,EAAA,QAAA,CAAS,GAAA,CAAI,CAAC,4BACb,GAAA,CAAC,IAAA,EAAA,EAAuC,aAAU,kBAAA,EAC/C,QAAA,EAAA,OAAA,CAAQ,wBACP,IAAA,CAAA,QAAA,EAAA,EAIE,QAAA,EAAA;AAAA,wBAAA,GAAA;AAAA,UAAC,OAAA;AAAA,UAAA;AAAA,YACC,WAAA,EAAU,kBAAA;AAAA,YACV,SAAA,EAAU,wDAAA;AAAA,YAET,QAAA,EAAA,OAAA,CAAQ;AAAA;AAAA,SACX;AAAA,wBACA,GAAA;AAAA,UAAC,WAAA;AAAA,UAAA;AAAA,YACC,OAAO,OAAA,CAAQ,KAAA;AAAA,YACf,WAAA;AAAA,YACA;AAAA;AAAA;AACF,OAAA,EACF,CAAA;AAAA;AAAA;AAAA,4BAIC,WAAA,EAAA,EAAY,KAAA,EAAO,CAAC,OAAO,CAAA,EAAG,aAA0B,UAAA,EAAwB;AAAA,OAAA,EAAA,EArB5E,OAAA,CAAQ,IAAA,IAAQ,OAAA,CAAQ,KAuBjC,CACD,CAAA,EACH;AAAA;AAAA,GACF;AAEJ","file":"side-nav.js","sourcesContent":["'use client'\n\nimport { cva, type VariantProps } from 'class-variance-authority'\nimport React from 'react'\n\nimport { cn } from '../lib/utils.js'\n\nimport { Collapsible, CollapsibleContent, CollapsibleTrigger } from '../components/collapsible.js'\nimport { Link } from '../components/link.js'\nimport { IconChevronRight } from '../icons/chevron-right.js'\n\n/**\n * One entry in a `SideNav` tree.\n *\n * - `href` and no `links` — a leaf link.\n * - `links` — a branch. At the top level it renders as a section heading over an\n * always-visible list; at any deeper level it renders as a collapsible\n * trigger. A branch's own `href` is IGNORED (the row is a disclosure button,\n * not a link) — a dev-only warning flags it, mirroring the nswds-app\n * `SidebarNavigation` behaviour where branch rows only toggled.\n * - Neither — a dead entry; rendered as inert text and flagged with a dev-only\n * warning rather than a decoy `<a>` with no destination.\n */\ntype SideNavItem = {\n /** Visible text for the link, section heading, or branch trigger. */\n title: string\n href?: string\n links?: SideNavItem[]\n}\n\n/**\n * Row treatment shared by leaf links and branch triggers — the nswds-app\n * left-rail language: each row carries its own left border sitting exactly on\n * the list's rail (the `-ml-px` on the `<li>`), so hover and the current-page\n * state recolour the rail segment beside the row.\n *\n * Departures from the source, both deliberate:\n * - The idle border is `border-transparent` rather than the bare `border-l`\n * default: idle rows show the rail through their transparent border, so the\n * idle rail colour is defined once (on the list) instead of twice.\n * - The current row adds `dark:text-white`. The source left dark active text\n * to fall through to the idle `dark:text-grey-400`, which on the\n * `dark:bg-white/20` highlight is both low-contrast and cascade-order\n * dependent; bold white ink clears WCAG 2.2 AA (1.4.3) on that overlay.\n *\n * The hover font-weight change (`hover:font-semibold`) is source parity; it\n * reflows the row's own text only, never the rail.\n *\n * Focus uses the house visible-focus pattern (outline-current, offset 2), so\n * the indicator always contrasts with whatever text colour the row currently\n * has (WCAG 2.2, 2.4.13 Focus Appearance).\n */\nconst sideNavRowVariants = cva(\n [\n 'w-full cursor-pointer rounded-r-sm border-l border-transparent py-1 pr-2 pl-4 text-left text-base/8 sm:text-sm/6',\n 'transition-colors motion-reduce:transition-none',\n 'hover:border-grey-950 hover:bg-primary-800/10 hover:font-semibold hover:text-grey-950',\n 'dark:text-grey-400 dark:hover:border-grey-400 dark:hover:text-white',\n 'focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-current',\n ],\n {\n variants: {\n current: {\n true: 'border-primary-800 bg-primary-800/10 font-bold text-primary-800 dark:border-white dark:bg-white/20 dark:text-white',\n false: '',\n },\n },\n defaultVariants: {\n current: false,\n },\n },\n)\n\n/**\n * Port of nswds-app's `isLinkOrDescendantActive`: true when the item itself,\n * or any item anywhere beneath it, is the current page. Drives `defaultOpen`\n * on branch collapsibles so the rail opens onto the reader's location.\n */\nfunction isItemOrDescendantCurrent(item: SideNavItem, currentHref: string | undefined): boolean {\n if (currentHref === undefined) {\n return false\n }\n if (item.href === currentHref) {\n return true\n }\n return item.links?.some((child) => isItemOrDescendantCurrent(child, currentHref)) ?? false\n}\n\n/**\n * Dev-only guard, mirroring the icon-only Button check in button.tsx: an item\n * with neither destination nor children renders as inert text (a decoy link\n * would violate WCAG 2.2, 4.1.2 Name, Role, Value expectations), and a branch's\n * `href` is silently unreachable because the row renders as a disclosure\n * button. Both are almost certainly data mistakes. No-op in production.\n */\nfunction warnIfItemMisshapen(item: SideNavItem) {\n if (process.env.NODE_ENV === 'production') {\n return\n }\n const hasChildren = (item.links?.length ?? 0) > 0\n if (!hasChildren && item.href === undefined) {\n console.warn(\n `[nswds/ui] SideNav item \"${item.title}\" has neither href nor links — it renders as inert text. Give it a destination or children.`,\n )\n }\n if (hasChildren && item.href !== undefined) {\n console.warn(\n `[nswds/ui] SideNav item \"${item.title}\" has both href and links — branch rows render as collapsible triggers, so its href is unreachable. Add a separate leaf item for the destination.`,\n )\n }\n}\n\ntype SideNavListProps = {\n items: SideNavItem[]\n currentHref?: string\n onNavigate?: React.MouseEventHandler<HTMLAnchorElement>\n /** Deeper than the section rail — tighter gap, indented, per the source. */\n nested?: boolean\n}\n\n/**\n * A rail of rows: the bordered `<ul>` every level of the tree renders into.\n * `role='list'` is kept from the source — Safari/VoiceOver strips list\n * semantics from lists whose `list-style` is removed, and the explicit role\n * restores them (this is the one sanctioned hand-written role in the file).\n */\nfunction SideNavList({ items, currentHref, onNavigate, nested = false }: SideNavListProps) {\n return (\n <ul\n role='list'\n data-slot='side-nav-list'\n className={cn(\n 'flex flex-col border-l border-grey-400 dark:border-grey-200/15',\n nested ? 'mt-2 ml-5 gap-1' : 'mt-2 gap-2 lg:mt-4',\n )}\n >\n {items.map((item) => (\n <SideNavRow\n key={item.href ?? item.title}\n item={item}\n currentHref={currentHref}\n onNavigate={onNavigate}\n />\n ))}\n </ul>\n )\n}\n\ntype SideNavRowProps = {\n item: SideNavItem\n currentHref?: string\n onNavigate?: React.MouseEventHandler<HTMLAnchorElement>\n}\n\n/**\n * One row of the rail — a leaf link, a collapsible branch, or (data mistake)\n * inert text. Recurses through `SideNavList` for branch children.\n */\nfunction SideNavRow({ item, currentHref, onNavigate }: SideNavRowProps) {\n const hasChildren = (item.links?.length ?? 0) > 0\n const isCurrent = currentHref !== undefined && item.href === currentHref\n\n warnIfItemMisshapen(item)\n\n if (hasChildren) {\n return (\n <li data-slot='side-nav-item' className='-ml-px flex w-full flex-col items-start gap-1'>\n {/* defaultOpen (not controlled `open`) so the branch holding the\n current page starts expanded but the reader can still fold it —\n the source's auto-expansion behaviour exactly. */}\n <Collapsible className='w-full' defaultOpen={isItemOrDescendantCurrent(item, currentHref)}>\n {/* Base UI's Trigger owns the disclosure semantics (aria-expanded,\n aria-controls, keyboard activation) — nothing hand-rolled here.\n `group` scopes the chevron's rotation to THIS trigger: nested\n triggers are never ancestors of each other's icons, and the\n Collapsible root carries data-open (not data-panel-open), so an\n open outer branch cannot rotate descendant chevrons. */}\n <CollapsibleTrigger\n data-slot='side-nav-trigger'\n className={cn(sideNavRowVariants(), 'group flex items-center justify-between gap-1')}\n >\n <span>{item.title}</span>\n <IconChevronRight\n aria-hidden='true'\n className='ml-2 size-5 shrink-0 transition-transform duration-200 group-data-panel-open:rotate-90 motion-reduce:transition-none'\n />\n </CollapsibleTrigger>\n <CollapsibleContent data-slot='side-nav-panel'>\n <SideNavList\n items={item.links ?? []}\n currentHref={currentHref}\n onNavigate={onNavigate}\n nested\n />\n </CollapsibleContent>\n </Collapsible>\n </li>\n )\n }\n\n if (item.href === undefined) {\n // No destination, no children: inert text, not a decoy anchor. The\n // dev-only warning above names the item.\n return (\n <li data-slot='side-nav-item' className='-ml-px flex w-full flex-col items-start gap-1'>\n <span\n data-slot='side-nav-text'\n className={cn(sideNavRowVariants(), 'inline-block cursor-default')}\n >\n {item.title}\n </span>\n </li>\n )\n }\n\n return (\n <li data-slot='side-nav-item' className='-ml-px flex w-full flex-col items-start gap-1'>\n {/* variant='unstyled' — the rail supplies the complete row treatment;\n Link's underline/colour variants would fight it. Rendering through\n Link still picks up the framework link component from LinkProvider\n (next/link et al). */}\n <Link\n variant='unstyled'\n data-slot='side-nav-link'\n href={item.href}\n onClick={onNavigate}\n aria-current={isCurrent ? 'page' : undefined}\n className={cn(sideNavRowVariants({ current: isCurrent }), 'inline-block')}\n >\n {item.title}\n </Link>\n </li>\n )\n}\n\ntype SideNavProps = Omit<React.ComponentPropsWithoutRef<'nav'>, 'children'> & {\n /**\n * The navigation tree. A top-level item with `links` renders as a section\n * heading over an always-visible rail; one without renders as a plain rail\n * link — mirroring nswds-app `Navigation`'s section shape. Deeper items with\n * `links` render as collapsible branches (nswds-app `SidebarNavigation`).\n */\n sections: SideNavItem[]\n /**\n * The current page's href. The matching leaf gets `aria-current='page'` and\n * the active rail treatment, and every branch on the path to it starts\n * expanded — at MOUNT only. Branches are `defaultOpen`, not controlled: a\n * later `currentHref` change (SPA navigation) re-highlights the leaf but\n * never re-expands a branch the reader has folded, so the highlight can\n * land inside a collapsed branch. Branch expansion is seeded from\n * `currentHref` on mount; pass a `key` (e.g. `key={currentHref}`) to\n * remount and re-open the path on navigation — the same contract as\n * PushMenu's level stack. Frameworkless replacement for the source's\n * `usePathname()` — pass your router's pathname in.\n */\n currentHref?: string\n /**\n * Fired from every leaf link (never from branch triggers). The mobile-drawer\n * close hook, as in the source's `onLinkClick`.\n */\n onNavigate?: React.MouseEventHandler<HTMLAnchorElement>\n /**\n * Heading level for section titles. Defaults to `2` — correct when the nav\n * sits at the top level of the document outline. Step it down when the page\n * nests the nav under another heading (WCAG 1.3.1). `1` is excluded: a\n * section-nav heading is never the page's own title. Same contract as\n * `FooterNavColumn`.\n */\n headingLevel?: 2 | 3 | 4 | 5 | 6\n ref?: React.Ref<HTMLElement>\n}\n\n/**\n * Left-rail section navigation — the consolidation of nswds-app's flat\n * `Navigation` and recursive `SidebarNavigation` into one tree-shaped\n * component. Renders a `<nav>` landmark of headed sections whose links may\n * nest to any depth; nested branches collapse.\n *\n * Accessibility contract:\n * - The landmark is named (`aria-label`, default \"Section navigation\") so it is\n * distinguishable from the page's other navigation landmarks (WCAG 1.3.1).\n * - Disclosure semantics — `aria-expanded`, `aria-controls`, Enter/Space\n * activation — come entirely from Base UI's Collapsible; nothing hand-rolled.\n * - The current page is marked with `aria-current='page'`, and every branch on\n * the path to it starts expanded ON MOUNT, so the highlighted location is\n * visible on arrival (ported `isLinkOrDescendantActive`). Expansion is\n * `defaultOpen`, so it does not re-run when `currentHref` changes — see the\n * `currentHref` prop for the `key={currentHref}` remount workaround.\n * - Focus is always visible via the house `outline-current` pattern (2.4.13).\n *\n * Departures from the nswds-app source (see also `sideNavRowVariants` and\n * `SideNavItem`):\n * - `usePathname()` → the `currentHref` prop; links render through `Link`, so\n * frameworks inject their own anchor via `LinkProvider`.\n * - The Radix-based Collapsible → the Base UI primitive (this repo's\n * `collapsible.tsx`), whose open state is `data-panel-open` on the trigger\n * rather than Radix's `data-state='open'`.\n * - The source rendered a stray empty `<ul>` after link-less sections and sent\n * `href='#'` placeholders through the tree; both are dropped.\n */\nfunction SideNav({\n className,\n sections,\n currentHref,\n onNavigate,\n headingLevel = 2,\n 'aria-label': ariaLabel = 'Section navigation',\n ref,\n ...props\n}: SideNavProps) {\n const Heading = `h${headingLevel}` as const\n\n return (\n <nav\n data-slot='side-nav'\n {...props}\n aria-label={ariaLabel}\n // Base ink declared once here (the source inherited the page body's\n // colour in light mode; a design-system component states it).\n className={cn('text-base text-grey-800 lg:text-sm dark:text-grey-400', className)}\n ref={ref}\n >\n <ul role='list' data-slot='side-nav-sections' className='flex flex-col gap-9'>\n {sections.map((section) => (\n <li key={section.href ?? section.title} data-slot='side-nav-section'>\n {section.links ? (\n <>\n {/* font-display resolves through @nswds/tokens' Tailwind\n preset (--font-display, Public Sans stack) — the same\n utility the source used. */}\n <Heading\n data-slot='side-nav-heading'\n className='font-display font-medium text-grey-800 dark:text-white'\n >\n {section.title}\n </Heading>\n <SideNavList\n items={section.links}\n currentHref={currentHref}\n onNavigate={onNavigate}\n />\n </>\n ) : (\n // A link-less section is a single rail link (Navigation.tsx\n // parity) — reuse the rail so the border/offset stay identical.\n <SideNavList items={[section]} currentHref={currentHref} onNavigate={onNavigate} />\n )}\n </li>\n ))}\n </ul>\n </nav>\n )\n}\n\nexport { SideNav, sideNavRowVariants }\nexport type { SideNavItem, SideNavProps }\nexport type SideNavRowVariantProps = VariantProps<typeof sideNavRowVariants>\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/components/side-nav.tsx"],"names":[],"mappings":";;;;;;;AAoDA,MAAM,kBAAA,GAAqB,GAAA;AAAA,EACzB;AAAA,IACE,yHAAA;AAAA,IACA,+BAAA;AAAA,IACA,uFAAA;AAAA,IACA,qEAAA;AAAA,IACA;AAAA,GACF;AAAA,EACA;AAAA,IACE,QAAA,EAAU;AAAA,MACR,OAAA,EAAS;AAAA,QACP,IAAA,EAAM,oHAAA;AAAA,QACN,KAAA,EAAO;AAAA;AACT,KACF;AAAA,IACA,eAAA,EAAiB;AAAA,MACf,OAAA,EAAS;AAAA;AACX;AAEJ;AAOA,SAAS,yBAAA,CAA0B,MAAmB,WAAA,EAA0C;AAC9F,EAAA,IAAI,gBAAgB,MAAA,EAAW;AAC7B,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,IAAI,IAAA,CAAK,SAAS,WAAA,EAAa;AAC7B,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,OAAO,IAAA,CAAK,OAAO,IAAA,CAAK,CAAC,UAAU,yBAAA,CAA0B,KAAA,EAAO,WAAW,CAAC,CAAA,IAAK,KAAA;AACvF;AASA,SAAS,oBAAoB,IAAA,EAAmB;AAC9C,EAAA,IAAI,OAAA,CAAQ,GAAA,CAAI,QAAA,KAAa,YAAA,EAAc;AACzC,IAAA;AAAA,EACF;AACA,EAAA,MAAM,WAAA,GAAA,CAAe,IAAA,CAAK,KAAA,EAAO,MAAA,IAAU,CAAA,IAAK,CAAA;AAChD,EAAA,IAAI,CAAC,WAAA,IAAe,IAAA,CAAK,IAAA,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;AAAA,UAAA;AAAA,YACC,WAAA,EAAU,kBAAA;AAAA,YACV,SAAA,EAAU,wDAAA;AAAA,YAET,QAAA,EAAA,OAAA,CAAQ;AAAA;AAAA,SACX;AAAA,wBACA,GAAA;AAAA,UAAC,WAAA;AAAA,UAAA;AAAA,YACC,OAAO,OAAA,CAAQ,KAAA;AAAA,YACf,WAAA;AAAA,YACA;AAAA;AAAA;AACF,OAAA,EACF,CAAA;AAAA;AAAA;AAAA,4BAIC,WAAA,EAAA,EAAY,KAAA,EAAO,CAAC,OAAO,CAAA,EAAG,aAA0B,UAAA,EAAwB;AAAA,OAAA,EAAA,EArB5E,OAAA,CAAQ,IAAA,IAAQ,OAAA,CAAQ,KAuBjC,CACD,CAAA,EACH;AAAA;AAAA,GACF;AAEJ","file":"side-nav.js","sourcesContent":["'use client'\n\nimport { cva, type VariantProps } from 'class-variance-authority'\nimport React from 'react'\n\nimport { cn } from '../lib/utils.js'\n\nimport { Collapsible, CollapsibleContent, CollapsibleTrigger } from '../components/collapsible.js'\nimport { Link } from '../components/link.js'\nimport { IconChevronRight } from '../icons/chevron-right.js'\n\n/**\n * One entry in a `SideNav` tree.\n *\n * - `href` and no `links` — a leaf link.\n * - `links` — a branch. At the top level it renders as a section heading over an\n * always-visible list; at any deeper level it renders as a collapsible\n * trigger. A branch's own `href` is IGNORED (the row is a disclosure button,\n * not a link) — a dev-only warning flags it, mirroring the nswds-app\n * `SidebarNavigation` behaviour where branch rows only toggled.\n * - Neither — a dead entry; rendered as inert text and flagged with a dev-only\n * warning rather than a decoy `<a>` with no destination.\n */\ntype SideNavItem = {\n /** Visible text for the link, section heading, or branch trigger. */\n title: string\n href?: string\n links?: SideNavItem[]\n}\n\n/**\n * Row treatment shared by leaf links and branch triggers — the nswds-app\n * left-rail language: each row carries its own left border sitting exactly on\n * the list's rail (the `-ml-px` on the `<li>`), so hover and the current-page\n * state recolour the rail segment beside the row.\n *\n * Departures from the source, both deliberate:\n * - The idle border is `border-transparent` rather than the bare `border-l`\n * default: idle rows show the rail through their transparent border, so the\n * idle rail colour is defined once (on the list) instead of twice.\n * - The current row adds `dark:text-white`. The source left dark active text\n * to fall through to the idle `dark:text-grey-400`, which on the\n * `dark:bg-white/20` highlight is both low-contrast and cascade-order\n * dependent; bold white ink clears WCAG 2.2 AA (1.4.3) on that overlay.\n *\n * The hover font-weight change (`hover:font-semibold`) is source parity; it\n * reflows the row's own text only, never the rail.\n *\n * Focus uses the house visible-focus pattern (outline-current, offset 2), so\n * the indicator always contrasts with whatever text colour the row currently\n * has (WCAG 2.2, 2.4.13 Focus Appearance).\n */\nconst sideNavRowVariants = cva(\n [\n 'w-full cursor-pointer rounded-r-sm border-l border-transparent py-1 pr-2 pl-4 text-left max-sm:text-base/8 sm:text-sm/6',\n 'motion-safe:transition-colors',\n 'hover:border-grey-950 hover:bg-primary-800/10 hover:font-semibold hover:text-grey-950',\n 'dark:text-grey-400 dark:hover:border-grey-400 dark:hover:text-white',\n 'focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-current',\n ],\n {\n variants: {\n current: {\n true: 'border-primary-800 bg-primary-800/10 font-bold text-primary-800 dark:border-white dark:bg-white/20 dark:text-white',\n false: '',\n },\n },\n defaultVariants: {\n current: false,\n },\n },\n)\n\n/**\n * Port of nswds-app's `isLinkOrDescendantActive`: true when the item itself,\n * or any item anywhere beneath it, is the current page. Drives `defaultOpen`\n * on branch collapsibles so the rail opens onto the reader's location.\n */\nfunction isItemOrDescendantCurrent(item: SideNavItem, currentHref: string | undefined): boolean {\n if (currentHref === undefined) {\n return false\n }\n if (item.href === currentHref) {\n return true\n }\n return item.links?.some((child) => isItemOrDescendantCurrent(child, currentHref)) ?? false\n}\n\n/**\n * Dev-only guard, mirroring the icon-only Button check in button.tsx: an item\n * with neither destination nor children renders as inert text (a decoy link\n * would violate WCAG 2.2, 4.1.2 Name, Role, Value expectations), and a branch's\n * `href` is silently unreachable because the row renders as a disclosure\n * button. Both are almost certainly data mistakes. No-op in production.\n */\nfunction warnIfItemMisshapen(item: SideNavItem) {\n if (process.env.NODE_ENV === 'production') {\n return\n }\n const hasChildren = (item.links?.length ?? 0) > 0\n if (!hasChildren && item.href === undefined) {\n console.warn(\n `[nswds/ui] SideNav item \"${item.title}\" has neither href nor links — it renders as inert text. Give it a destination or children.`,\n )\n }\n if (hasChildren && item.href !== undefined) {\n console.warn(\n `[nswds/ui] SideNav item \"${item.title}\" has both href and links — branch rows render as collapsible triggers, so its href is unreachable. Add a separate leaf item for the destination.`,\n )\n }\n}\n\ntype SideNavListProps = {\n items: SideNavItem[]\n currentHref?: string\n onNavigate?: React.MouseEventHandler<HTMLAnchorElement>\n /** Deeper than the section rail — tighter gap, indented, per the source. */\n nested?: boolean\n}\n\n/**\n * A rail of rows: the bordered `<ul>` every level of the tree renders into.\n * `role='list'` is kept from the source — Safari/VoiceOver strips list\n * semantics from lists whose `list-style` is removed, and the explicit role\n * restores them (this is the one sanctioned hand-written role in the file).\n */\nfunction SideNavList({ items, currentHref, onNavigate, nested = false }: SideNavListProps) {\n return (\n <ul\n role='list'\n data-slot='side-nav-list'\n className={cn(\n 'flex flex-col border-l border-grey-400 dark:border-grey-200/15',\n nested ? 'mt-2 ml-5 gap-1' : 'gap-2 max-lg:mt-2 lg:mt-4',\n )}\n >\n {items.map((item) => (\n <SideNavRow\n key={item.href ?? item.title}\n item={item}\n currentHref={currentHref}\n onNavigate={onNavigate}\n />\n ))}\n </ul>\n )\n}\n\ntype SideNavRowProps = {\n item: SideNavItem\n currentHref?: string\n onNavigate?: React.MouseEventHandler<HTMLAnchorElement>\n}\n\n/**\n * One row of the rail — a leaf link, a collapsible branch, or (data mistake)\n * inert text. Recurses through `SideNavList` for branch children.\n */\nfunction SideNavRow({ item, currentHref, onNavigate }: SideNavRowProps) {\n const hasChildren = (item.links?.length ?? 0) > 0\n const isCurrent = currentHref !== undefined && item.href === currentHref\n\n warnIfItemMisshapen(item)\n\n if (hasChildren) {\n return (\n <li data-slot='side-nav-item' className='-ml-px flex w-full flex-col items-start gap-1'>\n {/* defaultOpen (not controlled `open`) so the branch holding the\n current page starts expanded but the reader can still fold it —\n the source's auto-expansion behaviour exactly. */}\n <Collapsible className='w-full' defaultOpen={isItemOrDescendantCurrent(item, currentHref)}>\n {/* Base UI's Trigger owns the disclosure semantics (aria-expanded,\n aria-controls, keyboard activation) — nothing hand-rolled here.\n `group` scopes the chevron's rotation to THIS trigger: nested\n triggers are never ancestors of each other's icons, and the\n Collapsible root carries data-open (not data-panel-open), so an\n open outer branch cannot rotate descendant chevrons. */}\n <CollapsibleTrigger\n data-slot='side-nav-trigger'\n className={cn(sideNavRowVariants(), 'group flex items-center justify-between gap-1')}\n >\n <span>{item.title}</span>\n <IconChevronRight\n aria-hidden='true'\n className='ml-2 size-5 shrink-0 duration-200 group-data-panel-open:rotate-90 motion-safe:transition-transform'\n />\n </CollapsibleTrigger>\n <CollapsibleContent data-slot='side-nav-panel'>\n <SideNavList\n items={item.links ?? []}\n currentHref={currentHref}\n onNavigate={onNavigate}\n nested\n />\n </CollapsibleContent>\n </Collapsible>\n </li>\n )\n }\n\n if (item.href === undefined) {\n // No destination, no children: inert text, not a decoy anchor. The\n // dev-only warning above names the item.\n return (\n <li data-slot='side-nav-item' className='-ml-px flex w-full flex-col items-start gap-1'>\n <span\n data-slot='side-nav-text'\n className={cn(sideNavRowVariants(), 'inline-block cursor-default')}\n >\n {item.title}\n </span>\n </li>\n )\n }\n\n return (\n <li data-slot='side-nav-item' className='-ml-px flex w-full flex-col items-start gap-1'>\n {/* variant='unstyled' — the rail supplies the complete row treatment;\n Link's underline/colour variants would fight it. Rendering through\n Link still picks up the framework link component from LinkProvider\n (next/link et al). */}\n <Link\n variant='unstyled'\n data-slot='side-nav-link'\n href={item.href}\n onClick={onNavigate}\n aria-current={isCurrent ? 'page' : undefined}\n className={cn(sideNavRowVariants({ current: isCurrent }), 'inline-block')}\n >\n {item.title}\n </Link>\n </li>\n )\n}\n\ntype SideNavProps = Omit<React.ComponentPropsWithoutRef<'nav'>, 'children'> & {\n /**\n * The navigation tree. A top-level item with `links` renders as a section\n * heading over an always-visible rail; one without renders as a plain rail\n * link — mirroring nswds-app `Navigation`'s section shape. Deeper items with\n * `links` render as collapsible branches (nswds-app `SidebarNavigation`).\n */\n sections: SideNavItem[]\n /**\n * The current page's href. The matching leaf gets `aria-current='page'` and\n * the active rail treatment, and every branch on the path to it starts\n * expanded — at MOUNT only. Branches are `defaultOpen`, not controlled: a\n * later `currentHref` change (SPA navigation) re-highlights the leaf but\n * never re-expands a branch the reader has folded, so the highlight can\n * land inside a collapsed branch. Branch expansion is seeded from\n * `currentHref` on mount; pass a `key` (e.g. `key={currentHref}`) to\n * remount and re-open the path on navigation — the same contract as\n * PushMenu's level stack. Frameworkless replacement for the source's\n * `usePathname()` — pass your router's pathname in.\n */\n currentHref?: string\n /**\n * Fired from every leaf link (never from branch triggers). The mobile-drawer\n * close hook, as in the source's `onLinkClick`.\n */\n onNavigate?: React.MouseEventHandler<HTMLAnchorElement>\n /**\n * Heading level for section titles. Defaults to `2` — correct when the nav\n * sits at the top level of the document outline. Step it down when the page\n * nests the nav under another heading (WCAG 1.3.1). `1` is excluded: a\n * section-nav heading is never the page's own title. Same contract as\n * `FooterNavColumn`.\n */\n headingLevel?: 2 | 3 | 4 | 5 | 6\n ref?: React.Ref<HTMLElement>\n}\n\n/**\n * Left-rail section navigation — the consolidation of nswds-app's flat\n * `Navigation` and recursive `SidebarNavigation` into one tree-shaped\n * component. Renders a `<nav>` landmark of headed sections whose links may\n * nest to any depth; nested branches collapse.\n *\n * Accessibility contract:\n * - The landmark is named (`aria-label`, default \"Section navigation\") so it is\n * distinguishable from the page's other navigation landmarks (WCAG 1.3.1).\n * - Disclosure semantics — `aria-expanded`, `aria-controls`, Enter/Space\n * activation — come entirely from Base UI's Collapsible; nothing hand-rolled.\n * - The current page is marked with `aria-current='page'`, and every branch on\n * the path to it starts expanded ON MOUNT, so the highlighted location is\n * visible on arrival (ported `isLinkOrDescendantActive`). Expansion is\n * `defaultOpen`, so it does not re-run when `currentHref` changes — see the\n * `currentHref` prop for the `key={currentHref}` remount workaround.\n * - Focus is always visible via the house `outline-current` pattern (2.4.13).\n *\n * Departures from the nswds-app source (see also `sideNavRowVariants` and\n * `SideNavItem`):\n * - `usePathname()` → the `currentHref` prop; links render through `Link`, so\n * frameworks inject their own anchor via `LinkProvider`.\n * - The Radix-based Collapsible → the Base UI primitive (this repo's\n * `collapsible.tsx`), whose open state is `data-panel-open` on the trigger\n * rather than Radix's `data-state='open'`.\n * - The source rendered a stray empty `<ul>` after link-less sections and sent\n * `href='#'` placeholders through the tree; both are dropped.\n */\nfunction SideNav({\n className,\n sections,\n currentHref,\n onNavigate,\n headingLevel = 2,\n 'aria-label': ariaLabel = 'Section navigation',\n ref,\n ...props\n}: SideNavProps) {\n const Heading = `h${headingLevel}` as const\n\n return (\n <nav\n data-slot='side-nav'\n {...props}\n aria-label={ariaLabel}\n // Base ink declared once here (the source inherited the page body's\n // colour in light mode; a design-system component states it).\n className={cn('text-grey-800 max-lg:text-base lg:text-sm dark:text-grey-400', className)}\n ref={ref}\n >\n <ul role='list' data-slot='side-nav-sections' className='flex flex-col gap-9'>\n {sections.map((section) => (\n <li key={section.href ?? section.title} data-slot='side-nav-section'>\n {section.links ? (\n <>\n {/* font-display resolves through @nswds/tokens' Tailwind\n preset (--font-display, Public Sans stack) — the same\n utility the source used. */}\n <Heading\n data-slot='side-nav-heading'\n className='font-display font-medium text-grey-800 dark:text-white'\n >\n {section.title}\n </Heading>\n <SideNavList\n items={section.links}\n currentHref={currentHref}\n onNavigate={onNavigate}\n />\n </>\n ) : (\n // A link-less section is a single rail link (Navigation.tsx\n // parity) — reuse the rail so the border/offset stay identical.\n <SideNavList items={[section]} currentHref={currentHref} onNavigate={onNavigate} />\n )}\n </li>\n ))}\n </ul>\n </nav>\n )\n}\n\nexport { SideNav, sideNavRowVariants }\nexport type { SideNavItem, SideNavProps }\nexport type SideNavRowVariantProps = VariantProps<typeof sideNavRowVariants>\n"]}
|
|
@@ -91,7 +91,7 @@ function SiteSearch({
|
|
|
91
91
|
Dialog.Backdrop,
|
|
92
92
|
{
|
|
93
93
|
"data-slot": "site-search-overlay",
|
|
94
|
-
className: "fixed inset-0 z-50 bg-black/80
|
|
94
|
+
className: "fixed inset-0 z-50 bg-black/80 duration-150 data-ending-style:opacity-0 data-starting-style:opacity-0 supports-backdrop-filter:backdrop-blur-xs motion-safe:transition-opacity"
|
|
95
95
|
}
|
|
96
96
|
),
|
|
97
97
|
/* @__PURE__ */ jsxs(
|
|
@@ -104,7 +104,7 @@ function SiteSearch({
|
|
|
104
104
|
// Centred panel on the house popup surface (popover.tsx / sheet.tsx).
|
|
105
105
|
"fixed top-[max(--spacing(4),15vh)] left-1/2 z-50 w-[calc(100vw-2rem)] max-w-2xl -translate-x-1/2",
|
|
106
106
|
"rounded-lg bg-popover text-popover-foreground shadow-md ring-1 ring-foreground/10 outline-hidden",
|
|
107
|
-
"
|
|
107
|
+
"duration-150 ease-out motion-safe:transition",
|
|
108
108
|
"data-ending-style:scale-95 data-ending-style:opacity-0 data-starting-style:scale-95 data-starting-style:opacity-0",
|
|
109
109
|
className
|
|
110
110
|
),
|