@behavioral-agentic-design-system/core 0.4.0 → 0.6.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 +16 -8
- package/scripts/build-fonts.cjs +90 -0
- package/scripts/build-tokens.cjs +99 -8
- package/src/api/brand-fonts.ts +280 -0
- package/src/api/brand-mark.ts +146 -0
- package/src/api/layers/file.ts +4 -2
- package/src/api/layers.ts +23 -1
- package/src/app/font-ready.tsx +1 -1
- package/src/app/layout.tsx +3 -9
- package/src/app/page.tsx +9 -263
- package/src/app/preview/cards/page.tsx +1 -1
- package/src/app/preview/login/page.tsx +5 -0
- package/src/app/shell.tsx +354 -0
- package/src/components/admin-menu.stories.tsx +68 -0
- package/src/components/admin-menu.tsx +59 -0
- package/src/components/brand-mark.tsx +64 -0
- package/src/components/customize/brand-mark-section.tsx +265 -0
- package/src/components/customize/font-pickers.tsx +293 -0
- package/src/components/customize/save-bar.tsx +11 -5
- package/src/components/customize-tab.tsx +331 -26
- package/src/components/dev-identity-badge.tsx +92 -0
- package/src/components/home-tab.tsx +1022 -374
- package/src/components/layers-tab.tsx +38 -9
- package/src/components/ui/alert.tsx +10 -2
- package/src/components/ui/button.tsx +1 -1
- package/src/components/ui/calendar.tsx +1 -1
- package/src/components/ui/chart.tsx +13 -3
- package/src/components/ui/checkbox.tsx +1 -1
- package/src/components/ui/radio-group.tsx +1 -1
- package/src/components/ui/sidebar.tsx +6 -1
- package/src/components/ui/sonner.tsx +18 -0
- package/src/components/ui/switch.tsx +7 -1
- package/src/components/ui/tabs.tsx +1 -1
- package/src/hooks/use-global-brand-mark.ts +64 -0
- package/src/hooks/use-global-mono-font.ts +13 -3
- package/src/hooks/use-global-primary-color.ts +145 -8
- package/src/hooks/use-global-sans-font.ts +5 -3
- package/src/hooks/use-global-serif-font.ts +14 -4
- package/src/lib/storage.ts +31 -2
- package/src/lib/svg-sanitize.ts +272 -0
- package/src/styles.css +91 -46
- package/src/tokens.default.json +4 -4
- package/src/tokens.json +172 -78
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useState, useEffect, useRef, useCallback, createContext, useContext, useMemo } from "react";
|
|
4
|
+
import { Tabs, TabsContent, TabsList, TabsPanels, TabsTrigger } from "@behavioral-agentic-design-system/core/components/ui/tabs";
|
|
5
|
+
import { Badge } from "@behavioral-agentic-design-system/core/components/ui/badge";
|
|
6
|
+
import { Button } from "@behavioral-agentic-design-system/core/components/ui/button";
|
|
7
|
+
import { Sun, Moon, BookOpen } from "lucide-react";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Inline GitHub mark. Lucide dropped brand icons (Github / Twitter / etc.) in
|
|
11
|
+
* recent versions, so embedding the SVG directly insulates us from future
|
|
12
|
+
* lucide changes and keeps the header link rendering as the universally-
|
|
13
|
+
* recognized octocat. Uses currentColor so the icon inherits the surrounding
|
|
14
|
+
* Button's text color (including the hover-inverted state).
|
|
15
|
+
*/
|
|
16
|
+
function GithubMark({ className }: { className?: string }) {
|
|
17
|
+
return (
|
|
18
|
+
<svg
|
|
19
|
+
viewBox="0 0 24 24"
|
|
20
|
+
fill="currentColor"
|
|
21
|
+
aria-hidden="true"
|
|
22
|
+
className={className}
|
|
23
|
+
>
|
|
24
|
+
<path d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12" />
|
|
25
|
+
</svg>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
import { brand } from "@/brand.config";
|
|
29
|
+
import { CustomizeTab } from "@behavioral-agentic-design-system/core/components/customize-tab";
|
|
30
|
+
import { LayersTab } from "@behavioral-agentic-design-system/core/components/layers-tab";
|
|
31
|
+
import { HomeTab } from "@behavioral-agentic-design-system/core/components/home-tab";
|
|
32
|
+
import { BrandMark } from "@behavioral-agentic-design-system/core/components/brand-mark";
|
|
33
|
+
import { AdminMenu } from "@behavioral-agentic-design-system/core/components/admin-menu";
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Iframe-hosted preview surface. Listens for the parent's dark-mode state and
|
|
37
|
+
* mirrors it into its own document, so cross-fading tabs that hold iframes
|
|
38
|
+
* doesn't capture stale theming. Exported because most fork-supplied tabs
|
|
39
|
+
* will want to render an iframe of their own preview routes.
|
|
40
|
+
*/
|
|
41
|
+
export function IframePreview({
|
|
42
|
+
src,
|
|
43
|
+
minWidth,
|
|
44
|
+
dark,
|
|
45
|
+
}: {
|
|
46
|
+
src: string;
|
|
47
|
+
minWidth?: string;
|
|
48
|
+
dark: boolean;
|
|
49
|
+
}) {
|
|
50
|
+
const iframeRef = useRef<HTMLIFrameElement>(null);
|
|
51
|
+
// Capture the initial src once on mount. After load, dark mode is applied via
|
|
52
|
+
// class toggle (syncDarkMode) — recomputing src on every dark change would
|
|
53
|
+
// reload the iframe and cause a flicker during the theme transition.
|
|
54
|
+
const initialSrcRef = useRef(`${src}${dark ? "?dark=1" : ""}`);
|
|
55
|
+
// Iframe is visually hidden until its document fires `load`. Otherwise the
|
|
56
|
+
// user sees a brief flash of unstyled content (HTML paints before CSS+fonts
|
|
57
|
+
// arrive). Once loaded, fade the iframe in over 250ms — the parent tab fade
|
|
58
|
+
// is also running, so cumulatively the first-click feels like a single
|
|
59
|
+
// smooth transition.
|
|
60
|
+
const [loaded, setLoaded] = useState(false);
|
|
61
|
+
|
|
62
|
+
const syncDarkMode = useCallback(() => {
|
|
63
|
+
try {
|
|
64
|
+
iframeRef.current?.contentDocument?.documentElement.classList.toggle("dark", dark);
|
|
65
|
+
} catch {}
|
|
66
|
+
}, [dark]);
|
|
67
|
+
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
syncDarkMode();
|
|
70
|
+
}, [syncDarkMode]);
|
|
71
|
+
|
|
72
|
+
// Single-scrollbar policy: the iframe fills its container vertically and
|
|
73
|
+
// owns the vertical scrollbar (its own document scrolls). The outer wrapper
|
|
74
|
+
// only scrolls horizontally, and only when `minWidth` forces the inner
|
|
75
|
+
// track wider than the viewport (Dashboard, Mail). Two layers of vertical
|
|
76
|
+
// scrolling produced the "double scrollbar on the right" bug — keeping the
|
|
77
|
+
// overflow on a single axis fixes it.
|
|
78
|
+
return (
|
|
79
|
+
<div className="size-full relative overflow-x-auto overflow-y-hidden">
|
|
80
|
+
<div
|
|
81
|
+
style={{ minWidth: minWidth || "100%" }}
|
|
82
|
+
className="h-full w-full"
|
|
83
|
+
>
|
|
84
|
+
<iframe
|
|
85
|
+
ref={iframeRef}
|
|
86
|
+
src={initialSrcRef.current}
|
|
87
|
+
onLoad={() => {
|
|
88
|
+
syncDarkMode();
|
|
89
|
+
setLoaded(true);
|
|
90
|
+
}}
|
|
91
|
+
className="block h-full w-full border-0 transition-opacity duration-300 ease-out"
|
|
92
|
+
style={{
|
|
93
|
+
opacity: loaded ? 1 : 0,
|
|
94
|
+
}}
|
|
95
|
+
/>
|
|
96
|
+
</div>
|
|
97
|
+
</div>
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Runtime context handed to each tab's render function. `dark` mirrors the
|
|
103
|
+
* Shell's host dark-mode state so iframe-hosted tabs can sync the iframe's
|
|
104
|
+
* `<html>` class without prop-drilling through the tab list.
|
|
105
|
+
*/
|
|
106
|
+
export type ShellTabContext = {
|
|
107
|
+
dark: boolean;
|
|
108
|
+
goToTab: (value: string) => void;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Lets tab content request a tab switch without prop-drilling. Used by the
|
|
113
|
+
* "What's next" cards on the Home tab to jump straight into Components or
|
|
114
|
+
* Customize when a user clicks the corresponding affordance.
|
|
115
|
+
*
|
|
116
|
+
* Falls back to a no-op when consumed outside Shell (e.g. storybook), so the
|
|
117
|
+
* Home tab stays usable in isolation.
|
|
118
|
+
*/
|
|
119
|
+
type ShellNav = { setTab: (value: string) => void };
|
|
120
|
+
const ShellNavContext = createContext<ShellNav | null>(null);
|
|
121
|
+
export function useShellNav(): ShellNav {
|
|
122
|
+
return useContext(ShellNavContext) ?? { setTab: () => {} };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* One tab in the Shell. `render` is called once per first-visit and stays
|
|
127
|
+
* mounted afterwards (sticky-mount + cross-fade — see TabsPanels).
|
|
128
|
+
*
|
|
129
|
+
* `hidden: "md"` collapses the tab on screens below md breakpoint. Useful for
|
|
130
|
+
* dense iframe tabs (Dashboard, Mail) that don't read well on mobile.
|
|
131
|
+
*/
|
|
132
|
+
export type ShellTab = {
|
|
133
|
+
value: string;
|
|
134
|
+
label: string;
|
|
135
|
+
hidden?: "md";
|
|
136
|
+
render: (ctx: ShellTabContext) => React.ReactNode;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
export type ShellProps = {
|
|
140
|
+
tabs: ShellTab[];
|
|
141
|
+
/** Optional initial tab value. Defaults to the first tab. */
|
|
142
|
+
defaultTab?: string;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* The canonical BADS preview tabs. Forks pass these directly when they want
|
|
147
|
+
* the default shape, or compose their own list (or splice into this one) when
|
|
148
|
+
* they need custom surfaces alongside the built-ins.
|
|
149
|
+
*/
|
|
150
|
+
export const DEFAULT_TABS: ShellTab[] = [
|
|
151
|
+
{ value: "home", label: "Home", render: ({ goToTab }) => <HomeTab onBrowseComponents={() => goToTab("components")} /> },
|
|
152
|
+
{ value: "components", label: "Components", render: ({ dark }) => <IframePreview dark={dark} src="/preview/components" /> },
|
|
153
|
+
{ value: "cards", label: "Cards", render: ({ dark }) => <IframePreview dark={dark} src="/preview/cards" /> },
|
|
154
|
+
{ value: "dashboard", label: "Dashboard", hidden: "md", render: ({ dark }) => <IframePreview dark={dark} src="/preview/dashboard" minWidth="1400px" /> },
|
|
155
|
+
{ value: "mail", label: "Mail", hidden: "md", render: ({ dark }) => <IframePreview dark={dark} src="/preview/mail" minWidth="1300px" /> },
|
|
156
|
+
{ value: "pricing", label: "Pricing", render: ({ dark }) => <IframePreview dark={dark} src="/preview/pricing" /> },
|
|
157
|
+
{ value: "layers", label: "Layers", render: () => <LayersTab /> },
|
|
158
|
+
{ value: "colors", label: "Customize", render: () => <CustomizeTab /> },
|
|
159
|
+
];
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* The BADS preview shell — header (brand + Storybook + dark toggle) plus a
|
|
163
|
+
* sticky-mount cross-fade tab bar. Pass any `tabs` array to override the
|
|
164
|
+
* default surfaces; pass `DEFAULT_TABS` to keep the canonical layout.
|
|
165
|
+
*
|
|
166
|
+
* Forks that just want the default shell don't need to import this directly —
|
|
167
|
+
* they can re-export `@behavioral-agentic-design-system/core/app/page`. Use
|
|
168
|
+
* Shell directly when you need custom tabs (e.g. Pool, Meet, Athletes for a
|
|
169
|
+
* swim-club brand).
|
|
170
|
+
*/
|
|
171
|
+
export function Shell({ tabs, defaultTab }: ShellProps) {
|
|
172
|
+
const initialTab = defaultTab ?? tabs[0]?.value ?? "home";
|
|
173
|
+
const [activeTab, setActiveTab] = useState(initialTab);
|
|
174
|
+
const [dark, setDark] = useState(false);
|
|
175
|
+
// Sticky-mount: once a tab has been viewed, keep it mounted forever so the
|
|
176
|
+
// iframe (or React tree) doesn't cold-load on every switch. TabsPanels
|
|
177
|
+
// cross-fades between mounted siblings, so subsequent switches are instant
|
|
178
|
+
// and flash-free. Only the first visit to a tab pays the load cost.
|
|
179
|
+
const [seen, setSeen] = useState<Set<string>>(() => new Set([initialTab]));
|
|
180
|
+
useEffect(() => {
|
|
181
|
+
setSeen((prev) => (prev.has(activeTab) ? prev : new Set(prev).add(activeTab)));
|
|
182
|
+
}, [activeTab]);
|
|
183
|
+
|
|
184
|
+
// Background preload: after the active tab has fully painted and idled,
|
|
185
|
+
// mount every other tab so they load silently while the user is reading
|
|
186
|
+
// the home tab. By the time someone clicks any other tab, its iframe is
|
|
187
|
+
// already loaded + styled — the tab switch becomes an instant cross-fade,
|
|
188
|
+
// no FOUC, no spinner. Uses requestIdleCallback when available so we don't
|
|
189
|
+
// compete with the home tab's first paint; falls back to a 1500ms
|
|
190
|
+
// setTimeout in Safari.
|
|
191
|
+
useEffect(() => {
|
|
192
|
+
const preloadAll = () => {
|
|
193
|
+
setSeen((prev) => {
|
|
194
|
+
const next = new Set(prev);
|
|
195
|
+
tabs.forEach((t) => next.add(t.value));
|
|
196
|
+
return next;
|
|
197
|
+
});
|
|
198
|
+
};
|
|
199
|
+
type RIC = (cb: () => void, opts?: { timeout?: number }) => number;
|
|
200
|
+
const w = window as Window & { requestIdleCallback?: RIC; cancelIdleCallback?: (id: number) => void };
|
|
201
|
+
if (w.requestIdleCallback) {
|
|
202
|
+
const id = w.requestIdleCallback(preloadAll, { timeout: 2500 });
|
|
203
|
+
return () => w.cancelIdleCallback?.(id);
|
|
204
|
+
}
|
|
205
|
+
const id = window.setTimeout(preloadAll, 1500);
|
|
206
|
+
return () => window.clearTimeout(id);
|
|
207
|
+
}, [tabs]);
|
|
208
|
+
|
|
209
|
+
useEffect(() => {
|
|
210
|
+
document.documentElement.classList.toggle("dark", dark);
|
|
211
|
+
}, [dark]);
|
|
212
|
+
|
|
213
|
+
const toggleDark = (event: React.MouseEvent) => {
|
|
214
|
+
const next = !dark;
|
|
215
|
+
const root = document.documentElement;
|
|
216
|
+
const prefersReduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
217
|
+
const supports = typeof document !== "undefined" && "startViewTransition" in document;
|
|
218
|
+
|
|
219
|
+
// Sync every iframe preview's dark class right now so its DOM matches the
|
|
220
|
+
// new theme at the same instant the parent does — otherwise the iframe lags
|
|
221
|
+
// behind React's useEffect and the transition captures stale iframe content.
|
|
222
|
+
const syncIframes = () => {
|
|
223
|
+
document.querySelectorAll("iframe").forEach((f) => {
|
|
224
|
+
try {
|
|
225
|
+
f.contentDocument?.documentElement.classList.toggle("dark", next);
|
|
226
|
+
} catch {}
|
|
227
|
+
});
|
|
228
|
+
};
|
|
229
|
+
const syncHost = () => {
|
|
230
|
+
root.classList.toggle("dark", next);
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
if (!supports || prefersReduce) {
|
|
234
|
+
syncHost();
|
|
235
|
+
syncIframes();
|
|
236
|
+
setDark(next);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
root.style.setProperty("--x", `${event.clientX}px`);
|
|
240
|
+
root.style.setProperty("--y", `${event.clientY}px`);
|
|
241
|
+
(document as Document & { startViewTransition: (cb: () => void) => void }).startViewTransition(() => {
|
|
242
|
+
syncHost();
|
|
243
|
+
syncIframes();
|
|
244
|
+
setDark(next);
|
|
245
|
+
});
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
const ctx: ShellTabContext = { dark, goToTab: (value: string) => setActiveTab(value) };
|
|
249
|
+
const navValue = useMemo<ShellNav>(() => ({ setTab: setActiveTab }), []);
|
|
250
|
+
|
|
251
|
+
return (
|
|
252
|
+
<ShellNavContext.Provider value={navValue}>
|
|
253
|
+
<div className="min-h-screen bg-background flex flex-col">
|
|
254
|
+
<header className="border-b bg-card shrink-0">
|
|
255
|
+
<div className="flex h-14 items-center px-6">
|
|
256
|
+
<div className="flex items-center gap-2">
|
|
257
|
+
<div
|
|
258
|
+
className="h-8 w-8 rounded-lg flex items-center justify-center bg-primary text-primary-foreground"
|
|
259
|
+
>
|
|
260
|
+
<BrandMark size={20} />
|
|
261
|
+
</div>
|
|
262
|
+
<span className="text-lg font-semibold">{brand.name}</span>
|
|
263
|
+
<Badge variant="outline" className="ml-2 text-xs">{brand.tagline}</Badge>
|
|
264
|
+
</div>
|
|
265
|
+
<div className="ml-auto flex items-center gap-2">
|
|
266
|
+
<Button
|
|
267
|
+
asChild
|
|
268
|
+
variant="ghost"
|
|
269
|
+
size="sm"
|
|
270
|
+
className="group h-8 gap-1.5 border border-foreground/30 hover:!bg-foreground hover:!text-background hover:border-foreground"
|
|
271
|
+
title="Open Storybook (requires `pnpm dev` or `pnpm storybook` to be running on :6007)"
|
|
272
|
+
>
|
|
273
|
+
<a href="http://localhost:6007" target="_blank" rel="noreferrer" aria-label="Open Storybook in a new tab">
|
|
274
|
+
<BookOpen className="h-4 w-4 transition-all group-hover:scale-110" strokeWidth={1.5} />
|
|
275
|
+
<span className="text-xs font-medium">Storybook</span>
|
|
276
|
+
</a>
|
|
277
|
+
</Button>
|
|
278
|
+
{brand.repo && (
|
|
279
|
+
<Button
|
|
280
|
+
asChild
|
|
281
|
+
variant="ghost"
|
|
282
|
+
size="sm"
|
|
283
|
+
className="group h-8 gap-1.5 border border-foreground/30 hover:!bg-foreground hover:!text-background hover:border-foreground"
|
|
284
|
+
title={`Open ${brand.repo.replace(/^https?:\/\//, "")} on GitHub`}
|
|
285
|
+
>
|
|
286
|
+
<a href={brand.repo} target="_blank" rel="noreferrer" aria-label="Open GitHub repo in a new tab">
|
|
287
|
+
<GithubMark className="h-4 w-4 transition-all group-hover:scale-110" />
|
|
288
|
+
<span className="text-xs font-medium">GitHub</span>
|
|
289
|
+
</a>
|
|
290
|
+
</Button>
|
|
291
|
+
)}
|
|
292
|
+
<Button
|
|
293
|
+
variant="ghost"
|
|
294
|
+
size="icon"
|
|
295
|
+
onClick={toggleDark}
|
|
296
|
+
className="group size-8 border border-foreground/30 hover:!bg-foreground hover:!text-background hover:border-foreground"
|
|
297
|
+
aria-label={dark ? "Switch to light mode" : "Switch to dark mode"}
|
|
298
|
+
>
|
|
299
|
+
{dark ? (
|
|
300
|
+
<Sun className="h-4 w-4 transition-all group-hover:scale-110" />
|
|
301
|
+
) : (
|
|
302
|
+
<Moon className="h-4 w-4 transition-all group-hover:scale-110" />
|
|
303
|
+
)}
|
|
304
|
+
</Button>
|
|
305
|
+
</div>
|
|
306
|
+
</div>
|
|
307
|
+
</header>
|
|
308
|
+
|
|
309
|
+
<Tabs
|
|
310
|
+
value={activeTab}
|
|
311
|
+
onValueChange={setActiveTab}
|
|
312
|
+
// Slower cross-fade between mounted panels — 260ms feels deliberate
|
|
313
|
+
// without dragging. Read by the duration utility on TabsPanels.
|
|
314
|
+
style={{ "--tabs-fade-duration": "260ms" } as React.CSSProperties}
|
|
315
|
+
className="flex-1 flex flex-col overflow-hidden"
|
|
316
|
+
>
|
|
317
|
+
<div className="mt-2 mb-1 flex w-full items-center px-4">
|
|
318
|
+
<TabsList className="bg-background text-muted-foreground inline-flex w-fit items-center justify-center rounded-full px-0">
|
|
319
|
+
{tabs.map((tab) => (
|
|
320
|
+
<TabsTrigger
|
|
321
|
+
key={tab.value}
|
|
322
|
+
value={tab.value}
|
|
323
|
+
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 ${
|
|
324
|
+
tab.hidden === "md" ? "hidden md:inline-flex" : "inline-flex"
|
|
325
|
+
}`}
|
|
326
|
+
>
|
|
327
|
+
{tab.label}
|
|
328
|
+
</TabsTrigger>
|
|
329
|
+
))}
|
|
330
|
+
</TabsList>
|
|
331
|
+
</div>
|
|
332
|
+
|
|
333
|
+
<section className="relative flex-1 min-h-0 w-full overflow-hidden">
|
|
334
|
+
<div className="absolute inset-x-4 top-1 bottom-4 isolate overflow-hidden rounded-lg">
|
|
335
|
+
<TabsPanels>
|
|
336
|
+
{tabs.map((tab) =>
|
|
337
|
+
seen.has(tab.value) ? (
|
|
338
|
+
<TabsContent key={tab.value} value={tab.value} forceMount>
|
|
339
|
+
{tab.render(ctx)}
|
|
340
|
+
</TabsContent>
|
|
341
|
+
) : null,
|
|
342
|
+
)}
|
|
343
|
+
</TabsPanels>
|
|
344
|
+
</div>
|
|
345
|
+
</section>
|
|
346
|
+
</Tabs>
|
|
347
|
+
|
|
348
|
+
<div className="fixed bottom-4 right-4 flex items-end gap-2">
|
|
349
|
+
<AdminMenu />
|
|
350
|
+
</div>
|
|
351
|
+
</div>
|
|
352
|
+
</ShellNavContext.Provider>
|
|
353
|
+
);
|
|
354
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
|
+
import { AdminMenu } from "./admin-menu";
|
|
3
|
+
|
|
4
|
+
const meta: Meta<typeof AdminMenu> = {
|
|
5
|
+
title: "Components/AdminMenu",
|
|
6
|
+
component: AdminMenu,
|
|
7
|
+
tags: ["autodocs"],
|
|
8
|
+
parameters: {
|
|
9
|
+
layout: "padded",
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default meta;
|
|
14
|
+
type Story = StoryObj<typeof meta>;
|
|
15
|
+
|
|
16
|
+
export const Default: Story = {};
|
|
17
|
+
|
|
18
|
+
export const WithLabel: Story = {
|
|
19
|
+
args: {
|
|
20
|
+
label: "Admin",
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const WithChildren: Story = {
|
|
25
|
+
render: () => (
|
|
26
|
+
<AdminMenu>
|
|
27
|
+
<div className="space-y-2">
|
|
28
|
+
<button className="w-full px-2 py-1.5 text-sm font-medium text-left rounded hover:bg-muted transition-colors">
|
|
29
|
+
View 1: Calm
|
|
30
|
+
</button>
|
|
31
|
+
<button className="w-full px-2 py-1.5 text-sm font-medium text-left rounded hover:bg-muted transition-colors">
|
|
32
|
+
View 2: Rich
|
|
33
|
+
</button>
|
|
34
|
+
<button className="w-full px-2 py-1.5 text-sm font-medium text-left rounded hover:bg-muted transition-colors">
|
|
35
|
+
View 3: Editorial
|
|
36
|
+
</button>
|
|
37
|
+
</div>
|
|
38
|
+
</AdminMenu>
|
|
39
|
+
),
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const RealisticUse: Story = {
|
|
43
|
+
render: () => (
|
|
44
|
+
<div className="relative w-full h-96 border border-dashed border-muted-foreground/30 rounded-lg flex items-center justify-center bg-muted/20">
|
|
45
|
+
<div className="absolute bottom-4 right-4">
|
|
46
|
+
<AdminMenu>
|
|
47
|
+
<div className="space-y-2">
|
|
48
|
+
<div className="text-xs font-semibold text-muted-foreground uppercase tracking-wide mb-3 px-2">
|
|
49
|
+
Navigation Views
|
|
50
|
+
</div>
|
|
51
|
+
<button className="w-full px-2 py-1.5 text-sm rounded hover:bg-muted transition-colors text-left">
|
|
52
|
+
Calm View
|
|
53
|
+
</button>
|
|
54
|
+
<button className="w-full px-2 py-1.5 text-sm rounded hover:bg-muted transition-colors text-left">
|
|
55
|
+
Rich View
|
|
56
|
+
</button>
|
|
57
|
+
<button className="w-full px-2 py-1.5 text-sm rounded hover:bg-muted transition-colors text-left">
|
|
58
|
+
Editorial View
|
|
59
|
+
</button>
|
|
60
|
+
</div>
|
|
61
|
+
</AdminMenu>
|
|
62
|
+
</div>
|
|
63
|
+
<span className="text-sm text-muted-foreground">
|
|
64
|
+
AdminMenu positioned bottom-right with children
|
|
65
|
+
</span>
|
|
66
|
+
</div>
|
|
67
|
+
),
|
|
68
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { Settings, X } from "lucide-react";
|
|
5
|
+
import { Button } from "@behavioral-agentic-design-system/core/components/ui/button";
|
|
6
|
+
import {
|
|
7
|
+
Popover,
|
|
8
|
+
PopoverContent,
|
|
9
|
+
PopoverTrigger,
|
|
10
|
+
} from "@behavioral-agentic-design-system/core/components/ui/popover";
|
|
11
|
+
|
|
12
|
+
export type AdminMenuChildren = React.ReactNode;
|
|
13
|
+
|
|
14
|
+
export type AdminMenuProps = {
|
|
15
|
+
children?: AdminMenuChildren;
|
|
16
|
+
/**
|
|
17
|
+
* Optional text shown next to the gear icon. When omitted the trigger
|
|
18
|
+
* stays icon-only (44×44px). When provided the button widens to fit the
|
|
19
|
+
* label while preserving the AAA touch target.
|
|
20
|
+
*/
|
|
21
|
+
label?: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export function AdminMenu({ children, label }: AdminMenuProps) {
|
|
25
|
+
const [open, setOpen] = useState(false);
|
|
26
|
+
const hasLabel = Boolean(label);
|
|
27
|
+
|
|
28
|
+
// bg-card/95 + backdrop-blur-md mirrors the DevIdentityBadge treatment so
|
|
29
|
+
// the trigger stays legible on any background — flat surfaces, gradient
|
|
30
|
+
// hero blocks, photo backgrounds, anywhere a fork wants to drop it. Ghost
|
|
31
|
+
// variants disappear against busy backgrounds; the resting fill prevents
|
|
32
|
+
// that without changing the hover invert.
|
|
33
|
+
return (
|
|
34
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
35
|
+
<PopoverTrigger asChild>
|
|
36
|
+
<Button
|
|
37
|
+
variant="ghost"
|
|
38
|
+
size={hasLabel ? "sm" : "icon"}
|
|
39
|
+
className={
|
|
40
|
+
hasLabel
|
|
41
|
+
? "group h-8 gap-1.5 border border-border bg-card/95 backdrop-blur-md shadow-sm hover:!bg-foreground hover:!text-background hover:border-foreground"
|
|
42
|
+
: "group size-8 border border-border bg-card/95 backdrop-blur-md shadow-sm hover:!bg-foreground hover:!text-background hover:border-foreground"
|
|
43
|
+
}
|
|
44
|
+
aria-label={open ? "Close admin menu" : "Open admin menu"}
|
|
45
|
+
>
|
|
46
|
+
{open ? (
|
|
47
|
+
<X className="h-4 w-4 transition-all group-hover:scale-110" strokeWidth={1.5} />
|
|
48
|
+
) : (
|
|
49
|
+
<Settings className="h-4 w-4 transition-all group-hover:scale-110" strokeWidth={1.5} />
|
|
50
|
+
)}
|
|
51
|
+
{hasLabel && <span className="text-xs font-medium">{label}</span>}
|
|
52
|
+
</Button>
|
|
53
|
+
</PopoverTrigger>
|
|
54
|
+
<PopoverContent align="end" side="top" className="w-64 p-3">
|
|
55
|
+
{children}
|
|
56
|
+
</PopoverContent>
|
|
57
|
+
</Popover>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Sparkles } from "lucide-react";
|
|
4
|
+
import { brand } from "@/brand.config";
|
|
5
|
+
import { cn } from "@behavioral-agentic-design-system/core/lib/utils";
|
|
6
|
+
import { useGlobalBrandMarkSvg } from "@behavioral-agentic-design-system/core/hooks/use-global-brand-mark";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Brand mark / logo component. Renders the saved SVG from the live brand-mark
|
|
10
|
+
* override when present, otherwise the SVG declared in brand-mark.json, and
|
|
11
|
+
* falls back to the default Sparkles icon when no mark is configured.
|
|
12
|
+
*
|
|
13
|
+
* Theming: when the source SVG is monotone, the API rewrites all `fill` /
|
|
14
|
+
* `stroke` to `currentColor` so the mark adopts the surrounding text color.
|
|
15
|
+
* Multi-color marks are preserved exactly.
|
|
16
|
+
*
|
|
17
|
+
* Sizing: `size` controls both width and height in pixels (default 32). The
|
|
18
|
+
* inner SVG fills the wrapper via CSS, so any viewBox is preserved.
|
|
19
|
+
*/
|
|
20
|
+
export function BrandMark({
|
|
21
|
+
size = 32,
|
|
22
|
+
className,
|
|
23
|
+
title,
|
|
24
|
+
}: {
|
|
25
|
+
/** Pixel size for both width and height. Defaults to 32. */
|
|
26
|
+
size?: number;
|
|
27
|
+
className?: string;
|
|
28
|
+
/** Optional accessible label. Defaults to `${brand.name} logo`. */
|
|
29
|
+
title?: string;
|
|
30
|
+
}) {
|
|
31
|
+
const svg = useGlobalBrandMarkSvg();
|
|
32
|
+
const label = title ?? `${brand.name} logo`;
|
|
33
|
+
|
|
34
|
+
if (svg) {
|
|
35
|
+
return (
|
|
36
|
+
<span
|
|
37
|
+
role="img"
|
|
38
|
+
aria-label={label}
|
|
39
|
+
className={cn("inline-flex items-center justify-center [&>svg]:h-full [&>svg]:w-full", className)}
|
|
40
|
+
style={{ width: size, height: size }}
|
|
41
|
+
// SVG is sanitized server-side in /api/brand-mark before it lands in
|
|
42
|
+
// brand-mark.json — script tags, on* handlers, and dangerous URL
|
|
43
|
+
// protocols are stripped. Safe to inline render.
|
|
44
|
+
dangerouslySetInnerHTML={{ __html: svg }}
|
|
45
|
+
/>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<span
|
|
51
|
+
role="img"
|
|
52
|
+
aria-label={label}
|
|
53
|
+
className={cn("inline-flex items-center justify-center", className)}
|
|
54
|
+
style={{ width: size, height: size }}
|
|
55
|
+
>
|
|
56
|
+
<Sparkles
|
|
57
|
+
// Lucide expects px width/height. Match the wrapper so the icon fills it.
|
|
58
|
+
width={size * 0.55}
|
|
59
|
+
height={size * 0.55}
|
|
60
|
+
strokeWidth={1.5}
|
|
61
|
+
/>
|
|
62
|
+
</span>
|
|
63
|
+
);
|
|
64
|
+
}
|