@behavioral-agentic-design-system/core 0.24.0 → 0.27.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 (137) hide show
  1. package/package.json +5 -2
  2. package/scripts/build-tokens.cjs +87 -5
  3. package/src/app/preview/components/page.tsx +4745 -244
  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-action-button.tsx +179 -0
  34. package/src/components/ui/floating-panel.tsx +129 -0
  35. package/src/components/ui/format-number.tsx +122 -0
  36. package/src/components/ui/highlight.tsx +85 -0
  37. package/src/components/ui/image.tsx +195 -0
  38. package/src/components/ui/index.ts +51 -0
  39. package/src/components/ui/indicator.tsx +2 -2
  40. package/src/components/ui/input.tsx +48 -4
  41. package/src/components/ui/kbd.tsx +1 -1
  42. package/src/components/ui/link.tsx +158 -0
  43. package/src/components/ui/listbox.tsx +426 -0
  44. package/src/components/ui/loading-overlay.tsx +80 -0
  45. package/src/components/ui/marquee.tsx +193 -0
  46. package/src/components/ui/masonry.tsx +164 -0
  47. package/src/components/ui/meter.tsx +186 -0
  48. package/src/components/ui/motion-toggle.tsx +170 -0
  49. package/src/components/ui/notification.tsx +175 -0
  50. package/src/components/ui/overlay.tsx +63 -0
  51. package/src/components/ui/progress.tsx +95 -4
  52. package/src/components/ui/rating-group.tsx +1 -0
  53. package/src/components/ui/separator.tsx +57 -1
  54. package/src/components/ui/sidebar.tsx +1 -1
  55. package/src/components/ui/signature-pad.tsx +381 -0
  56. package/src/components/ui/skeleton.tsx +59 -2
  57. package/src/components/ui/skip-link.tsx +117 -0
  58. package/src/components/ui/slider.tsx +86 -1
  59. package/src/components/ui/spoiler.tsx +131 -0
  60. package/src/components/ui/tabs.tsx +1 -1
  61. package/src/components/ui/text.tsx +135 -0
  62. package/src/components/ui/textarea.tsx +66 -2
  63. package/src/components/ui/timeline.tsx +71 -14
  64. package/src/components/ui/timer.tsx +183 -0
  65. package/src/components/ui/tour.tsx +332 -0
  66. package/src/components/ui/transfer-list.tsx +343 -0
  67. package/src/components/ui/typing-indicator.tsx +96 -0
  68. package/src/components/ui/visually-hidden.tsx +42 -0
  69. package/src/components/ui/watermark.tsx +0 -0
  70. package/src/components/ui/word-rotate.tsx +82 -0
  71. package/src/data/docs-index.ts +10 -2
  72. package/src/stories/ActionBar.stories.tsx +201 -0
  73. package/src/stories/Affix.stories.tsx +165 -0
  74. package/src/stories/Alert.stories.tsx +58 -0
  75. package/src/stories/Anchor.stories.tsx +236 -0
  76. package/src/stories/AngleSlider.stories.tsx +128 -0
  77. package/src/stories/Autocomplete.stories.tsx +216 -0
  78. package/src/stories/Avatar.stories.tsx +73 -1
  79. package/src/stories/Blockquote.stories.tsx +148 -0
  80. package/src/stories/BottomNavigation.stories.tsx +195 -0
  81. package/src/stories/Burger.stories.tsx +79 -0
  82. package/src/stories/Button.stories.tsx +103 -2
  83. package/src/stories/Calendar.stories.tsx +4 -0
  84. package/src/stories/Card.stories.tsx +30 -0
  85. package/src/stories/Carousel.stories.tsx +2 -1
  86. package/src/stories/Cascader.stories.tsx +285 -0
  87. package/src/stories/Checkbox.stories.tsx +13 -0
  88. package/src/stories/CheckboxCard.stories.tsx +210 -0
  89. package/src/stories/CheckboxGroup.stories.tsx +186 -0
  90. package/src/stories/Chip.stories.tsx +173 -0
  91. package/src/stories/CircularProgress.stories.tsx +3 -0
  92. package/src/stories/ColorSwatch.stories.tsx +81 -0
  93. package/src/stories/CopyButton.stories.tsx +3 -3
  94. package/src/stories/DatePicker.stories.tsx +3 -0
  95. package/src/stories/DateRangePicker.stories.tsx +3 -0
  96. package/src/stories/Editable.stories.tsx +14 -0
  97. package/src/stories/FloatLabel.stories.tsx +148 -0
  98. package/src/stories/FloatingActionButton.stories.tsx +215 -0
  99. package/src/stories/FloatingPanel.stories.tsx +176 -0
  100. package/src/stories/FormatNumber.stories.tsx +308 -0
  101. package/src/stories/Highlight.stories.tsx +140 -0
  102. package/src/stories/Image.stories.tsx +141 -0
  103. package/src/stories/Indicator.stories.tsx +3 -0
  104. package/src/stories/Input.stories.tsx +33 -0
  105. package/src/stories/Kbd.stories.tsx +3 -0
  106. package/src/stories/Link.stories.tsx +198 -0
  107. package/src/stories/Listbox.stories.tsx +240 -0
  108. package/src/stories/LoadingOverlay.stories.tsx +148 -0
  109. package/src/stories/Marquee.stories.tsx +170 -0
  110. package/src/stories/Masonry.stories.tsx +227 -0
  111. package/src/stories/Meter.stories.tsx +150 -0
  112. package/src/stories/MotionToggle.stories.tsx +85 -0
  113. package/src/stories/Notification.stories.tsx +264 -0
  114. package/src/stories/Overlay.stories.tsx +169 -0
  115. package/src/stories/PasswordInput.stories.tsx +4 -0
  116. package/src/stories/Progress.stories.tsx +70 -27
  117. package/src/stories/RatingGroup.stories.tsx +5 -0
  118. package/src/stories/Separator.stories.tsx +41 -5
  119. package/src/stories/Sidebar.stories.tsx +2 -1
  120. package/src/stories/SignaturePad.stories.tsx +112 -0
  121. package/src/stories/Skeleton.stories.tsx +23 -4
  122. package/src/stories/SkipLink.stories.tsx +137 -0
  123. package/src/stories/Slider.stories.tsx +28 -0
  124. package/src/stories/Spoiler.stories.tsx +122 -0
  125. package/src/stories/Tabs.stories.tsx +2 -1
  126. package/src/stories/Text.stories.tsx +191 -0
  127. package/src/stories/Textarea.stories.tsx +58 -6
  128. package/src/stories/Timeline.stories.tsx +82 -0
  129. package/src/stories/Timer.stories.tsx +160 -0
  130. package/src/stories/Tour.stories.tsx +191 -0
  131. package/src/stories/TransferList.stories.tsx +190 -0
  132. package/src/stories/TypingIndicator.stories.tsx +139 -0
  133. package/src/stories/VisuallyHidden.stories.tsx +105 -0
  134. package/src/stories/Watermark.stories.tsx +212 -0
  135. package/src/stories/WordRotate.stories.tsx +101 -0
  136. package/src/styles.css +88 -6
  137. package/src/tokens.json +3 -3
@@ -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 }
@@ -0,0 +1,164 @@
1
+ import * as React from "react"
2
+
3
+ import { cn } from "../../lib/utils"
4
+
5
+ /** Column counts the masonry supports. Capped at 6 — beyond that, cells drop
6
+ * under readable width at any sane container size. */
7
+ type MasonryColumns = 1 | 2 | 3 | 4 | 5 | 6
8
+
9
+ /**
10
+ * Responsive column map, mobile-first. `base` applies below the `sm`
11
+ * breakpoint and defaults to 1 when the object form is used, so a masonry
12
+ * always degrades to a single readable column on narrow viewports.
13
+ */
14
+ interface MasonryResponsiveColumns {
15
+ base?: MasonryColumns
16
+ sm?: MasonryColumns
17
+ md?: MasonryColumns
18
+ lg?: MasonryColumns
19
+ xl?: MasonryColumns
20
+ }
21
+
22
+ /** Spacing-token steps supported for the gap. Drives BOTH the column gap and
23
+ * the vertical rhythm between items so the two can never drift apart. */
24
+ type MasonryGap = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "8"
25
+
26
+ export interface MasonryProps extends React.ComponentProps<"div"> {
27
+ /**
28
+ * Column count — a fixed number or a responsive breakpoint map
29
+ * (`{ sm: 1, md: 2, lg: 3 }`). Default 3.
30
+ */
31
+ columns?: MasonryColumns | MasonryResponsiveColumns
32
+ /**
33
+ * Spacing-token step applied to both the column gap and the vertical
34
+ * space between items. Default "4" (16px in BADS' scale).
35
+ */
36
+ gap?: MasonryGap
37
+ }
38
+
39
+ // Tailwind's scanner needs literal class strings in source — a template
40
+ // literal like `columns-${n}` compiles to nothing. Every supported
41
+ // combination is enumerated statically instead.
42
+ const BASE_COLUMNS: Record<MasonryColumns, string> = {
43
+ 1: "columns-1",
44
+ 2: "columns-2",
45
+ 3: "columns-3",
46
+ 4: "columns-4",
47
+ 5: "columns-5",
48
+ 6: "columns-6",
49
+ }
50
+
51
+ const SM_COLUMNS: Record<MasonryColumns, string> = {
52
+ 1: "sm:columns-1",
53
+ 2: "sm:columns-2",
54
+ 3: "sm:columns-3",
55
+ 4: "sm:columns-4",
56
+ 5: "sm:columns-5",
57
+ 6: "sm:columns-6",
58
+ }
59
+
60
+ const MD_COLUMNS: Record<MasonryColumns, string> = {
61
+ 1: "md:columns-1",
62
+ 2: "md:columns-2",
63
+ 3: "md:columns-3",
64
+ 4: "md:columns-4",
65
+ 5: "md:columns-5",
66
+ 6: "md:columns-6",
67
+ }
68
+
69
+ const LG_COLUMNS: Record<MasonryColumns, string> = {
70
+ 1: "lg:columns-1",
71
+ 2: "lg:columns-2",
72
+ 3: "lg:columns-3",
73
+ 4: "lg:columns-4",
74
+ 5: "lg:columns-5",
75
+ 6: "lg:columns-6",
76
+ }
77
+
78
+ const XL_COLUMNS: Record<MasonryColumns, string> = {
79
+ 1: "xl:columns-1",
80
+ 2: "xl:columns-2",
81
+ 3: "xl:columns-3",
82
+ 4: "xl:columns-4",
83
+ 5: "xl:columns-5",
84
+ 6: "xl:columns-6",
85
+ }
86
+
87
+ // The gap step sets the column gap on the root AND the bottom margin on every
88
+ // item. Multicol consumes `column-gap` from the `gap` shorthand; vertical
89
+ // rhythm inside a column has no gap property, so it rides `[&>*]:mb-*`.
90
+ const GAP_CLASSES: Record<MasonryGap, string> = {
91
+ "0": "gap-0 [&>*]:mb-0",
92
+ "1": "gap-1 [&>*]:mb-1",
93
+ "2": "gap-2 [&>*]:mb-2",
94
+ "3": "gap-3 [&>*]:mb-3",
95
+ "4": "gap-4 [&>*]:mb-4",
96
+ "5": "gap-5 [&>*]:mb-5",
97
+ "6": "gap-6 [&>*]:mb-6",
98
+ "8": "gap-8 [&>*]:mb-8",
99
+ }
100
+
101
+ function columnsClasses(columns: MasonryColumns | MasonryResponsiveColumns) {
102
+ if (typeof columns === "number") {
103
+ return BASE_COLUMNS[columns]
104
+ }
105
+ const { base = 1, sm, md, lg, xl } = columns
106
+ return cn(
107
+ BASE_COLUMNS[base],
108
+ sm && SM_COLUMNS[sm],
109
+ md && MD_COLUMNS[md],
110
+ lg && LG_COLUMNS[lg],
111
+ xl && XL_COLUMNS[xl]
112
+ )
113
+ }
114
+
115
+ /**
116
+ * Column-flowing masonry layout for variable-height content — photo
117
+ * galleries, testimonial walls, pinboard dashboards. Pure CSS `columns`
118
+ * (no JS measurement, no layout thrash): each direct child keeps its
119
+ * intrinsic height and flows top-to-bottom down each column in turn.
120
+ *
121
+ * The item contract (`break-inside-avoid`, bottom margin matching the gap,
122
+ * full width) is applied structurally via `[&>*]` child selectors, so a
123
+ * child can never be half-styled — the classic failure of hand-rolled
124
+ * CSS-columns masonry is a forgotten `break-inside-avoid` silently splitting
125
+ * a card across two columns.
126
+ *
127
+ * Ordering note: CSS columns flow item 1→N DOWN column one, then column two
128
+ * (column-major). DOM order, screen-reader order, and tab order all match
129
+ * that visual order — they never diverge — but if the sequence itself is
130
+ * meaningful left-to-right (ranked results, chronological steps), use a
131
+ * `grid` layout instead. See the registry anti-patterns.
132
+ *
133
+ * Motion: deliberately none. A layout container has no interactive states,
134
+ * and animating column reflow on resize is disorienting (and fights the
135
+ * reduced-motion guarantee). For entrance animation, wrap items in
136
+ * `<Reveal>` at the consumer layer.
137
+ *
138
+ * Accessibility: no implicit role — purely presentational. Add `role` /
139
+ * `aria-label` at the consumer layer when the collection is semantically a
140
+ * region or list. Interactive children keep their own contracts.
141
+ */
142
+ function Masonry({
143
+ columns = 3,
144
+ gap = "4",
145
+ className,
146
+ ...props
147
+ }: MasonryProps) {
148
+ return (
149
+ <div
150
+ data-slot="masonry"
151
+ className={cn(
152
+ "w-full",
153
+ columnsClasses(columns),
154
+ GAP_CLASSES[gap],
155
+ "[&>*]:w-full [&>*]:break-inside-avoid",
156
+ className
157
+ )}
158
+ {...props}
159
+ />
160
+ )
161
+ }
162
+
163
+ export { Masonry }
164
+ export type { MasonryColumns, MasonryResponsiveColumns, MasonryGap }
@@ -0,0 +1,186 @@
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
+
8
+ // Root/host carries the variant COLOR as text color; the track background and
9
+ // fill both inherit it via bg-current, so one CVA axis drives every painted
10
+ // surface (the CircularProgress stroke-current architecture, linearized).
11
+ //
12
+ // Status accents use the `[var(--success)]` / `[var(--warning)]` arbitrary
13
+ // form — the Sonner-proven pattern. NOT `hsl(var(--success))` (invalid CSS:
14
+ // those tokens are oklch values, so wrapping them in hsl() silently fails).
15
+ const meterVariants = cva("relative w-full overflow-hidden rounded-full", {
16
+ variants: {
17
+ variant: {
18
+ default: "text-primary",
19
+ success: "text-[var(--success)]",
20
+ warning: "text-[var(--warning)]",
21
+ destructive: "text-destructive",
22
+ },
23
+ size: {
24
+ sm: "h-1.5",
25
+ default: "h-2",
26
+ lg: "h-3",
27
+ },
28
+ },
29
+ defaultVariants: {
30
+ variant: "default",
31
+ size: "default",
32
+ },
33
+ })
34
+
35
+ type MeterProps = Omit<
36
+ React.HTMLAttributes<HTMLDivElement>,
37
+ // children: a meter renders its own track/fill — no content slot.
38
+ // role: the element IS role="meter"; overriding it would break the contract.
39
+ "children" | "role"
40
+ > &
41
+ VariantProps<typeof meterVariants> & {
42
+ /** The measurement. Clamped to [min, max] for both the fill and ARIA. */
43
+ value: number
44
+ /** Lower bound of the range. */
45
+ min?: number
46
+ /** Upper bound of the range. */
47
+ max?: number
48
+ /**
49
+ * Optional label rendered left-aligned above the track. Becomes the
50
+ * meter's accessible name via a generated-id aria-labelledby — unless the
51
+ * consumer already passed aria-label / aria-labelledby, which always win.
52
+ * (Same wiring as Progress.)
53
+ */
54
+ label?: React.ReactNode
55
+ /**
56
+ * Renders the value text right-aligned above the track. The visible
57
+ * string is getValueLabel(value, min, max) — the same string set as
58
+ * aria-valuetext — so the visible and announced values cannot diverge.
59
+ */
60
+ showValue?: boolean
61
+ /**
62
+ * Formats BOTH the visible value text and aria-valuetext.
63
+ * Default: percentage of the range, e.g. "62%".
64
+ */
65
+ getValueLabel?: (value: number, min: number, max: number) => string
66
+ /**
67
+ * Visual dim for disabled contexts (e.g. a metric inside a disabled
68
+ * fieldset). Display-only — a meter is never focusable either way.
69
+ */
70
+ disabled?: boolean
71
+ }
72
+
73
+ function defaultGetValueLabel(value: number, min: number, max: number) {
74
+ return `${Math.round(((value - min) / (max - min)) * 100)}%`
75
+ }
76
+
77
+ function Meter({
78
+ className,
79
+ value,
80
+ min = 0,
81
+ max = 100,
82
+ variant,
83
+ size,
84
+ label,
85
+ showValue,
86
+ getValueLabel,
87
+ disabled,
88
+ ...props
89
+ }: MeterProps) {
90
+ const labelId = React.useId()
91
+ const showLabel = label != null && label !== false
92
+ const hasHeader = showLabel || Boolean(showValue)
93
+ // Guard a degenerate range so the math can't divide by zero.
94
+ const resolvedMax = max > min ? max : min + 1
95
+ const clampedValue = Math.min(resolvedMax, Math.max(min, value))
96
+ const fillPercent = ((clampedValue - min) / (resolvedMax - min)) * 100
97
+ const valueText = (getValueLabel ?? defaultGetValueLabel)(
98
+ clampedValue,
99
+ min,
100
+ resolvedMax
101
+ )
102
+
103
+ const track = (
104
+ <div
105
+ data-slot="meter"
106
+ data-disabled={disabled ? "" : undefined}
107
+ // role="meter" (ARIA 1.1): a reading within a known range. Distinct
108
+ // from Progress's role="progressbar" — nothing is progressing here.
109
+ role="meter"
110
+ aria-valuenow={clampedValue}
111
+ aria-valuemin={min}
112
+ aria-valuemax={resolvedMax}
113
+ aria-valuetext={valueText}
114
+ {...(showLabel &&
115
+ !("aria-label" in props) &&
116
+ !("aria-labelledby" in props)
117
+ ? { "aria-labelledby": labelId }
118
+ : null)}
119
+ className={cn(
120
+ meterVariants({ variant, size }),
121
+ // Always dim the track when disabled — label text stays at full
122
+ // opacity so it meets WCAG AAA contrast regardless of state.
123
+ disabled && "opacity-50",
124
+ className
125
+ )}
126
+ {...props}
127
+ >
128
+ {/* Track wash: variant hue at reduced opacity. Same asymmetric alpha
129
+ convention as Progress/Slider (30% light / 60% dark) — the light-mode
130
+ value is a documented AAA 1.4.11 exception (see CLAUDE.md → Known
131
+ AAA exceptions). A separate layer (not track opacity) so the fill
132
+ child stays at full opacity. */}
133
+ <div
134
+ data-slot="meter-track-bg"
135
+ aria-hidden="true"
136
+ className="absolute inset-0 bg-current opacity-30 dark:opacity-60"
137
+ />
138
+ <div
139
+ data-slot="meter-fill"
140
+ className="absolute inset-y-0 left-0 rounded-full bg-current transition-[width,background-color]"
141
+ style={{
142
+ width: `${fillPercent}%`,
143
+ transitionDuration: "var(--duration-base)",
144
+ transitionTimingFunction: "var(--ease-out)",
145
+ }}
146
+ />
147
+ </div>
148
+ )
149
+
150
+ if (!hasHeader) return track
151
+
152
+ return (
153
+ <div
154
+ data-slot="meter-wrapper"
155
+ className="flex w-full flex-col gap-2"
156
+ >
157
+ <div className="flex items-center justify-between gap-3">
158
+ {showLabel ? (
159
+ <span
160
+ id={labelId}
161
+ data-slot="meter-label"
162
+ className="min-w-0 truncate text-sm font-medium text-foreground"
163
+ >
164
+ {label}
165
+ </span>
166
+ ) : null}
167
+ {showValue ? (
168
+ // aria-hidden: the identical string is already announced through
169
+ // the meter's aria-valuetext — visible-only here avoids the double
170
+ // announcement.
171
+ <span
172
+ aria-hidden="true"
173
+ data-slot="meter-value"
174
+ className="ml-auto shrink-0 text-sm text-muted-foreground tabular-nums"
175
+ >
176
+ {valueText}
177
+ </span>
178
+ ) : null}
179
+ </div>
180
+ {track}
181
+ </div>
182
+ )
183
+ }
184
+
185
+ export { Meter, meterVariants }
186
+ export type { MeterProps }