@behavioral-agentic-design-system/core 0.19.0 → 0.22.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/src/app/shell.tsx CHANGED
@@ -2,9 +2,10 @@
2
2
 
3
3
  import { useState, useEffect, useRef, useCallback, createContext, useContext, useMemo } from "react";
4
4
  import { Tabs, TabsContent, TabsList, TabsPanels, TabsTrigger } from "@behavioral-agentic-design-system/core/components/ui/tabs";
5
+ import { Sheet, SheetContent, SheetHeader, SheetTitle } from "@behavioral-agentic-design-system/core/components/ui/sheet";
5
6
  import { Badge } from "@behavioral-agentic-design-system/core/components/ui/badge";
6
7
  import { Button } from "@behavioral-agentic-design-system/core/components/ui/button";
7
- import { Sun, Moon, BookOpen, X, ExternalLink } from "lucide-react";
8
+ import { Sun, Moon, BookOpen, X, ExternalLink, Menu } from "lucide-react";
8
9
 
9
10
  /**
10
11
  * Inline GitHub mark. Lucide dropped brand icons (Github / Twitter / etc.) in
@@ -188,13 +189,15 @@ export const DEFAULT_TABS: ShellTab[] = [
188
189
  *
189
190
  * Forks that just want the default shell don't need to import this directly —
190
191
  * they can re-export `@behavioral-agentic-design-system/core/app/page`. Use
191
- * Shell directly when you need custom tabs (e.g. Pool, Meet, Athletes for a
192
- * swim-club brand).
192
+ * Shell directly when you need custom tabs (e.g. Components, Tokens, Changelog
193
+ * for a design-system docs site).
193
194
  */
194
195
  export function Shell({ tabs, defaultTab }: ShellProps) {
195
196
  const initialTab = defaultTab ?? tabs[0]?.value ?? "home";
196
197
  const [activeTab, setActiveTab] = useState(initialTab);
197
198
  const [dark, setDark] = useState(false);
199
+ // Mobile nav: below md the tab strip collapses into a hamburger + Sheet.
200
+ const [mobileNavOpen, setMobileNavOpen] = useState(false);
198
201
  // Fresh-fork onboarding: only render when brand still says "BADS" (the rename
199
202
  // hasn't run yet) AND the user hasn't dismissed the wizard this session.
200
203
  // Renamed forks never see this — they've already gone through onboarding.
@@ -510,7 +513,25 @@ export function Shell({ tabs, defaultTab }: ShellProps) {
510
513
  style={{ "--tabs-fade-duration": "260ms" } as React.CSSProperties}
511
514
  className="flex-1 flex flex-col overflow-hidden"
512
515
  >
513
- <div className="mt-2 mb-1 flex w-full items-center px-4 overflow-x-auto scrollbar-none">
516
+ {/* Mobile (<md): hamburger + active-tab label. The full tab strip is
517
+ hard to use on a phone, so it collapses into a Sheet drawer. */}
518
+ <div className="mt-2 mb-1 flex w-full items-center gap-2 px-4 md:hidden">
519
+ <Button
520
+ variant="ghost"
521
+ size="icon"
522
+ onClick={() => setMobileNavOpen(true)}
523
+ aria-label="Open navigation menu"
524
+ className="size-8 shrink-0 border border-foreground/30"
525
+ >
526
+ <Menu className="h-4 w-4" strokeWidth={1.5} />
527
+ </Button>
528
+ <span className="truncate text-sm font-medium text-foreground">
529
+ {tabs.find((t) => t.value === activeTab)?.label}
530
+ </span>
531
+ </div>
532
+
533
+ {/* Desktop (md+): the horizontal tab strip. */}
534
+ <div className="mt-2 mb-1 hidden w-full items-center px-4 overflow-x-auto scrollbar-none md:flex">
514
535
  <TabsList className="bg-background text-muted-foreground inline-flex w-max shrink-0 items-center justify-center rounded-full px-0">
515
536
  {tabs.map((tab) => (
516
537
  <TabsTrigger
@@ -545,6 +566,38 @@ export function Shell({ tabs, defaultTab }: ShellProps) {
545
566
  </section>
546
567
  </Tabs>
547
568
 
569
+ {/* Mobile navigation drawer — the tab list as a Sheet for small screens.
570
+ Excludes tabs marked hidden:"md" (dense iframe tabs that don't read
571
+ well on mobile), matching the desktop strip's behavior. */}
572
+ <Sheet open={mobileNavOpen} onOpenChange={setMobileNavOpen}>
573
+ <SheetContent side="left" className="w-72">
574
+ <SheetHeader>
575
+ <SheetTitle>{brand.name}</SheetTitle>
576
+ </SheetHeader>
577
+ <nav className="mt-4 flex flex-col gap-1 px-2">
578
+ {tabs
579
+ .filter((tab) => tab.hidden !== "md")
580
+ .map((tab) => (
581
+ <button
582
+ key={tab.value}
583
+ type="button"
584
+ onClick={() => {
585
+ selectTab(tab.value);
586
+ setMobileNavOpen(false);
587
+ }}
588
+ className={`rounded-md px-3 py-2 text-left text-sm font-medium transition-colors ${
589
+ activeTab === tab.value
590
+ ? "bg-primary text-primary-foreground"
591
+ : "text-foreground hover:bg-muted"
592
+ }`}
593
+ >
594
+ {tab.label}
595
+ </button>
596
+ ))}
597
+ </nav>
598
+ </SheetContent>
599
+ </Sheet>
600
+
548
601
  {showOnboarding ? (
549
602
  <div
550
603
  role="dialog"
@@ -1092,7 +1092,7 @@ export function OnboardingWizard({
1092
1092
  label="Industry or category"
1093
1093
  value={draft.industry}
1094
1094
  onChange={(industry) => updateDraft({ industry })}
1095
- placeholder="Healthcare, education, devtools, swim teams..."
1095
+ placeholder="Healthcare, education, devtools, fintech..."
1096
1096
  />
1097
1097
  <TextField
1098
1098
  id="onboarding-audience"
@@ -1,8 +1,10 @@
1
1
  "use client";
2
2
 
3
3
  import * as React from "react";
4
- import { Check } from "lucide-react";
4
+ import { Plus } from "lucide-react";
5
5
  import { cn } from "../../lib/utils";
6
+ import { Popover, PopoverTrigger, PopoverContent } from "./popover";
7
+ import { Button } from "./button";
6
8
 
7
9
  /* -------------------------------------------------------------------------- */
8
10
  /* Helpers */
@@ -22,21 +24,6 @@ function rgbToHex(r: number, g: number, b: number): string {
22
24
  return `#${to(r)}${to(g)}${to(b)}`;
23
25
  }
24
26
 
25
- function luminance(hex: string): number {
26
- const rgb = hexToRgb(hex);
27
- if (!rgb) return 1;
28
- const [r, g, b] = rgb.map((v) => {
29
- const s = v / 255;
30
- return s <= 0.03928 ? s / 12.92 : Math.pow((s + 0.055) / 1.055, 2.4);
31
- });
32
- return 0.2126 * r + 0.7152 * g + 0.0722 * b;
33
- }
34
-
35
- function contrastColor(hex: string): string {
36
- if (!isValidHex(hex)) return "#ffffff";
37
- return luminance(hex) > 0.179 ? "#000000" : "#ffffff";
38
- }
39
-
40
27
  function isValidHex(v: string): boolean {
41
28
  return /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(v);
42
29
  }
@@ -214,7 +201,6 @@ function ColorWheel({
214
201
  commitHsv(h, ns, nv);
215
202
  };
216
203
 
217
- // thumb positions
218
204
  const rad = (h * Math.PI) / 180;
219
205
  const hueX = CENTER + RING_RADIUS * Math.sin(rad);
220
206
  const hueY = CENTER - RING_RADIUS * Math.cos(rad);
@@ -229,7 +215,6 @@ function ColorWheel({
229
215
  className={cn("relative select-none touch-none", disabled && "opacity-50")}
230
216
  style={{ width: WHEEL_SIZE, height: WHEEL_SIZE }}
231
217
  >
232
- {/* Hue ring */}
233
218
  <div
234
219
  ref={ringRef}
235
220
  role="slider"
@@ -251,14 +236,12 @@ function ColorWheel({
251
236
  style={{ background: HUE_CONIC }}
252
237
  />
253
238
 
254
- {/* Center hole masks the conic so only the ring band shows */}
255
239
  <div
256
240
  aria-hidden
257
241
  className="absolute rounded-full bg-background pointer-events-none"
258
242
  style={{ width: HOLE, height: HOLE, left: RING_THICKNESS, top: RING_THICKNESS }}
259
243
  />
260
244
 
261
- {/* Saturation / brightness square */}
262
245
  <div
263
246
  ref={squareRef}
264
247
  role="slider"
@@ -299,7 +282,6 @@ function ColorWheel({
299
282
  />
300
283
  </div>
301
284
 
302
- {/* Hue thumb (rendered last so it sits above the ring) */}
303
285
  <span
304
286
  aria-hidden
305
287
  className={thumb}
@@ -328,15 +310,17 @@ export interface ColorPickerProps {
328
310
  onValueChange?: (value: string) => void;
329
311
  /** Preset swatch colors (hex strings) */
330
312
  swatches?: string[];
331
- /** Show a hex text input for custom colors */
313
+ /** Show a standalone hex text input for custom colors */
332
314
  allowCustom?: boolean;
333
315
  /**
334
- * Show a hue-ring + saturation/brightness color wheel above the swatches.
335
- * The wheel is a pointer/keyboard enhancement; the swatches + hex field
336
- * remain the primary keyboard/screen-reader path. Enabling the wheel always
337
- * surfaces the hex field too, so an exact value can still be typed.
316
+ * Add an "add a custom color" tile (+) after the swatches. Clicking it opens
317
+ * a popover with a hue-ring + saturation/brightness color wheel (and a hex
318
+ * field); confirming appends the picked color to the swatches and selects it.
319
+ * The wheel only appears on demand — the swatch grid stays the default view.
338
320
  */
339
321
  wheel?: boolean;
322
+ /** Fired when a color is added to the swatches via the wheel. */
323
+ onAddSwatch?: (hex: string) => void;
340
324
  disabled?: boolean;
341
325
  /** Accessible label for the radiogroup */
342
326
  "aria-label"?: string;
@@ -350,6 +334,7 @@ export function ColorPicker({
350
334
  swatches = [],
351
335
  allowCustom = false,
352
336
  wheel = false,
337
+ onAddSwatch,
353
338
  disabled = false,
354
339
  "aria-label": ariaLabel = "Color picker",
355
340
  className,
@@ -359,9 +344,21 @@ export function ColorPicker({
359
344
  const value = isControlled ? (valueProp ?? "") : valueState;
360
345
 
361
346
  const [customInput, setCustomInput] = React.useState<string>(() =>
362
- value && (wheel || !swatches.includes(value)) ? value : ""
347
+ value && !swatches.includes(value) ? value : ""
348
+ );
349
+
350
+ // Colors the user has added through the wheel, appended after the presets.
351
+ const [addedSwatches, setAddedSwatches] = React.useState<string[]>([]);
352
+ const allSwatches = React.useMemo(
353
+ () => [...swatches, ...addedSwatches.filter((c) => !swatches.includes(c))],
354
+ [swatches, addedSwatches]
363
355
  );
364
356
 
357
+ // Wheel popover state + its in-progress draft color.
358
+ const [wheelOpen, setWheelOpen] = React.useState(false);
359
+ const [draft, setDraft] = React.useState("#3b82f6");
360
+ const [draftInput, setDraftInput] = React.useState("#3b82f6");
361
+
365
362
  const swatchRefs = React.useRef<(HTMLButtonElement | null)[]>([]);
366
363
 
367
364
  const commit = React.useCallback(
@@ -373,15 +370,6 @@ export function ColorPicker({
373
370
  [disabled, isControlled, onValueChange]
374
371
  );
375
372
 
376
- // Keep the hex field mirrored when the wheel (or a swatch) drives the value.
377
- const commitFromControl = React.useCallback(
378
- (color: string) => {
379
- commit(color);
380
- setCustomInput(color);
381
- },
382
- [commit]
383
- );
384
-
385
373
  const handleKeyDown = React.useCallback(
386
374
  (e: React.KeyboardEvent<HTMLButtonElement>, index: number) => {
387
375
  const btns = swatchRefs.current.filter((b): b is HTMLButtonElement => !!b);
@@ -419,80 +407,163 @@ export function ColorPicker({
419
407
  if (isValidHex(v)) commit(v);
420
408
  };
421
409
 
422
- const selectedSwatchIdx = swatches.indexOf(value);
423
- const showHex = allowCustom || wheel;
410
+ const openWheel = (open: boolean) => {
411
+ if (open) {
412
+ const seed = isValidHex(value) ? value : "#3b82f6";
413
+ setDraft(seed);
414
+ setDraftInput(seed);
415
+ }
416
+ setWheelOpen(open);
417
+ };
418
+
419
+ const setDraftColor = (hex: string) => {
420
+ setDraft(hex);
421
+ setDraftInput(hex);
422
+ };
423
+
424
+ const handleDraftInput = (e: React.ChangeEvent<HTMLInputElement>) => {
425
+ const v = e.target.value;
426
+ setDraftInput(v);
427
+ if (isValidHex(v)) setDraft(v);
428
+ };
429
+
430
+ const addColor = () => {
431
+ if (disabled || !isValidHex(draft)) return;
432
+ if (!allSwatches.includes(draft)) setAddedSwatches((prev) => [...prev, draft]);
433
+ commit(draft);
434
+ if (!swatches.includes(draft)) setCustomInput("");
435
+ onAddSwatch?.(draft);
436
+ setWheelOpen(false);
437
+ };
438
+
439
+ const selectedSwatchIdx = allSwatches.indexOf(value);
424
440
 
425
441
  return (
426
442
  <div className={cn("space-y-3", className)}>
427
- {wheel && (
428
- <ColorWheel value={value} onChange={commitFromControl} disabled={disabled} />
429
- )}
430
-
431
- {swatches.length > 0 && (
432
- <div
433
- role="radiogroup"
434
- aria-label={ariaLabel}
435
- aria-disabled={disabled || undefined}
436
- className="flex flex-wrap gap-1.5"
437
- >
438
- {swatches.map((swatch, i) => {
439
- const isSelected = value === swatch;
440
- const isRovingFocus =
441
- selectedSwatchIdx >= 0 ? isSelected : i === 0;
442
- return (
443
- <button
444
- key={swatch}
445
- ref={(el) => {
446
- swatchRefs.current[i] = el;
447
- }}
448
- type="button"
449
- role="radio"
450
- aria-checked={isSelected}
451
- aria-label={swatch}
452
- tabIndex={isRovingFocus ? 0 : -1}
453
- disabled={disabled}
454
- onClick={() => {
455
- commit(swatch);
456
- setCustomInput("");
457
- }}
458
- onKeyDown={(e) => handleKeyDown(e, i)}
459
- className={cn(
460
- "relative size-7 shrink-0 rounded-md border-2 overflow-hidden",
461
- "focus-visible:outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:ring-offset-1",
462
- "disabled:pointer-events-none disabled:opacity-50",
463
- "transition-[border-color]",
464
- isSelected
465
- ? "border-foreground"
466
- : "border-transparent hover:border-foreground/30"
467
- )}
468
- style={{
469
- backgroundColor: swatch,
470
- transitionDuration: "var(--duration-fast)",
471
- transitionTimingFunction: "var(--ease-out)",
472
- }}
473
- >
474
- {isSelected && (
475
- <Check
476
- className="absolute inset-0 m-auto size-3.5"
477
- style={{ color: contrastColor(swatch) }}
478
- strokeWidth={1.5}
479
- aria-hidden
443
+ {(allSwatches.length > 0 || wheel) && (
444
+ <div className="flex flex-wrap items-center gap-1.5">
445
+ {allSwatches.length > 0 && (
446
+ <div
447
+ role="radiogroup"
448
+ aria-label={ariaLabel}
449
+ aria-disabled={disabled || undefined}
450
+ className="flex flex-wrap gap-1.5"
451
+ >
452
+ {allSwatches.map((swatch, i) => {
453
+ const isSelected = value === swatch;
454
+ const isRovingFocus = selectedSwatchIdx >= 0 ? isSelected : i === 0;
455
+ return (
456
+ <button
457
+ key={swatch}
458
+ ref={(el) => {
459
+ swatchRefs.current[i] = el;
460
+ }}
461
+ type="button"
462
+ role="radio"
463
+ aria-checked={isSelected}
464
+ aria-label={swatch}
465
+ tabIndex={isRovingFocus ? 0 : -1}
466
+ disabled={disabled}
467
+ onClick={() => {
468
+ commit(swatch);
469
+ setCustomInput("");
470
+ }}
471
+ onKeyDown={(e) => handleKeyDown(e, i)}
472
+ className={cn(
473
+ "size-7 shrink-0 rounded-md outline-none transition-[box-shadow]",
474
+ "focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:ring-offset-2 focus-visible:ring-offset-background",
475
+ "disabled:pointer-events-none disabled:opacity-50",
476
+ // Selected: an offset ring (radio-style), NOT a border on the color, so it
477
+ // reads as "selected" on any swatch instead of a harsh frame. Box-shadow
478
+ // rings are dropped in Windows High Contrast, so a forced-colors outline
479
+ // carries the selected state there (maps to a system color).
480
+ isSelected
481
+ ? "ring-2 ring-offset-2 ring-offset-background ring-foreground forced-colors:outline forced-colors:outline-2 forced-colors:outline-offset-2"
482
+ : "hover:ring-2 hover:ring-offset-2 hover:ring-offset-background hover:ring-foreground/25"
483
+ )}
484
+ style={{
485
+ backgroundColor: swatch,
486
+ transitionDuration: "var(--duration-fast)",
487
+ transitionTimingFunction: "var(--ease-out)",
488
+ }}
489
+ />
490
+ );
491
+ })}
492
+ </div>
493
+ )}
494
+
495
+ {wheel && (
496
+ <Popover open={wheelOpen} onOpenChange={openWheel}>
497
+ <PopoverTrigger asChild>
498
+ <button
499
+ type="button"
500
+ aria-label="Add a custom color"
501
+ disabled={disabled}
502
+ className={cn(
503
+ "flex size-7 shrink-0 items-center justify-center rounded-md",
504
+ "border-2 border-dashed border-input text-muted-foreground",
505
+ "hover:border-foreground/40 hover:text-foreground",
506
+ "focus-visible:outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:ring-offset-1",
507
+ "disabled:pointer-events-none disabled:opacity-50",
508
+ "transition-[border-color,color]"
509
+ )}
510
+ style={{
511
+ transitionDuration: "var(--duration-fast)",
512
+ transitionTimingFunction: "var(--ease-out)",
513
+ }}
514
+ >
515
+ <Plus className="size-4" strokeWidth={1.5} aria-hidden />
516
+ </button>
517
+ </PopoverTrigger>
518
+ <PopoverContent align="start" className="w-auto space-y-3">
519
+ <ColorWheel value={draft} onChange={setDraftColor} disabled={disabled} />
520
+ <div className="flex items-center gap-2">
521
+ <div
522
+ role="presentation"
523
+ className="size-8 shrink-0 rounded-md border border-input"
524
+ style={{ backgroundColor: isValidHex(draft) ? draft : "transparent" }}
480
525
  />
481
- )}
482
- </button>
483
- );
484
- })}
526
+ <input
527
+ type="text"
528
+ value={draftInput}
529
+ onChange={handleDraftInput}
530
+ disabled={disabled}
531
+ placeholder="#000000"
532
+ aria-label="Hex color"
533
+ spellCheck={false}
534
+ maxLength={7}
535
+ className={cn(
536
+ "h-9 w-full rounded-md border border-input bg-background px-2 py-1",
537
+ "font-mono text-sm text-foreground placeholder:text-muted-foreground",
538
+ "focus-visible:outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50",
539
+ "disabled:pointer-events-none disabled:opacity-50",
540
+ "transition-[border-color,box-shadow]"
541
+ )}
542
+ style={{
543
+ transitionDuration: "var(--duration-fast)",
544
+ transitionTimingFunction: "var(--ease-out)",
545
+ }}
546
+ />
547
+ </div>
548
+ <Button
549
+ type="button"
550
+ onClick={addColor}
551
+ disabled={disabled || !isValidHex(draft)}
552
+ className="w-full"
553
+ >
554
+ Add color
555
+ </Button>
556
+ </PopoverContent>
557
+ </Popover>
558
+ )}
485
559
  </div>
486
560
  )}
487
561
 
488
- {showHex && (
562
+ {allowCustom && (
489
563
  <div className="flex items-center gap-2">
490
564
  <div
491
565
  role="presentation"
492
- className={cn(
493
- "size-7 shrink-0 rounded-md border border-input",
494
- "transition-colors"
495
- )}
566
+ className={cn("size-7 shrink-0 rounded-md border border-input", "transition-colors")}
496
567
  style={{
497
568
  backgroundColor: value || "transparent",
498
569
  transitionDuration: "var(--duration-fast)",