@behavioral-agentic-design-system/core 0.42.0 → 0.47.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 +38 -8
- package/scripts/a11y-lint.cjs +101 -14
- package/scripts/bads-sync.mjs +1 -1
- package/scripts/build-tokens.cjs +122 -7
- package/scripts/check-dark-contrast.mjs +204 -0
- package/scripts/check-flush-edges.mjs +245 -0
- package/scripts/check-spec.mjs +73 -0
- package/scripts/deal-directions.mjs +186 -0
- package/scripts/design-system-advisory/README.md +239 -0
- package/scripts/design-system-advisory/check-copy-punctuation.mjs +44 -0
- package/scripts/design-system-advisory/check-even-padding.mjs +35 -0
- package/scripts/design-system-advisory/check-hand-built-button.mjs +46 -0
- package/scripts/design-system-advisory/check-html-nesting.mjs +51 -0
- package/scripts/design-system-advisory/check-icon-sizing.mjs +79 -0
- package/scripts/design-system-advisory/check-label-case.mjs +92 -0
- package/scripts/design-system-advisory/check-native-form-controls.mjs +53 -0
- package/scripts/design-system-advisory/check-radius.mjs +56 -0
- package/scripts/design-system-advisory/check-raw-values.mjs +61 -0
- package/scripts/design-system-advisory/check-small-text.mjs +72 -0
- package/scripts/design-system-advisory/check-tap-target.mjs +70 -0
- package/scripts/design-system-advisory/defaults.mjs +90 -0
- package/scripts/design-system-advisory/fixtures/clean.tsx.fixture +12 -0
- package/scripts/design-system-advisory/fixtures/violations.tsx.fixture +19 -0
- package/scripts/design-system-advisory/lib.mjs +255 -0
- package/scripts/design-system-advisory/run.mjs +189 -0
- package/scripts/design-system-advisory/workflow.yml +82 -0
- package/scripts/health-report.mjs +20 -14
- package/scripts/lib/copy-strings.mjs +146 -0
- package/scripts/lib/counted-lint.mjs +100 -0
- package/scripts/lib/dark-contrast.mjs +120 -0
- package/scripts/lib/flush-edges.mjs +294 -0
- package/scripts/lib/lab-lint.mjs +62 -0
- package/scripts/lib/marketing-library.mjs +129 -0
- package/scripts/lib/mount-page.mjs +25 -0
- package/scripts/lib/on-system.mjs +249 -0
- package/scripts/lib/random.mjs +22 -0
- package/scripts/lib/source-scan.mjs +173 -0
- package/scripts/lib/spec-parse.d.mts +25 -0
- package/scripts/lib/spec-parse.mjs +188 -0
- package/scripts/lib/tells.mjs +366 -0
- package/scripts/lint-arbitrary-tokens.mjs +47 -0
- package/scripts/lint-component-token-refs.mjs +63 -0
- package/scripts/lint-content-hierarchy.mjs +114 -0
- package/scripts/lint-control-baseline.mjs +72 -0
- package/scripts/lint-copy-punctuation.mjs +60 -0
- package/scripts/lint-css-vars.mjs +175 -0
- package/scripts/lint-even-padding.mjs +58 -0
- package/scripts/lint-html-nesting.mjs +116 -0
- package/scripts/lint-label-case.mjs +219 -0
- package/scripts/lint-live-ctas.mjs +138 -0
- package/scripts/lint-microanimation.mjs +2 -2
- package/scripts/lint-proximity.mjs +181 -0
- package/scripts/lint-slop.mjs +1 -1
- package/scripts/lint-spacing-scale.mjs +78 -0
- package/scripts/lint-target-size.cjs +132 -0
- package/scripts/lint-token-primitives.mjs +307 -0
- package/scripts/on-system-score.mjs +95 -0
- package/scripts/size-audit.cjs +2 -2
- package/scripts/slop-rules.mjs +1 -1
- package/scripts/source-images.mjs +180 -0
- package/scripts/ux-tells.mjs +80 -0
- package/scripts/wcag-audit.cjs +25 -4
- 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 +9 -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/api/site-auth.ts +14 -2
- package/src/app/layout.tsx +6 -0
- package/src/app/preview/canvas/page.tsx +12 -0
- package/src/app/preview/components/page.tsx +828 -14
- package/src/app/preview/sticker-sheet/page.tsx +329 -0
- package/src/app/preview/sticker-sheet/specimens.tsx +296 -0
- package/src/app/preview/studio/blank-screen.tsx +143 -0
- package/src/app/preview/studio/page.tsx +7 -0
- package/src/app/shell.tsx +164 -47
- package/src/components/Foundations/Colors.stories.tsx +119 -8
- 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/docs-tab.tsx +7 -7
- package/src/components/home-recent.tsx +73 -0
- package/src/components/home-tab.tsx +19 -14
- package/src/components/layers-tab.tsx +2 -2
- package/src/components/markdown-preview.tsx +60 -12
- package/src/components/onboarding-wizard.tsx +1 -1
- 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 +133 -128
- 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/autocomplete.tsx +1 -1
- package/src/components/ui/avatar.tsx +4 -0
- package/src/components/ui/chart.tsx +134 -42
- package/src/components/ui/checkbox-group.tsx +1 -1
- package/src/components/ui/checkbox.tsx +1 -1
- package/src/components/ui/color-picker.tsx +20 -4
- package/src/components/ui/combobox.tsx +1 -0
- package/src/components/ui/command.tsx +1 -1
- package/src/components/ui/data-table.tsx +64 -3
- package/src/components/ui/date-field.tsx +1 -1
- package/src/components/ui/date-picker.tsx +2 -0
- package/src/components/ui/date-range-picker.tsx +4 -0
- package/src/components/ui/editable.tsx +1 -0
- package/src/components/ui/faceted-filter.tsx +187 -0
- package/src/components/ui/file-upload.tsx +21 -2
- package/src/components/ui/gauge-chart.tsx +18 -4
- package/src/components/ui/heatmap.tsx +3 -1
- package/src/components/ui/inline-edit.tsx +175 -0
- package/src/components/ui/input-group.tsx +5 -2
- package/src/components/ui/month-picker.tsx +1 -1
- package/src/components/ui/multi-select.tsx +1 -0
- package/src/components/ui/number-input.tsx +28 -5
- package/src/components/ui/otp-input.tsx +208 -0
- package/src/components/ui/phone-input.tsx +274 -0
- package/src/components/ui/radio-group.tsx +2 -2
- package/src/components/ui/search-input.tsx +1 -1
- package/src/components/ui/sparkline.tsx +33 -4
- package/src/components/ui/spinner.tsx +23 -4
- package/src/components/ui/table.tsx +9 -0
- package/src/components/ui/tags-input.tsx +1 -1
- package/src/components/ui/timer.tsx +1 -0
- package/src/components/ui/transfer-list.tsx +13 -26
- package/src/components/ui/week-picker.tsx +1 -13
- package/src/components/ui/year-picker.tsx +1 -1
- package/src/data/component-added.json +966 -0
- package/src/data/docs-index.ts +35 -2
- package/src/data/history.json +161 -161
- package/src/data/sticker-sheet.json +9244 -0
- package/src/docs-trace-globs.json +1 -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/chart-motion.ts +41 -0
- package/src/lib/get-icon-color.ts +1 -1
- package/src/lib/spec-parse.ts +4 -0
- package/src/lib/svg-sanitize.ts +19 -9
- package/src/stories/Accordion.stories.tsx +7 -0
- package/src/stories/ActionBar.stories.tsx +5 -0
- package/src/stories/Affix.stories.tsx +4 -0
- package/src/stories/AiBadge.stories.tsx +9 -7
- package/src/stories/Alert.stories.tsx +13 -0
- package/src/stories/AlertDialog.stories.tsx +4 -0
- package/src/stories/Anchor.stories.tsx +5 -0
- package/src/stories/AngleSlider.stories.tsx +6 -3
- package/src/stories/AspectRatio.stories.tsx +4 -0
- package/src/stories/Autocomplete.stories.tsx +8 -0
- package/src/stories/Avatar.stories.tsx +10 -0
- package/src/stories/Badge.stories.tsx +14 -6
- package/src/stories/Blockquote.stories.tsx +6 -0
- package/src/stories/BottomNavigation.stories.tsx +4 -0
- package/src/stories/Breadcrumb.stories.tsx +3 -0
- package/src/stories/Burger.stories.tsx +1 -0
- package/src/stories/Button.stories.tsx +24 -0
- package/src/stories/ButtonGroup.stories.tsx +9 -0
- package/src/stories/Calendar.stories.tsx +3 -0
- package/src/stories/Canvas.stories.tsx +45 -0
- package/src/stories/Card.stories.tsx +4 -0
- package/src/stories/Carousel.stories.tsx +6 -0
- package/src/stories/Cascader.stories.tsx +4 -0
- package/src/stories/Chart.stories.tsx +46 -1
- package/src/stories/ChatBubble.stories.tsx +8 -2
- package/src/stories/ChatMarker.stories.tsx +1 -0
- package/src/stories/Checkbox.stories.tsx +40 -0
- package/src/stories/CheckboxCard.stories.tsx +8 -0
- package/src/stories/CheckboxGroup.stories.tsx +19 -0
- package/src/stories/Chip.stories.tsx +10 -19
- package/src/stories/CircularProgress.stories.tsx +13 -27
- package/src/stories/Clipboard.stories.tsx +6 -0
- package/src/stories/CloseButton.stories.tsx +6 -4
- package/src/stories/Code.stories.tsx +8 -1
- package/src/stories/Collapsible.stories.tsx +2 -0
- package/src/stories/ColorPicker.stories.tsx +46 -0
- package/src/stories/ColorSwatch.stories.tsx +1 -0
- package/src/stories/Combobox.stories.tsx +9 -0
- package/src/stories/Command.stories.tsx +2 -0
- package/src/stories/Container.stories.tsx +8 -0
- package/src/stories/ContextMenu.stories.tsx +9 -0
- package/src/stories/CopyButton.stories.tsx +12 -36
- package/src/stories/DataList.stories.tsx +8 -0
- package/src/stories/DataTable.stories.tsx +39 -0
- package/src/stories/DateField.stories.tsx +28 -0
- package/src/stories/DatePicker.stories.tsx +34 -0
- package/src/stories/DateRangePicker.stories.tsx +32 -0
- package/src/stories/Dialog.stories.tsx +8 -0
- package/src/stories/Drawer.stories.tsx +6 -0
- package/src/stories/DropdownMenu.stories.tsx +2 -0
- package/src/stories/Editable.stories.tsx +12 -0
- package/src/stories/EmptyState.stories.tsx +9 -0
- package/src/stories/FacetedFilter.stories.tsx +197 -0
- package/src/stories/Field.stories.tsx +7 -0
- package/src/stories/Fieldset.stories.tsx +8 -0
- package/src/stories/FileButton.stories.tsx +4 -0
- package/src/stories/FileUpload.stories.tsx +16 -17
- package/src/stories/FloatLabel.stories.tsx +3 -8
- package/src/stories/FloatingActionButton.stories.tsx +10 -0
- package/src/stories/FloatingIndicator.stories.tsx +4 -0
- package/src/stories/FloatingPanel.stories.tsx +6 -0
- package/src/stories/FocusTrap.stories.tsx +5 -0
- package/src/stories/FormatByte.stories.tsx +6 -0
- package/src/stories/FormatDate.stories.tsx +8 -0
- package/src/stories/FormatNumber.stories.tsx +9 -0
- package/src/stories/GaugeChart.stories.tsx +9 -3
- package/src/stories/Heatmap.stories.tsx +11 -0
- package/src/stories/Highlight.stories.tsx +6 -0
- package/src/stories/HoverCard.stories.tsx +4 -0
- package/src/stories/Image.stories.tsx +9 -0
- package/src/stories/Indicator.stories.tsx +19 -0
- package/src/stories/InlineEdit.stories.tsx +106 -0
- package/src/stories/Input.stories.tsx +7 -0
- package/src/stories/InputClearButton.stories.tsx +3 -0
- package/src/stories/InputGroup.stories.tsx +40 -0
- package/src/stories/Kbd.stories.tsx +7 -1
- package/src/stories/KeyboardShortcut.stories.tsx +2 -0
- package/src/stories/Label.stories.tsx +2 -0
- package/src/stories/Link.stories.tsx +9 -0
- package/src/stories/List.stories.tsx +8 -0
- package/src/stories/Listbox.stories.tsx +1 -0
- package/src/stories/LoadingDots.stories.tsx +5 -3
- package/src/stories/LoadingOverlay.stories.tsx +5 -1
- package/src/stories/Mark.stories.tsx +5 -0
- package/src/stories/MarkdownPreview.stories.tsx +53 -0
- package/src/stories/Marquee.stories.tsx +4 -0
- package/src/stories/Masonry.stories.tsx +5 -0
- package/src/stories/Menubar.stories.tsx +3 -0
- package/src/stories/Meter.stories.tsx +11 -17
- package/src/stories/MonthPicker.stories.tsx +26 -1
- package/src/stories/MotionToggle.stories.tsx +1 -0
- package/src/stories/MultiSelect.stories.tsx +9 -0
- package/src/stories/NativeSelect.stories.tsx +1 -0
- package/src/stories/NavLink.stories.tsx +7 -0
- package/src/stories/NavigationMenu.stories.tsx +5 -0
- package/src/stories/NavigationRail.stories.tsx +10 -0
- package/src/stories/Notification.stories.tsx +13 -34
- package/src/stories/NumberInput.stories.tsx +33 -1
- package/src/stories/OtpInput.stories.tsx +110 -0
- package/src/stories/Overlay.stories.tsx +5 -1
- package/src/stories/Pagination.stories.tsx +8 -0
- package/src/stories/PasswordInput.stories.tsx +2 -0
- package/src/stories/PhoneInput.stories.tsx +127 -0
- package/src/stories/PinInput.stories.tsx +9 -2
- package/src/stories/Popover.stories.tsx +2 -0
- package/src/stories/Progress.stories.tsx +6 -1
- package/src/stories/Prose.stories.tsx +8 -0
- package/src/stories/QrCode.stories.tsx +2 -0
- package/src/stories/Questionnaire.stories.tsx +7 -0
- package/src/stories/RadioGroup.stories.tsx +40 -0
- package/src/stories/RatingGroup.stories.tsx +8 -4
- package/src/stories/Resizable.stories.tsx +4 -2
- package/src/stories/Result.stories.tsx +3 -0
- package/src/stories/Reveal.stories.tsx +2 -0
- package/src/stories/RollingNumber.stories.tsx +5 -0
- package/src/stories/ScrollArea.stories.tsx +3 -1
- package/src/stories/SearchInput.stories.tsx +10 -6
- package/src/stories/SegmentedControl.stories.tsx +11 -0
- package/src/stories/Select.stories.tsx +7 -0
- package/src/stories/Separator.stories.tsx +6 -0
- package/src/stories/Sheet.stories.tsx +5 -0
- package/src/stories/Sidebar.stories.tsx +40 -1
- package/src/stories/SimpleGrid.stories.tsx +5 -0
- package/src/stories/Skeleton.stories.tsx +8 -0
- package/src/stories/SkeletonTable.stories.tsx +6 -5
- package/src/stories/SkipLink.stories.tsx +3 -0
- package/src/stories/Slider.stories.tsx +2 -1
- package/src/stories/Sonner.stories.tsx +7 -0
- package/src/stories/Sparkline.stories.tsx +14 -1
- package/src/stories/Spinner.stories.tsx +20 -10
- package/src/stories/Spoiler.stories.tsx +5 -0
- package/src/stories/Squircle.stories.tsx +7 -0
- package/src/stories/Stack.stories.tsx +7 -0
- package/src/stories/StatusBadge.stories.tsx +12 -6
- package/src/stories/Stepper.stories.tsx +5 -0
- package/src/stories/Switch.stories.tsx +4 -0
- package/src/stories/Table.stories.tsx +10 -1
- package/src/stories/Tabs.stories.tsx +8 -0
- package/src/stories/Tag.stories.tsx +13 -5
- package/src/stories/TagsInput.stories.tsx +15 -0
- package/src/stories/Text.stories.tsx +12 -0
- package/src/stories/Textarea.stories.tsx +9 -0
- package/src/stories/ThemeIcon.stories.tsx +6 -3
- package/src/stories/TimePicker.stories.tsx +2 -0
- package/src/stories/Timeline.stories.tsx +12 -0
- package/src/stories/Timer.stories.tsx +30 -0
- package/src/stories/Toggle.stories.tsx +7 -5
- package/src/stories/ToggleGroup.stories.tsx +5 -0
- package/src/stories/ToggleTip.stories.tsx +4 -0
- package/src/stories/Toolbar.stories.tsx +6 -0
- package/src/stories/Tooltip.stories.tsx +3 -0
- package/src/stories/Tour.stories.tsx +3 -0
- package/src/stories/TransferList.stories.tsx +7 -0
- package/src/stories/TreeSelect.stories.tsx +4 -0
- package/src/stories/TreeView.stories.tsx +5 -0
- package/src/stories/TypingIndicator.stories.tsx +4 -0
- package/src/stories/VisuallyHidden.stories.tsx +3 -0
- package/src/stories/Watermark.stories.tsx +6 -0
- package/src/stories/WeekPicker.stories.tsx +25 -1
- package/src/stories/WordRotate.stories.tsx +5 -0
- package/src/stories/YearPicker.stories.tsx +26 -11
- package/src/stories/story-groups.json +22 -16
- package/src/styles.css +50 -2
- package/src/tokens.json +86 -58
|
@@ -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, SwatchBook,
|
|
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";
|
|
@@ -221,13 +221,34 @@ 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" /> },
|
|
251
|
+
{ value: "sticker-sheet", label: "Sticker sheet", group: "build", icon: SwatchBook, noPreload: true, render: () => <IframePreview dark={false} src="/preview/sticker-sheet" title="Sticker sheet preview" /> },
|
|
231
252
|
|
|
232
253
|
// Typography was a route with no way to reach it — /preview/typography has
|
|
233
254
|
// rendered fine and been unlinked. The Foundations group is where it belongs.
|
|
@@ -256,10 +277,10 @@ export const DEFAULT_TABS: ShellTab[] = [
|
|
|
256
277
|
|
|
257
278
|
/**
|
|
258
279
|
* A rail destination: glyph, label, and (only when genuinely derived) a count.
|
|
259
|
-
* Icons render at the system stroke width of 1.5 — see
|
|
280
|
+
* Icons render at the system stroke width of 1.5 — see AGENTS.md "Icons".
|
|
260
281
|
*/
|
|
261
282
|
const RAIL_ITEM =
|
|
262
|
-
"flex w-full min-h-
|
|
283
|
+
"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
284
|
|
|
264
285
|
function RailTrigger({ tab, className }: { tab: ShellTab; className: string }) {
|
|
265
286
|
const Icon = tab.icon;
|
|
@@ -279,6 +300,23 @@ function RailTrigger({ tab, className }: { tab: ShellTab; className: string }) {
|
|
|
279
300
|
);
|
|
280
301
|
}
|
|
281
302
|
|
|
303
|
+
/** An external destination in the rail: same row as a tab, but a link that leaves the site. */
|
|
304
|
+
const RAIL_LINK =
|
|
305
|
+
"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";
|
|
306
|
+
|
|
307
|
+
type RailLinkItem = { label: string; href: string; icon: React.ComponentType<{ className?: string; strokeWidth?: number }> };
|
|
308
|
+
|
|
309
|
+
function RailLink({ link }: { link: RailLinkItem }) {
|
|
310
|
+
const Icon = link.icon;
|
|
311
|
+
return (
|
|
312
|
+
<a href={link.href} target="_blank" rel="noreferrer" className={RAIL_LINK} aria-label={`${link.label} (opens in a new tab)`}>
|
|
313
|
+
<Icon className="size-4 shrink-0" strokeWidth={1.5} />
|
|
314
|
+
<span className="min-w-0 flex-1 truncate text-left">{link.label}</span>
|
|
315
|
+
<ExternalLink aria-hidden="true" className="size-3.5 shrink-0" strokeWidth={1.5} />
|
|
316
|
+
</a>
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
|
|
282
320
|
export function Shell({ tabs, defaultTab }: ShellProps) {
|
|
283
321
|
const initialTab = defaultTab ?? tabs[0]?.value ?? "home";
|
|
284
322
|
const [activeTab, setActiveTab] = useState(initialTab);
|
|
@@ -471,6 +509,8 @@ export function Shell({ tabs, defaultTab }: ShellProps) {
|
|
|
471
509
|
const inInactivePanel = (f: HTMLIFrameElement) =>
|
|
472
510
|
f.closest('[data-slot="tabs-content"]')?.getAttribute("data-state") === "inactive";
|
|
473
511
|
const syncIframe = (f: HTMLIFrameElement, isDark: boolean) => {
|
|
512
|
+
// Studio preview frames that own their theme (Light / Dark / Both).
|
|
513
|
+
if (f.dataset.themeIndependent === "true") return;
|
|
474
514
|
try {
|
|
475
515
|
f.contentDocument?.documentElement.classList.toggle("dark", isDark);
|
|
476
516
|
} catch {}
|
|
@@ -494,6 +534,73 @@ export function Shell({ tabs, defaultTab }: ShellProps) {
|
|
|
494
534
|
setDark(next);
|
|
495
535
|
return;
|
|
496
536
|
}
|
|
537
|
+
|
|
538
|
+
// A root-level View Transition snapshots only the host document's render
|
|
539
|
+
// tree — cross-document content (every IframePreview-backed tab) never
|
|
540
|
+
// gets rasterized into the ::view-transition pseudo tree, no matter when
|
|
541
|
+
// its theme class flips. syncVisibleIframes above exists to avoid a
|
|
542
|
+
// *stutter* (flip timing), which is orthogonal to this: the chrome wipes
|
|
543
|
+
// cleanly along the iris while the iframe's content just snaps to the new
|
|
544
|
+
// theme outside the animation entirely — a hard seam at the tab boundary.
|
|
545
|
+
// There's no way to pull iframe content into the host's snapshot, so an
|
|
546
|
+
// iframe-hosted active tab skips the iris and cross-fades color
|
|
547
|
+
// properties on host + iframe together instead: inject a brief transition
|
|
548
|
+
// into both documents, force a reflow so the pre-flip colors are the
|
|
549
|
+
// animation's start state, then flip. Non-iframe tabs (Home) keep the iris.
|
|
550
|
+
const activePanelHasIframe = !!document.querySelector(
|
|
551
|
+
'[role="tabpanel"][data-state="active"] iframe',
|
|
552
|
+
);
|
|
553
|
+
if (activePanelHasIframe) {
|
|
554
|
+
const CROSSFADE_MS = 340;
|
|
555
|
+
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}`;
|
|
556
|
+
const styleTags: { doc: Document; style: HTMLStyleElement }[] = [];
|
|
557
|
+
const injectInto = (doc: Document) => {
|
|
558
|
+
try {
|
|
559
|
+
const style = doc.createElement("style");
|
|
560
|
+
style.textContent = css;
|
|
561
|
+
doc.head.appendChild(style);
|
|
562
|
+
styleTags.push({ doc, style });
|
|
563
|
+
} catch {}
|
|
564
|
+
};
|
|
565
|
+
injectInto(document);
|
|
566
|
+
const visibleIframeDocs: Document[] = [];
|
|
567
|
+
document.querySelectorAll<HTMLIFrameElement>("iframe").forEach((f) => {
|
|
568
|
+
if (inInactivePanel(f) || f.dataset.themeIndependent === "true") return;
|
|
569
|
+
try {
|
|
570
|
+
const doc = f.contentDocument;
|
|
571
|
+
if (doc) {
|
|
572
|
+
injectInto(doc);
|
|
573
|
+
visibleIframeDocs.push(doc);
|
|
574
|
+
}
|
|
575
|
+
} catch {}
|
|
576
|
+
});
|
|
577
|
+
// Force a synchronous reflow on every doc touched above so the pre-flip
|
|
578
|
+
// colors are the transition's baseline — otherwise the flip below and
|
|
579
|
+
// the injected transition could land in the same frame with no "from"
|
|
580
|
+
// state to fade from.
|
|
581
|
+
void document.body.offsetHeight;
|
|
582
|
+
visibleIframeDocs.forEach((doc) => {
|
|
583
|
+
try {
|
|
584
|
+
void doc.body?.offsetHeight;
|
|
585
|
+
} catch {}
|
|
586
|
+
});
|
|
587
|
+
syncHost();
|
|
588
|
+
syncVisibleIframes();
|
|
589
|
+
setDark(next);
|
|
590
|
+
window.setTimeout(() => {
|
|
591
|
+
styleTags.forEach(({ doc, style }) => {
|
|
592
|
+
try {
|
|
593
|
+
doc.head.removeChild(style);
|
|
594
|
+
} catch {}
|
|
595
|
+
});
|
|
596
|
+
// Converge any sticky-mounted-but-hidden iframes too, same as the
|
|
597
|
+
// iris path's deferred convergeAfterTeardown — they were invisible
|
|
598
|
+
// for this whole fade, so this repaint is free.
|
|
599
|
+
syncAllIframesToHost();
|
|
600
|
+
}, CROSSFADE_MS + 80);
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
|
|
497
604
|
root.style.setProperty("--x", `${event.clientX}px`);
|
|
498
605
|
root.style.setProperty("--y", `${event.clientY}px`);
|
|
499
606
|
// Exact wipe radius: distance from the click to the farthest viewport
|
|
@@ -588,6 +695,15 @@ export function Shell({ tabs, defaultTab }: ShellProps) {
|
|
|
588
695
|
? "http://localhost:6080"
|
|
589
696
|
: `/storybook/${process.env.NEXT_PUBLIC_STORYBOOK_VERSION || "dev"}/index.html`);
|
|
590
697
|
|
|
698
|
+
// External destinations that live in the rail instead of the footer: Storybook leads Reference, and any
|
|
699
|
+
// brand.headerLinks entry that names a `group` (upstream's Prototypes link names "build") joins that group.
|
|
700
|
+
// An entry without a group stays a footer button, which is what forks that set `headerLinks` already get.
|
|
701
|
+
const headerLinks = (brand as { headerLinks?: { label: string; href: string; group?: "build" | "foundations" | "reference" }[] }).headerLinks ?? [];
|
|
702
|
+
const railLinks: (RailLinkItem & { group: "build" | "foundations" | "reference"; at: "start" | "end" })[] = [
|
|
703
|
+
...headerLinks.filter((l) => l.group).map((l) => ({ label: l.label, href: l.href, icon: FlaskConical, group: l.group!, at: "end" as const })),
|
|
704
|
+
...(storybookUrl ? [{ label: "Storybook", href: storybookUrl, icon: BookOpen, group: "reference" as const, at: "start" as const }] : []),
|
|
705
|
+
];
|
|
706
|
+
|
|
591
707
|
// The GitHub link points at brand.repo, which 404s for anonymous visitors
|
|
592
708
|
// when the repo is private — so it stays dev-only. A fork with a public repo
|
|
593
709
|
// can drop `isDev &&` from its condition below.
|
|
@@ -635,7 +751,7 @@ export function Shell({ tabs, defaultTab }: ShellProps) {
|
|
|
635
751
|
>
|
|
636
752
|
{/* Mobile (<md): a compact bar. The rail is desktop-only; below md it
|
|
637
753
|
collapses into the Sheet drawer, as the tab strip used to. */}
|
|
638
|
-
<div className="flex h-14 shrink-0 items-center gap-2
|
|
754
|
+
<div className="flex h-14 shrink-0 items-center gap-2 bg-card px-4 md:hidden">
|
|
639
755
|
<Button
|
|
640
756
|
variant="ghost"
|
|
641
757
|
size="icon"
|
|
@@ -715,7 +831,7 @@ export function Shell({ tabs, defaultTab }: ShellProps) {
|
|
|
715
831
|
{/* Desktop (md+): the rail. It is a flex SIBLING with shrink-0, not a
|
|
716
832
|
sticky or fixed element, so it rides the root View Transition
|
|
717
833
|
snapshot exactly as the old header did and needs no
|
|
718
|
-
view-transition-name. Naming it would be the trap
|
|
834
|
+
view-transition-name. Naming it would be the trap docs/agent-rules/theme-transition-and-sticky-chrome.md
|
|
719
835
|
documents under "Theme transition and sticky chrome", not the fix.
|
|
720
836
|
The panel area scrolls inside itself, which is what keeps the rail
|
|
721
837
|
out of sticky-chrome territory in the first place. */}
|
|
@@ -762,39 +878,54 @@ export function Shell({ tabs, defaultTab }: ShellProps) {
|
|
|
762
878
|
</div>
|
|
763
879
|
|
|
764
880
|
<nav aria-label="Sections" className="min-h-0 flex-1 overflow-y-auto px-3 py-3">
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
.
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
881
|
+
{/* One tablist per group, not one for the whole rail: a link is not a tab, and a tablist may
|
|
882
|
+
hold tabs only, so the external links sit between the lists inside their group. Rows are 36px
|
|
883
|
+
with a 44px hit area painted past them (RAIL_ITEM); the gap between groups is what makes
|
|
884
|
+
them read as groups, so it is wider than the gap between rows. */}
|
|
885
|
+
{tabs.some((t) => !t.group) ? (
|
|
886
|
+
<TabsList aria-label="Overview" className="flex h-auto w-full flex-col items-stretch gap-1 bg-transparent p-0">
|
|
887
|
+
{tabs
|
|
888
|
+
.filter((t) => !t.group)
|
|
889
|
+
.map((tab) => (
|
|
890
|
+
<RailTrigger key={tab.value} tab={tab} className={RAIL_ITEM} />
|
|
891
|
+
))}
|
|
892
|
+
</TabsList>
|
|
893
|
+
) : null}
|
|
894
|
+
{SHELL_GROUPS.map((group) => {
|
|
895
|
+
const groupTabs = tabs.filter((t) => t.group === group.id);
|
|
896
|
+
const links = railLinks.filter((l) => l.group === group.id);
|
|
897
|
+
if (groupTabs.length === 0 && links.length === 0) return null;
|
|
898
|
+
const labelId = `rail-group-${group.id}`;
|
|
899
|
+
return (
|
|
900
|
+
<div key={group.id} role="group" aria-labelledby={labelId} className="mt-6 flex flex-col gap-1">
|
|
901
|
+
<div id={labelId} className="px-2 pb-0.5 text-xs font-medium tracking-wider text-muted-foreground uppercase">
|
|
902
|
+
{group.label}
|
|
785
903
|
</div>
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
904
|
+
{links.filter((l) => l.at === "start").map((l) => (
|
|
905
|
+
<RailLink key={l.href} link={l} />
|
|
906
|
+
))}
|
|
907
|
+
{groupTabs.length > 0 ? (
|
|
908
|
+
<TabsList aria-label={group.label} className="flex h-auto w-full flex-col items-stretch gap-1 bg-transparent p-0">
|
|
909
|
+
{groupTabs.map((tab) => (
|
|
910
|
+
<RailTrigger key={tab.value} tab={tab} className={RAIL_ITEM} />
|
|
911
|
+
))}
|
|
912
|
+
</TabsList>
|
|
913
|
+
) : null}
|
|
914
|
+
{links.filter((l) => l.at !== "start").map((l) => (
|
|
915
|
+
<RailLink key={l.href} link={l} />
|
|
916
|
+
))}
|
|
917
|
+
</div>
|
|
918
|
+
);
|
|
919
|
+
})}
|
|
789
920
|
</nav>
|
|
790
921
|
|
|
791
922
|
<div className="shrink-0 p-3">
|
|
792
923
|
<div className="flex flex-wrap items-center gap-1.5 sm:gap-2 shrink-0">
|
|
793
|
-
{/* Fork-configurable header links — set `headerLinks` in brand.config
|
|
924
|
+
{/* Storybook, and any headerLinks entry that names a `group`, live in the rail now. Fork-configurable header links — set `headerLinks` in brand.config
|
|
794
925
|
to add buttons (e.g. a link to a fork's prototypes site) without
|
|
795
926
|
shadowing this shell. Read defensively so forks that don't set it
|
|
796
927
|
are unaffected. */}
|
|
797
|
-
{((brand as { headerLinks?: { label: string; href: string }[] }).headerLinks ?? []).map((link) => (
|
|
928
|
+
{((brand as { headerLinks?: { label: string; href: string; group?: string }[] }).headerLinks ?? []).filter((link) => !link.group).map((link) => (
|
|
798
929
|
<Button
|
|
799
930
|
key={link.href}
|
|
800
931
|
asChild
|
|
@@ -809,20 +940,6 @@ export function Shell({ tabs, defaultTab }: ShellProps) {
|
|
|
809
940
|
</a>
|
|
810
941
|
</Button>
|
|
811
942
|
))}
|
|
812
|
-
{storybookUrl && (
|
|
813
|
-
<Button
|
|
814
|
-
asChild
|
|
815
|
-
variant="ghost"
|
|
816
|
-
size="sm"
|
|
817
|
-
className="group h-8 gap-1.5 border border-foreground/30 hover:!bg-primary hover:!text-primary-foreground hover:border-primary"
|
|
818
|
-
title="Open Storybook"
|
|
819
|
-
>
|
|
820
|
-
<a href={storybookUrl} target="_blank" rel="noreferrer" aria-label="Open Storybook in a new tab">
|
|
821
|
-
<BookOpen className="h-4 w-4" strokeWidth={1.5} />
|
|
822
|
-
<span className="text-xs font-medium hidden sm:inline">Storybook</span>
|
|
823
|
-
</a>
|
|
824
|
-
</Button>
|
|
825
|
-
)}
|
|
826
943
|
{isDev && brand.repo && (
|
|
827
944
|
<Button
|
|
828
945
|
asChild
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
|
+
import { useLayoutEffect, useRef, useState } from "react";
|
|
3
|
+
import { expect, waitFor } from "storybook/test";
|
|
2
4
|
|
|
3
5
|
const meta: Meta = {
|
|
4
6
|
title: "Foundations/Colors",
|
|
5
7
|
parameters: {
|
|
6
8
|
layout: "fullscreen",
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
// pairs stay enforced by `pnpm wcag:audit` (AAA) and the rest of CI.
|
|
13
|
-
a11y: { config: { rules: [{ id: "color-contrast", enabled: false }] } },
|
|
9
|
+
// color-contrast is ON for this story. Each swatch label measures its own
|
|
10
|
+
// swatch and changes to black or white when the paired token does not
|
|
11
|
+
// reach 4.5:1 (see useReadableLabel). Before that, the chart and input
|
|
12
|
+
// labels failed in some forks, and the rule was turned off for the whole
|
|
13
|
+
// page that exists to show colour discipline.
|
|
14
14
|
},
|
|
15
15
|
};
|
|
16
16
|
export default meta;
|
|
@@ -65,10 +65,104 @@ const GROUPS: Record<string, { name: string; var: string; bg: string; fg?: strin
|
|
|
65
65
|
],
|
|
66
66
|
};
|
|
67
67
|
|
|
68
|
+
// ---- readable labels ------------------------------------------------------
|
|
69
|
+
//
|
|
70
|
+
// A swatch shows a token as a background with its name on top. The name uses
|
|
71
|
+
// the token's paired foreground where one exists. But the colours change per
|
|
72
|
+
// fork and per theme, so a pairing that reads well in BADS can fail in a fork:
|
|
73
|
+
// FF-BADS measured "Chart 1" white on #3e7bc8 at 4.31:1, and "Input" (no pair,
|
|
74
|
+
// so it inherits) at 2.07:1. So each label measures what is painted. If the
|
|
75
|
+
// pair is under 4.5:1, the label changes to black or white, whichever reads
|
|
76
|
+
// better. One of the two always clears 4.5:1 on an opaque colour.
|
|
77
|
+
|
|
78
|
+
const MIN_RATIO = 4.5;
|
|
79
|
+
type RGBA = [number, number, number, number];
|
|
80
|
+
|
|
81
|
+
let probe: CanvasRenderingContext2D | null = null;
|
|
82
|
+
// The canvas turns any CSS colour (oklch, lab, color-mix, named) into sRGB.
|
|
83
|
+
function toRGBA(css: string): RGBA | null {
|
|
84
|
+
if (typeof document === "undefined") return null;
|
|
85
|
+
probe ??= Object.assign(document.createElement("canvas"), { width: 1, height: 1 })
|
|
86
|
+
.getContext("2d", { willReadFrequently: true });
|
|
87
|
+
if (!probe) return null;
|
|
88
|
+
probe.clearRect(0, 0, 1, 1);
|
|
89
|
+
probe.fillStyle = "rgba(0, 0, 0, 0)";
|
|
90
|
+
probe.fillStyle = css;
|
|
91
|
+
probe.fillRect(0, 0, 1, 1);
|
|
92
|
+
const [r, g, b, a] = probe.getImageData(0, 0, 1, 1).data;
|
|
93
|
+
return [r, g, b, a / 255];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function over(top: RGBA, under: RGBA): RGBA {
|
|
97
|
+
const a = top[3];
|
|
98
|
+
return [0, 1, 2].map((i) => top[i] * a + under[i] * (1 - a)).concat(1) as RGBA;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function luminance([r, g, b]: RGBA): number {
|
|
102
|
+
const c = [r, g, b].map((v) => {
|
|
103
|
+
const s = v / 255;
|
|
104
|
+
return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
|
|
105
|
+
});
|
|
106
|
+
return 0.2126 * c[0] + 0.7152 * c[1] + 0.0722 * c[2];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function ratio(a: RGBA, b: RGBA): number {
|
|
110
|
+
const [hi, lo] = [luminance(a), luminance(b)].sort((x, y) => y - x);
|
|
111
|
+
return (hi + 0.05) / (lo + 0.05);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// The colour actually behind an element: its own background, laid over each
|
|
115
|
+
// ancestor's background until an opaque one is reached.
|
|
116
|
+
function paintedBackground(el: Element | null): RGBA {
|
|
117
|
+
const layers: RGBA[] = [];
|
|
118
|
+
for (let n = el; n; n = n.parentElement) {
|
|
119
|
+
const c = toRGBA(getComputedStyle(n).backgroundColor);
|
|
120
|
+
if (!c || c[3] === 0) continue;
|
|
121
|
+
layers.push(c);
|
|
122
|
+
if (c[3] >= 1) break;
|
|
123
|
+
}
|
|
124
|
+
return layers.reduceRight<RGBA>((acc, c) => over(c, acc), [255, 255, 255, 1]);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const BLACK: RGBA = [0, 0, 0, 1];
|
|
128
|
+
const WHITE: RGBA = [255, 255, 255, 1];
|
|
129
|
+
|
|
130
|
+
function useReadableLabel() {
|
|
131
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
132
|
+
const [override, setOverride] = useState<string | undefined>(undefined);
|
|
133
|
+
useLayoutEffect(() => {
|
|
134
|
+
const el = ref.current;
|
|
135
|
+
if (!el) return;
|
|
136
|
+
const measure = () => {
|
|
137
|
+
// Read the paired token's colour with any earlier override taken off.
|
|
138
|
+
const previous = el.style.color;
|
|
139
|
+
el.style.color = "";
|
|
140
|
+
const fgRaw = toRGBA(getComputedStyle(el).color);
|
|
141
|
+
el.style.color = previous;
|
|
142
|
+
const bg = paintedBackground(el);
|
|
143
|
+
if (!fgRaw) return;
|
|
144
|
+
if (ratio(over(fgRaw, bg), bg) >= MIN_RATIO) return setOverride(undefined);
|
|
145
|
+
setOverride(ratio(BLACK, bg) >= ratio(WHITE, bg) ? "black" : "white");
|
|
146
|
+
};
|
|
147
|
+
measure();
|
|
148
|
+
// Re-measure when the theme class or the brand colour changes on <html>.
|
|
149
|
+
const mo = new MutationObserver(measure);
|
|
150
|
+
mo.observe(document.documentElement, { attributes: true, attributeFilter: ["class", "style", "data-theme"] });
|
|
151
|
+
return () => mo.disconnect();
|
|
152
|
+
}, []);
|
|
153
|
+
return { ref, override };
|
|
154
|
+
}
|
|
155
|
+
|
|
68
156
|
function Swatch({ name, var: v, bg, fg }: { name: string; var: string; bg: string; fg?: string }) {
|
|
157
|
+
const { ref, override } = useReadableLabel();
|
|
69
158
|
return (
|
|
70
159
|
<div className="flex flex-col">
|
|
71
|
-
<div
|
|
160
|
+
<div
|
|
161
|
+
ref={ref}
|
|
162
|
+
data-swatch-label={name}
|
|
163
|
+
className={`h-20 rounded-lg border border-border ${bg} ${fg ?? ""} flex items-end p-2.5`}
|
|
164
|
+
style={override ? { color: override } : undefined}
|
|
165
|
+
>
|
|
72
166
|
<span className="text-sm font-medium">{name}</span>
|
|
73
167
|
</div>
|
|
74
168
|
<p className="text-xs text-muted-foreground font-mono mt-1.5">{v}</p>
|
|
@@ -77,6 +171,23 @@ function Swatch({ name, var: v, bg, fg }: { name: string; var: string; bg: strin
|
|
|
77
171
|
}
|
|
78
172
|
|
|
79
173
|
export const All: Story = {
|
|
174
|
+
// Axe does not fail a story test in this repo, so the story checks its own
|
|
175
|
+
// promise: every label reads at 4.5:1 or better on the colour behind it.
|
|
176
|
+
play: async ({ canvasElement }) => {
|
|
177
|
+
const labels = [...canvasElement.querySelectorAll<HTMLElement>("[data-swatch-label]")];
|
|
178
|
+
await expect(labels.length).toBeGreaterThan(0);
|
|
179
|
+
await waitFor(() => {
|
|
180
|
+
const failing = labels
|
|
181
|
+
.map((el) => {
|
|
182
|
+
const bg = paintedBackground(el);
|
|
183
|
+
const fg = toRGBA(getComputedStyle(el).color);
|
|
184
|
+
return { name: el.dataset.swatchLabel, r: fg ? ratio(over(fg, bg), bg) : 0 };
|
|
185
|
+
})
|
|
186
|
+
.filter((x) => x.r < MIN_RATIO)
|
|
187
|
+
.map((x) => `${x.name} ${x.r.toFixed(2)}:1`);
|
|
188
|
+
expect(failing).toEqual([]);
|
|
189
|
+
});
|
|
190
|
+
},
|
|
80
191
|
render: () => (
|
|
81
192
|
<div className="p-8 space-y-8 bg-background">
|
|
82
193
|
{Object.entries(GROUPS).map(([title, swatches]) => (
|