@nswds/ui 8.1.0 → 8.2.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.
@@ -0,0 +1,30 @@
1
+ /*
2
+ * Single-build entry — for consumers who run their OWN Tailwind build.
3
+ *
4
+ * Importing this one file gives a consumer the full NSW token foundation, the
5
+ * component styles, and Tailwind itself, all compiled in THEIR build: one sort
6
+ * order, each utility emitted once, and their `lg:` means the same 1200px ours
7
+ * does. This is the recommended path when the consumer already runs Tailwind.
8
+ *
9
+ * Do NOT also `@import 'tailwindcss'` — this entry brings it (via theme.css).
10
+ * Doing both re-introduces the two-independently-sorted-builds cascade hazard
11
+ * this entry exists to avoid.
12
+ *
13
+ * Requires the optional peer deps to be installed alongside @nswds/ui:
14
+ * npm i -D tailwindcss @nswds/tokens tw-animate-css
15
+ *
16
+ * Consumers without a Tailwind build should import the precompiled
17
+ * `@nswds/ui/styles.css` instead. See packages/ui/README.md,
18
+ * "Using it with your own Tailwind build".
19
+ */
20
+ @import './theme.css';
21
+
22
+ /* Scan the shipped components for the utility classes they use. `@source` is
23
+ relative to this file (src/styles/), so ../../dist resolves to <pkg>/dist —
24
+ i.e. node_modules/@nswds/ui/dist in the consumer's install. Node_modules is
25
+ ignored by Tailwind's automatic detection, so this explicit source is what
26
+ makes the library's own utilities compile in the consumer's build. Point it
27
+ at the whole dist directory, not a `*.js` glob, so a change to the build's
28
+ output extension (e.g. .mjs/.cjs) can't silently drop a component's
29
+ utilities. */
30
+ @source '../../dist';
@@ -0,0 +1,239 @@
1
+ @import 'tailwindcss';
2
+ @import 'tw-animate-css';
3
+ /* Owned copy of shadcn's custom-variant + @utility layer (was `shadcn/tailwind.css`).
4
+ Vendored so a consumer compiling this theme in their own build doesn't need the
5
+ shadcn CLI installed. See nswds-shadcn.css for provenance. */
6
+ @import './nswds-shadcn.css';
7
+
8
+ /* ── Tailwind utility bridges + bundled token values ──
9
+ preset.css wires every non-theme token category into Tailwind @theme — colours
10
+ (global + semantic), radius, space, typography, motion, shadow, border, z-index —
11
+ and also bundles the raw colour values as HEX. Its @theme colour bridges reference
12
+ the raw custom properties (e.g. --color-danger-600: var(--danger-600)). */
13
+ @import '@nswds/tokens/tailwind/preset.css';
14
+
15
+ /* ── Raw NSW colour VALUES (oklch) ──
16
+ Re-asserted AFTER preset so the palette stays oklch (the project standard) instead
17
+ of preset's bundled hex; preset's bridges then resolve to these oklch values. */
18
+ /* Primitive palette + status ramps: --nsw-blue-800, --danger-600, --success-500, … */
19
+ @import '@nswds/tokens/css/colors/global/oklch.css';
20
+ /* Semantic role tokens (LIGHT): --danger-solid/-surface/-text/-border, --background-*,
21
+ --surface-*, --text-*, --border-*, --action-*. */
22
+ @import '@nswds/tokens/css/colors/semantic/oklch.css';
23
+ /* Semantic role tokens (DARK): same names, dark values, scoped `[data-theme=dark], .dark`
24
+ (the .dark scope was added in @nswds/tokens 4.1.0). This makes the role tokens below
25
+ flip automatically under our `.dark` class — no hand-maintained dark overrides needed.
26
+
27
+ ORDER IS LOAD-BEARING, and not only inside this file. `[data-theme=dark], .dark` is
28
+ specificity (0,1,0) — identical to the `:root` of the light import above — so dark
29
+ wins here purely by coming second. The same tie is why a CONSUMER must import
30
+ `@nswds/ui/styles.css` AFTER any `@nswds/tokens/tailwind/colors/semantic/*` bridge:
31
+ that bridge bundles its own unlayered `:root` of LIGHT values and ships no dark
32
+ counterpart, so imported later it lands last and dark mode silently no-ops. The
33
+ README documents the required order; the durable fix is upstream, raising the dark
34
+ block's specificity in @nswds/tokens so no bare `:root` can undercut it. */
35
+ @import '@nswds/tokens/css/colors/semantic/oklch.dark.css';
36
+ /* Masterbrand theme: --primary-* → --nsw-blue-*, --accent-* → --nsw-red-* (preset excludes themes) */
37
+ @import '@nswds/tokens/css/colors/themes/masterbrand/oklch.css';
38
+ /* Masterbrand theme utilities: fill-primary-800, text-accent-600, … */
39
+ @import '@nswds/tokens/tailwind/colors/themes/masterbrand/oklch.css';
40
+ /* Raw motion VALUES on :root (--duration-*, --easing-*, --transition-*, + its
41
+ prefers-reduced-motion overrides). preset only exposes these via @theme, which
42
+ Tailwind tree-shakes when no utility references them — so the motion bridge below
43
+ (var(--easing-standard)) needs the raw layer to resolve. */
44
+ @import '@nswds/tokens/css/motion/global.css';
45
+ /* Raw typography VALUES on :root (--font-size-*, --font-weight-*, --line-height-*),
46
+ so the type-scale bridge below resolves even though Tailwind tree-shakes the
47
+ unreferenced @theme keys. */
48
+ @import '@nswds/tokens/css/typography/global.css';
49
+
50
+ /* `dark:` utility variant. Two things it must line up with:
51
+ 1. The element carrying the marker, not just its descendants. `.dark *` alone
52
+ never matches the element the class sits on — which is normally <html>,
53
+ exactly where next-themes and Storybook's toolbar put it — so `dark:` on
54
+ the root element silently did nothing. `.dark, .dark *` covers both.
55
+ 2. The selectors the token values actually flip on. The semantic dark import
56
+ above is scoped `[data-theme='dark'], .dark`, so a consumer toggling the
57
+ attribute form (next-themes' `attribute="data-theme"`) got mode-aware role
58
+ tokens but dead `dark:` utilities. Matching both keeps the two in step.
59
+ Specificity is unchanged at (0,2,0): `:is()` takes its most specific argument,
60
+ and every argument here is a single class or attribute. */
61
+ @custom-variant dark (&:is(.dark, .dark *, [data-theme='dark'], [data-theme='dark'] *));
62
+
63
+ @theme inline {
64
+ --font-heading: var(--font-sans);
65
+ --color-sidebar-ring: var(--sidebar-ring);
66
+ --color-sidebar-border: var(--sidebar-border);
67
+ --color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
68
+ --color-sidebar-accent: var(--sidebar-accent);
69
+ --color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
70
+ --color-sidebar-primary: var(--sidebar-primary);
71
+ --color-sidebar-foreground: var(--sidebar-foreground);
72
+ --color-sidebar: var(--sidebar);
73
+ --color-chart-5: var(--chart-5);
74
+ --color-chart-4: var(--chart-4);
75
+ --color-chart-3: var(--chart-3);
76
+ --color-chart-2: var(--chart-2);
77
+ --color-chart-1: var(--chart-1);
78
+ --color-ring: var(--ring);
79
+ --color-input: var(--input);
80
+ --color-border: var(--border);
81
+ --color-destructive: var(--destructive);
82
+ --color-accent-foreground: var(--accent-foreground);
83
+ --color-accent: var(--accent);
84
+ --color-muted-foreground: var(--muted-foreground);
85
+ --color-muted: var(--muted);
86
+ --color-secondary-foreground: var(--secondary-foreground);
87
+ --color-secondary: var(--secondary);
88
+ --color-primary-foreground: var(--primary-foreground);
89
+ --color-primary: var(--primary);
90
+ --color-popover-foreground: var(--popover-foreground);
91
+ --color-popover: var(--popover);
92
+ --color-card-foreground: var(--card-foreground);
93
+ --color-card: var(--card);
94
+ --color-foreground: var(--foreground);
95
+ --color-background: var(--background);
96
+ /* Radius scale comes from @nswds/tokens v4 via preset.css:
97
+ --radius-none/sm(4px)/md(8px)/lg(16px)/pill. No longer hand-derived here. */
98
+ --font-sans: var(--font-sans);
99
+ --font-mono: var(--font-mono);
100
+ }
101
+
102
+ /* Motion: route Tailwind's default transition timing through the v4 motion tokens.
103
+ Values equal Tailwind's defaults (--duration-fast = 150ms,
104
+ --easing-standard = cubic-bezier(0.4,0,0.2,1)), so nothing changes visually — but
105
+ every `transition-*` utility now follows @nswds/tokens (incl. its prefers-reduced-motion
106
+ overrides) instead of Tailwind's hardcoded defaults. */
107
+ @theme {
108
+ --default-transition-duration: var(--duration-fast);
109
+ --default-transition-timing-function: var(--easing-standard);
110
+ }
111
+
112
+ /* Type scale: route Tailwind's font-size keys through the v4 type tokens. Values are
113
+ identical to Tailwind's defaults (--font-size-14 = 0.875rem = text-sm, etc.), so this
114
+ is visually neutral — it just makes the scale follow @nswds/tokens. Line-heights stay
115
+ on Tailwind/explicit utilities; font-weights already come from v4 via preset.css. */
116
+ @theme {
117
+ --text-xs: var(--font-size-12);
118
+ --text-sm: var(--font-size-14);
119
+ --text-base: var(--font-size-16);
120
+ --text-lg: var(--font-size-18);
121
+ --text-xl: var(--font-size-20);
122
+ --text-2xl: var(--font-size-24);
123
+ --text-3xl: var(--font-size-30);
124
+ }
125
+
126
+ :root {
127
+ /* shadcn semantic tokens mapped onto @nswds/tokens v4 role tokens. Role tokens are
128
+ mode-aware (light from the semantic LIGHT import; dark from the .dark-scoped DARK
129
+ import above), so these flip automatically under `.dark` — there is no longer a
130
+ hand-maintained `.dark` override block. */
131
+ /* Page canvas uses --surface-default (pure white in light) rather than v4's off-white
132
+ --background-default: components' soft/text colours are tuned for a white canvas and
133
+ the off-white tips some below WCAG AA 4.5:1. Still mode-aware (dark = role dark value). */
134
+ --background: var(--surface-default);
135
+ --foreground: var(--text-default);
136
+ --card: var(--surface-raised);
137
+ --card-foreground: var(--text-default);
138
+ --popover: var(--surface-raised);
139
+ --popover-foreground: var(--text-default);
140
+ /* Brand primary uses the v4 action role: light = --primary-800; dark = an accessible
141
+ lighter blue. Foreground inverts with it (white on dark blue / dark on light blue). */
142
+ --primary: var(--action-default);
143
+ --primary-foreground: var(--text-inverse);
144
+ --secondary: var(--surface-sunken);
145
+ --secondary-foreground: var(--text-default);
146
+ --muted: var(--background-subtle);
147
+ --muted-foreground: var(--text-muted);
148
+ --accent: var(--background-subtle);
149
+ --accent-foreground: var(--text-default);
150
+ --destructive: var(--danger-solid);
151
+ --border: var(--border-default);
152
+ --input: var(--border-default);
153
+ --ring: var(--border-strong);
154
+ /* Form input tokens — Input references ONLY these; the role tokens make them mode-aware. */
155
+ --input-border: var(--border-strong);
156
+ --input-foreground: var(--text-default);
157
+ /* `--text-muted`, not `--text-subtle`: text-subtle (#888f92, the same in both
158
+ modes) is only 3.29:1 on the white input surface — below the 4.5:1 WCAG AA
159
+ floor for text. text-muted is also a role token (auto-flips, brand-agnostic)
160
+ and clears WCAG AA contrast (>= 4.5:1) in both modes. */
161
+ --input-placeholder: var(--text-muted);
162
+ --input-surface: var(--surface-default);
163
+ --input-surface-hover: var(--surface-sunken);
164
+ --input-ring: var(--border-strong);
165
+ --input-invalid-border: var(--danger-border);
166
+ --input-invalid-surface-hover: var(--danger-surface);
167
+ --input-invalid-ring: var(--danger-solid);
168
+ /* Data-viz: brand primary ramp (mode-agnostic; not a role token). */
169
+ --chart-1: var(--primary-450);
170
+ --chart-2: var(--primary-550);
171
+ --chart-3: var(--primary-600);
172
+ --chart-4: var(--primary-650);
173
+ --chart-5: var(--primary-700);
174
+ /* shadcn base radius — sourced from the v4 token (8px), not hardcoded. */
175
+ --radius: var(--radius-md);
176
+ --sidebar: var(--background-subtle);
177
+ --sidebar-foreground: var(--text-default);
178
+ --sidebar-primary: var(--action-default);
179
+ --sidebar-primary-foreground: var(--text-inverse);
180
+ --sidebar-accent: var(--background-subtle);
181
+ --sidebar-accent-foreground: var(--text-default);
182
+ --sidebar-border: var(--border-default);
183
+ --sidebar-ring: var(--border-strong);
184
+ }
185
+
186
+ /* No `.dark` override block: every shadcn token above maps to a v4 role token whose
187
+ dark value is supplied by the .dark-scoped semantic dark import. Brand `dark:` utilities
188
+ inside components still work via the `@custom-variant dark` rule above. */
189
+
190
+ @layer base {
191
+ * {
192
+ @apply border-border outline-ring/50;
193
+ }
194
+ body {
195
+ @apply bg-background font-sans text-foreground antialiased;
196
+ }
197
+ button:not(:disabled),
198
+ [role='button']:not(:disabled) {
199
+ cursor: pointer;
200
+ }
201
+ }
202
+
203
+ /* ── System-level reduced-motion guard ──
204
+ The @nswds/tokens motion layer collapses --duration-* under
205
+ `prefers-reduced-motion: reduce`, which zeroes every transition routed through
206
+ --default-transition-duration. Two things it CANNOT reach, by construction:
207
+
208
+ 1. Keyframe animations. `animate-accordion-down`, `data-open:animate-in`,
209
+ the select's slide/zoom — their animation-duration is baked into
210
+ tw-animate-css's shorthand, not derived from --duration-*. So the height
211
+ tween and the dropdown zoom keep running for a reader who asked for less
212
+ motion, contradicting DESIGN.md ("motion-safe: transitions on the token
213
+ durations") and WCAG 2.3.3.
214
+ 2. Utility-set transition-duration. `duration-300` writes --tw-duration, not
215
+ --duration-*, so the token collapse leaves it at 300ms.
216
+
217
+ Both need one property zeroed globally, which a component class string cannot
218
+ do safely: pairing `animate-*` with `motion-reduce:animate-none` on the same
219
+ `animation` property is exactly the two-build cascade hazard check:cascade
220
+ forbids — a media query adds no specificity, so a consumer's own Tailwind
221
+ rebuild can re-emit the loser after ours. Hence a single unlayered rule here.
222
+
223
+ Unlayered + `!important` so it outranks every layered utility regardless of a
224
+ consumer's import order. `*, ::before, ::after` are ignored by check:cascade
225
+ (it only tokenises class strings and `.`-prefixed utility selectors), so this
226
+ introduces no cascade-unsafe pair. `.01ms` rather than `0` keeps the
227
+ animationend/transitionend events firing, which Base UI's accordion and select
228
+ state machines wait on to settle open/closed — the panel still OPENS, just
229
+ without the tween. iteration-count:1 stops any looping animation after one
230
+ pass instead of freezing it mid-cycle. */
231
+ @media (prefers-reduced-motion: reduce) {
232
+ *,
233
+ ::before,
234
+ ::after {
235
+ animation-duration: 0.01ms !important;
236
+ animation-iteration-count: 1 !important;
237
+ transition-duration: 0.01ms !important;
238
+ }
239
+ }