@nswds/ui 4.6.0 → 4.7.1
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.js +26 -6
- package/dist/components/badge.js.map +1 -1
- 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 +26 -1
- package/dist/components/header.js +13 -8
- 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.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/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.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/site-search.tsx"],"names":[],"mappings":";;;;;;;;AA4HA,SAAS,UAAA,CAAW;AAAA,EAClB,MAAA;AAAA,EACA,QAAA;AAAA,EACA,IAAA,EAAM,QAAA;AAAA,EACN,YAAA;AAAA,EACA,WAAA,GAAc,KAAA;AAAA,EACd,QAAA,GAAW,IAAA;AAAA,E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AA,0BAEV,QAAA,EAAA;AAAA,4CAAA,GAAA;AAAA,8BAAC,YAAA,CAAa,UAAA;AAAA,8BAAb;AAAA,gCACC,WAAA,EAAU,yBAAA;AAAA,gCACV,SAAA,EAAU,4DAAA;AAAA,gCAET,QAAA,EAAA,KAAA,CAAM;AAAA;AAAA,6BACT;AAAA,4CACA,GAAA,CAAC,YAAA,CAAa,UAAA,EAAb,EACE,WAAC,IAAA,qBACA,GAAA;AAAA,8BAAC,YAAA,CAAa,IAAA;AAAA,8BAAb;AAAA,gCAEC,KAAA,EAAO,IAAA;AAAA,gCACP,WAAA,EAAU,kBAAA;AAAA,gCACV,OAAA,EAAS,MAAM,YAAA,CAAa,IAAI,CAAA;AAAA,gCAGhC,SAAA,EAAU,4OAAA;AAAA,gCAET,QAAA,EAAA,IAAA,CAAK;AAAA,+BAAA;AAAA,8BARD,IAAA,CAAK;AAAA,6BASZ,EAEJ;AAAA;AAAA,yBAAA;AAAA,wBAxBK,KAAA,CAAM;AAAA;AAyBb;AAAA;AAEJ;AAAA;AAAA,aACF;AAAA,YAEC,YAAY,IAAA,mBACX,GAAA;AAAA,cAAC,KAAA;AAAA,cAAA;AAAA,gBACC,WAAA,EAAU,oBAAA;AAAA,gBACV,SAAA,EAAU,uEAAA;AAAA,gBAET;AAAA;AAAA,aACH,GACE;AAAA;AAAA;AAAA;AACN,KAAA,EACF;AAAA,GAAA,EACF,CAAA;AAEJ","file":"site-search.js","sourcesContent":["'use client'\n\nimport { Autocomplete } from '@base-ui/react/autocomplete'\nimport { Dialog } from '@base-ui/react/dialog'\nimport React from 'react'\n\nimport { IconSearch } from '../icons/search.js'\nimport { cn } from '../lib/utils.js'\n\nimport { Button } from '../components/button.js'\n\n/** A single searchable destination. `keywords` extend matching beyond the title. */\ntype SiteSearchItem = {\n title: string\n href: string\n keywords?: string[]\n}\n\n/** A titled section of results, rendered with a muted group heading. */\ntype SiteSearchGroup = {\n title: string\n items: SiteSearchItem[]\n}\n\ntype SiteSearchProps = {\n /** The searchable site map, as titled groups of items. */\n groups: SiteSearchGroup[]\n /**\n * Called with the chosen item on click or Enter, after the palette closes.\n * Navigation is the APP's job — call your router here (e.g. next/navigation's\n * `router.push(item.href)`). The design system ships no framework code, so it\n * never navigates itself; this mirrors the DS-wide framework-free rule\n * (see `Link` / `LinkProvider`).\n */\n onSelect: (item: SiteSearchItem) => void\n /** Whether the palette is open. Use when controlled. */\n open?: boolean\n /** Called whenever the palette asks to open or close. */\n onOpenChange?: (open: boolean) => void\n /** Whether the palette is initially open (uncontrolled). */\n defaultOpen?: boolean\n /**\n * Wire the global Cmd/Ctrl-K toggle on `document`, with cleanup on unmount.\n * Defaults to true. Only one shortcut-enabled SiteSearch should be mounted\n * per page, or each press toggles all of them.\n */\n shortcut?: boolean\n /**\n * Accessible name for the palette, applied as `aria-label` to the dialog\n * panel, the search input and the default trigger. Defaults to\n * `'Search site'`. Mirrors ExpandableSearch's `label` prop — localise it\n * rather than hardcoding English into consumers' pages.\n */\n label?: string\n /** Placeholder for the search input. */\n placeholder?: string\n /** Message shown when no items match the query. */\n emptyMessage?: string\n /**\n * The element that opens the palette. Defaults to a ghost icon `Button`\n * named by `label`. Pass an element to replace it — it is composed via Base\n * UI's `render` prop, so it inherits the trigger behaviour and ARIA — or\n * `null` to render no trigger at all (open via `open` or the shortcut).\n * A custom trigger owns its own accessible name — `label` is applied as\n * `aria-label` to the default icon button only, since overriding a visible\n * label that way fails WCAG 2.2, 2.5.3 Label in Name.\n *\n * Conditional triggers must resolve to `null`, not `false`: write\n * `cond ? <Button/> : null`, since `cond && <Button/>` yields `false`, which\n * Base UI's `render` prop rejects with an invalid-element error. TypeScript\n * catches it (`false` is not assignable here); plain-JS consumers see the\n * error at render.\n */\n trigger?: React.ReactElement | null\n /**\n * Extra content rendered at the foot of the panel, below the results —\n * e.g. shortcut hints or a \"browse all\" link.\n */\n children?: React.ReactNode\n /** Extra classes for the centred panel. */\n className?: string\n}\n\n/**\n * Cmd/Ctrl-K command-palette site search: a centred modal panel with a\n * filter-as-you-type input over a grouped list of destinations.\n *\n * Ported from nswds-app's `MobileSearch`, rebuilt framework-free: the app\n * version composed cmdk's `Command*` widgets with next/navigation's router;\n * this version composes Base UI's Autocomplete (the combobox/listbox pattern)\n * inside Base UI's Dialog, and hands the chosen item to `onSelect` instead of\n * navigating. The Autocomplete renders in `inline` mode — its input and list\n * sit statically inside the dialog panel with no popup of their own — which is\n * Base UI's documented composition for palettes (it avoids any portal /\n * focus-trap interplay between the two primitives; the always-`open` inline\n * root unmounts with the dialog, so the query and highlight reset on close).\n *\n * Accessibility contract (inherited, not hand-rolled):\n * - Dialog provides the modal behaviour: focus trap, scroll lock, Escape and\n * backdrop-press dismissal, and focus restoration to the trigger on close.\n * The panel is named via `aria-label` (WCAG 2.2, 4.1.2).\n * - Autocomplete provides the combobox pattern: the input is announced as a\n * combobox controlling a listbox, arrow keys move `aria-activedescendant`\n * highlight while DOM focus stays in the input, Enter activates the\n * highlighted item, and the empty state is announced politely.\n * - The trigger (default or custom) renders through `Dialog.Trigger`, so it\n * carries `aria-haspopup=\"dialog\"` / `aria-expanded` automatically.\n * - Result rows are at least 44px tall (2.5.8 Target Size, AAA-sized).\n * - Panel and backdrop transitions honour `prefers-reduced-motion` (2.3.3).\n *\n * Departures from the nswds-app source, beyond the rebuild above:\n * - `groups`/`onSelect` replace the app's `NavigationItem[]` + router: the\n * data shape is explicit (`title`/`href`/`keywords`) instead of the app's\n * nav config, and untitled/unlinked entries can't exist by construction\n * (the source filtered them at render time).\n * - Filtering matches `title` AND `keywords`, case-insensitively, via the\n * Autocomplete `filter` prop. Base UI's `useFilter` helper only matches one\n * string per item, so a custom predicate is the documented escape hatch for\n * multi-field matching; groups with no matching items are dropped by the\n * primitive, headings included.\n * - The Cmd/Ctrl-K listener can be disabled (`shortcut={false}`) — required\n * for pages that mount more than one instance. It still toggles, per the\n * source.\n */\nfunction SiteSearch({\n groups,\n onSelect,\n open: openProp,\n onOpenChange,\n defaultOpen = false,\n shortcut = true,\n label = 'Search site',\n placeholder = 'Type to search across the site...',\n emptyMessage = 'No results found.',\n trigger,\n children,\n className,\n}: SiteSearchProps) {\n const [uncontrolledOpen, setUncontrolledOpen] = React.useState(defaultOpen)\n const isControlled = openProp !== undefined\n const open = isControlled ? openProp : uncontrolledOpen\n\n const inputRef = React.useRef<HTMLInputElement>(null)\n\n // Latest-value refs so the document-level shortcut listener (bound once per\n // `shortcut` value) never acts on a stale open state or stale callbacks.\n // They are written in a passive effect (not during render, per\n // react-hooks/refs) — safe because they are only read from event listeners,\n // which always fire after the commit that synced them.\n const openRef = React.useRef(open)\n const requestOpenChangeRef = React.useRef<(next: boolean) => void>(() => {})\n\n const requestOpenChange = (next: boolean) => {\n if (isControlled) {\n // Dedupe against the render-authoritative prop only — never write\n // openRef optimistically here. An optimistic write would let a parent\n // that vetoes a request (ignores it, so no re-render runs the resync\n // effect) permanently swallow every later identical request. Accepted\n // trade-off: a same-tick duplicate close (Escape reaching both the\n // Autocomplete and the Dialog) may reach `onOpenChange` twice with the\n // same value — idempotent for a setState parent, and correctness in\n // the veto case beats dedupe cosmetics.\n if (open === next) {\n return\n }\n onOpenChange?.(next)\n return\n }\n // Uncontrolled, the component owns the state, so the optimistic write is\n // safe (the commit below confirms it) and dedupes the double-report case\n // (both primitives announcing the same close) down to one callback.\n if (openRef.current === next) {\n return\n }\n openRef.current = next\n setUncontrolledOpen(next)\n onOpenChange?.(next)\n }\n\n React.useEffect(() => {\n // `open` (not `next` from an event) is authoritative here: in controlled\n // mode this effect is the ref's ONLY writer, so the shortcut listener\n // always toggles from the last value the parent actually rendered.\n openRef.current = open\n requestOpenChangeRef.current = requestOpenChange\n })\n\n React.useEffect(() => {\n if (!shortcut) {\n return undefined\n }\n const handleKeyDown = (event: KeyboardEvent) => {\n if (\n event.key.toLowerCase() === 'k' &&\n (event.metaKey || event.ctrlKey) &&\n !event.altKey &&\n !event.defaultPrevented\n ) {\n event.preventDefault()\n // Toggle, per the nswds-app source: the same chord opens and closes.\n requestOpenChangeRef.current(!openRef.current)\n }\n }\n document.addEventListener('keydown', handleKeyDown)\n return () => document.removeEventListener('keydown', handleKeyDown)\n }, [shortcut])\n\n const handleSelect = (item: SiteSearchItem) => {\n // Close first, then hand over — mirrors the source's `runCommand`, so the\n // app's navigation starts from a closed palette.\n requestOpenChange(false)\n onSelect(item)\n }\n\n const filter = React.useCallback((item: SiteSearchItem, query: string) => {\n const q = query.trim().toLowerCase()\n if (q === '') {\n return true\n }\n if (item.title.toLowerCase().includes(q)) {\n return true\n }\n return (item.keywords ?? []).some((keyword) => keyword.toLowerCase().includes(q))\n }, [])\n\n const defaultTrigger = (\n <Button\n variant='ghost'\n color='grey'\n size='icon'\n aria-label={label}\n leadingVisual={IconSearch}\n />\n )\n\n return (\n <Dialog.Root open={open} onOpenChange={(next) => requestOpenChange(next)}>\n {trigger === null ? null : (\n <Dialog.Trigger data-slot='site-search-trigger' render={trigger ?? defaultTrigger} />\n )}\n\n <Dialog.Portal>\n <Dialog.Backdrop\n data-slot='site-search-overlay'\n className='fixed inset-0 z-50 bg-black/80 transition-opacity duration-150 data-ending-style:opacity-0 data-starting-style:opacity-0 supports-backdrop-filter:backdrop-blur-xs motion-reduce:transition-none'\n />\n <Dialog.Popup\n data-slot='site-search-panel'\n aria-label={label}\n // The default focus target on touch is the panel itself (to keep the\n // virtual keyboard closed) — wrong for a search palette, whose whole\n // purpose is typing. Always focus the input.\n initialFocus={inputRef}\n className={cn(\n // Centred panel on the house popup surface (popover.tsx / sheet.tsx).\n 'fixed top-[max(--spacing(4),15vh)] left-1/2 z-50 w-[calc(100vw-2rem)] max-w-2xl -translate-x-1/2',\n 'rounded-lg bg-popover text-popover-foreground shadow-md ring-1 ring-foreground/10 outline-hidden',\n 'transition duration-150 ease-out motion-reduce:transition-none',\n 'data-ending-style:scale-95 data-ending-style:opacity-0 data-starting-style:scale-95 data-starting-style:opacity-0',\n className,\n )}\n >\n <Autocomplete.Root\n items={groups}\n filter={filter}\n itemToStringValue={(item: SiteSearchItem) => item.title}\n autoHighlight\n // Inline mode: the list renders statically inside the dialog panel\n // (no Autocomplete portal/positioner), with `open` pinned per the\n // Base UI docs. Opening/closing belongs to the Dialog; the whole\n // Autocomplete unmounts with it, resetting query and highlight.\n inline\n open\n onOpenChange={(nextOpen, eventDetails) => {\n // The pinned-open inline Autocomplete still *requests* closes;\n // forward the ones that should dismiss the palette. Other\n // reasons (input-clear, focus-out) must not close the dialog —\n // clearing the query or tabbing within the trap isn't dismissal.\n if (\n !nextOpen &&\n (eventDetails.reason === 'escape-key' || eventDetails.reason === 'item-press')\n ) {\n requestOpenChange(false)\n }\n }}\n >\n <div\n data-slot='site-search-input-row'\n className='flex items-center gap-3 border-b border-foreground/10 px-4'\n >\n <IconSearch aria-hidden='true' className='size-5 shrink-0 text-muted-foreground' />\n <Autocomplete.Input\n data-slot='site-search-input'\n aria-label={label}\n placeholder={placeholder}\n className='h-12 w-full bg-transparent text-base text-foreground outline-hidden placeholder:text-muted-foreground'\n ref={inputRef}\n />\n </div>\n\n {/* Base UI renders Empty's children only while the list is empty;\n the padding lives on the inner div so the (always-mounted, for\n polite announcements) outer element paints nothing otherwise. */}\n <Autocomplete.Empty data-slot='site-search-empty'>\n <div className='px-4 py-6 text-center text-sm text-muted-foreground'>\n {emptyMessage}\n </div>\n </Autocomplete.Empty>\n\n <Autocomplete.List\n data-slot='site-search-list'\n className='max-h-[min(--spacing(96),60vh)] overflow-y-auto overscroll-contain p-2 empty:hidden'\n >\n {(group: SiteSearchGroup) => (\n <Autocomplete.Group\n key={group.title}\n items={group.items}\n data-slot='site-search-group'\n >\n <Autocomplete.GroupLabel\n data-slot='site-search-group-label'\n className='px-3 pt-3 pb-1 text-xs font-semibold text-muted-foreground'\n >\n {group.title}\n </Autocomplete.GroupLabel>\n <Autocomplete.Collection>\n {(item: SiteSearchItem) => (\n <Autocomplete.Item\n key={item.href}\n value={item}\n data-slot='site-search-item'\n onClick={() => handleSelect(item)}\n // Highlight treatment mirrors menubar.tsx: keyboard and\n // hover unify as data-highlighted, painted as 10% ink.\n className='flex min-h-11 cursor-default items-center gap-2 rounded-sm px-3 py-2 text-sm text-foreground outline-hidden select-none data-highlighted:bg-primary-800/10 data-highlighted:text-accent-foreground dark:data-highlighted:bg-primary-200/10'\n >\n {item.title}\n </Autocomplete.Item>\n )}\n </Autocomplete.Collection>\n </Autocomplete.Group>\n )}\n </Autocomplete.List>\n </Autocomplete.Root>\n\n {children != null ? (\n <div\n data-slot='site-search-footer'\n className='border-t border-foreground/10 px-4 py-2 text-xs text-muted-foreground'\n >\n {children}\n </div>\n ) : null}\n </Dialog.Popup>\n </Dialog.Portal>\n </Dialog.Root>\n )\n}\n\nexport { SiteSearch }\nexport type { SiteSearchGroup, SiteSearchItem, SiteSearchProps }\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/components/site-search.tsx"],"names":[],"mappings":";;;;;;;;AA4HA,SAAS,UAAA,CAAW;AAAA,EAClB,MAAA;AAAA,EACA,QAAA;AAAA,EACA,IAAA,EAAM,QAAA;AAAA,EACN,YAAA;AAAA,EACA,WAAA,GAAc,KAAA;AAAA,EACd,QAAA,GAAW,IAAA;AAAA,EACX,KAAA,GAAQ,aAAA;AAAA,EACR,WAAA,GAAc,mCAAA;AAAA,EACd,YAAA,GAAe,mBAAA;AAAA,EACf,OAAA;AAAA,EACA,QAAA;AAAA,EACA;AACF,CAAA,EAAoB;AAClB,EAAA,MAAM,CAAC,gBAAA,EAAkB,mBAAmB,CAAA,GAAI,KAAA,CAAM,SAAS,WAAW,CAAA;AAC1E,EAAA,MAAM,eAAe,QAAA,KAAa,MAAA;AAClC,EAAA,MAAM,IAAA,GAAO,eAAe,QAAA,GAAW,gBAAA;AAEvC,EAAA,MAAM,QAAA,GAAW,KAAA,CAAM,MAAA,CAAyB,IAAI,CAAA;AAOpD,EAAA,MAAM,OAAA,GAAU,KAAA,CAAM,MAAA,CAAO,IAAI,CAAA;AACjC,EAAA,MAAM,oBAAA,GA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A,IAAA,CAAK;AAAA,+BAAA;AAAA,8BARD,IAAA,CAAK;AAAA,6BASZ,EAEJ;AAAA;AAAA,yBAAA;AAAA,wBAxBK,KAAA,CAAM;AAAA;AAyBb;AAAA;AAEJ;AAAA;AAAA,aACF;AAAA,YAEC,YAAY,IAAA,mBACX,GAAA;AAAA,cAAC,KAAA;AAAA,cAAA;AAAA,gBACC,WAAA,EAAU,oBAAA;AAAA,gBACV,SAAA,EAAU,uEAAA;AAAA,gBAET;AAAA;AAAA,aACH,GACE;AAAA;AAAA;AAAA;AACN,KAAA,EACF;AAAA,GAAA,EACF,CAAA;AAEJ","file":"site-search.js","sourcesContent":["'use client'\n\nimport { Autocomplete } from '@base-ui/react/autocomplete'\nimport { Dialog } from '@base-ui/react/dialog'\nimport React from 'react'\n\nimport { IconSearch } from '../icons/search.js'\nimport { cn } from '../lib/utils.js'\n\nimport { Button } from '../components/button.js'\n\n/** A single searchable destination. `keywords` extend matching beyond the title. */\ntype SiteSearchItem = {\n title: string\n href: string\n keywords?: string[]\n}\n\n/** A titled section of results, rendered with a muted group heading. */\ntype SiteSearchGroup = {\n title: string\n items: SiteSearchItem[]\n}\n\ntype SiteSearchProps = {\n /** The searchable site map, as titled groups of items. */\n groups: SiteSearchGroup[]\n /**\n * Called with the chosen item on click or Enter, after the palette closes.\n * Navigation is the APP's job — call your router here (e.g. next/navigation's\n * `router.push(item.href)`). The design system ships no framework code, so it\n * never navigates itself; this mirrors the DS-wide framework-free rule\n * (see `Link` / `LinkProvider`).\n */\n onSelect: (item: SiteSearchItem) => void\n /** Whether the palette is open. Use when controlled. */\n open?: boolean\n /** Called whenever the palette asks to open or close. */\n onOpenChange?: (open: boolean) => void\n /** Whether the palette is initially open (uncontrolled). */\n defaultOpen?: boolean\n /**\n * Wire the global Cmd/Ctrl-K toggle on `document`, with cleanup on unmount.\n * Defaults to true. Only one shortcut-enabled SiteSearch should be mounted\n * per page, or each press toggles all of them.\n */\n shortcut?: boolean\n /**\n * Accessible name for the palette, applied as `aria-label` to the dialog\n * panel, the search input and the default trigger. Defaults to\n * `'Search site'`. Mirrors ExpandableSearch's `label` prop — localise it\n * rather than hardcoding English into consumers' pages.\n */\n label?: string\n /** Placeholder for the search input. */\n placeholder?: string\n /** Message shown when no items match the query. */\n emptyMessage?: string\n /**\n * The element that opens the palette. Defaults to a ghost icon `Button`\n * named by `label`. Pass an element to replace it — it is composed via Base\n * UI's `render` prop, so it inherits the trigger behaviour and ARIA — or\n * `null` to render no trigger at all (open via `open` or the shortcut).\n * A custom trigger owns its own accessible name — `label` is applied as\n * `aria-label` to the default icon button only, since overriding a visible\n * label that way fails WCAG 2.2, 2.5.3 Label in Name.\n *\n * Conditional triggers must resolve to `null`, not `false`: write\n * `cond ? <Button/> : null`, since `cond && <Button/>` yields `false`, which\n * Base UI's `render` prop rejects with an invalid-element error. TypeScript\n * catches it (`false` is not assignable here); plain-JS consumers see the\n * error at render.\n */\n trigger?: React.ReactElement | null\n /**\n * Extra content rendered at the foot of the panel, below the results —\n * e.g. shortcut hints or a \"browse all\" link.\n */\n children?: React.ReactNode\n /** Extra classes for the centred panel. */\n className?: string\n}\n\n/**\n * Cmd/Ctrl-K command-palette site search: a centred modal panel with a\n * filter-as-you-type input over a grouped list of destinations.\n *\n * Ported from nswds-app's `MobileSearch`, rebuilt framework-free: the app\n * version composed cmdk's `Command*` widgets with next/navigation's router;\n * this version composes Base UI's Autocomplete (the combobox/listbox pattern)\n * inside Base UI's Dialog, and hands the chosen item to `onSelect` instead of\n * navigating. The Autocomplete renders in `inline` mode — its input and list\n * sit statically inside the dialog panel with no popup of their own — which is\n * Base UI's documented composition for palettes (it avoids any portal /\n * focus-trap interplay between the two primitives; the always-`open` inline\n * root unmounts with the dialog, so the query and highlight reset on close).\n *\n * Accessibility contract (inherited, not hand-rolled):\n * - Dialog provides the modal behaviour: focus trap, scroll lock, Escape and\n * backdrop-press dismissal, and focus restoration to the trigger on close.\n * The panel is named via `aria-label` (WCAG 2.2, 4.1.2).\n * - Autocomplete provides the combobox pattern: the input is announced as a\n * combobox controlling a listbox, arrow keys move `aria-activedescendant`\n * highlight while DOM focus stays in the input, Enter activates the\n * highlighted item, and the empty state is announced politely.\n * - The trigger (default or custom) renders through `Dialog.Trigger`, so it\n * carries `aria-haspopup=\"dialog\"` / `aria-expanded` automatically.\n * - Result rows are at least 44px tall (2.5.8 Target Size, AAA-sized).\n * - Panel and backdrop transitions honour `prefers-reduced-motion` (2.3.3).\n *\n * Departures from the nswds-app source, beyond the rebuild above:\n * - `groups`/`onSelect` replace the app's `NavigationItem[]` + router: the\n * data shape is explicit (`title`/`href`/`keywords`) instead of the app's\n * nav config, and untitled/unlinked entries can't exist by construction\n * (the source filtered them at render time).\n * - Filtering matches `title` AND `keywords`, case-insensitively, via the\n * Autocomplete `filter` prop. Base UI's `useFilter` helper only matches one\n * string per item, so a custom predicate is the documented escape hatch for\n * multi-field matching; groups with no matching items are dropped by the\n * primitive, headings included.\n * - The Cmd/Ctrl-K listener can be disabled (`shortcut={false}`) — required\n * for pages that mount more than one instance. It still toggles, per the\n * source.\n */\nfunction SiteSearch({\n groups,\n onSelect,\n open: openProp,\n onOpenChange,\n defaultOpen = false,\n shortcut = true,\n label = 'Search site',\n placeholder = 'Type to search across the site...',\n emptyMessage = 'No results found.',\n trigger,\n children,\n className,\n}: SiteSearchProps) {\n const [uncontrolledOpen, setUncontrolledOpen] = React.useState(defaultOpen)\n const isControlled = openProp !== undefined\n const open = isControlled ? openProp : uncontrolledOpen\n\n const inputRef = React.useRef<HTMLInputElement>(null)\n\n // Latest-value refs so the document-level shortcut listener (bound once per\n // `shortcut` value) never acts on a stale open state or stale callbacks.\n // They are written in a passive effect (not during render, per\n // react-hooks/refs) — safe because they are only read from event listeners,\n // which always fire after the commit that synced them.\n const openRef = React.useRef(open)\n const requestOpenChangeRef = React.useRef<(next: boolean) => void>(() => {})\n\n const requestOpenChange = (next: boolean) => {\n if (isControlled) {\n // Dedupe against the render-authoritative prop only — never write\n // openRef optimistically here. An optimistic write would let a parent\n // that vetoes a request (ignores it, so no re-render runs the resync\n // effect) permanently swallow every later identical request. Accepted\n // trade-off: a same-tick duplicate close (Escape reaching both the\n // Autocomplete and the Dialog) may reach `onOpenChange` twice with the\n // same value — idempotent for a setState parent, and correctness in\n // the veto case beats dedupe cosmetics.\n if (open === next) {\n return\n }\n onOpenChange?.(next)\n return\n }\n // Uncontrolled, the component owns the state, so the optimistic write is\n // safe (the commit below confirms it) and dedupes the double-report case\n // (both primitives announcing the same close) down to one callback.\n if (openRef.current === next) {\n return\n }\n openRef.current = next\n setUncontrolledOpen(next)\n onOpenChange?.(next)\n }\n\n React.useEffect(() => {\n // `open` (not `next` from an event) is authoritative here: in controlled\n // mode this effect is the ref's ONLY writer, so the shortcut listener\n // always toggles from the last value the parent actually rendered.\n openRef.current = open\n requestOpenChangeRef.current = requestOpenChange\n })\n\n React.useEffect(() => {\n if (!shortcut) {\n return undefined\n }\n const handleKeyDown = (event: KeyboardEvent) => {\n if (\n event.key.toLowerCase() === 'k' &&\n (event.metaKey || event.ctrlKey) &&\n !event.altKey &&\n !event.defaultPrevented\n ) {\n event.preventDefault()\n // Toggle, per the nswds-app source: the same chord opens and closes.\n requestOpenChangeRef.current(!openRef.current)\n }\n }\n document.addEventListener('keydown', handleKeyDown)\n return () => document.removeEventListener('keydown', handleKeyDown)\n }, [shortcut])\n\n const handleSelect = (item: SiteSearchItem) => {\n // Close first, then hand over — mirrors the source's `runCommand`, so the\n // app's navigation starts from a closed palette.\n requestOpenChange(false)\n onSelect(item)\n }\n\n const filter = React.useCallback((item: SiteSearchItem, query: string) => {\n const q = query.trim().toLowerCase()\n if (q === '') {\n return true\n }\n if (item.title.toLowerCase().includes(q)) {\n return true\n }\n return (item.keywords ?? []).some((keyword) => keyword.toLowerCase().includes(q))\n }, [])\n\n const defaultTrigger = (\n <Button\n variant='ghost'\n color='grey'\n size='icon'\n aria-label={label}\n leadingVisual={IconSearch}\n />\n )\n\n return (\n <Dialog.Root open={open} onOpenChange={(next) => requestOpenChange(next)}>\n {trigger === null ? null : (\n <Dialog.Trigger data-slot='site-search-trigger' render={trigger ?? defaultTrigger} />\n )}\n\n <Dialog.Portal>\n <Dialog.Backdrop\n data-slot='site-search-overlay'\n 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'\n />\n <Dialog.Popup\n data-slot='site-search-panel'\n aria-label={label}\n // The default focus target on touch is the panel itself (to keep the\n // virtual keyboard closed) — wrong for a search palette, whose whole\n // purpose is typing. Always focus the input.\n initialFocus={inputRef}\n className={cn(\n // Centred panel on the house popup surface (popover.tsx / sheet.tsx).\n 'fixed top-[max(--spacing(4),15vh)] left-1/2 z-50 w-[calc(100vw-2rem)] max-w-2xl -translate-x-1/2',\n 'rounded-lg bg-popover text-popover-foreground shadow-md ring-1 ring-foreground/10 outline-hidden',\n 'duration-150 ease-out motion-safe:transition',\n 'data-ending-style:scale-95 data-ending-style:opacity-0 data-starting-style:scale-95 data-starting-style:opacity-0',\n className,\n )}\n >\n <Autocomplete.Root\n items={groups}\n filter={filter}\n itemToStringValue={(item: SiteSearchItem) => item.title}\n autoHighlight\n // Inline mode: the list renders statically inside the dialog panel\n // (no Autocomplete portal/positioner), with `open` pinned per the\n // Base UI docs. Opening/closing belongs to the Dialog; the whole\n // Autocomplete unmounts with it, resetting query and highlight.\n inline\n open\n onOpenChange={(nextOpen, eventDetails) => {\n // The pinned-open inline Autocomplete still *requests* closes;\n // forward the ones that should dismiss the palette. Other\n // reasons (input-clear, focus-out) must not close the dialog —\n // clearing the query or tabbing within the trap isn't dismissal.\n if (\n !nextOpen &&\n (eventDetails.reason === 'escape-key' || eventDetails.reason === 'item-press')\n ) {\n requestOpenChange(false)\n }\n }}\n >\n <div\n data-slot='site-search-input-row'\n className='flex items-center gap-3 border-b border-foreground/10 px-4'\n >\n <IconSearch aria-hidden='true' className='size-5 shrink-0 text-muted-foreground' />\n <Autocomplete.Input\n data-slot='site-search-input'\n aria-label={label}\n placeholder={placeholder}\n className='h-12 w-full bg-transparent text-base text-foreground outline-hidden placeholder:text-muted-foreground'\n ref={inputRef}\n />\n </div>\n\n {/* Base UI renders Empty's children only while the list is empty;\n the padding lives on the inner div so the (always-mounted, for\n polite announcements) outer element paints nothing otherwise. */}\n <Autocomplete.Empty data-slot='site-search-empty'>\n <div className='px-4 py-6 text-center text-sm text-muted-foreground'>\n {emptyMessage}\n </div>\n </Autocomplete.Empty>\n\n <Autocomplete.List\n data-slot='site-search-list'\n className='max-h-[min(--spacing(96),60vh)] overflow-y-auto overscroll-contain p-2 empty:hidden'\n >\n {(group: SiteSearchGroup) => (\n <Autocomplete.Group\n key={group.title}\n items={group.items}\n data-slot='site-search-group'\n >\n <Autocomplete.GroupLabel\n data-slot='site-search-group-label'\n className='px-3 pt-3 pb-1 text-xs font-semibold text-muted-foreground'\n >\n {group.title}\n </Autocomplete.GroupLabel>\n <Autocomplete.Collection>\n {(item: SiteSearchItem) => (\n <Autocomplete.Item\n key={item.href}\n value={item}\n data-slot='site-search-item'\n onClick={() => handleSelect(item)}\n // Highlight treatment mirrors menubar.tsx: keyboard and\n // hover unify as data-highlighted, painted as 10% ink.\n className='flex min-h-11 cursor-default items-center gap-2 rounded-sm px-3 py-2 text-sm text-foreground outline-hidden select-none data-highlighted:bg-primary-800/10 data-highlighted:text-accent-foreground dark:data-highlighted:bg-primary-200/10'\n >\n {item.title}\n </Autocomplete.Item>\n )}\n </Autocomplete.Collection>\n </Autocomplete.Group>\n )}\n </Autocomplete.List>\n </Autocomplete.Root>\n\n {children != null ? (\n <div\n data-slot='site-search-footer'\n className='border-t border-foreground/10 px-4 py-2 text-xs text-muted-foreground'\n >\n {children}\n </div>\n ) : null}\n </Dialog.Popup>\n </Dialog.Portal>\n </Dialog.Root>\n )\n}\n\nexport { SiteSearch }\nexport type { SiteSearchGroup, SiteSearchItem, SiteSearchProps }\n"]}
|
|
@@ -15,7 +15,7 @@ const skipLinkVariants = cva(
|
|
|
15
15
|
// pattern) — still in the tab order, so it is the first thing keyboard
|
|
16
16
|
// and screen-reader users reach.
|
|
17
17
|
"absolute inset-x-0 top-0 w-full -translate-y-[101%]",
|
|
18
|
-
"
|
|
18
|
+
"motion-safe:transition-transform",
|
|
19
19
|
"focus:translate-y-0",
|
|
20
20
|
// min-h-11 keeps the revealed bar at ≥44px — 2.5.5 Target Size (AAA).
|
|
21
21
|
"group flex min-h-11 items-center px-4 py-2 text-xs font-medium no-underline",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/skip-link.tsx"],"names":[],"mappings":";;;;AAYA,MAAM,cAAA,GAAiB;AAAA,EACrB,IAAA,EAAM,+CAAA;AAAA,EACN,KAAA,EAAO,2BAAA;AAAA,EACP,KAAA,EAAO,wBAAA;AAAA,EACP,IAAA,EAAM;AACR,CAAA;AAEA,MAAM,gBAAA,GAAmB,GAAA;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA,IAIE,qDAAA;AAAA,IACA,
|
|
1
|
+
{"version":3,"sources":["../../src/components/skip-link.tsx"],"names":[],"mappings":";;;;AAYA,MAAM,cAAA,GAAiB;AAAA,EACrB,IAAA,EAAM,+CAAA;AAAA,EACN,KAAA,EAAO,2BAAA;AAAA,EACP,KAAA,EAAO,wBAAA;AAAA,EACP,IAAA,EAAM;AACR,CAAA;AAEA,MAAM,gBAAA,GAAmB,GAAA;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA,IAIE,qDAAA;AAAA,IACA,kCAAA;AAAA,IACA,qBAAA;AAAA;AAAA,IAEA,6EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAKA;AAAA,GACF;AAAA,EACA;AAAA,IACE,QAAA,EAAU;AAAA,MACR,KAAA,EAAO;AAAA,KACT;AAAA,IACA,eAAA,EAAiB;AAAA,MACf,KAAA,EAAO;AAAA;AACT;AAEJ;AAQA,SAAS,gBAAgB,KAAA,EAA4C;AAC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CAAA;AAAA,MACA,WAAW,EAAA,CAAG,gBAAA,CAAiB,EAAE,KAAA,EAAO,GAAG,SAAS,CAAA;AAAA,MACpD,GAAA;AAAA,MAEA,QAAA,kBAAA,GAAA,CAAC,MAAA,EAAA,EAAK,SAAA,EAAU,oGAAA,EACb,QAAA,EACH;AAAA;AAAA,GACF;AAEJ;AA6BA,SAAS,SAAA,CAAU;AAAA,EACjB,SAAA;AAAA,EACA,KAAA;AAAA;AAAA;AAAA;AAAA,EAIA,2BACE,IAAA,CAAA,QAAA,EAAA,EACE,QAAA,EAAA;AAAA,oBAAA,GAAA,CAAC,QAAA,EAAA,EAAS,KAAA,EAAc,IAAA,EAAK,MAAA,EAAO,QAAA,EAAA,oBAAA,EAEpC,CAAA;AAAA,oBACA,GAAA,CAAC,QAAA,EAAA,EAAS,KAAA,EAAc,IAAA,EAAK,YAAW,QAAA,EAAA,iBAAA,EAExC;AAAA,GAAA,EACF,CAAA;AAAA,EAEF,GAAA;AAAA,EACA,GAAG;AACL,CAAA,EAAmB;AACjB,EAAA,uBACE,GAAA;AAAA,IAAC,KAAA;AAAA,IAAA;AAAA,MACC,YAAA,EAAW,YAAA;AAAA,MACX,WAAA,EAAU,YAAA;AAAA,MACT,GAAG,KAAA;AAAA,MACJ,SAAA,EAAW,EAAA,CAAG,mCAAA,EAAqC,SAAS,CAAA;AAAA,MAC5D,GAAA;AAAA,MAEC;AAAA;AAAA,GACH;AAEJ","file":"skip-link.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\n// Same curated WCAG 2.2 AAA (7:1) pairs as the Masthead — the two components\n// are designed to be themed together, mirroring how the legacy\n// `masthead-theme` option drove both `.nsw-masthead--light` and\n// `.nsw-skip--light`. Kept as a local map (not imported from masthead.tsx) so\n// each file stays standalone for registry distribution.\nconst skipLinkColors = {\n dark: 'bg-primary-800 text-white dark:bg-primary-950',\n light: 'bg-grey-100 text-grey-900',\n white: 'bg-white text-grey-900',\n grey: 'bg-grey-800 text-white',\n}\n\nconst skipLinkVariants = cva(\n [\n // Parked above the viewport until focused (legacy translateY(-101%)\n // pattern) — still in the tab order, so it is the first thing keyboard\n // and screen-reader users reach.\n 'absolute inset-x-0 top-0 w-full -translate-y-[101%]',\n 'motion-safe:transition-transform',\n 'focus:translate-y-0',\n // min-h-11 keeps the revealed bar at ≥44px — 2.5.5 Target Size (AAA).\n 'group flex min-h-11 items-center px-4 py-2 text-xs font-medium no-underline',\n // The visible focus indicator is the ring around the label span\n // (2.4.13 Focus Appearance): outline-current guarantees it contrasts with\n // the bar on every colour variant. outline-hidden (not outline-none) on\n // the anchor keeps a forced-colors fallback outline.\n 'focus:outline-hidden',\n ],\n {\n variants: {\n color: skipLinkColors,\n },\n defaultVariants: {\n color: 'dark',\n },\n },\n)\n\n/**\n * Move focus to the skip target. Fragment navigation alone only moves the\n * sequential-focus starting point; explicitly focusing the target makes\n * screen readers announce it. Non-focusable targets get a temporary\n * `tabindex=\"-1\"` (removed on blur), matching the legacy skip-to behaviour.\n */\nfunction focusSkipTarget(event: React.MouseEvent<HTMLAnchorElement>) {\n const hash = event.currentTarget.hash\n if (!hash || hash === '#') {\n return\n }\n\n let id = hash.slice(1)\n try {\n id = decodeURIComponent(id)\n } catch {\n // Malformed escape sequence — fall back to the raw fragment.\n }\n\n const target = document.getElementById(id)\n if (!target) {\n return\n }\n\n if (target.tabIndex < 0 && !target.hasAttribute('tabindex')) {\n target.setAttribute('tabindex', '-1')\n target.addEventListener(\n 'blur',\n () => {\n target.removeAttribute('tabindex')\n },\n { once: true },\n )\n }\n\n target.focus()\n}\n\ntype SkipLinkProps = React.ComponentPropsWithoutRef<'a'> &\n VariantProps<typeof skipLinkVariants> & {\n /** Same-page fragment target, e.g. `\"#content\"`. */\n href: string\n ref?: React.Ref<HTMLAnchorElement>\n }\n\n/**\n * A single focus-revealed bypass link (2.4.1 Bypass Blocks). Hidden above the\n * viewport until it receives keyboard focus, then slides in as a full-width\n * bar. Designed to sit inside `SkipLinks`, which provides the positioned\n * `<nav>` landmark; standalone use needs a positioned ancestor.\n *\n * Renders a plain `<a>` (not the themeable `Link`) because skip links are\n * same-page fragment jumps — routing framework link components are\n * unnecessary and can interfere with fragment navigation.\n */\nfunction SkipLink({ className, color, href, onClick, children, ref, ...props }: SkipLinkProps) {\n return (\n <a\n data-slot='skip-link'\n {...props}\n href={href}\n onClick={(event) => {\n onClick?.(event)\n if (!event.defaultPrevented) {\n focusSkipTarget(event)\n }\n }}\n className={cn(skipLinkVariants({ color }), className)}\n ref={ref}\n >\n <span className='group-focus:outline group-focus:outline-2 group-focus:outline-offset-2 group-focus:outline-current'>\n {children}\n </span>\n </a>\n )\n}\n\ntype SkipLinksProps = React.ComponentPropsWithoutRef<'nav'> &\n VariantProps<typeof skipLinkVariants> & {\n ref?: React.Ref<HTMLElement>\n }\n\n/**\n * Fixed landmark that holds the page's skip links, rendered as the first\n * element in the body (before the `Masthead`). Successor to the legacy\n * `.nsw-skip` nav.\n *\n * When the `children` prop is omitted it renders the legacy default pair —\n * \"Skip to navigation\" (`#nav`) and \"Skip to content\" (`#content`) — themed\n * by `color`. Any provided children (including an explicitly empty list from\n * a `.map()` or a false conditional) render exactly as given, per normal\n * React semantics — the defaults are never injected alongside or instead of\n * explicit content, since their `#nav`/`#content` targets may not exist on a\n * page that opted into custom links. Compose your own `SkipLink` children\n * for different targets or extra links:\n *\n * ```tsx\n * <SkipLinks>\n * <SkipLink href=\"#main-navigation\">Skip to navigation</SkipLink>\n * <SkipLink href=\"#main-content\">Skip to content</SkipLink>\n * <SkipLink href=\"#search\">Skip to search</SkipLink>\n * </SkipLinks>\n * ```\n */\nfunction SkipLinks({\n className,\n color,\n // Destructuring default: applies only when the prop is `undefined`\n // (omitted), never for explicit null/false/[] children. `color` is\n // initialised earlier in the pattern, so it is in scope here.\n children = (\n <>\n <SkipLink color={color} href='#nav'>\n Skip to navigation\n </SkipLink>\n <SkipLink color={color} href='#content'>\n Skip to content\n </SkipLink>\n </>\n ),\n ref,\n ...props\n}: SkipLinksProps) {\n return (\n <nav\n aria-label='Skip links'\n data-slot='skip-links'\n {...props}\n className={cn('fixed inset-x-0 top-0 z-50 w-full', className)}\n ref={ref}\n >\n {children}\n </nav>\n )\n}\n\nexport { SkipLink, SkipLinks, skipLinkVariants }\nexport type { SkipLinkProps, SkipLinksProps }\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/spinner.tsx"],"names":[],"mappings":";;;AAKA,MAAM,KAAA,GAAQ;AAAA,EACZ,IAAA,EAAM;AAAA,IACJ,EAAA,EAAI,SAAA;AAAA,IACJ,EAAA,EAAI,SAAA;AAAA,IACJ,EAAA,EAAI,SAAA;AAAA,IACJ,EAAA,EAAI,SAAA;AAAA,IACJ,EAAA,EAAI;AAAA,GACN;AAAA,EACA,KAAA,EAAO;AAAA,IACL,OAAA,EAAS,gCAAA;AAAA,IACT,MAAA,EAAQ,+BAAA;AAAA,IACR,KAAA,EAAO,0BAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAKP,OAAA,EAAS;AAAA;AAEb,CAAA;AAmBA,SAAS,OAAA,CAAQ;AAAA,EACf,SAAA;AAAA,EACA,YAAA;AAAA,EACA,IAAA,GAAO,IAAA;AAAA,EACP,KAAA,GAAQ,SAAA;AAAA,EACR,KAAA,GAAQ,SAAA;AAAA,EACR,GAAA;AAAA,EACA,GAAG;AACL,CAAA,EAAiB;AAKf,EAAA,MAAM,WAAW,KAAA,KAAU,EAAA;AAC3B,EAAA,uBACE,IAAA,CAAC,UAAK,GAAA,EAAU,IAAA,EAAM,WAAW,QAAA,GAAW,MAAA,EAAW,SAAA,EAAuB,GAAG,KAAA,EAC/E,QAAA,EAAA;AAAA,oBAAA,IAAA;AAAA,MAAC,KAAA;AAAA,MAAA;AAAA,QACC,IAAA,EAAK,MAAA;AAAA,QACL,OAAA,EAAQ,aAAA;AAAA,QACR,aAAA,EAAY,M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;AAAA,cACC,CAAA,EAAE,8WAAA;AAAA,cACF,IAAA,EAAK;AAAA;AAAA,WACP;AAAA,0BACA,GAAA;AAAA,YAAC,MAAA;AAAA,YAAA;AAAA,cACC,CAAA,EAAE,+kBAAA;AAAA,cACF,IAAA,EAAK;AAAA;AAAA;AACP;AAAA;AAAA,KACF;AAAA,IACC,2BAAW,GAAA,CAAC,MAAA,EAAA,EAAK,SAAA,EAAU,SAAA,EAAW,iBAAM,CAAA,GAAU;AAAA,GAAA,EACzD,CAAA;AAEJ","file":"spinner.js","sourcesContent":["'use client'\n\nimport * as React from 'react'\nimport { cn } from '../lib/utils.js'\n\nconst theme = {\n size: {\n xs: 'h-3 w-3',\n sm: 'h-4 w-4',\n md: 'h-6 w-6',\n lg: 'h-8 w-8',\n xl: 'h-10 w-10',\n },\n color: {\n primary: 'fill-primary-800 text-grey-400',\n accent: 'fill-accent-600 text-grey-400',\n white: 'fill-white text-white/30',\n // Inherit the surrounding text colour (e.g. inside a Button, where the\n // text colour varies per variant/colour). The arc uses currentColor at\n // full strength; the track is the same colour dimmed via opacity on the\n // first <path>, so the two-tone effect works from a single hue.\n current: 'fill-current text-current [&>path:first-child]:opacity-25',\n },\n}\n\ntype SpinnerProps = {\n /** Applied to the outer status element, like every other spread prop. */\n className?: string\n /** Applied to the inner svg (sizing/colour live there). */\n svgClassName?: string\n size?: keyof typeof theme.size\n color?: keyof typeof theme.color\n /**\n * Accessible name announced for the `role=\"status\"` element. Defaults to\n * \"Loading\"; pass an empty string to suppress when surrounding content\n * already conveys the busy state (e.g. inside a Button with a label).\n */\n label?: string\n} & React.HTMLAttributes<HTMLSpanElement> & {\n ref?: React.Ref<HTMLSpanElement>\n }\n\nfunction Spinner({\n className,\n svgClassName,\n size = 'md',\n color = 'primary',\n label = 'Loading',\n ref,\n ...props\n}: SpinnerProps) {\n // An empty label suppresses the live region entirely: a `role=\"status\"`\n // element with no text content is an empty, redundant live region (e.g. when\n // the Spinner sits inside a Button whose own `aria-busy` conveys the state).\n // A consumer-supplied `role` in `...props` still wins, as before.\n const labelled = label !== ''\n return (\n <span ref={ref} role={labelled ? 'status' : undefined} className={className} {...props}>\n <svg\n fill='none'\n viewBox='0 0 100 101'\n aria-hidden='true'\n className={cn(\n 'inline motion-safe:animate-spin',\n theme.color[color],\n theme.size[size],\n svgClassName,\n )}\n >\n <path\n d='M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z'\n fill='currentColor'\n />\n <path\n d='M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z'\n fill='currentFill'\n />\n </svg>\n {labelled ? <span className='sr-only'>{label}</span> : null}\n </span>\n )\n}\n\nexport { Spinner }\nexport type { SpinnerProps }\n"]}
|
|
@@ -60,7 +60,7 @@ const stepStatusStyles = {
|
|
|
60
60
|
};
|
|
61
61
|
const markerBase = [
|
|
62
62
|
"relative z-10 flex size-6 items-center justify-center rounded-full",
|
|
63
|
-
"
|
|
63
|
+
"motion-safe:transition-colors",
|
|
64
64
|
"[--step-ink-hover:color-mix(in_oklch,var(--step-ink)_85%,var(--black))]"
|
|
65
65
|
];
|
|
66
66
|
const markerStyles = {
|
|
@@ -78,7 +78,7 @@ const markerStyles = {
|
|
|
78
78
|
// filled for the current step).
|
|
79
79
|
dot: cn(markerBase, "border-2 border-(--step-ink) bg-background")
|
|
80
80
|
};
|
|
81
|
-
const stepTextClassName = "text-sm text-grey-700 transition-colors group-hover:text-grey-800
|
|
81
|
+
const stepTextClassName = "text-sm text-grey-700 motion-safe:transition-colors group-hover:text-grey-800 dark:text-grey-300 dark:group-hover:text-grey-100";
|
|
82
82
|
const currentTextClassName = "text-sm font-semibold text-primary-800 dark:text-primary-200";
|
|
83
83
|
const DEFAULT_STATUS_LABELS = Object.fromEntries(
|
|
84
84
|
Object.entries(stepStatusStyles).flatMap(
|
|
@@ -170,7 +170,7 @@ function StepIndicator({
|
|
|
170
170
|
"span",
|
|
171
171
|
{
|
|
172
172
|
className: cn(
|
|
173
|
-
"size-2 rounded-full
|
|
173
|
+
"size-2 rounded-full motion-safe:transition-colors",
|
|
174
174
|
currentVariant === "dot" ? "bg-(--step-ink)" : "bg-transparent group-hover:bg-(--step-ink)"
|
|
175
175
|
)
|
|
176
176
|
}
|
|
@@ -236,14 +236,14 @@ function StepNav({
|
|
|
236
236
|
ref,
|
|
237
237
|
"data-slot": "step-nav",
|
|
238
238
|
"aria-label": ariaLabel,
|
|
239
|
-
className: cn("text-base lg:text-sm", className),
|
|
239
|
+
className: cn("max-lg:text-base lg:text-sm", className),
|
|
240
240
|
...props,
|
|
241
241
|
children: /* @__PURE__ */ jsx("ol", { role: "list", className: "space-y-9", children: sections.map((section) => /* @__PURE__ */ jsxs("li", { "data-slot": "step-nav-section", children: [
|
|
242
242
|
/* @__PURE__ */ jsx(Heading, { "data-slot": "step-nav-heading", className: "font-medium text-foreground", children: section.title }),
|
|
243
243
|
/* @__PURE__ */ jsx(
|
|
244
244
|
StepIndicator,
|
|
245
245
|
{
|
|
246
|
-
className: "mt-2 lg:mt-4",
|
|
246
|
+
className: "max-lg:mt-2 lg:mt-4",
|
|
247
247
|
steps: section.steps,
|
|
248
248
|
currentHref,
|
|
249
249
|
onNavigate,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/step-indicator.tsx"],"names":[],"mappings":";;;;;;;;AAkEA,MAAM,gBAAA,GAgBF;AAAA,EACF,SAAA,EAAW;AAAA,IACT,GAAA,EAAK,sEAAA;AAAA,IACL,SAAA,EAAW,iBAAA;AAAA,IACX,MAAA,EAAQ,OAAA;AAAA,IACR,IAAA,EAAM,SAAA;AAAA,IACN,KAAA,EAAO;AAAA,GACT;AAAA,EACA,KAAA,EAAO;AAAA,IACL,GAAA,EAAK,sEAAA;AAAA,IACL,SAAA,EAAW,8BAAA;AAAA,IACX,MAAA,EAAQ,SAAA;AAAA,IACR,IAAA,EAAM,SAAA;AAAA,IACN,KAAA,EAAO;AAAA,GACT;AAAA,EACA,aAAA,EAAe;AAAA,IACb,GAAA,EAAK,sEAAA;AAAA,IACL,SAAA,EAAW,8BAAA;AAAA,IACX,MAAA,EAAQ,SAAA;AAAA,IACR,IAAA,EAAM,aAAA;AAAA,IACN,KAAA,EAAO;AAAA,GACT;AAAA,EACA,KAAA,EAAO;AAAA,IACL,GAAA,EAAK,oEAAA;AAAA,IACL,SAAA,EAAW,iBAAA;AAAA,IACX,MAAA,EAAQ,OAAA;AAAA,IACR,IAAA,EAAM,SAAA;AAAA,IACN,KAAA,EAAO;AAAA,GACT;AAAA,EACA,cAAA,EAAgB;AAAA,IACd,GAAA,EAAK,8BAAA;AAAA,IACL,SAAA,EAAW,8BAAA;AAAA,IACX,MAAA,EAAQ,OAAA;AAAA,IACR,IAAA,EAAM,UAAA;AAAA,IACN,KAAA,EAAO,kBAAA;AAAA,IACP,QAAA,EAAU;AAAA,GACZ;AAAA,EACA,aAAA,EAAe;AAAA,IACb,GAAA,EAAK,gEAAA;AAAA,IACL,SAA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GAAA,CAAC,WAAQ,WAAA,EAAU,kBAAA,EAAmB,SAAA,EAAU,6BAAA,EAC7C,kBAAQ,KAAA,EACX,CAAA;AAAA,wBACA,GAAA;AAAA,UAAC,aAAA;AAAA,UAAA;AAAA,YACC,SAAA,EAAU,cAAA;AAAA,YACV,OAAO,OAAA,CAAQ,KAAA;AAAA,YACf,WAAA;AAAA,YACA,UAAA;AAAA,YACA;AAAA;AAAA;AACF,OAAA,EAAA,EAVO,OAAA,CAAQ,KAWjB,CACD,CAAA,EACH;AAAA;AAAA,GACF;AAEJ","file":"step-indicator.js","sourcesContent":["'use client'\n\nimport React from 'react'\n\nimport { cn } from '../lib/utils.js'\n\nimport { Link } from '../components/link.js'\nimport { IconCheck } from '../icons/check.js'\nimport { IconError } from '../icons/error.js'\nimport { IconMoreHoriz } from '../icons/more-horiz.js'\nimport { IconRemove } from '../icons/remove.js'\n\n/**\n * Progress state of a single step in a multi-step journey.\n *\n * `'default'` is the unannotated baseline (a step with no `status` set) and\n * renders identically to `'not-started'` — both exist because the nswds-app\n * source distinguished them, and consumers may key behaviour off the\n * difference even though the visual is shared.\n */\ntype StepStatus =\n 'default' | 'not-started' | 'in-progress' | 'completed' | 'saved' | 'error' | 'cannot-start'\n\n/** One entry in a {@link StepIndicator} list. */\ntype Step = {\n /** Visible step name, e.g. \"Your details\". */\n title: string\n /** Optional second line under the title. */\n description?: string\n /** Navigation target; also the identity compared against `currentHref`. */\n href: string\n /** Progress state. Omitted = `'default'` (renders as not started). */\n status?: StepStatus\n}\n\n/**\n * Per-status visual treatment, collapsed from the nswds-app source's seven\n * copy-pasted JSX branches into one map. Every colour funnels through a single\n * `--step-ink` custom property declared on the `<li>`, so the marker,\n * connector, hover fill and focus ring all follow from one declaration per\n * status (the same ink-token pattern as footer.tsx / link.tsx).\n *\n * Ink values use RAW @nswds/tokens custom properties (`--success-600`, not the\n * `--color-success-600` Tailwind bridge alias): Tailwind v4 tree-shakes\n * unreferenced `@theme` keys and an arbitrary-property reference is not a\n * usage signal, but the raw tokens are plain `:root` declarations that always\n * resolve — the same precedent as button.tsx's semantic colours.\n *\n * Token remapping from the nswds-app source (documented per §3 of AGENTS.md):\n * - completed/saved: `success-450`/`-500`/`-550` → `--success-600` (dark:\n * `--success-500`). 450 (L≈0.63) gives the white check only ≈2.4:1; 600\n * (L≈0.55) clears the 3:1 non-text minimum (WCAG 2.2 1.4.11) and matches\n * Button's solid success.\n * - in-progress: `primary-500` → `--primary-600` (dark: `--primary-450`).\n * Masterbrand primary-500 (L≈0.72) fails 3:1 against white for the marker\n * border and icon; 600 matches Button's tertiary. The dark override\n * lightens the ink so it clears 3:1 against dark surfaces.\n * - error: `danger-450`/`-500` → `--danger-600` (dark: `--danger-500`),\n * matching Button's solid danger.\n * - not-started/default: border `grey-300` → `--grey-500` (dark:\n * `--grey-450`). grey-300 (L≈0.90) is ≈1.2:1 against white — invisible to\n * low-vision users; grey-500 clears 3:1 (1.4.11).\n * - cannot-start: `grey-600` kept (white glyph on it is ≈7:1 in both modes).\n * - marker fill `bg-white` → `bg-background` so outlined markers sit on the\n * page surface in dark mode instead of punching white holes in it.\n */\nconst stepStatusStyles: Record<\n StepStatus,\n {\n /** `--step-ink` declaration, applied to the `<li>` so descendants inherit. */\n ink: string\n /** Connector line colour (the `aria-hidden` rule between markers). */\n connector: string\n /** Structural marker treatment. */\n marker: 'solid' | 'outline' | 'dot'\n /** Glyph rendered inside the marker (always `aria-hidden`). */\n icon: React.ElementType | null\n /** Default visually-hidden status announcement (see `statusLabels`). */\n label?: string\n /** Steps that must not be reachable yet. */\n disabled?: boolean\n }\n> = {\n completed: {\n ink: '[--step-ink:var(--success-600)] dark:[--step-ink:var(--success-500)]',\n connector: 'bg-(--step-ink)',\n marker: 'solid',\n icon: IconCheck,\n label: 'Completed',\n },\n saved: {\n ink: '[--step-ink:var(--success-600)] dark:[--step-ink:var(--success-500)]',\n connector: 'bg-grey-300 dark:bg-grey-700',\n marker: 'outline',\n icon: IconCheck,\n label: 'Saved',\n },\n 'in-progress': {\n ink: '[--step-ink:var(--primary-600)] dark:[--step-ink:var(--primary-450)]',\n connector: 'bg-grey-300 dark:bg-grey-700',\n marker: 'outline',\n icon: IconMoreHoriz,\n label: 'In progress',\n },\n error: {\n ink: '[--step-ink:var(--danger-600)] dark:[--step-ink:var(--danger-500)]',\n connector: 'bg-(--step-ink)',\n marker: 'solid',\n icon: IconError,\n label: 'Error',\n },\n 'cannot-start': {\n ink: '[--step-ink:var(--grey-600)]',\n connector: 'bg-grey-300 dark:bg-grey-700',\n marker: 'solid',\n icon: IconRemove,\n label: 'Cannot start yet',\n disabled: true,\n },\n 'not-started': {\n ink: '[--step-ink:var(--grey-500)] dark:[--step-ink:var(--grey-450)]',\n connector: 'bg-grey-300 dark:bg-grey-700',\n marker: 'dot',\n icon: null,\n label: 'Not started',\n },\n default: {\n ink: '[--step-ink:var(--grey-500)] dark:[--step-ink:var(--grey-450)]',\n connector: 'bg-grey-300 dark:bg-grey-700',\n marker: 'dot',\n icon: null,\n },\n}\n\n// Shared marker shell. The hover shade derives from the ink via color-mix and\n// is declared here — NOT on the <ol> — because a custom property that\n// substitutes var(--step-ink) is resolved on the element it is declared on;\n// on the list root the ink is still undefined and the whole property would\n// compute to invalid. On the marker the inherited per-status ink has already\n// resolved. `--black` is the raw @nswds/tokens value (always on :root), not\n// the tree-shakeable --color-black bridge alias.\nconst markerBase = [\n 'relative z-10 flex size-6 items-center justify-center rounded-full',\n 'transition-colors motion-reduce:transition-none',\n '[--step-ink-hover:color-mix(in_oklch,var(--step-ink)_85%,var(--black))]',\n]\n\nconst markerStyles = {\n // Solid disc, white glyph; hover deepens the fill (source: -450 → -500).\n solid: cn(markerBase, 'bg-(--step-ink) text-white group-hover:bg-(--step-ink-hover)'),\n // Outlined disc, ink glyph; hover fills with the ink and inverts the glyph\n // (source: saved/in-progress fill-on-hover). In dark mode the inks are\n // light steps, so the hovered glyph flips to a dark grey instead of white.\n outline: cn(\n markerBase,\n 'border-2 border-(--step-ink) bg-background text-(--step-ink)',\n 'group-hover:bg-(--step-ink) group-hover:text-white dark:group-hover:text-grey-900',\n ),\n // Outlined disc with a centre dot that appears on hover (or is always\n // filled for the current step).\n dot: cn(markerBase, 'border-2 border-(--step-ink) bg-background'),\n}\n\n// One text treatment for title and description. The source coloured\n// `dark:text-slate-400` — a raw-palette leak — remapped here onto the grey\n// ramp. Hover moved from the text spans to `group-hover` so the whole link\n// (marker included) gives feedback, not just the glyph under the pointer.\nconst stepTextClassName =\n 'text-sm text-grey-700 transition-colors group-hover:text-grey-800 motion-reduce:transition-none dark:text-grey-300 dark:group-hover:text-grey-100'\n\n// Emphasised text for the current step. Source used primary-500 /\n// dark:slate-400; remapped to primary-800 / primary-200 — the ramp's text\n// steps (WCAG 2.2 1.4.3 AA needs 4.5:1 for 14px text; primary-500 on white\n// is ≈2.9:1).\nconst currentTextClassName = 'text-sm font-semibold text-primary-800 dark:text-primary-200'\n\n/** Built-in announcements; override or suppress per status via `statusLabels`. */\nconst DEFAULT_STATUS_LABELS: Partial<Record<StepStatus, string>> = Object.fromEntries(\n Object.entries(stepStatusStyles).flatMap(([status, style]) =>\n style.label ? [[status, style.label]] : [],\n ),\n)\n\ntype StepIndicatorProps = Omit<React.ComponentPropsWithoutRef<'ol'>, 'children'> & {\n /** Steps to render, in journey order. `href` must be unique per step. */\n steps: Step[]\n /**\n * The href of the page being viewed. The matching step gets\n * `aria-current=\"step\"` and — when its status carries no stronger visual\n * (default / not-started / in-progress) — the emphasised current treatment.\n * Replaces the source's internal next/navigation `usePathname()` coupling\n * so the component stays framework-free.\n */\n currentHref?: string\n /** Click handler applied to every enabled step link. */\n onNavigate?: React.MouseEventHandler<HTMLAnchorElement>\n /**\n * Visually-hidden status announcements appended to each title, merged over\n * the English defaults (\"Completed\", \"Saved\", …). Set a status to\n * `undefined` to suppress its announcement; supply strings to localise.\n */\n statusLabels?: Partial<Record<StepStatus, string | undefined>>\n ref?: React.Ref<HTMLOListElement>\n}\n\n/**\n * Vertical list of the steps in a multi-step journey — one link per step with\n * a status marker and connector line, as used beside long NSW Government\n * application forms.\n *\n * Accessibility contract:\n * - Renders an `<ol role=\"list\">` — steps are a sequence, so an ordered list\n * conveys the ordering to assistive tech (the nswds-app source used `<ul>`);\n * the explicit `role` restores list semantics in Safari/VoiceOver where\n * `list-style: none` removes them.\n * - The step matching `currentHref` gets `aria-current=\"step\"` whatever its\n * status (the source only set it on one of its seven branches).\n * - Markers and connectors are purely decorative (`aria-hidden`); status is\n * announced through a visually-hidden suffix after each title instead,\n * because colour and iconography alone would leave screen-reader users with\n * no status at all (WCAG 2.2 1.4.1 Use of Colour). See `statusLabels`.\n * - `cannot-start` steps are `aria-disabled`, removed from the tab order and\n * click-inert — the source left them fully clickable, which invited\n * navigation into pages that reject you.\n * - Links get a `focus-visible` outline drawn in the status ink (the source\n * relied on browser defaults), satisfying 2.4.7 Focus Visible with a 3:1\n * indicator (2.4.13).\n *\n * All anchors render through `Link` (`variant=\"unstyled\"`), so apps can inject\n * a framework link (e.g. next/link) via `LinkProvider`.\n */\nfunction StepIndicator({\n steps,\n currentHref,\n onNavigate,\n statusLabels,\n className,\n ref,\n ...props\n}: StepIndicatorProps) {\n if (process.env.NODE_ENV !== 'production') {\n const seen = new Set<string>()\n for (const step of steps) {\n if (seen.has(step.href)) {\n console.warn(\n `[nswds/ui] StepIndicator: duplicate step href \"${step.href}\" — hrefs are used as React keys and for currentHref matching, so duplicates will misrender.`,\n )\n }\n seen.add(step.href)\n }\n }\n\n const labels = { ...DEFAULT_STATUS_LABELS, ...statusLabels }\n\n return (\n <ol\n role='list'\n ref={ref}\n data-slot='step-indicator'\n className={cn('w-full', className)}\n {...props}\n >\n {steps.map((step, stepIdx) => {\n const status: StepStatus = step.status ?? 'default'\n const style = stepStatusStyles[status]\n const isCurrent = currentHref !== undefined && step.href === currentHref\n // Statuses with a strong treatment of their own (completed, saved,\n // error, cannot-start) keep it even when current — matching the\n // source's branch order.\n const currentVariant = !isCurrent\n ? null\n : status === 'in-progress'\n ? ('ring' as const)\n : status === 'default' || status === 'not-started'\n ? ('dot' as const)\n : null\n const isLast = stepIdx === steps.length - 1\n const StatusIcon = style.icon\n const label = labels[status]\n\n return (\n <li\n key={step.href}\n data-slot='step'\n data-status={status}\n data-current={isCurrent || undefined}\n className={cn(\n 'relative',\n !isLast && 'pb-3',\n style.ink,\n // A current default/not-started step promotes its ink to the\n // in-progress primary so the filled dot and ring read as \"you\n // are here\", not \"not started\".\n currentVariant === 'dot' && stepStatusStyles['in-progress'].ink,\n )}\n >\n {!isLast && (\n <div\n aria-hidden='true'\n data-slot='step-connector'\n className={cn('absolute top-4 left-3 mt-0.5 -ml-px h-full w-0.5', style.connector)}\n />\n )}\n <Link\n variant='unstyled'\n href={step.href}\n data-slot='step-link'\n aria-current={isCurrent ? 'step' : undefined}\n className={cn(\n 'group relative flex items-center rounded-sm',\n 'focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--step-ink)',\n style.disabled && 'pointer-events-none',\n )}\n onClick={\n style.disabled\n ? (event: React.MouseEvent<HTMLAnchorElement>) => event.preventDefault()\n : onNavigate\n }\n {...(style.disabled ? { 'aria-disabled': true, tabIndex: -1 } : {})}\n >\n {currentVariant === 'ring' ? (\n // Double ring: the source's emphasised in-progress-current\n // marker. The outer 32px ring centres on the 24px grid via\n // -ml-1, so the connector still meets the marker's middle.\n <span aria-hidden='true' className='-ml-1 flex h-9 items-center'>\n <span data-slot='step-marker' className={cn(markerStyles.dot, 'size-8')}>\n <span className='flex size-6 items-center justify-center rounded-full border-2 border-(--step-ink) bg-background'>\n <IconMoreHoriz className='size-4 text-(--step-ink)' aria-hidden='true' />\n </span>\n </span>\n </span>\n ) : (\n <span aria-hidden='true' className='flex h-9 items-center'>\n <span data-slot='step-marker' className={markerStyles[style.marker]}>\n {style.marker === 'dot' ? (\n <span\n className={cn(\n 'size-2 rounded-full transition-colors motion-reduce:transition-none',\n currentVariant === 'dot'\n ? 'bg-(--step-ink)'\n : 'bg-transparent group-hover:bg-(--step-ink)',\n )}\n />\n ) : (\n StatusIcon && <StatusIcon className='size-4' aria-hidden='true' />\n )}\n </span>\n </span>\n )}\n <span\n data-slot='step-content'\n className={cn('flex min-w-0 flex-col', currentVariant === 'ring' ? 'ml-3' : 'ml-4')}\n >\n <span\n data-slot='step-title'\n className={currentVariant ? currentTextClassName : stepTextClassName}\n >\n {step.title}\n {label && <span className='sr-only'> ({label})</span>}\n </span>\n {step.description && (\n <span\n data-slot='step-description'\n className={currentVariant ? currentTextClassName : stepTextClassName}\n >\n {step.description}\n </span>\n )}\n </span>\n </Link>\n </li>\n )\n })}\n </ol>\n )\n}\n\n/** A titled group of steps inside {@link StepNav}. */\ntype StepNavSection = {\n /** Section heading, e.g. \"Before you start\". */\n title: string\n steps: Step[]\n}\n\ntype StepNavProps = Omit<React.ComponentPropsWithoutRef<'nav'>, 'children'> & {\n /** Titled groups of steps, rendered as heading + StepIndicator pairs. */\n sections: StepNavSection[]\n /**\n * Heading element for section titles. Defaults to 2; set it so the headings\n * slot into the surrounding page outline (WCAG 2.2 1.3.1).\n */\n headingLevel?: 2 | 3 | 4 | 5 | 6\n /** Forwarded to every section's {@link StepIndicator}. */\n currentHref?: string\n /** Forwarded to every section's {@link StepIndicator}. */\n onNavigate?: React.MouseEventHandler<HTMLAnchorElement>\n /** Forwarded to every section's {@link StepIndicator}. */\n statusLabels?: Partial<Record<StepStatus, string | undefined>>\n ref?: React.Ref<HTMLElement>\n}\n\n/**\n * Sectioned journey navigation: a `<nav>` landmark containing one heading +\n * {@link StepIndicator} per section.\n *\n * Ported from nswds-app's `StepNavigation`, minus the app's form-store\n * coupling — the source read each step's status out of a zustand\n * `useFormStore` hook; the design-system version takes status as data on the\n * `steps` themselves, so any state source (form store, server props, URL) can\n * drive it.\n *\n * Accessibility contract:\n * - The landmark is named (`aria-label=\"Progress\"` by default, overridable)\n * so it is distinguishable from the site's other navigation landmarks\n * (WCAG 2.2 2.4.1 / ARIA landmark naming).\n * - Sections are an `<ol role=\"list\">` (they are ordered phases of one\n * journey; the source used `<ul>`).\n * - Section titles use a real heading element chosen via `headingLevel`\n * (source hard-coded `<h2>`), and the source's `text-slate-900` leak is\n * replaced with the theme-aware `text-foreground`.\n */\nfunction StepNav({\n sections,\n headingLevel = 2,\n currentHref,\n onNavigate,\n statusLabels,\n className,\n 'aria-label': ariaLabel = 'Progress',\n ref,\n ...props\n}: StepNavProps) {\n const Heading = `h${headingLevel}` as `h${2 | 3 | 4 | 5 | 6}`\n\n return (\n <nav\n ref={ref}\n data-slot='step-nav'\n aria-label={ariaLabel}\n className={cn('text-base lg:text-sm', className)}\n {...props}\n >\n <ol role='list' className='space-y-9'>\n {sections.map((section) => (\n <li key={section.title} data-slot='step-nav-section'>\n <Heading data-slot='step-nav-heading' className='font-medium text-foreground'>\n {section.title}\n </Heading>\n <StepIndicator\n className='mt-2 lg:mt-4'\n steps={section.steps}\n currentHref={currentHref}\n onNavigate={onNavigate}\n statusLabels={statusLabels}\n />\n </li>\n ))}\n </ol>\n </nav>\n )\n}\n\nexport { StepIndicator, StepNav, stepStatusStyles }\nexport type { Step, StepIndicatorProps, StepNavProps, StepNavSection, StepStatus }\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/components/step-indicator.tsx"],"names":[],"mappings":";;;;;;;;AAkEA,MAAM,gBAAA,GAgBF;AAAA,EACF,SAAA,EAAW;AAAA,IACT,GAAA,EAAK,sEAAA;AAAA,IACL,SAAA,EAAW,iBAAA;AAAA,IACX,MAAA,EAAQ,OAAA;AAAA,IACR,IAAA,EAAM,SAAA;AAAA,IACN,KAAA,EAAO;AAAA,GACT;AAAA,EACA,KAAA,EAAO;AAAA,IACL,GAAA,EAAK,sEAAA;AAAA,IACL,SAAA,EAAW,8BAAA;AAAA,IACX,MAAA,EAAQ,SAAA;AAAA,IACR,IAAA,EAAM,SAAA;AAAA,IACN,KAAA,EAAO;AAAA,GACT;AAAA,EACA,aAAA,EAAe;AAAA,IACb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AAAA,EACA,cAAc,SAAA,GAAY,UAAA;AAAA,EAC1B,GAAA;AAAA,EACA,GAAG;AACL,CAAA,EAAiB;AACf,EAAA,MAAM,OAAA,GAAU,IAAI,YAAY,CAAA,CAAA;AAEhC,EAAA,uBACE,GAAA;AAAA,IAAC,KAAA;AAAA,IAAA;AAAA,MACC,GAAA;AAAA,MACA,WAAA,EAAU,UAAA;AAAA,MACV,YAAA,EAAY,SAAA;AAAA,MACZ,SAAA,EAAW,EAAA,CAAG,6BAAA,EAA+B,SAAS,CAAA;AAAA,MACrD,GAAG,KAAA;AAAA,MAEJ,QAAA,kBAAA,GAAA,CAAC,IAAA,EAAA,EAAG,IAAA,EAAK,MAAA,EAAO,SAAA,EAAU,WAAA,EACvB,QAAA,EAAA,QAAA,CAAS,GAAA,CAAI,CAAC,OAAA,qBACb,IAAA,CAAC,IAAA,EAAA,EAAuB,aAAU,kBAAA,EAChC,QAAA,EAAA;AAAA,wBAAA,GAAA,CAAC,WAAQ,WAAA,EAAU,kBAAA,EAAmB,SAAA,EAAU,6BAAA,EAC7C,kBAAQ,KAAA,EACX,CAAA;AAAA,wBACA,GAAA;AAAA,UAAC,aAAA;AAAA,UAAA;AAAA,YACC,SAAA,EAAU,qBAAA;AAAA,YACV,OAAO,OAAA,CAAQ,KAAA;AAAA,YACf,WAAA;AAAA,YACA,UAAA;AAAA,YACA;AAAA;AAAA;AACF,OAAA,EAAA,EAVO,OAAA,CAAQ,KAWjB,CACD,CAAA,EACH;AAAA;AAAA,GACF;AAEJ","file":"step-indicator.js","sourcesContent":["'use client'\n\nimport React from 'react'\n\nimport { cn } from '../lib/utils.js'\n\nimport { Link } from '../components/link.js'\nimport { IconCheck } from '../icons/check.js'\nimport { IconError } from '../icons/error.js'\nimport { IconMoreHoriz } from '../icons/more-horiz.js'\nimport { IconRemove } from '../icons/remove.js'\n\n/**\n * Progress state of a single step in a multi-step journey.\n *\n * `'default'` is the unannotated baseline (a step with no `status` set) and\n * renders identically to `'not-started'` — both exist because the nswds-app\n * source distinguished them, and consumers may key behaviour off the\n * difference even though the visual is shared.\n */\ntype StepStatus =\n 'default' | 'not-started' | 'in-progress' | 'completed' | 'saved' | 'error' | 'cannot-start'\n\n/** One entry in a {@link StepIndicator} list. */\ntype Step = {\n /** Visible step name, e.g. \"Your details\". */\n title: string\n /** Optional second line under the title. */\n description?: string\n /** Navigation target; also the identity compared against `currentHref`. */\n href: string\n /** Progress state. Omitted = `'default'` (renders as not started). */\n status?: StepStatus\n}\n\n/**\n * Per-status visual treatment, collapsed from the nswds-app source's seven\n * copy-pasted JSX branches into one map. Every colour funnels through a single\n * `--step-ink` custom property declared on the `<li>`, so the marker,\n * connector, hover fill and focus ring all follow from one declaration per\n * status (the same ink-token pattern as footer.tsx / link.tsx).\n *\n * Ink values use RAW @nswds/tokens custom properties (`--success-600`, not the\n * `--color-success-600` Tailwind bridge alias): Tailwind v4 tree-shakes\n * unreferenced `@theme` keys and an arbitrary-property reference is not a\n * usage signal, but the raw tokens are plain `:root` declarations that always\n * resolve — the same precedent as button.tsx's semantic colours.\n *\n * Token remapping from the nswds-app source (documented per §3 of AGENTS.md):\n * - completed/saved: `success-450`/`-500`/`-550` → `--success-600` (dark:\n * `--success-500`). 450 (L≈0.63) gives the white check only ≈2.4:1; 600\n * (L≈0.55) clears the 3:1 non-text minimum (WCAG 2.2 1.4.11) and matches\n * Button's solid success.\n * - in-progress: `primary-500` → `--primary-600` (dark: `--primary-450`).\n * Masterbrand primary-500 (L≈0.72) fails 3:1 against white for the marker\n * border and icon; 600 matches Button's tertiary. The dark override\n * lightens the ink so it clears 3:1 against dark surfaces.\n * - error: `danger-450`/`-500` → `--danger-600` (dark: `--danger-500`),\n * matching Button's solid danger.\n * - not-started/default: border `grey-300` → `--grey-500` (dark:\n * `--grey-450`). grey-300 (L≈0.90) is ≈1.2:1 against white — invisible to\n * low-vision users; grey-500 clears 3:1 (1.4.11).\n * - cannot-start: `grey-600` kept (white glyph on it is ≈7:1 in both modes).\n * - marker fill `bg-white` → `bg-background` so outlined markers sit on the\n * page surface in dark mode instead of punching white holes in it.\n */\nconst stepStatusStyles: Record<\n StepStatus,\n {\n /** `--step-ink` declaration, applied to the `<li>` so descendants inherit. */\n ink: string\n /** Connector line colour (the `aria-hidden` rule between markers). */\n connector: string\n /** Structural marker treatment. */\n marker: 'solid' | 'outline' | 'dot'\n /** Glyph rendered inside the marker (always `aria-hidden`). */\n icon: React.ElementType | null\n /** Default visually-hidden status announcement (see `statusLabels`). */\n label?: string\n /** Steps that must not be reachable yet. */\n disabled?: boolean\n }\n> = {\n completed: {\n ink: '[--step-ink:var(--success-600)] dark:[--step-ink:var(--success-500)]',\n connector: 'bg-(--step-ink)',\n marker: 'solid',\n icon: IconCheck,\n label: 'Completed',\n },\n saved: {\n ink: '[--step-ink:var(--success-600)] dark:[--step-ink:var(--success-500)]',\n connector: 'bg-grey-300 dark:bg-grey-700',\n marker: 'outline',\n icon: IconCheck,\n label: 'Saved',\n },\n 'in-progress': {\n ink: '[--step-ink:var(--primary-600)] dark:[--step-ink:var(--primary-450)]',\n connector: 'bg-grey-300 dark:bg-grey-700',\n marker: 'outline',\n icon: IconMoreHoriz,\n label: 'In progress',\n },\n error: {\n ink: '[--step-ink:var(--danger-600)] dark:[--step-ink:var(--danger-500)]',\n connector: 'bg-(--step-ink)',\n marker: 'solid',\n icon: IconError,\n label: 'Error',\n },\n 'cannot-start': {\n ink: '[--step-ink:var(--grey-600)]',\n connector: 'bg-grey-300 dark:bg-grey-700',\n marker: 'solid',\n icon: IconRemove,\n label: 'Cannot start yet',\n disabled: true,\n },\n 'not-started': {\n ink: '[--step-ink:var(--grey-500)] dark:[--step-ink:var(--grey-450)]',\n connector: 'bg-grey-300 dark:bg-grey-700',\n marker: 'dot',\n icon: null,\n label: 'Not started',\n },\n default: {\n ink: '[--step-ink:var(--grey-500)] dark:[--step-ink:var(--grey-450)]',\n connector: 'bg-grey-300 dark:bg-grey-700',\n marker: 'dot',\n icon: null,\n },\n}\n\n// Shared marker shell. The hover shade derives from the ink via color-mix and\n// is declared here — NOT on the <ol> — because a custom property that\n// substitutes var(--step-ink) is resolved on the element it is declared on;\n// on the list root the ink is still undefined and the whole property would\n// compute to invalid. On the marker the inherited per-status ink has already\n// resolved. `--black` is the raw @nswds/tokens value (always on :root), not\n// the tree-shakeable --color-black bridge alias.\nconst markerBase = [\n 'relative z-10 flex size-6 items-center justify-center rounded-full',\n 'motion-safe:transition-colors',\n '[--step-ink-hover:color-mix(in_oklch,var(--step-ink)_85%,var(--black))]',\n]\n\nconst markerStyles = {\n // Solid disc, white glyph; hover deepens the fill (source: -450 → -500).\n solid: cn(markerBase, 'bg-(--step-ink) text-white group-hover:bg-(--step-ink-hover)'),\n // Outlined disc, ink glyph; hover fills with the ink and inverts the glyph\n // (source: saved/in-progress fill-on-hover). In dark mode the inks are\n // light steps, so the hovered glyph flips to a dark grey instead of white.\n outline: cn(\n markerBase,\n 'border-2 border-(--step-ink) bg-background text-(--step-ink)',\n 'group-hover:bg-(--step-ink) group-hover:text-white dark:group-hover:text-grey-900',\n ),\n // Outlined disc with a centre dot that appears on hover (or is always\n // filled for the current step).\n dot: cn(markerBase, 'border-2 border-(--step-ink) bg-background'),\n}\n\n// One text treatment for title and description. The source coloured\n// `dark:text-slate-400` — a raw-palette leak — remapped here onto the grey\n// ramp. Hover moved from the text spans to `group-hover` so the whole link\n// (marker included) gives feedback, not just the glyph under the pointer.\nconst stepTextClassName =\n 'text-sm text-grey-700 motion-safe:transition-colors group-hover:text-grey-800 dark:text-grey-300 dark:group-hover:text-grey-100'\n\n// Emphasised text for the current step. Source used primary-500 /\n// dark:slate-400; remapped to primary-800 / primary-200 — the ramp's text\n// steps (WCAG 2.2 1.4.3 AA needs 4.5:1 for 14px text; primary-500 on white\n// is ≈2.9:1).\nconst currentTextClassName = 'text-sm font-semibold text-primary-800 dark:text-primary-200'\n\n/** Built-in announcements; override or suppress per status via `statusLabels`. */\nconst DEFAULT_STATUS_LABELS: Partial<Record<StepStatus, string>> = Object.fromEntries(\n Object.entries(stepStatusStyles).flatMap(([status, style]) =>\n style.label ? [[status, style.label]] : [],\n ),\n)\n\ntype StepIndicatorProps = Omit<React.ComponentPropsWithoutRef<'ol'>, 'children'> & {\n /** Steps to render, in journey order. `href` must be unique per step. */\n steps: Step[]\n /**\n * The href of the page being viewed. The matching step gets\n * `aria-current=\"step\"` and — when its status carries no stronger visual\n * (default / not-started / in-progress) — the emphasised current treatment.\n * Replaces the source's internal next/navigation `usePathname()` coupling\n * so the component stays framework-free.\n */\n currentHref?: string\n /** Click handler applied to every enabled step link. */\n onNavigate?: React.MouseEventHandler<HTMLAnchorElement>\n /**\n * Visually-hidden status announcements appended to each title, merged over\n * the English defaults (\"Completed\", \"Saved\", …). Set a status to\n * `undefined` to suppress its announcement; supply strings to localise.\n */\n statusLabels?: Partial<Record<StepStatus, string | undefined>>\n ref?: React.Ref<HTMLOListElement>\n}\n\n/**\n * Vertical list of the steps in a multi-step journey — one link per step with\n * a status marker and connector line, as used beside long NSW Government\n * application forms.\n *\n * Accessibility contract:\n * - Renders an `<ol role=\"list\">` — steps are a sequence, so an ordered list\n * conveys the ordering to assistive tech (the nswds-app source used `<ul>`);\n * the explicit `role` restores list semantics in Safari/VoiceOver where\n * `list-style: none` removes them.\n * - The step matching `currentHref` gets `aria-current=\"step\"` whatever its\n * status (the source only set it on one of its seven branches).\n * - Markers and connectors are purely decorative (`aria-hidden`); status is\n * announced through a visually-hidden suffix after each title instead,\n * because colour and iconography alone would leave screen-reader users with\n * no status at all (WCAG 2.2 1.4.1 Use of Colour). See `statusLabels`.\n * - `cannot-start` steps are `aria-disabled`, removed from the tab order and\n * click-inert — the source left them fully clickable, which invited\n * navigation into pages that reject you.\n * - Links get a `focus-visible` outline drawn in the status ink (the source\n * relied on browser defaults), satisfying 2.4.7 Focus Visible with a 3:1\n * indicator (2.4.13).\n *\n * All anchors render through `Link` (`variant=\"unstyled\"`), so apps can inject\n * a framework link (e.g. next/link) via `LinkProvider`.\n */\nfunction StepIndicator({\n steps,\n currentHref,\n onNavigate,\n statusLabels,\n className,\n ref,\n ...props\n}: StepIndicatorProps) {\n if (process.env.NODE_ENV !== 'production') {\n const seen = new Set<string>()\n for (const step of steps) {\n if (seen.has(step.href)) {\n console.warn(\n `[nswds/ui] StepIndicator: duplicate step href \"${step.href}\" — hrefs are used as React keys and for currentHref matching, so duplicates will misrender.`,\n )\n }\n seen.add(step.href)\n }\n }\n\n const labels = { ...DEFAULT_STATUS_LABELS, ...statusLabels }\n\n return (\n <ol\n role='list'\n ref={ref}\n data-slot='step-indicator'\n className={cn('w-full', className)}\n {...props}\n >\n {steps.map((step, stepIdx) => {\n const status: StepStatus = step.status ?? 'default'\n const style = stepStatusStyles[status]\n const isCurrent = currentHref !== undefined && step.href === currentHref\n // Statuses with a strong treatment of their own (completed, saved,\n // error, cannot-start) keep it even when current — matching the\n // source's branch order.\n const currentVariant = !isCurrent\n ? null\n : status === 'in-progress'\n ? ('ring' as const)\n : status === 'default' || status === 'not-started'\n ? ('dot' as const)\n : null\n const isLast = stepIdx === steps.length - 1\n const StatusIcon = style.icon\n const label = labels[status]\n\n return (\n <li\n key={step.href}\n data-slot='step'\n data-status={status}\n data-current={isCurrent || undefined}\n className={cn(\n 'relative',\n !isLast && 'pb-3',\n style.ink,\n // A current default/not-started step promotes its ink to the\n // in-progress primary so the filled dot and ring read as \"you\n // are here\", not \"not started\".\n currentVariant === 'dot' && stepStatusStyles['in-progress'].ink,\n )}\n >\n {!isLast && (\n <div\n aria-hidden='true'\n data-slot='step-connector'\n className={cn('absolute top-4 left-3 mt-0.5 -ml-px h-full w-0.5', style.connector)}\n />\n )}\n <Link\n variant='unstyled'\n href={step.href}\n data-slot='step-link'\n aria-current={isCurrent ? 'step' : undefined}\n className={cn(\n 'group relative flex items-center rounded-sm',\n 'focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--step-ink)',\n style.disabled && 'pointer-events-none',\n )}\n onClick={\n style.disabled\n ? (event: React.MouseEvent<HTMLAnchorElement>) => event.preventDefault()\n : onNavigate\n }\n {...(style.disabled ? { 'aria-disabled': true, tabIndex: -1 } : {})}\n >\n {currentVariant === 'ring' ? (\n // Double ring: the source's emphasised in-progress-current\n // marker. The outer 32px ring centres on the 24px grid via\n // -ml-1, so the connector still meets the marker's middle.\n <span aria-hidden='true' className='-ml-1 flex h-9 items-center'>\n <span data-slot='step-marker' className={cn(markerStyles.dot, 'size-8')}>\n <span className='flex size-6 items-center justify-center rounded-full border-2 border-(--step-ink) bg-background'>\n <IconMoreHoriz className='size-4 text-(--step-ink)' aria-hidden='true' />\n </span>\n </span>\n </span>\n ) : (\n <span aria-hidden='true' className='flex h-9 items-center'>\n <span data-slot='step-marker' className={markerStyles[style.marker]}>\n {style.marker === 'dot' ? (\n <span\n className={cn(\n 'size-2 rounded-full motion-safe:transition-colors',\n currentVariant === 'dot'\n ? 'bg-(--step-ink)'\n : 'bg-transparent group-hover:bg-(--step-ink)',\n )}\n />\n ) : (\n StatusIcon && <StatusIcon className='size-4' aria-hidden='true' />\n )}\n </span>\n </span>\n )}\n <span\n data-slot='step-content'\n className={cn('flex min-w-0 flex-col', currentVariant === 'ring' ? 'ml-3' : 'ml-4')}\n >\n <span\n data-slot='step-title'\n className={currentVariant ? currentTextClassName : stepTextClassName}\n >\n {step.title}\n {label && <span className='sr-only'> ({label})</span>}\n </span>\n {step.description && (\n <span\n data-slot='step-description'\n className={currentVariant ? currentTextClassName : stepTextClassName}\n >\n {step.description}\n </span>\n )}\n </span>\n </Link>\n </li>\n )\n })}\n </ol>\n )\n}\n\n/** A titled group of steps inside {@link StepNav}. */\ntype StepNavSection = {\n /** Section heading, e.g. \"Before you start\". */\n title: string\n steps: Step[]\n}\n\ntype StepNavProps = Omit<React.ComponentPropsWithoutRef<'nav'>, 'children'> & {\n /** Titled groups of steps, rendered as heading + StepIndicator pairs. */\n sections: StepNavSection[]\n /**\n * Heading element for section titles. Defaults to 2; set it so the headings\n * slot into the surrounding page outline (WCAG 2.2 1.3.1).\n */\n headingLevel?: 2 | 3 | 4 | 5 | 6\n /** Forwarded to every section's {@link StepIndicator}. */\n currentHref?: string\n /** Forwarded to every section's {@link StepIndicator}. */\n onNavigate?: React.MouseEventHandler<HTMLAnchorElement>\n /** Forwarded to every section's {@link StepIndicator}. */\n statusLabels?: Partial<Record<StepStatus, string | undefined>>\n ref?: React.Ref<HTMLElement>\n}\n\n/**\n * Sectioned journey navigation: a `<nav>` landmark containing one heading +\n * {@link StepIndicator} per section.\n *\n * Ported from nswds-app's `StepNavigation`, minus the app's form-store\n * coupling — the source read each step's status out of a zustand\n * `useFormStore` hook; the design-system version takes status as data on the\n * `steps` themselves, so any state source (form store, server props, URL) can\n * drive it.\n *\n * Accessibility contract:\n * - The landmark is named (`aria-label=\"Progress\"` by default, overridable)\n * so it is distinguishable from the site's other navigation landmarks\n * (WCAG 2.2 2.4.1 / ARIA landmark naming).\n * - Sections are an `<ol role=\"list\">` (they are ordered phases of one\n * journey; the source used `<ul>`).\n * - Section titles use a real heading element chosen via `headingLevel`\n * (source hard-coded `<h2>`), and the source's `text-slate-900` leak is\n * replaced with the theme-aware `text-foreground`.\n */\nfunction StepNav({\n sections,\n headingLevel = 2,\n currentHref,\n onNavigate,\n statusLabels,\n className,\n 'aria-label': ariaLabel = 'Progress',\n ref,\n ...props\n}: StepNavProps) {\n const Heading = `h${headingLevel}` as `h${2 | 3 | 4 | 5 | 6}`\n\n return (\n <nav\n ref={ref}\n data-slot='step-nav'\n aria-label={ariaLabel}\n className={cn('max-lg:text-base lg:text-sm', className)}\n {...props}\n >\n <ol role='list' className='space-y-9'>\n {sections.map((section) => (\n <li key={section.title} data-slot='step-nav-section'>\n <Heading data-slot='step-nav-heading' className='font-medium text-foreground'>\n {section.title}\n </Heading>\n <StepIndicator\n className='max-lg:mt-2 lg:mt-4'\n steps={section.steps}\n currentHref={currentHref}\n onNavigate={onNavigate}\n statusLabels={statusLabels}\n />\n </li>\n ))}\n </ol>\n </nav>\n )\n}\n\nexport { StepIndicator, StepNav, stepStatusStyles }\nexport type { Step, StepIndicatorProps, StepNavProps, StepNavSection, StepStatus }\n"]}
|