@behavioral-agentic-design-system/core 0.40.0 → 0.45.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/README.md +2 -0
- package/package.json +41 -9
- package/scripts/a11y-lint.cjs +66 -3
- package/scripts/check-spec.mjs +73 -0
- package/scripts/deal-directions.mjs +186 -0
- package/scripts/health-report.mjs +23 -3
- package/scripts/lib/counted-lint.mjs +100 -0
- package/scripts/lib/marketing-library.mjs +129 -0
- package/scripts/lib/on-system.mjs +249 -0
- package/scripts/lib/random.mjs +22 -0
- package/scripts/lib/spec-parse.d.mts +25 -0
- package/scripts/lib/spec-parse.mjs +188 -0
- package/scripts/lib/tells.mjs +128 -0
- package/scripts/lint-css-vars.mjs +175 -0
- package/scripts/lint-html-nesting.mjs +116 -0
- package/scripts/lint-live-ctas.mjs +138 -0
- package/scripts/lint-slop.mjs +25 -1
- package/scripts/on-system-score.mjs +95 -0
- package/scripts/slop-rules.mjs +1 -1
- package/scripts/source-images.mjs +180 -0
- package/scripts/ux-tells.mjs +78 -0
- package/scripts/wcag-audit.cjs +72 -5
- package/src/api/brand-colors.ts +3 -0
- package/src/api/brand-fonts.ts +3 -0
- package/src/api/brand-mark.ts +6 -1
- package/src/api/dev-write-guard.ts +53 -0
- package/src/api/layers/file.ts +7 -4
- package/src/api/onboarding-extract.ts +85 -30
- package/src/api/onboarding.ts +3 -0
- package/src/api/save-tokens.ts +3 -0
- package/src/app/layout.tsx +6 -0
- package/src/app/opengraph-image.tsx +5 -0
- package/src/app/preview/canvas/page.tsx +12 -0
- package/src/app/preview/components/page.tsx +2003 -2
- package/src/app/preview/studio/blank-screen.tsx +143 -0
- package/src/app/preview/studio/page.tsx +7 -0
- package/src/app/shell.tsx +168 -49
- package/src/components/Foundations/Motion.stories.tsx +1 -0
- package/src/components/canvas/canvas.tsx +458 -0
- package/src/components/canvas/layout.ts +72 -0
- package/src/components/canvas/parse-canvas.ts +32 -0
- package/src/components/canvas/sample.ts +90 -0
- package/src/components/canvas/spec-frame.tsx +43 -0
- package/src/components/canvas/types.ts +33 -0
- package/src/components/customize/design-controls.tsx +16 -1
- package/src/components/docs-tab.tsx +7 -7
- package/src/components/home-recent.tsx +73 -0
- package/src/components/home-tab.tsx +13 -13
- package/src/components/layers-tab.tsx +2 -2
- package/src/components/markdown-preview.tsx +60 -12
- package/src/components/studio/control-panel.tsx +299 -0
- package/src/components/studio/control-row.tsx +77 -0
- package/src/components/studio/preview-frame.tsx +165 -0
- package/src/components/studio/preview-pane.tsx +247 -0
- package/src/components/studio/studio.tsx +158 -0
- package/src/components/studio/types.ts +218 -0
- package/src/components/studio/use-studio-tweaks.ts +128 -0
- package/src/components/studio/use-studio-view-state.ts +72 -0
- package/src/components/ui/anchor.tsx +37 -3
- package/src/components/ui/attachment.tsx +211 -0
- package/src/components/ui/autocomplete.tsx +1 -1
- package/src/components/ui/chart.tsx +3 -0
- package/src/components/ui/code.tsx +1 -1
- package/src/components/ui/color-picker.tsx +21 -5
- package/src/components/ui/data-table.tsx +64 -3
- package/src/components/ui/date-field.tsx +1 -1
- package/src/components/ui/editable.tsx +1 -0
- package/src/components/ui/faceted-filter.tsx +187 -0
- package/src/components/ui/gauge-chart.tsx +252 -0
- package/src/components/ui/heatmap.tsx +256 -0
- package/src/components/ui/index.ts +9 -0
- package/src/components/ui/infinite-scroll.tsx +103 -0
- package/src/components/ui/inline-edit.tsx +175 -0
- package/src/components/ui/json-input.tsx +351 -0
- package/src/components/ui/month-picker.tsx +1 -1
- package/src/components/ui/navigation-progress.tsx +281 -0
- package/src/components/ui/number-input.tsx +27 -7
- package/src/components/ui/otp-input.tsx +208 -0
- package/src/components/ui/password-input.tsx +2 -1
- package/src/components/ui/password-strength-input.tsx +288 -0
- package/src/components/ui/phone-input.tsx +274 -0
- package/src/components/ui/pill.tsx +140 -0
- package/src/components/ui/popover.tsx +27 -4
- package/src/components/ui/scroll-progress.tsx +100 -0
- package/src/components/ui/search-input.tsx +1 -1
- package/src/components/ui/snackbar.tsx +393 -0
- package/src/components/ui/sortable-list.tsx +342 -0
- package/src/components/ui/squircle.tsx +1 -1
- package/src/components/ui/table.tsx +1 -1
- package/src/components/ui/tags-input.tsx +1 -1
- package/src/components/ui/timer.tsx +1 -0
- package/src/components/ui/tour.tsx +1 -3
- package/src/components/ui/transfer-list.tsx +13 -26
- package/src/components/ui/week-picker.tsx +1 -1
- package/src/components/ui/year-picker.tsx +1 -1
- package/src/data/component-added.json +958 -0
- package/src/data/docs-index.ts +36 -0
- package/src/hooks/use-global-mono-font.ts +1 -0
- package/src/hooks/use-global-primary-color.ts +1 -0
- package/src/hooks/use-global-sans-font.ts +1 -0
- package/src/hooks/use-global-serif-font.ts +1 -0
- package/src/hooks/use-global-type-scale.ts +17 -2
- package/src/hooks/use-mobile.ts +2 -0
- package/src/hooks/use-sync-type-scale.ts +7 -11
- package/src/lib/clamp.ts +2 -0
- package/src/lib/spec-parse.ts +4 -0
- package/src/lib/svg-sanitize.ts +19 -9
- package/src/stories/Anchor.stories.tsx +54 -0
- package/src/stories/Attachment.stories.tsx +189 -0
- package/src/stories/Autocomplete.stories.tsx +2 -0
- package/src/stories/Canvas.stories.tsx +45 -0
- package/src/stories/Chart.stories.tsx +4 -0
- package/src/stories/Code.stories.tsx +1 -0
- package/src/stories/ColorPicker.stories.tsx +41 -0
- package/src/stories/DataTable.stories.tsx +30 -0
- package/src/stories/DateField.stories.tsx +21 -0
- package/src/stories/Editable.stories.tsx +2 -0
- package/src/stories/FacetedFilter.stories.tsx +197 -0
- package/src/stories/GaugeChart.stories.tsx +169 -0
- package/src/stories/Heatmap.stories.tsx +172 -0
- package/src/stories/InfiniteScroll.stories.tsx +225 -0
- package/src/stories/InlineEdit.stories.tsx +106 -0
- package/src/stories/JsonInput.stories.tsx +212 -0
- package/src/stories/MarkdownPreview.stories.tsx +53 -0
- package/src/stories/MonthPicker.stories.tsx +21 -0
- package/src/stories/NavigationProgress.stories.tsx +159 -0
- package/src/stories/NumberInput.stories.tsx +26 -0
- package/src/stories/OtpInput.stories.tsx +110 -0
- package/src/stories/PasswordInput.stories.tsx +4 -0
- package/src/stories/PasswordStrengthInput.stories.tsx +211 -0
- package/src/stories/PhoneInput.stories.tsx +127 -0
- package/src/stories/Pill.stories.tsx +201 -0
- package/src/stories/Popover.stories.tsx +29 -1
- package/src/stories/Portal.stories.tsx +3 -1
- package/src/stories/ScrollProgress.stories.tsx +117 -0
- package/src/stories/SearchInput.stories.tsx +2 -0
- package/src/stories/Snackbar.stories.tsx +315 -0
- package/src/stories/SortableList.stories.tsx +263 -0
- package/src/stories/Squircle.stories.tsx +1 -0
- package/src/stories/Table.stories.tsx +1 -0
- package/src/stories/TagsInput.stories.tsx +2 -0
- package/src/stories/Timer.stories.tsx +26 -0
- package/src/stories/Tour.stories.tsx +1 -0
- package/src/stories/TransferList.stories.tsx +4 -0
- package/src/stories/WeekPicker.stories.tsx +21 -0
- package/src/stories/YearPicker.stories.tsx +21 -0
- package/src/stories/story-groups.json +33 -16
- package/src/tokens.json +82 -54
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef, useState } from "react";
|
|
4
|
+
import { Badge } from "../../../components/ui/badge";
|
|
5
|
+
import { Button } from "../../../components/ui/button";
|
|
6
|
+
import {
|
|
7
|
+
Card,
|
|
8
|
+
CardContent,
|
|
9
|
+
CardDescription,
|
|
10
|
+
CardFooter,
|
|
11
|
+
CardHeader,
|
|
12
|
+
CardTitle,
|
|
13
|
+
} from "../../../components/ui/card";
|
|
14
|
+
import { Container } from "../../../components/ui/container";
|
|
15
|
+
import { Field, FieldControl, FieldGroup, FieldLabel } from "../../../components/ui/field";
|
|
16
|
+
import { Input } from "../../../components/ui/input";
|
|
17
|
+
import { Switch } from "../../../components/ui/switch";
|
|
18
|
+
|
|
19
|
+
const LONG_ROW_TEXT =
|
|
20
|
+
"Harborline Logistics, southeast distribution network redesign, phase two of three";
|
|
21
|
+
|
|
22
|
+
const TYPE_STEPS = ["text-xs", "text-sm", "text-base", "text-lg", "text-xl", "text-2xl", "text-3xl"] as const;
|
|
23
|
+
|
|
24
|
+
const SWATCHES = [
|
|
25
|
+
{ label: "Background", className: "bg-background" },
|
|
26
|
+
{ label: "Primary", className: "bg-primary" },
|
|
27
|
+
{ label: "Secondary", className: "bg-secondary" },
|
|
28
|
+
{ label: "Muted", className: "bg-muted" },
|
|
29
|
+
{ label: "Accent", className: "bg-accent" },
|
|
30
|
+
] as const;
|
|
31
|
+
|
|
32
|
+
/** One ladder row. Reads its own computed size so the number tracks every type tweak. */
|
|
33
|
+
function TypeStep({ step }: { step: (typeof TYPE_STEPS)[number] }) {
|
|
34
|
+
const sampleRef = useRef<HTMLDivElement>(null);
|
|
35
|
+
const [px, setPx] = useState<string>("");
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
const read = () => {
|
|
39
|
+
const el = sampleRef.current;
|
|
40
|
+
if (!el) return;
|
|
41
|
+
setPx(`${Math.round(parseFloat(getComputedStyle(el).fontSize) * 10) / 10}px`);
|
|
42
|
+
};
|
|
43
|
+
read();
|
|
44
|
+
// The global hooks write their CSS variables in response to the same storage event,
|
|
45
|
+
// so wait a frame before measuring.
|
|
46
|
+
const onStorage = () => requestAnimationFrame(read);
|
|
47
|
+
window.addEventListener("storage", onStorage);
|
|
48
|
+
return () => window.removeEventListener("storage", onStorage);
|
|
49
|
+
}, []);
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<div className="flex min-w-0 flex-col gap-1 border-b py-3 sm:grid sm:grid-cols-[9rem_minmax(0,1fr)] sm:items-baseline sm:gap-4">
|
|
53
|
+
<dt className="text-xs tabular-nums text-muted-foreground">
|
|
54
|
+
{step} · {px || "..."}
|
|
55
|
+
</dt>
|
|
56
|
+
<dd ref={sampleRef} className={`${step} min-w-0 break-words`}>
|
|
57
|
+
Ten layers in one fork
|
|
58
|
+
</dd>
|
|
59
|
+
</div>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function BlankScreen() {
|
|
64
|
+
return (
|
|
65
|
+
<div className="@container min-h-full w-full bg-background text-foreground">
|
|
66
|
+
<Container className="flex flex-col gap-10 py-10">
|
|
67
|
+
<header className="flex flex-col gap-3">
|
|
68
|
+
<h1 className="text-3xl font-semibold tracking-tight">Nothing here yet</h1>
|
|
69
|
+
<p className="text-base text-muted-foreground">
|
|
70
|
+
This screen is built only from the system's own parts. Change a value in Studio
|
|
71
|
+
and it redraws here.
|
|
72
|
+
</p>
|
|
73
|
+
</header>
|
|
74
|
+
|
|
75
|
+
<Card>
|
|
76
|
+
<CardHeader>
|
|
77
|
+
<CardTitle>Invite a reviewer</CardTitle>
|
|
78
|
+
<CardDescription>They get read access to this fork's preview.</CardDescription>
|
|
79
|
+
</CardHeader>
|
|
80
|
+
<CardContent>
|
|
81
|
+
<FieldGroup>
|
|
82
|
+
<Field name="reviewer-name">
|
|
83
|
+
<FieldLabel>Name</FieldLabel>
|
|
84
|
+
<FieldControl>
|
|
85
|
+
<Input defaultValue="Chloé Dubois-Martin" autoComplete="off" />
|
|
86
|
+
</FieldControl>
|
|
87
|
+
</Field>
|
|
88
|
+
<Field name="reviewer-team">
|
|
89
|
+
<FieldLabel>Team</FieldLabel>
|
|
90
|
+
<FieldControl>
|
|
91
|
+
<Input defaultValue="Cedar & Pine Studio" autoComplete="off" />
|
|
92
|
+
</FieldControl>
|
|
93
|
+
</Field>
|
|
94
|
+
<Field name="reviewer-notify" layout="horizontal" className="justify-between">
|
|
95
|
+
<FieldLabel>Email me when they reply</FieldLabel>
|
|
96
|
+
<FieldControl>
|
|
97
|
+
<Switch defaultChecked={false} />
|
|
98
|
+
</FieldControl>
|
|
99
|
+
</Field>
|
|
100
|
+
</FieldGroup>
|
|
101
|
+
</CardContent>
|
|
102
|
+
<CardFooter className="flex flex-wrap gap-3">
|
|
103
|
+
<Button size="xl">Send invite</Button>
|
|
104
|
+
<Button variant="outline" size="xl">
|
|
105
|
+
Cancel
|
|
106
|
+
</Button>
|
|
107
|
+
</CardFooter>
|
|
108
|
+
</Card>
|
|
109
|
+
|
|
110
|
+
<div className="flex min-w-0 items-center gap-3 overflow-hidden rounded-lg border p-4">
|
|
111
|
+
<Badge className="shrink-0">Draft</Badge>
|
|
112
|
+
<span className="min-w-0 truncate text-base" title={LONG_ROW_TEXT}>
|
|
113
|
+
{LONG_ROW_TEXT}
|
|
114
|
+
</span>
|
|
115
|
+
</div>
|
|
116
|
+
|
|
117
|
+
<section aria-labelledby="type-ladder-heading" className="flex flex-col gap-2">
|
|
118
|
+
<h2 id="type-ladder-heading" className="text-xl font-semibold">
|
|
119
|
+
Type ladder
|
|
120
|
+
</h2>
|
|
121
|
+
<dl className="border-t">
|
|
122
|
+
{TYPE_STEPS.map((step) => (
|
|
123
|
+
<TypeStep key={step} step={step} />
|
|
124
|
+
))}
|
|
125
|
+
</dl>
|
|
126
|
+
</section>
|
|
127
|
+
|
|
128
|
+
<section aria-labelledby="swatch-heading" className="flex flex-col gap-3">
|
|
129
|
+
<h2 id="swatch-heading" className="text-xl font-semibold">
|
|
130
|
+
Surfaces
|
|
131
|
+
</h2>
|
|
132
|
+
<div className="flex flex-wrap gap-3">
|
|
133
|
+
{SWATCHES.map((s) => (
|
|
134
|
+
<div key={s.label} className={`${s.className} size-11 rounded-md border`}>
|
|
135
|
+
<span className="sr-only">{s.label}</span>
|
|
136
|
+
</div>
|
|
137
|
+
))}
|
|
138
|
+
</div>
|
|
139
|
+
</section>
|
|
140
|
+
</Container>
|
|
141
|
+
</div>
|
|
142
|
+
);
|
|
143
|
+
}
|
package/src/app/shell.tsx
CHANGED
|
@@ -5,8 +5,8 @@ import { Tabs, TabsContent, TabsList, TabsPanels, TabsTrigger } from "@behaviora
|
|
|
5
5
|
import { Sheet, SheetContent, SheetHeader, SheetTitle } from "@behavioral-agentic-design-system/core/components/ui/sheet";
|
|
6
6
|
import { Button } from "@behavioral-agentic-design-system/core/components/ui/button";
|
|
7
7
|
import {
|
|
8
|
-
Sun, Moon, BookOpen, X, ExternalLink, Menu,
|
|
9
|
-
House, Blocks,
|
|
8
|
+
Sun, Moon, BookOpen, X, ExternalLink, Menu, FlaskConical,
|
|
9
|
+
House, Blocks,
|
|
10
10
|
Type, Shapes, FileText, Layers as LayersIcon, Activity, GitCommitHorizontal, SlidersHorizontal as StudioIcon,
|
|
11
11
|
} from "lucide-react";
|
|
12
12
|
import registry from "@/layer-5-component-registry/component-registry.json";
|
|
@@ -31,7 +31,7 @@ function GithubMark({ className }: { className?: string }) {
|
|
|
31
31
|
);
|
|
32
32
|
}
|
|
33
33
|
import { brand } from "@/brand.config";
|
|
34
|
-
import Studio from "
|
|
34
|
+
import Studio from "../components/studio/studio";
|
|
35
35
|
import { LayersTab } from "@behavioral-agentic-design-system/core/components/layers-tab";
|
|
36
36
|
import { HomeTab } from "@behavioral-agentic-design-system/core/components/home-tab";
|
|
37
37
|
import { DocsTab } from "@behavioral-agentic-design-system/core/components/docs-tab";
|
|
@@ -221,12 +221,32 @@ export type ShellProps = {
|
|
|
221
221
|
* the default shape, or compose their own list (or splice into this one) when
|
|
222
222
|
* they need custom surfaces alongside the built-ins.
|
|
223
223
|
*/
|
|
224
|
+
/**
|
|
225
|
+
* Opens a recently added component where it is shown: a primitive on the Components tab, a composition in
|
|
226
|
+
* Studio's Cards. Studio reads its subject from the URL once at mount, so the address is set first (it covers a
|
|
227
|
+
* Studio not mounted yet) and a live event follows (it covers one already mounted), the same pairing the Docs
|
|
228
|
+
* tab uses for "bads:docs:navigate".
|
|
229
|
+
*/
|
|
230
|
+
function openRecent(kind: "primitive" | "composition", goToTab: (value: string) => void) {
|
|
231
|
+
if (kind === "primitive") {
|
|
232
|
+
goToTab("components");
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
try {
|
|
236
|
+
const url = new URL(window.location.href);
|
|
237
|
+
url.searchParams.set("subject", "cards");
|
|
238
|
+
window.history.replaceState({ ...window.history.state }, "", url);
|
|
239
|
+
window.dispatchEvent(new CustomEvent("bads:studio:subject", { detail: "cards" }));
|
|
240
|
+
} catch {}
|
|
241
|
+
goToTab("studio");
|
|
242
|
+
}
|
|
243
|
+
|
|
224
244
|
export const DEFAULT_TABS: ShellTab[] = [
|
|
225
|
-
{ value: "home", label: "Home", icon: House, render: ({ goToTab }) => <HomeTab onBrowseDocs={() => goToTab("docs")} onBrowseComponents={() => goToTab("components")} /> },
|
|
245
|
+
{ value: "home", label: "Home", icon: House, render: ({ goToTab }) => <HomeTab onBrowseDocs={() => goToTab("docs")} onBrowseComponents={() => goToTab("components")} onOpenRecent={(item) => openRecent(item.kind, goToTab)} /> },
|
|
226
246
|
|
|
227
247
|
// Studio absorbs what Customize, Cards and Dashboard used to be: you tune a
|
|
228
248
|
// value and the specimens beside it repaint, instead of navigating to find out.
|
|
229
|
-
{ value: "studio", label: "Studio", group: "build", icon: StudioIcon, render: () => <Studio /> },
|
|
249
|
+
{ value: "studio", label: "Studio", group: "build", icon: StudioIcon, render: ({ dark }) => <Studio dark={dark} /> },
|
|
230
250
|
{ value: "components", label: "Components", group: "build", icon: Blocks, count: COMPONENT_COUNT, render: ({ dark }) => <IframePreview dark={dark} src="/preview/components" title="Components preview" /> },
|
|
231
251
|
|
|
232
252
|
// Typography was a route with no way to reach it — /preview/typography has
|
|
@@ -259,7 +279,7 @@ export const DEFAULT_TABS: ShellTab[] = [
|
|
|
259
279
|
* Icons render at the system stroke width of 1.5 — see CLAUDE.md "Icons".
|
|
260
280
|
*/
|
|
261
281
|
const RAIL_ITEM =
|
|
262
|
-
"flex w-full min-h-
|
|
282
|
+
"relative flex w-full min-h-9 items-center gap-2.5 rounded-md px-2.5 py-1.5 text-sm font-medium transition-colors before:absolute before:inset-x-0 before:-inset-y-1 before:content-[''] data-[state=active]:bg-primary data-[state=active]:text-primary-foreground data-[state=inactive]:text-muted-foreground hover:data-[state=inactive]:bg-muted hover:data-[state=inactive]:text-foreground";
|
|
263
283
|
|
|
264
284
|
function RailTrigger({ tab, className }: { tab: ShellTab; className: string }) {
|
|
265
285
|
const Icon = tab.icon;
|
|
@@ -268,14 +288,34 @@ function RailTrigger({ tab, className }: { tab: ShellTab; className: string }) {
|
|
|
268
288
|
{Icon ? <Icon className="size-4 shrink-0" strokeWidth={1.5} /> : null}
|
|
269
289
|
<span className="min-w-0 flex-1 truncate text-left">{tab.label}</span>
|
|
270
290
|
{typeof tab.count === "number" ? (
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
291
|
+
// No explicit color here on purpose: it inherits from the trigger, exactly like the
|
|
292
|
+
// label span above it. RAIL_ITEM already sets the right color per data-state (muted when
|
|
293
|
+
// inactive, --primary-foreground when active). A hardcoded text-muted-foreground here
|
|
294
|
+
// used to win over that inheritance, so the count stayed muted-gray even on the active
|
|
295
|
+
// row's near-black bg-primary pill -- dark-gray-on-near-black, unreadable.
|
|
296
|
+
<span className="shrink-0 text-xs tabular-nums">{tab.count}</span>
|
|
274
297
|
) : null}
|
|
275
298
|
</TabsTrigger>
|
|
276
299
|
);
|
|
277
300
|
}
|
|
278
301
|
|
|
302
|
+
/** An external destination in the rail: same row as a tab, but a link that leaves the site. */
|
|
303
|
+
const RAIL_LINK =
|
|
304
|
+
"relative flex w-full min-h-9 items-center gap-2.5 rounded-md px-2.5 py-1.5 text-sm font-medium text-muted-foreground transition-colors before:absolute before:inset-x-0 before:-inset-y-1 before:content-[''] hover:bg-muted hover:text-foreground";
|
|
305
|
+
|
|
306
|
+
type RailLinkItem = { label: string; href: string; icon: React.ComponentType<{ className?: string; strokeWidth?: number }> };
|
|
307
|
+
|
|
308
|
+
function RailLink({ link }: { link: RailLinkItem }) {
|
|
309
|
+
const Icon = link.icon;
|
|
310
|
+
return (
|
|
311
|
+
<a href={link.href} target="_blank" rel="noreferrer" className={RAIL_LINK} aria-label={`${link.label} (opens in a new tab)`}>
|
|
312
|
+
<Icon className="size-4 shrink-0" strokeWidth={1.5} />
|
|
313
|
+
<span className="min-w-0 flex-1 truncate text-left">{link.label}</span>
|
|
314
|
+
<ExternalLink aria-hidden="true" className="size-3.5 shrink-0" strokeWidth={1.5} />
|
|
315
|
+
</a>
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
|
|
279
319
|
export function Shell({ tabs, defaultTab }: ShellProps) {
|
|
280
320
|
const initialTab = defaultTab ?? tabs[0]?.value ?? "home";
|
|
281
321
|
const [activeTab, setActiveTab] = useState(initialTab);
|
|
@@ -468,6 +508,8 @@ export function Shell({ tabs, defaultTab }: ShellProps) {
|
|
|
468
508
|
const inInactivePanel = (f: HTMLIFrameElement) =>
|
|
469
509
|
f.closest('[data-slot="tabs-content"]')?.getAttribute("data-state") === "inactive";
|
|
470
510
|
const syncIframe = (f: HTMLIFrameElement, isDark: boolean) => {
|
|
511
|
+
// Studio preview frames that own their theme (Light / Dark / Both).
|
|
512
|
+
if (f.dataset.themeIndependent === "true") return;
|
|
471
513
|
try {
|
|
472
514
|
f.contentDocument?.documentElement.classList.toggle("dark", isDark);
|
|
473
515
|
} catch {}
|
|
@@ -491,6 +533,73 @@ export function Shell({ tabs, defaultTab }: ShellProps) {
|
|
|
491
533
|
setDark(next);
|
|
492
534
|
return;
|
|
493
535
|
}
|
|
536
|
+
|
|
537
|
+
// A root-level View Transition snapshots only the host document's render
|
|
538
|
+
// tree — cross-document content (every IframePreview-backed tab) never
|
|
539
|
+
// gets rasterized into the ::view-transition pseudo tree, no matter when
|
|
540
|
+
// its theme class flips. syncVisibleIframes above exists to avoid a
|
|
541
|
+
// *stutter* (flip timing), which is orthogonal to this: the chrome wipes
|
|
542
|
+
// cleanly along the iris while the iframe's content just snaps to the new
|
|
543
|
+
// theme outside the animation entirely — a hard seam at the tab boundary.
|
|
544
|
+
// There's no way to pull iframe content into the host's snapshot, so an
|
|
545
|
+
// iframe-hosted active tab skips the iris and cross-fades color
|
|
546
|
+
// properties on host + iframe together instead: inject a brief transition
|
|
547
|
+
// into both documents, force a reflow so the pre-flip colors are the
|
|
548
|
+
// animation's start state, then flip. Non-iframe tabs (Home) keep the iris.
|
|
549
|
+
const activePanelHasIframe = !!document.querySelector(
|
|
550
|
+
'[role="tabpanel"][data-state="active"] iframe',
|
|
551
|
+
);
|
|
552
|
+
if (activePanelHasIframe) {
|
|
553
|
+
const CROSSFADE_MS = 340;
|
|
554
|
+
const css = `*,*::before,*::after{transition:background-color ${CROSSFADE_MS}ms ease,color ${CROSSFADE_MS}ms ease,border-color ${CROSSFADE_MS}ms ease,fill ${CROSSFADE_MS}ms ease,stroke ${CROSSFADE_MS}ms ease!important}`;
|
|
555
|
+
const styleTags: { doc: Document; style: HTMLStyleElement }[] = [];
|
|
556
|
+
const injectInto = (doc: Document) => {
|
|
557
|
+
try {
|
|
558
|
+
const style = doc.createElement("style");
|
|
559
|
+
style.textContent = css;
|
|
560
|
+
doc.head.appendChild(style);
|
|
561
|
+
styleTags.push({ doc, style });
|
|
562
|
+
} catch {}
|
|
563
|
+
};
|
|
564
|
+
injectInto(document);
|
|
565
|
+
const visibleIframeDocs: Document[] = [];
|
|
566
|
+
document.querySelectorAll<HTMLIFrameElement>("iframe").forEach((f) => {
|
|
567
|
+
if (inInactivePanel(f) || f.dataset.themeIndependent === "true") return;
|
|
568
|
+
try {
|
|
569
|
+
const doc = f.contentDocument;
|
|
570
|
+
if (doc) {
|
|
571
|
+
injectInto(doc);
|
|
572
|
+
visibleIframeDocs.push(doc);
|
|
573
|
+
}
|
|
574
|
+
} catch {}
|
|
575
|
+
});
|
|
576
|
+
// Force a synchronous reflow on every doc touched above so the pre-flip
|
|
577
|
+
// colors are the transition's baseline — otherwise the flip below and
|
|
578
|
+
// the injected transition could land in the same frame with no "from"
|
|
579
|
+
// state to fade from.
|
|
580
|
+
void document.body.offsetHeight;
|
|
581
|
+
visibleIframeDocs.forEach((doc) => {
|
|
582
|
+
try {
|
|
583
|
+
void doc.body?.offsetHeight;
|
|
584
|
+
} catch {}
|
|
585
|
+
});
|
|
586
|
+
syncHost();
|
|
587
|
+
syncVisibleIframes();
|
|
588
|
+
setDark(next);
|
|
589
|
+
window.setTimeout(() => {
|
|
590
|
+
styleTags.forEach(({ doc, style }) => {
|
|
591
|
+
try {
|
|
592
|
+
doc.head.removeChild(style);
|
|
593
|
+
} catch {}
|
|
594
|
+
});
|
|
595
|
+
// Converge any sticky-mounted-but-hidden iframes too, same as the
|
|
596
|
+
// iris path's deferred convergeAfterTeardown — they were invisible
|
|
597
|
+
// for this whole fade, so this repaint is free.
|
|
598
|
+
syncAllIframesToHost();
|
|
599
|
+
}, CROSSFADE_MS + 80);
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
|
|
494
603
|
root.style.setProperty("--x", `${event.clientX}px`);
|
|
495
604
|
root.style.setProperty("--y", `${event.clientY}px`);
|
|
496
605
|
// Exact wipe radius: distance from the click to the farthest viewport
|
|
@@ -585,6 +694,15 @@ export function Shell({ tabs, defaultTab }: ShellProps) {
|
|
|
585
694
|
? "http://localhost:6080"
|
|
586
695
|
: `/storybook/${process.env.NEXT_PUBLIC_STORYBOOK_VERSION || "dev"}/index.html`);
|
|
587
696
|
|
|
697
|
+
// External destinations that live in the rail instead of the footer: Storybook leads Reference, and any
|
|
698
|
+
// brand.headerLinks entry that names a `group` (upstream's Prototypes link names "build") joins that group.
|
|
699
|
+
// An entry without a group stays a footer button, which is what forks that set `headerLinks` already get.
|
|
700
|
+
const headerLinks = (brand as { headerLinks?: { label: string; href: string; group?: "build" | "foundations" | "reference" }[] }).headerLinks ?? [];
|
|
701
|
+
const railLinks: (RailLinkItem & { group: "build" | "foundations" | "reference"; at: "start" | "end" })[] = [
|
|
702
|
+
...headerLinks.filter((l) => l.group).map((l) => ({ label: l.label, href: l.href, icon: FlaskConical, group: l.group!, at: "end" as const })),
|
|
703
|
+
...(storybookUrl ? [{ label: "Storybook", href: storybookUrl, icon: BookOpen, group: "reference" as const, at: "start" as const }] : []),
|
|
704
|
+
];
|
|
705
|
+
|
|
588
706
|
// The GitHub link points at brand.repo, which 404s for anonymous visitors
|
|
589
707
|
// when the repo is private — so it stays dev-only. A fork with a public repo
|
|
590
708
|
// can drop `isDev &&` from its condition below.
|
|
@@ -632,7 +750,7 @@ export function Shell({ tabs, defaultTab }: ShellProps) {
|
|
|
632
750
|
>
|
|
633
751
|
{/* Mobile (<md): a compact bar. The rail is desktop-only; below md it
|
|
634
752
|
collapses into the Sheet drawer, as the tab strip used to. */}
|
|
635
|
-
<div className="flex h-14 shrink-0 items-center gap-2
|
|
753
|
+
<div className="flex h-14 shrink-0 items-center gap-2 bg-card px-4 md:hidden">
|
|
636
754
|
<Button
|
|
637
755
|
variant="ghost"
|
|
638
756
|
size="icon"
|
|
@@ -759,39 +877,54 @@ export function Shell({ tabs, defaultTab }: ShellProps) {
|
|
|
759
877
|
</div>
|
|
760
878
|
|
|
761
879
|
<nav aria-label="Sections" className="min-h-0 flex-1 overflow-y-auto px-3 py-3">
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
.
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
880
|
+
{/* One tablist per group, not one for the whole rail: a link is not a tab, and a tablist may
|
|
881
|
+
hold tabs only, so the external links sit between the lists inside their group. Rows are 36px
|
|
882
|
+
with a 44px hit area painted past them (RAIL_ITEM); the gap between groups is what makes
|
|
883
|
+
them read as groups, so it is wider than the gap between rows. */}
|
|
884
|
+
{tabs.some((t) => !t.group) ? (
|
|
885
|
+
<TabsList aria-label="Overview" className="flex h-auto w-full flex-col items-stretch gap-1 bg-transparent p-0">
|
|
886
|
+
{tabs
|
|
887
|
+
.filter((t) => !t.group)
|
|
888
|
+
.map((tab) => (
|
|
889
|
+
<RailTrigger key={tab.value} tab={tab} className={RAIL_ITEM} />
|
|
890
|
+
))}
|
|
891
|
+
</TabsList>
|
|
892
|
+
) : null}
|
|
893
|
+
{SHELL_GROUPS.map((group) => {
|
|
894
|
+
const groupTabs = tabs.filter((t) => t.group === group.id);
|
|
895
|
+
const links = railLinks.filter((l) => l.group === group.id);
|
|
896
|
+
if (groupTabs.length === 0 && links.length === 0) return null;
|
|
897
|
+
const labelId = `rail-group-${group.id}`;
|
|
898
|
+
return (
|
|
899
|
+
<div key={group.id} role="group" aria-labelledby={labelId} className="mt-6 flex flex-col gap-1">
|
|
900
|
+
<div id={labelId} className="px-2 pb-0.5 text-xs font-medium tracking-wider text-muted-foreground uppercase">
|
|
901
|
+
{group.label}
|
|
782
902
|
</div>
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
903
|
+
{links.filter((l) => l.at === "start").map((l) => (
|
|
904
|
+
<RailLink key={l.href} link={l} />
|
|
905
|
+
))}
|
|
906
|
+
{groupTabs.length > 0 ? (
|
|
907
|
+
<TabsList aria-label={group.label} className="flex h-auto w-full flex-col items-stretch gap-1 bg-transparent p-0">
|
|
908
|
+
{groupTabs.map((tab) => (
|
|
909
|
+
<RailTrigger key={tab.value} tab={tab} className={RAIL_ITEM} />
|
|
910
|
+
))}
|
|
911
|
+
</TabsList>
|
|
912
|
+
) : null}
|
|
913
|
+
{links.filter((l) => l.at !== "start").map((l) => (
|
|
914
|
+
<RailLink key={l.href} link={l} />
|
|
915
|
+
))}
|
|
916
|
+
</div>
|
|
917
|
+
);
|
|
918
|
+
})}
|
|
786
919
|
</nav>
|
|
787
920
|
|
|
788
921
|
<div className="shrink-0 p-3">
|
|
789
922
|
<div className="flex flex-wrap items-center gap-1.5 sm:gap-2 shrink-0">
|
|
790
|
-
{/* Fork-configurable header links — set `headerLinks` in brand.config
|
|
923
|
+
{/* Storybook, and any headerLinks entry that names a `group`, live in the rail now. Fork-configurable header links — set `headerLinks` in brand.config
|
|
791
924
|
to add buttons (e.g. a link to a fork's prototypes site) without
|
|
792
925
|
shadowing this shell. Read defensively so forks that don't set it
|
|
793
926
|
are unaffected. */}
|
|
794
|
-
{((brand as { headerLinks?: { label: string; href: string }[] }).headerLinks ?? []).map((link) => (
|
|
927
|
+
{((brand as { headerLinks?: { label: string; href: string; group?: string }[] }).headerLinks ?? []).filter((link) => !link.group).map((link) => (
|
|
795
928
|
<Button
|
|
796
929
|
key={link.href}
|
|
797
930
|
asChild
|
|
@@ -806,20 +939,6 @@ export function Shell({ tabs, defaultTab }: ShellProps) {
|
|
|
806
939
|
</a>
|
|
807
940
|
</Button>
|
|
808
941
|
))}
|
|
809
|
-
{storybookUrl && (
|
|
810
|
-
<Button
|
|
811
|
-
asChild
|
|
812
|
-
variant="ghost"
|
|
813
|
-
size="sm"
|
|
814
|
-
className="group h-8 gap-1.5 border border-foreground/30 hover:!bg-primary hover:!text-primary-foreground hover:border-primary"
|
|
815
|
-
title="Open Storybook"
|
|
816
|
-
>
|
|
817
|
-
<a href={storybookUrl} target="_blank" rel="noreferrer" aria-label="Open Storybook in a new tab">
|
|
818
|
-
<BookOpen className="h-4 w-4" strokeWidth={1.5} />
|
|
819
|
-
<span className="text-xs font-medium hidden sm:inline">Storybook</span>
|
|
820
|
-
</a>
|
|
821
|
-
</Button>
|
|
822
|
-
)}
|
|
823
942
|
{isDev && brand.repo && (
|
|
824
943
|
<Button
|
|
825
944
|
asChild
|
|
@@ -259,6 +259,7 @@ export const ReducedMotion: Story = {
|
|
|
259
259
|
{/* The transition only exists under no-preference, so reduced-motion
|
|
260
260
|
users get an instant jump — the point of this story. When disarmed
|
|
261
261
|
we also force transition:none so the snap-to-start never animates. */}
|
|
262
|
+
{/* allow-inline-style: this story's whole point is demonstrating the reduced-motion media-query gate via raw CSS. */}
|
|
262
263
|
<style>{`
|
|
263
264
|
@media (prefers-reduced-motion: no-preference) {
|
|
264
265
|
.reduced-motion-demo[data-armed="true"] {
|