@behavioral-agentic-design-system/core 0.2.1 → 0.3.1

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.
Files changed (49) hide show
  1. package/package.json +37 -4
  2. package/scripts/bads-sync.mjs +81 -0
  3. package/scripts/build-tokens.cjs +487 -0
  4. package/src/api/bads-update-check.ts +151 -0
  5. package/src/api/brand-colors.ts +180 -0
  6. package/src/api/layers/file.ts +71 -0
  7. package/src/api/layers.ts +49 -0
  8. package/src/api/save-tokens.ts +280 -0
  9. package/src/app/font-ready.tsx +51 -0
  10. package/src/app/layout.tsx +152 -0
  11. package/src/app/page.tsx +267 -0
  12. package/src/app/preview/cards/page.tsx +8 -0
  13. package/src/app/preview/components/page.tsx +232 -0
  14. package/src/app/preview/dark-mode-client.tsx +24 -0
  15. package/src/app/preview/dashboard/page.tsx +4 -0
  16. package/src/app/preview/global-font-client.tsx +36 -0
  17. package/src/app/preview/layout.tsx +13 -0
  18. package/src/app/preview/mail/page.tsx +4 -0
  19. package/src/app/preview/pricing/page.tsx +4 -0
  20. package/src/app/preview/typography/page.tsx +11 -0
  21. package/src/app/providers.tsx +49 -0
  22. package/src/components/Foundations/Colors.stories.tsx +85 -0
  23. package/src/components/Foundations/Motion.stories.tsx +169 -0
  24. package/src/components/Foundations/Radius.stories.tsx +36 -0
  25. package/src/components/Foundations/Shadows.stories.tsx +30 -0
  26. package/src/components/Foundations/Spacing.stories.tsx +35 -0
  27. package/src/components/Foundations/Typography.stories.tsx +68 -0
  28. package/src/components/bads-update-banner.tsx +120 -0
  29. package/src/components/customize/design-controls.tsx +165 -0
  30. package/src/components/customize/font-pickers.tsx +118 -0
  31. package/src/components/customize/letter-spacing.tsx +105 -0
  32. package/src/components/customize/save-bar.tsx +379 -0
  33. package/src/components/customize/theme-io.tsx +245 -0
  34. package/src/components/customize/type-scale.tsx +134 -0
  35. package/src/components/customize-tab.tsx +502 -0
  36. package/src/components/home-tab.tsx +1227 -0
  37. package/src/components/layers-tab.tsx +225 -0
  38. package/src/components/ui/alert.tsx +5 -1
  39. package/src/hooks/use-global-design-controls.ts +117 -0
  40. package/src/hooks/use-global-mono-font.ts +73 -0
  41. package/src/hooks/use-global-primary-color.ts +544 -0
  42. package/src/hooks/use-global-sans-font.ts +98 -0
  43. package/src/hooks/use-global-serif-font.ts +77 -0
  44. package/src/hooks/use-global-theme.ts +259 -0
  45. package/src/hooks/use-global-type-scale.ts +141 -0
  46. package/src/hooks/use-sync-type-scale.ts +51 -0
  47. package/src/hooks/use-token-overrides.ts +98 -0
  48. package/src/styles.css +40 -6
  49. package/src/tokens.json +86 -5
@@ -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
+ }