@behavioral-agentic-design-system/core 0.2.1 → 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 +32 -4
- 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,120 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
import { ExternalLink, X, Sparkles } from "lucide-react";
|
|
5
|
+
import { Button } from "@behavioral-agentic-design-system/core/components/ui/button";
|
|
6
|
+
|
|
7
|
+
type CheckResult =
|
|
8
|
+
| { ok: true; upstream?: true; skip?: string }
|
|
9
|
+
| { ok: true; upToDate: true; local: string; remote: string }
|
|
10
|
+
| {
|
|
11
|
+
ok: true;
|
|
12
|
+
upToDate: false;
|
|
13
|
+
local: string;
|
|
14
|
+
remote: string;
|
|
15
|
+
behind: number | null;
|
|
16
|
+
remoteMessage: string | null;
|
|
17
|
+
remoteDate: string | null;
|
|
18
|
+
compareUrl: string;
|
|
19
|
+
releasesUrl: string;
|
|
20
|
+
}
|
|
21
|
+
| { ok: true; error: string };
|
|
22
|
+
|
|
23
|
+
const DISMISS_KEY = "BADS.updateDismissedFor";
|
|
24
|
+
|
|
25
|
+
export function BadsUpdateBanner() {
|
|
26
|
+
const [data, setData] = useState<CheckResult | null>(null);
|
|
27
|
+
const [dismissedFor, setDismissedFor] = useState<string | null>(null);
|
|
28
|
+
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
try {
|
|
31
|
+
setDismissedFor(window.localStorage.getItem(DISMISS_KEY));
|
|
32
|
+
} catch {}
|
|
33
|
+
fetch("/api/bads-update-check")
|
|
34
|
+
.then((r) => r.json())
|
|
35
|
+
.then((d) => setData(d))
|
|
36
|
+
.catch(() => setData({ ok: true, error: "fetch-failed" }));
|
|
37
|
+
}, []);
|
|
38
|
+
|
|
39
|
+
if (!data || !data.ok) return null;
|
|
40
|
+
if ("upstream" in data || "error" in data) return null;
|
|
41
|
+
if ("upToDate" in data && data.upToDate) return null;
|
|
42
|
+
|
|
43
|
+
// From here we know it's the "behind" shape.
|
|
44
|
+
const behindData = data as Extract<
|
|
45
|
+
CheckResult,
|
|
46
|
+
{ ok: true; upToDate: false }
|
|
47
|
+
>;
|
|
48
|
+
|
|
49
|
+
// Don't re-show after the user dismissed for this exact remote sha. New
|
|
50
|
+
// upstream commit → banner returns.
|
|
51
|
+
if (dismissedFor === behindData.remote) return null;
|
|
52
|
+
|
|
53
|
+
const handleDismiss = () => {
|
|
54
|
+
try {
|
|
55
|
+
window.localStorage.setItem(DISMISS_KEY, behindData.remote);
|
|
56
|
+
} catch {}
|
|
57
|
+
setDismissedFor(behindData.remote);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const behindLabel =
|
|
61
|
+
typeof behindData.behind === "number"
|
|
62
|
+
? `${behindData.behind} commit${behindData.behind === 1 ? "" : "s"} behind`
|
|
63
|
+
: "behind upstream";
|
|
64
|
+
|
|
65
|
+
const dateLabel = behindData.remoteDate
|
|
66
|
+
? new Date(behindData.remoteDate).toLocaleDateString("en-US", {
|
|
67
|
+
month: "short",
|
|
68
|
+
day: "numeric",
|
|
69
|
+
year: "numeric",
|
|
70
|
+
})
|
|
71
|
+
: null;
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<div className="rounded-lg border border-primary/30 bg-primary/5 p-4 flex items-start gap-3">
|
|
75
|
+
<Sparkles className="h-4 w-4 text-primary shrink-0 mt-0.5" strokeWidth={1.5} />
|
|
76
|
+
<div className="flex-1 min-w-0 space-y-1">
|
|
77
|
+
<p className="text-sm font-medium text-foreground">
|
|
78
|
+
BADS update available — {behindLabel}
|
|
79
|
+
</p>
|
|
80
|
+
<p className="text-xs text-muted-foreground">
|
|
81
|
+
{behindData.remoteMessage
|
|
82
|
+
? `Latest on upstream: "${behindData.remoteMessage}"`
|
|
83
|
+
: "Upstream BADS has new commits since this fork's last sync."}
|
|
84
|
+
{dateLabel && <> · {dateLabel}</>}
|
|
85
|
+
</p>
|
|
86
|
+
<div className="flex items-center gap-2 pt-1">
|
|
87
|
+
<Button size="sm" variant="default" className="gap-1.5" asChild>
|
|
88
|
+
<a href={behindData.releasesUrl} target="_blank" rel="noopener noreferrer">
|
|
89
|
+
See releases
|
|
90
|
+
<ExternalLink className="h-3.5 w-3.5" strokeWidth={1.5} />
|
|
91
|
+
</a>
|
|
92
|
+
</Button>
|
|
93
|
+
<Button size="sm" variant="outline" className="gap-1.5" asChild>
|
|
94
|
+
<a href={behindData.compareUrl} target="_blank" rel="noopener noreferrer">
|
|
95
|
+
View diff
|
|
96
|
+
<ExternalLink className="h-3.5 w-3.5" strokeWidth={1.5} />
|
|
97
|
+
</a>
|
|
98
|
+
</Button>
|
|
99
|
+
<code className="ml-2 font-mono text-xs text-muted-foreground">
|
|
100
|
+
<span className="text-foreground">{behindData.local.slice(0, 7)}</span>
|
|
101
|
+
{" → "}
|
|
102
|
+
<span className="text-primary">{behindData.remote.slice(0, 7)}</span>
|
|
103
|
+
</code>
|
|
104
|
+
</div>
|
|
105
|
+
<p className="text-xs text-muted-foreground pt-1">
|
|
106
|
+
Run <code className="font-mono">pnpm bads:sync</code> in this fork to pull
|
|
107
|
+
updates selectively.
|
|
108
|
+
</p>
|
|
109
|
+
</div>
|
|
110
|
+
<button
|
|
111
|
+
type="button"
|
|
112
|
+
onClick={handleDismiss}
|
|
113
|
+
aria-label="Dismiss this update notice"
|
|
114
|
+
className="shrink-0 text-muted-foreground hover:text-foreground"
|
|
115
|
+
>
|
|
116
|
+
<X className="h-4 w-4" strokeWidth={1.5} />
|
|
117
|
+
</button>
|
|
118
|
+
</div>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
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
|
+
DESIGN_CONTROL_DEFAULTS,
|
|
7
|
+
DESIGN_CONTROL_RANGES,
|
|
8
|
+
useGlobalDesignControls,
|
|
9
|
+
} from "@behavioral-agentic-design-system/core/hooks/use-global-design-controls";
|
|
10
|
+
import { RotateCcw } from "lucide-react";
|
|
11
|
+
|
|
12
|
+
function ControlRow({
|
|
13
|
+
label,
|
|
14
|
+
description,
|
|
15
|
+
value,
|
|
16
|
+
range,
|
|
17
|
+
onChange,
|
|
18
|
+
preview,
|
|
19
|
+
}: {
|
|
20
|
+
label: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
value: number;
|
|
23
|
+
range: { min: number; max: number; step: number; unit: string };
|
|
24
|
+
onChange: (next: number) => void;
|
|
25
|
+
preview?: React.ReactNode;
|
|
26
|
+
}) {
|
|
27
|
+
return (
|
|
28
|
+
<div className="space-y-3">
|
|
29
|
+
<div className="flex items-baseline justify-between gap-3">
|
|
30
|
+
<label className="text-sm font-semibold">{label}</label>
|
|
31
|
+
<span className="text-xs text-muted-foreground font-mono tabular-nums">
|
|
32
|
+
{value.toFixed(value < 1 ? 3 : 2)}
|
|
33
|
+
{range.unit}
|
|
34
|
+
</span>
|
|
35
|
+
</div>
|
|
36
|
+
<Slider
|
|
37
|
+
min={range.min}
|
|
38
|
+
max={range.max}
|
|
39
|
+
step={range.step}
|
|
40
|
+
value={[value]}
|
|
41
|
+
onValueChange={(v) => onChange(v[0] ?? value)}
|
|
42
|
+
/>
|
|
43
|
+
{description && (
|
|
44
|
+
<p className="text-xs text-muted-foreground max-w-prose">{description}</p>
|
|
45
|
+
)}
|
|
46
|
+
{preview && <div className="pt-1">{preview}</div>}
|
|
47
|
+
</div>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function RadiusPreview({ value }: { value: number }) {
|
|
52
|
+
const sizes = [
|
|
53
|
+
{ label: "sm", radius: Math.max(0, value - 0.25) },
|
|
54
|
+
{ label: "md", radius: Math.max(0, value - 0.125) },
|
|
55
|
+
{ label: "lg", radius: value },
|
|
56
|
+
{ label: "xl", radius: value + 0.25 },
|
|
57
|
+
];
|
|
58
|
+
return (
|
|
59
|
+
<div className="flex items-center gap-6">
|
|
60
|
+
{sizes.map((s) => (
|
|
61
|
+
<div key={s.label} className="flex flex-col items-center gap-1.5">
|
|
62
|
+
<div
|
|
63
|
+
className="h-10 w-10 bg-foreground"
|
|
64
|
+
style={{ borderRadius: `${s.radius}rem` }}
|
|
65
|
+
/>
|
|
66
|
+
<span className="text-xs text-muted-foreground font-mono">{s.label}</span>
|
|
67
|
+
</div>
|
|
68
|
+
))}
|
|
69
|
+
</div>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function SpacingPreview({ value }: { value: number }) {
|
|
74
|
+
const sizes = [2, 4, 6, 8];
|
|
75
|
+
return (
|
|
76
|
+
<div className="flex items-center gap-3">
|
|
77
|
+
{sizes.map((mult) => (
|
|
78
|
+
<div key={mult} className="flex flex-col items-center gap-1.5">
|
|
79
|
+
<div
|
|
80
|
+
className="bg-foreground"
|
|
81
|
+
style={{
|
|
82
|
+
width: `calc(${value}rem * ${mult})`,
|
|
83
|
+
height: "10px",
|
|
84
|
+
}}
|
|
85
|
+
/>
|
|
86
|
+
<span className="text-xs text-muted-foreground font-mono">×{mult}</span>
|
|
87
|
+
</div>
|
|
88
|
+
))}
|
|
89
|
+
</div>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function ShadowPreview() {
|
|
94
|
+
const sizes = ["sm", "md", "lg", "xl"] as const;
|
|
95
|
+
return (
|
|
96
|
+
<div className="flex items-center gap-6">
|
|
97
|
+
{sizes.map((s) => (
|
|
98
|
+
<div key={s} className="flex flex-col items-center gap-1.5">
|
|
99
|
+
<div
|
|
100
|
+
className={`h-10 w-10 rounded-md bg-card shadow-${s}`}
|
|
101
|
+
/>
|
|
102
|
+
<span className="text-xs text-muted-foreground font-mono">{s}</span>
|
|
103
|
+
</div>
|
|
104
|
+
))}
|
|
105
|
+
</div>
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function DesignControlsPanel() {
|
|
110
|
+
const { controls, setControl, reset } = useGlobalDesignControls();
|
|
111
|
+
|
|
112
|
+
const isCustom =
|
|
113
|
+
controls.radius !== DESIGN_CONTROL_DEFAULTS.radius ||
|
|
114
|
+
controls.spacing !== DESIGN_CONTROL_DEFAULTS.spacing ||
|
|
115
|
+
controls.shadowOpacity !== DESIGN_CONTROL_DEFAULTS.shadowOpacity;
|
|
116
|
+
|
|
117
|
+
return (
|
|
118
|
+
<div>
|
|
119
|
+
<div className="flex items-baseline justify-between gap-3 mb-2">
|
|
120
|
+
<h2 className="text-2xl font-semibold tracking-tight">
|
|
121
|
+
Design Controls
|
|
122
|
+
</h2>
|
|
123
|
+
{isCustom && (
|
|
124
|
+
<Button variant="ghost" size="sm" onClick={reset} className="gap-2">
|
|
125
|
+
<RotateCcw className="h-4 w-4" />
|
|
126
|
+
Reset
|
|
127
|
+
</Button>
|
|
128
|
+
)}
|
|
129
|
+
</div>
|
|
130
|
+
<p className="text-sm text-muted-foreground mb-8 max-w-prose">
|
|
131
|
+
Adjust the foundational scales. Changes apply in real time across every
|
|
132
|
+
preview screen and persist on refresh.
|
|
133
|
+
</p>
|
|
134
|
+
|
|
135
|
+
<div className="grid grid-cols-1 lg:grid-cols-2 gap-x-10 gap-y-8">
|
|
136
|
+
<ControlRow
|
|
137
|
+
label="Border Radius"
|
|
138
|
+
description="Drives every rounded corner. sm/md/lg/xl scale from this base."
|
|
139
|
+
value={controls.radius}
|
|
140
|
+
range={DESIGN_CONTROL_RANGES.radius}
|
|
141
|
+
onChange={(v) => setControl("radius", v)}
|
|
142
|
+
preview={<RadiusPreview value={controls.radius} />}
|
|
143
|
+
/>
|
|
144
|
+
|
|
145
|
+
<ControlRow
|
|
146
|
+
label="Spacing Scale"
|
|
147
|
+
description="Tailwind base spacing unit. Smaller compacts the system; larger opens it up."
|
|
148
|
+
value={controls.spacing}
|
|
149
|
+
range={DESIGN_CONTROL_RANGES.spacing}
|
|
150
|
+
onChange={(v) => setControl("spacing", v)}
|
|
151
|
+
preview={<SpacingPreview value={controls.spacing} />}
|
|
152
|
+
/>
|
|
153
|
+
|
|
154
|
+
<ControlRow
|
|
155
|
+
label="Shadow Opacity"
|
|
156
|
+
description="Applies to every shadow utility. Lower for soft surfaces, higher for emphatic ones."
|
|
157
|
+
value={controls.shadowOpacity}
|
|
158
|
+
range={DESIGN_CONTROL_RANGES.shadowOpacity}
|
|
159
|
+
onChange={(v) => setControl("shadowOpacity", v)}
|
|
160
|
+
preview={<ShadowPreview />}
|
|
161
|
+
/>
|
|
162
|
+
</div>
|
|
163
|
+
</div>
|
|
164
|
+
);
|
|
165
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
SANS_FONT_OPTIONS,
|
|
5
|
+
useGlobalSansFont,
|
|
6
|
+
type SansFontKey,
|
|
7
|
+
} from "@behavioral-agentic-design-system/core/hooks/use-global-sans-font";
|
|
8
|
+
import {
|
|
9
|
+
SERIF_FONT_OPTIONS,
|
|
10
|
+
useGlobalSerifFont,
|
|
11
|
+
type SerifFontKey,
|
|
12
|
+
} from "@behavioral-agentic-design-system/core/hooks/use-global-serif-font";
|
|
13
|
+
import {
|
|
14
|
+
MONO_FONT_OPTIONS,
|
|
15
|
+
useGlobalMonoFont,
|
|
16
|
+
type MonoFontKey,
|
|
17
|
+
} from "@behavioral-agentic-design-system/core/hooks/use-global-mono-font";
|
|
18
|
+
|
|
19
|
+
type FontOption = { label: string; stack: string };
|
|
20
|
+
|
|
21
|
+
function FontCardGrid<K extends string>({
|
|
22
|
+
options,
|
|
23
|
+
active,
|
|
24
|
+
onSelect,
|
|
25
|
+
sample = "Aa",
|
|
26
|
+
}: {
|
|
27
|
+
options: Record<K, FontOption>;
|
|
28
|
+
active: K;
|
|
29
|
+
onSelect: (key: K) => void;
|
|
30
|
+
sample?: string;
|
|
31
|
+
}) {
|
|
32
|
+
const keys = Object.keys(options) as K[];
|
|
33
|
+
return (
|
|
34
|
+
<div className="grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-3">
|
|
35
|
+
{keys.map((key) => {
|
|
36
|
+
const opt = options[key];
|
|
37
|
+
const isActive = key === active;
|
|
38
|
+
return (
|
|
39
|
+
<button
|
|
40
|
+
key={key}
|
|
41
|
+
type="button"
|
|
42
|
+
onClick={() => onSelect(key)}
|
|
43
|
+
aria-pressed={isActive}
|
|
44
|
+
className={`group flex flex-col items-start gap-3 rounded-lg border p-4 text-left transition-all ${
|
|
45
|
+
isActive
|
|
46
|
+
? "border-primary ring-2 ring-primary/30"
|
|
47
|
+
: "border-border hover:border-foreground/40"
|
|
48
|
+
}`}
|
|
49
|
+
>
|
|
50
|
+
<span
|
|
51
|
+
className="text-4xl leading-none"
|
|
52
|
+
style={{ fontFamily: opt.stack }}
|
|
53
|
+
>
|
|
54
|
+
{sample}
|
|
55
|
+
</span>
|
|
56
|
+
<span className="text-sm font-medium leading-tight">
|
|
57
|
+
{opt.label}
|
|
58
|
+
</span>
|
|
59
|
+
</button>
|
|
60
|
+
);
|
|
61
|
+
})}
|
|
62
|
+
</div>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function SansFontPicker() {
|
|
67
|
+
const { font, setFont } = useGlobalSansFont();
|
|
68
|
+
return (
|
|
69
|
+
<div>
|
|
70
|
+
<h4 className="text-base font-semibold mb-2">Sans</h4>
|
|
71
|
+
<p className="text-sm text-muted-foreground mb-5 max-w-prose">
|
|
72
|
+
The primary sans font. Applies via <code>--font-sans</code>.
|
|
73
|
+
</p>
|
|
74
|
+
<FontCardGrid<SansFontKey>
|
|
75
|
+
options={SANS_FONT_OPTIONS}
|
|
76
|
+
active={font}
|
|
77
|
+
onSelect={setFont}
|
|
78
|
+
/>
|
|
79
|
+
</div>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function SerifFontPicker() {
|
|
84
|
+
const { font, setFont } = useGlobalSerifFont();
|
|
85
|
+
return (
|
|
86
|
+
<div>
|
|
87
|
+
<h4 className="text-base font-semibold mb-2">Serif</h4>
|
|
88
|
+
<p className="text-sm text-muted-foreground mb-5 max-w-prose">
|
|
89
|
+
Used by headlines and editorial surfaces. Applies via{" "}
|
|
90
|
+
<code>--font-serif</code>.
|
|
91
|
+
</p>
|
|
92
|
+
<FontCardGrid<SerifFontKey>
|
|
93
|
+
options={SERIF_FONT_OPTIONS}
|
|
94
|
+
active={font}
|
|
95
|
+
onSelect={setFont}
|
|
96
|
+
/>
|
|
97
|
+
</div>
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function MonoFontPicker() {
|
|
102
|
+
const { font, setFont } = useGlobalMonoFont();
|
|
103
|
+
return (
|
|
104
|
+
<div>
|
|
105
|
+
<h4 className="text-base font-semibold mb-2">Mono</h4>
|
|
106
|
+
<p className="text-sm text-muted-foreground mb-5 max-w-prose">
|
|
107
|
+
Used by code, technical content, and tabular data. Applies via{" "}
|
|
108
|
+
<code>--font-mono</code>.
|
|
109
|
+
</p>
|
|
110
|
+
<FontCardGrid<MonoFontKey>
|
|
111
|
+
options={MONO_FONT_OPTIONS}
|
|
112
|
+
active={font}
|
|
113
|
+
onSelect={setFont}
|
|
114
|
+
sample="</>"
|
|
115
|
+
/>
|
|
116
|
+
</div>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
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
|
+
DESIGN_CONTROL_DEFAULTS,
|
|
7
|
+
DESIGN_CONTROL_RANGES,
|
|
8
|
+
useGlobalDesignControls,
|
|
9
|
+
} from "@behavioral-agentic-design-system/core/hooks/use-global-design-controls";
|
|
10
|
+
import { RotateCcw } from "lucide-react";
|
|
11
|
+
|
|
12
|
+
const PRESETS = [
|
|
13
|
+
{ value: -0.025, label: "Tight" },
|
|
14
|
+
{ value: 0, label: "Normal" },
|
|
15
|
+
{ value: 0.025, label: "Loose" },
|
|
16
|
+
{ value: 0.05, label: "Wide" },
|
|
17
|
+
] as const;
|
|
18
|
+
|
|
19
|
+
export function LetterSpacingPanel() {
|
|
20
|
+
const { controls, setControl } = useGlobalDesignControls();
|
|
21
|
+
const value = controls.letterSpacing;
|
|
22
|
+
const isCustom = value !== DESIGN_CONTROL_DEFAULTS.letterSpacing;
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<section>
|
|
26
|
+
<div className="flex items-baseline justify-between gap-3 mb-2">
|
|
27
|
+
<h2 className="text-2xl font-semibold tracking-tight">Letter Spacing</h2>
|
|
28
|
+
{isCustom && (
|
|
29
|
+
<Button
|
|
30
|
+
variant="ghost"
|
|
31
|
+
size="sm"
|
|
32
|
+
// Reset only this control — useGlobalDesignControls.reset() would
|
|
33
|
+
// wipe radius / spacing / shadow too, which is not the user's intent
|
|
34
|
+
// when they hit Reset on the letter-spacing panel.
|
|
35
|
+
onClick={() => setControl("letterSpacing", DESIGN_CONTROL_DEFAULTS.letterSpacing)}
|
|
36
|
+
className="gap-2"
|
|
37
|
+
>
|
|
38
|
+
<RotateCcw className="h-4 w-4" />
|
|
39
|
+
Reset
|
|
40
|
+
</Button>
|
|
41
|
+
)}
|
|
42
|
+
</div>
|
|
43
|
+
<p className="text-sm text-muted-foreground mb-8 max-w-prose">
|
|
44
|
+
Global tracking offset. Folds into every Tailwind <code>tracking-*</code>{" "}
|
|
45
|
+
utility via <code>--tracking-offset</code>, so headlines, body, and
|
|
46
|
+
labels all retrack live as you slide.
|
|
47
|
+
</p>
|
|
48
|
+
|
|
49
|
+
<div className="grid grid-cols-1 lg:grid-cols-2 gap-x-10 gap-y-8 mb-10">
|
|
50
|
+
<div className="space-y-3">
|
|
51
|
+
<div className="flex items-baseline justify-between gap-3">
|
|
52
|
+
<label className="text-sm font-semibold">Tracking</label>
|
|
53
|
+
<span className="text-xs text-muted-foreground font-mono tabular-nums">
|
|
54
|
+
{value > 0 ? "+" : ""}
|
|
55
|
+
{value.toFixed(3)}em
|
|
56
|
+
</span>
|
|
57
|
+
</div>
|
|
58
|
+
<Slider
|
|
59
|
+
min={DESIGN_CONTROL_RANGES.letterSpacing.min}
|
|
60
|
+
max={DESIGN_CONTROL_RANGES.letterSpacing.max}
|
|
61
|
+
step={DESIGN_CONTROL_RANGES.letterSpacing.step}
|
|
62
|
+
value={[value]}
|
|
63
|
+
onValueChange={(v) => setControl("letterSpacing", v[0] ?? value)}
|
|
64
|
+
/>
|
|
65
|
+
<div className="flex flex-wrap gap-1.5 pt-1">
|
|
66
|
+
{PRESETS.map((preset) => {
|
|
67
|
+
const active = Math.abs(value - preset.value) < 0.003;
|
|
68
|
+
return (
|
|
69
|
+
<button
|
|
70
|
+
key={preset.label}
|
|
71
|
+
type="button"
|
|
72
|
+
onClick={() => setControl("letterSpacing", preset.value)}
|
|
73
|
+
className={`text-xs font-medium px-2 py-1 rounded-md border transition-colors ${
|
|
74
|
+
active
|
|
75
|
+
? "border-primary text-primary"
|
|
76
|
+
: "border-border text-muted-foreground hover:border-foreground/40"
|
|
77
|
+
}`}
|
|
78
|
+
>
|
|
79
|
+
{preset.label}
|
|
80
|
+
</button>
|
|
81
|
+
);
|
|
82
|
+
})}
|
|
83
|
+
</div>
|
|
84
|
+
<p className="text-xs text-muted-foreground max-w-prose">
|
|
85
|
+
Negative tightens, positive opens. Tracking <code>tracking-*</code>{" "}
|
|
86
|
+
utilities still win on individual elements when set deliberately.
|
|
87
|
+
</p>
|
|
88
|
+
</div>
|
|
89
|
+
|
|
90
|
+
<div className="rounded-lg border bg-card p-6 space-y-3">
|
|
91
|
+
<p className="text-3xl font-semibold leading-tight">
|
|
92
|
+
The quick brown fox
|
|
93
|
+
</p>
|
|
94
|
+
<p className="text-base text-muted-foreground">
|
|
95
|
+
Body copy reflects the tracking value you set here. Headlines, body,
|
|
96
|
+
and labels inherit unless overridden.
|
|
97
|
+
</p>
|
|
98
|
+
<p className="text-xs text-muted-foreground font-mono">
|
|
99
|
+
0123456789 — sample numerals
|
|
100
|
+
</p>
|
|
101
|
+
</div>
|
|
102
|
+
</div>
|
|
103
|
+
</section>
|
|
104
|
+
);
|
|
105
|
+
}
|