@behavioral-agentic-design-system/core 0.5.0 → 0.7.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/LICENSE +21 -0
- package/package.json +39 -7
- package/scripts/bads-sync.mjs +1 -1
- package/scripts/build-fonts.cjs +97 -0
- package/scripts/build-tokens.cjs +202 -10
- package/src/api/brand-fonts.ts +301 -0
- package/src/api/brand-mark.ts +146 -0
- package/src/api/layers/file.ts +8 -5
- package/src/api/layers.ts +27 -4
- package/src/api/site-auth.ts +50 -0
- package/src/app/preview/cards/page.tsx +1 -1
- package/src/app/preview/components/page.tsx +78 -1
- package/src/app/preview/icons/page.tsx +5 -0
- package/src/app/shell.tsx +105 -39
- package/src/app/site-login/page.tsx +82 -0
- package/src/brand-fonts.css +5 -0
- package/src/components/Foundations/Motion.stories.tsx +66 -0
- package/src/components/brand-mark.tsx +64 -0
- package/src/components/customize/brand-mark-section.tsx +265 -0
- package/src/components/customize/font-pickers.tsx +293 -0
- package/src/components/customize/letter-spacing.tsx +3 -2
- package/src/components/customize/save-bar.tsx +11 -5
- package/src/components/customize/type-scale.tsx +3 -2
- package/src/components/customize-tab.tsx +330 -24
- package/src/components/dev-identity-badge.tsx +92 -0
- package/src/components/home-tab.tsx +1291 -380
- package/src/components/layers-tab.tsx +179 -12
- package/src/components/ui/alert.tsx +10 -2
- package/src/components/ui/bottom-sheet.tsx +124 -0
- package/src/components/ui/button.tsx +2 -2
- package/src/components/ui/calendar.tsx +1 -1
- package/src/components/ui/chart.tsx +118 -7
- package/src/components/ui/checkbox.tsx +3 -2
- package/src/components/ui/dialog.tsx +3 -3
- package/src/components/ui/index.ts +1 -0
- package/src/components/ui/radio-group.tsx +4 -3
- package/src/components/ui/sheet.tsx +1 -1
- package/src/components/ui/sidebar.tsx +6 -1
- package/src/components/ui/sonner.tsx +18 -0
- package/src/components/ui/switch.tsx +9 -3
- package/src/components/ui/tabs.tsx +7 -1
- package/src/fonts/HyperlegibleSans-Bold.woff2 +0 -0
- package/src/fonts/HyperlegibleSans-BoldItalic.woff2 +0 -0
- package/src/fonts/HyperlegibleSans-Italic.woff2 +0 -0
- package/src/fonts/HyperlegibleSans-Medium.woff2 +0 -0
- package/src/fonts/HyperlegibleSans-MediumItalic.woff2 +0 -0
- package/src/fonts/HyperlegibleSans-Regular.woff2 +0 -0
- package/src/fonts/InterVariable-Italic.woff2 +0 -0
- package/src/fonts/InterVariable.woff2 +0 -0
- package/src/fonts.css +99 -0
- package/src/hooks/use-global-brand-mark.ts +64 -0
- package/src/hooks/use-global-mono-font.ts +13 -3
- package/src/hooks/use-global-primary-color.ts +192 -9
- package/src/hooks/use-global-sans-font.ts +5 -3
- package/src/hooks/use-global-serif-font.ts +13 -3
- package/src/lib/storage.ts +29 -0
- package/src/lib/svg-sanitize.ts +272 -0
- package/src/styles.css +126 -6
- package/src/tokens.json +100 -9
- package/src/app/preview/mail/page.tsx +0 -4
- package/src/app/preview/pricing/page.tsx +0 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { useState } from "react";
|
|
4
|
-
import { Check, Plus, Pencil, Trash2, MoreHorizontal } from "lucide-react";
|
|
3
|
+
import { useState, useMemo, createContext, useContext } from "react";
|
|
4
|
+
import { Check, Plus, Pencil, Trash2, MoreHorizontal, AlertCircle, RotateCcw } from "lucide-react";
|
|
5
5
|
import { HexColorPicker } from "react-colorful";
|
|
6
6
|
import { ScrollArea } from "@behavioral-agentic-design-system/core/components/ui/scroll-area";
|
|
7
7
|
import { Button } from "@behavioral-agentic-design-system/core/components/ui/button";
|
|
@@ -19,11 +19,14 @@ import {
|
|
|
19
19
|
} from "@behavioral-agentic-design-system/core/components/ui/dropdown-menu";
|
|
20
20
|
import {
|
|
21
21
|
useGlobalPrimaryColor,
|
|
22
|
+
reapplyChartRamp,
|
|
22
23
|
type PrimaryColorKey,
|
|
23
24
|
type PrimaryColorOption,
|
|
24
25
|
type WcagGrade,
|
|
25
26
|
} from "@behavioral-agentic-design-system/core/hooks/use-global-primary-color";
|
|
27
|
+
import { useTokenOverrides } from "@behavioral-agentic-design-system/core/hooks/use-token-overrides";
|
|
26
28
|
import { ThemeIO } from "@behavioral-agentic-design-system/core/components/customize/theme-io";
|
|
29
|
+
import { BrandMarkSection } from "@behavioral-agentic-design-system/core/components/customize/brand-mark-section";
|
|
27
30
|
import { DesignControlsPanel } from "@behavioral-agentic-design-system/core/components/customize/design-controls";
|
|
28
31
|
import {
|
|
29
32
|
SansFontPicker,
|
|
@@ -35,6 +38,23 @@ import { LetterSpacingPanel } from "@behavioral-agentic-design-system/core/compo
|
|
|
35
38
|
import { SaveBar } from "@behavioral-agentic-design-system/core/components/customize/save-bar";
|
|
36
39
|
import { nameFromHex } from "@behavioral-agentic-design-system/core/lib/color-name";
|
|
37
40
|
|
|
41
|
+
type TokenSwatchPickerCtx = {
|
|
42
|
+
options: Record<string, PrimaryColorOption>;
|
|
43
|
+
overrides: Record<string, string>;
|
|
44
|
+
setToken: (variable: string, value: string) => void;
|
|
45
|
+
resetToken: (variable: string) => void;
|
|
46
|
+
/**
|
|
47
|
+
* Add a new color to the brand palette WITHOUT making it the active
|
|
48
|
+
* primary. The "+" tile inside ColorSwatch's popover uses this so a
|
|
49
|
+
* one-off color picked for a single token (e.g. --background) lands in
|
|
50
|
+
* the brand list for reuse but never hijacks --primary, --ring, --accent-
|
|
51
|
+
* foreground, etc. Token-scoped picks stay token-scoped.
|
|
52
|
+
*/
|
|
53
|
+
addCustomSilent: (hex: string, label?: string) => string | null;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const TokenSwatchPicker = createContext<TokenSwatchPickerCtx | null>(null);
|
|
57
|
+
|
|
38
58
|
function ColorSwatch({
|
|
39
59
|
name,
|
|
40
60
|
className,
|
|
@@ -46,20 +66,218 @@ function ColorSwatch({
|
|
|
46
66
|
variable: string;
|
|
47
67
|
textClassName?: string;
|
|
48
68
|
}) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
69
|
+
const ctx = useContext(TokenSwatchPicker);
|
|
70
|
+
// Defensive fallback — if mounted without provider, still render the swatch
|
|
71
|
+
// so the section degrades gracefully instead of throwing in storybook etc.
|
|
72
|
+
if (!ctx) {
|
|
73
|
+
return (
|
|
74
|
+
<div>
|
|
75
|
+
<div className={`h-20 rounded-lg border ${className} flex items-end p-2.5`}>
|
|
76
|
+
<span className={`text-xs font-medium truncate ${textClassName ?? ""}`}>{name}</span>
|
|
77
|
+
</div>
|
|
78
|
+
<p className="text-xs text-muted-foreground font-mono mt-1.5 truncate">{variable}</p>
|
|
53
79
|
</div>
|
|
54
|
-
|
|
55
|
-
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
const { options, overrides, setToken, resetToken, addCustomSilent } = ctx;
|
|
83
|
+
const isOverridden = variable in overrides;
|
|
84
|
+
const currentHex = overrides[variable]?.toUpperCase();
|
|
85
|
+
const entries = Object.entries(options);
|
|
86
|
+
|
|
87
|
+
// Inline "+ add color" state. When showAdd is true the popover swaps the
|
|
88
|
+
// brand-color grid for a HexColorPicker so designers can introduce a new
|
|
89
|
+
// brand color without leaving the per-token swatch picker. Save pushes
|
|
90
|
+
// the color to the brand palette (via addCustomSilent — does NOT change
|
|
91
|
+
// --primary or any brand-derived var) AND applies it ONLY to the current
|
|
92
|
+
// token via setToken. Token-scoped picks stay token-scoped.
|
|
93
|
+
const [showAdd, setShowAdd] = useState(false);
|
|
94
|
+
const [newHex, setNewHex] = useState("#1F1F1F");
|
|
95
|
+
const [newLabel, setNewLabel] = useState("");
|
|
96
|
+
const [addError, setAddError] = useState<string | null>(null);
|
|
97
|
+
|
|
98
|
+
const resetAddState = () => {
|
|
99
|
+
setShowAdd(false);
|
|
100
|
+
setNewHex("#1F1F1F");
|
|
101
|
+
setNewLabel("");
|
|
102
|
+
setAddError(null);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const handleAddAndApply = () => {
|
|
106
|
+
const value = newHex.trim();
|
|
107
|
+
if (!isValidHex(value)) {
|
|
108
|
+
setAddError("Enter a valid hex like #1F1F1F");
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const id = addCustomSilent(value, newLabel.trim() || undefined);
|
|
112
|
+
if (!id) {
|
|
113
|
+
setAddError("Could not add color");
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
setToken(variable, value.toUpperCase());
|
|
117
|
+
resetAddState();
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
return (
|
|
121
|
+
<Popover>
|
|
122
|
+
<PopoverTrigger asChild>
|
|
123
|
+
<button
|
|
124
|
+
type="button"
|
|
125
|
+
aria-label={`Edit ${variable}`}
|
|
126
|
+
className="group block w-full text-left rounded-lg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
|
|
127
|
+
>
|
|
128
|
+
<div
|
|
129
|
+
className={`h-20 rounded-lg border ${className} flex items-end p-2.5 transition-all group-hover:border-foreground/40 ${
|
|
130
|
+
isOverridden ? "ring-2 ring-primary/30" : ""
|
|
131
|
+
}`}
|
|
132
|
+
>
|
|
133
|
+
<span className={`text-xs font-medium truncate ${textClassName ?? ""}`}>{name}</span>
|
|
134
|
+
</div>
|
|
135
|
+
<p className="text-xs text-muted-foreground font-mono mt-1.5 truncate">{variable}</p>
|
|
136
|
+
</button>
|
|
137
|
+
</PopoverTrigger>
|
|
138
|
+
<PopoverContent align="start" className="w-72 p-3">
|
|
139
|
+
<div className="flex items-center justify-between gap-2 mb-3">
|
|
140
|
+
<p className="text-xs font-mono text-muted-foreground truncate">{variable}</p>
|
|
141
|
+
{!showAdd && isOverridden && (
|
|
142
|
+
<button
|
|
143
|
+
type="button"
|
|
144
|
+
onClick={() => {
|
|
145
|
+
resetToken(variable);
|
|
146
|
+
// Chart vars are written inline by use-global-primary-color
|
|
147
|
+
// so clearing the override here doesn't put the live --chart-N
|
|
148
|
+
// back into a brand-derived state — call back into the hook
|
|
149
|
+
// to re-evaluate the ramp against the current --primary.
|
|
150
|
+
if (variable.startsWith("--chart-")) {
|
|
151
|
+
reapplyChartRamp();
|
|
152
|
+
}
|
|
153
|
+
}}
|
|
154
|
+
className="inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors"
|
|
155
|
+
>
|
|
156
|
+
<RotateCcw className="h-3 w-3" strokeWidth={1.5} />
|
|
157
|
+
Reset
|
|
158
|
+
</button>
|
|
159
|
+
)}
|
|
160
|
+
{showAdd && (
|
|
161
|
+
<button
|
|
162
|
+
type="button"
|
|
163
|
+
onClick={resetAddState}
|
|
164
|
+
className="text-xs text-muted-foreground hover:text-foreground transition-colors"
|
|
165
|
+
>
|
|
166
|
+
Back
|
|
167
|
+
</button>
|
|
168
|
+
)}
|
|
169
|
+
</div>
|
|
170
|
+
|
|
171
|
+
{showAdd ? (
|
|
172
|
+
<div className="flex flex-col gap-3">
|
|
173
|
+
<HexColorPicker
|
|
174
|
+
style={{ width: "100%", height: "180px" }}
|
|
175
|
+
color={isValidHex(newHex) ? newHex : "#1F1F1F"}
|
|
176
|
+
onChange={(c) => {
|
|
177
|
+
setNewHex(c.toUpperCase());
|
|
178
|
+
if (addError) setAddError(null);
|
|
179
|
+
}}
|
|
180
|
+
/>
|
|
181
|
+
<Input
|
|
182
|
+
value={newLabel}
|
|
183
|
+
onChange={(e) => setNewLabel(e.target.value)}
|
|
184
|
+
placeholder={`Label — auto: ${isValidHex(newHex) ? nameFromHex(newHex) : "—"}`}
|
|
185
|
+
className="h-9"
|
|
186
|
+
/>
|
|
187
|
+
<div className="flex items-center gap-2">
|
|
188
|
+
<Input
|
|
189
|
+
value={newHex}
|
|
190
|
+
onChange={(e) => {
|
|
191
|
+
setNewHex(e.target.value);
|
|
192
|
+
if (addError) setAddError(null);
|
|
193
|
+
}}
|
|
194
|
+
onKeyDown={(e) => {
|
|
195
|
+
if (e.key === "Enter") handleAddAndApply();
|
|
196
|
+
}}
|
|
197
|
+
placeholder="#1F1F1F"
|
|
198
|
+
className="h-9 flex-1 min-w-0 font-mono text-sm"
|
|
199
|
+
/>
|
|
200
|
+
<Button size="sm" onClick={handleAddAndApply}>
|
|
201
|
+
Add
|
|
202
|
+
</Button>
|
|
203
|
+
</div>
|
|
204
|
+
{addError && <span className="text-xs text-destructive">{addError}</span>}
|
|
205
|
+
<p className="text-xs text-muted-foreground">
|
|
206
|
+
Saved to your brand colors and applied here.
|
|
207
|
+
</p>
|
|
208
|
+
</div>
|
|
209
|
+
) : (
|
|
210
|
+
<div className="grid grid-cols-4 gap-2">
|
|
211
|
+
{entries.map(([key, opt]) => {
|
|
212
|
+
const swatch = opt.swatch ?? opt.primary;
|
|
213
|
+
const isActive =
|
|
214
|
+
currentHex !== undefined &&
|
|
215
|
+
currentHex === (swatch ?? "").toUpperCase();
|
|
216
|
+
return (
|
|
217
|
+
<button
|
|
218
|
+
key={key}
|
|
219
|
+
type="button"
|
|
220
|
+
onClick={() => setToken(variable, swatch)}
|
|
221
|
+
title={`${opt.label} · ${swatch}`}
|
|
222
|
+
className={`group/sw flex flex-col items-center gap-1.5 rounded-md border p-2 transition-all ${
|
|
223
|
+
isActive
|
|
224
|
+
? "border-primary ring-2 ring-primary/30"
|
|
225
|
+
: "border-border hover:border-foreground/40"
|
|
226
|
+
}`}
|
|
227
|
+
>
|
|
228
|
+
<div
|
|
229
|
+
className="relative h-7 w-7 rounded-full border border-border/50"
|
|
230
|
+
style={{ backgroundColor: swatch }}
|
|
231
|
+
>
|
|
232
|
+
{isActive && (
|
|
233
|
+
<Check
|
|
234
|
+
className="absolute inset-0 m-auto h-3.5 w-3.5"
|
|
235
|
+
style={{ color: opt.swatchForeground ?? opt.primaryForeground }}
|
|
236
|
+
strokeWidth={1.5}
|
|
237
|
+
/>
|
|
238
|
+
)}
|
|
239
|
+
</div>
|
|
240
|
+
<span className="text-xs leading-tight truncate w-full text-center">
|
|
241
|
+
{opt.label}
|
|
242
|
+
</span>
|
|
243
|
+
</button>
|
|
244
|
+
);
|
|
245
|
+
})}
|
|
246
|
+
<button
|
|
247
|
+
type="button"
|
|
248
|
+
onClick={() => setShowAdd(true)}
|
|
249
|
+
title="Add a new brand color and apply it here"
|
|
250
|
+
className="group/sw flex flex-col items-center gap-1.5 rounded-md border border-dashed border-border p-2 transition-all hover:border-foreground/40"
|
|
251
|
+
>
|
|
252
|
+
<div className="flex h-7 w-7 items-center justify-center rounded-full border border-dashed border-border/60 text-muted-foreground group-hover/sw:text-foreground">
|
|
253
|
+
<Plus className="h-3.5 w-3.5" strokeWidth={1.5} />
|
|
254
|
+
</div>
|
|
255
|
+
<span className="text-xs leading-tight text-muted-foreground group-hover/sw:text-foreground truncate w-full text-center">
|
|
256
|
+
Add
|
|
257
|
+
</span>
|
|
258
|
+
</button>
|
|
259
|
+
</div>
|
|
260
|
+
)}
|
|
261
|
+
</PopoverContent>
|
|
262
|
+
</Popover>
|
|
56
263
|
);
|
|
57
264
|
}
|
|
58
265
|
|
|
59
|
-
function ColorSection({
|
|
266
|
+
function ColorSection({
|
|
267
|
+
title,
|
|
268
|
+
action,
|
|
269
|
+
children,
|
|
270
|
+
}: {
|
|
271
|
+
title: string;
|
|
272
|
+
action?: React.ReactNode;
|
|
273
|
+
children: React.ReactNode;
|
|
274
|
+
}) {
|
|
60
275
|
return (
|
|
61
276
|
<div>
|
|
62
|
-
<
|
|
277
|
+
<div className="flex items-center justify-between mb-4">
|
|
278
|
+
<h4 className="text-base font-semibold">{title}</h4>
|
|
279
|
+
{action}
|
|
280
|
+
</div>
|
|
63
281
|
<div className="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-3">
|
|
64
282
|
{children}
|
|
65
283
|
</div>
|
|
@@ -67,6 +285,32 @@ function ColorSection({ title, children }: { title: string; children: React.Reac
|
|
|
67
285
|
);
|
|
68
286
|
}
|
|
69
287
|
|
|
288
|
+
function ResetChartTokensButton() {
|
|
289
|
+
const ctx = useContext(TokenSwatchPicker);
|
|
290
|
+
if (!ctx) return null;
|
|
291
|
+
const overridden = ["--chart-1", "--chart-2", "--chart-3", "--chart-4", "--chart-5"].filter(
|
|
292
|
+
(v) => v in ctx.overrides,
|
|
293
|
+
);
|
|
294
|
+
if (overridden.length === 0) return null;
|
|
295
|
+
return (
|
|
296
|
+
<Button
|
|
297
|
+
variant="outline"
|
|
298
|
+
size="sm"
|
|
299
|
+
onClick={() => {
|
|
300
|
+
overridden.forEach((v) => ctx.resetToken(v));
|
|
301
|
+
// resetToken removes the inline value. Without this, the cascade
|
|
302
|
+
// would fall through to Lightning CSS's precomputed lab() rule
|
|
303
|
+
// (frozen at build-time --primary) instead of the brand ramp.
|
|
304
|
+
reapplyChartRamp();
|
|
305
|
+
}}
|
|
306
|
+
className="text-xs gap-1.5"
|
|
307
|
+
>
|
|
308
|
+
<RotateCcw className="h-3 w-3" strokeWidth={1.5} />
|
|
309
|
+
Reset {overridden.length === 5 ? "all" : `${overridden.length}`}
|
|
310
|
+
</Button>
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
|
|
70
314
|
function isValidHex(v: string) {
|
|
71
315
|
return /^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(v.trim());
|
|
72
316
|
}
|
|
@@ -241,6 +485,18 @@ function BrandColorCard({
|
|
|
241
485
|
// trigger is a sibling of the card button, so it needs the group on a
|
|
242
486
|
// shared ancestor for `group-hover:opacity-100` to fire on card hover.
|
|
243
487
|
<div className="group relative">
|
|
488
|
+
{opt.grade !== "AAA" && (
|
|
489
|
+
<span
|
|
490
|
+
className="pointer-events-none absolute -top-2 -right-2 z-10 inline-flex h-7 w-7 items-center justify-center rounded-full bg-amber-50 dark:bg-amber-950 border border-amber-300 dark:border-amber-700 shadow-sm"
|
|
491
|
+
title={`Below WCAG AAA — current ${opt.contrast}:1 (${opt.grade}), required 7:1`}
|
|
492
|
+
aria-label={`${opt.label} is below WCAG AAA contrast`}
|
|
493
|
+
>
|
|
494
|
+
<AlertCircle
|
|
495
|
+
className="h-4 w-4 text-amber-600 dark:text-amber-500"
|
|
496
|
+
strokeWidth={1.5}
|
|
497
|
+
/>
|
|
498
|
+
</span>
|
|
499
|
+
)}
|
|
244
500
|
<button
|
|
245
501
|
type="button"
|
|
246
502
|
onClick={onSelect}
|
|
@@ -339,9 +595,6 @@ function BrandColorCard({
|
|
|
339
595
|
}
|
|
340
596
|
|
|
341
597
|
function PrimaryColorPicker() {
|
|
342
|
-
// Note: the hook still exports pinCustom but the Save Bar's Save-to-
|
|
343
|
-
// tokens.json flow handles "promote custom to built-in" automatically,
|
|
344
|
-
// so we don't surface a separate Pin action here.
|
|
345
598
|
const {
|
|
346
599
|
color,
|
|
347
600
|
setColor,
|
|
@@ -352,27 +605,70 @@ function PrimaryColorPicker() {
|
|
|
352
605
|
renameCustom,
|
|
353
606
|
removeBuiltin,
|
|
354
607
|
renameBuiltin,
|
|
608
|
+
resetToDefaults,
|
|
609
|
+
isCustomized,
|
|
355
610
|
} = useGlobalPrimaryColor();
|
|
356
611
|
const keys = Object.keys(options) as PrimaryColorKey[];
|
|
612
|
+
const activeOption = options[color];
|
|
613
|
+
|
|
614
|
+
const hasContrast = useMemo(() => {
|
|
615
|
+
return activeOption && activeOption.grade !== "Fail";
|
|
616
|
+
}, [activeOption]);
|
|
617
|
+
|
|
618
|
+
const contrastWarning = useMemo(() => {
|
|
619
|
+
if (!activeOption || activeOption.grade === "AAA") return null;
|
|
620
|
+
return {
|
|
621
|
+
ratio: activeOption.contrast,
|
|
622
|
+
current: activeOption.grade,
|
|
623
|
+
};
|
|
624
|
+
}, [activeOption]);
|
|
625
|
+
|
|
357
626
|
return (
|
|
358
627
|
<div>
|
|
359
|
-
<
|
|
628
|
+
<div className="flex items-center justify-between mb-2">
|
|
629
|
+
<h2 className="text-2xl font-semibold tracking-tight">Brand Color</h2>
|
|
630
|
+
{isCustomized && (
|
|
631
|
+
<Button
|
|
632
|
+
variant="outline"
|
|
633
|
+
size="sm"
|
|
634
|
+
onClick={resetToDefaults}
|
|
635
|
+
className="text-xs"
|
|
636
|
+
>
|
|
637
|
+
Reset to Defaults
|
|
638
|
+
</Button>
|
|
639
|
+
)}
|
|
640
|
+
</div>
|
|
641
|
+
|
|
360
642
|
<p className="text-sm text-muted-foreground mb-6 max-w-prose">
|
|
361
|
-
|
|
362
|
-
<span className="font-medium text-foreground">+ Add color</span>
|
|
363
|
-
your browser
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
the repo. Built-ins can be renamed or deleted directly from each card.
|
|
643
|
+
Change the primary brand color used across every preview.{" "}
|
|
644
|
+
<span className="font-medium text-foreground">+ Add color</span> lets you try a
|
|
645
|
+
one-off in your browser. Hit{" "}
|
|
646
|
+
<span className="font-medium text-foreground">Save</span> to make it a built-in
|
|
647
|
+
for the whole team. Rename or delete built-ins from each card.
|
|
367
648
|
</p>
|
|
649
|
+
|
|
650
|
+
{contrastWarning && (
|
|
651
|
+
<div className="flex items-start gap-3 p-3 mb-4 rounded-lg bg-amber-50 dark:bg-amber-950/30 border border-amber-200 dark:border-amber-900/50">
|
|
652
|
+
<AlertCircle className="h-4 w-4 text-amber-900 dark:text-amber-100 flex-shrink-0 mt-0.5" strokeWidth={1.5} />
|
|
653
|
+
<div className="flex-1 text-sm text-amber-900 dark:text-amber-100">
|
|
654
|
+
<p className="font-medium">
|
|
655
|
+
Warning: {activeOption?.label ?? "This color"} doesn't meet WCAG AAA contrast
|
|
656
|
+
</p>
|
|
657
|
+
<p className="text-xs mt-1">
|
|
658
|
+
Current: {contrastWarning.ratio}:1 (grade: {contrastWarning.current}) · Required: 7:1 (AAA)
|
|
659
|
+
</p>
|
|
660
|
+
<p className="text-xs mt-2">
|
|
661
|
+
You can keep this color anyway. The warning is informational only.
|
|
662
|
+
</p>
|
|
663
|
+
</div>
|
|
664
|
+
</div>
|
|
665
|
+
)}
|
|
666
|
+
|
|
368
667
|
<div className="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-4 xl:grid-cols-8 gap-3">
|
|
369
668
|
{keys.map((key) => {
|
|
370
669
|
const opt = options[key];
|
|
371
670
|
const isCustom = key in customs;
|
|
372
671
|
const isNeutral = key === "neutral";
|
|
373
|
-
// Customs: local rename / delete (no Pin — Save Bar handles that).
|
|
374
|
-
// Built-ins (except shadcn neutral): server-backed rename / delete.
|
|
375
|
-
// Neutral: read-only — it's the system fallback.
|
|
376
672
|
const actions: BrandCardActions = isCustom
|
|
377
673
|
? {
|
|
378
674
|
rename: (label) => renameCustom(key, label),
|
|
@@ -402,10 +698,19 @@ function PrimaryColorPicker() {
|
|
|
402
698
|
}
|
|
403
699
|
|
|
404
700
|
function ColorPalette() {
|
|
701
|
+
const { options, addCustomSilent } = useGlobalPrimaryColor();
|
|
702
|
+
const { overrides, updateOverride, remove } = useTokenOverrides();
|
|
703
|
+
const swatchCtx = useMemo<TokenSwatchPickerCtx>(
|
|
704
|
+
() => ({ options, overrides, setToken: updateOverride, resetToken: remove, addCustomSilent }),
|
|
705
|
+
[options, overrides, updateOverride, remove, addCustomSilent],
|
|
706
|
+
);
|
|
707
|
+
|
|
405
708
|
return (
|
|
709
|
+
<TokenSwatchPicker.Provider value={swatchCtx}>
|
|
406
710
|
<div className="p-8 pb-32 max-w-7xl mx-auto space-y-20">
|
|
407
711
|
<ThemeIO />
|
|
408
712
|
<PrimaryColorPicker />
|
|
713
|
+
<BrandMarkSection />
|
|
409
714
|
|
|
410
715
|
<section>
|
|
411
716
|
<h2 className="text-2xl font-semibold tracking-tight mb-2">Typography</h2>
|
|
@@ -465,7 +770,7 @@ function ColorPalette() {
|
|
|
465
770
|
<ColorSwatch name="Destructive Foreground" className="bg-destructive-foreground text-destructive" variable="--destructive-foreground" />
|
|
466
771
|
</ColorSection>
|
|
467
772
|
|
|
468
|
-
<ColorSection title="Charts">
|
|
773
|
+
<ColorSection title="Charts" action={<ResetChartTokensButton />}>
|
|
469
774
|
<ColorSwatch name="Chart 1" className="bg-chart-1" textClassName="text-white" variable="--chart-1" />
|
|
470
775
|
<ColorSwatch name="Chart 2" className="bg-chart-2" textClassName="text-white" variable="--chart-2" />
|
|
471
776
|
<ColorSwatch name="Chart 3" className="bg-chart-3" textClassName="text-white" variable="--chart-3" />
|
|
@@ -488,6 +793,7 @@ function ColorPalette() {
|
|
|
488
793
|
|
|
489
794
|
<SaveBar />
|
|
490
795
|
</div>
|
|
796
|
+
</TokenSwatchPicker.Provider>
|
|
491
797
|
);
|
|
492
798
|
}
|
|
493
799
|
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Tiny fixed-position chip pinned to the bottom-right corner in development.
|
|
7
|
+
* Renders the app name, current port, and a "mounted X ago" relative time
|
|
8
|
+
* stamp so the tab clearly identifies itself. Designed for the common
|
|
9
|
+
* confusion case: six Next dev servers running across different repos all
|
|
10
|
+
* fighting over ports, and you can't tell which tab is which.
|
|
11
|
+
*
|
|
12
|
+
* Auto-hides in production (`process.env.NODE_ENV === 'production'`). Mounts
|
|
13
|
+
* client-side so it can read `window.location.port` and the live "ago"
|
|
14
|
+
* counter. Click-through is preserved everywhere except the chip itself.
|
|
15
|
+
*
|
|
16
|
+
* Usage in a root layout:
|
|
17
|
+
*
|
|
18
|
+
* import { DevIdentityBadge } from "@behavioral-agentic-design-system/core/components/dev-identity-badge";
|
|
19
|
+
*
|
|
20
|
+
* export default function RootLayout({ children }) {
|
|
21
|
+
* return (
|
|
22
|
+
* <html>
|
|
23
|
+
* <body>
|
|
24
|
+
* {children}
|
|
25
|
+
* <DevIdentityBadge name="swimtopia-prototypes" />
|
|
26
|
+
* </body>
|
|
27
|
+
* </html>
|
|
28
|
+
* );
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* The `name` prop is the only required input. If unset, the badge shows the
|
|
32
|
+
* port + relative time only — still useful, just less specific.
|
|
33
|
+
*/
|
|
34
|
+
export function DevIdentityBadge({
|
|
35
|
+
name,
|
|
36
|
+
/** Optional extra label rendered after the name, e.g. branch or env. */
|
|
37
|
+
context,
|
|
38
|
+
/** Override visibility manually. Defaults to dev-mode only. */
|
|
39
|
+
visible,
|
|
40
|
+
}: {
|
|
41
|
+
name?: string;
|
|
42
|
+
context?: string;
|
|
43
|
+
visible?: boolean;
|
|
44
|
+
}) {
|
|
45
|
+
const [mounted, setMounted] = useState(false);
|
|
46
|
+
const [port, setPort] = useState<string | null>(null);
|
|
47
|
+
const [mountedAt] = useState(() => Date.now());
|
|
48
|
+
const [, force] = useState(0);
|
|
49
|
+
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
setMounted(true);
|
|
52
|
+
if (typeof window !== "undefined") {
|
|
53
|
+
setPort(window.location.port || "—");
|
|
54
|
+
}
|
|
55
|
+
// Re-render every 10s to refresh the relative time. Cheaper than every
|
|
56
|
+
// tick — the badge is meant to be glanceable, not a stopwatch.
|
|
57
|
+
const id = window.setInterval(() => force((n) => n + 1), 10_000);
|
|
58
|
+
return () => window.clearInterval(id);
|
|
59
|
+
}, []);
|
|
60
|
+
|
|
61
|
+
const show =
|
|
62
|
+
typeof visible === "boolean"
|
|
63
|
+
? visible
|
|
64
|
+
: process.env.NODE_ENV !== "production";
|
|
65
|
+
|
|
66
|
+
if (!show || !mounted) return null;
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<div
|
|
70
|
+
role="status"
|
|
71
|
+
aria-label="Development build identifier"
|
|
72
|
+
className="fixed bottom-3 right-3 z-[2147483647] pointer-events-auto select-none"
|
|
73
|
+
>
|
|
74
|
+
<div className="flex items-center gap-2 rounded-full border border-border bg-card/95 backdrop-blur-md shadow-sm px-3 py-1.5 text-xs font-mono text-muted-foreground">
|
|
75
|
+
<span className="flex h-1.5 w-1.5 rounded-full bg-primary animate-pulse" />
|
|
76
|
+
{name && <span className="text-foreground font-semibold">{name}</span>}
|
|
77
|
+
{context && <span>· {context}</span>}
|
|
78
|
+
{port && <span>:{port}</span>}
|
|
79
|
+
<span>· {relativeTime(mountedAt)}</span>
|
|
80
|
+
</div>
|
|
81
|
+
</div>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function relativeTime(from: number): string {
|
|
86
|
+
const seconds = Math.max(1, Math.floor((Date.now() - from) / 1000));
|
|
87
|
+
if (seconds < 60) return `${seconds}s ago`;
|
|
88
|
+
const minutes = Math.floor(seconds / 60);
|
|
89
|
+
if (minutes < 60) return `${minutes}m ago`;
|
|
90
|
+
const hours = Math.floor(minutes / 60);
|
|
91
|
+
return `${hours}h ago`;
|
|
92
|
+
}
|