@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,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared contract for the Studio screen. Pure TypeScript: no React, no DOM.
|
|
3
|
+
* The view-state, hook, control-panel and preview packages all import from here
|
|
4
|
+
* so they agree on names, URL keys, ranges, and the 14px type floor.
|
|
5
|
+
*/
|
|
6
|
+
import {
|
|
7
|
+
DESIGN_CONTROL_DEFAULTS,
|
|
8
|
+
DESIGN_CONTROL_RANGES,
|
|
9
|
+
} from "@behavioral-agentic-design-system/core/hooks/use-global-design-controls";
|
|
10
|
+
import {
|
|
11
|
+
TYPE_SCALE_DEFAULTS,
|
|
12
|
+
TYPE_SCALE_RANGES,
|
|
13
|
+
type TypeScale,
|
|
14
|
+
} from "@behavioral-agentic-design-system/core/hooks/use-global-type-scale";
|
|
15
|
+
|
|
16
|
+
/* ── View state: lives in the URL ─────────────────────────────── */
|
|
17
|
+
|
|
18
|
+
export type StudioSubject = "blank" | "cards" | "dashboard";
|
|
19
|
+
export type StudioViewport = "fill" | "390" | "768" | "1280";
|
|
20
|
+
export type StudioPreviewTheme = "match" | "light" | "dark" | "both";
|
|
21
|
+
export type StudioPanelMode = "tweak" | "tokens";
|
|
22
|
+
|
|
23
|
+
/** The single source of truth for everything Studio shows that is NOT a token. */
|
|
24
|
+
export interface StudioViewState {
|
|
25
|
+
subject: StudioSubject;
|
|
26
|
+
viewport: StudioViewport;
|
|
27
|
+
theme: StudioPreviewTheme;
|
|
28
|
+
panel: StudioPanelMode;
|
|
29
|
+
controlsCollapsed: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const STUDIO_VIEW_DEFAULTS: StudioViewState = {
|
|
33
|
+
subject: "blank",
|
|
34
|
+
viewport: "fill",
|
|
35
|
+
theme: "match",
|
|
36
|
+
panel: "tweak",
|
|
37
|
+
controlsCollapsed: false,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/** URL param name for each field. */
|
|
41
|
+
export const STUDIO_URL_KEYS = {
|
|
42
|
+
subject: "subject",
|
|
43
|
+
viewport: "vp",
|
|
44
|
+
theme: "theme",
|
|
45
|
+
panel: "panel",
|
|
46
|
+
controlsCollapsed: "controls",
|
|
47
|
+
} as const satisfies Record<keyof StudioViewState, string>;
|
|
48
|
+
|
|
49
|
+
export const STUDIO_SUBJECTS: readonly { value: StudioSubject; label: string; src: string }[] = [
|
|
50
|
+
{ value: "blank", label: "Blank screen", src: "/preview/studio" },
|
|
51
|
+
{ value: "cards", label: "Cards", src: "/preview/cards" },
|
|
52
|
+
{ value: "dashboard", label: "Dashboard", src: "/preview/dashboard" },
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
export const STUDIO_VIEWPORTS: readonly { value: StudioViewport; label: string; width: number | null }[] = [
|
|
56
|
+
{ value: "fill", label: "Fill", width: null },
|
|
57
|
+
{ value: "390", label: "390", width: 390 },
|
|
58
|
+
{ value: "768", label: "768", width: 768 },
|
|
59
|
+
{ value: "1280", label: "1280", width: 1280 },
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
export const STUDIO_THEMES: readonly { value: StudioPreviewTheme; label: string }[] = [
|
|
63
|
+
{ value: "match", label: "Match app" },
|
|
64
|
+
{ value: "light", label: "Light" },
|
|
65
|
+
{ value: "dark", label: "Dark" },
|
|
66
|
+
{ value: "both", label: "Both" },
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
function pick<T extends string>(
|
|
70
|
+
raw: string | null,
|
|
71
|
+
options: readonly { value: T }[],
|
|
72
|
+
fallback: T,
|
|
73
|
+
): T {
|
|
74
|
+
const hit = options.find((o) => o.value === raw);
|
|
75
|
+
return hit ? hit.value : fallback;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const PANEL_MODES: readonly { value: StudioPanelMode }[] = [
|
|
79
|
+
{ value: "tweak" },
|
|
80
|
+
{ value: "tokens" },
|
|
81
|
+
];
|
|
82
|
+
|
|
83
|
+
/** Parse URLSearchParams into a complete state. Unknown or missing values fall back to defaults. */
|
|
84
|
+
export function parseStudioViewState(params: URLSearchParams): StudioViewState {
|
|
85
|
+
const d = STUDIO_VIEW_DEFAULTS;
|
|
86
|
+
const collapsed = params.get(STUDIO_URL_KEYS.controlsCollapsed);
|
|
87
|
+
return {
|
|
88
|
+
subject: pick(params.get(STUDIO_URL_KEYS.subject), STUDIO_SUBJECTS, d.subject),
|
|
89
|
+
viewport: pick(params.get(STUDIO_URL_KEYS.viewport), STUDIO_VIEWPORTS, d.viewport),
|
|
90
|
+
theme: pick(params.get(STUDIO_URL_KEYS.theme), STUDIO_THEMES, d.theme),
|
|
91
|
+
panel: pick(params.get(STUDIO_URL_KEYS.panel), PANEL_MODES, d.panel),
|
|
92
|
+
controlsCollapsed: collapsed === "collapsed" ? true : d.controlsCollapsed,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Write only non-default fields into `params` (mutates and returns it). Removes keys that are back at default. */
|
|
97
|
+
export function writeStudioViewState(
|
|
98
|
+
params: URLSearchParams,
|
|
99
|
+
state: StudioViewState,
|
|
100
|
+
): URLSearchParams {
|
|
101
|
+
const d = STUDIO_VIEW_DEFAULTS;
|
|
102
|
+
const set = (key: string, value: string, isDefault: boolean) => {
|
|
103
|
+
if (isDefault) params.delete(key);
|
|
104
|
+
else params.set(key, value);
|
|
105
|
+
};
|
|
106
|
+
set(STUDIO_URL_KEYS.subject, state.subject, state.subject === d.subject);
|
|
107
|
+
set(STUDIO_URL_KEYS.viewport, state.viewport, state.viewport === d.viewport);
|
|
108
|
+
set(STUDIO_URL_KEYS.theme, state.theme, state.theme === d.theme);
|
|
109
|
+
set(STUDIO_URL_KEYS.panel, state.panel, state.panel === d.panel);
|
|
110
|
+
set(
|
|
111
|
+
STUDIO_URL_KEYS.controlsCollapsed,
|
|
112
|
+
"collapsed",
|
|
113
|
+
state.controlsCollapsed === d.controlsCollapsed,
|
|
114
|
+
);
|
|
115
|
+
return params;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/* ── Tweaks: live in the existing global hooks ────────────────── */
|
|
119
|
+
|
|
120
|
+
export const TEXT_FLOOR_PX = 14;
|
|
121
|
+
|
|
122
|
+
/** text-xs is two steps below base. */
|
|
123
|
+
export function smallestTextPx(base: number, ratio: number): number {
|
|
124
|
+
return base / ratio ** 2;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Largest ratio that keeps text-xs at or above 14px for this base, capped at TYPE_SCALE_RANGES.ratio.max. */
|
|
128
|
+
export function maxRatioForBase(base: number): number {
|
|
129
|
+
return Math.min(TYPE_SCALE_RANGES.ratio.max, Math.sqrt(base / TEXT_FLOOR_PX));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Smallest base that keeps text-xs at or above 14px for this ratio, floored at TYPE_SCALE_RANGES.base.min. */
|
|
133
|
+
export function minBaseForRatio(ratio: number): number {
|
|
134
|
+
return Math.max(TYPE_SCALE_RANGES.base.min, TEXT_FLOOR_PX * ratio ** 2);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Clamp a scale so it satisfies the floor. Adjusts ratio first, then base. */
|
|
138
|
+
export function clampTypeScale(scale: TypeScale): TypeScale {
|
|
139
|
+
const ratio = Math.max(
|
|
140
|
+
TYPE_SCALE_RANGES.ratio.min,
|
|
141
|
+
Math.min(scale.ratio, maxRatioForBase(scale.base)),
|
|
142
|
+
);
|
|
143
|
+
// If the range minimum ratio still breaches the floor at this base, raise base.
|
|
144
|
+
const base = Math.min(
|
|
145
|
+
TYPE_SCALE_RANGES.base.max,
|
|
146
|
+
Math.max(scale.base, minBaseForRatio(ratio)),
|
|
147
|
+
);
|
|
148
|
+
return { base, ratio };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Every tweakable value Studio exposes, flattened into one typed object. */
|
|
152
|
+
export interface StudioTweaks {
|
|
153
|
+
primaryColor: string; // option key from useGlobalPrimaryColor
|
|
154
|
+
sansFont: string; // key of SANS_FONT_OPTIONS
|
|
155
|
+
typeBase: number; // px
|
|
156
|
+
typeRatio: number;
|
|
157
|
+
letterSpacing: number; // em
|
|
158
|
+
radius: number; // rem
|
|
159
|
+
shadowOpacity: number; // 0..1
|
|
160
|
+
spacing: number; // rem
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export type StudioTweakKey = keyof StudioTweaks;
|
|
164
|
+
|
|
165
|
+
/** Numeric tweak metadata. Ranges and defaults are imported, never retyped. */
|
|
166
|
+
export const NUMERIC_TWEAKS: Record<
|
|
167
|
+
Exclude<StudioTweakKey, "primaryColor" | "sansFont">,
|
|
168
|
+
{
|
|
169
|
+
label: string;
|
|
170
|
+
group: "type" | "shape" | "space";
|
|
171
|
+
min: number;
|
|
172
|
+
max: number;
|
|
173
|
+
step: number;
|
|
174
|
+
unit: string;
|
|
175
|
+
default: number;
|
|
176
|
+
}
|
|
177
|
+
> = {
|
|
178
|
+
typeBase: {
|
|
179
|
+
label: "Base size",
|
|
180
|
+
group: "type",
|
|
181
|
+
...TYPE_SCALE_RANGES.base,
|
|
182
|
+
default: TYPE_SCALE_DEFAULTS.base,
|
|
183
|
+
},
|
|
184
|
+
typeRatio: {
|
|
185
|
+
label: "Scale ratio",
|
|
186
|
+
group: "type",
|
|
187
|
+
...TYPE_SCALE_RANGES.ratio,
|
|
188
|
+
default: TYPE_SCALE_DEFAULTS.ratio,
|
|
189
|
+
},
|
|
190
|
+
letterSpacing: {
|
|
191
|
+
label: "Letter spacing",
|
|
192
|
+
group: "type",
|
|
193
|
+
...DESIGN_CONTROL_RANGES.letterSpacing,
|
|
194
|
+
default: DESIGN_CONTROL_DEFAULTS.letterSpacing,
|
|
195
|
+
},
|
|
196
|
+
radius: {
|
|
197
|
+
label: "Radius",
|
|
198
|
+
group: "shape",
|
|
199
|
+
...DESIGN_CONTROL_RANGES.radius,
|
|
200
|
+
default: DESIGN_CONTROL_DEFAULTS.radius,
|
|
201
|
+
},
|
|
202
|
+
shadowOpacity: {
|
|
203
|
+
label: "Shadow",
|
|
204
|
+
group: "shape",
|
|
205
|
+
...DESIGN_CONTROL_RANGES.shadowOpacity,
|
|
206
|
+
default: DESIGN_CONTROL_DEFAULTS.shadowOpacity,
|
|
207
|
+
},
|
|
208
|
+
spacing: {
|
|
209
|
+
label: "Spacing unit",
|
|
210
|
+
group: "space",
|
|
211
|
+
...DESIGN_CONTROL_RANGES.spacing,
|
|
212
|
+
default: DESIGN_CONTROL_DEFAULTS.spacing,
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
/** postMessage-free contract: the preview needs no messages. Documented here so nobody adds one. */
|
|
217
|
+
export const STUDIO_SYNC_NOTE =
|
|
218
|
+
"Preview iframes sync through the storage event via GlobalFontClient. Do not add a postMessage channel.";
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useCallback, useMemo } from "react";
|
|
4
|
+
import { useTokenOverrides } from "@behavioral-agentic-design-system/core/hooks/use-token-overrides";
|
|
5
|
+
import {
|
|
6
|
+
DEFAULT_PRIMARY_COLOR,
|
|
7
|
+
useGlobalPrimaryColor,
|
|
8
|
+
} from "@behavioral-agentic-design-system/core/hooks/use-global-primary-color";
|
|
9
|
+
import {
|
|
10
|
+
DEFAULT_SANS_FONT,
|
|
11
|
+
SANS_FONT_OPTIONS,
|
|
12
|
+
useGlobalSansFont,
|
|
13
|
+
} from "@behavioral-agentic-design-system/core/hooks/use-global-sans-font";
|
|
14
|
+
import { useGlobalTypeScale } from "@behavioral-agentic-design-system/core/hooks/use-global-type-scale";
|
|
15
|
+
import { useGlobalDesignControls } from "@behavioral-agentic-design-system/core/hooks/use-global-design-controls";
|
|
16
|
+
import {
|
|
17
|
+
NUMERIC_TWEAKS,
|
|
18
|
+
clampTypeScale,
|
|
19
|
+
type StudioTweakKey,
|
|
20
|
+
type StudioTweaks,
|
|
21
|
+
} from "./types";
|
|
22
|
+
|
|
23
|
+
const PRIMARY_DEFAULT = DEFAULT_PRIMARY_COLOR;
|
|
24
|
+
const SANS_DEFAULT = DEFAULT_SANS_FONT;
|
|
25
|
+
|
|
26
|
+
const DEFAULTS: StudioTweaks = {
|
|
27
|
+
primaryColor: PRIMARY_DEFAULT,
|
|
28
|
+
sansFont: SANS_DEFAULT,
|
|
29
|
+
typeBase: NUMERIC_TWEAKS.typeBase.default,
|
|
30
|
+
typeRatio: NUMERIC_TWEAKS.typeRatio.default,
|
|
31
|
+
letterSpacing: NUMERIC_TWEAKS.letterSpacing.default,
|
|
32
|
+
radius: NUMERIC_TWEAKS.radius.default,
|
|
33
|
+
shadowOpacity: NUMERIC_TWEAKS.shadowOpacity.default,
|
|
34
|
+
spacing: NUMERIC_TWEAKS.spacing.default,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Studio tweaks: a typed facade over the four existing global hooks. Adds no
|
|
39
|
+
* state of its own, so values stay in the shipped localStorage + storage-event
|
|
40
|
+
* contract that every preview iframe already listens to.
|
|
41
|
+
*/
|
|
42
|
+
export function useStudioTweaks() {
|
|
43
|
+
// Order matters: useTokenOverrides' mount effect runs applyThemeEditorState,
|
|
44
|
+
// which clears inline radius/spacing/fonts/colors. It must mount first so
|
|
45
|
+
// the other hooks' mount effects re-apply their values afterwards.
|
|
46
|
+
useTokenOverrides();
|
|
47
|
+
const { color, setColor, options, addCustomSilent } = useGlobalPrimaryColor();
|
|
48
|
+
const { font, setFont } = useGlobalSansFont();
|
|
49
|
+
const { scale, setScale, reset: resetScale } = useGlobalTypeScale();
|
|
50
|
+
const { controls, setControl, reset: resetControls } = useGlobalDesignControls();
|
|
51
|
+
|
|
52
|
+
const tweaks: StudioTweaks = useMemo(
|
|
53
|
+
() => ({
|
|
54
|
+
primaryColor: color,
|
|
55
|
+
sansFont: font,
|
|
56
|
+
typeBase: scale.base,
|
|
57
|
+
typeRatio: scale.ratio,
|
|
58
|
+
letterSpacing: controls.letterSpacing,
|
|
59
|
+
radius: controls.radius,
|
|
60
|
+
shadowOpacity: controls.shadowOpacity,
|
|
61
|
+
spacing: controls.spacing,
|
|
62
|
+
}),
|
|
63
|
+
[color, font, scale.base, scale.ratio, controls],
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const set = useCallback(
|
|
67
|
+
<K extends StudioTweakKey>(key: K, value: StudioTweaks[K]) => {
|
|
68
|
+
switch (key) {
|
|
69
|
+
case "primaryColor":
|
|
70
|
+
setColor(value as string);
|
|
71
|
+
break;
|
|
72
|
+
case "sansFont":
|
|
73
|
+
if ((value as string) in SANS_FONT_OPTIONS) setFont(value as string);
|
|
74
|
+
break;
|
|
75
|
+
case "typeBase":
|
|
76
|
+
case "typeRatio": {
|
|
77
|
+
const next = clampTypeScale({
|
|
78
|
+
base: key === "typeBase" ? (value as number) : scale.base,
|
|
79
|
+
ratio: key === "typeRatio" ? (value as number) : scale.ratio,
|
|
80
|
+
});
|
|
81
|
+
if (next.base !== scale.base) setScale("base", next.base);
|
|
82
|
+
if (next.ratio !== scale.ratio) setScale("ratio", next.ratio);
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
default:
|
|
86
|
+
setControl(key, value as number);
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
[setColor, setFont, setScale, setControl, scale.base, scale.ratio],
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
const reset = useCallback(
|
|
93
|
+
(key: StudioTweakKey) => set(key, DEFAULTS[key]),
|
|
94
|
+
[set],
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
const resetAll = useCallback(() => {
|
|
98
|
+
resetControls();
|
|
99
|
+
resetScale();
|
|
100
|
+
setFont(SANS_DEFAULT);
|
|
101
|
+
setColor(PRIMARY_DEFAULT);
|
|
102
|
+
}, [resetControls, resetScale, setFont, setColor]);
|
|
103
|
+
|
|
104
|
+
const isDefault = useCallback(
|
|
105
|
+
(key: StudioTweakKey) => tweaks[key] === DEFAULTS[key],
|
|
106
|
+
[tweaks],
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
const addCustomColor = useCallback(
|
|
110
|
+
(hex: string): string | null => {
|
|
111
|
+
const id = addCustomSilent(hex);
|
|
112
|
+
if (id) setColor(id);
|
|
113
|
+
return id;
|
|
114
|
+
},
|
|
115
|
+
[addCustomSilent, setColor],
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
tweaks,
|
|
120
|
+
defaults: DEFAULTS,
|
|
121
|
+
set,
|
|
122
|
+
reset,
|
|
123
|
+
resetAll,
|
|
124
|
+
isDefault,
|
|
125
|
+
primaryOptions: options,
|
|
126
|
+
addCustomColor,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
4
|
+
import {
|
|
5
|
+
STUDIO_SUBJECTS,
|
|
6
|
+
STUDIO_VIEW_DEFAULTS,
|
|
7
|
+
parseStudioViewState,
|
|
8
|
+
writeStudioViewState,
|
|
9
|
+
type StudioViewState,
|
|
10
|
+
} from "./types";
|
|
11
|
+
|
|
12
|
+
const URL_DEBOUNCE_MS = 150;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Studio view state (subject, viewport, theme, panel mode, collapsed) mirrored
|
|
16
|
+
* into the URL. Initial render returns the defaults so server and client agree;
|
|
17
|
+
* a mount effect reads window.location.search once. Writes use replaceState,
|
|
18
|
+
* never pushState, and spread the existing history.state so the shell's
|
|
19
|
+
* `shellTab` entry survives.
|
|
20
|
+
*/
|
|
21
|
+
export function useStudioViewState() {
|
|
22
|
+
const [state, setState] = useState<StudioViewState>(STUDIO_VIEW_DEFAULTS);
|
|
23
|
+
const latest = useRef<StudioViewState>(STUDIO_VIEW_DEFAULTS);
|
|
24
|
+
const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
25
|
+
const dirty = useRef(false);
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
const parsed = parseStudioViewState(new URLSearchParams(window.location.search));
|
|
29
|
+
latest.current = parsed;
|
|
30
|
+
setState(parsed);
|
|
31
|
+
}, []);
|
|
32
|
+
|
|
33
|
+
useEffect(
|
|
34
|
+
() => () => {
|
|
35
|
+
if (timer.current) clearTimeout(timer.current);
|
|
36
|
+
},
|
|
37
|
+
[],
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const set = useCallback(
|
|
41
|
+
<K extends keyof StudioViewState>(key: K, value: StudioViewState[K]) => {
|
|
42
|
+
const next = { ...latest.current, [key]: value };
|
|
43
|
+
latest.current = next;
|
|
44
|
+
dirty.current = true;
|
|
45
|
+
setState(next);
|
|
46
|
+
if (timer.current) clearTimeout(timer.current);
|
|
47
|
+
timer.current = setTimeout(() => {
|
|
48
|
+
timer.current = null;
|
|
49
|
+
if (typeof window === "undefined") return;
|
|
50
|
+
const url = new URL(window.location.href);
|
|
51
|
+
writeStudioViewState(url.searchParams, latest.current);
|
|
52
|
+
window.history.replaceState({ ...window.history.state }, "", url);
|
|
53
|
+
}, URL_DEBOUNCE_MS);
|
|
54
|
+
},
|
|
55
|
+
[],
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
// The mount effect above reads the URL once, so a Studio that is already mounted (the shell keeps visited tabs
|
|
59
|
+
// alive) never sees a link that points it at another subject. Home's "Recently added" sends this event, the
|
|
60
|
+
// same pairing the Docs tab uses with "bads:docs:navigate".
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
const onSubject = (event: Event) => {
|
|
63
|
+
const subject = (event as CustomEvent<unknown>).detail;
|
|
64
|
+
const match = STUDIO_SUBJECTS.find((s) => s.value === subject);
|
|
65
|
+
if (match) set("subject", match.value);
|
|
66
|
+
};
|
|
67
|
+
window.addEventListener("bads:studio:subject", onSubject);
|
|
68
|
+
return () => window.removeEventListener("bads:studio:subject", onSubject);
|
|
69
|
+
}, [set]);
|
|
70
|
+
|
|
71
|
+
return { state, set };
|
|
72
|
+
}
|
|
@@ -108,7 +108,7 @@ export function Autocomplete({
|
|
|
108
108
|
}
|
|
109
109
|
return;
|
|
110
110
|
}
|
|
111
|
-
if (e.key === "Enter") {
|
|
111
|
+
if (e.key === "Enter" && !e.nativeEvent.isComposing) {
|
|
112
112
|
// Free-text contract: only intercept Enter when an option is
|
|
113
113
|
// highlighted. Otherwise the typed text stands and the event falls
|
|
114
114
|
// through (form submit keeps working).
|
|
@@ -89,6 +89,10 @@ function AvatarGroup({ className, ...props }: React.ComponentProps<"div">) {
|
|
|
89
89
|
return (
|
|
90
90
|
<div
|
|
91
91
|
data-slot="avatar-group"
|
|
92
|
+
// A named group, so a screen reader announces "Project contributors, group"
|
|
93
|
+
// instead of a run of unrelated images. Pass aria-label (required) and
|
|
94
|
+
// override role if the group is a list in your layout.
|
|
95
|
+
role="group"
|
|
92
96
|
className={cn(
|
|
93
97
|
"group/avatar-group flex -space-x-2 *:data-[slot=avatar]:ring-2 *:data-[slot=avatar]:ring-background",
|
|
94
98
|
className
|
|
@@ -5,6 +5,7 @@ import * as RechartsPrimitive from "recharts"
|
|
|
5
5
|
|
|
6
6
|
import { cn } from "../../lib/utils"
|
|
7
7
|
import { useReducedMotion } from "../../hooks/use-reduced-motion"
|
|
8
|
+
import { readChartMotion, type ChartMotion } from "../../lib/chart-motion"
|
|
8
9
|
|
|
9
10
|
// Format: { THEME_NAME: CSS_SELECTOR }
|
|
10
11
|
const THEMES = { light: "", dark: ".dark" } as const
|
|
@@ -51,34 +52,74 @@ const ANIMATED_RECHARTS_COMPONENTS = new Set<React.ElementType>([
|
|
|
51
52
|
RechartsPrimitive.Scatter,
|
|
52
53
|
])
|
|
53
54
|
|
|
55
|
+
// Series that draw in along their path. ChartContainer gives them the
|
|
56
|
+
// token-derived draw timing (lib/chart-motion.ts) unless the consumer set
|
|
57
|
+
// their own.
|
|
58
|
+
const DRAWN_RECHARTS_COMPONENTS = new Set<React.ElementType>([
|
|
59
|
+
RechartsPrimitive.Line,
|
|
60
|
+
RechartsPrimitive.Area,
|
|
61
|
+
RechartsPrimitive.Radar,
|
|
62
|
+
])
|
|
63
|
+
|
|
54
64
|
function injectAnimationDefault(
|
|
55
65
|
node: React.ReactNode,
|
|
56
|
-
animate: boolean
|
|
66
|
+
animate: boolean,
|
|
67
|
+
motion: ChartMotion | null,
|
|
68
|
+
drawEnds: number[]
|
|
57
69
|
): React.ReactNode {
|
|
58
|
-
//
|
|
59
|
-
//
|
|
60
|
-
//
|
|
61
|
-
|
|
70
|
+
// animate=false: force isAnimationActive={false} on every animated
|
|
71
|
+
// primitive. animate=true: give drawn series the token-derived duration and
|
|
72
|
+
// easing (unless the consumer set their own) and record when each one
|
|
73
|
+
// finishes drawing, so the point dots can wait for it.
|
|
62
74
|
if (Array.isArray(node)) {
|
|
63
75
|
return node.map((child, i) => (
|
|
64
|
-
<React.Fragment key={i}>
|
|
76
|
+
<React.Fragment key={i}>
|
|
77
|
+
{injectAnimationDefault(child, animate, motion, drawEnds)}
|
|
78
|
+
</React.Fragment>
|
|
65
79
|
))
|
|
66
80
|
}
|
|
67
81
|
if (!React.isValidElement(node)) return node
|
|
68
82
|
const element = node as React.ReactElement<any>
|
|
69
83
|
const props = element.props || {}
|
|
70
|
-
const
|
|
71
|
-
element.type as React.ElementType
|
|
72
|
-
)
|
|
73
|
-
const needsDefault =
|
|
74
|
-
isAnimated && props.isAnimationActive === undefined
|
|
75
|
-
const hasChildren = props.children !== undefined
|
|
76
|
-
if (!needsDefault && !hasChildren) return element
|
|
84
|
+
const type = element.type as React.ElementType
|
|
77
85
|
const nextProps: Record<string, unknown> = {}
|
|
78
|
-
if (
|
|
79
|
-
|
|
80
|
-
|
|
86
|
+
if (!animate) {
|
|
87
|
+
if (
|
|
88
|
+
ANIMATED_RECHARTS_COMPONENTS.has(type) &&
|
|
89
|
+
props.isAnimationActive === undefined
|
|
90
|
+
) {
|
|
91
|
+
nextProps.isAnimationActive = false
|
|
92
|
+
}
|
|
93
|
+
} else if (DRAWN_RECHARTS_COMPONENTS.has(type) && props.isAnimationActive !== false) {
|
|
94
|
+
const duration =
|
|
95
|
+
typeof props.animationDuration === "number"
|
|
96
|
+
? props.animationDuration
|
|
97
|
+
: motion?.drawMs
|
|
98
|
+
if (props.animationDuration === undefined && motion) {
|
|
99
|
+
nextProps.animationDuration = motion.drawMs
|
|
100
|
+
}
|
|
101
|
+
if (props.animationEasing === undefined && motion) {
|
|
102
|
+
nextProps.animationEasing = motion.drawEasing
|
|
103
|
+
}
|
|
104
|
+
// Only Line dots need holding back: Recharts mounts them at their final
|
|
105
|
+
// positions while the stroke is still drawing. Area dots sit inside the
|
|
106
|
+
// area's reveal clip and Radar dots ride the growing polygon, so both
|
|
107
|
+
// already arrive with their series.
|
|
108
|
+
if (type === RechartsPrimitive.Line && typeof duration === "number") {
|
|
109
|
+
const begin =
|
|
110
|
+
typeof props.animationBegin === "number" ? props.animationBegin : 0
|
|
111
|
+
drawEnds.push(begin + duration)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (props.children !== undefined) {
|
|
115
|
+
nextProps.children = injectAnimationDefault(
|
|
116
|
+
props.children,
|
|
117
|
+
animate,
|
|
118
|
+
motion,
|
|
119
|
+
drawEnds
|
|
120
|
+
)
|
|
81
121
|
}
|
|
122
|
+
if (Object.keys(nextProps).length === 0) return element
|
|
82
123
|
return React.cloneElement(element, nextProps)
|
|
83
124
|
}
|
|
84
125
|
|
|
@@ -118,10 +159,12 @@ function ChartContainer({
|
|
|
118
159
|
// width AND height. The wrapping div still SSRs so layout is reserved.
|
|
119
160
|
const containerRef = React.useRef<HTMLDivElement | null>(null)
|
|
120
161
|
const [hasSize, setHasSize] = React.useState(false)
|
|
162
|
+
const [motion, setMotion] = React.useState<ChartMotion | null>(null)
|
|
121
163
|
|
|
122
164
|
React.useEffect(() => {
|
|
123
165
|
const el = containerRef.current
|
|
124
166
|
if (!el) return
|
|
167
|
+
setMotion(readChartMotion(el))
|
|
125
168
|
const observer = new ResizeObserver((entries) => {
|
|
126
169
|
for (const entry of entries) {
|
|
127
170
|
const { width, height } = entry.contentRect
|
|
@@ -139,10 +182,23 @@ function ChartContainer({
|
|
|
139
182
|
// Recursively default isAnimationActive={false} on every animated Recharts
|
|
140
183
|
// child. Consumers can override per-element by passing the prop explicitly,
|
|
141
184
|
// or opt the whole tree back in via the `animate` prop on the container.
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
)
|
|
185
|
+
// The same walk hands drawn series their token-derived timing and reports
|
|
186
|
+
// when the last one finishes drawing; the dots fade in after that, never
|
|
187
|
+
// ahead of the stroke.
|
|
188
|
+
const { safeChildren, dotDelayMs } = React.useMemo(() => {
|
|
189
|
+
const drawEnds: number[] = []
|
|
190
|
+
const next = injectAnimationDefault(
|
|
191
|
+
children,
|
|
192
|
+
effectiveAnimate,
|
|
193
|
+
motion,
|
|
194
|
+
drawEnds
|
|
195
|
+
) as typeof children
|
|
196
|
+
return {
|
|
197
|
+
safeChildren: next,
|
|
198
|
+
dotDelayMs:
|
|
199
|
+
effectiveAnimate && drawEnds.length ? Math.max(...drawEnds) : null,
|
|
200
|
+
}
|
|
201
|
+
}, [children, effectiveAnimate, motion])
|
|
146
202
|
|
|
147
203
|
return (
|
|
148
204
|
<ChartContext.Provider value={{ config }}>
|
|
@@ -162,8 +218,8 @@ function ChartContainer({
|
|
|
162
218
|
style={style}
|
|
163
219
|
{...props}
|
|
164
220
|
>
|
|
165
|
-
<ChartStyle id={chartId} config={config} />
|
|
166
|
-
{hasSize ? (
|
|
221
|
+
<ChartStyle id={chartId} config={config} dotDelayMs={dotDelayMs} />
|
|
222
|
+
{hasSize && motion ? (
|
|
167
223
|
<RechartsPrimitive.ResponsiveContainer width="100%" height="100%">
|
|
168
224
|
{safeChildren}
|
|
169
225
|
</RechartsPrimitive.ResponsiveContainer>
|
|
@@ -173,12 +229,56 @@ function ChartContainer({
|
|
|
173
229
|
)
|
|
174
230
|
}
|
|
175
231
|
|
|
176
|
-
|
|
232
|
+
// Line point dots (`<Line dot>`) render at their final positions the moment a
|
|
233
|
+
// series mounts, while the stroke takes the whole draw to reach them. Left
|
|
234
|
+
// alone they pop in all at once, ahead of the line. Hold them at
|
|
235
|
+
// opacity 0 until the last series has finished drawing (dotDelayMs, from
|
|
236
|
+
// ChartContainer), then fade them in over --duration-slow / --ease-out.
|
|
237
|
+
// Scoped to the line dot group so the hover activeDot (rendered in
|
|
238
|
+
// .recharts-active-dot) is never delayed, and Area / Radar dots (which
|
|
239
|
+
// already arrive with their series) are left alone. No rule at all when the chart is not
|
|
240
|
+
// animating, and none under prefers-reduced-motion: the global reduced-motion
|
|
241
|
+
// rule shortens animation-duration but not animation-delay.
|
|
242
|
+
const CHART_DOT_SELECTOR = [".recharts-line-dots .recharts-dot"]
|
|
243
|
+
|
|
244
|
+
function chartDotEntranceCss(id: string, dotDelayMs: number | null) {
|
|
245
|
+
if (dotDelayMs === null) return ""
|
|
246
|
+
const selector = CHART_DOT_SELECTOR.map(
|
|
247
|
+
(dots) => `[data-chart=${id}] ${dots}`
|
|
248
|
+
).join(",\n")
|
|
249
|
+
return `
|
|
250
|
+
@keyframes chart-dot-fade-in {
|
|
251
|
+
0% {
|
|
252
|
+
opacity: 0;
|
|
253
|
+
}
|
|
254
|
+
100% {
|
|
255
|
+
opacity: 1;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
260
|
+
${selector} {
|
|
261
|
+
animation: chart-dot-fade-in var(--duration-slow) var(--ease-out) ${Math.round(dotDelayMs)}ms both;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
`
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const ChartStyle = ({
|
|
268
|
+
id,
|
|
269
|
+
config,
|
|
270
|
+
dotDelayMs = null,
|
|
271
|
+
}: {
|
|
272
|
+
id: string
|
|
273
|
+
config: ChartConfig
|
|
274
|
+
dotDelayMs?: number | null
|
|
275
|
+
}) => {
|
|
177
276
|
const colorConfig = Object.entries(config).filter(
|
|
178
277
|
([, config]) => config.theme || config.color
|
|
179
278
|
)
|
|
279
|
+
const dotCss = chartDotEntranceCss(id, dotDelayMs)
|
|
180
280
|
|
|
181
|
-
if (!colorConfig.length) {
|
|
281
|
+
if (!colorConfig.length && !dotCss) {
|
|
182
282
|
return null
|
|
183
283
|
}
|
|
184
284
|
|
|
@@ -188,19 +288,12 @@ const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {
|
|
|
188
288
|
// per-instance generated CSS, and the values written ARE tokens.
|
|
189
289
|
<style
|
|
190
290
|
dangerouslySetInnerHTML={{
|
|
191
|
-
__html:
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
opacity: 1;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
${Object.entries(THEMES)
|
|
202
|
-
.map(
|
|
203
|
-
([theme, prefix]) => `
|
|
291
|
+
__html: `${dotCss}
|
|
292
|
+
${
|
|
293
|
+
colorConfig.length
|
|
294
|
+
? Object.entries(THEMES)
|
|
295
|
+
.map(
|
|
296
|
+
([theme, prefix]) => `
|
|
204
297
|
${prefix} [data-chart=${id}] {
|
|
205
298
|
${colorConfig
|
|
206
299
|
.map(([key, itemConfig]) => {
|
|
@@ -211,12 +304,11 @@ ${colorConfig
|
|
|
211
304
|
})
|
|
212
305
|
.join("\n")}
|
|
213
306
|
}
|
|
214
|
-
${prefix} [data-chart=${id}] .recharts-dot {
|
|
215
|
-
animation: chart-dot-fade-in 400ms ease-out 800ms both;
|
|
216
|
-
}
|
|
217
307
|
`
|
|
218
|
-
|
|
219
|
-
|
|
308
|
+
)
|
|
309
|
+
.join("\n")
|
|
310
|
+
: ""
|
|
311
|
+
}
|
|
220
312
|
`,
|
|
221
313
|
}}
|
|
222
314
|
/>
|