@behavioral-agentic-design-system/core 0.39.1 → 0.42.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 (115) hide show
  1. package/README.md +2 -0
  2. package/package.json +26 -5
  3. package/scripts/a11y-lint.cjs +88 -8
  4. package/scripts/bads-components.mjs +118 -0
  5. package/scripts/build-tokens.cjs +133 -12
  6. package/scripts/check-stories.mjs +1 -1
  7. package/scripts/health-report.mjs +16 -2
  8. package/scripts/lint-component-source.mjs +100 -0
  9. package/scripts/lint-microanimation.mjs +267 -0
  10. package/scripts/lint-slop.mjs +25 -1
  11. package/scripts/size-audit.cjs +79 -0
  12. package/scripts/source-of-truth.cjs +58 -0
  13. package/scripts/ux-smoke.mjs +438 -0
  14. package/scripts/wcag-audit.cjs +121 -6
  15. package/src/api/layers/file.ts +1 -0
  16. package/src/app/opengraph-image.tsx +5 -0
  17. package/src/app/preview/components/page.tsx +2237 -2
  18. package/src/app/shell.tsx +17 -16
  19. package/src/components/Foundations/Motion.stories.tsx +1 -0
  20. package/src/components/customize/brand-mark-section.tsx +4 -2
  21. package/src/components/customize/design-controls.tsx +17 -2
  22. package/src/components/customize/discipline-section.tsx +3 -6
  23. package/src/components/customize/font-pickers.tsx +1 -1
  24. package/src/components/customize/letter-spacing.tsx +1 -1
  25. package/src/components/customize/save-bar.tsx +2 -2
  26. package/src/components/customize/theme-io.tsx +7 -7
  27. package/src/components/customize/type-scale.tsx +1 -1
  28. package/src/components/customize-tab.tsx +7 -4
  29. package/src/components/home-tab.tsx +3 -0
  30. package/src/components/studio/studio.tsx +153 -0
  31. package/src/components/ui/accordion.tsx +7 -0
  32. package/src/components/ui/alert.tsx +1 -0
  33. package/src/components/ui/anchor.tsx +37 -3
  34. package/src/components/ui/announcement-bar.tsx +256 -0
  35. package/src/components/ui/attachment.tsx +211 -0
  36. package/src/components/ui/badge.tsx +1 -0
  37. package/src/components/ui/callout.tsx +218 -0
  38. package/src/components/ui/chart.tsx +5 -14
  39. package/src/components/ui/code.tsx +1 -1
  40. package/src/components/ui/color-picker.tsx +2 -2
  41. package/src/components/ui/format-relative-time.tsx +139 -0
  42. package/src/components/ui/gauge-chart.tsx +238 -0
  43. package/src/components/ui/grid.tsx +255 -0
  44. package/src/components/ui/heatmap.tsx +256 -0
  45. package/src/components/ui/icon.tsx +108 -0
  46. package/src/components/ui/index.ts +17 -0
  47. package/src/components/ui/infinite-scroll.tsx +103 -0
  48. package/src/components/ui/json-input.tsx +351 -0
  49. package/src/components/ui/navigation-progress.tsx +281 -0
  50. package/src/components/ui/number-input.tsx +1 -4
  51. package/src/components/ui/page-header.tsx +63 -0
  52. package/src/components/ui/password-input.tsx +2 -1
  53. package/src/components/ui/password-strength-input.tsx +288 -0
  54. package/src/components/ui/pill.tsx +140 -0
  55. package/src/components/ui/popover.tsx +27 -4
  56. package/src/components/ui/portal.tsx +111 -0
  57. package/src/components/ui/presence.tsx +172 -0
  58. package/src/components/ui/progress-stack.tsx +258 -0
  59. package/src/components/ui/scroll-progress.tsx +100 -0
  60. package/src/components/ui/select.tsx +89 -4
  61. package/src/components/ui/separator.tsx +1 -0
  62. package/src/components/ui/slider.tsx +83 -3
  63. package/src/components/ui/snackbar.tsx +393 -0
  64. package/src/components/ui/sortable-list.tsx +342 -0
  65. package/src/components/ui/sparkline.tsx +2 -14
  66. package/src/components/ui/squircle.tsx +1 -1
  67. package/src/components/ui/table.tsx +1 -1
  68. package/src/components/ui/textarea.tsx +28 -1
  69. package/src/components/ui/tour.tsx +1 -3
  70. package/src/data/docs-index.ts +25 -0
  71. package/src/hooks/use-reduced-motion.ts +6 -0
  72. package/src/lib/clamp.ts +2 -0
  73. package/src/stories/Accordion.stories.tsx +59 -0
  74. package/src/stories/Alert.stories.tsx +3 -1
  75. package/src/stories/Anchor.stories.tsx +54 -0
  76. package/src/stories/AnnouncementBar.stories.tsx +261 -0
  77. package/src/stories/Attachment.stories.tsx +189 -0
  78. package/src/stories/Badge.stories.tsx +3 -0
  79. package/src/stories/Calendar.stories.tsx +1 -1
  80. package/src/stories/Callout.stories.tsx +219 -0
  81. package/src/stories/Chart.stories.tsx +8 -0
  82. package/src/stories/Code.stories.tsx +1 -0
  83. package/src/stories/ColorPicker.stories.tsx +24 -0
  84. package/src/stories/FormatRelativeTime.stories.tsx +116 -0
  85. package/src/stories/GaugeChart.stories.tsx +163 -0
  86. package/src/stories/Grid.stories.tsx +197 -0
  87. package/src/stories/Heatmap.stories.tsx +172 -0
  88. package/src/stories/Icon.stories.tsx +175 -0
  89. package/src/stories/InfiniteScroll.stories.tsx +225 -0
  90. package/src/stories/JsonInput.stories.tsx +212 -0
  91. package/src/stories/MultiSelect.stories.tsx +1 -1
  92. package/src/stories/NavigationProgress.stories.tsx +159 -0
  93. package/src/stories/NumberInput.stories.tsx +1 -0
  94. package/src/stories/PageHeader.stories.tsx +102 -0
  95. package/src/stories/PasswordInput.stories.tsx +4 -0
  96. package/src/stories/PasswordStrengthInput.stories.tsx +211 -0
  97. package/src/stories/Pill.stories.tsx +201 -0
  98. package/src/stories/Popover.stories.tsx +29 -1
  99. package/src/stories/Portal.stories.tsx +191 -0
  100. package/src/stories/Presence.stories.tsx +228 -0
  101. package/src/stories/ProgressStack.stories.tsx +287 -0
  102. package/src/stories/ScrollProgress.stories.tsx +117 -0
  103. package/src/stories/Select.stories.tsx +25 -0
  104. package/src/stories/Separator.stories.tsx +3 -0
  105. package/src/stories/Slider.stories.tsx +54 -5
  106. package/src/stories/Snackbar.stories.tsx +315 -0
  107. package/src/stories/SortableList.stories.tsx +263 -0
  108. package/src/stories/Sparkline.stories.tsx +3 -0
  109. package/src/stories/Squircle.stories.tsx +1 -0
  110. package/src/stories/Table.stories.tsx +1 -0
  111. package/src/stories/Textarea.stories.tsx +18 -0
  112. package/src/stories/Tour.stories.tsx +1 -0
  113. package/src/stories/story-groups.json +26 -6
  114. package/src/styles.css +133 -12
  115. package/LICENSE +0 -21
@@ -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";
@@ -0,0 +1,256 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+
5
+ import { cn } from "../../lib/utils"
6
+
7
+ // Heatmap — a matrix of cells whose color intensity encodes a value.
8
+ //
9
+ // The fifth chart primitive, and the first one that is not a Recharts wrapper:
10
+ // Recharts has no heatmap series, and a value matrix does not want an SVG
11
+ // anyway. It wants a <table>. Row and column headers are the axes, each cell
12
+ // is a <td> with a tinted swatch, and the formatted value rides along as
13
+ // screen-reader-only text, so the chart is its own text alternative — a
14
+ // screen reader walks it as "Mon, Week 3, 12 commits" with no separate data
15
+ // table needed (docs/chart-design.md → Accessibility recap).
16
+ //
17
+ // Peer parity: Mantine `@mantine/charts` Heatmap (5 levels, Less→More legend,
18
+ // per-cell tooltip), MUI X Charts Heatmap (x/y axes + continuous color map),
19
+ // AntV Heatmap (xField/yField/colorField + legend ramp). BADS keeps the five
20
+ // levels and the legend, uses a native `title` for the per-cell tooltip, and
21
+ // adds the table semantics none of the three ship.
22
+ //
23
+ // Color (docs/chart-color-palette.md): ONE series color — `--chart-1` by
24
+ // default — and an opacity ramp for intensity. The data is the only saturated
25
+ // thing on the canvas; labels and the legend chrome sit in muted-foreground.
26
+ // Level 0 (the lowest bucket) and "no data" are `--muted`, so a quiet cell
27
+ // reads as surface, not as a faint data mark. Zero new tokens.
28
+ //
29
+ // Motion is pattern (c): the swatch transitions opacity + box-shadow on
30
+ // var(--duration-fast) / var(--ease-out) for the hover ring. Static otherwise.
31
+
32
+ const LEVELS = 5
33
+ /** Opacity for levels 1..4 (level 0 is the muted "lowest" bucket). */
34
+ const LEVEL_OPACITY = [0, 0.3, 0.5, 0.75, 1] as const
35
+
36
+ const sizeClass = {
37
+ sm: "size-3",
38
+ md: "size-4",
39
+ lg: "size-6",
40
+ } as const
41
+
42
+ // Explicit default locale, same reasoning as FormatNumber: an implicit
43
+ // navigator locale formats differently on the server and the client. Pass
44
+ // `formatValue` from your i18n layer to localize.
45
+ const defaultFormatter = new Intl.NumberFormat("en-US")
46
+
47
+ export interface HeatmapProps
48
+ extends Omit<React.ComponentProps<"div">, "children"> {
49
+ /** Row (y-axis) labels, top to bottom. One per row of `data`. */
50
+ rows: string[]
51
+ /** Column (x-axis) labels, left to right. One per entry of each row. */
52
+ columns: string[]
53
+ /**
54
+ * `rows.length` × `columns.length` matrix. `null` / `undefined` is "no data"
55
+ * and renders as a quiet muted cell, announced as "No data".
56
+ */
57
+ data: ReadonlyArray<ReadonlyArray<number | null | undefined>>
58
+ /**
59
+ * Series color — any CSS color, usually a chart token
60
+ * (`var(--chart-2)`). Intensity is an opacity ramp of this one color.
61
+ * Defaults to `var(--chart-1)`.
62
+ */
63
+ color?: string
64
+ /** Cell size: sm 12px, md 16px (default), lg 24px. */
65
+ size?: keyof typeof sizeClass
66
+ /**
67
+ * Fixed `[min, max]` for the intensity scale. Defaults to the data's own
68
+ * range. Pass it when several heatmaps must share one scale (a row of
69
+ * months, one per card) so the same value reads the same shade everywhere.
70
+ */
71
+ domain?: [number, number]
72
+ /**
73
+ * Formats a value for the cell tooltip, the screen-reader text, and the
74
+ * legend. Defaults to `Intl.NumberFormat("en-US")`.
75
+ */
76
+ formatValue?: (value: number) => string
77
+ /** Render the Less → More ramp below the grid. Default `true`. */
78
+ showLegend?: boolean
79
+ /**
80
+ * Accessible name — becomes the scroll region's `aria-label` and the
81
+ * table's caption. Say what the matrix measures: "Commits by weekday,
82
+ * last 12 weeks". Default "Heatmap".
83
+ */
84
+ label?: string
85
+ }
86
+
87
+ function quantize(
88
+ value: number | null | undefined,
89
+ min: number,
90
+ max: number
91
+ ): number | null {
92
+ if (value == null || Number.isNaN(value)) return null
93
+ if (max === min) return value > 0 ? LEVELS - 1 : 0
94
+ if (value <= min) return 0
95
+ const t = (value - min) / (max - min)
96
+ return Math.min(LEVELS - 1, 1 + Math.floor(t * (LEVELS - 1)))
97
+ }
98
+
99
+ function Heatmap({
100
+ rows,
101
+ columns,
102
+ data,
103
+ color = "var(--chart-1)",
104
+ size = "md",
105
+ domain,
106
+ formatValue,
107
+ showLegend = true,
108
+ label = "Heatmap",
109
+ className,
110
+ ...props
111
+ }: HeatmapProps) {
112
+ const format = React.useCallback(
113
+ (v: number) => (formatValue ? formatValue(v) : defaultFormatter.format(v)),
114
+ [formatValue]
115
+ )
116
+
117
+ const [min, max] = React.useMemo<[number, number]>(() => {
118
+ if (domain) return domain
119
+ let lo = Number.POSITIVE_INFINITY
120
+ let hi = Number.NEGATIVE_INFINITY
121
+ for (const row of data) {
122
+ for (const v of row) {
123
+ if (v == null || Number.isNaN(v)) continue
124
+ if (v < lo) lo = v
125
+ if (v > hi) hi = v
126
+ }
127
+ }
128
+ if (lo === Number.POSITIVE_INFINITY) return [0, 0]
129
+ return [lo, hi]
130
+ }, [data, domain])
131
+
132
+ const swatchSize = sizeClass[size]
133
+ const motion: React.CSSProperties = {
134
+ transitionDuration: "var(--duration-fast)",
135
+ transitionTimingFunction: "var(--ease-out)",
136
+ }
137
+
138
+ return (
139
+ <div
140
+ data-slot="heatmap"
141
+ data-size={size}
142
+ // The matrix can be wider than its container (52 weeks, 24 hours), so
143
+ // the root is a scroll region. A scroll container no keyboard user can
144
+ // reach fails axe (scrollable-region-focusable) — hence tabIndex + a
145
+ // landmark role with the chart's name (corrections #019).
146
+ role="region"
147
+ aria-label={label}
148
+ tabIndex={0}
149
+ className={cn(
150
+ "inline-flex max-w-full flex-col gap-3 overflow-x-auto rounded-md outline-none",
151
+ "focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
152
+ className
153
+ )}
154
+ {...props}
155
+ >
156
+ <table
157
+ data-slot="heatmap-table"
158
+ className="w-max border-separate border-spacing-0.5 text-xs text-muted-foreground"
159
+ >
160
+ <caption className="sr-only">{label}</caption>
161
+ <thead>
162
+ <tr>
163
+ {/* Empty corner cell above the row labels. */}
164
+ <td aria-hidden="true" />
165
+ {columns.map((column, ci) => (
166
+ <th
167
+ key={`${column}-${ci}`}
168
+ scope="col"
169
+ data-slot="heatmap-column-label"
170
+ className="px-0 pb-1 text-center align-bottom font-normal whitespace-nowrap"
171
+ >
172
+ {column}
173
+ </th>
174
+ ))}
175
+ </tr>
176
+ </thead>
177
+ <tbody>
178
+ {rows.map((row, ri) => (
179
+ <tr key={`${row}-${ri}`}>
180
+ <th
181
+ scope="row"
182
+ data-slot="heatmap-row-label"
183
+ className="pr-2 text-left align-middle font-normal whitespace-nowrap"
184
+ >
185
+ {row}
186
+ </th>
187
+ {columns.map((column, ci) => {
188
+ const value = data[ri]?.[ci]
189
+ const level = quantize(value, min, max)
190
+ const text =
191
+ level == null ? "No data" : format(value as number)
192
+ return (
193
+ <td
194
+ key={`${column}-${ci}`}
195
+ data-slot="heatmap-cell"
196
+ data-level={level ?? undefined}
197
+ title={`${row} · ${column}: ${text}`}
198
+ className="group/cell p-0 align-middle"
199
+ >
200
+ <span
201
+ data-slot="heatmap-swatch"
202
+ aria-hidden="true"
203
+ className={cn(
204
+ "block rounded-sm transition-[opacity,box-shadow]",
205
+ swatchSize,
206
+ level == null && "bg-muted/50",
207
+ level === 0 && "bg-muted",
208
+ "group-hover/cell:ring-2 group-hover/cell:ring-ring group-hover/cell:ring-offset-1 group-hover/cell:ring-offset-background"
209
+ )}
210
+ style={{
211
+ ...motion,
212
+ ...(level != null && level > 0
213
+ ? { backgroundColor: color, opacity: LEVEL_OPACITY[level] }
214
+ : null),
215
+ }}
216
+ />
217
+ <span className="sr-only">{text}</span>
218
+ </td>
219
+ )
220
+ })}
221
+ </tr>
222
+ ))}
223
+ </tbody>
224
+ </table>
225
+ {showLegend && (
226
+ <div
227
+ data-slot="heatmap-legend"
228
+ className="flex items-center justify-end gap-1 text-xs text-muted-foreground"
229
+ >
230
+ <span>Less</span>
231
+ <span className="sr-only">
232
+ {` (${format(min)}) to `}
233
+ </span>
234
+ <span aria-hidden="true" className="flex items-center gap-0.5">
235
+ {Array.from({ length: LEVELS }, (_, level) => (
236
+ <span
237
+ key={level}
238
+ data-level={level}
239
+ className={cn("block rounded-sm", swatchSize, level === 0 && "bg-muted")}
240
+ style={
241
+ level > 0
242
+ ? { backgroundColor: color, opacity: LEVEL_OPACITY[level] }
243
+ : undefined
244
+ }
245
+ />
246
+ ))}
247
+ </span>
248
+ <span>More</span>
249
+ <span className="sr-only">{` (${format(max)})`}</span>
250
+ </div>
251
+ )}
252
+ </div>
253
+ )
254
+ }
255
+
256
+ export { Heatmap }
@@ -0,0 +1,108 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import { cva, type VariantProps } from "class-variance-authority"
5
+
6
+ import { cn } from "../../lib/utils"
7
+ import { getIconColor, type IconRole } from "../../lib/get-icon-color"
8
+
9
+ /**
10
+ * Icon — the system wrapper for any Lucide (or SVG-prop-spreading) icon.
11
+ * Three rules from CLAUDE.md → Icons become unforgettable here:
12
+ *
13
+ * 1. **Stroke width is 1.5, always.** Lucide defaults to 2; this wrapper pins
14
+ * 1.5 and deliberately omits `strokeWidth` from its props. If an icon
15
+ * looks too thin or heavy at 1.5, swap the icon — never the stroke.
16
+ * 2. **Size is a token ladder** (`sm` 14 / `default` 16 / `lg` 20 / `xl` 24),
17
+ * not a per-call pixel number. `default` matches the `size-4` convention
18
+ * every BADS button and row already uses.
19
+ * 3. **Color is a semantic role**, not a class. `color="error"` resolves
20
+ * through `getIconColor()` to `text-icon-error` — the `icon-*` token
21
+ * family that aliases already-AAA-audited text roles. No `color` means
22
+ * `currentColor`, which is the right default for an icon beside text.
23
+ *
24
+ * Accessibility: decorative by default (`aria-hidden="true"`, the Lucide
25
+ * default). Pass `label` when the icon carries meaning on its own — it then
26
+ * renders `role="img"` + `aria-label`. Name the meaning ("Passing"), not the
27
+ * glyph ("check mark").
28
+ *
29
+ * Peer parity: Chakra UI Icon, MUI SvgIcon / Icon, Ant Design Icon,
30
+ * Component Gallery "Icon".
31
+ */
32
+
33
+ const iconVariants = cva("inline-block shrink-0 transition-colors", {
34
+ variants: {
35
+ size: {
36
+ sm: "size-3.5",
37
+ default: "size-4",
38
+ lg: "size-5",
39
+ xl: "size-6",
40
+ },
41
+ },
42
+ defaultVariants: {
43
+ size: "default",
44
+ },
45
+ })
46
+
47
+ type IconComponent = React.ComponentType<React.SVGProps<SVGSVGElement>>
48
+
49
+ interface IconProps
50
+ extends Omit<
51
+ React.ComponentPropsWithoutRef<"svg">,
52
+ "strokeWidth" | "color" | "children"
53
+ >,
54
+ VariantProps<typeof iconVariants> {
55
+ /** The icon component to render — any Lucide icon, or any component that
56
+ * spreads SVG props (`stroke="currentColor" fill="none"`). */
57
+ as: IconComponent
58
+ /**
59
+ * Semantic color role from the `icon-*` token family. Omit for
60
+ * `currentColor` (inherit from surrounding text). Never pass a token name
61
+ * or a Tailwind class here — `pnpm lint:icon-color` flags it.
62
+ */
63
+ color?: IconRole
64
+ /**
65
+ * Accessible name. When set, the icon is announced as an image with this
66
+ * label; when omitted the icon is decorative and hidden from assistive
67
+ * tech. Describe the meaning, not the shape.
68
+ */
69
+ label?: string
70
+ }
71
+
72
+ // Pattern-c motion: a parent-driven color change (group-hover, a role swap)
73
+ // eases on the fast token instead of snapping. The CSS vars resolve at
74
+ // runtime against :root in the generated styles.css.
75
+ const motionStyle: React.CSSProperties = {
76
+ transitionDuration: "var(--duration-fast)",
77
+ transitionTimingFunction: "var(--ease-out)",
78
+ }
79
+
80
+ const Icon = React.forwardRef<SVGSVGElement, IconProps>(
81
+ ({ as: Component, size, color, label, className, style, ...props }, ref) => {
82
+ const labelled = typeof label === "string" && label.length > 0
83
+ return (
84
+ <Component
85
+ ref={ref}
86
+ data-slot="icon"
87
+ data-size={size ?? "default"}
88
+ data-color={color}
89
+ strokeWidth={1.5}
90
+ focusable="false"
91
+ role={labelled ? "img" : undefined}
92
+ aria-label={labelled ? label : undefined}
93
+ aria-hidden={labelled ? undefined : true}
94
+ className={cn(
95
+ iconVariants({ size }),
96
+ color ? getIconColor(color) : undefined,
97
+ className
98
+ )}
99
+ style={{ ...motionStyle, ...style }}
100
+ {...props}
101
+ />
102
+ )
103
+ }
104
+ )
105
+ Icon.displayName = "Icon"
106
+
107
+ export { Icon, iconVariants }
108
+ export type { IconProps, IconComponent }
@@ -78,6 +78,7 @@ export * from "./editable";
78
78
  export * from "./qr-code";
79
79
  export * from "./highlight";
80
80
  export * from "./format-number";
81
+ export * from "./format-relative-time";
81
82
  export * from "./autocomplete";
82
83
  export * from "./button-group";
83
84
  export * from "./checkbox-group";
@@ -142,5 +143,21 @@ export * from "./date-field";
142
143
  export * from "./stack";
143
144
  export * from "./container";
144
145
  export * from "./simple-grid";
146
+ export * from "./grid";
145
147
  export * from "./close-button";
146
148
  export * from "./toggle-tip";
149
+ export * from "./presence";
150
+ export * from "./portal";
151
+ export * from "./icon";
152
+ export * from "./progress-stack";
153
+ export * from "./callout";
154
+ export * from "./announcement-bar";
155
+ export * from "./gauge-chart";
156
+ export * from "./password-strength-input";
157
+ export * from "./pill";
158
+ export * from "./snackbar";
159
+ export * from "./json-input";
160
+ export * from "./sortable-list";
161
+ export * from "./heatmap";
162
+ export * from "./navigation-progress";
163
+ export * from "./attachment";