@behavioral-agentic-design-system/core 0.21.0 → 0.23.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.
@@ -84,41 +84,50 @@ function ColorSwatch({
84
84
  const currentHex = overrides[variable]?.toUpperCase();
85
85
  const entries = Object.entries(options);
86
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);
87
+ // wheelHex drives the HexColorPicker (always a valid 6-char hex).
88
+ // inputValue leads the hex input and may be incomplete while the user types.
89
+ const [wheelHex, setWheelHex] = useState(currentHex ?? "#808080");
90
+ const [inputValue, setInputValue] = useState(currentHex ?? "");
91
+
92
+ // True when the current wheelHex already exists in the brand palette.
93
+ const inPalette = useMemo(
94
+ () =>
95
+ entries.some(([, opt]) => {
96
+ const swatch = (opt.swatch ?? opt.primary ?? "").toUpperCase();
97
+ return swatch !== "" && swatch === wheelHex;
98
+ }),
99
+ [entries, wheelHex],
100
+ );
101
+
102
+ // Apply a validated hex to the token and sync both local states.
103
+ const applyHex = (hex: string) => {
104
+ const upper = hex.toUpperCase();
105
+ setWheelHex(upper);
106
+ setInputValue(upper);
107
+ setToken(variable, upper);
103
108
  };
104
109
 
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();
110
+ const handleReset = () => {
111
+ resetToken(variable);
112
+ // Chart vars are written inline by use-global-primary-color; clearing the
113
+ // override here won't restore the brand-derived ramp without this call.
114
+ if (variable.startsWith("--chart-")) reapplyChartRamp();
115
+ setWheelHex("#808080");
116
+ setInputValue("");
118
117
  };
119
118
 
120
119
  return (
121
- <Popover>
120
+ <Popover
121
+ onOpenChange={(open) => {
122
+ if (open) {
123
+ // Sync to the current override each time the popover opens so the
124
+ // wheel reflects the live token value rather than stale local state.
125
+ const cur = overrides[variable]?.toUpperCase();
126
+ setWheelHex(cur ?? "#808080");
127
+ setInputValue(cur ?? "");
128
+ }
129
+ }}
130
+ >
122
131
  <PopoverTrigger asChild>
123
132
  <button
124
133
  type="button"
@@ -138,129 +147,91 @@ function ColorSwatch({
138
147
  <PopoverContent align="start" className="w-72 p-3">
139
148
  <div className="flex items-center justify-between gap-2 mb-3">
140
149
  <p className="text-xs font-mono text-muted-foreground truncate">{variable}</p>
141
- {!showAdd && isOverridden && (
150
+ {isOverridden && (
142
151
  <button
143
152
  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
- }}
153
+ onClick={handleReset}
154
154
  className="inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors"
155
155
  >
156
156
  <RotateCcw className="h-3 w-3" strokeWidth={1.5} />
157
157
  Reset
158
158
  </button>
159
159
  )}
160
- {showAdd && (
161
- // allow-text-xs-cta — sub-flow Back link, paired with the
162
- // text-xs labels around it in the color-add panel header.
163
- // Reads as a breadcrumb/cancel, not a flow CTA.
164
- <button
160
+ </div>
161
+
162
+ {/* Color wheel — always visible; no sub-flow required */}
163
+ <HexColorPicker
164
+ style={{ width: "100%", height: "180px" }}
165
+ color={isValidHex(wheelHex) ? wheelHex : "#808080"}
166
+ onChange={(c) => applyHex(c)}
167
+ />
168
+
169
+ {/* Hex input synced with the wheel + save-to-palette when not already there */}
170
+ <div className="flex items-center gap-2 mt-2">
171
+ <Input
172
+ value={inputValue}
173
+ onChange={(e) => {
174
+ setInputValue(e.target.value);
175
+ if (isValidHex(e.target.value.trim())) {
176
+ applyHex(e.target.value.trim());
177
+ }
178
+ }}
179
+ placeholder="#1F1F1F"
180
+ className="h-9 flex-1 min-w-0 font-mono text-sm"
181
+ />
182
+ {!inPalette && isValidHex(wheelHex) && (
183
+ <Button
165
184
  type="button"
166
- onClick={resetAddState}
167
- className="text-xs text-muted-foreground hover:text-foreground transition-colors"
185
+ size="icon"
186
+ variant="outline"
187
+ className="h-9 w-9 shrink-0"
188
+ onClick={() => addCustomSilent(wheelHex)}
189
+ title="Save to brand palette"
168
190
  >
169
- Back
170
- </button>
191
+ <Plus className="h-4 w-4" strokeWidth={1.5} />
192
+ </Button>
171
193
  )}
172
194
  </div>
173
195
 
174
- {showAdd ? (
175
- <div className="flex flex-col gap-3">
176
- <HexColorPicker
177
- style={{ width: "100%", height: "180px" }}
178
- color={isValidHex(newHex) ? newHex : "#1F1F1F"}
179
- onChange={(c) => {
180
- setNewHex(c.toUpperCase());
181
- if (addError) setAddError(null);
182
- }}
183
- />
184
- <Input
185
- value={newLabel}
186
- onChange={(e) => setNewLabel(e.target.value)}
187
- placeholder={`Label — auto: ${isValidHex(newHex) ? nameFromHex(newHex) : "—"}`}
188
- className="h-9"
189
- />
190
- <div className="flex items-center gap-2">
191
- <Input
192
- value={newHex}
193
- onChange={(e) => {
194
- setNewHex(e.target.value);
195
- if (addError) setAddError(null);
196
- }}
197
- onKeyDown={(e) => {
198
- if (e.key === "Enter") handleAddAndApply();
199
- }}
200
- placeholder="#1F1F1F"
201
- className="h-9 flex-1 min-w-0 font-mono text-sm"
202
- />
203
- <Button size="sm" onClick={handleAddAndApply}>
204
- Add
205
- </Button>
206
- </div>
207
- {addError && <span className="text-xs text-destructive">{addError}</span>}
208
- <p className="text-xs text-muted-foreground">
209
- Saved to your brand colors and applied here.
210
- </p>
211
- </div>
212
- ) : (
213
- <div className="grid grid-cols-4 gap-2">
214
- {entries.map(([key, opt]) => {
215
- const swatch = opt.swatch ?? opt.primary;
216
- const isActive =
217
- currentHex !== undefined &&
218
- currentHex === (swatch ?? "").toUpperCase();
219
- return (
220
- <button
221
- key={key}
222
- type="button"
223
- onClick={() => setToken(variable, swatch)}
224
- title={`${opt.label} · ${swatch}`}
225
- className={`group/sw flex flex-col items-center gap-1.5 rounded-md border p-2 transition-all ${
226
- isActive
227
- ? "border-primary ring-2 ring-primary/30"
228
- : "border-border hover:border-primary/40"
229
- }`}
196
+ {/* Brand color presets — clicking applies the color and syncs the wheel */}
197
+ <div className="grid grid-cols-4 gap-2 mt-3">
198
+ {entries.map(([key, opt]) => {
199
+ const swatch = opt.swatch ?? opt.primary;
200
+ const isActive =
201
+ swatch != null && swatch.toUpperCase() === wheelHex;
202
+ return (
203
+ <button
204
+ key={key}
205
+ type="button"
206
+ onClick={() => { if (swatch) applyHex(swatch); }}
207
+ aria-label={`${opt.label} — ${swatch}${isActive ? ", selected" : ""}`}
208
+ aria-pressed={isActive}
209
+ className={`group/sw flex flex-col items-center gap-1.5 rounded-md border p-2 transition-all ${
210
+ isActive
211
+ ? "border-primary ring-2 ring-primary/30"
212
+ : "border-border hover:border-primary/40"
213
+ }`}
214
+ >
215
+ <div
216
+ className="relative h-7 w-7 rounded-full border border-border/50"
217
+ style={{ backgroundColor: swatch }}
230
218
  >
231
- <div
232
- className="relative h-7 w-7 rounded-full border border-border/50"
233
- style={{ backgroundColor: swatch }}
234
- >
235
- {isActive && (
236
- <Check
237
- className="absolute inset-0 m-auto h-3.5 w-3.5"
238
- style={{ color: opt.swatchForeground ?? opt.primaryForeground }}
239
- strokeWidth={1.5}
240
- />
241
- )}
242
- </div>
243
- <span className="text-xs leading-tight truncate w-full text-center">
244
- {opt.label}
245
- </span>
246
- </button>
247
- );
248
- })}
249
- <button
250
- type="button"
251
- onClick={() => setShowAdd(true)}
252
- title="Add a new brand color and apply it here"
253
- className="group/sw flex flex-col items-center gap-1.5 rounded-md border border-dashed border-border p-2 transition-all hover:border-primary/40"
254
- >
255
- <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">
256
- <Plus className="h-3.5 w-3.5" strokeWidth={1.5} />
257
- </div>
258
- <span className="text-xs leading-tight text-muted-foreground group-hover/sw:text-foreground truncate w-full text-center">
259
- Add
260
- </span>
261
- </button>
262
- </div>
263
- )}
219
+ {isActive && (
220
+ <Check
221
+ aria-hidden="true"
222
+ className="absolute inset-0 m-auto h-3.5 w-3.5"
223
+ style={{ color: opt.swatchForeground ?? opt.primaryForeground }}
224
+ strokeWidth={1.5}
225
+ />
226
+ )}
227
+ </div>
228
+ <span className="text-xs leading-tight truncate w-full text-center">
229
+ {opt.label}
230
+ </span>
231
+ </button>
232
+ );
233
+ })}
234
+ </div>
264
235
  </PopoverContent>
265
236
  </Popover>
266
237
  );
@@ -518,6 +489,7 @@ function BrandColorCard({
518
489
  >
519
490
  {isActive && (
520
491
  <Check
492
+ aria-hidden="true"
521
493
  className="absolute inset-0 m-auto h-5 w-5"
522
494
  style={{ color: swatchFg }}
523
495
  strokeWidth={1.5}
@@ -250,7 +250,7 @@ function MetricPill({
250
250
  <span className="font-mono text-2xl font-semibold tracking-tight tabular-nums">
251
251
  {value}
252
252
  </span>
253
- <span className="text-xs uppercase tracking-wide text-muted-foreground">
253
+ <span className="text-xs uppercase tracking-wide text-foreground">
254
254
  {label}
255
255
  </span>
256
256
  </div>
@@ -315,7 +315,7 @@ export function HomeTab({ onBrowseDocs, onBrowseComponents }: HomeTabProps) {
315
315
  <Separator />
316
316
 
317
317
  <section className="flex flex-col gap-4">
318
- <h2 className="text-sm font-semibold uppercase tracking-wide text-muted-foreground">
318
+ <h2 className="text-sm font-semibold uppercase tracking-wide text-foreground">
319
319
  What ships today
320
320
  </h2>
321
321
  <div className="grid grid-cols-2 gap-3 sm:grid-cols-4">
@@ -341,18 +341,11 @@ export function HomeTab({ onBrowseDocs, onBrowseComponents }: HomeTabProps) {
341
341
  {STARTER_CARDS.map((card) => {
342
342
  const Icon = card.icon;
343
343
  return (
344
- <Card
344
+ <button
345
345
  key={card.id}
346
- role="button"
347
- tabIndex={0}
348
- onClick={() => openDocAt(card.path)}
349
- onKeyDown={(e) => {
350
- if (e.key === "Enter" || e.key === " ") {
351
- e.preventDefault();
352
- openDocAt(card.path);
353
- }
354
- }}
355
- className="group cursor-pointer transition-colors hover:border-primary/40 hover:bg-accent/30 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
346
+ type="button"
347
+ onClick={() => openDocAt(card.path)} // lint-disable: card-bypass — whole card is a click target, so it must be a <button> for keyboard activation, not a <Card> div
348
+ className="flex flex-col gap-4 rounded-lg border bg-card text-card-foreground shadow-sm group cursor-pointer text-left w-full transition-colors hover:border-primary/40 hover:bg-accent/30 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
356
349
  style={{
357
350
  transitionDuration: "var(--duration-fast)",
358
351
  transitionTimingFunction: "var(--ease-out)",
@@ -383,7 +376,7 @@ export function HomeTab({ onBrowseDocs, onBrowseComponents }: HomeTabProps) {
383
376
  />
384
377
  </div>
385
378
  </CardContent>
386
- </Card>
379
+ </button>
387
380
  );
388
381
  })}
389
382
  </div>
@@ -163,6 +163,11 @@ export function LayersTab() {
163
163
  setStatus("idle");
164
164
  setStatusMessage("");
165
165
 
166
+ // Markdown files default to the rendered preview so they're never blank.
167
+ if (isMarkdown(activePath)) {
168
+ setViewMode("preview");
169
+ }
170
+
166
171
  // Synthetic semantic-tokens view: read tokens.json (the only non-layer
167
172
  // path the file route allows) and pull the theme.light / theme.dark
168
173
  // maps into a name → {light, dark} table. Always read-only.
@@ -963,7 +963,7 @@ export function OnboardingWizard({
963
963
  void analyzeUrl();
964
964
  }
965
965
  }}
966
- placeholder="https://example.com"
966
+ placeholder="https://design.bads.com"
967
967
  className="h-14 pl-11 text-lg"
968
968
  />
969
969
  </div>