@behavioral-agentic-design-system/core 0.4.0 → 0.5.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 +2 -1
- package/scripts/build-tokens.cjs +15 -0
- package/src/app/page.tsx +9 -263
- package/src/app/shell.tsx +293 -0
- package/src/components/customize-tab.tsx +2 -2
- package/src/styles.css +25 -10
- package/src/tokens.json +19 -19
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@behavioral-agentic-design-system/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "BADS core — tokens, shadcn/ui components, and the BADS template shell (app routes, customize tab, theme hooks). Forks consume this and re-export, keeping client repos to ~30 lines of glue.",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"type": "module",
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"./components/customize/*": "./src/components/customize/*.tsx",
|
|
36
36
|
"./components/Foundations/*": "./src/components/Foundations/*.tsx",
|
|
37
37
|
"./app/page": "./src/app/page.tsx",
|
|
38
|
+
"./app/shell": "./src/app/shell.tsx",
|
|
38
39
|
"./app/layout": "./src/app/layout.tsx",
|
|
39
40
|
"./app/providers": "./src/app/providers.tsx",
|
|
40
41
|
"./app/font-ready": "./src/app/font-ready.tsx",
|
package/scripts/build-tokens.cjs
CHANGED
|
@@ -417,6 +417,21 @@ const pkgCss = `${banner}
|
|
|
417
417
|
|
|
418
418
|
@import url('https://fonts.googleapis.com/css2?family=Atkinson+Hyperlegible:wght@400;700&display=swap');
|
|
419
419
|
|
|
420
|
+
/* Tailwind v4 only generates classes it scans. The shell components, hooks,
|
|
421
|
+
* and app routes shipped in this package use plenty of Tailwind classes that
|
|
422
|
+
* the consumer's own source code never references — Button's variants,
|
|
423
|
+
* Dialog's overlay, the customize tab's grid, etc. Without these @source
|
|
424
|
+
* paths a fresh fork imports styles.css and gets unstyled components because
|
|
425
|
+
* the classes never made it into the consumer's bundle.
|
|
426
|
+
*
|
|
427
|
+
* Paths resolve relative to this file (node_modules/@.../core/src/styles.css),
|
|
428
|
+
* so they cover the package's own source files in node_modules. Consumers
|
|
429
|
+
* don't need to touch their own Tailwind content config to get this working. */
|
|
430
|
+
@source "./components/**/*.{ts,tsx}";
|
|
431
|
+
@source "./app/**/*.{ts,tsx}";
|
|
432
|
+
@source "./hooks/**/*.{ts,tsx}";
|
|
433
|
+
@source "./lib/**/*.{ts,tsx}";
|
|
434
|
+
|
|
420
435
|
@custom-variant dark (&:is(.dark *));
|
|
421
436
|
|
|
422
437
|
:root {
|
package/src/app/page.tsx
CHANGED
|
@@ -1,267 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import { LayersTab } from "@behavioral-agentic-design-system/core/components/layers-tab";
|
|
12
|
-
import { HomeTab } from "@behavioral-agentic-design-system/core/components/home-tab";
|
|
13
|
-
|
|
14
|
-
function IframePreview({ src, minWidth, dark }: { src: string; minWidth?: string; dark: boolean }) {
|
|
15
|
-
const iframeRef = useRef<HTMLIFrameElement>(null);
|
|
16
|
-
// Capture the initial src once on mount. After load, dark mode is applied via
|
|
17
|
-
// class toggle (syncDarkMode) — recomputing src on every dark change would
|
|
18
|
-
// reload the iframe and cause a flicker during the theme transition.
|
|
19
|
-
const initialSrcRef = useRef(`${src}${dark ? "?dark=1" : ""}`);
|
|
20
|
-
// Iframe is visually hidden until its document fires `load`. Otherwise the
|
|
21
|
-
// user sees a brief flash of unstyled content (HTML paints before CSS+fonts
|
|
22
|
-
// arrive). Once loaded, fade the iframe in over 250ms — the parent tab fade
|
|
23
|
-
// is also running, so cumulatively the first-click feels like a single
|
|
24
|
-
// smooth transition.
|
|
25
|
-
const [loaded, setLoaded] = useState(false);
|
|
26
|
-
|
|
27
|
-
const syncDarkMode = useCallback(() => {
|
|
28
|
-
try {
|
|
29
|
-
iframeRef.current?.contentDocument?.documentElement.classList.toggle("dark", dark);
|
|
30
|
-
} catch {}
|
|
31
|
-
}, [dark]);
|
|
32
|
-
|
|
33
|
-
useEffect(() => {
|
|
34
|
-
syncDarkMode();
|
|
35
|
-
}, [syncDarkMode]);
|
|
36
|
-
|
|
37
|
-
return (
|
|
38
|
-
<div className="size-full relative">
|
|
39
|
-
<ScrollArea className="size-full">
|
|
40
|
-
<div style={{ minWidth: minWidth || "100%" }} className="h-full">
|
|
41
|
-
<iframe
|
|
42
|
-
ref={iframeRef}
|
|
43
|
-
src={initialSrcRef.current}
|
|
44
|
-
onLoad={() => {
|
|
45
|
-
syncDarkMode();
|
|
46
|
-
setLoaded(true);
|
|
47
|
-
}}
|
|
48
|
-
className="w-full border-0 transition-opacity duration-300 ease-out"
|
|
49
|
-
style={{
|
|
50
|
-
height: "100vh",
|
|
51
|
-
minHeight: "800px",
|
|
52
|
-
opacity: loaded ? 1 : 0,
|
|
53
|
-
}}
|
|
54
|
-
/>
|
|
55
|
-
</div>
|
|
56
|
-
{minWidth && <ScrollBar orientation="horizontal" />}
|
|
57
|
-
</ScrollArea>
|
|
58
|
-
</div>
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const tabs = [
|
|
63
|
-
{ value: "home", label: "Home" },
|
|
64
|
-
{ value: "components", label: "Components" },
|
|
65
|
-
{ value: "cards", label: "Cards" },
|
|
66
|
-
{ value: "dashboard", label: "Dashboard", hidden: "md" },
|
|
67
|
-
{ value: "mail", label: "Mail", hidden: "md" },
|
|
68
|
-
{ value: "pricing", label: "Pricing" },
|
|
69
|
-
{ value: "layers", label: "Layers" },
|
|
70
|
-
{ value: "colors", label: "Customize" },
|
|
71
|
-
];
|
|
72
|
-
|
|
3
|
+
import { Shell, DEFAULT_TABS } from "./shell";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Default Page surface for the BADS shell. Wraps Shell with the canonical tab
|
|
7
|
+
* list. Forks that want different tabs should write their own page.tsx that
|
|
8
|
+
* imports Shell from @behavioral-agentic-design-system/core/app/shell and
|
|
9
|
+
* passes a custom `tabs` array (optionally splicing into DEFAULT_TABS).
|
|
10
|
+
*/
|
|
73
11
|
export default function DesignSystemPreview() {
|
|
74
|
-
|
|
75
|
-
const [dark, setDark] = useState(false);
|
|
76
|
-
// Sticky-mount: once a tab has been viewed, keep it mounted forever so the
|
|
77
|
-
// iframe (or React tree) doesn't cold-load on every switch. TabsPanels
|
|
78
|
-
// cross-fades between mounted siblings, so subsequent switches are instant
|
|
79
|
-
// and flash-free. Only the first visit to a tab pays the load cost.
|
|
80
|
-
const [seen, setSeen] = useState<Set<string>>(() => new Set([activeTab]));
|
|
81
|
-
useEffect(() => {
|
|
82
|
-
setSeen((prev) => (prev.has(activeTab) ? prev : new Set(prev).add(activeTab)));
|
|
83
|
-
}, [activeTab]);
|
|
84
|
-
|
|
85
|
-
// Background preload: after the active tab has fully painted and idled,
|
|
86
|
-
// mount every iframe tab so they load silently while the user is reading
|
|
87
|
-
// the home tab. By the time someone clicks Components / Cards / Dashboard /
|
|
88
|
-
// Mail / Pricing, the iframe is already loaded + styled — the tab switch
|
|
89
|
-
// becomes an instant cross-fade, no FOUC, no spinner. Uses
|
|
90
|
-
// requestIdleCallback when available so we don't compete with the home
|
|
91
|
-
// tab's first paint; falls back to a 1500ms setTimeout in Safari.
|
|
92
|
-
useEffect(() => {
|
|
93
|
-
const preloadAll = () => {
|
|
94
|
-
setSeen((prev) => {
|
|
95
|
-
const next = new Set(prev);
|
|
96
|
-
["components", "cards", "dashboard", "mail", "pricing", "layers", "colors"].forEach(
|
|
97
|
-
(t) => next.add(t),
|
|
98
|
-
);
|
|
99
|
-
return next;
|
|
100
|
-
});
|
|
101
|
-
};
|
|
102
|
-
type RIC = (cb: () => void, opts?: { timeout?: number }) => number;
|
|
103
|
-
const w = window as Window & { requestIdleCallback?: RIC; cancelIdleCallback?: (id: number) => void };
|
|
104
|
-
if (w.requestIdleCallback) {
|
|
105
|
-
const id = w.requestIdleCallback(preloadAll, { timeout: 2500 });
|
|
106
|
-
return () => w.cancelIdleCallback?.(id);
|
|
107
|
-
}
|
|
108
|
-
const id = window.setTimeout(preloadAll, 1500);
|
|
109
|
-
return () => window.clearTimeout(id);
|
|
110
|
-
}, []);
|
|
111
|
-
|
|
112
|
-
useEffect(() => {
|
|
113
|
-
document.documentElement.classList.toggle("dark", dark);
|
|
114
|
-
}, [dark]);
|
|
115
|
-
|
|
116
|
-
const toggleDark = (event: React.MouseEvent) => {
|
|
117
|
-
const next = !dark;
|
|
118
|
-
const root = document.documentElement;
|
|
119
|
-
const prefersReduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
120
|
-
const supports = typeof document !== "undefined" && "startViewTransition" in document;
|
|
121
|
-
|
|
122
|
-
// Sync every iframe preview's dark class right now so its DOM matches the
|
|
123
|
-
// new theme at the same instant the parent does — otherwise the iframe lags
|
|
124
|
-
// behind React's useEffect and the transition captures stale iframe content.
|
|
125
|
-
const syncIframes = () => {
|
|
126
|
-
document.querySelectorAll("iframe").forEach((f) => {
|
|
127
|
-
try {
|
|
128
|
-
f.contentDocument?.documentElement.classList.toggle("dark", next);
|
|
129
|
-
} catch {}
|
|
130
|
-
});
|
|
131
|
-
};
|
|
132
|
-
const syncHost = () => {
|
|
133
|
-
root.classList.toggle("dark", next);
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
if (!supports || prefersReduce) {
|
|
137
|
-
syncHost();
|
|
138
|
-
syncIframes();
|
|
139
|
-
setDark(next);
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
root.style.setProperty("--x", `${event.clientX}px`);
|
|
143
|
-
root.style.setProperty("--y", `${event.clientY}px`);
|
|
144
|
-
(document as Document & { startViewTransition: (cb: () => void) => void }).startViewTransition(() => {
|
|
145
|
-
syncHost();
|
|
146
|
-
syncIframes();
|
|
147
|
-
setDark(next);
|
|
148
|
-
});
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
return (
|
|
152
|
-
<div className="min-h-screen bg-background flex flex-col">
|
|
153
|
-
<header className="border-b bg-card shrink-0">
|
|
154
|
-
<div className="flex h-14 items-center px-6">
|
|
155
|
-
<div className="flex items-center gap-2">
|
|
156
|
-
<div
|
|
157
|
-
className="h-8 w-8 rounded-lg flex items-center justify-center bg-primary"
|
|
158
|
-
>
|
|
159
|
-
<Sparkles className="h-4 w-4 text-primary-foreground" />
|
|
160
|
-
</div>
|
|
161
|
-
<span className="text-lg font-semibold">{brand.name}</span>
|
|
162
|
-
<Badge variant="outline" className="ml-2 text-xs">{brand.tagline}</Badge>
|
|
163
|
-
</div>
|
|
164
|
-
<div className="ml-auto flex items-center gap-2">
|
|
165
|
-
<Button
|
|
166
|
-
asChild
|
|
167
|
-
variant="ghost"
|
|
168
|
-
size="sm"
|
|
169
|
-
className="group h-8 gap-1.5 border border-foreground/30 hover:!bg-foreground hover:!text-background hover:border-foreground"
|
|
170
|
-
title="Open Storybook (requires `pnpm dev` or `pnpm storybook` to be running on :6006)"
|
|
171
|
-
>
|
|
172
|
-
<a href="http://localhost:6006" target="_blank" rel="noreferrer" aria-label="Open Storybook in a new tab">
|
|
173
|
-
<BookOpen className="h-4 w-4 transition-all group-hover:scale-110" strokeWidth={1.5} />
|
|
174
|
-
<span className="text-xs font-medium">Storybook</span>
|
|
175
|
-
</a>
|
|
176
|
-
</Button>
|
|
177
|
-
<Button
|
|
178
|
-
variant="ghost"
|
|
179
|
-
size="icon"
|
|
180
|
-
onClick={toggleDark}
|
|
181
|
-
className="group size-8 border border-foreground/30 hover:!bg-foreground hover:!text-background hover:border-foreground"
|
|
182
|
-
aria-label={dark ? "Switch to light mode" : "Switch to dark mode"}
|
|
183
|
-
>
|
|
184
|
-
{dark ? (
|
|
185
|
-
<Sun className="h-4 w-4 transition-all group-hover:scale-110" />
|
|
186
|
-
) : (
|
|
187
|
-
<Moon className="h-4 w-4 transition-all group-hover:scale-110" />
|
|
188
|
-
)}
|
|
189
|
-
</Button>
|
|
190
|
-
</div>
|
|
191
|
-
</div>
|
|
192
|
-
</header>
|
|
193
|
-
|
|
194
|
-
<Tabs
|
|
195
|
-
value={activeTab}
|
|
196
|
-
onValueChange={setActiveTab}
|
|
197
|
-
// Slower cross-fade between mounted panels — 260ms feels deliberate
|
|
198
|
-
// without dragging. Read by the duration utility on TabsPanels.
|
|
199
|
-
style={{ "--tabs-fade-duration": "260ms" } as React.CSSProperties}
|
|
200
|
-
className="flex-1 flex flex-col overflow-hidden"
|
|
201
|
-
>
|
|
202
|
-
<div className="mt-2 mb-1 flex w-full items-center px-4">
|
|
203
|
-
<TabsList className="bg-background text-muted-foreground inline-flex w-fit items-center justify-center rounded-full px-0">
|
|
204
|
-
{tabs.map((tab) => (
|
|
205
|
-
<TabsTrigger
|
|
206
|
-
key={tab.value}
|
|
207
|
-
value={tab.value}
|
|
208
|
-
className={`items-center justify-center rounded-full px-3 py-1.5 text-sm font-medium whitespace-nowrap transition-all data-[state=active]:bg-primary data-[state=active]:text-primary-foreground data-[state=active]:shadow-sm ${
|
|
209
|
-
tab.hidden === "md" ? "hidden md:inline-flex" : "inline-flex"
|
|
210
|
-
}`}
|
|
211
|
-
>
|
|
212
|
-
{tab.label}
|
|
213
|
-
</TabsTrigger>
|
|
214
|
-
))}
|
|
215
|
-
</TabsList>
|
|
216
|
-
</div>
|
|
217
|
-
|
|
218
|
-
<section className="relative flex-1 min-h-0 w-full overflow-hidden">
|
|
219
|
-
<div className="absolute inset-x-4 top-1 bottom-4 isolate overflow-hidden rounded-lg">
|
|
220
|
-
<TabsPanels>
|
|
221
|
-
{seen.has("home") && (
|
|
222
|
-
<TabsContent value="home" forceMount>
|
|
223
|
-
<HomeTab />
|
|
224
|
-
</TabsContent>
|
|
225
|
-
)}
|
|
226
|
-
{seen.has("components") && (
|
|
227
|
-
<TabsContent value="components" forceMount>
|
|
228
|
-
<IframePreview dark={dark} src="/preview/components" />
|
|
229
|
-
</TabsContent>
|
|
230
|
-
)}
|
|
231
|
-
{seen.has("cards") && (
|
|
232
|
-
<TabsContent value="cards" forceMount>
|
|
233
|
-
<IframePreview dark={dark} src="/preview/cards" />
|
|
234
|
-
</TabsContent>
|
|
235
|
-
)}
|
|
236
|
-
{seen.has("dashboard") && (
|
|
237
|
-
<TabsContent value="dashboard" forceMount>
|
|
238
|
-
<IframePreview dark={dark} src="/preview/dashboard" minWidth="1400px" />
|
|
239
|
-
</TabsContent>
|
|
240
|
-
)}
|
|
241
|
-
{seen.has("mail") && (
|
|
242
|
-
<TabsContent value="mail" forceMount>
|
|
243
|
-
<IframePreview dark={dark} src="/preview/mail" minWidth="1300px" />
|
|
244
|
-
</TabsContent>
|
|
245
|
-
)}
|
|
246
|
-
{seen.has("pricing") && (
|
|
247
|
-
<TabsContent value="pricing" forceMount>
|
|
248
|
-
<IframePreview dark={dark} src="/preview/pricing" />
|
|
249
|
-
</TabsContent>
|
|
250
|
-
)}
|
|
251
|
-
{seen.has("layers") && (
|
|
252
|
-
<TabsContent value="layers" forceMount>
|
|
253
|
-
<LayersTab />
|
|
254
|
-
</TabsContent>
|
|
255
|
-
)}
|
|
256
|
-
{seen.has("colors") && (
|
|
257
|
-
<TabsContent value="colors" forceMount>
|
|
258
|
-
<CustomizeTab />
|
|
259
|
-
</TabsContent>
|
|
260
|
-
)}
|
|
261
|
-
</TabsPanels>
|
|
262
|
-
</div>
|
|
263
|
-
</section>
|
|
264
|
-
</Tabs>
|
|
265
|
-
</div>
|
|
266
|
-
);
|
|
12
|
+
return <Shell tabs={DEFAULT_TABS} />;
|
|
267
13
|
}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useState, useEffect, useRef, useCallback } from "react";
|
|
4
|
+
import { Tabs, TabsContent, TabsList, TabsPanels, TabsTrigger } from "@behavioral-agentic-design-system/core/components/ui/tabs";
|
|
5
|
+
import { ScrollArea, ScrollBar } from "@behavioral-agentic-design-system/core/components/ui/scroll-area";
|
|
6
|
+
import { Badge } from "@behavioral-agentic-design-system/core/components/ui/badge";
|
|
7
|
+
import { Button } from "@behavioral-agentic-design-system/core/components/ui/button";
|
|
8
|
+
import { Sparkles, Sun, Moon, BookOpen } from "lucide-react";
|
|
9
|
+
import { brand } from "@/brand.config";
|
|
10
|
+
import { CustomizeTab } from "@behavioral-agentic-design-system/core/components/customize-tab";
|
|
11
|
+
import { LayersTab } from "@behavioral-agentic-design-system/core/components/layers-tab";
|
|
12
|
+
import { HomeTab } from "@behavioral-agentic-design-system/core/components/home-tab";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Iframe-hosted preview surface. Listens for the parent's dark-mode state and
|
|
16
|
+
* mirrors it into its own document, so cross-fading tabs that hold iframes
|
|
17
|
+
* doesn't capture stale theming. Exported because most fork-supplied tabs
|
|
18
|
+
* will want to render an iframe of their own preview routes.
|
|
19
|
+
*/
|
|
20
|
+
export function IframePreview({
|
|
21
|
+
src,
|
|
22
|
+
minWidth,
|
|
23
|
+
dark,
|
|
24
|
+
}: {
|
|
25
|
+
src: string;
|
|
26
|
+
minWidth?: string;
|
|
27
|
+
dark: boolean;
|
|
28
|
+
}) {
|
|
29
|
+
const iframeRef = useRef<HTMLIFrameElement>(null);
|
|
30
|
+
// Capture the initial src once on mount. After load, dark mode is applied via
|
|
31
|
+
// class toggle (syncDarkMode) — recomputing src on every dark change would
|
|
32
|
+
// reload the iframe and cause a flicker during the theme transition.
|
|
33
|
+
const initialSrcRef = useRef(`${src}${dark ? "?dark=1" : ""}`);
|
|
34
|
+
// Iframe is visually hidden until its document fires `load`. Otherwise the
|
|
35
|
+
// user sees a brief flash of unstyled content (HTML paints before CSS+fonts
|
|
36
|
+
// arrive). Once loaded, fade the iframe in over 250ms — the parent tab fade
|
|
37
|
+
// is also running, so cumulatively the first-click feels like a single
|
|
38
|
+
// smooth transition.
|
|
39
|
+
const [loaded, setLoaded] = useState(false);
|
|
40
|
+
|
|
41
|
+
const syncDarkMode = useCallback(() => {
|
|
42
|
+
try {
|
|
43
|
+
iframeRef.current?.contentDocument?.documentElement.classList.toggle("dark", dark);
|
|
44
|
+
} catch {}
|
|
45
|
+
}, [dark]);
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
syncDarkMode();
|
|
49
|
+
}, [syncDarkMode]);
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<div className="size-full relative">
|
|
53
|
+
<ScrollArea className="size-full">
|
|
54
|
+
<div style={{ minWidth: minWidth || "100%" }} className="h-full">
|
|
55
|
+
<iframe
|
|
56
|
+
ref={iframeRef}
|
|
57
|
+
src={initialSrcRef.current}
|
|
58
|
+
onLoad={() => {
|
|
59
|
+
syncDarkMode();
|
|
60
|
+
setLoaded(true);
|
|
61
|
+
}}
|
|
62
|
+
className="w-full border-0 transition-opacity duration-300 ease-out"
|
|
63
|
+
style={{
|
|
64
|
+
height: "100vh",
|
|
65
|
+
minHeight: "800px",
|
|
66
|
+
opacity: loaded ? 1 : 0,
|
|
67
|
+
}}
|
|
68
|
+
/>
|
|
69
|
+
</div>
|
|
70
|
+
{minWidth && <ScrollBar orientation="horizontal" />}
|
|
71
|
+
</ScrollArea>
|
|
72
|
+
</div>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Runtime context handed to each tab's render function. `dark` mirrors the
|
|
78
|
+
* Shell's host dark-mode state so iframe-hosted tabs can sync the iframe's
|
|
79
|
+
* `<html>` class without prop-drilling through the tab list.
|
|
80
|
+
*/
|
|
81
|
+
export type ShellTabContext = {
|
|
82
|
+
dark: boolean;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* One tab in the Shell. `render` is called once per first-visit and stays
|
|
87
|
+
* mounted afterwards (sticky-mount + cross-fade — see TabsPanels).
|
|
88
|
+
*
|
|
89
|
+
* `hidden: "md"` collapses the tab on screens below md breakpoint. Useful for
|
|
90
|
+
* dense iframe tabs (Dashboard, Mail) that don't read well on mobile.
|
|
91
|
+
*/
|
|
92
|
+
export type ShellTab = {
|
|
93
|
+
value: string;
|
|
94
|
+
label: string;
|
|
95
|
+
hidden?: "md";
|
|
96
|
+
render: (ctx: ShellTabContext) => React.ReactNode;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export type ShellProps = {
|
|
100
|
+
tabs: ShellTab[];
|
|
101
|
+
/** Optional initial tab value. Defaults to the first tab. */
|
|
102
|
+
defaultTab?: string;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The canonical BADS preview tabs. Forks pass these directly when they want
|
|
107
|
+
* the default shape, or compose their own list (or splice into this one) when
|
|
108
|
+
* they need custom surfaces alongside the built-ins.
|
|
109
|
+
*/
|
|
110
|
+
export const DEFAULT_TABS: ShellTab[] = [
|
|
111
|
+
{ value: "home", label: "Home", render: () => <HomeTab /> },
|
|
112
|
+
{ value: "components", label: "Components", render: ({ dark }) => <IframePreview dark={dark} src="/preview/components" /> },
|
|
113
|
+
{ value: "cards", label: "Cards", render: ({ dark }) => <IframePreview dark={dark} src="/preview/cards" /> },
|
|
114
|
+
{ value: "dashboard", label: "Dashboard", hidden: "md", render: ({ dark }) => <IframePreview dark={dark} src="/preview/dashboard" minWidth="1400px" /> },
|
|
115
|
+
{ value: "mail", label: "Mail", hidden: "md", render: ({ dark }) => <IframePreview dark={dark} src="/preview/mail" minWidth="1300px" /> },
|
|
116
|
+
{ value: "pricing", label: "Pricing", render: ({ dark }) => <IframePreview dark={dark} src="/preview/pricing" /> },
|
|
117
|
+
{ value: "layers", label: "Layers", render: () => <LayersTab /> },
|
|
118
|
+
{ value: "colors", label: "Customize", render: () => <CustomizeTab /> },
|
|
119
|
+
];
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* The BADS preview shell — header (brand + Storybook + dark toggle) plus a
|
|
123
|
+
* sticky-mount cross-fade tab bar. Pass any `tabs` array to override the
|
|
124
|
+
* default surfaces; pass `DEFAULT_TABS` to keep the canonical layout.
|
|
125
|
+
*
|
|
126
|
+
* Forks that just want the default shell don't need to import this directly —
|
|
127
|
+
* they can re-export `@behavioral-agentic-design-system/core/app/page`. Use
|
|
128
|
+
* Shell directly when you need custom tabs (e.g. Pool, Meet, Athletes for a
|
|
129
|
+
* swim-club brand).
|
|
130
|
+
*/
|
|
131
|
+
export function Shell({ tabs, defaultTab }: ShellProps) {
|
|
132
|
+
const initialTab = defaultTab ?? tabs[0]?.value ?? "home";
|
|
133
|
+
const [activeTab, setActiveTab] = useState(initialTab);
|
|
134
|
+
const [dark, setDark] = useState(false);
|
|
135
|
+
// Sticky-mount: once a tab has been viewed, keep it mounted forever so the
|
|
136
|
+
// iframe (or React tree) doesn't cold-load on every switch. TabsPanels
|
|
137
|
+
// cross-fades between mounted siblings, so subsequent switches are instant
|
|
138
|
+
// and flash-free. Only the first visit to a tab pays the load cost.
|
|
139
|
+
const [seen, setSeen] = useState<Set<string>>(() => new Set([initialTab]));
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
setSeen((prev) => (prev.has(activeTab) ? prev : new Set(prev).add(activeTab)));
|
|
142
|
+
}, [activeTab]);
|
|
143
|
+
|
|
144
|
+
// Background preload: after the active tab has fully painted and idled,
|
|
145
|
+
// mount every other tab so they load silently while the user is reading
|
|
146
|
+
// the home tab. By the time someone clicks any other tab, its iframe is
|
|
147
|
+
// already loaded + styled — the tab switch becomes an instant cross-fade,
|
|
148
|
+
// no FOUC, no spinner. Uses requestIdleCallback when available so we don't
|
|
149
|
+
// compete with the home tab's first paint; falls back to a 1500ms
|
|
150
|
+
// setTimeout in Safari.
|
|
151
|
+
useEffect(() => {
|
|
152
|
+
const preloadAll = () => {
|
|
153
|
+
setSeen((prev) => {
|
|
154
|
+
const next = new Set(prev);
|
|
155
|
+
tabs.forEach((t) => next.add(t.value));
|
|
156
|
+
return next;
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
type RIC = (cb: () => void, opts?: { timeout?: number }) => number;
|
|
160
|
+
const w = window as Window & { requestIdleCallback?: RIC; cancelIdleCallback?: (id: number) => void };
|
|
161
|
+
if (w.requestIdleCallback) {
|
|
162
|
+
const id = w.requestIdleCallback(preloadAll, { timeout: 2500 });
|
|
163
|
+
return () => w.cancelIdleCallback?.(id);
|
|
164
|
+
}
|
|
165
|
+
const id = window.setTimeout(preloadAll, 1500);
|
|
166
|
+
return () => window.clearTimeout(id);
|
|
167
|
+
}, [tabs]);
|
|
168
|
+
|
|
169
|
+
useEffect(() => {
|
|
170
|
+
document.documentElement.classList.toggle("dark", dark);
|
|
171
|
+
}, [dark]);
|
|
172
|
+
|
|
173
|
+
const toggleDark = (event: React.MouseEvent) => {
|
|
174
|
+
const next = !dark;
|
|
175
|
+
const root = document.documentElement;
|
|
176
|
+
const prefersReduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
177
|
+
const supports = typeof document !== "undefined" && "startViewTransition" in document;
|
|
178
|
+
|
|
179
|
+
// Sync every iframe preview's dark class right now so its DOM matches the
|
|
180
|
+
// new theme at the same instant the parent does — otherwise the iframe lags
|
|
181
|
+
// behind React's useEffect and the transition captures stale iframe content.
|
|
182
|
+
const syncIframes = () => {
|
|
183
|
+
document.querySelectorAll("iframe").forEach((f) => {
|
|
184
|
+
try {
|
|
185
|
+
f.contentDocument?.documentElement.classList.toggle("dark", next);
|
|
186
|
+
} catch {}
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
const syncHost = () => {
|
|
190
|
+
root.classList.toggle("dark", next);
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
if (!supports || prefersReduce) {
|
|
194
|
+
syncHost();
|
|
195
|
+
syncIframes();
|
|
196
|
+
setDark(next);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
root.style.setProperty("--x", `${event.clientX}px`);
|
|
200
|
+
root.style.setProperty("--y", `${event.clientY}px`);
|
|
201
|
+
(document as Document & { startViewTransition: (cb: () => void) => void }).startViewTransition(() => {
|
|
202
|
+
syncHost();
|
|
203
|
+
syncIframes();
|
|
204
|
+
setDark(next);
|
|
205
|
+
});
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
const ctx: ShellTabContext = { dark };
|
|
209
|
+
|
|
210
|
+
return (
|
|
211
|
+
<div className="min-h-screen bg-background flex flex-col">
|
|
212
|
+
<header className="border-b bg-card shrink-0">
|
|
213
|
+
<div className="flex h-14 items-center px-6">
|
|
214
|
+
<div className="flex items-center gap-2">
|
|
215
|
+
<div
|
|
216
|
+
className="h-8 w-8 rounded-lg flex items-center justify-center bg-primary"
|
|
217
|
+
>
|
|
218
|
+
<Sparkles className="h-4 w-4 text-primary-foreground" />
|
|
219
|
+
</div>
|
|
220
|
+
<span className="text-lg font-semibold">{brand.name}</span>
|
|
221
|
+
<Badge variant="outline" className="ml-2 text-xs">{brand.tagline}</Badge>
|
|
222
|
+
</div>
|
|
223
|
+
<div className="ml-auto flex items-center gap-2">
|
|
224
|
+
<Button
|
|
225
|
+
asChild
|
|
226
|
+
variant="ghost"
|
|
227
|
+
size="sm"
|
|
228
|
+
className="group h-8 gap-1.5 border border-foreground/30 hover:!bg-foreground hover:!text-background hover:border-foreground"
|
|
229
|
+
title="Open Storybook (requires `pnpm dev` or `pnpm storybook` to be running on :6006)"
|
|
230
|
+
>
|
|
231
|
+
<a href="http://localhost:6006" target="_blank" rel="noreferrer" aria-label="Open Storybook in a new tab">
|
|
232
|
+
<BookOpen className="h-4 w-4 transition-all group-hover:scale-110" strokeWidth={1.5} />
|
|
233
|
+
<span className="text-xs font-medium">Storybook</span>
|
|
234
|
+
</a>
|
|
235
|
+
</Button>
|
|
236
|
+
<Button
|
|
237
|
+
variant="ghost"
|
|
238
|
+
size="icon"
|
|
239
|
+
onClick={toggleDark}
|
|
240
|
+
className="group size-8 border border-foreground/30 hover:!bg-foreground hover:!text-background hover:border-foreground"
|
|
241
|
+
aria-label={dark ? "Switch to light mode" : "Switch to dark mode"}
|
|
242
|
+
>
|
|
243
|
+
{dark ? (
|
|
244
|
+
<Sun className="h-4 w-4 transition-all group-hover:scale-110" />
|
|
245
|
+
) : (
|
|
246
|
+
<Moon className="h-4 w-4 transition-all group-hover:scale-110" />
|
|
247
|
+
)}
|
|
248
|
+
</Button>
|
|
249
|
+
</div>
|
|
250
|
+
</div>
|
|
251
|
+
</header>
|
|
252
|
+
|
|
253
|
+
<Tabs
|
|
254
|
+
value={activeTab}
|
|
255
|
+
onValueChange={setActiveTab}
|
|
256
|
+
// Slower cross-fade between mounted panels — 260ms feels deliberate
|
|
257
|
+
// without dragging. Read by the duration utility on TabsPanels.
|
|
258
|
+
style={{ "--tabs-fade-duration": "260ms" } as React.CSSProperties}
|
|
259
|
+
className="flex-1 flex flex-col overflow-hidden"
|
|
260
|
+
>
|
|
261
|
+
<div className="mt-2 mb-1 flex w-full items-center px-4">
|
|
262
|
+
<TabsList className="bg-background text-muted-foreground inline-flex w-fit items-center justify-center rounded-full px-0">
|
|
263
|
+
{tabs.map((tab) => (
|
|
264
|
+
<TabsTrigger
|
|
265
|
+
key={tab.value}
|
|
266
|
+
value={tab.value}
|
|
267
|
+
className={`items-center justify-center rounded-full px-3 py-1.5 text-sm font-medium whitespace-nowrap transition-all data-[state=active]:bg-primary data-[state=active]:text-primary-foreground data-[state=active]:shadow-sm ${
|
|
268
|
+
tab.hidden === "md" ? "hidden md:inline-flex" : "inline-flex"
|
|
269
|
+
}`}
|
|
270
|
+
>
|
|
271
|
+
{tab.label}
|
|
272
|
+
</TabsTrigger>
|
|
273
|
+
))}
|
|
274
|
+
</TabsList>
|
|
275
|
+
</div>
|
|
276
|
+
|
|
277
|
+
<section className="relative flex-1 min-h-0 w-full overflow-hidden">
|
|
278
|
+
<div className="absolute inset-x-4 top-1 bottom-4 isolate overflow-hidden rounded-lg">
|
|
279
|
+
<TabsPanels>
|
|
280
|
+
{tabs.map((tab) =>
|
|
281
|
+
seen.has(tab.value) ? (
|
|
282
|
+
<TabsContent key={tab.value} value={tab.value} forceMount>
|
|
283
|
+
{tab.render(ctx)}
|
|
284
|
+
</TabsContent>
|
|
285
|
+
) : null,
|
|
286
|
+
)}
|
|
287
|
+
</TabsPanels>
|
|
288
|
+
</div>
|
|
289
|
+
</section>
|
|
290
|
+
</Tabs>
|
|
291
|
+
</div>
|
|
292
|
+
);
|
|
293
|
+
}
|
|
@@ -466,8 +466,8 @@ function ColorPalette() {
|
|
|
466
466
|
</ColorSection>
|
|
467
467
|
|
|
468
468
|
<ColorSection title="Charts">
|
|
469
|
-
<ColorSwatch name="Chart 1" className="bg-chart-1" textClassName="text-
|
|
470
|
-
<ColorSwatch name="Chart 2" className="bg-chart-2" textClassName="text-
|
|
469
|
+
<ColorSwatch name="Chart 1" className="bg-chart-1" textClassName="text-white" variable="--chart-1" />
|
|
470
|
+
<ColorSwatch name="Chart 2" className="bg-chart-2" textClassName="text-white" variable="--chart-2" />
|
|
471
471
|
<ColorSwatch name="Chart 3" className="bg-chart-3" textClassName="text-white" variable="--chart-3" />
|
|
472
472
|
<ColorSwatch name="Chart 4" className="bg-chart-4" textClassName="text-white" variable="--chart-4" />
|
|
473
473
|
<ColorSwatch name="Chart 5" className="bg-chart-5" textClassName="text-white" variable="--chart-5" />
|
package/src/styles.css
CHANGED
|
@@ -14,6 +14,21 @@
|
|
|
14
14
|
|
|
15
15
|
@import url('https://fonts.googleapis.com/css2?family=Atkinson+Hyperlegible:wght@400;700&display=swap');
|
|
16
16
|
|
|
17
|
+
/* Tailwind v4 only generates classes it scans. The shell components, hooks,
|
|
18
|
+
* and app routes shipped in this package use plenty of Tailwind classes that
|
|
19
|
+
* the consumer's own source code never references — Button's variants,
|
|
20
|
+
* Dialog's overlay, the customize tab's grid, etc. Without these @source
|
|
21
|
+
* paths a fresh fork imports styles.css and gets unstyled components because
|
|
22
|
+
* the classes never made it into the consumer's bundle.
|
|
23
|
+
*
|
|
24
|
+
* Paths resolve relative to this file (node_modules/@.../core/src/styles.css),
|
|
25
|
+
* so they cover the package's own source files in node_modules. Consumers
|
|
26
|
+
* don't need to touch their own Tailwind content config to get this working. */
|
|
27
|
+
@source "./components/**/*.{ts,tsx}";
|
|
28
|
+
@source "./app/**/*.{ts,tsx}";
|
|
29
|
+
@source "./hooks/**/*.{ts,tsx}";
|
|
30
|
+
@source "./lib/**/*.{ts,tsx}";
|
|
31
|
+
|
|
17
32
|
@custom-variant dark (&:is(.dark *));
|
|
18
33
|
|
|
19
34
|
:root {
|
|
@@ -44,11 +59,11 @@
|
|
|
44
59
|
--border: oklch(0.6100 0 0);
|
|
45
60
|
--input: oklch(0.6100 0 0);
|
|
46
61
|
--ring: oklch(0.4500 0 0);
|
|
47
|
-
--chart-1: oklch(0.
|
|
48
|
-
--chart-2: oklch(0.
|
|
49
|
-
--chart-3: oklch(0.
|
|
50
|
-
--chart-4: oklch(0.
|
|
51
|
-
--chart-5: oklch(0.
|
|
62
|
+
--chart-1: oklch(0.6200 0.2000 220);
|
|
63
|
+
--chart-2: oklch(0.6200 0.2200 145);
|
|
64
|
+
--chart-3: oklch(0.6500 0.1800 88);
|
|
65
|
+
--chart-4: oklch(0.6000 0.2600 340);
|
|
66
|
+
--chart-5: oklch(0.6200 0.2200 25);
|
|
52
67
|
--sidebar: oklch(0.9850 0 0);
|
|
53
68
|
--sidebar-foreground: oklch(0.1450 0 0);
|
|
54
69
|
--sidebar-primary: oklch(0.2050 0 0);
|
|
@@ -119,11 +134,11 @@
|
|
|
119
134
|
--border: oklch(0.5500 0 0);
|
|
120
135
|
--input: oklch(0.5500 0 0);
|
|
121
136
|
--ring: oklch(0.7000 0 0);
|
|
122
|
-
--chart-1: oklch(0.7800 0.
|
|
123
|
-
--chart-2: oklch(0.
|
|
124
|
-
--chart-3: oklch(0.
|
|
125
|
-
--chart-4: oklch(0.
|
|
126
|
-
--chart-5: oklch(0.
|
|
137
|
+
--chart-1: oklch(0.7800 0.1800 220);
|
|
138
|
+
--chart-2: oklch(0.8000 0.2000 145);
|
|
139
|
+
--chart-3: oklch(0.8500 0.1700 90);
|
|
140
|
+
--chart-4: oklch(0.7600 0.2200 340);
|
|
141
|
+
--chart-5: oklch(0.7800 0.1800 25);
|
|
127
142
|
--sidebar: oklch(0.2050 0 0);
|
|
128
143
|
--sidebar-foreground: oklch(0.9850 0 0);
|
|
129
144
|
--sidebar-primary: oklch(0.4200 0.2000 264.3760);
|
package/src/tokens.json
CHANGED
|
@@ -814,29 +814,29 @@
|
|
|
814
814
|
"$description": "Focus ring base. AAA non-text + 2.4.13: ≥3:1 on every surface. Tracks --primary when brand color changes (luminance-clamped to keep 3:1)."
|
|
815
815
|
},
|
|
816
816
|
"chart-1": {
|
|
817
|
-
"$value": "oklch(0.
|
|
817
|
+
"$value": "oklch(0.6200 0.2000 220)",
|
|
818
818
|
"$type": "color",
|
|
819
|
-
"$description": "Tuned for AAA 3:1 on white card.
|
|
819
|
+
"$description": "Tuned for AAA 3:1 on white card. Electric cyan-blue."
|
|
820
820
|
},
|
|
821
821
|
"chart-2": {
|
|
822
|
-
"$value": "oklch(0.
|
|
822
|
+
"$value": "oklch(0.6200 0.2200 145)",
|
|
823
823
|
"$type": "color",
|
|
824
|
-
"$description": "Tuned for AAA 3:1 on white card.
|
|
824
|
+
"$description": "Tuned for AAA 3:1 on white card. Spring green."
|
|
825
825
|
},
|
|
826
826
|
"chart-3": {
|
|
827
|
-
"$value": "oklch(0.
|
|
827
|
+
"$value": "oklch(0.6500 0.1800 88)",
|
|
828
828
|
"$type": "color",
|
|
829
|
-
"$description": "Tuned for AAA 3:1 on white card.
|
|
829
|
+
"$description": "Tuned for AAA 3:1 on white card. Bright gold."
|
|
830
830
|
},
|
|
831
831
|
"chart-4": {
|
|
832
|
-
"$value": "oklch(0.
|
|
832
|
+
"$value": "oklch(0.6000 0.2600 340)",
|
|
833
833
|
"$type": "color",
|
|
834
|
-
"$description": "Tuned for AAA 3:1 on white card.
|
|
834
|
+
"$description": "Tuned for AAA 3:1 on white card. Hot fuchsia."
|
|
835
835
|
},
|
|
836
836
|
"chart-5": {
|
|
837
|
-
"$value": "oklch(0.
|
|
837
|
+
"$value": "oklch(0.6200 0.2200 25)",
|
|
838
838
|
"$type": "color",
|
|
839
|
-
"$description": "Tuned for AAA 3:1 on white card.
|
|
839
|
+
"$description": "Tuned for AAA 3:1 on white card. Coral."
|
|
840
840
|
},
|
|
841
841
|
"sidebar": {
|
|
842
842
|
"$value": "oklch(0.9850 0 0)",
|
|
@@ -1007,29 +1007,29 @@
|
|
|
1007
1007
|
"$description": "Focus ring base, dark mode. AAA non-text 3:1 on dark."
|
|
1008
1008
|
},
|
|
1009
1009
|
"chart-1": {
|
|
1010
|
-
"$value": "oklch(0.7800 0.
|
|
1010
|
+
"$value": "oklch(0.7800 0.1800 220)",
|
|
1011
1011
|
"$type": "color",
|
|
1012
1012
|
"$description": "Tuned for AAA 3:1 on dark card. Bright cyan-blue."
|
|
1013
1013
|
},
|
|
1014
1014
|
"chart-2": {
|
|
1015
|
-
"$value": "oklch(0.
|
|
1015
|
+
"$value": "oklch(0.8000 0.2000 145)",
|
|
1016
1016
|
"$type": "color",
|
|
1017
|
-
"$description": "Tuned for AAA 3:1 on dark card. Bright green."
|
|
1017
|
+
"$description": "Tuned for AAA 3:1 on dark card. Bright spring green."
|
|
1018
1018
|
},
|
|
1019
1019
|
"chart-3": {
|
|
1020
|
-
"$value": "oklch(0.
|
|
1020
|
+
"$value": "oklch(0.8500 0.1700 90)",
|
|
1021
1021
|
"$type": "color",
|
|
1022
|
-
"$description": "Tuned for AAA 3:1 on dark card.
|
|
1022
|
+
"$description": "Tuned for AAA 3:1 on dark card. Bright gold."
|
|
1023
1023
|
},
|
|
1024
1024
|
"chart-4": {
|
|
1025
|
-
"$value": "oklch(0.
|
|
1025
|
+
"$value": "oklch(0.7600 0.2200 340)",
|
|
1026
1026
|
"$type": "color",
|
|
1027
|
-
"$description": "Tuned for AAA 3:1 on dark card.
|
|
1027
|
+
"$description": "Tuned for AAA 3:1 on dark card. Bright fuchsia."
|
|
1028
1028
|
},
|
|
1029
1029
|
"chart-5": {
|
|
1030
|
-
"$value": "oklch(0.
|
|
1030
|
+
"$value": "oklch(0.7800 0.1800 25)",
|
|
1031
1031
|
"$type": "color",
|
|
1032
|
-
"$description": "Tuned for AAA 3:1 on dark card.
|
|
1032
|
+
"$description": "Tuned for AAA 3:1 on dark card. Bright coral."
|
|
1033
1033
|
},
|
|
1034
1034
|
"sidebar": {
|
|
1035
1035
|
"$value": "oklch(0.2050 0 0)",
|