@behavioral-agentic-design-system/core 0.24.0 → 0.26.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 (131) hide show
  1. package/package.json +5 -2
  2. package/scripts/build-tokens.cjs +79 -5
  3. package/src/app/preview/components/page.tsx +4474 -208
  4. package/src/app/shell.tsx +18 -6
  5. package/src/components/customize/brand-mark-section.tsx +1 -1
  6. package/src/components/customize-tab.tsx +2 -2
  7. package/src/components/home-tab.tsx +2 -2
  8. package/src/components/ui/action-bar.tsx +142 -0
  9. package/src/components/ui/affix.tsx +109 -0
  10. package/src/components/ui/alert.tsx +37 -3
  11. package/src/components/ui/anchor.tsx +136 -0
  12. package/src/components/ui/angle-slider.tsx +265 -0
  13. package/src/components/ui/autocomplete.tsx +223 -0
  14. package/src/components/ui/avatar.tsx +8 -2
  15. package/src/components/ui/blockquote.tsx +112 -0
  16. package/src/components/ui/bottom-navigation.tsx +144 -0
  17. package/src/components/ui/burger.tsx +117 -0
  18. package/src/components/ui/button.tsx +101 -3
  19. package/src/components/ui/calendar.tsx +1 -1
  20. package/src/components/ui/card.tsx +43 -5
  21. package/src/components/ui/carousel.tsx +10 -5
  22. package/src/components/ui/cascader.tsx +253 -0
  23. package/src/components/ui/checkbox-card.tsx +176 -0
  24. package/src/components/ui/checkbox-group.tsx +231 -0
  25. package/src/components/ui/checkbox.tsx +14 -3
  26. package/src/components/ui/chip.tsx +143 -0
  27. package/src/components/ui/circular-progress.tsx +2 -2
  28. package/src/components/ui/color-swatch.tsx +73 -0
  29. package/src/components/ui/copy-button.tsx +21 -4
  30. package/src/components/ui/date-picker.tsx +6 -3
  31. package/src/components/ui/date-range-picker.tsx +6 -3
  32. package/src/components/ui/float-label.tsx +114 -0
  33. package/src/components/ui/floating-panel.tsx +129 -0
  34. package/src/components/ui/format-number.tsx +122 -0
  35. package/src/components/ui/highlight.tsx +85 -0
  36. package/src/components/ui/image.tsx +195 -0
  37. package/src/components/ui/index.ts +50 -0
  38. package/src/components/ui/indicator.tsx +2 -2
  39. package/src/components/ui/input.tsx +48 -4
  40. package/src/components/ui/kbd.tsx +1 -1
  41. package/src/components/ui/link.tsx +158 -0
  42. package/src/components/ui/listbox.tsx +426 -0
  43. package/src/components/ui/loading-overlay.tsx +80 -0
  44. package/src/components/ui/marquee.tsx +193 -0
  45. package/src/components/ui/masonry.tsx +164 -0
  46. package/src/components/ui/meter.tsx +186 -0
  47. package/src/components/ui/motion-toggle.tsx +170 -0
  48. package/src/components/ui/notification.tsx +175 -0
  49. package/src/components/ui/overlay.tsx +63 -0
  50. package/src/components/ui/progress.tsx +95 -4
  51. package/src/components/ui/rating-group.tsx +1 -0
  52. package/src/components/ui/separator.tsx +57 -1
  53. package/src/components/ui/sidebar.tsx +1 -1
  54. package/src/components/ui/signature-pad.tsx +381 -0
  55. package/src/components/ui/skeleton.tsx +59 -2
  56. package/src/components/ui/skip-link.tsx +117 -0
  57. package/src/components/ui/slider.tsx +86 -1
  58. package/src/components/ui/spoiler.tsx +131 -0
  59. package/src/components/ui/tabs.tsx +1 -1
  60. package/src/components/ui/text.tsx +135 -0
  61. package/src/components/ui/textarea.tsx +66 -2
  62. package/src/components/ui/timeline.tsx +71 -14
  63. package/src/components/ui/timer.tsx +183 -0
  64. package/src/components/ui/tour.tsx +332 -0
  65. package/src/components/ui/transfer-list.tsx +308 -0
  66. package/src/components/ui/visually-hidden.tsx +42 -0
  67. package/src/components/ui/watermark.tsx +0 -0
  68. package/src/data/docs-index.ts +9 -2
  69. package/src/stories/ActionBar.stories.tsx +201 -0
  70. package/src/stories/Affix.stories.tsx +165 -0
  71. package/src/stories/Alert.stories.tsx +58 -0
  72. package/src/stories/Anchor.stories.tsx +236 -0
  73. package/src/stories/AngleSlider.stories.tsx +128 -0
  74. package/src/stories/Autocomplete.stories.tsx +216 -0
  75. package/src/stories/Avatar.stories.tsx +73 -1
  76. package/src/stories/Blockquote.stories.tsx +148 -0
  77. package/src/stories/BottomNavigation.stories.tsx +195 -0
  78. package/src/stories/Burger.stories.tsx +79 -0
  79. package/src/stories/Button.stories.tsx +103 -2
  80. package/src/stories/Calendar.stories.tsx +4 -0
  81. package/src/stories/Card.stories.tsx +30 -0
  82. package/src/stories/Carousel.stories.tsx +2 -1
  83. package/src/stories/Cascader.stories.tsx +285 -0
  84. package/src/stories/Checkbox.stories.tsx +13 -0
  85. package/src/stories/CheckboxCard.stories.tsx +210 -0
  86. package/src/stories/CheckboxGroup.stories.tsx +186 -0
  87. package/src/stories/Chip.stories.tsx +173 -0
  88. package/src/stories/CircularProgress.stories.tsx +3 -0
  89. package/src/stories/ColorSwatch.stories.tsx +81 -0
  90. package/src/stories/CopyButton.stories.tsx +3 -3
  91. package/src/stories/DatePicker.stories.tsx +3 -0
  92. package/src/stories/DateRangePicker.stories.tsx +3 -0
  93. package/src/stories/Editable.stories.tsx +14 -0
  94. package/src/stories/FloatLabel.stories.tsx +148 -0
  95. package/src/stories/FloatingPanel.stories.tsx +176 -0
  96. package/src/stories/FormatNumber.stories.tsx +308 -0
  97. package/src/stories/Highlight.stories.tsx +140 -0
  98. package/src/stories/Image.stories.tsx +141 -0
  99. package/src/stories/Indicator.stories.tsx +3 -0
  100. package/src/stories/Input.stories.tsx +33 -0
  101. package/src/stories/Kbd.stories.tsx +3 -0
  102. package/src/stories/Link.stories.tsx +198 -0
  103. package/src/stories/Listbox.stories.tsx +240 -0
  104. package/src/stories/LoadingOverlay.stories.tsx +148 -0
  105. package/src/stories/Marquee.stories.tsx +170 -0
  106. package/src/stories/Masonry.stories.tsx +227 -0
  107. package/src/stories/Meter.stories.tsx +143 -0
  108. package/src/stories/MotionToggle.stories.tsx +85 -0
  109. package/src/stories/Notification.stories.tsx +264 -0
  110. package/src/stories/Overlay.stories.tsx +169 -0
  111. package/src/stories/PasswordInput.stories.tsx +4 -0
  112. package/src/stories/Progress.stories.tsx +70 -27
  113. package/src/stories/RatingGroup.stories.tsx +5 -0
  114. package/src/stories/Separator.stories.tsx +41 -5
  115. package/src/stories/Sidebar.stories.tsx +2 -1
  116. package/src/stories/SignaturePad.stories.tsx +112 -0
  117. package/src/stories/Skeleton.stories.tsx +23 -4
  118. package/src/stories/SkipLink.stories.tsx +137 -0
  119. package/src/stories/Slider.stories.tsx +28 -0
  120. package/src/stories/Spoiler.stories.tsx +122 -0
  121. package/src/stories/Tabs.stories.tsx +2 -1
  122. package/src/stories/Text.stories.tsx +191 -0
  123. package/src/stories/Textarea.stories.tsx +58 -6
  124. package/src/stories/Timeline.stories.tsx +82 -0
  125. package/src/stories/Timer.stories.tsx +160 -0
  126. package/src/stories/Tour.stories.tsx +191 -0
  127. package/src/stories/TransferList.stories.tsx +169 -0
  128. package/src/stories/VisuallyHidden.stories.tsx +105 -0
  129. package/src/stories/Watermark.stories.tsx +212 -0
  130. package/src/styles.css +80 -6
  131. package/src/tokens.json +2 -2
@@ -0,0 +1,426 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+
5
+ import { cn } from "../../lib/utils";
6
+
7
+ /**
8
+ * Listbox — a controlled, always-visible listbox widget for single or
9
+ * multi-select. Renders with role="listbox" and role="option" children,
10
+ * following the ARIA Listbox pattern with aria-activedescendant keyboard
11
+ * navigation (focus stays on the container; the logical cursor is tracked
12
+ * via aria-activedescendant, not DOM focus movement between options).
13
+ *
14
+ * Use for: filter sidebars, settings panels, language/locale pickers — any
15
+ * surface where the list stays open and the selection is immediately visible.
16
+ *
17
+ * Do NOT use for:
18
+ * - Navigation (use NavigationMenu)
19
+ * - Popup/trigger-activated selection (use Select, Combobox, DropdownMenu)
20
+ *
21
+ * Sources: Ark UI (Listbox), Chakra UI v3 (Listbox).
22
+ *
23
+ * @example Single-select
24
+ * ```tsx
25
+ * <ListboxRoot value={status} onValueChange={setStatus} aria-label="Filter by status">
26
+ * <ListboxOption value="active">Active</ListboxOption>
27
+ * <ListboxOption value="in-review">In Review</ListboxOption>
28
+ * <ListboxOption value="archived" disabled>Archived</ListboxOption>
29
+ * </ListboxRoot>
30
+ * ```
31
+ *
32
+ * @example Multi-select
33
+ * ```tsx
34
+ * <ListboxRoot multiple value={tags} onValueChange={setTags} aria-label="Filter by tag">
35
+ * <ListboxOption value="design">Design</ListboxOption>
36
+ * <ListboxOption value="tokens">Tokens</ListboxOption>
37
+ * <ListboxOption value="a11y">Accessibility</ListboxOption>
38
+ * </ListboxRoot>
39
+ * ```
40
+ */
41
+
42
+ // ---------------------------------------------------------------------------
43
+ // Context
44
+ // ---------------------------------------------------------------------------
45
+
46
+ type ListboxContextValue = {
47
+ value: string[];
48
+ activeId: string | undefined;
49
+ setActiveId: (id: string | undefined) => void;
50
+ multiple: boolean;
51
+ disabled: boolean;
52
+ toggleOption: (optionValue: string, withShift?: boolean) => void;
53
+ isSelected: (optionValue: string) => boolean;
54
+ };
55
+
56
+ const ListboxContext = React.createContext<ListboxContextValue | null>(null);
57
+
58
+ function useListboxContext(caller: string) {
59
+ const ctx = React.useContext(ListboxContext);
60
+ if (!ctx) {
61
+ throw new Error(`${caller} must be rendered inside a <ListboxRoot>.`);
62
+ }
63
+ return ctx;
64
+ }
65
+
66
+ // ---------------------------------------------------------------------------
67
+ // ListboxRoot
68
+ // ---------------------------------------------------------------------------
69
+
70
+ export interface ListboxRootProps
71
+ extends Omit<React.ComponentProps<"div">, "value" | "onChange"> {
72
+ /**
73
+ * When false (default): `value` is a string, `onValueChange` receives a string.
74
+ * When true: `value` is a string[], `onValueChange` receives a string[].
75
+ */
76
+ multiple?: boolean;
77
+ /**
78
+ * Controlled selected value(s). In single mode, a string; in multi mode, a
79
+ * string[]. If omitted, the component manages its own selection state.
80
+ */
81
+ value?: string | string[];
82
+ /** Called with the new value on every selection change. */
83
+ onValueChange?: (value: string | string[]) => void;
84
+ /** Disables the entire listbox and all options. */
85
+ disabled?: boolean;
86
+ }
87
+
88
+ function ListboxRoot({
89
+ className,
90
+ multiple = false,
91
+ value: valueProp,
92
+ onValueChange,
93
+ disabled = false,
94
+ children,
95
+ onFocus,
96
+ onKeyDown,
97
+ ...props
98
+ }: ListboxRootProps) {
99
+ const containerRef = React.useRef<HTMLDivElement>(null);
100
+ const [activeId, setActiveId] = React.useState<string | undefined>();
101
+
102
+ // Anchor for Shift+click / Shift+Arrow range extension (multi mode)
103
+ const anchorValueRef = React.useRef<string | undefined>(undefined);
104
+
105
+ // Normalize value prop → string[]
106
+ const normalizeValue = (v: string | string[] | undefined): string[] => {
107
+ if (v === undefined) return [];
108
+ return Array.isArray(v) ? v : [v];
109
+ };
110
+
111
+ const [internalValue, setInternalValue] = React.useState<string[]>(() =>
112
+ normalizeValue(valueProp),
113
+ );
114
+
115
+ const isControlled = valueProp !== undefined;
116
+ const value = isControlled ? normalizeValue(valueProp) : internalValue;
117
+
118
+ // Stable ref to avoid stale-closure in toggleOption
119
+ const onValueChangeRef = React.useRef(onValueChange);
120
+ React.useEffect(() => {
121
+ onValueChangeRef.current = onValueChange;
122
+ });
123
+
124
+ const valueRef = React.useRef(value);
125
+ valueRef.current = value;
126
+
127
+ // Helper: query navigable (non-disabled) option elements in DOM order
128
+ const getNavigableOptions = React.useCallback((): HTMLElement[] => {
129
+ if (!containerRef.current) return [];
130
+ return Array.from(
131
+ containerRef.current.querySelectorAll<HTMLElement>(
132
+ '[role="option"]:not([aria-disabled="true"])',
133
+ ),
134
+ );
135
+ }, []);
136
+
137
+ const toggleOption = React.useCallback(
138
+ (optionValue: string, withShift = false) => {
139
+ if (disabled) return;
140
+
141
+ let next: string[];
142
+
143
+ if (!multiple) {
144
+ // Single select: replace
145
+ next = [optionValue];
146
+ anchorValueRef.current = optionValue;
147
+ } else if (withShift && anchorValueRef.current) {
148
+ // Shift: select the contiguous range from anchor to target
149
+ const options = getNavigableOptions();
150
+ const optionValues = options.map(
151
+ (el) => el.getAttribute("data-value") ?? "",
152
+ );
153
+ const anchorIdx = optionValues.indexOf(anchorValueRef.current);
154
+ const targetIdx = optionValues.indexOf(optionValue);
155
+
156
+ if (anchorIdx !== -1 && targetIdx !== -1) {
157
+ const [start, end] =
158
+ anchorIdx <= targetIdx
159
+ ? [anchorIdx, targetIdx]
160
+ : [targetIdx, anchorIdx];
161
+ const rangeValues = optionValues
162
+ .slice(start, end + 1)
163
+ .filter(Boolean);
164
+ // Merge range into existing selection (preserving anything outside)
165
+ const outsideRange = valueRef.current.filter(
166
+ (v) => !optionValues.includes(v),
167
+ );
168
+ next = [...new Set([...outsideRange, ...rangeValues])];
169
+ } else {
170
+ // Fallback: toggle
171
+ next = valueRef.current.includes(optionValue)
172
+ ? valueRef.current.filter((v) => v !== optionValue)
173
+ : [...valueRef.current, optionValue];
174
+ }
175
+ } else {
176
+ // Multi-select: toggle individual option
177
+ next = valueRef.current.includes(optionValue)
178
+ ? valueRef.current.filter((v) => v !== optionValue)
179
+ : [...valueRef.current, optionValue];
180
+ anchorValueRef.current = optionValue;
181
+ }
182
+
183
+ if (!isControlled) setInternalValue(next);
184
+
185
+ // Emit the correct shape for single vs multi
186
+ onValueChangeRef.current?.(multiple ? next : (next[0] ?? ""));
187
+ },
188
+ [disabled, getNavigableOptions, isControlled, multiple],
189
+ );
190
+
191
+ const handleKeyDown = React.useCallback(
192
+ (e: React.KeyboardEvent<HTMLDivElement>) => {
193
+ onKeyDown?.(e);
194
+ if (disabled || e.defaultPrevented) return;
195
+
196
+ const options = getNavigableOptions();
197
+ if (options.length === 0) return;
198
+
199
+ const currentIndex = activeId
200
+ ? options.findIndex((el) => el.id === activeId)
201
+ : -1;
202
+
203
+ switch (e.key) {
204
+ case "ArrowDown": {
205
+ e.preventDefault();
206
+ const nextIdx =
207
+ currentIndex < options.length - 1 ? currentIndex + 1 : 0;
208
+ const nextEl = options[nextIdx];
209
+ if (nextEl) {
210
+ setActiveId(nextEl.id);
211
+ if (multiple && e.shiftKey) {
212
+ const optValue = nextEl.getAttribute("data-value");
213
+ if (optValue) toggleOption(optValue, true);
214
+ }
215
+ }
216
+ break;
217
+ }
218
+ case "ArrowUp": {
219
+ e.preventDefault();
220
+ const prevIdx =
221
+ currentIndex > 0 ? currentIndex - 1 : options.length - 1;
222
+ const prevEl = options[prevIdx];
223
+ if (prevEl) {
224
+ setActiveId(prevEl.id);
225
+ if (multiple && e.shiftKey) {
226
+ const optValue = prevEl.getAttribute("data-value");
227
+ if (optValue) toggleOption(optValue, true);
228
+ }
229
+ }
230
+ break;
231
+ }
232
+ case "Home": {
233
+ e.preventDefault();
234
+ const firstEl = options[0];
235
+ if (firstEl) setActiveId(firstEl.id);
236
+ break;
237
+ }
238
+ case "End": {
239
+ e.preventDefault();
240
+ const lastEl = options[options.length - 1];
241
+ if (lastEl) setActiveId(lastEl.id);
242
+ break;
243
+ }
244
+ case " ":
245
+ case "Enter": {
246
+ e.preventDefault();
247
+ if (activeId) {
248
+ const activeEl = options.find((el) => el.id === activeId);
249
+ if (activeEl) {
250
+ const optValue = activeEl.getAttribute("data-value");
251
+ if (optValue) toggleOption(optValue);
252
+ }
253
+ } else {
254
+ // No active item yet — activate + select the first option
255
+ const firstEl = options[0];
256
+ if (firstEl) {
257
+ setActiveId(firstEl.id);
258
+ const optValue = firstEl.getAttribute("data-value");
259
+ if (optValue) toggleOption(optValue);
260
+ }
261
+ }
262
+ break;
263
+ }
264
+ }
265
+ },
266
+ [activeId, disabled, getNavigableOptions, multiple, onKeyDown, toggleOption],
267
+ );
268
+
269
+ const handleFocus = React.useCallback(
270
+ (e: React.FocusEvent<HTMLDivElement>) => {
271
+ onFocus?.(e);
272
+ // Set an initial active descendant on focus if none is set yet
273
+ if (!activeId) {
274
+ const options = getNavigableOptions();
275
+ // Prefer the first selected option, fall back to first option
276
+ const firstSelected = valueRef.current[0];
277
+ if (firstSelected) {
278
+ const selectedEl = options.find(
279
+ (el) => el.getAttribute("data-value") === firstSelected,
280
+ );
281
+ if (selectedEl) {
282
+ setActiveId(selectedEl.id);
283
+ return;
284
+ }
285
+ }
286
+ if (options[0]) setActiveId(options[0].id);
287
+ }
288
+ },
289
+ [activeId, getNavigableOptions, onFocus],
290
+ );
291
+
292
+ const isSelected = React.useCallback(
293
+ (optionValue: string) => value.includes(optionValue),
294
+ [value],
295
+ );
296
+
297
+ const ctx = React.useMemo<ListboxContextValue>(
298
+ () => ({
299
+ value,
300
+ activeId,
301
+ setActiveId,
302
+ multiple,
303
+ disabled,
304
+ toggleOption,
305
+ isSelected,
306
+ }),
307
+ [value, activeId, multiple, disabled, toggleOption, isSelected],
308
+ );
309
+
310
+ return (
311
+ <ListboxContext.Provider value={ctx}>
312
+ <div
313
+ ref={containerRef}
314
+ role="listbox"
315
+ data-slot="listbox"
316
+ aria-multiselectable={multiple || undefined}
317
+ aria-disabled={disabled || undefined}
318
+ aria-activedescendant={activeId}
319
+ tabIndex={disabled ? -1 : 0}
320
+ onKeyDown={handleKeyDown}
321
+ onFocus={handleFocus}
322
+ className={cn(
323
+ "flex flex-col rounded-md border border-border bg-background py-1 text-foreground outline-none",
324
+ // Focus ring — visible when the container itself is keyboard-focused
325
+ "focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:border-ring",
326
+ disabled && "pointer-events-none opacity-50",
327
+ className,
328
+ )}
329
+ {...props}
330
+ >
331
+ {children}
332
+ </div>
333
+ </ListboxContext.Provider>
334
+ );
335
+ }
336
+
337
+ // ---------------------------------------------------------------------------
338
+ // ListboxOption
339
+ // ---------------------------------------------------------------------------
340
+
341
+ export interface ListboxOptionProps
342
+ extends Omit<React.ComponentProps<"div">, "value"> {
343
+ /** The value this option represents. */
344
+ value: string;
345
+ /** Prevents this option from being selected or navigated to. */
346
+ disabled?: boolean;
347
+ }
348
+
349
+ function ListboxOption({
350
+ className,
351
+ value: optionValue,
352
+ disabled: optionDisabled = false,
353
+ children,
354
+ onClick,
355
+ ...props
356
+ }: ListboxOptionProps) {
357
+ const ctx = useListboxContext("ListboxOption");
358
+
359
+ // Stable ID for aria-activedescendant linkage
360
+ const rawId = React.useId();
361
+ // useId returns strings like ":ra:" — strip colons for a clean HTML id
362
+ const optionId = `listbox-option-${rawId.replace(/:/g, "")}`;
363
+
364
+ const selected = ctx.isSelected(optionValue);
365
+ const isActive = ctx.activeId === optionId;
366
+ const isDisabled = ctx.disabled || optionDisabled;
367
+
368
+ const handleClick = (e: React.MouseEvent<HTMLDivElement>) => {
369
+ if (isDisabled) return;
370
+ ctx.setActiveId(optionId);
371
+ ctx.toggleOption(optionValue, e.shiftKey && ctx.multiple);
372
+ onClick?.(e);
373
+ };
374
+
375
+ return (
376
+ <div
377
+ id={optionId}
378
+ role="option"
379
+ data-slot="listbox-option"
380
+ data-value={optionValue}
381
+ data-state={selected ? "selected" : "unselected"}
382
+ data-active={isActive || undefined}
383
+ data-disabled={isDisabled || undefined}
384
+ aria-selected={selected}
385
+ aria-disabled={isDisabled || undefined}
386
+ onClick={handleClick}
387
+ className={cn(
388
+ // Base — layout, type, sizing
389
+ "relative flex cursor-pointer select-none items-center px-3 py-2 text-sm",
390
+ // 44px minimum touch target (SC 2.5.5 Enhanced)
391
+ "min-h-11",
392
+ // Default (unselected, non-active) hover
393
+ !isDisabled && !selected && "hover:bg-accent/50 hover:text-accent-foreground",
394
+ // Selected state
395
+ selected && "bg-accent text-accent-foreground",
396
+ // Active-descendant cursor when not selected — subtle accent tint
397
+ isActive && !selected && "bg-accent/30",
398
+ // Disabled
399
+ isDisabled && "pointer-events-none cursor-not-allowed opacity-50",
400
+ className,
401
+ )}
402
+ // Microanimation: pattern-c — inline style with BADS motion tokens.
403
+ // transitionProperty lists only the properties we animate (SC 2.4.13 safe).
404
+ // var(--duration-fast) + var(--ease-out) resolve from styles.css via
405
+ // pnpm build:tokens. Reduced-motion is auto-killed by the base layer's
406
+ // @media (prefers-reduced-motion: reduce) rule in styles.css.
407
+ style={{
408
+ transitionProperty: "background-color, color",
409
+ transitionDuration: "var(--duration-fast)",
410
+ transitionTimingFunction: "var(--ease-out)",
411
+ }}
412
+ {...props}
413
+ >
414
+ {children}
415
+ </div>
416
+ );
417
+ }
418
+
419
+ // ---------------------------------------------------------------------------
420
+ // Exports
421
+ // ---------------------------------------------------------------------------
422
+
423
+ /** Convenience alias for single-select usage: const Listbox = ListboxRoot */
424
+ const Listbox = ListboxRoot;
425
+
426
+ export { Listbox, ListboxRoot, ListboxOption };
@@ -0,0 +1,80 @@
1
+ import * as React from "react"
2
+ import { cn } from "../../lib/utils"
3
+ import { Spinner } from "./spinner"
4
+
5
+ type LoadingOverlayProps = React.HTMLAttributes<HTMLDivElement> & {
6
+ /** Overlay is visible (and announced to assistive tech) while true. */
7
+ loading: boolean
8
+ /** Adds a backdrop blur to the overlay surface. */
9
+ blur?: boolean
10
+ /**
11
+ * Cover the whole viewport (fixed positioning) instead of the wrapped
12
+ * content. Reserve for page-level transitions — not card regions.
13
+ */
14
+ fullscreen?: boolean
15
+ /** Class for the overlay surface (the backdrop element itself). */
16
+ overlayClassName?: string
17
+ /** Overrides the overlay's default stacking (z-50). */
18
+ zIndex?: number
19
+ }
20
+
21
+ /**
22
+ * Full-coverage loading state for a container or the viewport. Wraps its
23
+ * children in a positioned container and renders a semi-transparent
24
+ * backdrop with a centered Spinner over them while `loading` is true.
25
+ *
26
+ * The overlay stays in the DOM in both states so the opacity fade runs in
27
+ * both directions; while idle it is `pointer-events-none` and hidden from
28
+ * assistive tech. The overlay element owns the `role="status"` polite
29
+ * live-region announcement — the inner Spinner is presentational.
30
+ *
31
+ * Reduced motion: the base layer's `prefers-reduced-motion` rule collapses
32
+ * the transition automatically; no component-level guard is needed.
33
+ */
34
+ function LoadingOverlay({
35
+ loading,
36
+ blur = false,
37
+ fullscreen = false,
38
+ overlayClassName,
39
+ zIndex,
40
+ className,
41
+ children,
42
+ ...props
43
+ }: LoadingOverlayProps) {
44
+ return (
45
+ <div
46
+ data-slot="loading-overlay"
47
+ data-loading={loading || undefined}
48
+ className={cn("relative", className)}
49
+ {...props}
50
+ >
51
+ {children}
52
+ <div
53
+ data-slot="loading-overlay-overlay"
54
+ role="status"
55
+ aria-live="polite"
56
+ aria-label="Loading"
57
+ aria-hidden={!loading || undefined}
58
+ className={cn(
59
+ "inset-0 z-50 flex items-center justify-center bg-background/80 transition-opacity",
60
+ fullscreen ? "fixed" : "absolute",
61
+ blur && "backdrop-blur-sm",
62
+ loading ? "opacity-100" : "pointer-events-none opacity-0",
63
+ overlayClassName
64
+ )}
65
+ style={{
66
+ transitionDuration: "var(--duration-fast)",
67
+ transitionTimingFunction: "var(--ease-out)",
68
+ ...(zIndex !== undefined ? { zIndex } : null),
69
+ }}
70
+ >
71
+ {/* The overlay element above owns the status announcement; hiding
72
+ the Spinner prevents a duplicate role="status" from announcing
73
+ "Loading" twice. */}
74
+ <Spinner size="lg" aria-hidden="true" />
75
+ </div>
76
+ </div>
77
+ )
78
+ }
79
+
80
+ export { LoadingOverlay, type LoadingOverlayProps }
@@ -0,0 +1,193 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import { PauseIcon, PlayIcon } from "lucide-react"
5
+
6
+ import { cn } from "../../lib/utils"
7
+ import { Button } from "./button"
8
+
9
+ export interface MarqueeProps extends React.ComponentProps<"div"> {
10
+ /**
11
+ * Scroll speed in pixels per second. Default 40. The component measures
12
+ * the loop width and writes the resulting `--marquee-duration` as an
13
+ * inline CSS variable; passing your own `--marquee-duration` via `style`
14
+ * (or a stylesheet rule on a higher-specificity selector) overrides it.
15
+ */
16
+ speed?: number
17
+ /** Scroll direction. Default "left" (content travels toward the start). */
18
+ direction?: "left" | "right"
19
+ /**
20
+ * Fade the strip out at both edges via a CSS mask, so items dissolve
21
+ * instead of hard-clipping. Default false.
22
+ */
23
+ fade?: boolean
24
+ /**
25
+ * Render the visible pause/resume control (default true).
26
+ *
27
+ * SC 2.2.2 (Pause, Stop, Hide) consumer contract: auto-scrolling content
28
+ * that lasts longer than 5 seconds MUST be pauseable. With the control
29
+ * hidden, hover and focus-within still pause the strip, but touch users
30
+ * have no mechanism — if you set `showControl={false}` you MUST provide
31
+ * your own pause affordance. Drive it by passing `data-state="paused"` /
32
+ * `data-state="running"` on the root (consumer props spread last, so
33
+ * your value wins over the internal state).
34
+ */
35
+ showControl?: boolean
36
+ }
37
+
38
+ /**
39
+ * Continuously auto-scrolling strip of repeated content — logo walls,
40
+ * ticker rows, testimonial strips. Pure CSS keyframe animation
41
+ * (`marquee-scroll`, defined in the design-system layer and keyed off
42
+ * `data-slot="marquee-track"`), so the base layer's
43
+ * `prefers-reduced-motion` kill genuinely halts it.
44
+ *
45
+ * Seamless loop: the track renders `2 × K` identical copies of the
46
+ * children (K = enough sets to cover the viewport, measured with a
47
+ * ResizeObserver) and animates `translateX(-50%)`, which is always exactly
48
+ * K sets — so the loop point is invisible at any viewport width. Only the
49
+ * first copy is exposed to assistive tech; duplicates are `aria-hidden`.
50
+ *
51
+ * Pausing (SC 2.2.2): three mechanisms, all on by default —
52
+ * 1. a visible 44×44 pause/resume button (`showControl`),
53
+ * 2. pause on hover anywhere over the strip,
54
+ * 3. pause on focus-within (keyboard users pause it by reaching it).
55
+ *
56
+ * Accessibility notes:
57
+ * - Give the root an `aria-label` ("Customer logos") — it renders as a
58
+ * labelled `role="group"`.
59
+ * - Never put critical information or interactive controls inside the
60
+ * strip; content should be decorative/reinforcing, fully available
61
+ * elsewhere or non-essential.
62
+ * - Tune gap density via the `--marquee-gap` CSS variable (default 3rem).
63
+ */
64
+ function Marquee({
65
+ speed = 40,
66
+ direction = "left",
67
+ fade = false,
68
+ showControl = true,
69
+ className,
70
+ style,
71
+ children,
72
+ ...props
73
+ }: MarqueeProps) {
74
+ const [paused, setPaused] = React.useState(false)
75
+ // How many copies of `children` each half of the track needs so one half
76
+ // always covers the viewport. Track = 2 × repeat identical groups;
77
+ // translateX(-50%) is then exactly one half — seamless at any width.
78
+ const [repeat, setRepeat] = React.useState(1)
79
+ const [duration, setDuration] = React.useState<string | null>(null)
80
+ const viewportRef = React.useRef<HTMLDivElement>(null)
81
+ const firstGroupRef = React.useRef<HTMLDivElement>(null)
82
+
83
+ React.useLayoutEffect(() => {
84
+ const viewport = viewportRef.current
85
+ const firstGroup = firstGroupRef.current
86
+ if (!viewport || !firstGroup) return
87
+
88
+ const measure = () => {
89
+ // scrollWidth includes the group's trailing padding-inline-end gap,
90
+ // so setWidth is the true per-copy stride of the loop.
91
+ const setWidth = firstGroup.scrollWidth
92
+ const viewportWidth = viewport.clientWidth
93
+ if (setWidth <= 0) return
94
+ const nextRepeat = Math.max(1, Math.ceil(viewportWidth / setWidth))
95
+ setRepeat(nextRepeat)
96
+ // One loop = one half of the track = repeat × setWidth pixels.
97
+ // Constant px/s regardless of how many copies auto-fill added.
98
+ const seconds = (nextRepeat * setWidth) / Math.max(1, speed)
99
+ setDuration(`${Math.round(seconds * 100) / 100}s`)
100
+ }
101
+
102
+ measure()
103
+ const observer = new ResizeObserver(measure)
104
+ observer.observe(viewport)
105
+ observer.observe(firstGroup)
106
+ return () => observer.disconnect()
107
+ }, [speed, children])
108
+
109
+ const groups = []
110
+ for (let i = 0; i < repeat * 2; i++) {
111
+ groups.push(
112
+ // Copy 0 is the one assistive tech reads; every duplicate exists only
113
+ // to make the loop seamless and is hidden from the a11y tree.
114
+ <div
115
+ key={i}
116
+ ref={i === 0 ? firstGroupRef : undefined}
117
+ data-slot="marquee-group"
118
+ aria-hidden={i > 0 || undefined}
119
+ >
120
+ {children}
121
+ </div>
122
+ )
123
+ }
124
+
125
+ return (
126
+ <div
127
+ data-slot="marquee"
128
+ data-state={paused ? "paused" : "running"}
129
+ role="group"
130
+ className={cn("flex w-full items-center gap-3", className)}
131
+ style={
132
+ {
133
+ // Written before the consumer `style` spread so an explicit
134
+ // consumer override of --marquee-duration always wins.
135
+ ...(duration ? { "--marquee-duration": duration } : undefined),
136
+ ...style,
137
+ } as React.CSSProperties
138
+ }
139
+ {...props}
140
+ >
141
+ <div
142
+ ref={viewportRef}
143
+ data-slot="marquee-viewport"
144
+ data-fade={fade ? "" : undefined}
145
+ className="min-w-0 flex-1 overflow-hidden"
146
+ >
147
+ <div
148
+ data-slot="marquee-track"
149
+ data-direction={direction}
150
+ className="flex w-max"
151
+ >
152
+ {groups}
153
+ </div>
154
+ </div>
155
+ {showControl && (
156
+ <Button
157
+ type="button"
158
+ variant="ghost"
159
+ size="icon-xl"
160
+ data-slot="marquee-control"
161
+ aria-pressed={paused}
162
+ aria-label={paused ? "Resume auto-scroll" : "Pause auto-scroll"}
163
+ onClick={() => setPaused((p) => !p)}
164
+ >
165
+ {paused ? (
166
+ <PlayIcon strokeWidth={1.5} aria-hidden="true" />
167
+ ) : (
168
+ <PauseIcon strokeWidth={1.5} aria-hidden="true" />
169
+ )}
170
+ </Button>
171
+ )}
172
+ </div>
173
+ )
174
+ }
175
+
176
+ /**
177
+ * One cell of marquee content — a logo, chip, or card. `shrink-0` keeps
178
+ * every item at its intrinsic width so the loop measurement is exact.
179
+ */
180
+ function MarqueeItem({
181
+ className,
182
+ ...props
183
+ }: React.ComponentProps<"div">) {
184
+ return (
185
+ <div
186
+ data-slot="marquee-item"
187
+ className={cn("flex shrink-0 items-center", className)}
188
+ {...props}
189
+ />
190
+ )
191
+ }
192
+
193
+ export { Marquee, MarqueeItem }