@nswds/ui 4.7.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 +1 -1
- 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.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.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/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;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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,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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A,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"]}
|