@behavioral-agentic-design-system/core 0.28.0 → 0.30.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 (106) hide show
  1. package/package.json +2 -2
  2. package/scripts/a11y-lint.cjs +78 -9
  3. package/scripts/build-tokens.cjs +273 -15
  4. package/scripts/wcag-audit.cjs +67 -11
  5. package/src/api/layers/file.ts +1 -0
  6. package/src/app/font-ready.tsx +6 -5
  7. package/src/app/layout.tsx +54 -3
  8. package/src/app/preview/components/page.tsx +5679 -3073
  9. package/src/app/preview/health/page.tsx +201 -0
  10. package/src/app/preview/layout.tsx +4 -1
  11. package/src/app/preview/showcase-filter.tsx +66 -0
  12. package/src/app/preview/tab-replay.tsx +63 -0
  13. package/src/app/shell.tsx +74 -18
  14. package/src/components/customize/save-bar.tsx +19 -6
  15. package/src/components/docs-tab.tsx +36 -24
  16. package/src/components/layers-tab.tsx +37 -5
  17. package/src/components/ui/alert.tsx +12 -0
  18. package/src/components/ui/badge.tsx +19 -0
  19. package/src/components/ui/button.tsx +10 -0
  20. package/src/components/ui/chat-marker.tsx +120 -0
  21. package/src/components/ui/checkbox.tsx +9 -1
  22. package/src/components/ui/close-button.tsx +71 -0
  23. package/src/components/ui/combobox.tsx +62 -3
  24. package/src/components/ui/container.tsx +65 -0
  25. package/src/components/ui/date-field.tsx +368 -0
  26. package/src/components/ui/drawer.tsx +334 -0
  27. package/src/components/ui/file-button.tsx +145 -0
  28. package/src/components/ui/floating-indicator.tsx +217 -0
  29. package/src/components/ui/format-byte.tsx +113 -0
  30. package/src/components/ui/index.ts +21 -0
  31. package/src/components/ui/input-clear-button.tsx +52 -0
  32. package/src/components/ui/input.tsx +39 -20
  33. package/src/components/ui/keyboard-shortcut.tsx +146 -0
  34. package/src/components/ui/loading-dots.tsx +99 -0
  35. package/src/components/ui/month-picker.tsx +296 -0
  36. package/src/components/ui/multi-select.tsx +35 -19
  37. package/src/components/ui/nav-link.tsx +200 -0
  38. package/src/components/ui/navigation-rail.tsx +256 -0
  39. package/src/components/ui/notification.tsx +20 -0
  40. package/src/components/ui/password-input.tsx +34 -1
  41. package/src/components/ui/progress.tsx +15 -1
  42. package/src/components/ui/prose.tsx +62 -0
  43. package/src/components/ui/questionnaire.tsx +334 -0
  44. package/src/components/ui/result.tsx +151 -0
  45. package/src/components/ui/rolling-number.tsx +1 -0
  46. package/src/components/ui/sidebar.tsx +5 -0
  47. package/src/components/ui/simple-grid.tsx +110 -0
  48. package/src/components/ui/skeleton.tsx +52 -3
  49. package/src/components/ui/squircle.tsx +274 -0
  50. package/src/components/ui/stack.tsx +105 -0
  51. package/src/components/ui/status-badge.tsx +93 -0
  52. package/src/components/ui/tabs.tsx +34 -7
  53. package/src/components/ui/tag.tsx +46 -5
  54. package/src/components/ui/textarea.tsx +5 -0
  55. package/src/components/ui/theme-icon.tsx +138 -0
  56. package/src/components/ui/timeline.tsx +27 -10
  57. package/src/components/ui/tooltip.tsx +12 -1
  58. package/src/components/ui/tree-select.tsx +386 -0
  59. package/src/components/ui/year-picker.tsx +307 -0
  60. package/src/data/docs-index.ts +12 -0
  61. package/src/hooks/use-global-primary-color.ts +57 -6
  62. package/src/lib/get-icon-color.ts +66 -0
  63. package/src/stories/Alert.stories.tsx +31 -1
  64. package/src/stories/Badge.stories.tsx +63 -6
  65. package/src/stories/Button.stories.tsx +3 -0
  66. package/src/stories/ChatMarker.stories.tsx +59 -0
  67. package/src/stories/Checkbox.stories.tsx +5 -0
  68. package/src/stories/CloseButton.stories.tsx +65 -0
  69. package/src/stories/Combobox.stories.tsx +74 -3
  70. package/src/stories/Container.stories.tsx +134 -0
  71. package/src/stories/DateField.stories.tsx +114 -0
  72. package/src/stories/Drawer.stories.tsx +211 -0
  73. package/src/stories/FileButton.stories.tsx +117 -0
  74. package/src/stories/FloatingIndicator.stories.tsx +343 -0
  75. package/src/stories/FormatByte.stories.tsx +142 -0
  76. package/src/stories/Input.stories.tsx +94 -0
  77. package/src/stories/InputClearButton.stories.tsx +53 -0
  78. package/src/stories/KeyboardShortcut.stories.tsx +87 -0
  79. package/src/stories/LoadingDots.stories.tsx +73 -0
  80. package/src/stories/MonthPicker.stories.tsx +99 -0
  81. package/src/stories/MultiSelect.stories.tsx +7 -1
  82. package/src/stories/NavLink.stories.tsx +213 -0
  83. package/src/stories/NavigationRail.stories.tsx +413 -0
  84. package/src/stories/Notification.stories.tsx +53 -0
  85. package/src/stories/PasswordInput.stories.tsx +21 -0
  86. package/src/stories/Progress.stories.tsx +38 -0
  87. package/src/stories/Prose.stories.tsx +232 -0
  88. package/src/stories/Questionnaire.stories.tsx +287 -0
  89. package/src/stories/Result.stories.tsx +145 -0
  90. package/src/stories/RollingNumber.stories.tsx +1 -1
  91. package/src/stories/Sidebar.stories.tsx +2 -0
  92. package/src/stories/SimpleGrid.stories.tsx +130 -0
  93. package/src/stories/Skeleton.stories.tsx +62 -1
  94. package/src/stories/Squircle.stories.tsx +127 -0
  95. package/src/stories/Stack.stories.tsx +140 -0
  96. package/src/stories/StatusBadge.stories.tsx +125 -0
  97. package/src/stories/Tabs.stories.tsx +56 -1
  98. package/src/stories/Tag.stories.tsx +31 -0
  99. package/src/stories/Textarea.stories.tsx +2 -0
  100. package/src/stories/ThemeIcon.stories.tsx +97 -0
  101. package/src/stories/Timeline.stories.tsx +69 -0
  102. package/src/stories/Tooltip.stories.tsx +18 -0
  103. package/src/stories/TreeSelect.stories.tsx +222 -0
  104. package/src/stories/YearPicker.stories.tsx +100 -0
  105. package/src/styles.css +289 -15
  106. package/src/tokens.json +96 -1
@@ -14,6 +14,15 @@ type SkeletonProps = React.ComponentProps<"div"> & {
14
14
  * Ignored for other shapes; `<= 1` renders a single text line.
15
15
  */
16
16
  lines?: number
17
+ /**
18
+ * Loading motion. `"pulse"` (default) is the classic opacity pulse,
19
+ * `"wave"` sweeps a highlight left to right (CSS keyed off
20
+ * `data-animation="wave"` in the design-system layer), `false` renders
21
+ * a static block. Peer precedent: MUI `animation="pulse" | "wave" | false`,
22
+ * Mantine `animate`, Ant Design `active`. The base layer's reduced-motion
23
+ * rule stills both animated modes automatically.
24
+ */
25
+ animation?: "pulse" | "wave" | false
17
26
  }
18
27
 
19
28
  const shapeClasses = {
@@ -25,12 +34,31 @@ const shapeClasses = {
25
34
  text: "animate-pulse rounded-md bg-accent h-4 w-full",
26
35
  } as const
27
36
 
37
+ // Same silhouettes minus animate-pulse — used when animation is "wave"
38
+ // (keyframe applied via the data-animation selector in the generated CSS)
39
+ // or false (static block).
40
+ const staticShapeClasses = {
41
+ default: "rounded-md bg-accent",
42
+ circle: "rounded-full bg-accent size-10",
43
+ text: "rounded-md bg-accent h-4 w-full",
44
+ } as const
45
+
28
46
  function Skeleton({
29
47
  className,
30
48
  shape = "default",
31
49
  lines,
50
+ animation = "pulse",
32
51
  ...props
33
52
  }: SkeletonProps) {
53
+ const shapeClass =
54
+ animation === "pulse" ? shapeClasses[shape] : staticShapeClasses[shape]
55
+ // Omitted for the default pulse so a bare <Skeleton /> stays byte-identical
56
+ // to the pre-variant render. The attribute goes on the bg-carrying elements
57
+ // only (never the transparent multi-line wrapper) so the wave gradient
58
+ // can't paint on a bg-less container.
59
+ const dataAnimation =
60
+ animation === "pulse" ? undefined : animation === false ? "none" : "wave"
61
+
34
62
  const lineCount =
35
63
  shape === "text" && typeof lines === "number" && lines >= 2
36
64
  ? Math.floor(lines)
@@ -39,6 +67,7 @@ function Skeleton({
39
67
  if (lineCount) {
40
68
  return (
41
69
  <div
70
+ aria-hidden="true"
42
71
  data-slot="skeleton"
43
72
  data-shape="text"
44
73
  className={cn("flex w-full flex-col gap-2", className)}
@@ -48,7 +77,8 @@ function Skeleton({
48
77
  <div
49
78
  key={i}
50
79
  data-slot="skeleton-line"
51
- className={cn(shapeClasses.text, i === lineCount - 1 && "w-3/5")}
80
+ data-animation={dataAnimation}
81
+ className={cn(shapeClass, i === lineCount - 1 && "w-3/5")}
52
82
  />
53
83
  ))}
54
84
  </div>
@@ -57,14 +87,33 @@ function Skeleton({
57
87
 
58
88
  return (
59
89
  <div
90
+ aria-hidden="true"
60
91
  data-slot="skeleton"
61
92
  // data-shape is omitted for the default shape so a bare <Skeleton />
62
93
  // stays byte-identical to the pre-variant render.
63
94
  data-shape={shape === "default" ? undefined : shape}
64
- className={cn(shapeClasses[shape], className)}
95
+ data-animation={dataAnimation}
96
+ className={cn(shapeClass, className)}
65
97
  {...props}
66
98
  />
67
99
  )
68
100
  }
69
101
 
70
- export { Skeleton }
102
+ type SkeletonRegionProps = React.ComponentProps<"div"> & {
103
+ /** Accessible label announced while content is loading. */
104
+ label?: string
105
+ }
106
+
107
+ function SkeletonRegion({
108
+ label = "Loading…",
109
+ children,
110
+ ...props
111
+ }: SkeletonRegionProps) {
112
+ return (
113
+ <div role="status" aria-label={label} aria-live="polite" {...props}>
114
+ {children}
115
+ </div>
116
+ )
117
+ }
118
+
119
+ export { Skeleton, SkeletonRegion }
@@ -0,0 +1,274 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+
5
+ import { cn } from "../../lib/utils"
6
+
7
+ /* -------------------------------------------------------------------------------------------------
8
+ * Superellipse path math — Figma's corner-smoothing model
9
+ * (public algorithm: https://www.figma.com/blog/desperately-seeking-squircles/).
10
+ * Reimplemented here rather than vendored so BADS owns the source of record.
11
+ *
12
+ * A squircle is a superellipse: the corner is a circular arc whose ends are extended by two Bézier
13
+ * segments that blend the arc tangentially into the straight edges. `smoothing` (0–1) controls how
14
+ * much of the corner is Bézier blend vs pure arc — 0 = an ordinary rounded corner, ~0.6 = the iOS
15
+ * look. The output is a static SVG path fed to `clip-path: path(...)`, which the browser composites
16
+ * like `border-radius` (no per-frame work) and which works identically in every browser.
17
+ * ----------------------------------------------------------------------------------------------- */
18
+
19
+ const toRadians = (deg: number) => (deg * Math.PI) / 180
20
+
21
+ /** Trim float noise so identical sizes produce identical cache keys / paths. */
22
+ const n = (v: number) => Number(v.toFixed(4))
23
+
24
+ const clamp = (v: number, min: number, max: number) => Math.min(max, Math.max(min, v))
25
+
26
+ interface CornerParams {
27
+ a: number
28
+ b: number
29
+ c: number
30
+ d: number
31
+ p: number
32
+ arcSectionLength: number
33
+ radius: number
34
+ }
35
+
36
+ /**
37
+ * Derive the Bézier control offsets (a, b, c, d), the arc chord length, and the corner "reach" p
38
+ * for a single corner. `budget` is the space available along each edge from the corner (normally
39
+ * half the shorter side) — rounding + smoothing are clamped to it so adjacent corners never overlap.
40
+ */
41
+ function getCornerParams(cornerRadius: number, cornerSmoothing: number, budget: number): CornerParams {
42
+ const radius = Math.min(Math.max(0, cornerRadius), budget)
43
+ // Clamp smoothing so (1 + smoothing) * radius still fits the budget — otherwise a large radius
44
+ // with high smoothing would push p past the edge midpoint and self-intersect.
45
+ const maxSmoothing = radius > 0 ? budget / radius - 1 : 0
46
+ const smoothing = clamp(Math.min(cornerSmoothing, maxSmoothing), 0, 1)
47
+ const p = Math.min((1 + smoothing) * radius, budget)
48
+
49
+ const arcMeasure = 90 * (1 - smoothing)
50
+ const arcSectionLength = Math.sin(toRadians(arcMeasure / 2)) * radius * Math.SQRT2
51
+
52
+ const angleAlpha = (90 - arcMeasure) / 2
53
+ const p3ToP4Distance = radius * Math.tan(toRadians(angleAlpha / 2))
54
+
55
+ const angleBeta = 45 * smoothing
56
+ const c = p3ToP4Distance * Math.cos(toRadians(angleBeta))
57
+ const d = c * Math.tan(toRadians(angleBeta))
58
+
59
+ const b = (p - arcSectionLength - c - d) / 3
60
+ const a = 2 * b
61
+
62
+ return { a, b, c, d, p, arcSectionLength, radius }
63
+ }
64
+
65
+ /**
66
+ * Build the full squircle path for a box of `width` × `height` with a uniform `cornerRadius` and
67
+ * `smoothing`, optionally translated by (ox, oy) — the translate is used to draw the inner edge of
68
+ * the optional border. Absolute commands (M, L) carry the offset; the c/a segments are relative.
69
+ */
70
+ function squirclePath(
71
+ width: number,
72
+ height: number,
73
+ cornerRadius: number,
74
+ smoothing: number,
75
+ ox = 0,
76
+ oy = 0,
77
+ ): string {
78
+ const budget = Math.max(0, Math.min(width, height) / 2)
79
+ const { a, b, c, d, p, arcSectionLength, radius } = getCornerParams(cornerRadius, smoothing, budget)
80
+
81
+ // No radius → plain rectangle (still respects the offset for the border's inner path).
82
+ if (radius <= 0) {
83
+ return [
84
+ `M ${n(ox)} ${n(oy)}`,
85
+ `L ${n(ox + width)} ${n(oy)}`,
86
+ `L ${n(ox + width)} ${n(oy + height)}`,
87
+ `L ${n(ox)} ${n(oy + height)}`,
88
+ `Z`,
89
+ ].join(" ")
90
+ }
91
+
92
+ return [
93
+ `M ${n(ox + width - p)} ${n(oy)}`,
94
+ // top-right corner
95
+ `c ${n(a)} 0 ${n(a + b)} 0 ${n(a + b + c)} ${n(d)}`,
96
+ `a ${n(radius)} ${n(radius)} 0 0 1 ${n(arcSectionLength)} ${n(arcSectionLength)}`,
97
+ `c ${n(d)} ${n(c)} ${n(d)} ${n(b + c)} ${n(d)} ${n(a + b + c)}`,
98
+ `L ${n(ox + width)} ${n(oy + height - p)}`,
99
+ // bottom-right corner
100
+ `c 0 ${n(a)} 0 ${n(a + b)} ${n(-d)} ${n(a + b + c)}`,
101
+ `a ${n(radius)} ${n(radius)} 0 0 1 ${n(-arcSectionLength)} ${n(arcSectionLength)}`,
102
+ `c ${n(-c)} ${n(d)} ${n(-(b + c))} ${n(d)} ${n(-(a + b + c))} ${n(d)}`,
103
+ `L ${n(ox + p)} ${n(oy + height)}`,
104
+ // bottom-left corner
105
+ `c ${n(-a)} 0 ${n(-(a + b))} 0 ${n(-(a + b + c))} ${n(-d)}`,
106
+ `a ${n(radius)} ${n(radius)} 0 0 1 ${n(-arcSectionLength)} ${n(-arcSectionLength)}`,
107
+ `c ${n(-d)} ${n(-c)} ${n(-d)} ${n(-(b + c))} ${n(-d)} ${n(-(a + b + c))}`,
108
+ `L ${n(ox)} ${n(oy + p)}`,
109
+ // top-left corner
110
+ `c 0 ${n(-a)} 0 ${n(-(a + b))} ${n(d)} ${n(-(a + b + c))}`,
111
+ `a ${n(radius)} ${n(radius)} 0 0 1 ${n(arcSectionLength)} ${n(-arcSectionLength)}`,
112
+ `c ${n(c)} ${n(-d)} ${n(b + c)} ${n(-d)} ${n(a + b + c)} ${n(-d)}`,
113
+ `Z`,
114
+ ].join(" ")
115
+ }
116
+
117
+ /* -------------------------------------------------------------------------------------------------
118
+ * Token resolution helpers — the primitive reads its defaults off the live CSS custom properties so
119
+ * a Squircle tracks the same `--radius` every `rounded-*` uses (and the Customize-tab radius control).
120
+ * ----------------------------------------------------------------------------------------------- */
121
+
122
+ function cssLengthToPx(raw: string, el: Element): number {
123
+ const value = raw.trim()
124
+ if (!value) return 0
125
+ if (value.endsWith("px")) return parseFloat(value) || 0
126
+ if (value.endsWith("rem")) {
127
+ const rootFontSize =
128
+ parseFloat(getComputedStyle(el.ownerDocument.documentElement).fontSize) || 16
129
+ return (parseFloat(value) || 0) * rootFontSize
130
+ }
131
+ const num = parseFloat(value)
132
+ return Number.isFinite(num) ? num : 0
133
+ }
134
+
135
+ /** Merge a forwarded ref with the internal measuring ref. */
136
+ function useMergedRef<T>(external: React.Ref<T> | undefined) {
137
+ const internal = React.useRef<T | null>(null)
138
+ const callback = React.useCallback(
139
+ (node: T | null) => {
140
+ internal.current = node
141
+ if (typeof external === "function") external(node)
142
+ else if (external) (external as React.MutableRefObject<T | null>).current = node
143
+ },
144
+ [external],
145
+ )
146
+ return [internal, callback] as const
147
+ }
148
+
149
+ /* -------------------------------------------------------------------------------------------------
150
+ * Squircle
151
+ * ----------------------------------------------------------------------------------------------- */
152
+
153
+ type SquircleOwnProps = {
154
+ /**
155
+ * Corner radius in px. Omit to inherit the live `--radius` token (so a Squircle reads at the same
156
+ * corner radius as every `rounded-*` box — only the curve differs). When `radius ≥ min(w,h)/2` the
157
+ * shape becomes a capsule automatically.
158
+ */
159
+ radius?: number
160
+ /**
161
+ * Superellipse smoothing, 0–1. Omit to inherit `--corner-smoothing` (≈0.6, iOS-like). `0` renders
162
+ * pixel-identical to an ordinary rounded corner — the proof that Squircle re-curves the radius
163
+ * scale rather than competing with it.
164
+ */
165
+ smoothing?: number
166
+ /** Polymorphic host element/component. Defaults to `"div"`. Use `as={motion.div}`, `as="a"`, etc. */
167
+ as?: React.ElementType
168
+ /** Optional border that follows the squircle edge (drawn via an even-odd clipped overlay). */
169
+ borderWidth?: number
170
+ /** Border color — a token by default. Only used when `borderWidth > 0`. */
171
+ borderColor?: string
172
+ }
173
+
174
+ export type SquircleProps = SquircleOwnProps &
175
+ Omit<React.HTMLAttributes<HTMLElement>, keyof SquircleOwnProps> & {
176
+ ref?: React.Ref<HTMLElement>
177
+ children?: React.ReactNode
178
+ }
179
+
180
+ function Squircle({
181
+ radius,
182
+ smoothing,
183
+ as,
184
+ borderWidth = 0,
185
+ borderColor = "var(--border)",
186
+ className,
187
+ style,
188
+ children,
189
+ ref,
190
+ ...rest
191
+ }: SquircleProps) {
192
+ const Comp = (as ?? "div") as React.ElementType
193
+ const [measureRef, setRef] = useMergedRef<HTMLElement>(ref)
194
+ const [path, setPath] = React.useState<string | null>(null)
195
+ const [borderClip, setBorderClip] = React.useState<string | null>(null)
196
+
197
+ React.useEffect(() => {
198
+ const el = measureRef.current
199
+ if (!el) return
200
+ // Resolve the correct window from the node — BADS surfaces render inside preview iframes and
201
+ // portals, where the bare global `window`/`ResizeObserver` is the wrong one (build-spec §2).
202
+ const win = el.ownerDocument.defaultView ?? window
203
+
204
+ const compute = () => {
205
+ // borderBoxSize floats keep sub-pixel precision during size transitions; fall back to offset*.
206
+ const width = el.offsetWidth
207
+ const height = el.offsetHeight
208
+ if (width <= 0 || height <= 0) return
209
+
210
+ const styles = win.getComputedStyle(el)
211
+ const resolvedRadius =
212
+ typeof radius === "number"
213
+ ? radius
214
+ : cssLengthToPx(styles.getPropertyValue("--radius"), el)
215
+ const resolvedSmoothing =
216
+ typeof smoothing === "number"
217
+ ? smoothing
218
+ : (() => {
219
+ const raw = parseFloat(styles.getPropertyValue("--corner-smoothing"))
220
+ return Number.isFinite(raw) ? raw : 0.6
221
+ })()
222
+
223
+ const r = Math.max(0, resolvedRadius)
224
+ const s = clamp(resolvedSmoothing, 0, 1)
225
+
226
+ setPath(squirclePath(width, height, r, s))
227
+
228
+ if (borderWidth > 0) {
229
+ const inner = squirclePath(
230
+ Math.max(0, width - borderWidth * 2),
231
+ Math.max(0, height - borderWidth * 2),
232
+ Math.max(0, r - borderWidth),
233
+ s,
234
+ borderWidth,
235
+ borderWidth,
236
+ )
237
+ const outer = squirclePath(width, height, r, s)
238
+ // evenodd: paint only the ring between the outer squircle and the inset inner squircle.
239
+ setBorderClip(`path(evenodd, "${outer} ${inner}")`)
240
+ } else {
241
+ setBorderClip(null)
242
+ }
243
+ }
244
+
245
+ compute()
246
+ const ro = new win.ResizeObserver(compute)
247
+ ro.observe(el)
248
+ return () => ro.disconnect()
249
+ }, [radius, smoothing, borderWidth, measureRef])
250
+
251
+ return (
252
+ <Comp
253
+ ref={setRef}
254
+ data-slot="squircle"
255
+ // `relative` anchors the optional border overlay; `overflow: visible` (default) is required so
256
+ // the clip doesn't fight the border — content needing `overflow: hidden` wraps an inner box.
257
+ className={cn("relative", className)}
258
+ style={path ? { clipPath: `path("${path}")`, ...style } : style}
259
+ {...rest}
260
+ >
261
+ {children}
262
+ {borderWidth > 0 && borderClip ? (
263
+ <span
264
+ aria-hidden="true"
265
+ data-slot="squircle-border"
266
+ className="pointer-events-none absolute inset-0"
267
+ style={{ clipPath: borderClip, backgroundColor: borderColor }}
268
+ />
269
+ ) : null}
270
+ </Comp>
271
+ )
272
+ }
273
+
274
+ export { Squircle }
@@ -0,0 +1,105 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import { cva, type VariantProps } from "class-variance-authority";
5
+ import { cn } from "../../lib/utils";
6
+
7
+ // ─── Shared variants ──────────────────────────────────────────────────────────
8
+
9
+ const layoutVariants = cva("flex", {
10
+ variants: {
11
+ /**
12
+ * Gap between child elements. Maps to Tailwind gap utilities keyed to the
13
+ * BADS spacing scale (gap-0 / 1 / 2 / 4 / 6 / 8 → 0 / 4px / 8px / 16px /
14
+ * 24px / 32px). Default: "md" for Stack, "sm" for Group.
15
+ */
16
+ gap: {
17
+ none: "gap-0",
18
+ xs: "gap-1",
19
+ sm: "gap-2",
20
+ md: "gap-4",
21
+ lg: "gap-6",
22
+ xl: "gap-8",
23
+ },
24
+ /**
25
+ * Cross-axis alignment (align-items). Default: "stretch" for Stack so
26
+ * children fill the container width; "center" for Group so inline items
27
+ * baseline-align naturally.
28
+ */
29
+ align: {
30
+ start: "items-start",
31
+ center: "items-center",
32
+ end: "items-end",
33
+ baseline: "items-baseline",
34
+ stretch: "items-stretch",
35
+ },
36
+ /**
37
+ * Main-axis distribution (justify-content).
38
+ */
39
+ justify: {
40
+ start: "justify-start",
41
+ center: "justify-center",
42
+ end: "justify-end",
43
+ between: "justify-between",
44
+ around: "justify-around",
45
+ evenly: "justify-evenly",
46
+ },
47
+ },
48
+ defaultVariants: {
49
+ gap: "md",
50
+ align: "stretch",
51
+ justify: "start",
52
+ },
53
+ });
54
+
55
+ // ─── Stack ─────────────────────────────────────────────────────────────────────
56
+ //
57
+ // Vertical flex column. Replaces boilerplate `<div className="flex flex-col gap-4">`.
58
+ // Children fill the container width by default (align="stretch").
59
+
60
+ export interface StackProps
61
+ extends React.HTMLAttributes<HTMLDivElement>,
62
+ VariantProps<typeof layoutVariants> {}
63
+
64
+ export const Stack = React.forwardRef<HTMLDivElement, StackProps>(
65
+ ({ className, gap, align, justify, ...props }, ref) => (
66
+ <div
67
+ ref={ref}
68
+ data-slot="stack"
69
+ className={cn("flex flex-col", layoutVariants({ gap, align, justify }), className)}
70
+ {...props}
71
+ />
72
+ )
73
+ );
74
+ Stack.displayName = "Stack";
75
+
76
+ // ─── Group ─────────────────────────────────────────────────────────────────────
77
+ //
78
+ // Horizontal flex row. Replaces boilerplate `<div className="flex flex-row flex-wrap gap-2 items-center">`.
79
+ // Items wrap by default; set wrap={false} for a strict single-line row.
80
+ // align defaults to "center" so inline items (tags, buttons, icons) sit on the
81
+ // same baseline without extra class wiring.
82
+
83
+ export interface GroupProps
84
+ extends React.HTMLAttributes<HTMLDivElement>,
85
+ VariantProps<typeof layoutVariants> {
86
+ /** Wrap items when the container is full. Default: true. */
87
+ wrap?: boolean;
88
+ }
89
+
90
+ export const Group = React.forwardRef<HTMLDivElement, GroupProps>(
91
+ ({ className, gap = "sm", align = "center", justify, wrap = true, ...props }, ref) => (
92
+ <div
93
+ ref={ref}
94
+ data-slot="group"
95
+ className={cn(
96
+ "flex flex-row",
97
+ wrap ? "flex-wrap" : "flex-nowrap",
98
+ layoutVariants({ gap, align, justify }),
99
+ className
100
+ )}
101
+ {...props}
102
+ />
103
+ )
104
+ );
105
+ Group.displayName = "Group";
@@ -0,0 +1,93 @@
1
+ import * as React from "react"
2
+
3
+ import { cn } from "../../lib/utils"
4
+
5
+ type StatusVariant =
6
+ | "active"
7
+ | "pending"
8
+ | "processing"
9
+ | "error"
10
+ | "offline"
11
+ | "warning"
12
+
13
+ const STATUS_LABELS: Record<StatusVariant, string> = {
14
+ active: "Active",
15
+ pending: "Pending",
16
+ processing: "Processing",
17
+ error: "Error",
18
+ offline: "Offline",
19
+ warning: "Warning",
20
+ }
21
+
22
+ // Dot color maps directly to semantic tokens. Text stays text-foreground so
23
+ // the 7:1 AAA floor is unconditional — the dot is the non-text signal (3:1).
24
+ const DOT_COLORS: Record<StatusVariant, string> = {
25
+ active: "bg-success",
26
+ pending: "bg-warning",
27
+ processing: "bg-info",
28
+ error: "bg-destructive",
29
+ offline: "bg-muted-foreground",
30
+ warning: "bg-warning",
31
+ }
32
+
33
+ const DOT_SIZES = {
34
+ sm: "size-1.5",
35
+ default: "size-2",
36
+ lg: "size-2.5",
37
+ } as const
38
+
39
+ const TEXT_SIZES = {
40
+ sm: "text-xs",
41
+ default: "text-sm",
42
+ lg: "text-base",
43
+ } as const
44
+
45
+ type StatusBadgeProps = React.ComponentProps<"span"> & {
46
+ /** The semantic status — drives dot color and default label. */
47
+ status: StatusVariant
48
+ /** Override the default capitalized status name. */
49
+ label?: string
50
+ /** Scales dot and text together. */
51
+ size?: "sm" | "default" | "lg"
52
+ }
53
+
54
+ function StatusBadge({
55
+ className,
56
+ status,
57
+ label,
58
+ size = "default",
59
+ ...props
60
+ }: StatusBadgeProps) {
61
+ const displayLabel = label ?? STATUS_LABELS[status]
62
+
63
+ return (
64
+ <span
65
+ data-slot="status-badge"
66
+ data-status={status}
67
+ className={cn(
68
+ "inline-flex items-center gap-1.5 font-medium",
69
+ TEXT_SIZES[size],
70
+ className
71
+ )}
72
+ {...props}
73
+ >
74
+ {/* aria-hidden: dot color is non-text signal only; the label carries a11y meaning */}
75
+ <span
76
+ aria-hidden
77
+ data-slot="status-dot"
78
+ className={cn(
79
+ "shrink-0 rounded-full",
80
+ DOT_SIZES[size],
81
+ DOT_COLORS[status],
82
+ // processing: pulsing dot signals in-flight work. The base layer's
83
+ // prefers-reduced-motion rule stills it automatically.
84
+ status === "processing" && "animate-pulse"
85
+ )}
86
+ />
87
+ {displayLabel}
88
+ </span>
89
+ )
90
+ }
91
+
92
+ export { StatusBadge }
93
+ export type { StatusVariant }
@@ -28,12 +28,15 @@ function Tabs({
28
28
  }
29
29
 
30
30
  const tabsListVariants = cva(
31
- "group/tabs-list inline-flex h-10 w-fit items-center justify-center rounded-md p-1 text-muted-foreground group-data-[orientation=vertical]/tabs:h-fit group-data-[orientation=vertical]/tabs:flex-col data-[variant=line]:rounded-none",
31
+ "group/tabs-list inline-flex h-10 w-fit items-center justify-center rounded-md p-1 text-muted-foreground group-data-[orientation=vertical]/tabs:h-fit group-data-[orientation=vertical]/tabs:flex-col data-[variant=line]:rounded-none data-[variant=pill]:rounded-none data-[variant=pill]:p-0",
32
32
  {
33
33
  variants: {
34
34
  variant: {
35
35
  default: "bg-muted",
36
36
  line: "gap-1 bg-transparent",
37
+ // Each trigger is an independently-shaped pill; the list is just
38
+ // a flex row with a gap — no shared container background.
39
+ pill: "gap-1.5 bg-transparent",
37
40
  },
38
41
  },
39
42
  defaultVariants: {
@@ -73,11 +76,30 @@ function TabsList({
73
76
  el.scrollLeft + el.clientWidth < el.scrollWidth - 1
74
77
  el.toggleAttribute("data-overflowing", overflowing)
75
78
  }
76
- // Keep the active trigger visible when the selection changes.
79
+ // Keep the active trigger visible when the selection changes — but scroll
80
+ // ONLY this list's own horizontal overflow, never Element.scrollIntoView.
81
+ // scrollIntoView also scrolls vertical ancestors (the whole page) to bring
82
+ // the trigger into the viewport, so a scrollable tab row below the fold
83
+ // yanks the entire page down to itself on mount (corrections.md #012, the
84
+ // "Tabs & Dialog" recurrence). Same rule the Carousel documents. We nudge
85
+ // el.scrollLeft directly, which can only move this row horizontally.
77
86
  const scrollActiveIntoView = () => {
78
- el
79
- .querySelector<HTMLElement>('[data-slot="tabs-trigger"][data-state="active"]')
80
- ?.scrollIntoView({ inline: "nearest", block: "nearest", behavior: "smooth" })
87
+ const active = el.querySelector<HTMLElement>(
88
+ '[data-slot="tabs-trigger"][data-state="active"]'
89
+ )
90
+ if (!active) return
91
+ const pad = 16
92
+ const viewLeft = el.scrollLeft
93
+ const viewRight = viewLeft + el.clientWidth
94
+ const aLeft = active.offsetLeft
95
+ const aRight = aLeft + active.offsetWidth
96
+ let next = viewLeft
97
+ if (aLeft < viewLeft + pad) next = aLeft - pad
98
+ else if (aRight > viewRight - pad) next = aRight - el.clientWidth + pad
99
+ next = Math.max(0, Math.min(next, el.scrollWidth - el.clientWidth))
100
+ if (Math.abs(next - viewLeft) > 1) {
101
+ el.scrollTo({ left: next, behavior: "smooth" })
102
+ }
81
103
  }
82
104
 
83
105
  update()
@@ -125,7 +147,12 @@ function TabsTrigger({
125
147
  // Active state uses --primary / --primary-foreground so the selected tab
126
148
  // always reflects the fork's brand color. bg-accent broke forks where
127
149
  // --accent is a dark brand color (e.g. plum), rendering the pill illegibly dark.
128
- "inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-xs font-medium text-muted-foreground hover:text-foreground ring-offset-background transition-colors focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-primary data-[state=active]:text-primary-foreground data-[state=active]:shadow-xs",
150
+ // Base layout and interactive states shared across all variants.
151
+ // `group-data-[variant=pill]/tabs-list:*` overrides shape + active
152
+ // coloring when the parent TabsList is in pill mode: rounded-full
153
+ // container with a softer brand tint (bg-primary/10 text-primary)
154
+ // instead of the solid filled slab of the default variant.
155
+ "inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-xs font-medium text-muted-foreground hover:text-foreground ring-offset-background transition-colors focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-primary data-[state=active]:text-primary-foreground data-[state=active]:shadow-xs group-data-[variant=pill]/tabs-list:rounded-full group-data-[variant=pill]/tabs-list:px-4 group-data-[variant=pill]/tabs-list:data-[state=active]:shadow-none group-data-[variant=pill]/tabs-list:data-[state=active]:bg-primary/10 group-data-[variant=pill]/tabs-list:data-[state=active]:text-primary",
129
156
  className
130
157
  )}
131
158
  {...props}
@@ -140,7 +167,7 @@ function TabsContent({
140
167
  return (
141
168
  <TabsPrimitive.Content
142
169
  data-slot="tabs-content"
143
- className={cn("mt-2 ring-offset-background focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2", className)}
170
+ className={cn("mt-2 ring-offset-background focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 scrollbar-gutter-stable", className)}
144
171
  {...props}
145
172
  />
146
173
  )