@behavioral-agentic-design-system/core 0.2.0 → 0.3.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 +36 -5
- package/scripts/bads-sync.mjs +81 -0
- package/scripts/build-tokens.cjs +430 -0
- package/src/app/font-ready.tsx +51 -0
- package/src/app/layout.tsx +152 -0
- package/src/app/page.tsx +267 -0
- package/src/app/preview/cards/page.tsx +8 -0
- package/src/app/preview/components/page.tsx +232 -0
- package/src/app/preview/dark-mode-client.tsx +24 -0
- package/src/app/preview/dashboard/page.tsx +4 -0
- package/src/app/preview/global-font-client.tsx +36 -0
- package/src/app/preview/layout.tsx +13 -0
- package/src/app/preview/mail/page.tsx +4 -0
- package/src/app/preview/pricing/page.tsx +4 -0
- package/src/app/preview/typography/page.tsx +11 -0
- package/src/app/providers.tsx +49 -0
- package/src/components/Foundations/Colors.stories.tsx +85 -0
- package/src/components/Foundations/Motion.stories.tsx +169 -0
- package/src/components/Foundations/Radius.stories.tsx +36 -0
- package/src/components/Foundations/Shadows.stories.tsx +30 -0
- package/src/components/Foundations/Spacing.stories.tsx +35 -0
- package/src/components/Foundations/Typography.stories.tsx +68 -0
- package/src/components/bads-update-banner.tsx +120 -0
- package/src/components/customize/design-controls.tsx +165 -0
- package/src/components/customize/font-pickers.tsx +118 -0
- package/src/components/customize/letter-spacing.tsx +105 -0
- package/src/components/customize/save-bar.tsx +379 -0
- package/src/components/customize/theme-io.tsx +245 -0
- package/src/components/customize/type-scale.tsx +134 -0
- package/src/components/customize-tab.tsx +502 -0
- package/src/components/home-tab.tsx +1227 -0
- package/src/components/layers-tab.tsx +225 -0
- package/src/components/ui/alert.tsx +5 -1
- package/src/hooks/use-global-design-controls.ts +117 -0
- package/src/hooks/use-global-mono-font.ts +73 -0
- package/src/hooks/use-global-primary-color.ts +544 -0
- package/src/hooks/use-global-sans-font.ts +98 -0
- package/src/hooks/use-global-serif-font.ts +77 -0
- package/src/hooks/use-global-theme.ts +259 -0
- package/src/hooks/use-global-type-scale.ts +141 -0
- package/src/hooks/use-sync-type-scale.ts +51 -0
- package/src/hooks/use-token-overrides.ts +98 -0
- package/src/styles.css +20 -5
- package/src/tokens.json +5 -5
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Button } from "@behavioral-agentic-design-system/core/components/ui/button";
|
|
4
|
+
import { Slider } from "@behavioral-agentic-design-system/core/components/ui/slider";
|
|
5
|
+
import {
|
|
6
|
+
RATIO_PRESETS,
|
|
7
|
+
TYPE_SCALE_DEFAULTS,
|
|
8
|
+
TYPE_SCALE_RANGES,
|
|
9
|
+
computeSizes,
|
|
10
|
+
useGlobalTypeScale,
|
|
11
|
+
} from "@behavioral-agentic-design-system/core/hooks/use-global-type-scale";
|
|
12
|
+
import { RotateCcw } from "lucide-react";
|
|
13
|
+
|
|
14
|
+
const PREVIEW_ROWS = [
|
|
15
|
+
{ token: "text-3xl", label: "Display headline" },
|
|
16
|
+
{ token: "text-2xl", label: "Section title" },
|
|
17
|
+
{ token: "text-xl", label: "Card title" },
|
|
18
|
+
{ token: "text-lg", label: "Subhead" },
|
|
19
|
+
{ token: "text-base", label: "Body text — the quick brown fox jumps" },
|
|
20
|
+
{ token: "text-sm", label: "Secondary text — descriptions and helper copy" },
|
|
21
|
+
{ token: "text-xs", label: "Captions and labels" },
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
export function TypeScalePanel() {
|
|
25
|
+
const { scale, setScale, reset } = useGlobalTypeScale();
|
|
26
|
+
const sizes = computeSizes(scale);
|
|
27
|
+
const isCustom =
|
|
28
|
+
scale.base !== TYPE_SCALE_DEFAULTS.base ||
|
|
29
|
+
scale.ratio !== TYPE_SCALE_DEFAULTS.ratio;
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<section>
|
|
33
|
+
<div className="flex items-baseline justify-between gap-3 mb-2">
|
|
34
|
+
<h2 className="text-2xl font-semibold tracking-tight">Type Scale</h2>
|
|
35
|
+
{isCustom && (
|
|
36
|
+
<Button variant="ghost" size="sm" onClick={reset} className="gap-2">
|
|
37
|
+
<RotateCcw className="h-4 w-4" />
|
|
38
|
+
Reset
|
|
39
|
+
</Button>
|
|
40
|
+
)}
|
|
41
|
+
</div>
|
|
42
|
+
<p className="text-sm text-muted-foreground mb-8 max-w-prose">
|
|
43
|
+
Drives every <code>text-*</code> utility from a single base size and
|
|
44
|
+
modular ratio. Each step multiplies or divides by the ratio, so the
|
|
45
|
+
whole hierarchy stays harmonic when you change either control.
|
|
46
|
+
</p>
|
|
47
|
+
|
|
48
|
+
<div className="grid grid-cols-1 lg:grid-cols-2 gap-x-10 gap-y-8 mb-10">
|
|
49
|
+
<div className="space-y-3">
|
|
50
|
+
<div className="flex items-baseline justify-between gap-3">
|
|
51
|
+
<label className="text-sm font-semibold">Base Size</label>
|
|
52
|
+
<span className="text-xs text-muted-foreground font-mono tabular-nums">
|
|
53
|
+
{scale.base.toFixed(1)}px
|
|
54
|
+
</span>
|
|
55
|
+
</div>
|
|
56
|
+
<Slider
|
|
57
|
+
min={TYPE_SCALE_RANGES.base.min}
|
|
58
|
+
max={TYPE_SCALE_RANGES.base.max}
|
|
59
|
+
step={TYPE_SCALE_RANGES.base.step}
|
|
60
|
+
value={[scale.base]}
|
|
61
|
+
onValueChange={(v) => setScale("base", v[0] ?? scale.base)}
|
|
62
|
+
/>
|
|
63
|
+
<p className="text-xs text-muted-foreground max-w-prose">
|
|
64
|
+
The size of body text. Other steps scale from this. 18px is the
|
|
65
|
+
current default — comfortable on mobile, generous for low-vision.
|
|
66
|
+
</p>
|
|
67
|
+
</div>
|
|
68
|
+
|
|
69
|
+
<div className="space-y-3">
|
|
70
|
+
<div className="flex items-baseline justify-between gap-3">
|
|
71
|
+
<label className="text-sm font-semibold">Scale Ratio</label>
|
|
72
|
+
<span className="text-xs text-muted-foreground font-mono tabular-nums">
|
|
73
|
+
{scale.ratio.toFixed(3)}
|
|
74
|
+
</span>
|
|
75
|
+
</div>
|
|
76
|
+
<Slider
|
|
77
|
+
min={TYPE_SCALE_RANGES.ratio.min}
|
|
78
|
+
max={TYPE_SCALE_RANGES.ratio.max}
|
|
79
|
+
step={TYPE_SCALE_RANGES.ratio.step}
|
|
80
|
+
value={[scale.ratio]}
|
|
81
|
+
onValueChange={(v) => setScale("ratio", v[0] ?? scale.ratio)}
|
|
82
|
+
/>
|
|
83
|
+
<div className="flex flex-wrap gap-1.5 pt-1">
|
|
84
|
+
{RATIO_PRESETS.map((preset) => {
|
|
85
|
+
const active = Math.abs(scale.ratio - preset.value) < 0.003;
|
|
86
|
+
return (
|
|
87
|
+
<button
|
|
88
|
+
key={preset.label}
|
|
89
|
+
type="button"
|
|
90
|
+
onClick={() => setScale("ratio", preset.value)}
|
|
91
|
+
className={`text-xs font-medium px-2 py-1 rounded-md border transition-colors ${
|
|
92
|
+
active
|
|
93
|
+
? "border-primary text-primary"
|
|
94
|
+
: "border-border text-muted-foreground hover:border-foreground/40"
|
|
95
|
+
}`}
|
|
96
|
+
>
|
|
97
|
+
{preset.label}
|
|
98
|
+
</button>
|
|
99
|
+
);
|
|
100
|
+
})}
|
|
101
|
+
</div>
|
|
102
|
+
<p className="text-xs text-muted-foreground max-w-prose">
|
|
103
|
+
How much each step grows. Smaller ratios feel calmer and editorial;
|
|
104
|
+
larger ratios feel more dramatic.
|
|
105
|
+
</p>
|
|
106
|
+
</div>
|
|
107
|
+
</div>
|
|
108
|
+
|
|
109
|
+
<div className="rounded-lg border bg-card p-6 space-y-4">
|
|
110
|
+
{PREVIEW_ROWS.map((row) => (
|
|
111
|
+
<div
|
|
112
|
+
key={row.token}
|
|
113
|
+
className="flex items-baseline gap-6 border-b last:border-b-0 pb-3 last:pb-0"
|
|
114
|
+
>
|
|
115
|
+
<div className="w-32 shrink-0 flex items-baseline gap-2">
|
|
116
|
+
<code className="text-xs text-muted-foreground font-mono">
|
|
117
|
+
{row.token}
|
|
118
|
+
</code>
|
|
119
|
+
<span className="text-xs text-muted-foreground font-mono tabular-nums">
|
|
120
|
+
{sizes[row.token].toFixed(0)}
|
|
121
|
+
</span>
|
|
122
|
+
</div>
|
|
123
|
+
<div
|
|
124
|
+
className="leading-tight"
|
|
125
|
+
style={{ fontSize: `${sizes[row.token]}px` }}
|
|
126
|
+
>
|
|
127
|
+
{row.label}
|
|
128
|
+
</div>
|
|
129
|
+
</div>
|
|
130
|
+
))}
|
|
131
|
+
</div>
|
|
132
|
+
</section>
|
|
133
|
+
);
|
|
134
|
+
}
|
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { Check, Plus, Pencil, Trash2, MoreHorizontal } from "lucide-react";
|
|
5
|
+
import { HexColorPicker } from "react-colorful";
|
|
6
|
+
import { ScrollArea } from "@behavioral-agentic-design-system/core/components/ui/scroll-area";
|
|
7
|
+
import { Button } from "@behavioral-agentic-design-system/core/components/ui/button";
|
|
8
|
+
import { Input } from "@behavioral-agentic-design-system/core/components/ui/input";
|
|
9
|
+
import {
|
|
10
|
+
Popover,
|
|
11
|
+
PopoverContent,
|
|
12
|
+
PopoverTrigger,
|
|
13
|
+
} from "@behavioral-agentic-design-system/core/components/ui/popover";
|
|
14
|
+
import {
|
|
15
|
+
DropdownMenu,
|
|
16
|
+
DropdownMenuContent,
|
|
17
|
+
DropdownMenuItem,
|
|
18
|
+
DropdownMenuTrigger,
|
|
19
|
+
} from "@behavioral-agentic-design-system/core/components/ui/dropdown-menu";
|
|
20
|
+
import {
|
|
21
|
+
useGlobalPrimaryColor,
|
|
22
|
+
type PrimaryColorKey,
|
|
23
|
+
type PrimaryColorOption,
|
|
24
|
+
type WcagGrade,
|
|
25
|
+
} from "@behavioral-agentic-design-system/core/hooks/use-global-primary-color";
|
|
26
|
+
import { ThemeIO } from "@behavioral-agentic-design-system/core/components/customize/theme-io";
|
|
27
|
+
import { DesignControlsPanel } from "@behavioral-agentic-design-system/core/components/customize/design-controls";
|
|
28
|
+
import {
|
|
29
|
+
SansFontPicker,
|
|
30
|
+
SerifFontPicker,
|
|
31
|
+
MonoFontPicker,
|
|
32
|
+
} from "@behavioral-agentic-design-system/core/components/customize/font-pickers";
|
|
33
|
+
import { TypeScalePanel } from "@behavioral-agentic-design-system/core/components/customize/type-scale";
|
|
34
|
+
import { LetterSpacingPanel } from "@behavioral-agentic-design-system/core/components/customize/letter-spacing";
|
|
35
|
+
import { SaveBar } from "@behavioral-agentic-design-system/core/components/customize/save-bar";
|
|
36
|
+
import { nameFromHex } from "@behavioral-agentic-design-system/core/lib/color-name";
|
|
37
|
+
|
|
38
|
+
function ColorSwatch({
|
|
39
|
+
name,
|
|
40
|
+
className,
|
|
41
|
+
variable,
|
|
42
|
+
textClassName,
|
|
43
|
+
}: {
|
|
44
|
+
name: string;
|
|
45
|
+
className: string;
|
|
46
|
+
variable: string;
|
|
47
|
+
textClassName?: string;
|
|
48
|
+
}) {
|
|
49
|
+
return (
|
|
50
|
+
<div>
|
|
51
|
+
<div className={`h-20 rounded-lg border ${className} flex items-end p-2.5`}>
|
|
52
|
+
<span className={`text-xs font-medium truncate ${textClassName ?? ""}`}>{name}</span>
|
|
53
|
+
</div>
|
|
54
|
+
<p className="text-xs text-muted-foreground font-mono mt-1.5 truncate">{variable}</p>
|
|
55
|
+
</div>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function ColorSection({ title, children }: { title: string; children: React.ReactNode }) {
|
|
60
|
+
return (
|
|
61
|
+
<div>
|
|
62
|
+
<h4 className="text-base font-semibold mb-4">{title}</h4>
|
|
63
|
+
<div className="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-3">
|
|
64
|
+
{children}
|
|
65
|
+
</div>
|
|
66
|
+
</div>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function isValidHex(v: string) {
|
|
71
|
+
return /^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(v.trim());
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function AddBrandColorButton({
|
|
75
|
+
onAdd,
|
|
76
|
+
}: {
|
|
77
|
+
onAdd: (hex: string, label?: string) => string | null;
|
|
78
|
+
}) {
|
|
79
|
+
const [open, setOpen] = useState(false);
|
|
80
|
+
const [hex, setHex] = useState("#1F1F1F");
|
|
81
|
+
const [label, setLabel] = useState("");
|
|
82
|
+
const [error, setError] = useState<string | null>(null);
|
|
83
|
+
|
|
84
|
+
const handleAdd = () => {
|
|
85
|
+
const value = hex.trim();
|
|
86
|
+
if (!isValidHex(value)) {
|
|
87
|
+
setError("Enter a valid hex like #1F1F1F");
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const id = onAdd(value, label.trim() || undefined);
|
|
91
|
+
if (!id) {
|
|
92
|
+
setError("Could not add color");
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
setOpen(false);
|
|
96
|
+
setHex("#1F1F1F");
|
|
97
|
+
setLabel("");
|
|
98
|
+
setError(null);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
return (
|
|
102
|
+
<Popover
|
|
103
|
+
open={open}
|
|
104
|
+
onOpenChange={(o) => {
|
|
105
|
+
setOpen(o);
|
|
106
|
+
if (!o) {
|
|
107
|
+
setError(null);
|
|
108
|
+
}
|
|
109
|
+
}}
|
|
110
|
+
>
|
|
111
|
+
<PopoverTrigger asChild>
|
|
112
|
+
<button
|
|
113
|
+
type="button"
|
|
114
|
+
className="group flex flex-col items-center justify-center gap-2 rounded-lg border border-dashed border-border p-3 transition-all hover:border-foreground/40 min-h-[8.5rem]"
|
|
115
|
+
aria-label="Add brand color"
|
|
116
|
+
>
|
|
117
|
+
<div className="flex h-12 w-12 items-center justify-center rounded-full border border-dashed border-border text-muted-foreground group-hover:text-foreground">
|
|
118
|
+
<Plus className="h-5 w-5" strokeWidth={1.5} />
|
|
119
|
+
</div>
|
|
120
|
+
<span className="text-xs font-medium text-muted-foreground group-hover:text-foreground leading-tight">
|
|
121
|
+
Add color
|
|
122
|
+
</span>
|
|
123
|
+
</button>
|
|
124
|
+
</PopoverTrigger>
|
|
125
|
+
<PopoverContent className="w-[260px] p-3" align="start">
|
|
126
|
+
<div className="flex flex-col gap-3">
|
|
127
|
+
<HexColorPicker
|
|
128
|
+
style={{ width: "236px", height: "200px" }}
|
|
129
|
+
color={isValidHex(hex) ? hex : "#1F1F1F"}
|
|
130
|
+
onChange={(c) => {
|
|
131
|
+
setHex(c.toUpperCase());
|
|
132
|
+
if (error) setError(null);
|
|
133
|
+
}}
|
|
134
|
+
/>
|
|
135
|
+
<Input
|
|
136
|
+
value={label}
|
|
137
|
+
onChange={(e) => setLabel(e.target.value)}
|
|
138
|
+
placeholder={`Label — auto: ${isValidHex(hex) ? nameFromHex(hex) : "—"}`}
|
|
139
|
+
className="h-9"
|
|
140
|
+
/>
|
|
141
|
+
<div className="flex items-center gap-2">
|
|
142
|
+
<Input
|
|
143
|
+
value={hex}
|
|
144
|
+
onChange={(e) => {
|
|
145
|
+
setHex(e.target.value);
|
|
146
|
+
if (error) setError(null);
|
|
147
|
+
}}
|
|
148
|
+
onKeyDown={(e) => {
|
|
149
|
+
if (e.key === "Enter") handleAdd();
|
|
150
|
+
}}
|
|
151
|
+
placeholder="#1F1F1F"
|
|
152
|
+
className="h-9 flex-1 min-w-0 font-mono text-sm"
|
|
153
|
+
/>
|
|
154
|
+
<Button size="sm" onClick={handleAdd}>
|
|
155
|
+
Add
|
|
156
|
+
</Button>
|
|
157
|
+
</div>
|
|
158
|
+
{error && <span className="text-xs text-destructive">{error}</span>}
|
|
159
|
+
</div>
|
|
160
|
+
</PopoverContent>
|
|
161
|
+
</Popover>
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function GradePill({ grade, contrast }: { grade: WcagGrade; contrast: number }) {
|
|
166
|
+
// Subtle color coding so failing colors stand out without overwhelming
|
|
167
|
+
// the picker grid. Tooltip surfaces the precise contrast ratio.
|
|
168
|
+
const tone =
|
|
169
|
+
grade === "AAA"
|
|
170
|
+
? "border-emerald-600/40 text-emerald-700 dark:text-emerald-400"
|
|
171
|
+
: grade === "AA"
|
|
172
|
+
? "border-amber-600/40 text-amber-700 dark:text-amber-400"
|
|
173
|
+
: grade === "AA Large"
|
|
174
|
+
? "border-amber-600/40 text-amber-700 dark:text-amber-400"
|
|
175
|
+
: "border-destructive/40 text-destructive";
|
|
176
|
+
return (
|
|
177
|
+
<span
|
|
178
|
+
className={`inline-flex h-5 items-center rounded-full border px-1.5 text-xs font-mono uppercase tracking-wider ${tone}`}
|
|
179
|
+
title={`WCAG ${grade} — ${contrast}:1 contrast vs foreground`}
|
|
180
|
+
>
|
|
181
|
+
{grade}
|
|
182
|
+
</span>
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
type BrandCardActions = {
|
|
187
|
+
/** Inline-rename. Sync (custom) or async via server (built-in). */
|
|
188
|
+
rename?: ((label: string) => void | Promise<{ ok: boolean; error?: string }>) | null;
|
|
189
|
+
/** Delete. Sync (custom) or async via server (built-in). */
|
|
190
|
+
remove?: (() => void | Promise<{ ok: boolean; error?: string }>) | null;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
function BrandColorCard({
|
|
194
|
+
id,
|
|
195
|
+
opt,
|
|
196
|
+
isActive,
|
|
197
|
+
onSelect,
|
|
198
|
+
actions,
|
|
199
|
+
}: {
|
|
200
|
+
id: string;
|
|
201
|
+
opt: PrimaryColorOption;
|
|
202
|
+
isActive: boolean;
|
|
203
|
+
onSelect: () => void;
|
|
204
|
+
actions: BrandCardActions;
|
|
205
|
+
}) {
|
|
206
|
+
const [renaming, setRenaming] = useState(false);
|
|
207
|
+
const [draftLabel, setDraftLabel] = useState(opt.label);
|
|
208
|
+
const [pending, setPending] = useState<null | "remove" | "rename">(null);
|
|
209
|
+
const [error, setError] = useState<string | null>(null);
|
|
210
|
+
const swatch = opt.swatch ?? opt.primary;
|
|
211
|
+
const swatchFg = opt.swatchForeground ?? opt.primaryForeground;
|
|
212
|
+
const hasMenu = Boolean(actions.rename || actions.remove);
|
|
213
|
+
|
|
214
|
+
const commitRename = async () => {
|
|
215
|
+
const next = draftLabel.trim();
|
|
216
|
+
if (!next || next === opt.label || !actions.rename) {
|
|
217
|
+
setDraftLabel(opt.label);
|
|
218
|
+
setRenaming(false);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
setRenaming(false);
|
|
222
|
+
setPending("rename");
|
|
223
|
+
const result = await Promise.resolve(actions.rename(next));
|
|
224
|
+
setPending(null);
|
|
225
|
+
if (result && result.ok === false) {
|
|
226
|
+
setError(result.error ?? "Rename failed");
|
|
227
|
+
setDraftLabel(opt.label);
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
const handleRemove = async () => {
|
|
232
|
+
if (!actions.remove) return;
|
|
233
|
+
setPending("remove");
|
|
234
|
+
const r = await Promise.resolve(actions.remove());
|
|
235
|
+
setPending(null);
|
|
236
|
+
if (r && r.ok === false) setError(r.error ?? "Remove failed");
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
return (
|
|
240
|
+
// `group` lives on the wrapper, not the inner card button — the dropdown
|
|
241
|
+
// trigger is a sibling of the card button, so it needs the group on a
|
|
242
|
+
// shared ancestor for `group-hover:opacity-100` to fire on card hover.
|
|
243
|
+
<div className="group relative">
|
|
244
|
+
<button
|
|
245
|
+
type="button"
|
|
246
|
+
onClick={onSelect}
|
|
247
|
+
aria-pressed={isActive}
|
|
248
|
+
title={opt.note ?? undefined}
|
|
249
|
+
disabled={pending !== null}
|
|
250
|
+
className={`flex w-full flex-col items-center gap-2 rounded-lg border p-3 transition-all min-h-[8.5rem] ${
|
|
251
|
+
isActive
|
|
252
|
+
? "border-primary ring-2 ring-primary/30"
|
|
253
|
+
: "border-border hover:border-foreground/40"
|
|
254
|
+
} ${pending ? "opacity-60" : ""}`}
|
|
255
|
+
>
|
|
256
|
+
<div
|
|
257
|
+
className="relative h-12 w-12 rounded-full border border-border/50"
|
|
258
|
+
style={{ backgroundColor: swatch }}
|
|
259
|
+
>
|
|
260
|
+
{isActive && (
|
|
261
|
+
<Check
|
|
262
|
+
className="absolute inset-0 m-auto h-5 w-5"
|
|
263
|
+
style={{ color: swatchFg }}
|
|
264
|
+
strokeWidth={1.5}
|
|
265
|
+
/>
|
|
266
|
+
)}
|
|
267
|
+
</div>
|
|
268
|
+
{renaming ? (
|
|
269
|
+
<Input
|
|
270
|
+
autoFocus
|
|
271
|
+
value={draftLabel}
|
|
272
|
+
onChange={(e) => setDraftLabel(e.target.value)}
|
|
273
|
+
onClick={(e) => e.stopPropagation()}
|
|
274
|
+
onKeyDown={(e) => {
|
|
275
|
+
if (e.key === "Enter") {
|
|
276
|
+
e.preventDefault();
|
|
277
|
+
commitRename();
|
|
278
|
+
} else if (e.key === "Escape") {
|
|
279
|
+
e.preventDefault();
|
|
280
|
+
setDraftLabel(opt.label);
|
|
281
|
+
setRenaming(false);
|
|
282
|
+
}
|
|
283
|
+
}}
|
|
284
|
+
onBlur={commitRename}
|
|
285
|
+
className="h-7 text-xs text-center"
|
|
286
|
+
/>
|
|
287
|
+
) : (
|
|
288
|
+
<span className="text-xs font-medium text-center leading-tight">{opt.label}</span>
|
|
289
|
+
)}
|
|
290
|
+
<span className="text-xs text-muted-foreground font-mono">{swatch}</span>
|
|
291
|
+
<GradePill grade={opt.grade} contrast={opt.contrast} />
|
|
292
|
+
</button>
|
|
293
|
+
|
|
294
|
+
{hasMenu && !renaming && (
|
|
295
|
+
<DropdownMenu>
|
|
296
|
+
<DropdownMenuTrigger asChild>
|
|
297
|
+
<button
|
|
298
|
+
type="button"
|
|
299
|
+
aria-label={`Edit ${opt.label}`}
|
|
300
|
+
disabled={pending !== null}
|
|
301
|
+
className="absolute top-1.5 right-1.5 inline-flex h-6 w-6 items-center justify-center rounded-md border border-border bg-background text-muted-foreground hover:text-foreground hover:border-foreground/40 opacity-0 group-hover:opacity-100 focus-visible:opacity-100 transition-opacity disabled:opacity-50"
|
|
302
|
+
>
|
|
303
|
+
<MoreHorizontal className="h-3 w-3" strokeWidth={1.5} />
|
|
304
|
+
</button>
|
|
305
|
+
</DropdownMenuTrigger>
|
|
306
|
+
<DropdownMenuContent align="end" className="w-44">
|
|
307
|
+
{actions.rename && (
|
|
308
|
+
<DropdownMenuItem
|
|
309
|
+
onSelect={(e) => {
|
|
310
|
+
e.preventDefault();
|
|
311
|
+
setDraftLabel(opt.label);
|
|
312
|
+
setRenaming(true);
|
|
313
|
+
}}
|
|
314
|
+
>
|
|
315
|
+
<Pencil className="h-3.5 w-3.5 mr-2" strokeWidth={1.5} />
|
|
316
|
+
Rename
|
|
317
|
+
</DropdownMenuItem>
|
|
318
|
+
)}
|
|
319
|
+
{actions.remove && (
|
|
320
|
+
<DropdownMenuItem
|
|
321
|
+
onSelect={handleRemove}
|
|
322
|
+
className="text-destructive focus:text-destructive"
|
|
323
|
+
>
|
|
324
|
+
<Trash2 className="h-3.5 w-3.5 mr-2" strokeWidth={1.5} />
|
|
325
|
+
Delete
|
|
326
|
+
</DropdownMenuItem>
|
|
327
|
+
)}
|
|
328
|
+
</DropdownMenuContent>
|
|
329
|
+
</DropdownMenu>
|
|
330
|
+
)}
|
|
331
|
+
|
|
332
|
+
{error && (
|
|
333
|
+
<p className="absolute -bottom-5 left-0 right-0 text-center text-xs text-destructive">
|
|
334
|
+
{error}
|
|
335
|
+
</p>
|
|
336
|
+
)}
|
|
337
|
+
</div>
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
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
|
+
const {
|
|
346
|
+
color,
|
|
347
|
+
setColor,
|
|
348
|
+
options,
|
|
349
|
+
customs,
|
|
350
|
+
addCustom,
|
|
351
|
+
removeCustom,
|
|
352
|
+
renameCustom,
|
|
353
|
+
removeBuiltin,
|
|
354
|
+
renameBuiltin,
|
|
355
|
+
} = useGlobalPrimaryColor();
|
|
356
|
+
const keys = Object.keys(options) as PrimaryColorKey[];
|
|
357
|
+
return (
|
|
358
|
+
<div>
|
|
359
|
+
<h2 className="text-2xl font-semibold tracking-tight mb-2">Brand Color</h2>
|
|
360
|
+
<p className="text-sm text-muted-foreground mb-6 max-w-prose">
|
|
361
|
+
Switch the primary brand color across every preview screen. Add a one-off with{" "}
|
|
362
|
+
<span className="font-medium text-foreground">+ Add color</span> — it stays in
|
|
363
|
+
your browser only. Hit <span className="font-medium text-foreground">Save to
|
|
364
|
+
tokens.json</span> at the bottom and the active color is promoted to a built-in
|
|
365
|
+
in <code className="font-mono text-xs">brand-colors.json</code> for everyone on
|
|
366
|
+
the repo. Built-ins can be renamed or deleted directly from each card.
|
|
367
|
+
</p>
|
|
368
|
+
<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
|
+
{keys.map((key) => {
|
|
370
|
+
const opt = options[key];
|
|
371
|
+
const isCustom = key in customs;
|
|
372
|
+
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
|
+
const actions: BrandCardActions = isCustom
|
|
377
|
+
? {
|
|
378
|
+
rename: (label) => renameCustom(key, label),
|
|
379
|
+
remove: () => removeCustom(key),
|
|
380
|
+
}
|
|
381
|
+
: isNeutral
|
|
382
|
+
? {}
|
|
383
|
+
: {
|
|
384
|
+
rename: (label) => renameBuiltin(key, label),
|
|
385
|
+
remove: () => removeBuiltin(key),
|
|
386
|
+
};
|
|
387
|
+
return (
|
|
388
|
+
<BrandColorCard
|
|
389
|
+
key={key}
|
|
390
|
+
id={key}
|
|
391
|
+
opt={opt}
|
|
392
|
+
isActive={color === key}
|
|
393
|
+
onSelect={() => setColor(key)}
|
|
394
|
+
actions={actions}
|
|
395
|
+
/>
|
|
396
|
+
);
|
|
397
|
+
})}
|
|
398
|
+
<AddBrandColorButton onAdd={addCustom} />
|
|
399
|
+
</div>
|
|
400
|
+
</div>
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
function ColorPalette() {
|
|
405
|
+
return (
|
|
406
|
+
<div className="p-8 pb-32 max-w-7xl mx-auto space-y-20">
|
|
407
|
+
<ThemeIO />
|
|
408
|
+
<PrimaryColorPicker />
|
|
409
|
+
|
|
410
|
+
<section>
|
|
411
|
+
<h2 className="text-2xl font-semibold tracking-tight mb-2">Typography</h2>
|
|
412
|
+
<p className="text-sm text-muted-foreground mb-8 max-w-prose">
|
|
413
|
+
Sans, serif, and mono fonts each apply system-wide. Choices persist
|
|
414
|
+
and propagate across every preview screen.
|
|
415
|
+
</p>
|
|
416
|
+
<div className="space-y-12">
|
|
417
|
+
<SansFontPicker />
|
|
418
|
+
<SerifFontPicker />
|
|
419
|
+
<MonoFontPicker />
|
|
420
|
+
</div>
|
|
421
|
+
</section>
|
|
422
|
+
|
|
423
|
+
<TypeScalePanel />
|
|
424
|
+
<LetterSpacingPanel />
|
|
425
|
+
<DesignControlsPanel />
|
|
426
|
+
|
|
427
|
+
<section>
|
|
428
|
+
<h2 className="text-2xl font-semibold tracking-tight mb-2">Color Tokens</h2>
|
|
429
|
+
<p className="text-sm text-muted-foreground mb-8 max-w-prose">
|
|
430
|
+
The semantic color variables that power every component. These reflect
|
|
431
|
+
the current theme and update as you adjust the controls above.
|
|
432
|
+
</p>
|
|
433
|
+
<div className="space-y-8">
|
|
434
|
+
<ColorSection title="Primary Theme Colors">
|
|
435
|
+
<ColorSwatch name="Background" className="bg-background text-foreground" variable="--background" />
|
|
436
|
+
<ColorSwatch name="Foreground" className="bg-foreground text-background" variable="--foreground" />
|
|
437
|
+
<ColorSwatch name="Primary" className="bg-primary text-primary-foreground" variable="--primary" />
|
|
438
|
+
<ColorSwatch name="Primary Foreground" className="bg-primary-foreground text-primary" variable="--primary-foreground" />
|
|
439
|
+
</ColorSection>
|
|
440
|
+
|
|
441
|
+
<ColorSection title="Secondary & Accent">
|
|
442
|
+
<ColorSwatch name="Secondary" className="bg-secondary text-secondary-foreground" variable="--secondary" />
|
|
443
|
+
<ColorSwatch name="Secondary Foreground" className="bg-secondary-foreground text-secondary" variable="--secondary-foreground" />
|
|
444
|
+
<ColorSwatch name="Accent" className="bg-accent text-accent-foreground" variable="--accent" />
|
|
445
|
+
<ColorSwatch name="Accent Foreground" className="bg-accent-foreground text-accent" variable="--accent-foreground" />
|
|
446
|
+
</ColorSection>
|
|
447
|
+
|
|
448
|
+
<ColorSection title="UI Surfaces">
|
|
449
|
+
<ColorSwatch name="Card" className="bg-card text-card-foreground" variable="--card" />
|
|
450
|
+
<ColorSwatch name="Card Foreground" className="bg-card-foreground text-card" variable="--card-foreground" />
|
|
451
|
+
<ColorSwatch name="Popover" className="bg-popover text-popover-foreground" variable="--popover" />
|
|
452
|
+
<ColorSwatch name="Popover Foreground" className="bg-popover-foreground text-popover" variable="--popover-foreground" />
|
|
453
|
+
<ColorSwatch name="Muted" className="bg-muted text-muted-foreground" variable="--muted" />
|
|
454
|
+
<ColorSwatch name="Muted Foreground" className="bg-muted-foreground text-muted" variable="--muted-foreground" />
|
|
455
|
+
</ColorSection>
|
|
456
|
+
|
|
457
|
+
<ColorSection title="Utility & Form">
|
|
458
|
+
<ColorSwatch name="Border" className="bg-border" variable="--border" />
|
|
459
|
+
<ColorSwatch name="Input" className="bg-input" variable="--input" />
|
|
460
|
+
<ColorSwatch name="Ring" className="bg-ring text-primary-foreground" variable="--ring" />
|
|
461
|
+
</ColorSection>
|
|
462
|
+
|
|
463
|
+
<ColorSection title="Status & Feedback">
|
|
464
|
+
<ColorSwatch name="Destructive" className="bg-destructive text-destructive-foreground" variable="--destructive" />
|
|
465
|
+
<ColorSwatch name="Destructive Foreground" className="bg-destructive-foreground text-destructive" variable="--destructive-foreground" />
|
|
466
|
+
</ColorSection>
|
|
467
|
+
|
|
468
|
+
<ColorSection title="Charts">
|
|
469
|
+
<ColorSwatch name="Chart 1" className="bg-chart-1" textClassName="text-neutral-900" variable="--chart-1" />
|
|
470
|
+
<ColorSwatch name="Chart 2" className="bg-chart-2" textClassName="text-neutral-900" variable="--chart-2" />
|
|
471
|
+
<ColorSwatch name="Chart 3" className="bg-chart-3" textClassName="text-white" variable="--chart-3" />
|
|
472
|
+
<ColorSwatch name="Chart 4" className="bg-chart-4" textClassName="text-white" variable="--chart-4" />
|
|
473
|
+
<ColorSwatch name="Chart 5" className="bg-chart-5" textClassName="text-white" variable="--chart-5" />
|
|
474
|
+
</ColorSection>
|
|
475
|
+
|
|
476
|
+
<ColorSection title="Sidebar & Navigation">
|
|
477
|
+
<ColorSwatch name="Sidebar Background" className="bg-sidebar text-sidebar-foreground" variable="--sidebar" />
|
|
478
|
+
<ColorSwatch name="Sidebar Foreground" className="bg-sidebar-foreground text-sidebar" variable="--sidebar-foreground" />
|
|
479
|
+
<ColorSwatch name="Sidebar Primary" className="bg-sidebar-primary text-sidebar-primary-foreground" variable="--sidebar-primary" />
|
|
480
|
+
<ColorSwatch name="Sidebar Primary Foreground" className="bg-sidebar-primary-foreground text-sidebar-primary" variable="--sidebar-primary-foreground" />
|
|
481
|
+
<ColorSwatch name="Sidebar Accent" className="bg-sidebar-accent text-sidebar-accent-foreground" variable="--sidebar-accent" />
|
|
482
|
+
<ColorSwatch name="Sidebar Accent Foreground" className="bg-sidebar-accent-foreground text-sidebar-accent" variable="--sidebar-accent-foreground" />
|
|
483
|
+
<ColorSwatch name="Sidebar Border" className="bg-sidebar-border" variable="--sidebar-border" />
|
|
484
|
+
<ColorSwatch name="Sidebar Ring" className="bg-sidebar-ring text-sidebar-primary-foreground" variable="--sidebar-ring" />
|
|
485
|
+
</ColorSection>
|
|
486
|
+
</div>
|
|
487
|
+
</section>
|
|
488
|
+
|
|
489
|
+
<SaveBar />
|
|
490
|
+
</div>
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
export function CustomizeTab() {
|
|
495
|
+
return (
|
|
496
|
+
<ScrollArea className="size-full">
|
|
497
|
+
<div className="motion-safe:animate-in motion-safe:fade-in motion-safe:slide-in-from-bottom-2 motion-safe:duration-500">
|
|
498
|
+
<ColorPalette />
|
|
499
|
+
</div>
|
|
500
|
+
</ScrollArea>
|
|
501
|
+
);
|
|
502
|
+
}
|