@behavioral-agentic-design-system/core 0.27.0 → 0.29.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 (113) hide show
  1. package/package.json +5 -5
  2. package/scripts/a11y-lint.cjs +78 -9
  3. package/scripts/build-tokens.cjs +273 -15
  4. package/scripts/wcag-audit.cjs +37 -7
  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 +5735 -2500
  9. package/src/app/preview/layout.tsx +4 -1
  10. package/src/app/preview/showcase-filter.tsx +66 -0
  11. package/src/app/preview/tab-replay.tsx +63 -0
  12. package/src/app/shell.tsx +91 -18
  13. package/src/components/customize/save-bar.tsx +19 -6
  14. package/src/components/docs-tab.tsx +36 -24
  15. package/src/components/layers-tab.tsx +37 -5
  16. package/src/components/ui/ai-badge.tsx +74 -0
  17. package/src/components/ui/alert.tsx +12 -0
  18. package/src/components/ui/badge.tsx +19 -0
  19. package/src/components/ui/chat-bubble.tsx +298 -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/clipboard.tsx +291 -0
  23. package/src/components/ui/close-button.tsx +71 -0
  24. package/src/components/ui/combobox.tsx +62 -3
  25. package/src/components/ui/container.tsx +65 -0
  26. package/src/components/ui/copy-button.tsx +5 -1
  27. package/src/components/ui/data-table.tsx +388 -0
  28. package/src/components/ui/date-field.tsx +368 -0
  29. package/src/components/ui/drawer.tsx +334 -0
  30. package/src/components/ui/file-button.tsx +145 -0
  31. package/src/components/ui/floating-indicator.tsx +217 -0
  32. package/src/components/ui/focus-trap.tsx +184 -0
  33. package/src/components/ui/format-byte.tsx +113 -0
  34. package/src/components/ui/index.ts +28 -0
  35. package/src/components/ui/input.tsx +38 -3
  36. package/src/components/ui/keyboard-shortcut.tsx +146 -0
  37. package/src/components/ui/loading-dots.tsx +99 -0
  38. package/src/components/ui/mark.tsx +69 -0
  39. package/src/components/ui/month-picker.tsx +296 -0
  40. package/src/components/ui/multi-select.tsx +15 -13
  41. package/src/components/ui/nav-link.tsx +200 -0
  42. package/src/components/ui/navigation-rail.tsx +256 -0
  43. package/src/components/ui/notification.tsx +20 -0
  44. package/src/components/ui/password-input.tsx +34 -1
  45. package/src/components/ui/progress.tsx +15 -1
  46. package/src/components/ui/prose.tsx +62 -0
  47. package/src/components/ui/result.tsx +151 -0
  48. package/src/components/ui/rolling-number.tsx +201 -0
  49. package/src/components/ui/simple-grid.tsx +110 -0
  50. package/src/components/ui/skeleton.tsx +52 -3
  51. package/src/components/ui/squircle.tsx +274 -0
  52. package/src/components/ui/stack.tsx +105 -0
  53. package/src/components/ui/status-badge.tsx +93 -0
  54. package/src/components/ui/tabs.tsx +34 -7
  55. package/src/components/ui/tag.tsx +46 -5
  56. package/src/components/ui/theme-icon.tsx +138 -0
  57. package/src/components/ui/timeline.tsx +27 -10
  58. package/src/components/ui/tooltip.tsx +12 -1
  59. package/src/components/ui/tree-select.tsx +386 -0
  60. package/src/components/ui/typing-indicator.tsx +2 -2
  61. package/src/components/ui/word-rotate.tsx +6 -1
  62. package/src/components/ui/year-picker.tsx +307 -0
  63. package/src/data/docs-index.ts +10 -0
  64. package/src/hooks/use-global-primary-color.ts +57 -6
  65. package/src/stories/AiBadge.stories.tsx +67 -0
  66. package/src/stories/Alert.stories.tsx +31 -1
  67. package/src/stories/Badge.stories.tsx +63 -6
  68. package/src/stories/ChatBubble.stories.tsx +222 -0
  69. package/src/stories/ChatMarker.stories.tsx +59 -0
  70. package/src/stories/Checkbox.stories.tsx +5 -0
  71. package/src/stories/Clipboard.stories.tsx +136 -0
  72. package/src/stories/CloseButton.stories.tsx +65 -0
  73. package/src/stories/Combobox.stories.tsx +74 -3
  74. package/src/stories/Container.stories.tsx +134 -0
  75. package/src/stories/CopyButton.stories.tsx +2 -0
  76. package/src/stories/DataTable.stories.tsx +271 -0
  77. package/src/stories/DateField.stories.tsx +114 -0
  78. package/src/stories/Drawer.stories.tsx +211 -0
  79. package/src/stories/FileButton.stories.tsx +117 -0
  80. package/src/stories/FloatingIndicator.stories.tsx +343 -0
  81. package/src/stories/FocusTrap.stories.tsx +218 -0
  82. package/src/stories/FormatByte.stories.tsx +142 -0
  83. package/src/stories/Input.stories.tsx +91 -0
  84. package/src/stories/KeyboardShortcut.stories.tsx +87 -0
  85. package/src/stories/LoadingDots.stories.tsx +73 -0
  86. package/src/stories/Mark.stories.tsx +84 -0
  87. package/src/stories/MonthPicker.stories.tsx +99 -0
  88. package/src/stories/MultiSelect.stories.tsx +3 -1
  89. package/src/stories/NavLink.stories.tsx +213 -0
  90. package/src/stories/NavigationRail.stories.tsx +413 -0
  91. package/src/stories/Notification.stories.tsx +53 -0
  92. package/src/stories/PasswordInput.stories.tsx +21 -0
  93. package/src/stories/Progress.stories.tsx +38 -0
  94. package/src/stories/Prose.stories.tsx +232 -0
  95. package/src/stories/Result.stories.tsx +145 -0
  96. package/src/stories/RollingNumber.stories.tsx +226 -0
  97. package/src/stories/SimpleGrid.stories.tsx +130 -0
  98. package/src/stories/Skeleton.stories.tsx +62 -1
  99. package/src/stories/Squircle.stories.tsx +127 -0
  100. package/src/stories/Stack.stories.tsx +139 -0
  101. package/src/stories/StatusBadge.stories.tsx +125 -0
  102. package/src/stories/Tabs.stories.tsx +56 -1
  103. package/src/stories/Tag.stories.tsx +31 -0
  104. package/src/stories/ThemeIcon.stories.tsx +97 -0
  105. package/src/stories/Timeline.stories.tsx +69 -0
  106. package/src/stories/Tooltip.stories.tsx +18 -0
  107. package/src/stories/TreeSelect.stories.tsx +222 -0
  108. package/src/stories/TypingIndicator.stories.tsx +1 -0
  109. package/src/stories/WordRotate.stories.tsx +1 -0
  110. package/src/stories/YearPicker.stories.tsx +100 -0
  111. package/src/styles.css +289 -15
  112. package/src/tokens.json +96 -1
  113. package/LICENSE +0 -21
@@ -0,0 +1,256 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import { cn } from "../../lib/utils";
5
+
6
+ // ─── Context ──────────────────────────────────────────────────────────────────
7
+
8
+ interface NavigationRailContextValue {
9
+ value: string;
10
+ onValueChange: (value: string) => void;
11
+ expanded: boolean;
12
+ }
13
+
14
+ const NavigationRailContext = React.createContext<NavigationRailContextValue>({
15
+ value: "",
16
+ onValueChange: () => {},
17
+ expanded: false,
18
+ });
19
+
20
+ // ─── Root ─────────────────────────────────────────────────────────────────────
21
+
22
+ export interface NavigationRailProps
23
+ extends Omit<React.HTMLAttributes<HTMLElement>, "onChange"> {
24
+ /** The value of the currently active destination (controlled). */
25
+ value?: string;
26
+ /** Initial active destination (uncontrolled). */
27
+ defaultValue?: string;
28
+ /** Callback fired when the user activates a destination. */
29
+ onValueChange?: (value: string) => void;
30
+ /**
31
+ * Expanded layout: icon beside label in a wider rail. Compact (default)
32
+ * stacks the label under the icon in an 80px strip.
33
+ */
34
+ expanded?: boolean;
35
+ /**
36
+ * Accessible label for the navigation landmark. Keeps multiple nav
37
+ * landmarks on a page distinguishable to screen readers.
38
+ */
39
+ label?: string;
40
+ }
41
+
42
+ /**
43
+ * Narrow vertical navigation rail — a `<nav>` landmark holding icon+label
44
+ * destination buttons, one of which is current. The vertical partner of
45
+ * BottomNavigation for desktop and tablet app shells (the Material Design
46
+ * "navigation rail" pattern).
47
+ *
48
+ * NOT a tablist: it navigates between top-level destinations
49
+ * (`aria-current="page"` on the active item), it does not switch visible
50
+ * content panels in place. For in-place switching use Tabs; for a wide
51
+ * collapsible navigation panel with groups, use Sidebar.
52
+ */
53
+ export function NavigationRail({
54
+ value: valueProp,
55
+ defaultValue,
56
+ onValueChange,
57
+ expanded = false,
58
+ label = "Primary navigation",
59
+ className,
60
+ children,
61
+ ...props
62
+ }: NavigationRailProps) {
63
+ const [internalValue, setInternalValue] = React.useState(defaultValue ?? "");
64
+ const value = valueProp ?? internalValue;
65
+
66
+ const handleValueChange = React.useCallback(
67
+ (next: string) => {
68
+ setInternalValue(next);
69
+ onValueChange?.(next);
70
+ },
71
+ [onValueChange]
72
+ );
73
+
74
+ return (
75
+ <NavigationRailContext.Provider
76
+ value={{ value, onValueChange: handleValueChange, expanded }}
77
+ >
78
+ <nav
79
+ aria-label={label}
80
+ data-slot="navigation-rail"
81
+ data-orientation="vertical"
82
+ data-expanded={expanded ? "true" : "false"}
83
+ className={cn(
84
+ "flex h-full flex-col items-stretch gap-1 border-r border-border bg-background px-1.5 py-3",
85
+ // Compact rail is 80px (the Material/desktop convention) — a 56px
86
+ // strip couldn't fit even short 4–5 char labels ("Home", "Setup"),
87
+ // truncating every one to an ellipsis. 80px leaves ~60px usable so
88
+ // typical rail labels render in full; `truncate` on the label stays
89
+ // as graceful fallback for anything genuinely long. (corrections.md)
90
+ expanded ? "w-52" : "w-20",
91
+ className
92
+ )}
93
+ {...props}
94
+ >
95
+ {children}
96
+ </nav>
97
+ </NavigationRailContext.Provider>
98
+ );
99
+ }
100
+
101
+ // ─── Header ───────────────────────────────────────────────────────────────────
102
+
103
+ export type NavigationRailHeaderProps = React.HTMLAttributes<HTMLDivElement>;
104
+
105
+ /** Optional slot above the destination items — logo, wordmark, menu toggle. */
106
+ export function NavigationRailHeader({
107
+ className,
108
+ children,
109
+ ...props
110
+ }: NavigationRailHeaderProps) {
111
+ const { expanded } = React.useContext(NavigationRailContext);
112
+ return (
113
+ <div
114
+ data-slot="navigation-rail-header"
115
+ className={cn(
116
+ "flex min-w-0 items-center gap-3 pb-2",
117
+ expanded ? "justify-start px-3" : "justify-center px-1",
118
+ className
119
+ )}
120
+ >
121
+ {children}
122
+ </div>
123
+ );
124
+ }
125
+
126
+ // ─── Footer ───────────────────────────────────────────────────────────────────
127
+
128
+ export type NavigationRailFooterProps = React.HTMLAttributes<HTMLDivElement>;
129
+
130
+ /**
131
+ * Optional slot below the destination items — settings, help, profile.
132
+ * Pushed to the rail's bottom edge; put secondary NavigationRailItems here.
133
+ */
134
+ export function NavigationRailFooter({
135
+ className,
136
+ children,
137
+ ...props
138
+ }: NavigationRailFooterProps) {
139
+ return (
140
+ <div
141
+ data-slot="navigation-rail-footer"
142
+ className={cn("mt-auto flex flex-col items-stretch gap-1 pt-2", className)}
143
+ {...props}
144
+ >
145
+ {children}
146
+ </div>
147
+ );
148
+ }
149
+
150
+ // ─── Item ─────────────────────────────────────────────────────────────────────
151
+
152
+ export interface NavigationRailItemProps
153
+ extends React.ButtonHTMLAttributes<HTMLButtonElement> {
154
+ /** The destination value this item represents. */
155
+ value: string;
156
+ /** Icon for the destination. Must be a Lucide icon with strokeWidth={1.5}. */
157
+ icon: React.ReactNode;
158
+ /** Visible text label. Always shown — hiding labels hurts comprehension. */
159
+ label: string;
160
+ /** Optional count badge overlaid on the icon (unread counts, alerts). */
161
+ badge?: string | number;
162
+ /**
163
+ * Screen-reader label for the badge. Defaults to "<badge> notifications" —
164
+ * override when the count means something else ("3 unread messages").
165
+ */
166
+ badgeLabel?: string;
167
+ }
168
+
169
+ export function NavigationRailItem({
170
+ value,
171
+ icon,
172
+ label,
173
+ badge,
174
+ badgeLabel,
175
+ className,
176
+ disabled,
177
+ onClick,
178
+ ...props
179
+ }: NavigationRailItemProps) {
180
+ const {
181
+ value: activeValue,
182
+ onValueChange,
183
+ expanded,
184
+ } = React.useContext(NavigationRailContext);
185
+ const isActive = activeValue === value;
186
+
187
+ return (
188
+ <button
189
+ type="button"
190
+ aria-current={isActive ? "page" : undefined}
191
+ data-slot="navigation-rail-item"
192
+ data-state={isActive ? "active" : "inactive"}
193
+ disabled={disabled}
194
+ onClick={(event) => {
195
+ onClick?.(event);
196
+ if (!event.defaultPrevented && !disabled) onValueChange(value);
197
+ }}
198
+ className={cn(
199
+ "group flex min-h-[44px] w-full cursor-pointer select-none rounded-lg",
200
+ expanded
201
+ ? "flex-row items-center justify-start gap-3 px-3 py-2.5"
202
+ : "flex-col items-center justify-center gap-0.5 px-1 py-1.5",
203
+ "text-muted-foreground transition-colors",
204
+ "hover:bg-accent/60 hover:text-foreground",
205
+ "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
206
+ "disabled:pointer-events-none disabled:opacity-50",
207
+ "data-[state=active]:bg-accent data-[state=active]:text-accent-foreground",
208
+ className
209
+ )}
210
+ style={{
211
+ transitionDuration: "var(--duration-fast)",
212
+ transitionTimingFunction: "var(--ease-out)",
213
+ }}
214
+ {...props}
215
+ >
216
+ <span
217
+ data-slot="navigation-rail-icon"
218
+ className={cn(
219
+ "relative shrink-0 transition-transform",
220
+ !expanded && "group-data-[state=active]:-translate-y-0.5"
221
+ )}
222
+ style={{
223
+ transitionDuration: "var(--duration-base)",
224
+ transitionTimingFunction: "var(--ease-spring)",
225
+ }}
226
+ >
227
+ <span aria-hidden="true" className="block [&>svg]:size-5 [&>svg]:stroke-[1.5]">
228
+ {icon}
229
+ </span>
230
+ {badge !== undefined && (
231
+ <>
232
+ <span
233
+ aria-hidden="true"
234
+ data-slot="navigation-rail-badge"
235
+ className="absolute -right-2.5 -top-2 flex h-5 min-w-5 items-center justify-center rounded-full bg-primary px-1 text-xs font-medium leading-none text-primary-foreground"
236
+ >
237
+ {badge}
238
+ </span>
239
+ <span className="sr-only">
240
+ {badgeLabel ?? `${badge} notifications`}
241
+ </span>
242
+ </>
243
+ )}
244
+ </span>
245
+ <span
246
+ data-slot="navigation-rail-label"
247
+ className={cn(
248
+ "min-w-0 max-w-full truncate font-medium group-data-[state=active]:font-semibold",
249
+ expanded ? "text-sm" : "text-xs"
250
+ )}
251
+ >
252
+ {label}
253
+ </span>
254
+ </button>
255
+ );
256
+ }
@@ -53,6 +53,13 @@ type NotificationProps = Omit<React.ComponentProps<"div">, "title"> &
53
53
  icon?: React.ReactNode
54
54
  /** Meta line, e.g. "2 min ago" / "Just now". */
55
55
  timestamp?: React.ReactNode
56
+ /**
57
+ * Inline action buttons rendered below the description/timestamp,
58
+ * inside the content column — typically 1–2 `<Button size="sm">`.
59
+ * DOM order keeps these BEFORE the built-in dismiss button, so
60
+ * keyboard users reach the meaningful actions first.
61
+ */
62
+ actions?: React.ReactNode
56
63
  /** Marks the item unread: renders the dot indicator + `data-unread`. */
57
64
  unread?: boolean
58
65
  /** Shows a Spinner in the icon slot and sets `aria-busy` on the root. */
@@ -68,6 +75,7 @@ function Notification({
68
75
  description,
69
76
  icon,
70
77
  timestamp,
78
+ actions,
71
79
  unread,
72
80
  loading,
73
81
  onDismiss,
@@ -142,6 +150,18 @@ function Notification({
142
150
  {timestamp}
143
151
  </div>
144
152
  )}
153
+ {/* Action slot — last in the content column so tab order runs
154
+ title/description context → actions → dismiss (dismiss button is
155
+ a later DOM sibling). flex-wrap lets long/localized labels wrap
156
+ inside the min-w-0 column instead of overflowing. */}
157
+ {actions && (
158
+ <div
159
+ data-slot="notification-actions"
160
+ className="mt-3 flex flex-wrap gap-2"
161
+ >
162
+ {actions}
163
+ </div>
164
+ )}
145
165
  </div>
146
166
 
147
167
  {/* Built-in dismiss. A small utility action (Tag/Sonner-close class),
@@ -63,6 +63,7 @@ function PasswordInput({
63
63
  const [visibleState, setVisibleState] = React.useState(defaultVisible);
64
64
  const isControlled = visibleProp !== undefined;
65
65
  const visible = isControlled ? visibleProp : visibleState;
66
+ const inputRef = React.useRef<HTMLInputElement>(null);
66
67
 
67
68
  function toggle() {
68
69
  const next = !visible;
@@ -70,6 +71,33 @@ function PasswordInput({
70
71
  onVisibilityChange?.(next);
71
72
  }
72
73
 
74
+ // Return focus to the input after a pointer-click on the toggle button so
75
+ // the cursor position is preserved and the field stays focused (Radix
76
+ // PasswordToggleField behaviour, 2026-08-18 ecosystem research).
77
+ function handleTogglePointerDown(e: React.PointerEvent<HTMLButtonElement>) {
78
+ // Only redirect for pointer (mouse/touch), not keyboard — keyboard users
79
+ // should keep focus on the button so they can toggle again without tabbing.
80
+ if (e.pointerType === "mouse" || e.pointerType === "touch" || e.pointerType === "pen") {
81
+ e.preventDefault(); // stop button from taking focus
82
+ toggle();
83
+ inputRef.current?.focus();
84
+ }
85
+ }
86
+
87
+ // Reset visibility to "password" on form submit to prevent accidental
88
+ // autofill leakage (passwords should not persist in "text" mode across
89
+ // submissions — Radix PasswordToggleField behaviour).
90
+ React.useEffect(() => {
91
+ const form = inputRef.current?.closest("form");
92
+ if (!form) return;
93
+ function handleSubmit() {
94
+ if (!isControlled) setVisibleState(false);
95
+ onVisibilityChange?.(false);
96
+ }
97
+ form.addEventListener("submit", handleSubmit);
98
+ return () => form.removeEventListener("submit", handleSubmit);
99
+ }, [isControlled, onVisibilityChange]);
100
+
73
101
  const paddingBySize: Record<string, string> = {
74
102
  sm: "px-2.5 py-1",
75
103
  default: "px-3 py-1",
@@ -105,6 +133,7 @@ function PasswordInput({
105
133
  className={cn(passwordInputVariants({ size, className }))}
106
134
  >
107
135
  <input
136
+ ref={inputRef}
108
137
  id={inputId}
109
138
  type={visible ? "text" : "password"}
110
139
  disabled={disabled}
@@ -119,7 +148,11 @@ function PasswordInput({
119
148
  />
120
149
  <button
121
150
  type="button"
122
- onClick={toggle}
151
+ onPointerDown={handleTogglePointerDown}
152
+ onClick={(e) => {
153
+ // keyboard-triggered clicks don't fire pointerdown — handle here
154
+ if (e.detail === 0) toggle();
155
+ }}
123
156
  disabled={disabled}
124
157
  tabIndex={0}
125
158
  aria-label={visible ? "Hide password" : "Show password"}
@@ -22,6 +22,15 @@ type ProgressProps = React.ComponentProps<typeof ProgressPrimitive.Root> & {
22
22
  * progress is indeterminate (no numeric value).
23
23
  */
24
24
  showValue?: boolean
25
+ /**
26
+ * Track height (peer parity: Mantine / Chakra / Ark Progress size).
27
+ * sm = 4px (quiet inline progress — table rows, list items),
28
+ * default = 8px (unchanged), lg = 12px (prominent surfaces — upload
29
+ * panels, onboarding). Only the track thickness changes; the header row
30
+ * (label / showValue) is size-independent. An explicit height utility in
31
+ * className still wins for one-off values.
32
+ */
33
+ size?: "sm" | "default" | "lg"
25
34
  }
26
35
 
27
36
  // Mirrors Radix Progress's built-in getValueLabel default so the visible
@@ -37,6 +46,7 @@ function Progress({
37
46
  getValueLabel,
38
47
  label,
39
48
  showValue,
49
+ size = "default",
40
50
  ...props
41
51
  }: ProgressProps) {
42
52
  const labelId = React.useId()
@@ -55,13 +65,17 @@ function Progress({
55
65
  const track = (
56
66
  <ProgressPrimitive.Root
57
67
  data-slot="progress"
68
+ data-size={size}
58
69
  className={cn(
59
70
  // Asymmetric alpha: /30 in light gives a faint "empty track" feel
60
71
  // (typical progress UX, ~2.0:1 — under AAA 1.4.11), /60 in dark hits
61
72
  // 6.79:1 (AAA pass). Documented exception in CLAUDE.md → "Known AAA
62
73
  // exceptions" because no symmetric value reads correctly in both modes
63
74
  // with a near-black primary.
64
- "relative h-2 w-full overflow-hidden rounded-full bg-primary/30 dark:bg-primary/60",
75
+ // Size ladder rides data-size so the base h-2 (default) stays
76
+ // byte-identical and a consumer's explicit height utility in
77
+ // className still wins (data-[size]:h-* only fires for sm/lg).
78
+ "relative h-2 w-full overflow-hidden rounded-full bg-primary/30 data-[size=lg]:h-3 data-[size=sm]:h-1 dark:bg-primary/60",
65
79
  className
66
80
  )}
67
81
  // max / getValueLabel always reach Radix (they rode {...props} before
@@ -0,0 +1,62 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import { Slot } from "@radix-ui/react-slot";
5
+
6
+ import { cn } from "../../lib/utils";
7
+
8
+ /**
9
+ * Long-form typography wrapper. Applies consistent, token-driven typographic
10
+ * rhythm — heading scale, paragraph spacing, list indentation, blockquote,
11
+ * inline/block code, links, tables — to arbitrary HTML descendants: MDX
12
+ * output, remote CMS articles, rendered markdown, anything you didn't author
13
+ * element-by-element. The Chakra `Prose` / Mantine `TypographyStylesProvider`
14
+ * shape, with every value sourced from BADS tokens instead of
15
+ * `@tailwindcss/typography` (whose stock scale and gray palette would breach
16
+ * the AAA 14px / 7:1 floors).
17
+ *
18
+ * <Prose>
19
+ * <h2>Getting started</h2>
20
+ * <p>Fork it, rename it, customize the brand colors, and start building.</p>
21
+ * </Prose>
22
+ *
23
+ * // Semantic override — pick the landmark yourself:
24
+ * <Prose asChild>
25
+ * <article dangerouslySetInnerHTML={{ __html: cmsArticle }} />
26
+ * </Prose>
27
+ *
28
+ * NOT the same as `Text` / `Heading` (single authored elements you control).
29
+ * Reach for Prose only when the markup arrives as a passage; keep authoring
30
+ * individual UI strings with the per-element primitives.
31
+ *
32
+ * The element styles live in the design-system CSS layer (a `.prose` block
33
+ * generated by `packages/core/scripts/build-tokens.cjs` into styles.css /
34
+ * globals.css), keyed off the class this component applies — the same
35
+ * pattern the Accordion/Marquee keyframes use. Zero new tokens: colors,
36
+ * fonts, sizes, radii, and the link-hover transition all resolve through
37
+ * existing `var(--*)` tokens, so token edits propagate via `pnpm
38
+ * build:tokens` with no component change.
39
+ *
40
+ * Display-only: adds no roles, no landmarks, no ARIA, no focus management —
41
+ * the content's own semantics pass through untouched. Width is deliberately
42
+ * consumer-controlled (pair with `max-w-prose` for a 65ch measure); baking a
43
+ * max-width in would fight card and panel layouts.
44
+ */
45
+
46
+ export interface ProseProps extends React.ComponentProps<"div"> {
47
+ /**
48
+ * When true, renders as the child element instead of the default `<div>`
49
+ * (Radix Slot). Use for semantic overrides, e.g.
50
+ * `<Prose asChild><article>…</article></Prose>`.
51
+ */
52
+ asChild?: boolean;
53
+ }
54
+
55
+ function Prose({ className, asChild = false, ...props }: ProseProps) {
56
+ const Comp = asChild ? Slot : "div";
57
+ return (
58
+ <Comp data-slot="prose" className={cn("prose", className)} {...props} />
59
+ );
60
+ }
61
+
62
+ export { Prose };
@@ -0,0 +1,151 @@
1
+ import * as React from "react"
2
+ import { cva, type VariantProps } from "class-variance-authority"
3
+ import { CheckCircle2, XCircle, AlertTriangle, Info } from "lucide-react"
4
+
5
+ import { cn } from "../../lib/utils"
6
+
7
+ // Result — feedback primitive for the outcome of a concluded operation
8
+ // (form submitted, payment confirmed, sync failed, onboarding complete).
9
+ // Distinct from EmptyState (no data yet — nothing happened) and from
10
+ // Sonner/Notification (transient or list-bound feedback): Result owns the
11
+ // surface after the operation ends.
12
+ //
13
+ // Status colors use the `text-[var(--success)]` arbitrary form — the
14
+ // Sonner / Meter / CircularProgress-proven pattern. The theme tokens are raw
15
+ // oklch values, so wrapping them in `hsl(var(--success))` produces invalid
16
+ // CSS that fails silently. `error` maps to the audited `text-destructive`
17
+ // utility. Zero new tokens.
18
+ //
19
+ // Motion (spec §4 pattern c): the icon wrapper enters via tw-animate-css
20
+ // `animate-in fade-in zoom-in-50` with token-driven timing supplied inline
21
+ // (`animationDuration: var(--duration-base)`, `animationTimingFunction:
22
+ // var(--ease-spring)`). No `duration-*` token utility classes — Tailwind v4
23
+ // has no `--duration-*` namespace and those classes compile to nothing.
24
+ // Reduced-motion is handled by the base layer (0.01ms override).
25
+
26
+ const resultVariants = cva("flex flex-col items-center text-center", {
27
+ variants: {
28
+ size: {
29
+ default: "gap-4 px-8 py-12",
30
+ sm: "gap-3 px-6 py-8",
31
+ },
32
+ },
33
+ defaultVariants: {
34
+ size: "default",
35
+ },
36
+ })
37
+
38
+ const resultIconVariants = cva(
39
+ "animate-in fade-in zoom-in-50 [&>svg]:shrink-0",
40
+ {
41
+ variants: {
42
+ status: {
43
+ success: "text-[var(--success)]",
44
+ error: "text-destructive",
45
+ warning: "text-[var(--warning)]",
46
+ info: "text-[var(--info)]",
47
+ },
48
+ size: {
49
+ default: "[&>svg]:size-12",
50
+ sm: "[&>svg]:size-10",
51
+ },
52
+ },
53
+ defaultVariants: {
54
+ size: "default",
55
+ },
56
+ }
57
+ )
58
+
59
+ const DEFAULT_STATUS_ICONS: Record<
60
+ NonNullable<ResultProps["status"]>,
61
+ React.ComponentType<React.SVGProps<SVGSVGElement> & { strokeWidth?: number }>
62
+ > = {
63
+ success: CheckCircle2,
64
+ error: XCircle,
65
+ warning: AlertTriangle,
66
+ info: Info,
67
+ }
68
+
69
+ export interface ResultProps
70
+ extends React.ComponentPropsWithoutRef<"div">,
71
+ VariantProps<typeof resultVariants> {
72
+ /** Semantic outcome — controls the default icon and its color. */
73
+ status: "success" | "error" | "warning" | "info"
74
+ /** Primary outcome statement. */
75
+ title: string
76
+ /** Supporting detail rendered below the title. */
77
+ subtitle?: string
78
+ /**
79
+ * Custom icon or illustration — replaces the default status icon when
80
+ * provided. The wrapper still carries the status color, so a custom SVG
81
+ * using `currentColor` inherits it.
82
+ */
83
+ icon?: React.ReactNode
84
+ /** Action row below title + subtitle — Buttons, links, extra detail. */
85
+ extra?: React.ReactNode
86
+ }
87
+
88
+ function Result({
89
+ className,
90
+ status,
91
+ size,
92
+ title,
93
+ subtitle,
94
+ icon,
95
+ extra,
96
+ ...props
97
+ }: ResultProps) {
98
+ const DefaultIcon = DEFAULT_STATUS_ICONS[status]
99
+ return (
100
+ <div
101
+ data-slot="result"
102
+ data-status={status}
103
+ // Outcome surfaces announce politely; errors announce assertively.
104
+ // Overridable — the spread below wins. Note: live regions only fire
105
+ // reliably when the Result is injected into an already-rendered
106
+ // container; a fresh-route render should not rely on the announcement.
107
+ role={status === "error" ? "alert" : "status"}
108
+ className={cn(resultVariants({ size }), className)}
109
+ {...props}
110
+ >
111
+ <div
112
+ data-slot="result-icon"
113
+ aria-hidden="true"
114
+ className={resultIconVariants({ status, size })}
115
+ style={{
116
+ animationDuration: "var(--duration-base)",
117
+ animationTimingFunction: "var(--ease-spring)",
118
+ }}
119
+ >
120
+ {icon ?? <DefaultIcon strokeWidth={1.5} />}
121
+ </div>
122
+ <div
123
+ data-slot="result-title"
124
+ className={cn(
125
+ "font-semibold tracking-tight text-foreground",
126
+ size === "sm" ? "text-lg" : "text-2xl"
127
+ )}
128
+ >
129
+ {title}
130
+ </div>
131
+ {subtitle && (
132
+ <p
133
+ data-slot="result-subtitle"
134
+ className="max-w-md text-sm leading-relaxed text-muted-foreground"
135
+ >
136
+ {subtitle}
137
+ </p>
138
+ )}
139
+ {extra && (
140
+ <div
141
+ data-slot="result-extra"
142
+ className="flex flex-wrap items-center justify-center gap-2 pt-2"
143
+ >
144
+ {extra}
145
+ </div>
146
+ )}
147
+ </div>
148
+ )
149
+ }
150
+
151
+ export { Result, resultVariants }