@behavioral-agentic-design-system/core 0.6.0 → 0.8.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.
Files changed (64) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +35 -6
  3. package/scripts/bads-sync.mjs +1 -1
  4. package/scripts/build-fonts.cjs +15 -8
  5. package/scripts/build-tokens.cjs +139 -23
  6. package/src/api/brand-fonts.ts +27 -6
  7. package/src/api/layers/file.ts +4 -3
  8. package/src/api/layers.ts +41 -12
  9. package/src/api/onboarding-extract.ts +435 -0
  10. package/src/api/onboarding.ts +82 -0
  11. package/src/api/site-auth.ts +50 -0
  12. package/src/app/font-ready.tsx +1 -1
  13. package/src/app/layout.tsx +9 -3
  14. package/src/app/preview/components/page.tsx +78 -1
  15. package/src/app/preview/icons/page.tsx +5 -0
  16. package/src/app/shell.tsx +90 -23
  17. package/src/app/site-login/page.tsx +82 -0
  18. package/src/brand-fonts.css +5 -0
  19. package/src/components/Foundations/Colors.stories.tsx +10 -1
  20. package/src/components/Foundations/Motion.stories.tsx +66 -0
  21. package/src/components/customize/letter-spacing.tsx +3 -2
  22. package/src/components/customize/type-scale.tsx +3 -2
  23. package/src/components/customize-tab.tsx +11 -7
  24. package/src/components/home-tab.tsx +498 -235
  25. package/src/components/layers-tab.tsx +313 -10
  26. package/src/components/onboarding-wizard.tsx +1421 -0
  27. package/src/components/ui/alert.tsx +2 -2
  28. package/src/components/ui/bottom-sheet.tsx +124 -0
  29. package/src/components/ui/button.tsx +1 -1
  30. package/src/components/ui/chart.tsx +115 -14
  31. package/src/components/ui/checkbox.tsx +3 -2
  32. package/src/components/ui/dialog.tsx +7 -4
  33. package/src/components/ui/dropdown-menu.tsx +4 -0
  34. package/src/components/ui/index.ts +1 -0
  35. package/src/components/ui/popover.tsx +6 -0
  36. package/src/components/ui/radio-group.tsx +4 -3
  37. package/src/components/ui/scroll-area.tsx +5 -0
  38. package/src/components/ui/select.tsx +4 -0
  39. package/src/components/ui/sheet.tsx +8 -1
  40. package/src/components/ui/slider.tsx +22 -7
  41. package/src/components/ui/switch.tsx +3 -3
  42. package/src/components/ui/tabs.tsx +6 -0
  43. package/src/components/ui/tooltip.tsx +4 -0
  44. package/src/fonts/HyperlegibleSans-Bold.woff2 +0 -0
  45. package/src/fonts/HyperlegibleSans-BoldItalic.woff2 +0 -0
  46. package/src/fonts/HyperlegibleSans-Italic.woff2 +0 -0
  47. package/src/fonts/HyperlegibleSans-Medium.woff2 +0 -0
  48. package/src/fonts/HyperlegibleSans-MediumItalic.woff2 +0 -0
  49. package/src/fonts/HyperlegibleSans-Regular.woff2 +0 -0
  50. package/src/fonts/InterVariable-Italic.woff2 +0 -0
  51. package/src/fonts/InterVariable.woff2 +0 -0
  52. package/src/fonts.css +99 -0
  53. package/src/hooks/use-global-primary-color.ts +114 -68
  54. package/src/hooks/use-global-serif-font.ts +1 -1
  55. package/src/hooks/use-portal-theme-class.tsx +90 -0
  56. package/src/lib/storage.ts +2 -2
  57. package/src/styles.css +151 -61
  58. package/src/tokens.default.json +4 -4
  59. package/src/tokens.json +159 -162
  60. package/src/app/preview/login/page.tsx +0 -5
  61. package/src/app/preview/mail/page.tsx +0 -4
  62. package/src/app/preview/pricing/page.tsx +0 -4
  63. package/src/components/admin-menu.stories.tsx +0 -68
  64. package/src/components/admin-menu.tsx +0 -59
@@ -4,6 +4,7 @@ import * as React from "react"
4
4
  import * as TooltipPrimitive from "@radix-ui/react-tooltip"
5
5
 
6
6
  import { cn } from "../../lib/utils"
7
+ import { usePortalThemeClass } from "../../hooks/use-portal-theme-class"
7
8
 
8
9
  function TooltipProvider({
9
10
  delayDuration = 0,
@@ -36,6 +37,8 @@ function TooltipContent({
36
37
  children,
37
38
  ...props
38
39
  }: React.ComponentProps<typeof TooltipPrimitive.Content>) {
40
+ // See use-portal-theme-class.ts.
41
+ const portalThemeClass = usePortalThemeClass()
39
42
  return (
40
43
  <TooltipPrimitive.Portal>
41
44
  <TooltipPrimitive.Content
@@ -43,6 +46,7 @@ function TooltipContent({
43
46
  sideOffset={sideOffset}
44
47
  className={cn(
45
48
  "z-50 w-fit origin-(--radix-tooltip-content-transform-origin) animate-in rounded-md bg-foreground px-3 py-1.5 text-xs text-balance text-background fade-in-0 zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95",
49
+ portalThemeClass,
46
50
  className
47
51
  )}
48
52
  {...props}
Binary file
package/src/fonts.css ADDED
@@ -0,0 +1,99 @@
1
+ /* @behavioral-agentic-design-system/core — canonical brand fonts.
2
+ *
3
+ * Static, hand-maintained @font-face block for the SIL OFL-licensed
4
+ * defaults that ship with the package (currently Hyperlegible Sans, 6
5
+ * weights). The .woff2 binaries live in ./fonts/ inside the published
6
+ * tarball.
7
+ *
8
+ * URLs resolve to /fonts/<file>.woff2 at runtime — the consumer is
9
+ * responsible for copying the binaries from
10
+ * `node_modules/@behavioral-agentic-design-system/core/fonts/` into
11
+ * their own `public/fonts/` so Next.js (or any static host) serves them
12
+ * at the expected path. See CLIENT_ONBOARDING.md → "Shipping fonts" for
13
+ * the canonical postinstall recipe.
14
+ *
15
+ * Styles.css `@import`s this file automatically — consumers don't need
16
+ * to import it themselves. Brand-uploaded faces (Season, custom client
17
+ * fonts) live in the generated companion file `./brand-fonts.css`,
18
+ * also auto-imported.
19
+ */
20
+
21
+ /* ============================================================
22
+ * Inter — primary sans (SIL OFL 1.1), VARIABLE.
23
+ * A single woff2 per style covers the full 100–900 weight axis, so
24
+ * font-weight resolves continuously and forks can tune the wght/opsz
25
+ * axes via --font-variation-settings (tokens.json → fontVariationSettings)
26
+ * without shipping extra files. Latin subset (wght axis). Source:
27
+ * fontsource Inter VF. font-display: swap to avoid invisible text.
28
+ * https://rsms.me/inter/
29
+ * ============================================================ */
30
+ @font-face {
31
+ font-family: 'Inter';
32
+ src: url('/fonts/InterVariable.woff2') format('woff2');
33
+ font-weight: 100 900;
34
+ font-style: normal;
35
+ font-display: swap;
36
+ }
37
+
38
+ @font-face {
39
+ font-family: 'Inter';
40
+ src: url('/fonts/InterVariable-Italic.woff2') format('woff2');
41
+ font-weight: 100 900;
42
+ font-style: italic;
43
+ font-display: swap;
44
+ }
45
+
46
+ /* ============================================================
47
+ * Hyperlegible Sans — accessibility-preserving fallback (SIL OFL 1.1).
48
+ * The Braille Institute's low-vision face. Stays self-hosted and second
49
+ * in the --font-sans stack so a low-vision-heavy fork can reorder
50
+ * tokens.json fontFamily.sans to lead with it. Static weights.
51
+ * https://www.brailleinstitute.org/freefont
52
+ * ============================================================ */
53
+ @font-face {
54
+ font-family: 'Hyperlegible Sans';
55
+ src: url('/fonts/HyperlegibleSans-Regular.woff2') format('woff2');
56
+ font-weight: 400;
57
+ font-style: normal;
58
+ font-display: swap;
59
+ }
60
+
61
+ @font-face {
62
+ font-family: 'Hyperlegible Sans';
63
+ src: url('/fonts/HyperlegibleSans-Italic.woff2') format('woff2');
64
+ font-weight: 400;
65
+ font-style: italic;
66
+ font-display: swap;
67
+ }
68
+
69
+ @font-face {
70
+ font-family: 'Hyperlegible Sans';
71
+ src: url('/fonts/HyperlegibleSans-Medium.woff2') format('woff2');
72
+ font-weight: 500;
73
+ font-style: normal;
74
+ font-display: swap;
75
+ }
76
+
77
+ @font-face {
78
+ font-family: 'Hyperlegible Sans';
79
+ src: url('/fonts/HyperlegibleSans-MediumItalic.woff2') format('woff2');
80
+ font-weight: 500;
81
+ font-style: italic;
82
+ font-display: swap;
83
+ }
84
+
85
+ @font-face {
86
+ font-family: 'Hyperlegible Sans';
87
+ src: url('/fonts/HyperlegibleSans-Bold.woff2') format('woff2');
88
+ font-weight: 700;
89
+ font-style: normal;
90
+ font-display: swap;
91
+ }
92
+
93
+ @font-face {
94
+ font-family: 'Hyperlegible Sans';
95
+ src: url('/fonts/HyperlegibleSans-BoldItalic.woff2') format('woff2');
96
+ font-weight: 700;
97
+ font-style: italic;
98
+ font-display: swap;
99
+ }
@@ -163,6 +163,12 @@ const PRIMARY_OVERRIDE_VARIABLES = [
163
163
  "--sidebar-primary",
164
164
  "--sidebar-primary-foreground",
165
165
  "--sidebar-ring",
166
+ // Chart vars are written inline by applyColor / writeChartRamp below.
167
+ // The stylesheet rule (oklch(from var(--primary) ...)) emitted by
168
+ // build-tokens.cjs gets precompiled by Next 16's Lightning CSS into a
169
+ // static lab() fallback that wins on every modern browser. Writing
170
+ // inline forces runtime resolution against the live --primary so picker
171
+ // changes actually reach charts.
166
172
  "--chart-1",
167
173
  "--chart-2",
168
174
  "--chart-3",
@@ -170,68 +176,50 @@ const PRIMARY_OVERRIDE_VARIABLES = [
170
176
  "--chart-5",
171
177
  ];
172
178
 
173
- // Chart ramp config — must stay in sync with tokens.json chart.lightnessSteps
174
- // and chart.chromaSteps. Build-tokens.cjs reads the same values to emit the
175
- // CSS derivation block, but we also write the ramp inline at runtime because
176
- // Lightning CSS precomputes oklch(from var(--primary) ...) into a static
177
- // lab() fallback inside @supports — which wins over the relative-color rule
178
- // and freezes the chart palette to the build-time --primary. Writing inline
179
- // bypasses the bundler and lets the browser resolve the relative color at
180
- // runtime against whatever --primary the brand picker just set.
181
- const CHART_RAMP = [
182
- { l: "0.58", c: "1.00" },
183
- { l: "0.50", c: "0.95" },
184
- { l: "0.42", c: "0.80" },
185
- { l: "0.34", c: "0.60" },
186
- { l: "0.27", c: "0.40" },
187
- ] as const;
188
- const CHART_RAMP_DARK = [
189
- { l: "0.78", c: "1.00" },
190
- { l: "0.70", c: "0.95" },
191
- { l: "0.62", c: "0.80" },
192
- { l: "0.56", c: "0.60" },
193
- { l: "0.52", c: "0.40" },
194
- ] as const;
195
-
196
- // Variables managed elsewhere (Customize tab token swatch picker) that we
197
- // should NOT overwrite on a brand change. Read fresh from localStorage so
198
- // the brand picker honors them without needing a hook subscription.
199
- function readUserTokenOverrides(): Set<string> {
179
+ // Chart ramp constants — mirror tokens.json → chart.lightness / hueRotation /
180
+ // chroma2Damping. Update both files together when retuning the chart palette.
181
+ const CHART_LIGHTNESS_LIGHT = 0.58;
182
+ const CHART_LIGHTNESS_DARK = 0.78;
183
+ const CHART_HUE_ROTATIONS = [0, 35, 70, 105, 140] as const;
184
+ const CHART_CHROMA2_DAMPING = 0.65;
185
+
186
+ function readOverriddenChartVars(): Set<string> {
200
187
  if (typeof window === "undefined") return new Set();
201
188
  try {
202
- const raw =
203
- window.localStorage.getItem(storageKey("tokenOverrides")) ??
204
- window.localStorage.getItem("tokenOverrides");
189
+ const raw = readMigrated("tokenOverrides");
205
190
  if (!raw) return new Set();
206
191
  const parsed = JSON.parse(raw) as Record<string, string>;
207
- return new Set(Object.keys(parsed ?? {}));
192
+ if (!parsed || typeof parsed !== "object") return new Set();
193
+ return new Set(Object.keys(parsed).filter((k) => k.startsWith("--chart-")));
208
194
  } catch {
209
195
  return new Set();
210
196
  }
211
197
  }
212
198
 
213
- function chartRampValue(index: 0 | 1 | 2 | 3 | 4, dark: boolean): string {
214
- const step = (dark ? CHART_RAMP_DARK : CHART_RAMP)[index];
215
- const c = step.c === "1.00" ? "c" : `calc(c * ${step.c})`;
216
- return `oklch(from var(--primary) ${step.l} ${c} h)`;
199
+ function writeChartRamp() {
200
+ if (typeof document === "undefined") return;
201
+ const root = document.documentElement;
202
+ const style = root.style;
203
+ const isDark = root.classList.contains("dark");
204
+ const L = isDark ? CHART_LIGHTNESS_DARK : CHART_LIGHTNESS_LIGHT;
205
+ const overridden = readOverriddenChartVars();
206
+ for (let i = 0; i < 5; i++) {
207
+ const name = `--chart-${i + 1}`;
208
+ if (overridden.has(name)) continue;
209
+ const hue = CHART_HUE_ROTATIONS[i];
210
+ const chroma = i === 1 ? `calc(c * ${CHART_CHROMA2_DAMPING})` : "c";
211
+ style.setProperty(name, `oklch(from var(--primary) ${L} ${chroma} calc(h + ${hue}))`);
212
+ }
217
213
  }
218
214
 
219
215
  /**
220
- * Re-apply the chart ramp inline based on the current --primary and dark
221
- * mode. Use after clearing a chart-N user override so the cascade doesn't
222
- * fall through to the Lightning CSS lab() precomputation. Skips any chart
223
- * variable still listed in user token overrides.
216
+ * Re-evaluate the chart ramp against the current --primary and dark-mode
217
+ * state. Called when the user resets a chart-N override so the cleared
218
+ * variable falls back to the brand-derived ramp instead of the frozen
219
+ * build-time lab() value Lightning CSS precomputed.
224
220
  */
225
- export function reapplyChartRamp() {
226
- if (typeof document === "undefined") return;
227
- const root = document.documentElement.style;
228
- const userOverrides = readUserTokenOverrides();
229
- const isDark = document.documentElement.classList.contains("dark");
230
- for (let i = 0; i < 5; i++) {
231
- const varName = `--chart-${i + 1}`;
232
- if (userOverrides.has(varName)) continue;
233
- root.setProperty(varName, chartRampValue(i as 0 | 1 | 2 | 3 | 4, isDark));
234
- }
221
+ export function reapplyChartRamp(): void {
222
+ writeChartRamp();
235
223
  }
236
224
 
237
225
  function buildCustom(hex: string, label?: string): PrimaryColorOption {
@@ -296,22 +284,75 @@ function applyColor(opt: PrimaryColorOption) {
296
284
  root.setProperty("--primary", opt.primary);
297
285
  root.setProperty("--primary-foreground", opt.primaryForeground);
298
286
  root.setProperty("--ring", opt.primary);
299
- root.setProperty("--accent-foreground", opt.primary);
287
+
288
+ // --accent-foreground used to be set unconditionally to opt.primary. That
289
+ // produced silent contrast failures when the brand color was too close in
290
+ // luminance to the dark-mode accent surface (the wcag-audit script can't
291
+ // see runtime overrides, so this bug stayed hidden). Now we read the live
292
+ // --accent value, compute contrast for both candidates (brand color +
293
+ // brand-foreground), and pick whichever passes AAA. If neither does, we
294
+ // skip the override and let the stylesheet default win — it's already
295
+ // luminance-tuned.
296
+ const accentFg = pickAccentForeground(opt);
297
+ if (accentFg) {
298
+ root.setProperty("--accent-foreground", accentFg);
299
+ } else {
300
+ root.removeProperty("--accent-foreground");
301
+ }
302
+
300
303
  root.setProperty("--sidebar-primary", opt.primary);
301
304
  root.setProperty("--sidebar-primary-foreground", opt.primaryForeground);
302
305
  root.setProperty("--sidebar-ring", opt.primary);
306
+ // Inline-write the chart ramp so brand picker changes reach charts. The
307
+ // stylesheet rule is precomputed by Lightning CSS into a frozen lab().
308
+ writeChartRamp();
309
+ }
303
310
 
304
- // Apply the chart ramp inline. This duplicates the CSS derivation but is
305
- // necessary because Lightning CSS bakes the CSS rule into a static lab()
306
- // fallback that wins over the relative-color form. Inline values escape
307
- // that precomputation. Per-chart user overrides (token swatch picker) are
308
- // preserved by reading the tokenOverrides map and skipping those keys.
309
- const userOverrides = readUserTokenOverrides();
310
- const isDark = document.documentElement.classList.contains("dark");
311
- for (let i = 0; i < 5; i++) {
312
- const varName = `--chart-${i + 1}`;
313
- if (userOverrides.has(varName)) continue;
314
- root.setProperty(varName, chartRampValue(i as 0 | 1 | 2 | 3 | 4, isDark));
311
+ const ACCENT_TEXT_FLOOR = 4.5; // AA for text — accent surfaces typically host UI labels, not body.
312
+
313
+ function pickAccentForeground(opt: PrimaryColorOption): string | null {
314
+ if (typeof document === "undefined") return null;
315
+ const accentValue = getComputedStyle(document.documentElement)
316
+ .getPropertyValue("--accent")
317
+ .trim();
318
+ if (!accentValue) return null;
319
+ const accentRgb = parseCssColorToRgb(accentValue);
320
+ if (!accentRgb) return null;
321
+ const candidates: string[] = [opt.primary, opt.primaryForeground];
322
+ for (const cand of candidates) {
323
+ const candRgb = rgbFromHex(cand);
324
+ if (contrastRatio(candRgb, accentRgb) >= ACCENT_TEXT_FLOOR) return cand;
325
+ }
326
+ // Both candidates fail — give up and let the stylesheet default ride.
327
+ return null;
328
+ }
329
+
330
+ // Parses a computed-style color (hex, rgb(), oklch(), lab()) into [r,g,b].
331
+ // Returns null if the browser hasn't resolved the value or the parse fails.
332
+ function parseCssColorToRgb(value: string): [number, number, number] | null {
333
+ if (typeof document === "undefined") return null;
334
+ // Cheapest path: hex literal.
335
+ if (/^#([0-9a-fA-F]{3,8})$/.test(value)) {
336
+ try {
337
+ return rgbFromHex(value);
338
+ } catch {
339
+ return null;
340
+ }
341
+ }
342
+ // Fall through to canvas: every other CSS color string parses uniformly.
343
+ try {
344
+ const canvas = document.createElement("canvas");
345
+ canvas.width = 1;
346
+ canvas.height = 1;
347
+ const ctx = canvas.getContext("2d");
348
+ if (!ctx) return null;
349
+ ctx.fillStyle = "#000";
350
+ ctx.fillStyle = value;
351
+ ctx.fillRect(0, 0, 1, 1);
352
+ const [r, g, b] = ctx.getImageData(0, 0, 1, 1).data;
353
+ return [r / 255, g / 255, b / 255];
354
+ } catch {
355
+ return null;
315
356
  }
316
357
  }
317
358
 
@@ -396,14 +437,19 @@ function bootstrap() {
396
437
  }
397
438
  });
398
439
 
399
- // Re-apply the chart ramp when dark mode toggles. The ramp values differ
400
- // between light (L=0.58 → 0.27) and dark (L=0.78 → 0.52) because the AAA
401
- // contrast floor against the card background is mode-dependent.
402
- const darkObserver = new MutationObserver(() => {
403
- const merged = { ...BUILTIN_PRIMARY_COLORS, ...snapshot.customs };
404
- applySelectedColor(snapshot.color, merged);
440
+ // Dark-mode toggle: re-evaluate the chart ramp at the new mode's L. The
441
+ // shell toggles `.dark` on documentElement; we observe that class attribute
442
+ // and re-run applySelectedColor so writeChartRamp picks up the new mode.
443
+ const themeObserver = new MutationObserver((mutations) => {
444
+ for (const m of mutations) {
445
+ if (m.attributeName === "class") {
446
+ const merged = { ...BUILTIN_PRIMARY_COLORS, ...snapshot.customs };
447
+ applySelectedColor(snapshot.color, merged);
448
+ break;
449
+ }
450
+ }
405
451
  });
406
- darkObserver.observe(document.documentElement, {
452
+ themeObserver.observe(document.documentElement, {
407
453
  attributes: true,
408
454
  attributeFilter: ["class"],
409
455
  });
@@ -36,7 +36,7 @@ export type SerifFontKey = string;
36
36
  import { storageKey, readMigrated } from "@behavioral-agentic-design-system/core/lib/storage";
37
37
 
38
38
  const STORAGE_KEY = storageKey("serifFont");
39
- const DEFAULT: SerifFontKey = "season-serif";
39
+ const DEFAULT: SerifFontKey = "georgia";
40
40
 
41
41
  function isValidKey(value: string | null): value is SerifFontKey {
42
42
  return !!value && value in SERIF_FONT_OPTIONS;
@@ -0,0 +1,90 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+
5
+ /**
6
+ * Portal-theme-class — keeps Radix Portal'd content (Dialog / Sheet /
7
+ * Popover / Tooltip / HoverCard / DropdownMenu / Select content) inside
8
+ * a consumer's theme scope.
9
+ *
10
+ * Why this exists
11
+ * ----------------
12
+ * Radix portals every "content" surface to `<body>`. Theme classes a
13
+ * consumer applies to a page wrapper (e.g. `<div className="atrium-theme">`)
14
+ * sit ABOVE the body's children in the DOM tree, NOT above the portal —
15
+ * so theme-scoped CSS variables (`--shell-chrome-bg-rgb`, `--brand-*`)
16
+ * defined inside that wrapper class don't reach the portal'd content.
17
+ *
18
+ * The most visible failure mode: a SheetContent styled with
19
+ * `style={{ backgroundColor: "rgb(var(--shell-chrome-bg-rgb) / 0.98)" }}`
20
+ * evaluates to `rgb(undefined / 0.98)` inside the portal, the property
21
+ * is invalid at computed-value time, and the panel falls through to a
22
+ * transparent ghost over the dimmed page. Same root cause as the
23
+ * pre-2026-05 `:root { --shell-cta-bg: var(--shell-accent) }`
24
+ * "white-on-white CTA" bug — variable referenced outside its declaring
25
+ * scope.
26
+ *
27
+ * How it works
28
+ * ------------
29
+ * `<PortalThemeProvider scope="atrium-theme">` is placed once near the
30
+ * app root (typically in the shell's layout) and re-renders whenever
31
+ * the active scope changes. React context CROSSES portals: the body is
32
+ * the React parent of every Portal'd child, but the React TREE still
33
+ * walks up through the provider to find the context value. So Portal'd
34
+ * components reading `usePortalThemeClass()` get the live scope class
35
+ * regardless of where Radix moved their DOM.
36
+ *
37
+ * Each BADS-shipped Portal component (Sheet, Dialog, Popover, etc.)
38
+ * calls the hook and merges the returned class into its content's
39
+ * className via `cn()`. The scope className applied there re-introduces
40
+ * the theme-scoped CSS variables INSIDE the portal — so
41
+ * `rgb(var(--shell-chrome-bg-rgb) / 0.98)` resolves correctly because
42
+ * the var() lookup happens at the portal element, which now has the
43
+ * theme class applied.
44
+ *
45
+ * Multiple scope classes
46
+ * ----------------------
47
+ * `scope` accepts a space-separated string, so a consumer composing
48
+ * style + dark mode + brand can pass `"atrium-theme dark brand-pool"`.
49
+ * The hook returns whatever string the provider holds.
50
+ *
51
+ * SSR
52
+ * ---
53
+ * Defaults to `""` — no class is applied. Renders identically server-
54
+ * and client-side as long as the provider value is stable through
55
+ * hydration. Consumers reading state from localStorage should defer the
56
+ * provider value to a useEffect-mounted state to avoid hydration
57
+ * mismatch (`""` server, scope after hydrate).
58
+ *
59
+ * Backwards compat
60
+ * ----------------
61
+ * If a consumer never adds the provider, the hook returns `""` and
62
+ * every BADS Portal component renders as before. Additive — no
63
+ * breaking changes.
64
+ */
65
+
66
+ const PortalThemeContext = React.createContext<string>("");
67
+
68
+ export function PortalThemeProvider({
69
+ scope,
70
+ children,
71
+ }: {
72
+ /**
73
+ * Space-separated class names to apply to every Portal'd BADS
74
+ * component's content surface (Dialog/Sheet/Popover/Tooltip/etc.).
75
+ * Typically the active theme/scope class — e.g. `"atrium-theme"`,
76
+ * `"clap-brand dark"`, etc.
77
+ */
78
+ scope: string;
79
+ children: React.ReactNode;
80
+ }) {
81
+ return (
82
+ <PortalThemeContext.Provider value={scope}>
83
+ {children}
84
+ </PortalThemeContext.Provider>
85
+ );
86
+ }
87
+
88
+ export function usePortalThemeClass(): string {
89
+ return React.useContext(PortalThemeContext);
90
+ }
@@ -4,13 +4,13 @@
4
4
  *
5
5
  * Why this exists
6
6
  * ----------------
7
- * Before 0.4.0, every hook had `const STORAGE_KEY = "SWIMTOPIA-AGENTIC-DESIGN-SYSTEM.sansFont"` (and
7
+ * Before 0.4.0, every hook had `const STORAGE_KEY = "BADS.sansFont"` (and
8
8
  * similar) inlined. `scripts/rename.mjs` rewrote those strings at fork time
9
9
  * so a renamed fork stored data under "<SLUG_UPPER>.sansFont" instead.
10
10
  *
11
11
  * Once @core started shipping the hooks via npm (0.3.0), rename.mjs could no
12
12
  * longer reach the hook source — it lives in node_modules, not the consumer
13
- * tree. Forks ended up reading "SWIMTOPIA-AGENTIC-DESIGN-SYSTEM.sansFont" from localStorage even though
13
+ * tree. Forks ended up reading "BADS.sansFont" from localStorage even though
14
14
  * their saved customizations were under "<SLUG_UPPER>.sansFont", silently
15
15
  * losing every Customize-tab edit they had made.
16
16
  *