@behavioral-agentic-design-system/core 0.27.0 → 0.29.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/package.json +5 -5
- package/scripts/a11y-lint.cjs +78 -9
- package/scripts/build-tokens.cjs +273 -15
- package/scripts/wcag-audit.cjs +37 -7
- package/src/api/layers/file.ts +1 -0
- package/src/app/font-ready.tsx +6 -5
- package/src/app/layout.tsx +54 -3
- package/src/app/preview/components/page.tsx +5735 -2500
- package/src/app/preview/layout.tsx +4 -1
- package/src/app/preview/showcase-filter.tsx +66 -0
- package/src/app/preview/tab-replay.tsx +63 -0
- package/src/app/shell.tsx +91 -18
- package/src/components/customize/save-bar.tsx +19 -6
- package/src/components/docs-tab.tsx +36 -24
- package/src/components/layers-tab.tsx +37 -5
- package/src/components/ui/ai-badge.tsx +74 -0
- package/src/components/ui/alert.tsx +12 -0
- package/src/components/ui/badge.tsx +19 -0
- package/src/components/ui/chat-bubble.tsx +298 -0
- package/src/components/ui/chat-marker.tsx +120 -0
- package/src/components/ui/checkbox.tsx +9 -1
- package/src/components/ui/clipboard.tsx +291 -0
- package/src/components/ui/close-button.tsx +71 -0
- package/src/components/ui/combobox.tsx +62 -3
- package/src/components/ui/container.tsx +65 -0
- package/src/components/ui/copy-button.tsx +5 -1
- package/src/components/ui/data-table.tsx +388 -0
- package/src/components/ui/date-field.tsx +368 -0
- package/src/components/ui/drawer.tsx +334 -0
- package/src/components/ui/file-button.tsx +145 -0
- package/src/components/ui/floating-indicator.tsx +217 -0
- package/src/components/ui/focus-trap.tsx +184 -0
- package/src/components/ui/format-byte.tsx +113 -0
- package/src/components/ui/index.ts +28 -0
- package/src/components/ui/input.tsx +38 -3
- package/src/components/ui/keyboard-shortcut.tsx +146 -0
- package/src/components/ui/loading-dots.tsx +99 -0
- package/src/components/ui/mark.tsx +69 -0
- package/src/components/ui/month-picker.tsx +296 -0
- package/src/components/ui/multi-select.tsx +15 -13
- package/src/components/ui/nav-link.tsx +200 -0
- package/src/components/ui/navigation-rail.tsx +256 -0
- package/src/components/ui/notification.tsx +20 -0
- package/src/components/ui/password-input.tsx +34 -1
- package/src/components/ui/progress.tsx +15 -1
- package/src/components/ui/prose.tsx +62 -0
- package/src/components/ui/result.tsx +151 -0
- package/src/components/ui/rolling-number.tsx +201 -0
- package/src/components/ui/simple-grid.tsx +110 -0
- package/src/components/ui/skeleton.tsx +52 -3
- package/src/components/ui/squircle.tsx +274 -0
- package/src/components/ui/stack.tsx +105 -0
- package/src/components/ui/status-badge.tsx +93 -0
- package/src/components/ui/tabs.tsx +34 -7
- package/src/components/ui/tag.tsx +46 -5
- package/src/components/ui/theme-icon.tsx +138 -0
- package/src/components/ui/timeline.tsx +27 -10
- package/src/components/ui/tooltip.tsx +12 -1
- package/src/components/ui/tree-select.tsx +386 -0
- package/src/components/ui/typing-indicator.tsx +2 -2
- package/src/components/ui/word-rotate.tsx +6 -1
- package/src/components/ui/year-picker.tsx +307 -0
- package/src/data/docs-index.ts +10 -0
- package/src/hooks/use-global-primary-color.ts +57 -6
- package/src/stories/AiBadge.stories.tsx +67 -0
- package/src/stories/Alert.stories.tsx +31 -1
- package/src/stories/Badge.stories.tsx +63 -6
- package/src/stories/ChatBubble.stories.tsx +222 -0
- package/src/stories/ChatMarker.stories.tsx +59 -0
- package/src/stories/Checkbox.stories.tsx +5 -0
- package/src/stories/Clipboard.stories.tsx +136 -0
- package/src/stories/CloseButton.stories.tsx +65 -0
- package/src/stories/Combobox.stories.tsx +74 -3
- package/src/stories/Container.stories.tsx +134 -0
- package/src/stories/CopyButton.stories.tsx +2 -0
- package/src/stories/DataTable.stories.tsx +271 -0
- package/src/stories/DateField.stories.tsx +114 -0
- package/src/stories/Drawer.stories.tsx +211 -0
- package/src/stories/FileButton.stories.tsx +117 -0
- package/src/stories/FloatingIndicator.stories.tsx +343 -0
- package/src/stories/FocusTrap.stories.tsx +218 -0
- package/src/stories/FormatByte.stories.tsx +142 -0
- package/src/stories/Input.stories.tsx +91 -0
- package/src/stories/KeyboardShortcut.stories.tsx +87 -0
- package/src/stories/LoadingDots.stories.tsx +73 -0
- package/src/stories/Mark.stories.tsx +84 -0
- package/src/stories/MonthPicker.stories.tsx +99 -0
- package/src/stories/MultiSelect.stories.tsx +3 -1
- package/src/stories/NavLink.stories.tsx +213 -0
- package/src/stories/NavigationRail.stories.tsx +413 -0
- package/src/stories/Notification.stories.tsx +53 -0
- package/src/stories/PasswordInput.stories.tsx +21 -0
- package/src/stories/Progress.stories.tsx +38 -0
- package/src/stories/Prose.stories.tsx +232 -0
- package/src/stories/Result.stories.tsx +145 -0
- package/src/stories/RollingNumber.stories.tsx +226 -0
- package/src/stories/SimpleGrid.stories.tsx +130 -0
- package/src/stories/Skeleton.stories.tsx +62 -1
- package/src/stories/Squircle.stories.tsx +127 -0
- package/src/stories/Stack.stories.tsx +139 -0
- package/src/stories/StatusBadge.stories.tsx +125 -0
- package/src/stories/Tabs.stories.tsx +56 -1
- package/src/stories/Tag.stories.tsx +31 -0
- package/src/stories/ThemeIcon.stories.tsx +97 -0
- package/src/stories/Timeline.stories.tsx +69 -0
- package/src/stories/Tooltip.stories.tsx +18 -0
- package/src/stories/TreeSelect.stories.tsx +222 -0
- package/src/stories/TypingIndicator.stories.tsx +1 -0
- package/src/stories/WordRotate.stories.tsx +1 -0
- package/src/stories/YearPicker.stories.tsx +100 -0
- package/src/styles.css +289 -15
- package/src/tokens.json +96 -1
- package/LICENSE +0 -21
|
@@ -2,12 +2,15 @@ import "@/styles/globals.css";
|
|
|
2
2
|
import { TooltipProvider } from "@behavioral-agentic-design-system/core/components/ui/tooltip";
|
|
3
3
|
import DarkModeClient from "./dark-mode-client";
|
|
4
4
|
import GlobalFontClient from "./global-font-client";
|
|
5
|
+
import { TabReplay } from "./tab-replay";
|
|
5
6
|
|
|
6
7
|
export default function PreviewLayout({ children }: { children: React.ReactNode }) {
|
|
7
8
|
return (
|
|
8
9
|
<TooltipProvider>
|
|
9
10
|
<GlobalFontClient />
|
|
10
|
-
<DarkModeClient>
|
|
11
|
+
<DarkModeClient>
|
|
12
|
+
<TabReplay>{children}</TabReplay>
|
|
13
|
+
</DarkModeClient>
|
|
11
14
|
</TooltipProvider>
|
|
12
15
|
);
|
|
13
16
|
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Lets a consuming fork decide which primitives its Components tab shows.
|
|
5
|
+
*
|
|
6
|
+
* The problem this solves is a release problem, not a rendering one. Core's Components tab renders
|
|
7
|
+
* every primitive core ships — 129 sections and growing nightly. Because forks import that page
|
|
8
|
+
* directly, publishing a release drops every newly-added component straight into every client's
|
|
9
|
+
* design system, unannounced. From the client's side a routine dependency bump looks like someone
|
|
10
|
+
* added thirty components to their product overnight, and the catalogue stops reading as a set of
|
|
11
|
+
* deliberate choices.
|
|
12
|
+
*
|
|
13
|
+
* Wrapping the page in a provider inverts that: the fork names what belongs in its system, and
|
|
14
|
+
* anything else core ships stays installed and importable but invisible until the fork asks for it.
|
|
15
|
+
* A component earns its place by being listed.
|
|
16
|
+
*
|
|
17
|
+
* import { ShowcaseFilterProvider } from "@behavioral-agentic-design-system/core/app/preview/showcase-filter";
|
|
18
|
+
* import CorePrimitives from "@behavioral-agentic-design-system/core/app/preview/components/page";
|
|
19
|
+
*
|
|
20
|
+
* <ShowcaseFilterProvider include={["buttons", "inputs", "form-controls"]}>
|
|
21
|
+
* <CorePrimitives />
|
|
22
|
+
* </ShowcaseFilterProvider>
|
|
23
|
+
*
|
|
24
|
+
* Ids are slugified section titles ("Form controls" → "form-controls"). Every section renders a
|
|
25
|
+
* `data-section-id` attribute, so the available ids can be read straight off the page in devtools
|
|
26
|
+
* rather than guessed from source.
|
|
27
|
+
*
|
|
28
|
+
* With no provider the value is "all", so this is backwards compatible: an existing fork that
|
|
29
|
+
* upgrades sees no change until it opts in.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
import { createContext, useContext, type ReactNode } from "react";
|
|
33
|
+
|
|
34
|
+
export type ShowcaseInclude = readonly string[] | "all";
|
|
35
|
+
|
|
36
|
+
const ShowcaseFilterContext = createContext<ShowcaseInclude>("all");
|
|
37
|
+
|
|
38
|
+
/** Slugify a section title into its stable id. Shared so filtering and rendering cannot disagree. */
|
|
39
|
+
export function sectionId(title: string): string {
|
|
40
|
+
return title
|
|
41
|
+
.toLowerCase()
|
|
42
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
43
|
+
.replace(/(^-|-$)/g, "");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function ShowcaseFilterProvider({
|
|
47
|
+
include,
|
|
48
|
+
children,
|
|
49
|
+
}: {
|
|
50
|
+
/** Section ids to show, or "all". */
|
|
51
|
+
include: ShowcaseInclude;
|
|
52
|
+
children: ReactNode;
|
|
53
|
+
}) {
|
|
54
|
+
return (
|
|
55
|
+
<ShowcaseFilterContext.Provider value={include}>
|
|
56
|
+
{children}
|
|
57
|
+
</ShowcaseFilterContext.Provider>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Whether a section should render. True when no provider is mounted. */
|
|
62
|
+
export function useSectionVisible(id: string): boolean {
|
|
63
|
+
const include = useContext(ShowcaseFilterContext);
|
|
64
|
+
if (include === "all") return true;
|
|
65
|
+
return include.includes(id);
|
|
66
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Replays the tab's entrance animation every time the tab is (re-)activated.
|
|
5
|
+
*
|
|
6
|
+
* The preview tabs are sticky-mounted iframes (see shell.tsx / TabsPanels): a
|
|
7
|
+
* tab mounts once and stays in the DOM so switching back is instant. The side
|
|
8
|
+
* effect is that the charts inside animate exactly once — on that first mount,
|
|
9
|
+
* often while the tab is still hidden during preload — and never again. So on
|
|
10
|
+
* every subsequent visit the content just sits there, fully drawn, with no
|
|
11
|
+
* entrance.
|
|
12
|
+
*
|
|
13
|
+
* This wrapper watches the host tab's `data-state` (read from the parent
|
|
14
|
+
* TabsContent via `window.frameElement`, same-origin) and bumps a remount key
|
|
15
|
+
* each time the tab transitions inactive → active. Remounting the subtree makes
|
|
16
|
+
* every chart re-run its recharts entrance (and any mount-time motion), so the
|
|
17
|
+
* page animates in fresh each time you load the tab — including the first real
|
|
18
|
+
* view, which fixes the "animation finished during hidden preload" case too.
|
|
19
|
+
*
|
|
20
|
+
* Guards:
|
|
21
|
+
* - `prefers-reduced-motion: reduce` → never replays (no observer, no remount).
|
|
22
|
+
* - Direct visit (not inside a tab iframe) → renders once, no replay.
|
|
23
|
+
* - Only inactive → active transitions remount; leaving a tab does nothing.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import * as React from "react";
|
|
27
|
+
import { prefersReducedMotion } from "../../hooks/use-reduced-motion";
|
|
28
|
+
|
|
29
|
+
export function TabReplay({ children }: { children: React.ReactNode }) {
|
|
30
|
+
const [gen, setGen] = React.useState(0);
|
|
31
|
+
|
|
32
|
+
React.useEffect(() => {
|
|
33
|
+
if (prefersReducedMotion()) return;
|
|
34
|
+
|
|
35
|
+
let frameEl: Element | null = null;
|
|
36
|
+
try {
|
|
37
|
+
frameEl = window.frameElement;
|
|
38
|
+
} catch {
|
|
39
|
+
frameEl = null;
|
|
40
|
+
}
|
|
41
|
+
// Not inside the tab iframe (e.g. /preview/cards opened directly): mount
|
|
42
|
+
// once and let the charts animate normally — nothing to replay against.
|
|
43
|
+
if (!frameEl) return;
|
|
44
|
+
|
|
45
|
+
const panel = frameEl.closest('[data-slot="tabs-content"], [role="tabpanel"]');
|
|
46
|
+
if (!panel) return;
|
|
47
|
+
|
|
48
|
+
let wasActive = panel.getAttribute("data-state") === "active";
|
|
49
|
+
const obs = new MutationObserver(() => {
|
|
50
|
+
const active = panel.getAttribute("data-state") === "active";
|
|
51
|
+
// Remount only on the inactive → active edge so the entrance replays once
|
|
52
|
+
// per visit, not on every attribute mutation.
|
|
53
|
+
if (active && !wasActive) setGen((g) => g + 1);
|
|
54
|
+
wasActive = active;
|
|
55
|
+
});
|
|
56
|
+
obs.observe(panel, { attributes: true, attributeFilter: ["data-state"] });
|
|
57
|
+
return () => obs.disconnect();
|
|
58
|
+
}, []);
|
|
59
|
+
|
|
60
|
+
// A keyed fragment: changing the key remounts the whole subtree in a single
|
|
61
|
+
// React commit (no blank frame), so charts re-init and re-animate.
|
|
62
|
+
return <React.Fragment key={gen}>{children}</React.Fragment>;
|
|
63
|
+
}
|
package/src/app/shell.tsx
CHANGED
|
@@ -84,6 +84,16 @@ export function IframePreview({
|
|
|
84
84
|
}, [dark]);
|
|
85
85
|
|
|
86
86
|
useEffect(() => {
|
|
87
|
+
// Skip while hidden inside an inactive tab panel. This passive effect
|
|
88
|
+
// fires after first paint — mid view-transition — and retheming a heavy
|
|
89
|
+
// hidden document there stutters the dark/light iris wipe. The Shell's
|
|
90
|
+
// toggleDark converges every hidden iframe after the transition finishes,
|
|
91
|
+
// so nothing stays stale (see the retheme-strategy comment in toggleDark).
|
|
92
|
+
if (
|
|
93
|
+
iframeRef.current?.closest('[data-slot="tabs-content"]')?.getAttribute("data-state") ===
|
|
94
|
+
"inactive"
|
|
95
|
+
)
|
|
96
|
+
return;
|
|
87
97
|
syncDarkMode();
|
|
88
98
|
}, [syncDarkMode]);
|
|
89
99
|
|
|
@@ -250,6 +260,23 @@ export function Shell({ tabs, defaultTab }: ShellProps) {
|
|
|
250
260
|
url.searchParams.set("tab", value);
|
|
251
261
|
window.history.pushState({ shellTab: value }, "", url);
|
|
252
262
|
} catch {}
|
|
263
|
+
// Snap the (re)selected preview tab's iframe back to the top. The tabs are
|
|
264
|
+
// sticky-mounted, so returning to Components would otherwise land wherever
|
|
265
|
+
// it was last scrolled — clicking a preview tab should show it from the
|
|
266
|
+
// start. Same-origin iframe, so contentWindow is reachable (the theme-sync
|
|
267
|
+
// effect uses it too). rAF waits for Radix to flip data-state on the new
|
|
268
|
+
// panel; native tabs (no iframe) match nothing → their scroll is preserved.
|
|
269
|
+
// On a tab's first-ever selection the iframe hasn't mounted yet, so this
|
|
270
|
+
// no-ops — a cold load already starts at the top.
|
|
271
|
+
requestAnimationFrame(() => {
|
|
272
|
+
try {
|
|
273
|
+
document
|
|
274
|
+
.querySelector<HTMLIFrameElement>(
|
|
275
|
+
'[role="tabpanel"][data-state="active"] iframe',
|
|
276
|
+
)
|
|
277
|
+
?.contentWindow?.scrollTo({ top: 0 });
|
|
278
|
+
} catch {}
|
|
279
|
+
});
|
|
253
280
|
}, []);
|
|
254
281
|
|
|
255
282
|
// Restore the active tab once on mount, preferring an explicit ?tab= in the
|
|
@@ -347,40 +374,86 @@ export function Shell({ tabs, defaultTab }: ShellProps) {
|
|
|
347
374
|
const prefersReduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
348
375
|
const supports = typeof document !== "undefined" && "startViewTransition" in document;
|
|
349
376
|
|
|
350
|
-
//
|
|
351
|
-
//
|
|
352
|
-
//
|
|
353
|
-
//
|
|
354
|
-
//
|
|
355
|
-
//
|
|
356
|
-
//
|
|
357
|
-
//
|
|
358
|
-
//
|
|
359
|
-
//
|
|
360
|
-
|
|
377
|
+
// Iframe retheme is split by visibility. Only iframes in the ACTIVE tab
|
|
378
|
+
// panel paint into the view-transition snapshot, so only they sync
|
|
379
|
+
// synchronously inside the callback. Hidden panels (opacity-0,
|
|
380
|
+
// sticky-mounted) are invisible for the whole wipe — their retheme is
|
|
381
|
+
// deferred to transition.finished, where the repaint is free because
|
|
382
|
+
// nothing on screen references those layers.
|
|
383
|
+
//
|
|
384
|
+
// History, because this code has flip-flopped: retheming hidden iframes
|
|
385
|
+
// via the per-IframePreview useEffect stuttered the wipe (passive effects
|
|
386
|
+
// fire after first paint, so the repaint landed mid-animation — fixed
|
|
387
|
+
// 8c9588c by syncing everything up front). Then the Components preview
|
|
388
|
+
// grew past 120 sections and the up-front sync itself started starving
|
|
389
|
+
// the wipe's first ~400ms of frames. Deferred-until-AFTER-the-transition
|
|
390
|
+
// is the only window where a heavy retheme can't steal wipe frames.
|
|
391
|
+
// IframePreview's own effect skips hidden panels for the same reason.
|
|
392
|
+
//
|
|
393
|
+
// The deferred pass reads the host classList instead of capturing `next`,
|
|
394
|
+
// so rapid double-toggles converge every iframe on whatever theme the
|
|
395
|
+
// host settled on. Known gap: switching tabs mid-wipe can show the old
|
|
396
|
+
// theme in the incoming panel until `finished` lands (≤ ~0.4s).
|
|
397
|
+
const inInactivePanel = (f: HTMLIFrameElement) =>
|
|
398
|
+
f.closest('[data-slot="tabs-content"]')?.getAttribute("data-state") === "inactive";
|
|
399
|
+
const syncIframe = (f: HTMLIFrameElement, isDark: boolean) => {
|
|
400
|
+
try {
|
|
401
|
+
f.contentDocument?.documentElement.classList.toggle("dark", isDark);
|
|
402
|
+
} catch {}
|
|
403
|
+
};
|
|
404
|
+
const syncVisibleIframes = () => {
|
|
361
405
|
document.querySelectorAll<HTMLIFrameElement>("iframe").forEach((f) => {
|
|
362
|
-
|
|
363
|
-
f.contentDocument?.documentElement.classList.toggle("dark", next);
|
|
364
|
-
} catch {}
|
|
406
|
+
if (!inInactivePanel(f)) syncIframe(f, next);
|
|
365
407
|
});
|
|
366
408
|
};
|
|
409
|
+
const syncAllIframesToHost = () => {
|
|
410
|
+
const isDark = root.classList.contains("dark");
|
|
411
|
+
document.querySelectorAll<HTMLIFrameElement>("iframe").forEach((f) => syncIframe(f, isDark));
|
|
412
|
+
};
|
|
367
413
|
const syncHost = () => {
|
|
368
414
|
root.classList.toggle("dark", next);
|
|
369
415
|
};
|
|
370
416
|
|
|
371
417
|
if (!supports || prefersReduce) {
|
|
372
418
|
syncHost();
|
|
373
|
-
|
|
419
|
+
syncAllIframesToHost();
|
|
374
420
|
setDark(next);
|
|
375
421
|
return;
|
|
376
422
|
}
|
|
377
423
|
root.style.setProperty("--x", `${event.clientX}px`);
|
|
378
424
|
root.style.setProperty("--y", `${event.clientY}px`);
|
|
379
|
-
|
|
425
|
+
// Exact wipe radius: distance from the click to the farthest viewport
|
|
426
|
+
// corner, +3%. The old blanket 150vmax always covered, but on wide
|
|
427
|
+
// screens it overshot the needed radius by ~40%, so the eased timeline
|
|
428
|
+
// spent its whole tail growing an invisible circle — the far side of the
|
|
429
|
+
// screen swept past in ~1 frame (12ms) and read as an end-of-wipe pop.
|
|
430
|
+
// With +3%, the farthest corner is covered right where ease-in-out's
|
|
431
|
+
// deceleration flattens (~t=0.9): the far-side crossing stretches to
|
|
432
|
+
// ~3-4 frames of visible, slowing sweep, and the last ~10% of the
|
|
433
|
+
// timeline is dropped-frame insurance before teardown. Keep the buffer
|
|
434
|
+
// small — every extra % here steals deceleration from the visible sweep
|
|
435
|
+
// (1.12 was tried first: crossing stayed a 2-frame blink).
|
|
436
|
+
// (See the theme-reveal comment in build-tokens.cjs.)
|
|
437
|
+
const radius = Math.hypot(
|
|
438
|
+
Math.max(event.clientX, window.innerWidth - event.clientX),
|
|
439
|
+
Math.max(event.clientY, window.innerHeight - event.clientY)
|
|
440
|
+
);
|
|
441
|
+
root.style.setProperty("--r", `${Math.ceil(radius * 1.03)}px`);
|
|
442
|
+
const transition = (document as Document & {
|
|
443
|
+
startViewTransition: (cb: () => void) => { finished: Promise<void> };
|
|
444
|
+
}).startViewTransition(() => {
|
|
380
445
|
syncHost();
|
|
381
|
-
|
|
446
|
+
syncVisibleIframes();
|
|
382
447
|
setDark(next);
|
|
383
448
|
});
|
|
449
|
+
// `finished` rejects when a newer transition skips this one — converge
|
|
450
|
+
// either way. Two rAFs past `finished` so the overlay-teardown frame
|
|
451
|
+
// paints before the hidden-iframe recalc lands: with the exact radius the
|
|
452
|
+
// teardown now coincides with the visually complete wipe, and a blocked
|
|
453
|
+
// teardown frame would hold the last animation frame on screen.
|
|
454
|
+
const convergeAfterTeardown = () =>
|
|
455
|
+
requestAnimationFrame(() => requestAnimationFrame(syncAllIframesToHost));
|
|
456
|
+
transition.finished.then(convergeAfterTeardown, convergeAfterTeardown);
|
|
384
457
|
};
|
|
385
458
|
|
|
386
459
|
const ctx: ShellTabContext = { dark, goToTab: selectTab };
|
|
@@ -571,7 +644,7 @@ export function Shell({ tabs, defaultTab }: ShellProps) {
|
|
|
571
644
|
</TabsList>
|
|
572
645
|
</div>
|
|
573
646
|
|
|
574
|
-
<section id="main-content" tabIndex={-1} className="relative flex-1 min-h-0 w-full overflow-hidden">
|
|
647
|
+
<section id="main-content" tabIndex={-1} className="relative flex-1 min-h-0 w-full overflow-hidden scrollbar-gutter-stable">
|
|
575
648
|
<div className="absolute inset-x-4 top-1 bottom-4 isolate overflow-hidden rounded-lg">
|
|
576
649
|
<TabsPanels>
|
|
577
650
|
{tabs.map((tab) => {
|
|
@@ -35,6 +35,7 @@ import {
|
|
|
35
35
|
readMigrated,
|
|
36
36
|
clearAllCustomization,
|
|
37
37
|
} from "@behavioral-agentic-design-system/core/lib/storage";
|
|
38
|
+
import { brand, type BrandDefaults } from "@/brand.config";
|
|
38
39
|
|
|
39
40
|
const STORAGE_KEYS = {
|
|
40
41
|
primaryColor: storageKey("primaryColor"),
|
|
@@ -83,10 +84,22 @@ type Snapshot = {
|
|
|
83
84
|
typeScale: TypeScale | null;
|
|
84
85
|
};
|
|
85
86
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
/**
|
|
88
|
+
* A fork's real shipped defaults (from brand.config → `defaults`) take priority
|
|
89
|
+
* over BADS' generic baseline. Without this, a fork whose bootstrapped theme
|
|
90
|
+
* differs from hyperlegible/georgia/jetbrains/blue/18·1.125 shows a permanent,
|
|
91
|
+
* un-clearable phantom diff count from first load — the counter compares live
|
|
92
|
+
* state against a baseline the fork never actually ships. `brand.defaults` is
|
|
93
|
+
* null on upstream BADS (its shipped defaults ARE these values), so this is a
|
|
94
|
+
* no-op here and only activates for forks that declare their own defaults.
|
|
95
|
+
*/
|
|
96
|
+
const FORK_DEFAULTS: BrandDefaults = brand.defaults ?? {};
|
|
97
|
+
const SANS_DEFAULT: SansFontKey = (FORK_DEFAULTS.sansFont as SansFontKey) ?? "hyperlegible";
|
|
98
|
+
const SERIF_DEFAULT: SerifFontKey = (FORK_DEFAULTS.serifFont as SerifFontKey) ?? "georgia";
|
|
99
|
+
const MONO_DEFAULT: MonoFontKey = (FORK_DEFAULTS.monoFont as MonoFontKey) ?? "jetbrains";
|
|
100
|
+
const PRIMARY_DEFAULT: PrimaryColorKey = (FORK_DEFAULTS.primaryColor as PrimaryColorKey) ?? "blue";
|
|
101
|
+
const TYPE_SCALE_BASE_DEFAULT = FORK_DEFAULTS.typeScale?.base ?? TYPE_SCALE_DEFAULTS.base;
|
|
102
|
+
const TYPE_SCALE_RATIO_DEFAULT = FORK_DEFAULTS.typeScale?.ratio ?? TYPE_SCALE_DEFAULTS.ratio;
|
|
90
103
|
|
|
91
104
|
function readSnapshot(): Snapshot {
|
|
92
105
|
if (typeof window === "undefined") {
|
|
@@ -147,8 +160,8 @@ function diffCount(s: Snapshot, saved: Snapshot | null): number {
|
|
|
147
160
|
if (s.serifFont && differs(s.serifFont, saved?.serifFont, SERIF_DEFAULT)) count++;
|
|
148
161
|
if (s.monoFont && differs(s.monoFont, saved?.monoFont, MONO_DEFAULT)) count++;
|
|
149
162
|
if (s.typeScale) {
|
|
150
|
-
const baseTarget = saved?.typeScale?.base ??
|
|
151
|
-
const ratioTarget = saved?.typeScale?.ratio ??
|
|
163
|
+
const baseTarget = saved?.typeScale?.base ?? TYPE_SCALE_BASE_DEFAULT;
|
|
164
|
+
const ratioTarget = saved?.typeScale?.ratio ?? TYPE_SCALE_RATIO_DEFAULT;
|
|
152
165
|
if (s.typeScale.base !== baseTarget) count++;
|
|
153
166
|
if (s.typeScale.ratio !== ratioTarget) count++;
|
|
154
167
|
}
|
|
@@ -192,11 +192,11 @@ export function DocsTab() {
|
|
|
192
192
|
};
|
|
193
193
|
|
|
194
194
|
return (
|
|
195
|
-
<div data-slot="docs-tab" className="size-full flex gap-0">
|
|
195
|
+
<div data-slot="docs-tab" className="size-full flex min-h-0 gap-0">
|
|
196
196
|
{/* Sidebar — collapsible groups, doc rows, search affordance. */}
|
|
197
197
|
<aside
|
|
198
198
|
data-slot="docs-sidebar"
|
|
199
|
-
className="hidden w-72 shrink-0 flex-col border-r border-border bg-card md:flex"
|
|
199
|
+
className="hidden h-full min-h-0 w-72 shrink-0 flex-col border-r border-border bg-card md:flex"
|
|
200
200
|
aria-label="Documentation index"
|
|
201
201
|
>
|
|
202
202
|
<div className="flex shrink-0 items-center justify-between gap-2 border-b border-border px-4 py-3">
|
|
@@ -228,7 +228,7 @@ export function DocsTab() {
|
|
|
228
228
|
className="h-9 text-sm"
|
|
229
229
|
/>
|
|
230
230
|
</div>
|
|
231
|
-
<nav className="min-h-0 flex-1 overflow-y-auto px-2 py-3" aria-label="Documentation groups">
|
|
231
|
+
<nav className="min-h-0 flex-1 overflow-y-auto overscroll-contain [-webkit-overflow-scrolling:touch] px-2 py-3" aria-label="Documentation groups">
|
|
232
232
|
{sidebarGroups.length === 0 ? (
|
|
233
233
|
<p className="px-2 py-4 text-xs text-muted-foreground">
|
|
234
234
|
No docs match this filter.
|
|
@@ -247,32 +247,44 @@ export function DocsTab() {
|
|
|
247
247
|
</aside>
|
|
248
248
|
|
|
249
249
|
{/* Reading pane (and mobile top-bar with Browse) */}
|
|
250
|
+
{/* Grid (not flex) column: `minmax(0,1fr)` on the body row is the reliable
|
|
251
|
+
cross-browser "header + scrolling body" pattern. Safari treats a flex
|
|
252
|
+
item's stretched height as indefinite and lets a `flex-1 overflow-auto`
|
|
253
|
+
child grow to its content instead of scrolling ("scrolls a little but
|
|
254
|
+
not all the way"); a grid `minmax(0,1fr)` track bounds the body to the
|
|
255
|
+
remaining space so it scrolls. Row 1 (auto) holds the header group; the
|
|
256
|
+
mobile bar collapses to nothing on desktop, so the scroller always sits
|
|
257
|
+
in row 2. gridTemplateRows is inline to sidestep any Tailwind
|
|
258
|
+
arbitrary-value comma issue. */}
|
|
250
259
|
<main
|
|
251
260
|
data-slot="docs-reading-pane"
|
|
252
|
-
className="
|
|
261
|
+
className="grid h-full min-h-0 min-w-0 flex-1 bg-background"
|
|
262
|
+
style={{ gridTemplateRows: "auto minmax(0, 1fr)" }}
|
|
253
263
|
aria-label="Documentation reader"
|
|
254
264
|
>
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
<
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
265
|
+
<div className="min-w-0">
|
|
266
|
+
{/* Mobile-only top bar with the Browse affordance. */}
|
|
267
|
+
<div className="flex shrink-0 items-center gap-2 border-b border-border bg-card px-4 py-3 md:hidden">
|
|
268
|
+
<BookOpen className="size-4 text-primary" strokeWidth={1.5} />
|
|
269
|
+
<span className="text-sm font-semibold">Docs</span>
|
|
270
|
+
<Badge variant="secondary" className="ml-1">
|
|
271
|
+
{DOCS_TOTAL}
|
|
272
|
+
</Badge>
|
|
273
|
+
<Button
|
|
274
|
+
variant="outline"
|
|
275
|
+
size="sm"
|
|
276
|
+
className="ml-auto h-9 gap-2 px-3"
|
|
277
|
+
onClick={() => setPaletteOpen(true)}
|
|
278
|
+
aria-label="Open docs search"
|
|
279
|
+
>
|
|
280
|
+
<Search className="size-3.5" strokeWidth={1.5} />
|
|
281
|
+
<span className="text-sm">Browse</span>
|
|
282
|
+
</Button>
|
|
283
|
+
</div>
|
|
273
284
|
|
|
274
|
-
|
|
275
|
-
|
|
285
|
+
<ReadingHeader activeEntry={activeEntry} activePath={activePath} />
|
|
286
|
+
</div>
|
|
287
|
+
<div className="min-h-0 overflow-y-auto overscroll-contain [-webkit-overflow-scrolling:touch] px-6 py-8 lg:px-10">
|
|
276
288
|
{loading ? (
|
|
277
289
|
<div className="flex items-center gap-2 text-sm text-muted-foreground">
|
|
278
290
|
<Loader2 className="size-4 animate-spin" strokeWidth={1.5} />
|
|
@@ -143,6 +143,12 @@ export function LayersTab() {
|
|
|
143
143
|
// null = loading; [] = loaded-but-empty. Only used by the synthetic
|
|
144
144
|
// semantic-tokens view.
|
|
145
145
|
const [semanticTokens, setSemanticTokens] = useState<SemanticToken[] | null>(null);
|
|
146
|
+
// Content-fetch lifecycle for the reading pane. Without this the pane
|
|
147
|
+
// rendered a SILENT BLANK on a slow/failed `/api/layers/file` fetch (the
|
|
148
|
+
// symptom Sir hit on a just-deployed Vercel function before its doc files
|
|
149
|
+
// were traced in). "loading" shows a spinner; "error" shows a retry.
|
|
150
|
+
const [fileStatus, setFileStatus] = useState<"idle" | "loading" | "error">("idle");
|
|
151
|
+
const [reloadKey, setReloadKey] = useState(0);
|
|
146
152
|
|
|
147
153
|
// Load tree
|
|
148
154
|
useEffect(() => {
|
|
@@ -162,6 +168,7 @@ export function LayersTab() {
|
|
|
162
168
|
if (!activePath) return;
|
|
163
169
|
setStatus("idle");
|
|
164
170
|
setStatusMessage("");
|
|
171
|
+
setFileStatus("idle");
|
|
165
172
|
|
|
166
173
|
// Markdown files default to the rendered preview so they're never blank.
|
|
167
174
|
if (isMarkdown(activePath)) {
|
|
@@ -197,18 +204,27 @@ export function LayersTab() {
|
|
|
197
204
|
}
|
|
198
205
|
|
|
199
206
|
setFileType(getFileType(activePath));
|
|
207
|
+
setFileStatus("loading");
|
|
200
208
|
fetch(`/api/layers/file?path=${encodeURIComponent(activePath)}`)
|
|
201
|
-
.then((r) =>
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
209
|
+
.then(async (r) => {
|
|
210
|
+
const data = await r.json().catch(() => ({}));
|
|
211
|
+
// The API returns { error } with a non-2xx status for not-found /
|
|
212
|
+
// invalid paths; treat a missing string body as a failure too, so a
|
|
213
|
+
// transient 404 surfaces as an error state instead of a blank pane.
|
|
214
|
+
if (!r.ok || typeof data.content !== "string") {
|
|
215
|
+
throw new Error(data.error ?? "Failed to load");
|
|
216
|
+
}
|
|
217
|
+
setContent(data.content);
|
|
218
|
+
setOriginalContent(data.content);
|
|
205
219
|
setCommitMessage(`docs: edit ${activePath}`);
|
|
220
|
+
setFileStatus("idle");
|
|
206
221
|
})
|
|
207
222
|
.catch(() => {
|
|
208
223
|
setContent("");
|
|
209
224
|
setOriginalContent("");
|
|
225
|
+
setFileStatus("error");
|
|
210
226
|
});
|
|
211
|
-
}, [activePath]);
|
|
227
|
+
}, [activePath, reloadKey]);
|
|
212
228
|
|
|
213
229
|
const dirty = content !== originalContent;
|
|
214
230
|
|
|
@@ -424,6 +440,22 @@ export function LayersTab() {
|
|
|
424
440
|
|
|
425
441
|
{activePath === SEMANTIC_VIEW ? (
|
|
426
442
|
<SemanticTokensView tokens={semanticTokens} />
|
|
443
|
+
) : fileStatus === "loading" ? (
|
|
444
|
+
<div className="flex-1 flex items-center justify-center text-muted-foreground">
|
|
445
|
+
<Loader2 className="h-4 w-4 animate-spin" strokeWidth={1.5} />
|
|
446
|
+
<span className="ml-2 text-sm">Loading…</span>
|
|
447
|
+
</div>
|
|
448
|
+
) : fileStatus === "error" ? (
|
|
449
|
+
<div className="flex-1 flex items-center justify-center px-6">
|
|
450
|
+
<div className="text-center">
|
|
451
|
+
<AlertCircle className="h-8 w-8 mx-auto mb-3 text-muted-foreground" strokeWidth={1.5} />
|
|
452
|
+
<p className="text-sm text-foreground mb-1">Couldn't load this document.</p>
|
|
453
|
+
<p className="text-xs text-muted-foreground font-mono mb-4 break-all">{activePath}</p>
|
|
454
|
+
<Button variant="outline" size="sm" onClick={() => setReloadKey((k) => k + 1)}>
|
|
455
|
+
Retry
|
|
456
|
+
</Button>
|
|
457
|
+
</div>
|
|
458
|
+
</div>
|
|
427
459
|
) : fileType === "read-only" ? (
|
|
428
460
|
<div className="flex-1 rounded-none border-0 font-mono text-sm leading-relaxed overflow-auto bg-muted/30 p-6">
|
|
429
461
|
<pre className="whitespace-pre-wrap break-words text-foreground/80">
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
3
|
+
import { Slot } from "@radix-ui/react-slot"
|
|
4
|
+
import { Sparkles } from "lucide-react"
|
|
5
|
+
|
|
6
|
+
import { cn } from "../../lib/utils"
|
|
7
|
+
|
|
8
|
+
// AiBadge — the canonical BADS disclosure for AI-generated content. It exists
|
|
9
|
+
// so the Transparency floor's "AI-generated content is marked [AI]" rule is a
|
|
10
|
+
// real, accessible component rather than a hand-typed string: the disclosure
|
|
11
|
+
// announces itself fully to assistive tech (aria-label "AI-generated content")
|
|
12
|
+
// even when the visible text is just "AI", and it can't be typo'd out of
|
|
13
|
+
// existence. `lint:ai-label` accepts <AiBadge> as a valid disclosure token.
|
|
14
|
+
const aiBadgeVariants = cva(
|
|
15
|
+
"inline-flex w-fit shrink-0 items-center justify-center gap-1 rounded-full border font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 [&>svg]:pointer-events-none [&>svg]:shrink-0",
|
|
16
|
+
{
|
|
17
|
+
variants: {
|
|
18
|
+
variant: {
|
|
19
|
+
// Quiet by default — a disclosure should be legible, not loud, sitting
|
|
20
|
+
// beside the content it labels.
|
|
21
|
+
subtle: "border-transparent bg-muted text-muted-foreground",
|
|
22
|
+
solid: "border-transparent bg-primary text-primary-foreground",
|
|
23
|
+
outline: "border-border text-foreground",
|
|
24
|
+
},
|
|
25
|
+
size: {
|
|
26
|
+
sm: "gap-0.5 px-1.5 py-0.5 text-xs [&>svg]:size-2.5",
|
|
27
|
+
default: "px-2 py-0.5 text-xs [&>svg]:size-3",
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
defaultVariants: {
|
|
31
|
+
variant: "subtle",
|
|
32
|
+
size: "default",
|
|
33
|
+
},
|
|
34
|
+
}
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
function AiBadge({
|
|
38
|
+
className,
|
|
39
|
+
variant,
|
|
40
|
+
size,
|
|
41
|
+
showIcon = true,
|
|
42
|
+
label = "AI-generated content",
|
|
43
|
+
children,
|
|
44
|
+
asChild = false,
|
|
45
|
+
...props
|
|
46
|
+
}: React.ComponentProps<"span"> &
|
|
47
|
+
VariantProps<typeof aiBadgeVariants> & {
|
|
48
|
+
/** Render as the child element (e.g. wrap an anchor) via Radix Slot. */
|
|
49
|
+
asChild?: boolean
|
|
50
|
+
/** Show the leading AI glyph. Default true. */
|
|
51
|
+
showIcon?: boolean
|
|
52
|
+
/**
|
|
53
|
+
* The full phrase announced to assistive tech. Overrides the compact
|
|
54
|
+
* visible text so a screen reader always hears the complete disclosure,
|
|
55
|
+
* not just "AI". Default "AI-generated content".
|
|
56
|
+
*/
|
|
57
|
+
label?: string
|
|
58
|
+
}) {
|
|
59
|
+
const Comp = asChild ? Slot : "span"
|
|
60
|
+
return (
|
|
61
|
+
<Comp
|
|
62
|
+
data-slot="ai-badge"
|
|
63
|
+
data-variant={variant ?? "subtle"}
|
|
64
|
+
aria-label={label}
|
|
65
|
+
className={cn(aiBadgeVariants({ variant, size }), className)}
|
|
66
|
+
{...props}
|
|
67
|
+
>
|
|
68
|
+
{showIcon ? <Sparkles strokeWidth={1.5} aria-hidden="true" /> : null}
|
|
69
|
+
{children ?? "AI"}
|
|
70
|
+
</Comp>
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export { AiBadge, aiBadgeVariants }
|
|
@@ -36,6 +36,18 @@ const alertVariants = cva(
|
|
|
36
36
|
// destructive tokens should re-check with `pnpm wcag:audit`.
|
|
37
37
|
destructive:
|
|
38
38
|
"border-[var(--destructive)]! border-l-4 bg-destructive/5 text-destructive *:data-[slot=alert-description]:text-destructive/90 [&>svg]:text-current dark:bg-destructive/10",
|
|
39
|
+
// Semantic status variants: left-bar accent pattern (same as default)
|
|
40
|
+
// so alerts and Sonner toasts read as one system. text-foreground keeps
|
|
41
|
+
// body text at AAA contrast; icon and accent use the semantic token.
|
|
42
|
+
// bg-success/warning/info uses the new --color-* @theme inline entries
|
|
43
|
+
// so opacity modifiers compile. Non-text AAA: success 4.5:1 ≥ 3:1 ✓,
|
|
44
|
+
// warning 4.4:1 ≥ 3:1 ✓, info 4.8:1 ≥ 3:1 ✓ (wcag:audit).
|
|
45
|
+
success:
|
|
46
|
+
"border-border border-l-4 border-l-[var(--success)]! bg-success/5 text-foreground [&>svg]:text-success dark:bg-success/10",
|
|
47
|
+
warning:
|
|
48
|
+
"border-border border-l-4 border-l-[var(--warning)]! bg-warning/5 text-foreground [&>svg]:text-warning dark:bg-warning/10",
|
|
49
|
+
info:
|
|
50
|
+
"border-border border-l-4 border-l-[var(--info)]! bg-info/5 text-foreground [&>svg]:text-info dark:bg-info/10",
|
|
39
51
|
},
|
|
40
52
|
},
|
|
41
53
|
defaultVariants: {
|
|
@@ -18,6 +18,25 @@ const badgeVariants = cva(
|
|
|
18
18
|
"border-border text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground",
|
|
19
19
|
ghost: "[a&]:hover:bg-accent [a&]:hover:text-accent-foreground",
|
|
20
20
|
link: "text-primary underline-offset-4 [a&]:hover:underline",
|
|
21
|
+
// Semantic status variants (peer parity: Mantine Badge color,
|
|
22
|
+
// Chakra colorPalette, Ant Design status Tags). Same color language
|
|
23
|
+
// as Alert's status variants so badges and alerts read as one
|
|
24
|
+
// system: semantic-token border + subtle tinted background + icon in
|
|
25
|
+
// the semantic color. Text stays text-foreground — the raw
|
|
26
|
+
// success/warning/info tokens sit at ~4.4-4.8:1 in light mode, which
|
|
27
|
+
// passes the 3:1 non-text floor (border/icon) but NOT the 7:1 AAA
|
|
28
|
+
// text floor, so the label never takes the semantic color.
|
|
29
|
+
//
|
|
30
|
+
// NOTE: border color uses arbitrary `border-[var(--token)]!` — the
|
|
31
|
+
// named border-color utilities don't generate a rule in this
|
|
32
|
+
// Tailwind v4 setup (see the same note in alert.tsx) and `!` beats
|
|
33
|
+
// the base `border-transparent`.
|
|
34
|
+
success:
|
|
35
|
+
"border-[var(--success)]! bg-success/10 text-foreground [&>svg]:text-success dark:bg-success/15",
|
|
36
|
+
warning:
|
|
37
|
+
"border-[var(--warning)]! bg-warning/10 text-foreground [&>svg]:text-warning dark:bg-warning/15",
|
|
38
|
+
info:
|
|
39
|
+
"border-[var(--info)]! bg-info/10 text-foreground [&>svg]:text-info dark:bg-info/15",
|
|
21
40
|
},
|
|
22
41
|
},
|
|
23
42
|
defaultVariants: {
|