@nswds/ui 4.2.0 → 4.4.0
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/dist/components/expandable-search.d.ts +119 -0
- package/dist/components/expandable-search.js +252 -0
- package/dist/components/expandable-search.js.map +1 -0
- package/dist/components/header.d.ts +147 -0
- package/dist/components/header.js +221 -0
- package/dist/components/header.js.map +1 -0
- package/dist/components/main-nav.d.ts +144 -0
- package/dist/components/main-nav.js +366 -0
- package/dist/components/main-nav.js.map +1 -0
- package/dist/components/navigation-menu.d.ts +148 -0
- package/dist/components/navigation-menu.js +205 -0
- package/dist/components/navigation-menu.js.map +1 -0
- package/dist/components/push-menu.d.ts +149 -0
- package/dist/components/push-menu.js +357 -0
- package/dist/components/push-menu.js.map +1 -0
- package/dist/components/side-nav.d.ts +116 -0
- package/dist/components/side-nav.js +180 -0
- package/dist/components/side-nav.js.map +1 -0
- package/dist/components/site-search.d.ts +115 -0
- package/dist/components/site-search.js +204 -0
- package/dist/components/site-search.js.map +1 -0
- package/dist/components/step-indicator.d.ts +160 -0
- package/dist/components/step-indicator.js +260 -0
- package/dist/components/step-indicator.js.map +1 -0
- package/dist/components/theme-switcher.d.ts +70 -0
- package/dist/components/theme-switcher.js +52 -0
- package/dist/components/theme-switcher.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/styles.css +1 -1
- package/package.json +6 -5
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import React__default from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Progress state of a single step in a multi-step journey.
|
|
5
|
+
*
|
|
6
|
+
* `'default'` is the unannotated baseline (a step with no `status` set) and
|
|
7
|
+
* renders identically to `'not-started'` — both exist because the nswds-app
|
|
8
|
+
* source distinguished them, and consumers may key behaviour off the
|
|
9
|
+
* difference even though the visual is shared.
|
|
10
|
+
*/
|
|
11
|
+
type StepStatus = 'default' | 'not-started' | 'in-progress' | 'completed' | 'saved' | 'error' | 'cannot-start';
|
|
12
|
+
/** One entry in a {@link StepIndicator} list. */
|
|
13
|
+
type Step = {
|
|
14
|
+
/** Visible step name, e.g. "Your details". */
|
|
15
|
+
title: string;
|
|
16
|
+
/** Optional second line under the title. */
|
|
17
|
+
description?: string;
|
|
18
|
+
/** Navigation target; also the identity compared against `currentHref`. */
|
|
19
|
+
href: string;
|
|
20
|
+
/** Progress state. Omitted = `'default'` (renders as not started). */
|
|
21
|
+
status?: StepStatus;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Per-status visual treatment, collapsed from the nswds-app source's seven
|
|
25
|
+
* copy-pasted JSX branches into one map. Every colour funnels through a single
|
|
26
|
+
* `--step-ink` custom property declared on the `<li>`, so the marker,
|
|
27
|
+
* connector, hover fill and focus ring all follow from one declaration per
|
|
28
|
+
* status (the same ink-token pattern as footer.tsx / link.tsx).
|
|
29
|
+
*
|
|
30
|
+
* Ink values use RAW @nswds/tokens custom properties (`--success-600`, not the
|
|
31
|
+
* `--color-success-600` Tailwind bridge alias): Tailwind v4 tree-shakes
|
|
32
|
+
* unreferenced `@theme` keys and an arbitrary-property reference is not a
|
|
33
|
+
* usage signal, but the raw tokens are plain `:root` declarations that always
|
|
34
|
+
* resolve — the same precedent as button.tsx's semantic colours.
|
|
35
|
+
*
|
|
36
|
+
* Token remapping from the nswds-app source (documented per §3 of AGENTS.md):
|
|
37
|
+
* - completed/saved: `success-450`/`-500`/`-550` → `--success-600` (dark:
|
|
38
|
+
* `--success-500`). 450 (L≈0.63) gives the white check only ≈2.4:1; 600
|
|
39
|
+
* (L≈0.55) clears the 3:1 non-text minimum (WCAG 2.2 1.4.11) and matches
|
|
40
|
+
* Button's solid success.
|
|
41
|
+
* - in-progress: `primary-500` → `--primary-600` (dark: `--primary-450`).
|
|
42
|
+
* Masterbrand primary-500 (L≈0.72) fails 3:1 against white for the marker
|
|
43
|
+
* border and icon; 600 matches Button's tertiary. The dark override
|
|
44
|
+
* lightens the ink so it clears 3:1 against dark surfaces.
|
|
45
|
+
* - error: `danger-450`/`-500` → `--danger-600` (dark: `--danger-500`),
|
|
46
|
+
* matching Button's solid danger.
|
|
47
|
+
* - not-started/default: border `grey-300` → `--grey-500` (dark:
|
|
48
|
+
* `--grey-450`). grey-300 (L≈0.90) is ≈1.2:1 against white — invisible to
|
|
49
|
+
* low-vision users; grey-500 clears 3:1 (1.4.11).
|
|
50
|
+
* - cannot-start: `grey-600` kept (white glyph on it is ≈7:1 in both modes).
|
|
51
|
+
* - marker fill `bg-white` → `bg-background` so outlined markers sit on the
|
|
52
|
+
* page surface in dark mode instead of punching white holes in it.
|
|
53
|
+
*/
|
|
54
|
+
declare const stepStatusStyles: Record<StepStatus, {
|
|
55
|
+
/** `--step-ink` declaration, applied to the `<li>` so descendants inherit. */
|
|
56
|
+
ink: string;
|
|
57
|
+
/** Connector line colour (the `aria-hidden` rule between markers). */
|
|
58
|
+
connector: string;
|
|
59
|
+
/** Structural marker treatment. */
|
|
60
|
+
marker: 'solid' | 'outline' | 'dot';
|
|
61
|
+
/** Glyph rendered inside the marker (always `aria-hidden`). */
|
|
62
|
+
icon: React__default.ElementType | null;
|
|
63
|
+
/** Default visually-hidden status announcement (see `statusLabels`). */
|
|
64
|
+
label?: string;
|
|
65
|
+
/** Steps that must not be reachable yet. */
|
|
66
|
+
disabled?: boolean;
|
|
67
|
+
}>;
|
|
68
|
+
type StepIndicatorProps = Omit<React__default.ComponentPropsWithoutRef<'ol'>, 'children'> & {
|
|
69
|
+
/** Steps to render, in journey order. `href` must be unique per step. */
|
|
70
|
+
steps: Step[];
|
|
71
|
+
/**
|
|
72
|
+
* The href of the page being viewed. The matching step gets
|
|
73
|
+
* `aria-current="step"` and — when its status carries no stronger visual
|
|
74
|
+
* (default / not-started / in-progress) — the emphasised current treatment.
|
|
75
|
+
* Replaces the source's internal next/navigation `usePathname()` coupling
|
|
76
|
+
* so the component stays framework-free.
|
|
77
|
+
*/
|
|
78
|
+
currentHref?: string;
|
|
79
|
+
/** Click handler applied to every enabled step link. */
|
|
80
|
+
onNavigate?: React__default.MouseEventHandler<HTMLAnchorElement>;
|
|
81
|
+
/**
|
|
82
|
+
* Visually-hidden status announcements appended to each title, merged over
|
|
83
|
+
* the English defaults ("Completed", "Saved", …). Set a status to
|
|
84
|
+
* `undefined` to suppress its announcement; supply strings to localise.
|
|
85
|
+
*/
|
|
86
|
+
statusLabels?: Partial<Record<StepStatus, string | undefined>>;
|
|
87
|
+
ref?: React__default.Ref<HTMLOListElement>;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Vertical list of the steps in a multi-step journey — one link per step with
|
|
91
|
+
* a status marker and connector line, as used beside long NSW Government
|
|
92
|
+
* application forms.
|
|
93
|
+
*
|
|
94
|
+
* Accessibility contract:
|
|
95
|
+
* - Renders an `<ol role="list">` — steps are a sequence, so an ordered list
|
|
96
|
+
* conveys the ordering to assistive tech (the nswds-app source used `<ul>`);
|
|
97
|
+
* the explicit `role` restores list semantics in Safari/VoiceOver where
|
|
98
|
+
* `list-style: none` removes them.
|
|
99
|
+
* - The step matching `currentHref` gets `aria-current="step"` whatever its
|
|
100
|
+
* status (the source only set it on one of its seven branches).
|
|
101
|
+
* - Markers and connectors are purely decorative (`aria-hidden`); status is
|
|
102
|
+
* announced through a visually-hidden suffix after each title instead,
|
|
103
|
+
* because colour and iconography alone would leave screen-reader users with
|
|
104
|
+
* no status at all (WCAG 2.2 1.4.1 Use of Colour). See `statusLabels`.
|
|
105
|
+
* - `cannot-start` steps are `aria-disabled`, removed from the tab order and
|
|
106
|
+
* click-inert — the source left them fully clickable, which invited
|
|
107
|
+
* navigation into pages that reject you.
|
|
108
|
+
* - Links get a `focus-visible` outline drawn in the status ink (the source
|
|
109
|
+
* relied on browser defaults), satisfying 2.4.7 Focus Visible with a 3:1
|
|
110
|
+
* indicator (2.4.13).
|
|
111
|
+
*
|
|
112
|
+
* All anchors render through `Link` (`variant="unstyled"`), so apps can inject
|
|
113
|
+
* a framework link (e.g. next/link) via `LinkProvider`.
|
|
114
|
+
*/
|
|
115
|
+
declare function StepIndicator({ steps, currentHref, onNavigate, statusLabels, className, ref, ...props }: StepIndicatorProps): React__default.JSX.Element;
|
|
116
|
+
/** A titled group of steps inside {@link StepNav}. */
|
|
117
|
+
type StepNavSection = {
|
|
118
|
+
/** Section heading, e.g. "Before you start". */
|
|
119
|
+
title: string;
|
|
120
|
+
steps: Step[];
|
|
121
|
+
};
|
|
122
|
+
type StepNavProps = Omit<React__default.ComponentPropsWithoutRef<'nav'>, 'children'> & {
|
|
123
|
+
/** Titled groups of steps, rendered as heading + StepIndicator pairs. */
|
|
124
|
+
sections: StepNavSection[];
|
|
125
|
+
/**
|
|
126
|
+
* Heading element for section titles. Defaults to 2; set it so the headings
|
|
127
|
+
* slot into the surrounding page outline (WCAG 2.2 1.3.1).
|
|
128
|
+
*/
|
|
129
|
+
headingLevel?: 2 | 3 | 4 | 5 | 6;
|
|
130
|
+
/** Forwarded to every section's {@link StepIndicator}. */
|
|
131
|
+
currentHref?: string;
|
|
132
|
+
/** Forwarded to every section's {@link StepIndicator}. */
|
|
133
|
+
onNavigate?: React__default.MouseEventHandler<HTMLAnchorElement>;
|
|
134
|
+
/** Forwarded to every section's {@link StepIndicator}. */
|
|
135
|
+
statusLabels?: Partial<Record<StepStatus, string | undefined>>;
|
|
136
|
+
ref?: React__default.Ref<HTMLElement>;
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Sectioned journey navigation: a `<nav>` landmark containing one heading +
|
|
140
|
+
* {@link StepIndicator} per section.
|
|
141
|
+
*
|
|
142
|
+
* Ported from nswds-app's `StepNavigation`, minus the app's form-store
|
|
143
|
+
* coupling — the source read each step's status out of a zustand
|
|
144
|
+
* `useFormStore` hook; the design-system version takes status as data on the
|
|
145
|
+
* `steps` themselves, so any state source (form store, server props, URL) can
|
|
146
|
+
* drive it.
|
|
147
|
+
*
|
|
148
|
+
* Accessibility contract:
|
|
149
|
+
* - The landmark is named (`aria-label="Progress"` by default, overridable)
|
|
150
|
+
* so it is distinguishable from the site's other navigation landmarks
|
|
151
|
+
* (WCAG 2.2 2.4.1 / ARIA landmark naming).
|
|
152
|
+
* - Sections are an `<ol role="list">` (they are ordered phases of one
|
|
153
|
+
* journey; the source used `<ul>`).
|
|
154
|
+
* - Section titles use a real heading element chosen via `headingLevel`
|
|
155
|
+
* (source hard-coded `<h2>`), and the source's `text-slate-900` leak is
|
|
156
|
+
* replaced with the theme-aware `text-foreground`.
|
|
157
|
+
*/
|
|
158
|
+
declare function StepNav({ sections, headingLevel, currentHref, onNavigate, statusLabels, className, 'aria-label': ariaLabel, ref, ...props }: StepNavProps): React__default.JSX.Element;
|
|
159
|
+
|
|
160
|
+
export { type Step, StepIndicator, type StepIndicatorProps, StepNav, type StepNavProps, type StepNavSection, type StepStatus, stepStatusStyles };
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
+
import { cn } from '../lib/utils.js';
|
|
4
|
+
import { Link } from '../components/link.js';
|
|
5
|
+
import { IconCheck } from '../icons/check.js';
|
|
6
|
+
import { IconError } from '../icons/error.js';
|
|
7
|
+
import { IconMoreHoriz } from '../icons/more-horiz.js';
|
|
8
|
+
import { IconRemove } from '../icons/remove.js';
|
|
9
|
+
|
|
10
|
+
const stepStatusStyles = {
|
|
11
|
+
completed: {
|
|
12
|
+
ink: "[--step-ink:var(--success-600)] dark:[--step-ink:var(--success-500)]",
|
|
13
|
+
connector: "bg-(--step-ink)",
|
|
14
|
+
marker: "solid",
|
|
15
|
+
icon: IconCheck,
|
|
16
|
+
label: "Completed"
|
|
17
|
+
},
|
|
18
|
+
saved: {
|
|
19
|
+
ink: "[--step-ink:var(--success-600)] dark:[--step-ink:var(--success-500)]",
|
|
20
|
+
connector: "bg-grey-300 dark:bg-grey-700",
|
|
21
|
+
marker: "outline",
|
|
22
|
+
icon: IconCheck,
|
|
23
|
+
label: "Saved"
|
|
24
|
+
},
|
|
25
|
+
"in-progress": {
|
|
26
|
+
ink: "[--step-ink:var(--primary-600)] dark:[--step-ink:var(--primary-450)]",
|
|
27
|
+
connector: "bg-grey-300 dark:bg-grey-700",
|
|
28
|
+
marker: "outline",
|
|
29
|
+
icon: IconMoreHoriz,
|
|
30
|
+
label: "In progress"
|
|
31
|
+
},
|
|
32
|
+
error: {
|
|
33
|
+
ink: "[--step-ink:var(--danger-600)] dark:[--step-ink:var(--danger-500)]",
|
|
34
|
+
connector: "bg-(--step-ink)",
|
|
35
|
+
marker: "solid",
|
|
36
|
+
icon: IconError,
|
|
37
|
+
label: "Error"
|
|
38
|
+
},
|
|
39
|
+
"cannot-start": {
|
|
40
|
+
ink: "[--step-ink:var(--grey-600)]",
|
|
41
|
+
connector: "bg-grey-300 dark:bg-grey-700",
|
|
42
|
+
marker: "solid",
|
|
43
|
+
icon: IconRemove,
|
|
44
|
+
label: "Cannot start yet",
|
|
45
|
+
disabled: true
|
|
46
|
+
},
|
|
47
|
+
"not-started": {
|
|
48
|
+
ink: "[--step-ink:var(--grey-500)] dark:[--step-ink:var(--grey-450)]",
|
|
49
|
+
connector: "bg-grey-300 dark:bg-grey-700",
|
|
50
|
+
marker: "dot",
|
|
51
|
+
icon: null,
|
|
52
|
+
label: "Not started"
|
|
53
|
+
},
|
|
54
|
+
default: {
|
|
55
|
+
ink: "[--step-ink:var(--grey-500)] dark:[--step-ink:var(--grey-450)]",
|
|
56
|
+
connector: "bg-grey-300 dark:bg-grey-700",
|
|
57
|
+
marker: "dot",
|
|
58
|
+
icon: null
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const markerBase = [
|
|
62
|
+
"relative z-10 flex size-6 items-center justify-center rounded-full",
|
|
63
|
+
"transition-colors motion-reduce:transition-none",
|
|
64
|
+
"[--step-ink-hover:color-mix(in_oklch,var(--step-ink)_85%,var(--black))]"
|
|
65
|
+
];
|
|
66
|
+
const markerStyles = {
|
|
67
|
+
// Solid disc, white glyph; hover deepens the fill (source: -450 → -500).
|
|
68
|
+
solid: cn(markerBase, "bg-(--step-ink) text-white group-hover:bg-(--step-ink-hover)"),
|
|
69
|
+
// Outlined disc, ink glyph; hover fills with the ink and inverts the glyph
|
|
70
|
+
// (source: saved/in-progress fill-on-hover). In dark mode the inks are
|
|
71
|
+
// light steps, so the hovered glyph flips to a dark grey instead of white.
|
|
72
|
+
outline: cn(
|
|
73
|
+
markerBase,
|
|
74
|
+
"border-2 border-(--step-ink) bg-background text-(--step-ink)",
|
|
75
|
+
"group-hover:bg-(--step-ink) group-hover:text-white dark:group-hover:text-grey-900"
|
|
76
|
+
),
|
|
77
|
+
// Outlined disc with a centre dot that appears on hover (or is always
|
|
78
|
+
// filled for the current step).
|
|
79
|
+
dot: cn(markerBase, "border-2 border-(--step-ink) bg-background")
|
|
80
|
+
};
|
|
81
|
+
const stepTextClassName = "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";
|
|
82
|
+
const currentTextClassName = "text-sm font-semibold text-primary-800 dark:text-primary-200";
|
|
83
|
+
const DEFAULT_STATUS_LABELS = Object.fromEntries(
|
|
84
|
+
Object.entries(stepStatusStyles).flatMap(
|
|
85
|
+
([status, style]) => style.label ? [[status, style.label]] : []
|
|
86
|
+
)
|
|
87
|
+
);
|
|
88
|
+
function StepIndicator({
|
|
89
|
+
steps,
|
|
90
|
+
currentHref,
|
|
91
|
+
onNavigate,
|
|
92
|
+
statusLabels,
|
|
93
|
+
className,
|
|
94
|
+
ref,
|
|
95
|
+
...props
|
|
96
|
+
}) {
|
|
97
|
+
if (process.env.NODE_ENV !== "production") {
|
|
98
|
+
const seen = /* @__PURE__ */ new Set();
|
|
99
|
+
for (const step of steps) {
|
|
100
|
+
if (seen.has(step.href)) {
|
|
101
|
+
console.warn(
|
|
102
|
+
`[nswds/ui] StepIndicator: duplicate step href "${step.href}" \u2014 hrefs are used as React keys and for currentHref matching, so duplicates will misrender.`
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
seen.add(step.href);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const labels = { ...DEFAULT_STATUS_LABELS, ...statusLabels };
|
|
109
|
+
return /* @__PURE__ */ jsx(
|
|
110
|
+
"ol",
|
|
111
|
+
{
|
|
112
|
+
role: "list",
|
|
113
|
+
ref,
|
|
114
|
+
"data-slot": "step-indicator",
|
|
115
|
+
className: cn("w-full", className),
|
|
116
|
+
...props,
|
|
117
|
+
children: steps.map((step, stepIdx) => {
|
|
118
|
+
const status = step.status ?? "default";
|
|
119
|
+
const style = stepStatusStyles[status];
|
|
120
|
+
const isCurrent = currentHref !== void 0 && step.href === currentHref;
|
|
121
|
+
const currentVariant = !isCurrent ? null : status === "in-progress" ? "ring" : status === "default" || status === "not-started" ? "dot" : null;
|
|
122
|
+
const isLast = stepIdx === steps.length - 1;
|
|
123
|
+
const StatusIcon = style.icon;
|
|
124
|
+
const label = labels[status];
|
|
125
|
+
return /* @__PURE__ */ jsxs(
|
|
126
|
+
"li",
|
|
127
|
+
{
|
|
128
|
+
"data-slot": "step",
|
|
129
|
+
"data-status": status,
|
|
130
|
+
"data-current": isCurrent || void 0,
|
|
131
|
+
className: cn(
|
|
132
|
+
"relative",
|
|
133
|
+
!isLast && "pb-3",
|
|
134
|
+
style.ink,
|
|
135
|
+
// A current default/not-started step promotes its ink to the
|
|
136
|
+
// in-progress primary so the filled dot and ring read as "you
|
|
137
|
+
// are here", not "not started".
|
|
138
|
+
currentVariant === "dot" && stepStatusStyles["in-progress"].ink
|
|
139
|
+
),
|
|
140
|
+
children: [
|
|
141
|
+
!isLast && /* @__PURE__ */ jsx(
|
|
142
|
+
"div",
|
|
143
|
+
{
|
|
144
|
+
"aria-hidden": "true",
|
|
145
|
+
"data-slot": "step-connector",
|
|
146
|
+
className: cn("absolute top-4 left-3 mt-0.5 -ml-px h-full w-0.5", style.connector)
|
|
147
|
+
}
|
|
148
|
+
),
|
|
149
|
+
/* @__PURE__ */ jsxs(
|
|
150
|
+
Link,
|
|
151
|
+
{
|
|
152
|
+
variant: "unstyled",
|
|
153
|
+
href: step.href,
|
|
154
|
+
"data-slot": "step-link",
|
|
155
|
+
"aria-current": isCurrent ? "step" : void 0,
|
|
156
|
+
className: cn(
|
|
157
|
+
"group relative flex items-center rounded-sm",
|
|
158
|
+
"focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--step-ink)",
|
|
159
|
+
style.disabled && "pointer-events-none"
|
|
160
|
+
),
|
|
161
|
+
onClick: style.disabled ? (event) => event.preventDefault() : onNavigate,
|
|
162
|
+
...style.disabled ? { "aria-disabled": true, tabIndex: -1 } : {},
|
|
163
|
+
children: [
|
|
164
|
+
currentVariant === "ring" ? (
|
|
165
|
+
// Double ring: the source's emphasised in-progress-current
|
|
166
|
+
// marker. The outer 32px ring centres on the 24px grid via
|
|
167
|
+
// -ml-1, so the connector still meets the marker's middle.
|
|
168
|
+
/* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "-ml-1 flex h-9 items-center", children: /* @__PURE__ */ jsx("span", { "data-slot": "step-marker", className: cn(markerStyles.dot, "size-8"), children: /* @__PURE__ */ jsx("span", { className: "flex size-6 items-center justify-center rounded-full border-2 border-(--step-ink) bg-background", children: /* @__PURE__ */ jsx(IconMoreHoriz, { className: "size-4 text-(--step-ink)", "aria-hidden": "true" }) }) }) })
|
|
169
|
+
) : /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "flex h-9 items-center", children: /* @__PURE__ */ jsx("span", { "data-slot": "step-marker", className: markerStyles[style.marker], children: style.marker === "dot" ? /* @__PURE__ */ jsx(
|
|
170
|
+
"span",
|
|
171
|
+
{
|
|
172
|
+
className: cn(
|
|
173
|
+
"size-2 rounded-full transition-colors motion-reduce:transition-none",
|
|
174
|
+
currentVariant === "dot" ? "bg-(--step-ink)" : "bg-transparent group-hover:bg-(--step-ink)"
|
|
175
|
+
)
|
|
176
|
+
}
|
|
177
|
+
) : StatusIcon && /* @__PURE__ */ jsx(StatusIcon, { className: "size-4", "aria-hidden": "true" }) }) }),
|
|
178
|
+
/* @__PURE__ */ jsxs(
|
|
179
|
+
"span",
|
|
180
|
+
{
|
|
181
|
+
"data-slot": "step-content",
|
|
182
|
+
className: cn("flex min-w-0 flex-col", currentVariant === "ring" ? "ml-3" : "ml-4"),
|
|
183
|
+
children: [
|
|
184
|
+
/* @__PURE__ */ jsxs(
|
|
185
|
+
"span",
|
|
186
|
+
{
|
|
187
|
+
"data-slot": "step-title",
|
|
188
|
+
className: currentVariant ? currentTextClassName : stepTextClassName,
|
|
189
|
+
children: [
|
|
190
|
+
step.title,
|
|
191
|
+
label && /* @__PURE__ */ jsxs("span", { className: "sr-only", children: [
|
|
192
|
+
" (",
|
|
193
|
+
label,
|
|
194
|
+
")"
|
|
195
|
+
] })
|
|
196
|
+
]
|
|
197
|
+
}
|
|
198
|
+
),
|
|
199
|
+
step.description && /* @__PURE__ */ jsx(
|
|
200
|
+
"span",
|
|
201
|
+
{
|
|
202
|
+
"data-slot": "step-description",
|
|
203
|
+
className: currentVariant ? currentTextClassName : stepTextClassName,
|
|
204
|
+
children: step.description
|
|
205
|
+
}
|
|
206
|
+
)
|
|
207
|
+
]
|
|
208
|
+
}
|
|
209
|
+
)
|
|
210
|
+
]
|
|
211
|
+
}
|
|
212
|
+
)
|
|
213
|
+
]
|
|
214
|
+
},
|
|
215
|
+
step.href
|
|
216
|
+
);
|
|
217
|
+
})
|
|
218
|
+
}
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
function StepNav({
|
|
222
|
+
sections,
|
|
223
|
+
headingLevel = 2,
|
|
224
|
+
currentHref,
|
|
225
|
+
onNavigate,
|
|
226
|
+
statusLabels,
|
|
227
|
+
className,
|
|
228
|
+
"aria-label": ariaLabel = "Progress",
|
|
229
|
+
ref,
|
|
230
|
+
...props
|
|
231
|
+
}) {
|
|
232
|
+
const Heading = `h${headingLevel}`;
|
|
233
|
+
return /* @__PURE__ */ jsx(
|
|
234
|
+
"nav",
|
|
235
|
+
{
|
|
236
|
+
ref,
|
|
237
|
+
"data-slot": "step-nav",
|
|
238
|
+
"aria-label": ariaLabel,
|
|
239
|
+
className: cn("text-base lg:text-sm", className),
|
|
240
|
+
...props,
|
|
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
|
+
/* @__PURE__ */ jsx(Heading, { "data-slot": "step-nav-heading", className: "font-medium text-foreground", children: section.title }),
|
|
243
|
+
/* @__PURE__ */ jsx(
|
|
244
|
+
StepIndicator,
|
|
245
|
+
{
|
|
246
|
+
className: "mt-2 lg:mt-4",
|
|
247
|
+
steps: section.steps,
|
|
248
|
+
currentHref,
|
|
249
|
+
onNavigate,
|
|
250
|
+
statusLabels
|
|
251
|
+
}
|
|
252
|
+
)
|
|
253
|
+
] }, section.title)) })
|
|
254
|
+
}
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export { StepIndicator, StepNav, stepStatusStyles };
|
|
259
|
+
//# sourceMappingURL=step-indicator.js.map
|
|
260
|
+
//# sourceMappingURL=step-indicator.js.map
|
|
@@ -0,0 +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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AAAA,EACf,WAAA;AAAA,EACA,UAAA;AAAA,EACA,YAAA;AAAA,EACA,SAAA;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,sBAAA,EAAwB,SAAS,CAAA;AAAA,MAC9C,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,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"]}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import React__default from 'react';
|
|
2
|
+
import { ButtonProps } from './button.js';
|
|
3
|
+
import 'class-variance-authority/types';
|
|
4
|
+
import '@base-ui/react/button';
|
|
5
|
+
import 'class-variance-authority';
|
|
6
|
+
import './link.js';
|
|
7
|
+
|
|
8
|
+
/** The two colour schemes the switcher toggles between. */
|
|
9
|
+
type ThemeSwitcherTheme = 'light' | 'dark';
|
|
10
|
+
type ThemeSwitcherProps = Omit<ButtonProps, 'children'> & {
|
|
11
|
+
/**
|
|
12
|
+
* Current theme (controlled). When set, the component never updates its own
|
|
13
|
+
* state — wire `onThemeChange` back into whatever owns the theme (see the
|
|
14
|
+
* next-themes snippet on the Storybook docs page). Pick one mode per
|
|
15
|
+
* instance: don't switch between supplying and omitting `theme` across
|
|
16
|
+
* renders.
|
|
17
|
+
*/
|
|
18
|
+
theme?: ThemeSwitcherTheme;
|
|
19
|
+
/** Initial theme when uncontrolled. Defaults to `'light'`. */
|
|
20
|
+
defaultTheme?: ThemeSwitcherTheme;
|
|
21
|
+
/**
|
|
22
|
+
* Called with the NEXT theme (the one the user asked for) on every
|
|
23
|
+
* activation, in both controlled and uncontrolled modes.
|
|
24
|
+
*/
|
|
25
|
+
onThemeChange?: (theme: ThemeSwitcherTheme) => void;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Light/dark theme toggle button, ported from nswds-app's `ThemeSwitcher`
|
|
29
|
+
* minus its `next-themes` dependency — a design system cannot depend on a
|
|
30
|
+
* theming framework, so this is a plain controlled/uncontrolled input
|
|
31
|
+
* (`theme` / `defaultTheme` / `onThemeChange`) and the app owns the plumbing.
|
|
32
|
+
* All other props pass through to `Button` (defaults: `variant='surface'`,
|
|
33
|
+
* `color='grey'`, `size='icon'` — the source's `color='light'` does not exist
|
|
34
|
+
* on this Button; `grey` is its nearest ink).
|
|
35
|
+
*
|
|
36
|
+
* The icon depicts the DESTINATION: a moon (`IconDarkMode`) while the theme is
|
|
37
|
+
* light, a sun (`IconLightMode`) while it is dark — matching the source and
|
|
38
|
+
* the action-phrased label below.
|
|
39
|
+
*
|
|
40
|
+
* Accessibility contract:
|
|
41
|
+
* - The `aria-label` announces the ACTION ("Switch to dark theme"), not the
|
|
42
|
+
* state, and flips after each activation so the control always names what
|
|
43
|
+
* pressing it will do (WCAG 2.2, 4.1.2 Name, Role, Value). The source
|
|
44
|
+
* duplicated the same words in an `sr-only` span AND the `aria-label`; the
|
|
45
|
+
* span is dropped here because a control with both gets its name announced
|
|
46
|
+
* twice by common screen readers (label, then descendant text).
|
|
47
|
+
* - No `aria-pressed`. This is a mode switch between two peer states, each
|
|
48
|
+
* with its own action label — not a pressed/unpressed toggle of a single
|
|
49
|
+
* action. Combining `aria-pressed` with a flipping label is actively
|
|
50
|
+
* confusing ("Switch to dark theme, pressed" — pressed relative to what?);
|
|
51
|
+
* the flipping label alone is the established pattern for theme switchers.
|
|
52
|
+
* - The icon is decorative (`aria-hidden`) and painted with `fill-current` so
|
|
53
|
+
* it follows the Button ink in every variant/colour and in dark mode — the
|
|
54
|
+
* source hardcoded `fill-grey-600 dark:fill-grey-100`, which broke on any
|
|
55
|
+
* non-grey button surface.
|
|
56
|
+
*
|
|
57
|
+
* Departures from the nswds-app source, beyond those above:
|
|
58
|
+
* - No mounted-gate/hydration dance. The source rendered a disabled
|
|
59
|
+
* placeholder until after mount because next-themes' `resolvedTheme` is
|
|
60
|
+
* undefined during SSR. That is the theme framework's concern, not this
|
|
61
|
+
* component's: an SSR app passes `theme={resolvedTheme}` and gates its own
|
|
62
|
+
* render (or accepts the swap) itself. Wiring snippet on the docs page.
|
|
63
|
+
* - The app's `ThemeProvider` (a next-themes re-export) intentionally has no
|
|
64
|
+
* design-system equivalent: theme plumbing is an app concern. Storybook
|
|
65
|
+
* toggles the `.dark` class via addon-themes, so clicking this component in
|
|
66
|
+
* a story does not restyle the canvas.
|
|
67
|
+
*/
|
|
68
|
+
declare function ThemeSwitcher({ theme: themeProp, defaultTheme, onThemeChange, variant, color, size, onClick, 'aria-label': ariaLabel, ...props }: ThemeSwitcherProps): React__default.JSX.Element;
|
|
69
|
+
|
|
70
|
+
export { ThemeSwitcher, type ThemeSwitcherProps, type ThemeSwitcherTheme };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { IconDarkMode } from '../icons/dark-mode.js';
|
|
5
|
+
import { IconLightMode } from '../icons/light-mode.js';
|
|
6
|
+
import { Button } from '../components/button.js';
|
|
7
|
+
|
|
8
|
+
function ThemeSwitcher({
|
|
9
|
+
theme: themeProp,
|
|
10
|
+
defaultTheme = "light",
|
|
11
|
+
onThemeChange,
|
|
12
|
+
variant = "surface",
|
|
13
|
+
color = "grey",
|
|
14
|
+
size = "icon",
|
|
15
|
+
onClick,
|
|
16
|
+
"aria-label": ariaLabel,
|
|
17
|
+
...props
|
|
18
|
+
}) {
|
|
19
|
+
const [uncontrolledTheme, setUncontrolledTheme] = React.useState(defaultTheme);
|
|
20
|
+
const isControlled = themeProp !== void 0;
|
|
21
|
+
const theme = isControlled ? themeProp : uncontrolledTheme;
|
|
22
|
+
const nextTheme = theme === "dark" ? "light" : "dark";
|
|
23
|
+
const Icon = theme === "dark" ? IconLightMode : IconDarkMode;
|
|
24
|
+
const handleClick = (event) => {
|
|
25
|
+
onClick?.(event);
|
|
26
|
+
if (event.defaultPrevented) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (!isControlled) {
|
|
30
|
+
setUncontrolledTheme(nextTheme);
|
|
31
|
+
}
|
|
32
|
+
onThemeChange?.(nextTheme);
|
|
33
|
+
};
|
|
34
|
+
return /* @__PURE__ */ jsx(
|
|
35
|
+
Button,
|
|
36
|
+
{
|
|
37
|
+
"data-slot": "theme-switcher",
|
|
38
|
+
"data-mode": theme,
|
|
39
|
+
variant,
|
|
40
|
+
color,
|
|
41
|
+
size,
|
|
42
|
+
"aria-label": ariaLabel ?? `Switch to ${nextTheme} theme`,
|
|
43
|
+
...props,
|
|
44
|
+
onClick: handleClick,
|
|
45
|
+
children: /* @__PURE__ */ jsx(Icon, { "aria-hidden": "true", className: "fill-current" })
|
|
46
|
+
}
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { ThemeSwitcher };
|
|
51
|
+
//# sourceMappingURL=theme-switcher.js.map
|
|
52
|
+
//# sourceMappingURL=theme-switcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/theme-switcher.tsx"],"names":[],"mappings":";;;;;;AAuEA,SAAS,aAAA,CAAc;AAAA,EACrB,KAAA,EAAO,SAAA;AAAA,EACP,YAAA,GAAe,OAAA;AAAA,EACf,aAAA;AAAA,EACA,OAAA,GAAU,SAAA;AAAA,EACV,KAAA,GAAQ,MAAA;AAAA,EACR,IAAA,GAAO,MAAA;AAAA,EACP,OAAA;AAAA,EACA,YAAA,EAAc,SAAA;AAAA,EACd,GAAG;AACL,CAAA,EAAuB;AACrB,EAAA,MAAM,CAAC,iBAAA,EAAmB,oBAAoB,CAAA,GAAI,KAAA,CAAM,SAA6B,YAAY,CAAA;AACjG,EAAA,MAAM,eAAe,SAAA,KAAc,MAAA;AACnC,EAAA,MAAM,KAAA,GAAQ,eAAe,SAAA,GAAY,iBAAA;AACzC,EAAA,MAAM,SAAA,GAAgC,KAAA,KAAU,MAAA,GAAS,OAAA,GAAU,MAAA;AAEnE,EAAA,MAAM,IAAA,GAAO,KAAA,KAAU,MAAA,GAAS,aAAA,GAAgB,YAAA;AAIhD,EAAA,MAAM,WAAA,GAAsC,CAAC,KAAA,KAAU;AACrD,IAAA,OAAA,GAAU,KAAK,CAAA;AAGf,IAAA,IAAI,MAAM,gBAAA,EAAkB;AAC1B,MAAA;AAAA,IACF;AACA,IAAA,IAAI,CAAC,YAAA,EAAc;AACjB,MAAA,oBAAA,CAAqB,SAAS,CAAA;AAAA,IAChC;AACA,IAAA,aAAA,GAAgB,SAAS,CAAA;AAAA,EAC3B,CAAA;AAEA,EAAA,uBACE,GAAA;AAAA,IAAC,MAAA;AAAA,IAAA;AAAA,MACC,WAAA,EAAU,gBAAA;AAAA,MAMV,WAAA,EAAW,KAAA;AAAA,MACX,OAAA;AAAA,MACA,KAAA;AAAA,MACA,IAAA;AAAA,MACA,YAAA,EAAY,SAAA,IAAa,CAAA,UAAA,EAAa,SAAS,CAAA,MAAA,CAAA;AAAA,MAC9C,GAAG,KAAA;AAAA,MACJ,OAAA,EAAS,WAAA;AAAA,MAIT,QAAA,kBAAA,GAAA,CAAC,IAAA,EAAA,EAAK,aAAA,EAAY,MAAA,EAAO,WAAU,cAAA,EAAe;AAAA;AAAA,GACpD;AAEJ","file":"theme-switcher.js","sourcesContent":["'use client'\n\nimport React from 'react'\n\nimport { IconDarkMode } from '../icons/dark-mode.js'\nimport { IconLightMode } from '../icons/light-mode.js'\n\nimport { Button, type ButtonProps } from '../components/button.js'\n\n/** The two colour schemes the switcher toggles between. */\ntype ThemeSwitcherTheme = 'light' | 'dark'\n\ntype ThemeSwitcherProps = Omit<ButtonProps, 'children'> & {\n /**\n * Current theme (controlled). When set, the component never updates its own\n * state — wire `onThemeChange` back into whatever owns the theme (see the\n * next-themes snippet on the Storybook docs page). Pick one mode per\n * instance: don't switch between supplying and omitting `theme` across\n * renders.\n */\n theme?: ThemeSwitcherTheme\n /** Initial theme when uncontrolled. Defaults to `'light'`. */\n defaultTheme?: ThemeSwitcherTheme\n /**\n * Called with the NEXT theme (the one the user asked for) on every\n * activation, in both controlled and uncontrolled modes.\n */\n onThemeChange?: (theme: ThemeSwitcherTheme) => void\n}\n\n/**\n * Light/dark theme toggle button, ported from nswds-app's `ThemeSwitcher`\n * minus its `next-themes` dependency — a design system cannot depend on a\n * theming framework, so this is a plain controlled/uncontrolled input\n * (`theme` / `defaultTheme` / `onThemeChange`) and the app owns the plumbing.\n * All other props pass through to `Button` (defaults: `variant='surface'`,\n * `color='grey'`, `size='icon'` — the source's `color='light'` does not exist\n * on this Button; `grey` is its nearest ink).\n *\n * The icon depicts the DESTINATION: a moon (`IconDarkMode`) while the theme is\n * light, a sun (`IconLightMode`) while it is dark — matching the source and\n * the action-phrased label below.\n *\n * Accessibility contract:\n * - The `aria-label` announces the ACTION (\"Switch to dark theme\"), not the\n * state, and flips after each activation so the control always names what\n * pressing it will do (WCAG 2.2, 4.1.2 Name, Role, Value). The source\n * duplicated the same words in an `sr-only` span AND the `aria-label`; the\n * span is dropped here because a control with both gets its name announced\n * twice by common screen readers (label, then descendant text).\n * - No `aria-pressed`. This is a mode switch between two peer states, each\n * with its own action label — not a pressed/unpressed toggle of a single\n * action. Combining `aria-pressed` with a flipping label is actively\n * confusing (\"Switch to dark theme, pressed\" — pressed relative to what?);\n * the flipping label alone is the established pattern for theme switchers.\n * - The icon is decorative (`aria-hidden`) and painted with `fill-current` so\n * it follows the Button ink in every variant/colour and in dark mode — the\n * source hardcoded `fill-grey-600 dark:fill-grey-100`, which broke on any\n * non-grey button surface.\n *\n * Departures from the nswds-app source, beyond those above:\n * - No mounted-gate/hydration dance. The source rendered a disabled\n * placeholder until after mount because next-themes' `resolvedTheme` is\n * undefined during SSR. That is the theme framework's concern, not this\n * component's: an SSR app passes `theme={resolvedTheme}` and gates its own\n * render (or accepts the swap) itself. Wiring snippet on the docs page.\n * - The app's `ThemeProvider` (a next-themes re-export) intentionally has no\n * design-system equivalent: theme plumbing is an app concern. Storybook\n * toggles the `.dark` class via addon-themes, so clicking this component in\n * a story does not restyle the canvas.\n */\nfunction ThemeSwitcher({\n theme: themeProp,\n defaultTheme = 'light',\n onThemeChange,\n variant = 'surface',\n color = 'grey',\n size = 'icon',\n onClick,\n 'aria-label': ariaLabel,\n ...props\n}: ThemeSwitcherProps) {\n const [uncontrolledTheme, setUncontrolledTheme] = React.useState<ThemeSwitcherTheme>(defaultTheme)\n const isControlled = themeProp !== undefined\n const theme = isControlled ? themeProp : uncontrolledTheme\n const nextTheme: ThemeSwitcherTheme = theme === 'dark' ? 'light' : 'dark'\n // While light, show the moon (the action is \"go dark\"), and vice versa.\n const Icon = theme === 'dark' ? IconLightMode : IconDarkMode\n\n // Typed from the prop: Base UI augments the native event with its\n // BaseUIEvent extras, so a hand-written React.MouseEvent would not assign.\n const handleClick: ButtonProps['onClick'] = (event) => {\n onClick?.(event)\n // A consumer handler that prevented default has vetoed the switch —\n // same chaining contract as ExpandableSearch's onSubmit.\n if (event.defaultPrevented) {\n return\n }\n if (!isControlled) {\n setUncontrolledTheme(nextTheme)\n }\n onThemeChange?.(nextTheme)\n }\n\n return (\n <Button\n data-slot='theme-switcher'\n // Value-carrying, like Header's data-color: styling/tests can key off\n // the CURRENT theme without parsing the action-phrased label. NOT named\n // data-theme — @nswds/tokens scopes its dark role tokens to the\n // unqualified selector [data-theme='dark'], so that attribute on the\n // button would flip semantic tokens for its own subtree.\n data-mode={theme}\n variant={variant}\n color={color}\n size={size}\n aria-label={ariaLabel ?? `Switch to ${nextTheme} theme`}\n {...props}\n onClick={handleClick}\n >\n {/* Generated icons bake in data-slot='icon', which Button's icon sizing\n selector keys off; fill-current keeps the glyph on the Button ink. */}\n <Icon aria-hidden='true' className='fill-current' />\n </Button>\n )\n}\n\nexport { ThemeSwitcher }\nexport type { ThemeSwitcherProps, ThemeSwitcherTheme }\n"]}
|