@behavioral-agentic-design-system/core 0.39.1 → 0.40.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.
Files changed (69) hide show
  1. package/package.json +8 -3
  2. package/scripts/a11y-lint.cjs +47 -6
  3. package/scripts/bads-components.mjs +118 -0
  4. package/scripts/build-tokens.cjs +133 -12
  5. package/scripts/check-stories.mjs +1 -1
  6. package/scripts/lint-component-source.mjs +100 -0
  7. package/scripts/lint-microanimation.mjs +267 -0
  8. package/scripts/size-audit.cjs +79 -0
  9. package/scripts/source-of-truth.cjs +58 -0
  10. package/scripts/ux-smoke.mjs +438 -0
  11. package/scripts/wcag-audit.cjs +49 -1
  12. package/src/api/layers/file.ts +1 -0
  13. package/src/app/preview/components/page.tsx +968 -0
  14. package/src/app/shell.tsx +11 -13
  15. package/src/components/customize/brand-mark-section.tsx +4 -2
  16. package/src/components/customize/design-controls.tsx +1 -1
  17. package/src/components/customize/discipline-section.tsx +3 -6
  18. package/src/components/customize/font-pickers.tsx +1 -1
  19. package/src/components/customize/letter-spacing.tsx +1 -1
  20. package/src/components/customize/save-bar.tsx +2 -2
  21. package/src/components/customize/theme-io.tsx +7 -7
  22. package/src/components/customize/type-scale.tsx +1 -1
  23. package/src/components/customize-tab.tsx +7 -4
  24. package/src/components/home-tab.tsx +3 -0
  25. package/src/components/ui/accordion.tsx +7 -0
  26. package/src/components/ui/alert.tsx +1 -0
  27. package/src/components/ui/announcement-bar.tsx +256 -0
  28. package/src/components/ui/badge.tsx +1 -0
  29. package/src/components/ui/callout.tsx +218 -0
  30. package/src/components/ui/chart.tsx +2 -14
  31. package/src/components/ui/color-picker.tsx +1 -1
  32. package/src/components/ui/format-relative-time.tsx +139 -0
  33. package/src/components/ui/grid.tsx +255 -0
  34. package/src/components/ui/icon.tsx +108 -0
  35. package/src/components/ui/index.ts +8 -0
  36. package/src/components/ui/page-header.tsx +63 -0
  37. package/src/components/ui/portal.tsx +111 -0
  38. package/src/components/ui/presence.tsx +172 -0
  39. package/src/components/ui/progress-stack.tsx +258 -0
  40. package/src/components/ui/select.tsx +89 -4
  41. package/src/components/ui/separator.tsx +1 -0
  42. package/src/components/ui/slider.tsx +83 -3
  43. package/src/components/ui/sparkline.tsx +2 -14
  44. package/src/components/ui/textarea.tsx +28 -1
  45. package/src/data/docs-index.ts +1 -0
  46. package/src/hooks/use-reduced-motion.ts +6 -0
  47. package/src/stories/Accordion.stories.tsx +59 -0
  48. package/src/stories/Alert.stories.tsx +3 -1
  49. package/src/stories/AnnouncementBar.stories.tsx +261 -0
  50. package/src/stories/Badge.stories.tsx +3 -0
  51. package/src/stories/Calendar.stories.tsx +1 -1
  52. package/src/stories/Callout.stories.tsx +219 -0
  53. package/src/stories/Chart.stories.tsx +4 -0
  54. package/src/stories/ColorPicker.stories.tsx +23 -0
  55. package/src/stories/FormatRelativeTime.stories.tsx +116 -0
  56. package/src/stories/Grid.stories.tsx +197 -0
  57. package/src/stories/Icon.stories.tsx +175 -0
  58. package/src/stories/MultiSelect.stories.tsx +1 -1
  59. package/src/stories/PageHeader.stories.tsx +102 -0
  60. package/src/stories/Portal.stories.tsx +189 -0
  61. package/src/stories/Presence.stories.tsx +228 -0
  62. package/src/stories/ProgressStack.stories.tsx +287 -0
  63. package/src/stories/Select.stories.tsx +25 -0
  64. package/src/stories/Separator.stories.tsx +3 -0
  65. package/src/stories/Slider.stories.tsx +54 -5
  66. package/src/stories/Sparkline.stories.tsx +3 -0
  67. package/src/stories/Textarea.stories.tsx +18 -0
  68. package/src/stories/story-groups.json +14 -5
  69. package/src/styles.css +133 -12
@@ -0,0 +1,218 @@
1
+ import * as React from "react"
2
+ import {
3
+ InfoIcon,
4
+ LightbulbIcon,
5
+ TriangleAlertIcon,
6
+ OctagonAlertIcon,
7
+ CircleAlertIcon,
8
+ } from "lucide-react"
9
+ import { cva, type VariantProps } from "class-variance-authority"
10
+
11
+ import { cn } from "../../lib/utils"
12
+
13
+ // ─── Callout — the prose / documentation callout block ───────────────────────
14
+ //
15
+ // The editorial sibling of Alert, Notification, and Sonner. Use it to draw
16
+ // attention to a block of content inside prose or documentation, not to
17
+ // communicate system feedback.
18
+ //
19
+ // How it differs from Alert:
20
+ // - No `role="alert"`: a callout is contextual annotation, not urgent feedback.
21
+ // Screen readers should announce it in reading order, not interrupt.
22
+ // - Richer content slot: the body can hold headings, lists, inline code, and
23
+ // multiple paragraphs — no single-line constraint.
24
+ // - No dismiss button or action row (editorial asides are not dismissed).
25
+ // - Variants named for editorial convention: note / tip / warning / danger / info.
26
+ //
27
+ // Sources: GitHub Markdown callout syntax (> [!NOTE]), Nextra, VitePress,
28
+ // Docusaurus admonitions, Notion callout block, Tailwind CSS docs.
29
+ //
30
+ // Motion: none — callouts are display-only annotation; entrance animation
31
+ // would distract from the prose flow around them.
32
+
33
+ // ─── Variants ─────────────────────────────────────────────────────────────────
34
+
35
+ const calloutVariants = cva(
36
+ // Grid with icon pinned to col-1 row-1, same layout as Alert. The icon
37
+ // column activates only when an icon is rendered (has-[>svg]). Padding is
38
+ // slightly more generous than Alert-sm to give body text room to breathe.
39
+ [
40
+ "relative grid w-full grid-cols-[0_1fr] items-start rounded-lg border",
41
+ "[&>svg]:row-start-1 [&>svg]:col-start-1 [&>svg]:text-current",
42
+ "has-[>svg]:grid-cols-[calc(var(--spacing)*5)_1fr] has-[>svg]:gap-x-3",
43
+ "px-5 py-4 gap-y-1.5 [&>svg]:size-5 [&>svg]:mt-0.5",
44
+ ],
45
+ {
46
+ variants: {
47
+ /**
48
+ * Semantic intent for the callout. The intent drives icon, border
49
+ * accent, and background tint; the label color stays text-foreground
50
+ * (AAA floor). Never rely on color alone — the default icon and
51
+ * (optionally) the `title` text carry the semantic label visually.
52
+ *
53
+ * note — primary accent (blue). General informational aside.
54
+ * tip — success accent (green). Helpful shortcut or best practice.
55
+ * warning — warning accent (amber). Caution: risk or potential issue.
56
+ * danger — destructive accent (red). Stop: breaking change or data loss.
57
+ * info — info accent. Neutral reference that isn't an error or tip.
58
+ */
59
+ variant: {
60
+ // NOTE: accent colors use the arbitrary `border-l-[var(--token)]!`
61
+ // form — named border-color utilities don't generate a rule in this
62
+ // Tailwind v4 setup. Same pattern as Alert and Notification.
63
+ note: [
64
+ "border-border border-l-4 border-l-[var(--primary)]!",
65
+ "bg-primary/5 dark:bg-primary/10",
66
+ "[&>svg]:text-primary",
67
+ ],
68
+ tip: [
69
+ "border-border border-l-4 border-l-[var(--success)]!",
70
+ "bg-success/5 dark:bg-success/10",
71
+ "[&>svg]:text-[var(--success)]",
72
+ ],
73
+ warning: [
74
+ "border-border border-l-4 border-l-[var(--warning)]!",
75
+ "bg-warning/5 dark:bg-warning/10",
76
+ "[&>svg]:text-[var(--warning)]",
77
+ ],
78
+ danger: [
79
+ "border-[var(--destructive)]! border-l-4",
80
+ "bg-destructive/5 dark:bg-destructive/10",
81
+ "[&>svg]:text-destructive",
82
+ ],
83
+ info: [
84
+ "border-border border-l-4 border-l-[var(--info)]!",
85
+ "bg-info/5 dark:bg-info/10",
86
+ "[&>svg]:text-[var(--info)]",
87
+ ],
88
+ },
89
+ },
90
+ defaultVariants: {
91
+ variant: "note",
92
+ },
93
+ }
94
+ )
95
+
96
+ // ─── Types ────────────────────────────────────────────────────────────────────
97
+
98
+ type CalloutVariant = NonNullable<VariantProps<typeof calloutVariants>["variant"]>
99
+
100
+ export interface CalloutProps
101
+ extends Omit<React.ComponentProps<"aside">, "title">,
102
+ VariantProps<typeof calloutVariants> {
103
+ /**
104
+ * Custom icon to replace the default. Pass `null` to suppress the icon
105
+ * entirely and let the callout render without one. The default icon is
106
+ * chosen per variant (note → Info, tip → Lightbulb, warning → TriangleAlert,
107
+ * danger → OctagonAlert, info → CircleAlert).
108
+ */
109
+ icon?: React.ReactNode | null
110
+ /**
111
+ * Optional short header rendered above the body. Use for the "Note",
112
+ * "Warning", etc. label or a custom heading. When omitted, the callout has
113
+ * no visible heading — the icon alone carries the variant signal.
114
+ */
115
+ title?: React.ReactNode
116
+ }
117
+
118
+ // ─── Default icons per variant ────────────────────────────────────────────────
119
+
120
+ const DEFAULT_ICONS: Record<CalloutVariant, React.ElementType> = {
121
+ note: InfoIcon,
122
+ tip: LightbulbIcon,
123
+ warning: TriangleAlertIcon,
124
+ danger: OctagonAlertIcon,
125
+ info: CircleAlertIcon,
126
+ }
127
+
128
+ // ─── Sub-components ───────────────────────────────────────────────────────────
129
+
130
+ function CalloutTitle({ className, ...props }: React.ComponentProps<"p">) {
131
+ return (
132
+ <p
133
+ data-slot="callout-title"
134
+ className={cn("col-start-2 text-sm font-medium leading-snug", className)}
135
+ {...props}
136
+ />
137
+ )
138
+ }
139
+
140
+ function CalloutBody({ className, ...props }: React.ComponentProps<"div">) {
141
+ return (
142
+ <div
143
+ data-slot="callout-body"
144
+ className={cn(
145
+ "col-start-2 text-sm text-muted-foreground",
146
+ // Let inline headings, lists, and code render cleanly inside the body.
147
+ // Prose spacing: small gap between children.
148
+ "[&>*+*]:mt-2",
149
+ className
150
+ )}
151
+ {...props}
152
+ />
153
+ )
154
+ }
155
+
156
+ // ─── Root ─────────────────────────────────────────────────────────────────────
157
+
158
+ /**
159
+ * Callout — a documentation/editorial aside that highlights contextual
160
+ * information inside prose.
161
+ *
162
+ * Use `<Callout>` for inline editorial annotation: a note about a gotcha, a
163
+ * tip about a shortcut, a warning before a destructive operation's docs.
164
+ *
165
+ * Five variants (note / tip / warning / danger / info) map to the same
166
+ * intent family as Alert and Notification so all three surfaces read as one
167
+ * system, but with a different visual treatment — left-border accent only,
168
+ * no dismiss, no action, no `role="alert"` urgency.
169
+ *
170
+ * @example
171
+ * ```tsx
172
+ * <Callout variant="tip" title="Tip">
173
+ * Run <Code>pnpm build:tokens</Code> after editing <Code>tokens.json</Code>.
174
+ * Both CSS files regenerate automatically.
175
+ * </Callout>
176
+ *
177
+ * <Callout variant="danger" title="Breaking change">
178
+ * <p>The <Code>size</Code> prop on Button was renamed to <Code>buttonSize</Code>.</p>
179
+ * <p>Update every usage before upgrading to v3.</p>
180
+ * </Callout>
181
+ * ```
182
+ */
183
+ function Callout({
184
+ className,
185
+ variant = "note",
186
+ icon,
187
+ title,
188
+ children,
189
+ ...props
190
+ }: CalloutProps) {
191
+ // Resolve icon: explicit null suppresses, explicit ReactNode overrides,
192
+ // undefined falls back to the default for the variant.
193
+ const DefaultIcon = DEFAULT_ICONS[variant ?? "note"]
194
+ const resolvedIcon =
195
+ icon === null ? null : icon !== undefined ? icon : (
196
+ <DefaultIcon
197
+ data-slot="callout-icon"
198
+ strokeWidth={1.5}
199
+ aria-hidden
200
+ />
201
+ )
202
+
203
+ return (
204
+ <aside
205
+ data-slot="callout"
206
+ data-variant={variant}
207
+ className={cn(calloutVariants({ variant }), className)}
208
+ {...props}
209
+ >
210
+ {resolvedIcon}
211
+ {title && <CalloutTitle>{title}</CalloutTitle>}
212
+ <CalloutBody>{children}</CalloutBody>
213
+ </aside>
214
+ )
215
+ }
216
+
217
+ export { Callout, CalloutTitle, CalloutBody, calloutVariants }
218
+ export type { CalloutVariant }
@@ -4,6 +4,7 @@ import * as React from "react"
4
4
  import * as RechartsPrimitive from "recharts"
5
5
 
6
6
  import { cn } from "../../lib/utils"
7
+ import { useReducedMotion } from "../../hooks/use-reduced-motion"
7
8
 
8
9
  // Format: { THEME_NAME: CSS_SELECTOR }
9
10
  const THEMES = { light: "", dark: ".dark" } as const
@@ -81,19 +82,6 @@ function injectAnimationDefault(
81
82
  return React.cloneElement(element, nextProps)
82
83
  }
83
84
 
84
- function usePrefersReducedMotion() {
85
- const [reduced, setReduced] = React.useState(false)
86
- React.useEffect(() => {
87
- if (typeof window === "undefined" || !window.matchMedia) return
88
- const mql = window.matchMedia("(prefers-reduced-motion: reduce)")
89
- setReduced(mql.matches)
90
- const onChange = (e: MediaQueryListEvent) => setReduced(e.matches)
91
- mql.addEventListener("change", onChange)
92
- return () => mql.removeEventListener("change", onChange)
93
- }, [])
94
- return reduced
95
- }
96
-
97
85
  function ChartContainer({
98
86
  id,
99
87
  className,
@@ -120,7 +108,7 @@ function ChartContainer({
120
108
  }) {
121
109
  const uniqueId = React.useId()
122
110
  const chartId = `chart-${id || uniqueId.replace(/:/g, "")}`
123
- const prefersReducedMotion = usePrefersReducedMotion()
111
+ const prefersReducedMotion = useReducedMotion()
124
112
  const effectiveAnimate = animate && !prefersReducedMotion
125
113
 
126
114
  // ResponsiveContainer logs "width(-1) and height(-1)" whenever it renders
@@ -549,7 +549,7 @@ export function ColorPicker({
549
549
  type="button"
550
550
  onClick={addColor}
551
551
  disabled={disabled || !isValidHex(draft)}
552
- className="w-full"
552
+ className="w-full min-h-11"
553
553
  >
554
554
  Add color
555
555
  </Button>
@@ -0,0 +1,139 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+
5
+ import { cn } from "../../lib/utils"
6
+
7
+ /**
8
+ * Explicit default locale — never reads navigator.language, which differs
9
+ * between server and client and causes hydration mismatches.
10
+ */
11
+ const FORMAT_RELATIVE_TIME_DEFAULT_LOCALE = "en-US"
12
+
13
+ /** Thresholds for picking the right Intl unit. */
14
+ const UNITS: { unit: Intl.RelativeTimeFormatUnit; ms: number }[] = [
15
+ { unit: "second", ms: 60_000 },
16
+ { unit: "minute", ms: 3_600_000 },
17
+ { unit: "hour", ms: 86_400_000 },
18
+ { unit: "day", ms: 2_592_000_000 },
19
+ { unit: "month", ms: 31_536_000_000 },
20
+ { unit: "year", ms: Infinity },
21
+ ]
22
+
23
+ function formatRelative(
24
+ date: Date,
25
+ locale: string,
26
+ numeric: Intl.RelativeTimeFormatNumeric,
27
+ style: Intl.RelativeTimeFormatStyle
28
+ ): string {
29
+ const diffMs = date.getTime() - Date.now()
30
+ const absDiff = Math.abs(diffMs)
31
+
32
+ for (let i = 0; i < UNITS.length; i++) {
33
+ const { unit, ms } = UNITS[i]
34
+ if (absDiff < ms) {
35
+ const prevMs = UNITS[i - 1]?.ms ?? 1_000
36
+ const value = Math.round(diffMs / prevMs)
37
+ return new Intl.RelativeTimeFormat(locale, { numeric, style }).format(
38
+ value,
39
+ unit
40
+ )
41
+ }
42
+ }
43
+ // Fallback: years
44
+ const value = Math.round(diffMs / 31_536_000_000)
45
+ return new Intl.RelativeTimeFormat(locale, { numeric, style }).format(
46
+ value,
47
+ "year"
48
+ )
49
+ }
50
+
51
+ export interface FormatRelativeTimeProps
52
+ extends Omit<React.ComponentProps<"time">, "children" | "dateTime"> {
53
+ /**
54
+ * The date to express as relative to now. Accepts a Date, ISO 8601 string,
55
+ * or UNIX timestamp (ms).
56
+ */
57
+ date: Date | string | number
58
+ /**
59
+ * BCP 47 locale tag. Defaults to "en-US" (explicit, SSR-safe).
60
+ */
61
+ locale?: string
62
+ /**
63
+ * Whether the displayed string should update automatically.
64
+ * @default true
65
+ */
66
+ live?: boolean
67
+ /**
68
+ * How often to recalculate the relative string, in milliseconds.
69
+ * Ignored when `live` is false.
70
+ * @default 30000 (30 s)
71
+ */
72
+ updateInterval?: number
73
+ /**
74
+ * `Intl.RelativeTimeFormat` numeric mode.
75
+ * "auto" produces "yesterday", "today", "tomorrow".
76
+ * "always" produces "-1 day", "0 days", "+1 day".
77
+ * @default "auto"
78
+ */
79
+ numeric?: Intl.RelativeTimeFormatNumeric
80
+ /**
81
+ * `Intl.RelativeTimeFormat` style.
82
+ * @default "long"
83
+ */
84
+ formatStyle?: Intl.RelativeTimeFormatStyle
85
+ }
86
+
87
+ /**
88
+ * Locale-aware relative-time display primitive — a thin wrapper around
89
+ * `Intl.RelativeTimeFormat`. Renders a `<time>` element with a machine-
90
+ * readable `dateTime` attribute and a human-readable relative string like
91
+ * "3 minutes ago" or "in 2 days". Optionally live-updates.
92
+ *
93
+ * Display-only. For editable date/time inputs use DatePicker or TimePicker.
94
+ */
95
+ function FormatRelativeTime({
96
+ date,
97
+ locale = FORMAT_RELATIVE_TIME_DEFAULT_LOCALE,
98
+ live = true,
99
+ updateInterval = 30_000,
100
+ numeric = "auto",
101
+ formatStyle = "long",
102
+ className,
103
+ title,
104
+ ...props
105
+ }: FormatRelativeTimeProps) {
106
+ const parsed = React.useMemo(
107
+ () => (date instanceof Date ? date : new Date(date)),
108
+ [date]
109
+ )
110
+
111
+ const [text, setText] = React.useState<string>(() =>
112
+ formatRelative(parsed, locale, numeric, formatStyle)
113
+ )
114
+
115
+ React.useEffect(() => {
116
+ setText(formatRelative(parsed, locale, numeric, formatStyle))
117
+ if (!live) return
118
+ const id = setInterval(() => {
119
+ setText(formatRelative(parsed, locale, numeric, formatStyle))
120
+ }, updateInterval)
121
+ return () => clearInterval(id)
122
+ }, [parsed, locale, live, updateInterval, numeric, formatStyle])
123
+
124
+ const isoString = parsed.toISOString()
125
+
126
+ return (
127
+ <time
128
+ data-slot="format-relative-time"
129
+ dateTime={isoString}
130
+ title={title ?? isoString}
131
+ className={cn(className)}
132
+ {...props}
133
+ >
134
+ {text}
135
+ </time>
136
+ )
137
+ }
138
+
139
+ export { FormatRelativeTime, FORMAT_RELATIVE_TIME_DEFAULT_LOCALE }
@@ -0,0 +1,255 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import { cn } from "../../lib/utils";
5
+
6
+ // ─── Grid ─────────────────────────────────────────────────────────────────────
7
+ //
8
+ // Twelve-track span grid — the SimpleGrid sibling for UNEQUAL columns. A
9
+ // GridCol spans 1–12 tracks and may be pushed right by leading empty tracks
10
+ // (`offset`), per breakpoint. Same statically-safe contract as SimpleGrid:
11
+ // every span and start value maps to a literal Tailwind class from the lookup
12
+ // tables below, so a template-string `col-span-${n}` can never silently
13
+ // compile to nothing under the Tailwind v4 scanner.
14
+ //
15
+ // Cross-system references: Mantine Grid / Grid.Col (span, offset), MUI Grid
16
+ // (size, offset), Ant Design Row / Col (span, offset), Chakra Grid / GridItem
17
+ // (colSpan, colStart). Columns are fixed at 12 — every source defaults to it.
18
+ //
19
+ // Offset is implemented as `grid-column-start` (Chakra's model). With row
20
+ // auto-flow, an offset cell that no longer fits the current row wraps to the
21
+ // next — the same visible behavior as Mantine's / Ant's margin-based offset.
22
+ //
23
+ // Layout-only primitive (Stack / Group / Container / SimpleGrid class): no
24
+ // ARIA, no interaction, no motion. Deliberately NO `order` prop — a visual
25
+ // reorder desynchronizes reading order from DOM order (SC 1.3.2 / 2.4.3).
26
+ // For equal-width tracks reach for SimpleGrid; for variable-height packing,
27
+ // Masonry; for tabular data, Table / DataTable.
28
+
29
+ type Span = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
30
+ type Offset = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11;
31
+
32
+ /** Track counts per breakpoint. `base` applies from 0px up; sm/md/lg override upward. */
33
+ export interface ResponsiveSpan {
34
+ base?: Span;
35
+ sm?: Span;
36
+ md?: Span;
37
+ lg?: Span;
38
+ }
39
+
40
+ /** Leading empty tracks per breakpoint. `0` at a breakpoint resets to auto placement. */
41
+ export interface ResponsiveOffset {
42
+ base?: Offset;
43
+ sm?: Offset;
44
+ md?: Offset;
45
+ lg?: Offset;
46
+ }
47
+
48
+ // Literal class maps — every generated class must be spelled out so the
49
+ // Tailwind scanner ships it. Never build these strings dynamically.
50
+ const BASE_SPAN: Record<Span, string> = {
51
+ 1: "col-span-1",
52
+ 2: "col-span-2",
53
+ 3: "col-span-3",
54
+ 4: "col-span-4",
55
+ 5: "col-span-5",
56
+ 6: "col-span-6",
57
+ 7: "col-span-7",
58
+ 8: "col-span-8",
59
+ 9: "col-span-9",
60
+ 10: "col-span-10",
61
+ 11: "col-span-11",
62
+ 12: "col-span-12",
63
+ };
64
+ const SM_SPAN: Record<Span, string> = {
65
+ 1: "sm:col-span-1",
66
+ 2: "sm:col-span-2",
67
+ 3: "sm:col-span-3",
68
+ 4: "sm:col-span-4",
69
+ 5: "sm:col-span-5",
70
+ 6: "sm:col-span-6",
71
+ 7: "sm:col-span-7",
72
+ 8: "sm:col-span-8",
73
+ 9: "sm:col-span-9",
74
+ 10: "sm:col-span-10",
75
+ 11: "sm:col-span-11",
76
+ 12: "sm:col-span-12",
77
+ };
78
+ const MD_SPAN: Record<Span, string> = {
79
+ 1: "md:col-span-1",
80
+ 2: "md:col-span-2",
81
+ 3: "md:col-span-3",
82
+ 4: "md:col-span-4",
83
+ 5: "md:col-span-5",
84
+ 6: "md:col-span-6",
85
+ 7: "md:col-span-7",
86
+ 8: "md:col-span-8",
87
+ 9: "md:col-span-9",
88
+ 10: "md:col-span-10",
89
+ 11: "md:col-span-11",
90
+ 12: "md:col-span-12",
91
+ };
92
+ const LG_SPAN: Record<Span, string> = {
93
+ 1: "lg:col-span-1",
94
+ 2: "lg:col-span-2",
95
+ 3: "lg:col-span-3",
96
+ 4: "lg:col-span-4",
97
+ 5: "lg:col-span-5",
98
+ 6: "lg:col-span-6",
99
+ 7: "lg:col-span-7",
100
+ 8: "lg:col-span-8",
101
+ 9: "lg:col-span-9",
102
+ 10: "lg:col-span-10",
103
+ 11: "lg:col-span-11",
104
+ 12: "lg:col-span-12",
105
+ };
106
+
107
+ // Offset N → grid-column-start N+1. Offset 0 at the base breakpoint emits
108
+ // nothing (auto placement is the default); at sm/md/lg it emits an explicit
109
+ // `col-start-auto` so a smaller breakpoint's offset can be reset upward.
110
+ const BASE_START: Record<Offset, string> = {
111
+ 0: "",
112
+ 1: "col-start-2",
113
+ 2: "col-start-3",
114
+ 3: "col-start-4",
115
+ 4: "col-start-5",
116
+ 5: "col-start-6",
117
+ 6: "col-start-7",
118
+ 7: "col-start-8",
119
+ 8: "col-start-9",
120
+ 9: "col-start-10",
121
+ 10: "col-start-11",
122
+ 11: "col-start-12",
123
+ };
124
+ const SM_START: Record<Offset, string> = {
125
+ 0: "sm:col-start-auto",
126
+ 1: "sm:col-start-2",
127
+ 2: "sm:col-start-3",
128
+ 3: "sm:col-start-4",
129
+ 4: "sm:col-start-5",
130
+ 5: "sm:col-start-6",
131
+ 6: "sm:col-start-7",
132
+ 7: "sm:col-start-8",
133
+ 8: "sm:col-start-9",
134
+ 9: "sm:col-start-10",
135
+ 10: "sm:col-start-11",
136
+ 11: "sm:col-start-12",
137
+ };
138
+ const MD_START: Record<Offset, string> = {
139
+ 0: "md:col-start-auto",
140
+ 1: "md:col-start-2",
141
+ 2: "md:col-start-3",
142
+ 3: "md:col-start-4",
143
+ 4: "md:col-start-5",
144
+ 5: "md:col-start-6",
145
+ 6: "md:col-start-7",
146
+ 7: "md:col-start-8",
147
+ 8: "md:col-start-9",
148
+ 9: "md:col-start-10",
149
+ 10: "md:col-start-11",
150
+ 11: "md:col-start-12",
151
+ };
152
+ const LG_START: Record<Offset, string> = {
153
+ 0: "lg:col-start-auto",
154
+ 1: "lg:col-start-2",
155
+ 2: "lg:col-start-3",
156
+ 3: "lg:col-start-4",
157
+ 4: "lg:col-start-5",
158
+ 5: "lg:col-start-6",
159
+ 6: "lg:col-start-7",
160
+ 7: "lg:col-start-8",
161
+ 8: "lg:col-start-9",
162
+ 9: "lg:col-start-10",
163
+ 10: "lg:col-start-11",
164
+ 11: "lg:col-start-12",
165
+ };
166
+
167
+ /** Same token-keyed gap scale as Stack / Group / SimpleGrid (gap-0/1/2/4/6/8 → 0/4/8/16/24/32px). */
168
+ const GAP: Record<"none" | "xs" | "sm" | "md" | "lg" | "xl", string> = {
169
+ none: "gap-0",
170
+ xs: "gap-1",
171
+ sm: "gap-2",
172
+ md: "gap-4",
173
+ lg: "gap-6",
174
+ xl: "gap-8",
175
+ };
176
+
177
+ /** Cross-axis alignment of cells within each row (align-items). */
178
+ const ALIGN: Record<"start" | "center" | "end" | "stretch", string> = {
179
+ start: "items-start",
180
+ center: "items-center",
181
+ end: "items-end",
182
+ stretch: "items-stretch",
183
+ };
184
+
185
+ export interface GridProps extends React.HTMLAttributes<HTMLDivElement> {
186
+ /** Gap between cells, keyed to the BADS spacing scale. Default: "lg" (24px) — matches SimpleGrid. */
187
+ gap?: keyof typeof GAP;
188
+ /** Row cross-axis alignment. Default: "stretch" so sibling cards in a row share a height. */
189
+ align?: keyof typeof ALIGN;
190
+ }
191
+
192
+ export interface GridColProps extends React.HTMLAttributes<HTMLDivElement> {
193
+ /**
194
+ * Tracks this cell spans, out of 12 — a single number (fixed at all widths)
195
+ * or a responsive object, e.g. `{ base: 12, md: 8 }`. Default: 12 (full
196
+ * width), so a column stacks on mobile unless told otherwise.
197
+ */
198
+ span?: Span | ResponsiveSpan;
199
+ /**
200
+ * Leading empty tracks before this cell (0–11), fixed or responsive.
201
+ * Implemented as `grid-column-start`; a cell that no longer fits its row
202
+ * wraps to the next. Default: 0.
203
+ */
204
+ offset?: Offset | ResponsiveOffset;
205
+ }
206
+
207
+ function spanClasses(span: Span | ResponsiveSpan): string[] {
208
+ if (typeof span === "number") return [BASE_SPAN[span]];
209
+ const out: string[] = [BASE_SPAN[span.base ?? 12]];
210
+ if (span.sm) out.push(SM_SPAN[span.sm]);
211
+ if (span.md) out.push(MD_SPAN[span.md]);
212
+ if (span.lg) out.push(LG_SPAN[span.lg]);
213
+ return out;
214
+ }
215
+
216
+ function offsetClasses(offset: Offset | ResponsiveOffset): string[] {
217
+ if (typeof offset === "number") return [BASE_START[offset]];
218
+ const out: string[] = [BASE_START[offset.base ?? 0]];
219
+ if (offset.sm !== undefined) out.push(SM_START[offset.sm]);
220
+ if (offset.md !== undefined) out.push(MD_START[offset.md]);
221
+ if (offset.lg !== undefined) out.push(LG_START[offset.lg]);
222
+ return out;
223
+ }
224
+
225
+ export const Grid = React.forwardRef<HTMLDivElement, GridProps>(
226
+ ({ className, gap = "lg", align = "stretch", ...props }, ref) => (
227
+ <div
228
+ ref={ref}
229
+ data-slot="grid"
230
+ className={cn("grid grid-cols-12", GAP[gap], ALIGN[align], className)}
231
+ {...props}
232
+ />
233
+ )
234
+ );
235
+ Grid.displayName = "Grid";
236
+
237
+ export const GridCol = React.forwardRef<HTMLDivElement, GridColProps>(
238
+ ({ className, span = 12, offset = 0, ...props }, ref) => (
239
+ <div
240
+ ref={ref}
241
+ data-slot="grid-col"
242
+ // min-w-0 so a long runtime string inside a cell truncates / wraps
243
+ // instead of forcing the track wider (long-label overflow contract,
244
+ // corrections.md #001).
245
+ className={cn(
246
+ "min-w-0",
247
+ ...spanClasses(span),
248
+ ...offsetClasses(offset),
249
+ className
250
+ )}
251
+ {...props}
252
+ />
253
+ )
254
+ );
255
+ GridCol.displayName = "GridCol";