@behavioral-agentic-design-system/core 0.8.0 → 0.8.3

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.
@@ -5,24 +5,36 @@ import { cn } from "../../lib/utils"
5
5
 
6
6
  const alertVariants = cva(
7
7
  // Icon is explicitly pinned to row 1 / col 1 so it sits alongside the title,
8
- // not auto-placed somewhere ambiguous. mt-1 nudges its top down ~4px so the
9
- // icon's vertical center aligns with the title's cap height (text-lg
10
- // leading-tight ≈ 22px line-box; cap height ≈ 14px from top).
11
- "relative grid w-full grid-cols-[0_1fr] items-start gap-y-1 rounded-lg border px-6 py-5 text-sm has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] has-[>svg]:gap-x-3 [&>svg]:size-4 [&>svg]:row-start-1 [&>svg]:col-start-1 [&>svg]:mt-1 [&>svg]:text-current",
8
+ // not auto-placed somewhere ambiguous. size-5 (20px) balances the text-lg
9
+ // title; mt-0.5 nudges its top down ~2px so the icon's vertical center aligns
10
+ // with the title's cap height (text-lg leading-tight ≈ 22px line-box).
11
+ "relative grid w-full grid-cols-[0_1fr] items-start gap-y-1.5 rounded-lg border px-6 py-5 text-sm has-[>svg]:grid-cols-[calc(var(--spacing)*5)_1fr] has-[>svg]:gap-x-3.5 [&>svg]:size-5 [&>svg]:row-start-1 [&>svg]:col-start-1 [&>svg]:mt-0.5 [&>svg]:text-current",
12
12
  {
13
13
  variants: {
14
14
  variant: {
15
- // bg-muted gives default alerts a subtle surface bump so they read as
16
- // a callout even when nested inside a Card (which is also bg-card).
17
- // Without this, default alert + card = identical surfaces, no hierarchy.
18
- default: "border-l-4 border-l-primary bg-primary/5 text-foreground [&>svg]:text-primary dark:bg-primary/10",
19
- // bg-destructive/10 gives destructive alerts a soft red tint without
20
- // overwhelming the surface. Composite contrast (destructive on
21
- // destructive/10 over card) stays above AA 4.5:1 across the default
22
- // BADS palette; forks with very saturated destructive tokens should
23
- // re-check with `pnpm wcag:audit` after token edits.
15
+ // Subtle primary tint (bg-primary/5) gives default alerts a surface
16
+ // bump so they read as a callout even nested in a Card, plus a 4px
17
+ // primary left-accent bar + primary icon — the same colored-icon +
18
+ // left-accent language the Sonner toasts use, so alerts and
19
+ // notifications match.
20
+ //
21
+ // NOTE: the accent + border colors use arbitrary `border-[var(--token)]`
22
+ // with `!`, NOT the named `border-primary` / `border-destructive`
23
+ // utilities. In this Tailwind v4 setup the named border-color utilities
24
+ // don't generate a rule (the class lands on the element but no CSS is
25
+ // emitted), so the color silently fell through to the `:root *`
26
+ // `border-border` base reset (the bug that made these accents render
27
+ // grey). Arbitrary values always generate; `!` wins over `:root *`.
28
+ default: "border-border border-l-4 border-l-[var(--primary)]! bg-primary/5 text-foreground [&>svg]:text-primary dark:bg-primary/10",
29
+ // Full red border (all four sides) so the error reads as an error at a
30
+ // glance, with the 4px left bar as the accent. bg-destructive/5 tint
31
+ // stays subtle; composite text contrast (destructive on destructive/5
32
+ // over card) stays above AA 4.5:1 on the default palette. The border is
33
+ // the destructive token, audited non-text AAA (`destructive accent on
34
+ // page`, 7.4:1 light / 8.2:1 dark). Forks with very saturated
35
+ // destructive tokens should re-check with `pnpm wcag:audit`.
24
36
  destructive:
25
- "border-l-4 border-l-destructive bg-destructive/5 text-destructive *:data-[slot=alert-description]:text-destructive/90 [&>svg]:text-current dark:bg-destructive/10",
37
+ "border-[var(--destructive)]! border-l-4 bg-destructive/5 text-destructive *:data-[slot=alert-description]:text-destructive/90 [&>svg]:text-current dark:bg-destructive/10",
26
38
  },
27
39
  },
28
40
  defaultVariants: {
@@ -5,7 +5,7 @@ import { Slot } from "@radix-ui/react-slot"
5
5
  import { cn } from "../../lib/utils"
6
6
 
7
7
  const buttonVariants = cva(
8
- "inline-flex shrink-0 items-center justify-center gap-2 rounded-full text-sm font-medium whitespace-nowrap transition-all outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
8
+ "inline-flex shrink-0 items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap transition-all outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
9
9
  {
10
10
  variants: {
11
11
  variant: {
@@ -23,13 +23,13 @@ const buttonVariants = cva(
23
23
  },
24
24
  size: {
25
25
  default: "h-9 px-4 py-2",
26
- xs: "h-6 gap-1 rounded-md px-2 text-xs [&_svg:not([class*='size-'])]:size-3",
27
- sm: "h-8 gap-1.5 rounded-md px-3",
28
- lg: "h-10 rounded-md px-8",
29
- xl: "h-11 rounded-md px-10 text-base [&_svg:not([class*='size-'])]:size-5",
30
- "2xl": "h-12 rounded-md px-12 text-base font-semibold [&_svg:not([class*='size-'])]:size-5",
26
+ xs: "h-6 gap-1 px-2 text-xs [&_svg:not([class*='size-'])]:size-3",
27
+ sm: "h-8 gap-1.5 px-3",
28
+ lg: "h-10 px-8",
29
+ xl: "h-11 px-10 text-base [&_svg:not([class*='size-'])]:size-5",
30
+ "2xl": "h-12 px-12 text-base font-semibold [&_svg:not([class*='size-'])]:size-5",
31
31
  icon: "size-9",
32
- "icon-xs": "size-6 rounded-md [&_svg:not([class*='size-'])]:size-3",
32
+ "icon-xs": "size-6 [&_svg:not([class*='size-'])]:size-3",
33
33
  "icon-sm": "size-8",
34
34
  "icon-lg": "size-10",
35
35
  "icon-xl": "size-11 [&_svg:not([class*='size-'])]:size-5",
@@ -23,7 +23,19 @@ function ScrollArea({
23
23
  // scrollable-region-focusable). The focus-visible ring below already
24
24
  // anticipates this — Radix's Viewport just isn't focusable on its own.
25
25
  tabIndex={0}
26
- className="size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1"
26
+ // Radix's Viewport wraps `children` in a div it inline-styles as
27
+ // `display:table; min-width:100%`. `display:table` shrink-wraps to the
28
+ // widest unbreakable descendant (a long <pre> line, a whitespace-nowrap
29
+ // badge), so on a narrow viewport that wrapper balloons past the
30
+ // viewport width and the ScrollArea scrolls horizontally instead of the
31
+ // inner element's own `overflow-x-auto` kicking in — content gets
32
+ // clipped on mobile. Forcing the wrapper back to a normal block (still
33
+ // min-w-full for the vertical scrollbar math) makes it honor the
34
+ // viewport width so children wrap/scroll within their own box. This is
35
+ // the canonical fix for ScrollArea horizontal-overflow on mobile and is
36
+ // safe because no BADS surface relies on ScrollArea's own horizontal
37
+ // scroll (horizontal cases use a dedicated overflow-x-auto wrapper).
38
+ className="size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1 [&>div]:!block [&>div]:!min-w-0 [&>div]:w-full"
27
39
  >
28
40
  {children}
29
41
  </ScrollAreaPrimitive.Viewport>
@@ -84,7 +84,7 @@ function SheetContent({
84
84
  {showCloseButton && (
85
85
  <SheetPrimitive.Close
86
86
  data-slot="sheet-close"
87
- className="absolute top-4 right-4 rounded-xs text-foreground ring-offset-background transition-opacity hover:opacity-70 focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-8"
87
+ className="absolute top-3 right-3 inline-flex size-9 items-center justify-center rounded-md text-foreground ring-offset-background transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4"
88
88
  style={{ strokeWidth: '1.5px' }}
89
89
  >
90
90
  <XIcon />
@@ -100,7 +100,9 @@ function SheetHeader({ className, ...props }: React.ComponentProps<"div">) {
100
100
  return (
101
101
  <div
102
102
  data-slot="sheet-header"
103
- className={cn("flex flex-col gap-1.5 p-4", className)}
103
+ // pr-12 reserves space for the absolutely-positioned close button (top-3
104
+ // right-3, size-9) so the title/description can never run underneath it.
105
+ className={cn("flex flex-col gap-1.5 p-4 pr-12", className)}
104
106
  {...props}
105
107
  />
106
108
  )
@@ -18,11 +18,11 @@ const Toaster = ({ ...props }: ToasterProps) => {
18
18
  theme={theme as ToasterProps["theme"]}
19
19
  className="toaster group"
20
20
  icons={{
21
- success: <CircleCheckIcon className="size-4" />,
22
- info: <InfoIcon className="size-4" />,
23
- warning: <TriangleAlertIcon className="size-4" />,
24
- error: <OctagonXIcon className="size-4" />,
25
- loading: <Loader2Icon className="size-4 animate-spin" />,
21
+ success: <CircleCheckIcon className="size-[50px] text-[var(--success)]" strokeWidth={1.5} />,
22
+ info: <InfoIcon className="size-[50px] text-[var(--info)]" strokeWidth={1.5} />,
23
+ warning: <TriangleAlertIcon className="size-[50px] text-[var(--warning)]" strokeWidth={1.5} />,
24
+ error: <OctagonXIcon className="size-[50px] text-[var(--destructive)]" strokeWidth={1.5} />,
25
+ loading: <Loader2Icon className="size-[50px] animate-spin" strokeWidth={1.5} />,
26
26
  }}
27
27
  style={
28
28
  {
@@ -38,16 +38,43 @@ const Toaster = ({ ...props }: ToasterProps) => {
38
38
  // regardless of where --border lands on the fork's palette. Sonner's
39
39
  // default leans on --border, which can be invisible on tonal forks.
40
40
  toast:
41
- "group toast group-[.toaster]:bg-popover group-[.toaster]:text-popover-foreground group-[.toaster]:border group-[.toaster]:border-foreground/10 group-[.toaster]:shadow-lg",
41
+ "group toast group-[.toaster]:bg-popover group-[.toaster]:text-popover-foreground group-[.toaster]:border group-[.toaster]:border-foreground/10 group-[.toaster]:shadow-lg group-[.toaster]:items-start!",
42
+ // 50px status icon, top-aligned to the text. Sonner centers the icon
43
+ // row by default (align-items: center) and gives [data-icon] its own
44
+ // alignment + margin — `!` + self-start pins the icon to the top edge
45
+ // of the title instead of centering it against the full text block.
46
+ icon: "size-[50px]! shrink-0 self-start! mt-0.5 mr-3",
42
47
  title: "text-base font-semibold",
43
- // Sonner sets description opacity low by default — override with an
44
- // explicit muted-foreground token so it reads at every brightness.
48
+ // Sonner hard-codes the description color via a high-specificity
49
+ // selector (`[data-sonner-toast] [data-description]`, 0,3,0) that
50
+ // out-ranks a plain `text-muted-foreground` utility — so BADS' token
51
+ // silently lost and the description rendered at Sonner's fixed grey
52
+ // rather than ours (faint / off-brand depending on CSS load order).
53
+ // The `!` important modifier makes the AAA muted-foreground token win
54
+ // deterministically in both light and dark, putting the design system
55
+ // back in control of the description contrast.
45
56
  description:
46
- "text-sm text-muted-foreground leading-relaxed group-[.toast]:text-muted-foreground",
57
+ "text-sm! text-muted-foreground! leading-relaxed",
47
58
  actionButton:
48
59
  "group-[.toast]:bg-primary group-[.toast]:text-primary-foreground",
49
60
  cancelButton:
50
61
  "group-[.toast]:bg-muted group-[.toast]:text-muted-foreground",
62
+ // Per-variant status color: a 4px left accent bar in the status
63
+ // token. The icon (set in `icons` above) carries the same color.
64
+ // Surface + text stay neutral (popover / popover-foreground) so body
65
+ // copy keeps its AAA contrast — only the non-text accent + icon are
66
+ // colored. Tokens are tuned ≥3:1 on popover in both themes
67
+ // (see wcag:audit "<status> accent on popover").
68
+ //
69
+ // `!` important: Sonner draws the toast border via a high-specificity
70
+ // `[data-sonner-toast]` rule that out-ranks a plain border utility
71
+ // (same reason the description color above needs `!`). Important makes
72
+ // the left edge win deterministically; the other three sides keep
73
+ // Sonner's neutral 1px border.
74
+ success: "border-l-4! border-l-[var(--success)]!",
75
+ warning: "border-l-4! border-l-[var(--warning)]!",
76
+ info: "border-l-4! border-l-[var(--info)]!",
77
+ error: "border-l-4! border-l-[var(--destructive)]!",
51
78
  },
52
79
  }}
53
80
  {...props}
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Brand-mark tone classifier (client-safe — no @xmldom).
3
+ *
4
+ * Decides whether a brand mark would be hard to see against the current
5
+ * surface, so the renderer can auto-invert it in the offending theme. The
6
+ * goal: a black logo stays black in light mode but flips to white in dark
7
+ * mode (and vice-versa) without the designer hand-editing the SVG per theme.
8
+ *
9
+ * Rules:
10
+ * - A mark that uses `currentColor` is **adaptive** — the monotone path in
11
+ * svg-sanitize already rewrote it, so it follows the text color on its own.
12
+ * Never filter those (inverting would fight the currentColor adaptation).
13
+ * - A mark whose every resolvable color is dark is **dark** → invert it in
14
+ * dark mode. Every color light → **light** → invert it in light mode.
15
+ * - Anything with a mix of light and dark fixed colors is **mixed** → left
16
+ * exactly as authored, because inverting a multi-color logo wrecks the brand
17
+ * colors. Same for marks whose colors we can't resolve (oklch/hsl/exotic
18
+ * named) — we don't guess.
19
+ */
20
+
21
+ export type MarkTone = "adaptive" | "dark" | "light" | "mixed";
22
+
23
+ // Minimal named-color table — the ones that actually show up in logos. Unknown
24
+ // names resolve to null (unclassifiable) rather than a wrong guess.
25
+ const NAMED_HEX: Record<string, string> = {
26
+ black: "#000000",
27
+ white: "#ffffff",
28
+ gray: "#808080",
29
+ grey: "#808080",
30
+ silver: "#c0c0c0",
31
+ red: "#ff0000",
32
+ green: "#008000",
33
+ lime: "#00ff00",
34
+ blue: "#0000ff",
35
+ navy: "#000080",
36
+ yellow: "#ffff00",
37
+ orange: "#ffa500",
38
+ purple: "#800080",
39
+ teal: "#008080",
40
+ maroon: "#800000",
41
+ olive: "#808000",
42
+ };
43
+
44
+ function srgbToLinear(channel: number): number {
45
+ const s = channel / 255;
46
+ return s <= 0.03928 ? s / 12.92 : Math.pow((s + 0.055) / 1.055, 2.4);
47
+ }
48
+
49
+ function relativeLuminance(r: number, g: number, b: number): number {
50
+ return 0.2126 * srgbToLinear(r) + 0.7152 * srgbToLinear(g) + 0.0722 * srgbToLinear(b);
51
+ }
52
+
53
+ /** Returns 0–1 relative luminance, or null if the color can't be resolved. */
54
+ function luminanceOf(raw: string): number | null {
55
+ let v = raw.trim().toLowerCase();
56
+ if (!v || v === "none" || v === "transparent" || v === "inherit" || v === "currentcolor") {
57
+ return null;
58
+ }
59
+ if (NAMED_HEX[v]) v = NAMED_HEX[v];
60
+ if (/^#[0-9a-f]{3}$/.test(v)) {
61
+ v = `#${v[1]}${v[1]}${v[2]}${v[2]}${v[3]}${v[3]}`;
62
+ }
63
+ if (/^#[0-9a-f]{6}$/.test(v)) {
64
+ const r = parseInt(v.slice(1, 3), 16);
65
+ const g = parseInt(v.slice(3, 5), 16);
66
+ const b = parseInt(v.slice(5, 7), 16);
67
+ return relativeLuminance(r, g, b);
68
+ }
69
+ const rgb = v.match(/^rgba?\(([^)]+)\)$/);
70
+ if (rgb) {
71
+ const parts = rgb[1]
72
+ .split(/[,\s/]+/)
73
+ .filter(Boolean)
74
+ .slice(0, 3)
75
+ .map(Number);
76
+ if (parts.length === 3 && parts.every((n) => !Number.isNaN(n))) {
77
+ return relativeLuminance(parts[0], parts[1], parts[2]);
78
+ }
79
+ }
80
+ return null;
81
+ }
82
+
83
+ function colorTokens(svg: string): string[] {
84
+ const tokens: string[] = [];
85
+ let m: RegExpExecArray | null;
86
+
87
+ const attrRe = /(?:fill|stroke|stop-color)\s*=\s*["']([^"']+)["']/gi;
88
+ while ((m = attrRe.exec(svg))) tokens.push(m[1]);
89
+
90
+ const styleRe = /style\s*=\s*["']([^"']+)["']/gi;
91
+ while ((m = styleRe.exec(svg))) {
92
+ for (const decl of m[1].split(";")) {
93
+ const [prop, val] = decl.split(":").map((s) => s?.trim());
94
+ if (val && (prop?.toLowerCase() === "fill" || prop?.toLowerCase() === "stroke")) {
95
+ tokens.push(val);
96
+ }
97
+ }
98
+ }
99
+ return tokens;
100
+ }
101
+
102
+ // Luminance below this reads as "dark"; above LIGHT reads as "light". The gap
103
+ // in between is deliberately wide so mid-tone marks fall through to "mixed"
104
+ // and are left alone rather than aggressively inverted.
105
+ const DARK_MAX = 0.22;
106
+ const LIGHT_MIN = 0.6;
107
+
108
+ export function classifyMarkTone(svg: string | null): MarkTone {
109
+ if (!svg) return "adaptive";
110
+ const tokens = colorTokens(svg);
111
+ // Any currentColor usage means the mark already adapts to the theme.
112
+ if (tokens.some((t) => t.trim().toLowerCase() === "currentcolor")) return "adaptive";
113
+
114
+ const lums: number[] = [];
115
+ for (const t of tokens) {
116
+ const l = luminanceOf(t);
117
+ if (l !== null) lums.push(l);
118
+ }
119
+ if (lums.length === 0) return "adaptive"; // nothing fixed to worry about
120
+
121
+ if (lums.every((l) => l <= DARK_MAX)) return "dark";
122
+ if (lums.every((l) => l >= LIGHT_MIN)) return "light";
123
+ return "mixed";
124
+ }
125
+
126
+ /**
127
+ * Tailwind class that inverts the mark only when it would be low-contrast.
128
+ *
129
+ * Pass `mode` for the Customize preview tiles, which fake light/dark via
130
+ * explicit backgrounds instead of the `.dark` class. Omit it on real surfaces
131
+ * — the app toggles `.dark` on <html>, so the `dark:` variants fire.
132
+ */
133
+ export function markToneFilterClass(tone: MarkTone, mode?: "light" | "dark"): string {
134
+ if (tone === "adaptive" || tone === "mixed") return "";
135
+ if (mode) {
136
+ const invert = (tone === "dark" && mode === "dark") || (tone === "light" && mode === "light");
137
+ return invert ? "invert" : "";
138
+ }
139
+ return tone === "dark" ? "dark:invert" : "invert dark:invert-0";
140
+ }