@behavioral-agentic-design-system/core 0.48.0 → 0.49.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 +1 -1
- package/scripts/build-tokens.cjs +24 -3
- package/scripts/ux-smoke.mjs +5 -1
- package/src/api/save-tokens.ts +170 -24
- package/src/app/layout.tsx +12 -1
- package/src/app/preview/components/page.tsx +25 -18
- package/src/app/preview/global-font-client.tsx +2 -0
- package/src/app/providers.tsx +2 -0
- package/src/app/shell.tsx +50 -156
- package/src/components/customize/brand-mark-section.tsx +65 -95
- package/src/components/customize/font-pickers.tsx +25 -2
- package/src/components/customize/save-bar.tsx +120 -7
- package/src/components/customize/theme-io.tsx +62 -21
- package/src/components/customize-tab.tsx +3 -1
- package/src/components/home-recent.tsx +58 -25
- package/src/components/motion/reveal.tsx +168 -12
- package/src/components/studio/control-panel.tsx +98 -19
- package/src/components/studio/import-theme-dialog.tsx +167 -0
- package/src/components/studio/tokens-panel.tsx +215 -0
- package/src/components/studio/types.ts +5 -2
- package/src/components/studio/use-studio-tweaks.ts +36 -4
- package/src/components/studio/use-token-edits.ts +160 -0
- package/src/components/ui/toggle-tip.tsx +38 -29
- package/src/data/component-stories.json +1214 -0
- package/src/data/docs-index.ts +7 -2
- package/src/data/hidden-views.ts +22 -0
- package/src/data/history.json +32 -32
- package/src/data/sticker-sheet.json +1878 -1821
- package/src/fonts/Figtree-OFL.txt +93 -0
- package/src/fonts/figtree-latin-ext-wght-normal.woff2 +0 -0
- package/src/fonts/figtree-latin-wght-italic.woff2 +0 -0
- package/src/fonts/figtree-latin-wght-normal.woff2 +0 -0
- package/src/fonts-cdn.css +3 -1
- package/src/fonts.css +44 -0
- package/src/hooks/use-global-heading-font.ts +104 -0
- package/src/hooks/use-global-sans-font.ts +8 -3
- package/src/hooks/use-global-theme.ts +2 -2
- package/src/hooks/use-token-overrides.ts +62 -14
- package/src/lib/css-color.ts +42 -0
- package/src/lib/storybook-url.ts +28 -0
- package/src/lib/theme-editor.ts +7 -1
- package/src/lib/theme-import.ts +99 -0
- package/src/lib/theme-transition.ts +93 -0
- package/src/lib/token-list.ts +133 -0
- package/src/lib/token-value.ts +31 -0
- package/src/stories/Accordion.stories.tsx +1 -1
- package/src/stories/Affix.stories.tsx +1 -1
- package/src/stories/AiBadge.stories.tsx +1 -1
- package/src/stories/Alert.stories.tsx +1 -1
- package/src/stories/AlertDialog.stories.tsx +1 -1
- package/src/stories/AngleSlider.stories.tsx +1 -1
- package/src/stories/AnnouncementBar.stories.tsx +2 -2
- package/src/stories/AspectRatio.stories.tsx +1 -1
- package/src/stories/Attachment.stories.tsx +1 -1
- package/src/stories/Autocomplete.stories.tsx +1 -1
- package/src/stories/Avatar.stories.tsx +1 -1
- package/src/stories/Badge.stories.tsx +1 -1
- package/src/stories/Blockquote.stories.tsx +1 -1
- package/src/stories/Burger.stories.tsx +1 -1
- package/src/stories/Button.stories.tsx +1 -1
- package/src/stories/ButtonGroup.stories.tsx +1 -1
- package/src/stories/Calendar.stories.tsx +1 -1
- package/src/stories/Callout.stories.tsx +1 -1
- package/src/stories/Canvas.stories.tsx +1 -1
- package/src/stories/Card.stories.tsx +1 -1
- package/src/stories/Carousel.stories.tsx +1 -1
- package/src/stories/Cascader.stories.tsx +1 -1
- package/src/stories/Chart.stories.tsx +1 -1
- package/src/stories/ChatBubble.stories.tsx +1 -1
- package/src/stories/ChatMarker.stories.tsx +1 -1
- package/src/stories/Checkbox.stories.tsx +1 -1
- package/src/stories/CheckboxCard.stories.tsx +1 -1
- package/src/stories/CheckboxGroup.stories.tsx +1 -1
- package/src/stories/Chip.stories.tsx +1 -1
- package/src/stories/CircularProgress.stories.tsx +1 -1
- package/src/stories/Clipboard.stories.tsx +1 -1
- package/src/stories/CloseButton.stories.tsx +1 -1
- package/src/stories/Code.stories.tsx +1 -1
- package/src/stories/Collapsible.stories.tsx +1 -1
- package/src/stories/ColorPicker.stories.tsx +1 -1
- package/src/stories/ColorSwatch.stories.tsx +1 -1
- package/src/stories/Combobox.stories.tsx +1 -1
- package/src/stories/Container.stories.tsx +1 -1
- package/src/stories/ContextMenu.stories.tsx +1 -1
- package/src/stories/CopyButton.stories.tsx +1 -1
- package/src/stories/DataList.stories.tsx +1 -1
- package/src/stories/DataTable.stories.tsx +1 -1
- package/src/stories/DateField.stories.tsx +1 -1
- package/src/stories/DatePicker.stories.tsx +1 -1
- package/src/stories/DateRangePicker.stories.tsx +1 -1
- package/src/stories/Dialog.stories.tsx +1 -1
- package/src/stories/Drawer.stories.tsx +1 -1
- package/src/stories/DropdownMenu.stories.tsx +1 -1
- package/src/stories/Editable.stories.tsx +1 -1
- package/src/stories/EmptyState.stories.tsx +1 -1
- package/src/stories/FacetedFilter.stories.tsx +1 -1
- package/src/stories/Field.stories.tsx +1 -1
- package/src/stories/Fieldset.stories.tsx +1 -1
- package/src/stories/FileButton.stories.tsx +1 -1
- package/src/stories/FileUpload.stories.tsx +1 -1
- package/src/stories/FloatLabel.stories.tsx +1 -1
- package/src/stories/FloatingActionButton.stories.tsx +1 -1
- package/src/stories/FloatingIndicator.stories.tsx +1 -1
- package/src/stories/FloatingPanel.stories.tsx +1 -1
- package/src/stories/FocusTrap.stories.tsx +1 -1
- package/src/stories/FormatByte.stories.tsx +1 -1
- package/src/stories/FormatDate.stories.tsx +1 -1
- package/src/stories/FormatNumber.stories.tsx +1 -1
- package/src/stories/FormatRelativeTime.stories.tsx +1 -1
- package/src/stories/GaugeChart.stories.tsx +1 -1
- package/src/stories/Grid.stories.tsx +1 -1
- package/src/stories/Heatmap.stories.tsx +1 -1
- package/src/stories/Highlight.stories.tsx +1 -1
- package/src/stories/HoverCard.stories.tsx +1 -1
- package/src/stories/Icon.stories.tsx +1 -1
- package/src/stories/Image.stories.tsx +1 -1
- package/src/stories/Indicator.stories.tsx +1 -1
- package/src/stories/InfiniteScroll.stories.tsx +1 -1
- package/src/stories/InlineEdit.stories.tsx +1 -1
- package/src/stories/Input.stories.tsx +1 -1
- package/src/stories/InputClearButton.stories.tsx +1 -1
- package/src/stories/InputGroup.stories.tsx +1 -1
- package/src/stories/JsonInput.stories.tsx +1 -1
- package/src/stories/Kbd.stories.tsx +1 -1
- package/src/stories/KeyboardShortcut.stories.tsx +1 -1
- package/src/stories/Label.stories.tsx +1 -1
- package/src/stories/List.stories.tsx +1 -1
- package/src/stories/Listbox.stories.tsx +1 -1
- package/src/stories/LoadingDots.stories.tsx +1 -1
- package/src/stories/LoadingOverlay.stories.tsx +1 -1
- package/src/stories/Mark.stories.tsx +1 -1
- package/src/stories/MarkdownPreview.stories.tsx +1 -1
- package/src/stories/Marquee.stories.tsx +1 -1
- package/src/stories/Masonry.stories.tsx +1 -1
- package/src/stories/Meter.stories.tsx +1 -1
- package/src/stories/MonthPicker.stories.tsx +1 -1
- package/src/stories/MotionToggle.stories.tsx +1 -1
- package/src/stories/MultiSelect.stories.tsx +1 -1
- package/src/stories/NativeSelect.stories.tsx +1 -1
- package/src/stories/NavigationProgress.stories.tsx +1 -1
- package/src/stories/Notification.stories.tsx +1 -1
- package/src/stories/NumberField.stories.tsx +1 -1
- package/src/stories/NumberInput.stories.tsx +1 -1
- package/src/stories/OtpInput.stories.tsx +1 -1
- package/src/stories/Overlay.stories.tsx +1 -1
- package/src/stories/PageHeader.stories.tsx +1 -1
- package/src/stories/PasswordInput.stories.tsx +1 -1
- package/src/stories/PasswordStrengthInput.stories.tsx +1 -1
- package/src/stories/PhoneInput.stories.tsx +1 -1
- package/src/stories/Pill.stories.tsx +1 -1
- package/src/stories/PinInput.stories.tsx +1 -1
- package/src/stories/Popover.stories.tsx +1 -1
- package/src/stories/Portal.stories.tsx +1 -1
- package/src/stories/Presence.stories.tsx +1 -1
- package/src/stories/Progress.stories.tsx +1 -1
- package/src/stories/ProgressStack.stories.tsx +1 -1
- package/src/stories/Prose.stories.tsx +1 -1
- package/src/stories/QrCode.stories.tsx +1 -1
- package/src/stories/Questionnaire.stories.tsx +1 -1
- package/src/stories/RadioGroup.stories.tsx +1 -1
- package/src/stories/RatingGroup.stories.tsx +1 -1
- package/src/stories/Resizable.stories.tsx +1 -1
- package/src/stories/Result.stories.tsx +1 -1
- package/src/stories/Reveal.stories.tsx +1 -1
- package/src/stories/RollingNumber.stories.tsx +1 -1
- package/src/stories/ScrollArea.stories.tsx +1 -1
- package/src/stories/ScrollProgress.stories.tsx +1 -1
- package/src/stories/SearchInput.stories.tsx +1 -1
- package/src/stories/SegmentedControl.stories.tsx +1 -1
- package/src/stories/Select.stories.tsx +1 -1
- package/src/stories/Separator.stories.tsx +1 -1
- package/src/stories/Sheet.stories.tsx +1 -1
- package/src/stories/SignaturePad.stories.tsx +1 -1
- package/src/stories/SimpleGrid.stories.tsx +1 -1
- package/src/stories/Skeleton.stories.tsx +1 -1
- package/src/stories/SkeletonTable.stories.tsx +1 -1
- package/src/stories/Slider.stories.tsx +1 -1
- package/src/stories/Snackbar.stories.tsx +1 -1
- package/src/stories/Sonner.stories.tsx +1 -1
- package/src/stories/SortableList.stories.tsx +1 -1
- package/src/stories/Sparkline.stories.tsx +1 -1
- package/src/stories/Spinner.stories.tsx +1 -1
- package/src/stories/Spoiler.stories.tsx +1 -1
- package/src/stories/Squircle.stories.tsx +1 -1
- package/src/stories/Stack.stories.tsx +1 -1
- package/src/stories/StatusBadge.stories.tsx +1 -1
- package/src/stories/Switch.stories.tsx +1 -1
- package/src/stories/Table.stories.tsx +1 -1
- package/src/stories/Tag.stories.tsx +1 -1
- package/src/stories/TagsInput.stories.tsx +1 -1
- package/src/stories/Text.stories.tsx +1 -1
- package/src/stories/Textarea.stories.tsx +1 -1
- package/src/stories/ThemeIcon.stories.tsx +1 -1
- package/src/stories/TimePicker.stories.tsx +1 -1
- package/src/stories/Timeline.stories.tsx +1 -1
- package/src/stories/Timer.stories.tsx +1 -1
- package/src/stories/Toggle.stories.tsx +1 -1
- package/src/stories/ToggleGroup.stories.tsx +1 -1
- package/src/stories/ToggleTip.stories.tsx +106 -1
- package/src/stories/Tooltip.stories.tsx +56 -1
- package/src/stories/TransferList.stories.tsx +1 -1
- package/src/stories/TreeSelect.stories.tsx +1 -1
- package/src/stories/TypingIndicator.stories.tsx +1 -1
- package/src/stories/VisuallyHidden.stories.tsx +1 -1
- package/src/stories/Watermark.stories.tsx +1 -1
- package/src/stories/WeekPicker.stories.tsx +1 -1
- package/src/stories/WordRotate.stories.tsx +1 -1
- package/src/stories/YearPicker.stories.tsx +1 -1
- package/src/stories/story-groups.json +216 -224
- package/src/styles.css +20 -3
- package/src/tokens.default.json +6 -1
- package/src/tokens.json +7 -2
|
@@ -11,6 +11,11 @@ import {
|
|
|
11
11
|
SANS_FONT_OPTIONS,
|
|
12
12
|
type SansFontKey,
|
|
13
13
|
} from "@behavioral-agentic-design-system/core/hooks/use-global-sans-font";
|
|
14
|
+
import {
|
|
15
|
+
HEADING_FONT_OPTIONS,
|
|
16
|
+
DEFAULT_HEADING_FONT,
|
|
17
|
+
type HeadingFontKey,
|
|
18
|
+
} from "@behavioral-agentic-design-system/core/hooks/use-global-heading-font";
|
|
14
19
|
import {
|
|
15
20
|
SERIF_FONT_OPTIONS,
|
|
16
21
|
type SerifFontKey,
|
|
@@ -36,14 +41,18 @@ import {
|
|
|
36
41
|
clearAllCustomization,
|
|
37
42
|
} from "@behavioral-agentic-design-system/core/lib/storage";
|
|
38
43
|
import { brand, type BrandDefaults } from "@/brand.config";
|
|
44
|
+
import { DARK_PREFIX } from "@behavioral-agentic-design-system/core/hooks/use-token-overrides";
|
|
45
|
+
import { PRIMITIVE_COLORS, TOKEN_ROWS } from "@behavioral-agentic-design-system/core/lib/token-list";
|
|
39
46
|
|
|
40
47
|
const STORAGE_KEYS = {
|
|
41
48
|
primaryColor: storageKey("primaryColor"),
|
|
42
49
|
sansFont: storageKey("sansFont"),
|
|
50
|
+
headingFont: storageKey("headingFont"),
|
|
43
51
|
serifFont: storageKey("serifFont"),
|
|
44
52
|
monoFont: storageKey("monoFont"),
|
|
45
53
|
designControls: storageKey("designControls"),
|
|
46
54
|
typeScale: storageKey("typeScale"),
|
|
55
|
+
tokenOverrides: storageKey("tokenOverrides"),
|
|
47
56
|
} as const;
|
|
48
57
|
|
|
49
58
|
/**
|
|
@@ -78,10 +87,12 @@ function readCustomPrimaryColors(): Record<string, PrimaryColorOption> {
|
|
|
78
87
|
type Snapshot = {
|
|
79
88
|
primaryColor: PrimaryColorKey | null;
|
|
80
89
|
sansFont: SansFontKey | null;
|
|
90
|
+
headingFont: HeadingFontKey | null;
|
|
81
91
|
serifFont: SerifFontKey | null;
|
|
82
92
|
monoFont: MonoFontKey | null;
|
|
83
93
|
designControls: DesignControls | null;
|
|
84
94
|
typeScale: TypeScale | null;
|
|
95
|
+
tokenOverrides: Record<string, string> | null;
|
|
85
96
|
};
|
|
86
97
|
|
|
87
98
|
/**
|
|
@@ -95,6 +106,7 @@ type Snapshot = {
|
|
|
95
106
|
*/
|
|
96
107
|
const FORK_DEFAULTS: BrandDefaults = brand.defaults ?? {};
|
|
97
108
|
const SANS_DEFAULT: SansFontKey = (FORK_DEFAULTS.sansFont as SansFontKey) ?? "hyperlegible";
|
|
109
|
+
const HEADING_DEFAULT: HeadingFontKey = (FORK_DEFAULTS.headingFont as HeadingFontKey) ?? DEFAULT_HEADING_FONT;
|
|
98
110
|
const SERIF_DEFAULT: SerifFontKey = (FORK_DEFAULTS.serifFont as SerifFontKey) ?? "georgia";
|
|
99
111
|
const MONO_DEFAULT: MonoFontKey = (FORK_DEFAULTS.monoFont as MonoFontKey) ?? "jetbrains";
|
|
100
112
|
const PRIMARY_DEFAULT: PrimaryColorKey = (FORK_DEFAULTS.primaryColor as PrimaryColorKey) ?? "blue";
|
|
@@ -106,10 +118,12 @@ function readSnapshot(): Snapshot {
|
|
|
106
118
|
return {
|
|
107
119
|
primaryColor: null,
|
|
108
120
|
sansFont: null,
|
|
121
|
+
headingFont: null,
|
|
109
122
|
serifFont: null,
|
|
110
123
|
monoFont: null,
|
|
111
124
|
designControls: null,
|
|
112
125
|
typeScale: null,
|
|
126
|
+
tokenOverrides: null,
|
|
113
127
|
};
|
|
114
128
|
}
|
|
115
129
|
const get = (key: string) => window.localStorage.getItem(key);
|
|
@@ -125,10 +139,12 @@ function readSnapshot(): Snapshot {
|
|
|
125
139
|
return {
|
|
126
140
|
primaryColor: get(STORAGE_KEYS.primaryColor) as PrimaryColorKey | null,
|
|
127
141
|
sansFont: get(STORAGE_KEYS.sansFont) as SansFontKey | null,
|
|
142
|
+
headingFont: get(STORAGE_KEYS.headingFont) as HeadingFontKey | null,
|
|
128
143
|
serifFont: get(STORAGE_KEYS.serifFont) as SerifFontKey | null,
|
|
129
144
|
monoFont: get(STORAGE_KEYS.monoFont) as MonoFontKey | null,
|
|
130
145
|
designControls: parse<DesignControls>(STORAGE_KEYS.designControls),
|
|
131
146
|
typeScale: parse<TypeScale>(STORAGE_KEYS.typeScale),
|
|
147
|
+
tokenOverrides: parse<Record<string, string>>(STORAGE_KEYS.tokenOverrides),
|
|
132
148
|
};
|
|
133
149
|
}
|
|
134
150
|
|
|
@@ -153,10 +169,53 @@ function differs<T>(live: T, savedFromSnapshot: T | null | undefined, hardcodedD
|
|
|
153
169
|
return live !== baseline;
|
|
154
170
|
}
|
|
155
171
|
|
|
172
|
+
/** Override keys that differ from the last save. One count per token the list changed. */
|
|
173
|
+
function overrideDiff(s: Snapshot, saved: Snapshot | null): number {
|
|
174
|
+
const live = s.tokenOverrides ?? {};
|
|
175
|
+
const base = saved?.tokenOverrides ?? {};
|
|
176
|
+
const keys = new Set([...Object.keys(live), ...Object.keys(base)]);
|
|
177
|
+
let n = 0;
|
|
178
|
+
for (const k of keys) if (live[k] !== base[k]) n++;
|
|
179
|
+
return n;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const ROW_BY_VAR = new Map(TOKEN_ROWS.filter((r) => r.cssVar).map((r) => [r.cssVar!, r]));
|
|
183
|
+
|
|
184
|
+
/** The tokens.json path an override key writes to, or null when the key is not a token row. */
|
|
185
|
+
function overridePath(key: string): string | null {
|
|
186
|
+
const dark = key.startsWith(DARK_PREFIX);
|
|
187
|
+
const row = ROW_BY_VAR.get(dark ? key.slice(DARK_PREFIX.length) : key);
|
|
188
|
+
if (!row) return null;
|
|
189
|
+
const isTheme = row.tier === "semantic" && row.path.startsWith("theme.");
|
|
190
|
+
return isTheme ? `theme.${dark ? "dark" : "light"}.${row.name}` : row.path;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** Token-list edits as tokens.json paths. A palette alias becomes the file's own {color.primitive.x.y} reference. */
|
|
194
|
+
function tokenValuesFrom(overrides: Record<string, string> | null): Record<string, string> {
|
|
195
|
+
const out: Record<string, string> = {};
|
|
196
|
+
for (const [key, raw] of Object.entries(overrides ?? {})) {
|
|
197
|
+
// localStorage can hold anything; only strings are values.
|
|
198
|
+
if (typeof raw !== "string") continue;
|
|
199
|
+
const value = raw.trim();
|
|
200
|
+
const path = overridePath(key);
|
|
201
|
+
if (!path) continue;
|
|
202
|
+
// A palette alias is looked up by its CSS variable, so any family or step name works (warm-gray, brand-main).
|
|
203
|
+
// The route refuses a raw var(--primitive-*) because styles.css does not declare those variables, so one that
|
|
204
|
+
// names no palette color is not sent.
|
|
205
|
+
const alias = /^var\(--primitive-[A-Za-z0-9-]+\)$/.test(value)
|
|
206
|
+
? PRIMITIVE_COLORS.find((p) => `var(${p.cssVar})` === value)
|
|
207
|
+
: null;
|
|
208
|
+
if (alias) out[path] = `{${alias.path}}`;
|
|
209
|
+
else if (!/var\(\s*--primitive-/i.test(value)) out[path] = value;
|
|
210
|
+
}
|
|
211
|
+
return out;
|
|
212
|
+
}
|
|
213
|
+
|
|
156
214
|
function diffCount(s: Snapshot, saved: Snapshot | null): number {
|
|
157
|
-
let count =
|
|
215
|
+
let count = overrideDiff(s, saved);
|
|
158
216
|
if (s.primaryColor && differs(s.primaryColor, saved?.primaryColor, PRIMARY_DEFAULT)) count++;
|
|
159
217
|
if (s.sansFont && differs(s.sansFont, saved?.sansFont, SANS_DEFAULT)) count++;
|
|
218
|
+
if (s.headingFont && differs(s.headingFont, saved?.headingFont, HEADING_DEFAULT)) count++;
|
|
160
219
|
if (s.serifFont && differs(s.serifFont, saved?.serifFont, SERIF_DEFAULT)) count++;
|
|
161
220
|
if (s.monoFont && differs(s.monoFont, saved?.monoFont, MONO_DEFAULT)) count++;
|
|
162
221
|
if (s.typeScale) {
|
|
@@ -232,6 +291,9 @@ function buildPayload(s: Snapshot) {
|
|
|
232
291
|
if (s.sansFont && SANS_FONT_OPTIONS[s.sansFont]) {
|
|
233
292
|
fonts.sans = SANS_FONT_OPTIONS[s.sansFont].stack;
|
|
234
293
|
}
|
|
294
|
+
if (s.headingFont && HEADING_FONT_OPTIONS[s.headingFont]) {
|
|
295
|
+
fonts.heading = HEADING_FONT_OPTIONS[s.headingFont].stack;
|
|
296
|
+
}
|
|
235
297
|
if (s.serifFont && SERIF_FONT_OPTIONS[s.serifFont]) {
|
|
236
298
|
fonts.serif = SERIF_FONT_OPTIONS[s.serifFont].stack;
|
|
237
299
|
}
|
|
@@ -248,10 +310,17 @@ function buildPayload(s: Snapshot) {
|
|
|
248
310
|
payload.radius = s.designControls.radius;
|
|
249
311
|
}
|
|
250
312
|
|
|
313
|
+
const tokenValues = tokenValuesFrom(s.tokenOverrides);
|
|
314
|
+
if (Object.keys(tokenValues).length > 0) payload.tokenValues = tokenValues;
|
|
315
|
+
|
|
251
316
|
return payload;
|
|
252
317
|
}
|
|
253
318
|
|
|
254
|
-
|
|
319
|
+
/**
|
|
320
|
+
* Save the customizations to tokens.json. `inline` renders it as a block inside a panel (the Studio's Tweak tab)
|
|
321
|
+
* instead of the fixed full-width bar, and leaves Reset all to the panel, which has its own.
|
|
322
|
+
*/
|
|
323
|
+
export function SaveBar({ inline = false }: { inline?: boolean } = {}) {
|
|
255
324
|
const [snapshot, setSnapshot] = useState<Snapshot | null>(null);
|
|
256
325
|
const [savedSnapshot, setSavedSnapshot] = useState<Snapshot | null>(null);
|
|
257
326
|
const [status, setStatus] = useState<"idle" | "saving" | "saved" | "error">("idle");
|
|
@@ -292,9 +361,21 @@ export function SaveBar() {
|
|
|
292
361
|
setMessage(data.error ?? "Save failed");
|
|
293
362
|
return;
|
|
294
363
|
}
|
|
295
|
-
setStatus("saved");
|
|
296
364
|
const count = Array.isArray(data.updates) ? data.updates.length : 0;
|
|
297
|
-
|
|
365
|
+
const rejected: { path: string; reason: string }[] = Array.isArray(data.rejected) ? data.rejected : [];
|
|
366
|
+
const wrote = count > 0 ? `Wrote ${count} token${count === 1 ? "" : "s"} to tokens.json` : "Nothing to save";
|
|
367
|
+
if (rejected.length > 0) {
|
|
368
|
+
// Rows the file refused (or that could not be sent) stay out of the baseline, so the counter still shows them.
|
|
369
|
+
setStatus("error");
|
|
370
|
+
setMessage(
|
|
371
|
+
`${wrote}. ${rejected.length} token${rejected.length === 1 ? " was" : "s were"} not saved: ` +
|
|
372
|
+
rejected.slice(0, 3).map((r) => `${r.path} (${r.reason})`).join(", ") +
|
|
373
|
+
(rejected.length > 3 ? ` and ${rejected.length - 3} more` : ""),
|
|
374
|
+
);
|
|
375
|
+
} else {
|
|
376
|
+
setStatus("saved");
|
|
377
|
+
setMessage(wrote);
|
|
378
|
+
}
|
|
298
379
|
|
|
299
380
|
// If the save promoted a custom color to a built-in, drop the
|
|
300
381
|
// localStorage custom (now redundant), point the active color at the
|
|
@@ -317,8 +398,19 @@ export function SaveBar() {
|
|
|
317
398
|
// 0 until the user changes something else. The customizations stay in
|
|
318
399
|
// their own localStorage keys (and stay applied visually) — only the
|
|
319
400
|
// counter's reference point moves.
|
|
320
|
-
|
|
321
|
-
|
|
401
|
+
const sent = tokenValuesFrom(snapshot.tokenOverrides);
|
|
402
|
+
const refused = new Set(rejected.map((r) => r.path));
|
|
403
|
+
const kept = Object.fromEntries(
|
|
404
|
+
Object.entries(snapshot.tokenOverrides ?? {}).filter(([key]) => {
|
|
405
|
+
const path = overridePath(key);
|
|
406
|
+
// Only a row that was sent and not refused counts as saved.
|
|
407
|
+
return !path || (path in sent && !refused.has(path));
|
|
408
|
+
}),
|
|
409
|
+
);
|
|
410
|
+
const baseline = { ...snapshot, tokenOverrides: Object.keys(kept).length ? kept : null };
|
|
411
|
+
window.localStorage.setItem(SAVED_SNAPSHOT_KEY, JSON.stringify(baseline));
|
|
412
|
+
setSavedSnapshot(baseline);
|
|
413
|
+
if (rejected.length > 0) return;
|
|
322
414
|
window.setTimeout(() => {
|
|
323
415
|
setStatus("idle");
|
|
324
416
|
setMessage(null);
|
|
@@ -341,9 +433,30 @@ export function SaveBar() {
|
|
|
341
433
|
window.location.reload();
|
|
342
434
|
}, []);
|
|
343
435
|
|
|
436
|
+
// The save route answers 403 outside development, so the inline block would only ever show an error on a
|
|
437
|
+
// deployed site. Export and Import (client-side) stay available in the Studio; Save is a local-dev action.
|
|
438
|
+
if (inline && process.env.NODE_ENV !== "development") return null;
|
|
344
439
|
if (!snapshot) return null;
|
|
345
440
|
const count = diffCount(snapshot, savedSnapshot);
|
|
346
|
-
if (count === 0 && status === "idle") return null;
|
|
441
|
+
if (count === 0 && status === "idle" && !inline) return null;
|
|
442
|
+
|
|
443
|
+
if (inline) {
|
|
444
|
+
return (
|
|
445
|
+
<div data-slot="save-bar" className="flex min-w-0 flex-col gap-3">
|
|
446
|
+
<p role="status" aria-live="polite" className="text-xs text-muted-foreground">
|
|
447
|
+
{status === "saved" || status === "error"
|
|
448
|
+
? message
|
|
449
|
+
: count === 0
|
|
450
|
+
? "Nothing to save. Changes you make are kept in this browser."
|
|
451
|
+
: `${count} change${count === 1 ? "" : "s"} not saved to tokens.json yet.`}
|
|
452
|
+
</p>
|
|
453
|
+
<Button size="xl" className="w-full gap-2" onClick={handleSave} disabled={status === "saving" || count === 0}>
|
|
454
|
+
<Save className="h-4 w-4" aria-hidden="true" />
|
|
455
|
+
{status === "saving" ? "Saving" : "Save to tokens.json"}
|
|
456
|
+
</Button>
|
|
457
|
+
</div>
|
|
458
|
+
);
|
|
459
|
+
}
|
|
347
460
|
|
|
348
461
|
return (
|
|
349
462
|
<div className="fixed bottom-0 left-0 right-0 z-50 border-t bg-card/95 backdrop-blur supports-[backdrop-filter]:bg-card/80 shadow-lg">
|
|
@@ -20,27 +20,7 @@ import {
|
|
|
20
20
|
import { useGlobalPrimaryColor } from "@behavioral-agentic-design-system/core/hooks/use-global-primary-color";
|
|
21
21
|
import { Copy, Download, Upload, Check, RotateCcw, ExternalLink } from "lucide-react";
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
* Convert any CSS color string the browser can parse — oklch, hsl, rgb, hex,
|
|
25
|
-
* named — into a normalized #RRGGBB hex. Uses a temporary DOM probe so the
|
|
26
|
-
* browser does the actual color-space math; we just read getComputedStyle.
|
|
27
|
-
* Returns null if the string isn't a valid CSS color.
|
|
28
|
-
*/
|
|
29
|
-
function cssColorToHex(value: string): string | null {
|
|
30
|
-
if (typeof document === "undefined") return null;
|
|
31
|
-
const probe = document.createElement("div");
|
|
32
|
-
probe.style.color = "";
|
|
33
|
-
probe.style.color = value;
|
|
34
|
-
if (!probe.style.color) return null;
|
|
35
|
-
document.body.appendChild(probe);
|
|
36
|
-
const computed = getComputedStyle(probe).color;
|
|
37
|
-
document.body.removeChild(probe);
|
|
38
|
-
const m = computed.match(/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);
|
|
39
|
-
if (!m) return null;
|
|
40
|
-
const toHex = (n: string) =>
|
|
41
|
-
parseInt(n, 10).toString(16).padStart(2, "0").toUpperCase();
|
|
42
|
-
return `#${toHex(m[1])}${toHex(m[2])}${toHex(m[3])}`;
|
|
43
|
-
}
|
|
23
|
+
import { cssColorToHex } from "@behavioral-agentic-design-system/core/lib/css-color";
|
|
44
24
|
|
|
45
25
|
export function ThemeIO() {
|
|
46
26
|
const { hasTheme, importTheme, clearTheme } = useGlobalTheme();
|
|
@@ -243,3 +223,64 @@ export function ThemeIO() {
|
|
|
243
223
|
</div>
|
|
244
224
|
);
|
|
245
225
|
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Export only, for the Studio's Tweak tab. Shows the current theme as :root and .dark CSS (the same blocks the
|
|
229
|
+
* Import theme dialog reads) so a theme round-trips: export here, paste there.
|
|
230
|
+
*/
|
|
231
|
+
export function ExportThemeButton() {
|
|
232
|
+
const [open, setOpen] = useState(false);
|
|
233
|
+
const [value, setValue] = useState("");
|
|
234
|
+
const [copied, setCopied] = useState(false);
|
|
235
|
+
|
|
236
|
+
const copy = async () => {
|
|
237
|
+
try {
|
|
238
|
+
await navigator.clipboard.writeText(value);
|
|
239
|
+
setCopied(true);
|
|
240
|
+
setTimeout(() => setCopied(false), 2000);
|
|
241
|
+
} catch {
|
|
242
|
+
// clipboard unavailable: the text stays selectable
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
return (
|
|
247
|
+
<Dialog open={open} onOpenChange={setOpen}>
|
|
248
|
+
<DialogTrigger asChild>
|
|
249
|
+
<Button
|
|
250
|
+
type="button"
|
|
251
|
+
variant="outline"
|
|
252
|
+
size="xl"
|
|
253
|
+
className="w-full gap-2"
|
|
254
|
+
onClick={() => {
|
|
255
|
+
setValue(exportThemeCss());
|
|
256
|
+
setCopied(false);
|
|
257
|
+
}}
|
|
258
|
+
>
|
|
259
|
+
<Download className="h-4 w-4" aria-hidden="true" />
|
|
260
|
+
Export theme
|
|
261
|
+
</Button>
|
|
262
|
+
</DialogTrigger>
|
|
263
|
+
<DialogContent className="flex max-h-[85vh] flex-col sm:max-w-2xl">
|
|
264
|
+
<DialogHeader>
|
|
265
|
+
<DialogTitle>Export theme</DialogTitle>
|
|
266
|
+
<DialogDescription>The current theme as CSS, light and dark. Paste it into Import theme or tweakcn.</DialogDescription>
|
|
267
|
+
</DialogHeader>
|
|
268
|
+
<Textarea
|
|
269
|
+
aria-label="Theme CSS"
|
|
270
|
+
value={value}
|
|
271
|
+
readOnly
|
|
272
|
+
spellCheck={false}
|
|
273
|
+
className="h-[50vh] max-h-[50vh] resize-none overflow-auto font-mono text-xs"
|
|
274
|
+
onFocus={(e) => e.currentTarget.select()}
|
|
275
|
+
/>
|
|
276
|
+
<DialogFooter>
|
|
277
|
+
<Button variant="outline" size="xl" onClick={() => setOpen(false)}>Close</Button>
|
|
278
|
+
<Button size="xl" onClick={copy} className="gap-2">
|
|
279
|
+
{copied ? <Check className="h-4 w-4" aria-hidden="true" /> : <Copy className="h-4 w-4" aria-hidden="true" />}
|
|
280
|
+
{copied ? "Copied" : "Copy CSS"}
|
|
281
|
+
</Button>
|
|
282
|
+
</DialogFooter>
|
|
283
|
+
</DialogContent>
|
|
284
|
+
</Dialog>
|
|
285
|
+
);
|
|
286
|
+
}
|
|
@@ -29,6 +29,7 @@ import { ThemeIO } from "@behavioral-agentic-design-system/core/components/custo
|
|
|
29
29
|
import { BrandMarkSection } from "@behavioral-agentic-design-system/core/components/customize/brand-mark-section";
|
|
30
30
|
import { DesignControlsPanel } from "@behavioral-agentic-design-system/core/components/customize/design-controls";
|
|
31
31
|
import {
|
|
32
|
+
HeadingFontPicker,
|
|
32
33
|
SansFontPicker,
|
|
33
34
|
SerifFontPicker,
|
|
34
35
|
MonoFontPicker,
|
|
@@ -694,10 +695,11 @@ export function ColorPalette() {
|
|
|
694
695
|
<section>
|
|
695
696
|
<h2 className="text-2xl font-semibold tracking-tight mb-2">Typography</h2>
|
|
696
697
|
<p className="text-sm text-muted-foreground mb-8 max-w-prose">
|
|
697
|
-
|
|
698
|
+
Heading, body, serif, and mono fonts each apply system-wide. Choices persist
|
|
698
699
|
and propagate across every preview screen.
|
|
699
700
|
</p>
|
|
700
701
|
<div className="space-y-12">
|
|
702
|
+
<HeadingFontPicker />
|
|
701
703
|
<SansFontPicker />
|
|
702
704
|
<SerifFontPicker />
|
|
703
705
|
<MonoFontPicker />
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
+
import { Link } from "@behavioral-agentic-design-system/core/components/ui/link";
|
|
4
|
+
import { storybookPageUrl, type StoryRef } from "@behavioral-agentic-design-system/core/lib/storybook-url";
|
|
3
5
|
import added from "../data/component-added.json";
|
|
6
|
+
import stories from "../data/component-stories.json";
|
|
4
7
|
|
|
5
8
|
export type RecentItem = { name: string; date: string; kind: "primitive" | "composition" };
|
|
6
9
|
|
|
@@ -25,12 +28,24 @@ function newest(): RecentItem[] {
|
|
|
25
28
|
|
|
26
29
|
const ITEMS = newest();
|
|
27
30
|
|
|
31
|
+
/** The component's own Storybook page, from the generated map (pnpm build:component-stories). "" when it has none. */
|
|
32
|
+
function storyHref(name: string): string {
|
|
33
|
+
const ref = (stories as Record<string, StoryRef | null>)[name];
|
|
34
|
+
return ref ? storybookPageUrl(ref) : "";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const TILE =
|
|
38
|
+
"flex min-h-11 w-full min-w-0 flex-col gap-0.5 overflow-hidden rounded-lg bg-muted/50 px-4 py-3 text-left transition-colors hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2";
|
|
39
|
+
|
|
28
40
|
/**
|
|
29
41
|
* "Recently added": the newest components in the system, so new work is visible without hunting for it.
|
|
30
42
|
*
|
|
31
43
|
* It reads packages/core/src/data/component-added.json, which `pnpm check:showcase-placement` requires an entry in
|
|
32
|
-
* for every registry component.
|
|
33
|
-
*
|
|
44
|
+
* for every registry component. Storybook is the source of truth for components, so each entry is a real link to that
|
|
45
|
+
* component's own Storybook page (ids come from data/component-stories.json, generated from the story files, see
|
|
46
|
+
* scripts/build-component-stories.mjs). Like the other Storybook links on this site it opens in a new tab. An entry
|
|
47
|
+
* with no story, or a deploy with no Storybook, falls back to the old behavior: a primitive opens the Components tab
|
|
48
|
+
* and a composition opens Studio's Cards. Upstream only: a client fork has none of these compositions to open.
|
|
34
49
|
*/
|
|
35
50
|
export function RecentlyAdded({ onOpen }: { onOpen: (item: RecentItem) => void }) {
|
|
36
51
|
if (ITEMS.length === 0) return null;
|
|
@@ -41,32 +56,50 @@ export function RecentlyAdded({ onOpen }: { onOpen: (item: RecentItem) => void }
|
|
|
41
56
|
Recently added
|
|
42
57
|
</h2>
|
|
43
58
|
<p className="mt-1 text-sm text-muted-foreground">
|
|
44
|
-
The newest {ITEMS.length} components. Each opens
|
|
59
|
+
The newest {ITEMS.length} components. Each opens its Storybook page.
|
|
45
60
|
</p>
|
|
46
61
|
</div>
|
|
47
62
|
<ul className="grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4">
|
|
48
|
-
{ITEMS.map((item) =>
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
63
|
+
{ITEMS.map((item) => {
|
|
64
|
+
const href = storyHref(item.name);
|
|
65
|
+
const meta = `${item.kind === "composition" ? "Composition" : "Primitive"} · ${shortDate(item.date)}`;
|
|
66
|
+
const style = {
|
|
67
|
+
transitionDuration: "var(--duration-fast)",
|
|
68
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
69
|
+
};
|
|
70
|
+
return (
|
|
71
|
+
<li key={item.name} className="min-w-0">
|
|
72
|
+
{href ? (
|
|
73
|
+
<Link asChild underline="none" tone="foreground" className={TILE} style={style}>
|
|
74
|
+
<a
|
|
75
|
+
href={href}
|
|
76
|
+
target="_blank"
|
|
77
|
+
rel="noopener noreferrer"
|
|
78
|
+
aria-label={`${item.name}, a ${item.kind} added ${shortDate(item.date)}. Opens its Storybook page in a new tab.`}
|
|
79
|
+
title={item.name}
|
|
80
|
+
>
|
|
81
|
+
<span className="truncate text-sm font-medium text-foreground">{item.name}</span>
|
|
82
|
+
<span className="text-xs text-muted-foreground">{meta}</span>
|
|
83
|
+
</a>
|
|
84
|
+
</Link>
|
|
85
|
+
) : (
|
|
86
|
+
<button
|
|
87
|
+
type="button"
|
|
88
|
+
onClick={() => onOpen(item)}
|
|
89
|
+
aria-label={`${item.name}, a ${item.kind} added ${shortDate(item.date)}. Opens ${
|
|
90
|
+
item.kind === "composition" ? "Studio, Cards" : "the Components tab"
|
|
91
|
+
}.`}
|
|
92
|
+
className={TILE}
|
|
93
|
+
style={style}
|
|
94
|
+
title={item.name}
|
|
95
|
+
>
|
|
96
|
+
<span className="truncate text-sm font-medium text-foreground">{item.name}</span>
|
|
97
|
+
<span className="text-xs text-muted-foreground">{meta}</span>
|
|
98
|
+
</button>
|
|
99
|
+
)}
|
|
100
|
+
</li>
|
|
101
|
+
);
|
|
102
|
+
})}
|
|
70
103
|
</ul>
|
|
71
104
|
</section>
|
|
72
105
|
);
|