@behavioral-agentic-design-system/core 0.39.1 → 0.40.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.
- package/package.json +8 -3
- package/scripts/a11y-lint.cjs +47 -6
- package/scripts/bads-components.mjs +118 -0
- package/scripts/build-tokens.cjs +133 -12
- package/scripts/check-stories.mjs +1 -1
- package/scripts/lint-component-source.mjs +100 -0
- package/scripts/lint-microanimation.mjs +267 -0
- package/scripts/size-audit.cjs +79 -0
- package/scripts/source-of-truth.cjs +58 -0
- package/scripts/ux-smoke.mjs +438 -0
- package/scripts/wcag-audit.cjs +49 -1
- package/src/api/layers/file.ts +1 -0
- package/src/app/preview/components/page.tsx +968 -0
- package/src/app/shell.tsx +11 -13
- package/src/components/customize/brand-mark-section.tsx +4 -2
- package/src/components/customize/design-controls.tsx +1 -1
- package/src/components/customize/discipline-section.tsx +3 -6
- package/src/components/customize/font-pickers.tsx +1 -1
- package/src/components/customize/letter-spacing.tsx +1 -1
- package/src/components/customize/save-bar.tsx +2 -2
- package/src/components/customize/theme-io.tsx +7 -7
- package/src/components/customize/type-scale.tsx +1 -1
- package/src/components/customize-tab.tsx +7 -4
- package/src/components/home-tab.tsx +3 -0
- package/src/components/ui/accordion.tsx +7 -0
- package/src/components/ui/alert.tsx +1 -0
- package/src/components/ui/announcement-bar.tsx +256 -0
- package/src/components/ui/badge.tsx +1 -0
- package/src/components/ui/callout.tsx +218 -0
- package/src/components/ui/chart.tsx +2 -14
- package/src/components/ui/color-picker.tsx +1 -1
- package/src/components/ui/format-relative-time.tsx +139 -0
- package/src/components/ui/grid.tsx +255 -0
- package/src/components/ui/icon.tsx +108 -0
- package/src/components/ui/index.ts +8 -0
- package/src/components/ui/page-header.tsx +63 -0
- package/src/components/ui/portal.tsx +111 -0
- package/src/components/ui/presence.tsx +172 -0
- package/src/components/ui/progress-stack.tsx +258 -0
- package/src/components/ui/select.tsx +89 -4
- package/src/components/ui/separator.tsx +1 -0
- package/src/components/ui/slider.tsx +83 -3
- package/src/components/ui/sparkline.tsx +2 -14
- package/src/components/ui/textarea.tsx +28 -1
- package/src/data/docs-index.ts +1 -0
- package/src/hooks/use-reduced-motion.ts +6 -0
- package/src/stories/Accordion.stories.tsx +59 -0
- package/src/stories/Alert.stories.tsx +3 -1
- package/src/stories/AnnouncementBar.stories.tsx +261 -0
- package/src/stories/Badge.stories.tsx +3 -0
- package/src/stories/Calendar.stories.tsx +1 -1
- package/src/stories/Callout.stories.tsx +219 -0
- package/src/stories/Chart.stories.tsx +4 -0
- package/src/stories/ColorPicker.stories.tsx +23 -0
- package/src/stories/FormatRelativeTime.stories.tsx +116 -0
- package/src/stories/Grid.stories.tsx +197 -0
- package/src/stories/Icon.stories.tsx +175 -0
- package/src/stories/MultiSelect.stories.tsx +1 -1
- package/src/stories/PageHeader.stories.tsx +102 -0
- package/src/stories/Portal.stories.tsx +189 -0
- package/src/stories/Presence.stories.tsx +228 -0
- package/src/stories/ProgressStack.stories.tsx +287 -0
- package/src/stories/Select.stories.tsx +25 -0
- package/src/stories/Separator.stories.tsx +3 -0
- package/src/stories/Slider.stories.tsx +54 -5
- package/src/stories/Sparkline.stories.tsx +3 -0
- package/src/stories/Textarea.stories.tsx +18 -0
- package/src/stories/story-groups.json +14 -5
- package/src/styles.css +133 -12
|
@@ -0,0 +1,258 @@
|
|
|
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
|
+
// ─── Token cycling ────────────────────────────────────────────────────────────
|
|
9
|
+
//
|
|
10
|
+
// Default segment colors cycle through the --chart-1..5 family so a
|
|
11
|
+
// ProgressStack reads as part of the same system as BADS charts. Override
|
|
12
|
+
// per-segment via the `color` field.
|
|
13
|
+
|
|
14
|
+
const CHART_COLORS = [
|
|
15
|
+
"var(--chart-1)",
|
|
16
|
+
"var(--chart-2)",
|
|
17
|
+
"var(--chart-3)",
|
|
18
|
+
"var(--chart-4)",
|
|
19
|
+
"var(--chart-5)",
|
|
20
|
+
] as const
|
|
21
|
+
|
|
22
|
+
// ─── Track variants ───────────────────────────────────────────────────────────
|
|
23
|
+
|
|
24
|
+
const progressStackVariants = cva(
|
|
25
|
+
"relative flex w-full overflow-hidden rounded-full bg-secondary",
|
|
26
|
+
{
|
|
27
|
+
variants: {
|
|
28
|
+
/**
|
|
29
|
+
* Track height (peer parity: Mantine Progress size, Bootstrap
|
|
30
|
+
* progress-sm/-lg). Thickness changes only the track — legend typography
|
|
31
|
+
* is size-independent.
|
|
32
|
+
*
|
|
33
|
+
* sm = 4px (dense list rows, table cells)
|
|
34
|
+
* default = 8px (standard dashboard surface)
|
|
35
|
+
* lg = 16px (hero / storage panels)
|
|
36
|
+
*/
|
|
37
|
+
size: {
|
|
38
|
+
sm: "h-1",
|
|
39
|
+
default: "h-2.5",
|
|
40
|
+
lg: "h-4",
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
defaultVariants: {
|
|
44
|
+
size: "default",
|
|
45
|
+
},
|
|
46
|
+
}
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
// ─── Types ────────────────────────────────────────────────────────────────────
|
|
50
|
+
|
|
51
|
+
export interface ProgressStackSegment {
|
|
52
|
+
/**
|
|
53
|
+
* Raw numeric value. Proportioned against the sum of all segment values, or
|
|
54
|
+
* against `max` on the root when provided.
|
|
55
|
+
*/
|
|
56
|
+
value: number
|
|
57
|
+
/** Human-readable label for the legend and screen readers. */
|
|
58
|
+
label: string
|
|
59
|
+
/**
|
|
60
|
+
* Explicit CSS color for this segment. Accepts any CSS color (hex, hsl(),
|
|
61
|
+
* or a variable reference such as `"var(--chart-3)"`). Defaults to cycling
|
|
62
|
+
* through `--chart-1` to `--chart-5`.
|
|
63
|
+
*/
|
|
64
|
+
color?: string
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface ProgressStackProps
|
|
68
|
+
extends Omit<React.ComponentProps<"div">, "children">,
|
|
69
|
+
VariantProps<typeof progressStackVariants> {
|
|
70
|
+
/**
|
|
71
|
+
* The segments that make up the stacked bar. Required — at least one
|
|
72
|
+
* segment is needed for a meaningful render.
|
|
73
|
+
*/
|
|
74
|
+
segments: ProgressStackSegment[]
|
|
75
|
+
/**
|
|
76
|
+
* Total value the segments are measured against. Defaults to the sum of all
|
|
77
|
+
* segment values so the bar is always full. Pass an explicit `max` when the
|
|
78
|
+
* segments may not fill the bar — for example, 70 GB used across categories
|
|
79
|
+
* out of a 128 GB disk renders 70/128 of the track filled with the rest
|
|
80
|
+
* shown as the empty track.
|
|
81
|
+
*/
|
|
82
|
+
max?: number
|
|
83
|
+
/**
|
|
84
|
+
* Renders a color-coded legend row below the bar: a colored swatch, the
|
|
85
|
+
* segment label, and optionally the formatted value when `showValues` is
|
|
86
|
+
* also true. Default `false`.
|
|
87
|
+
*/
|
|
88
|
+
showLegend?: boolean
|
|
89
|
+
/**
|
|
90
|
+
* When `showLegend` is true, also renders the formatted percentage (or
|
|
91
|
+
* custom `formatValue` output) beside each legend label. Default `false`.
|
|
92
|
+
*/
|
|
93
|
+
showValues?: boolean
|
|
94
|
+
/**
|
|
95
|
+
* Custom value-formatting function for the legend. Receives the segment's
|
|
96
|
+
* raw value and the computed total. Defaults to `"N%"` (nearest integer).
|
|
97
|
+
*/
|
|
98
|
+
formatValue?: (value: number, total: number) => string
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// ─── Component ────────────────────────────────────────────────────────────────
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* ProgressStack — a multi-segment stacked horizontal bar showing a
|
|
105
|
+
* proportional breakdown across categories.
|
|
106
|
+
*
|
|
107
|
+
* Distinct from:
|
|
108
|
+
* - `Progress` — single determinate/indeterminate fill with Radix semantics
|
|
109
|
+
* - `Meter` — a gauge for where one value falls within a known range
|
|
110
|
+
* - `CircularProgress` — a ring variant of the single-fill pattern
|
|
111
|
+
*
|
|
112
|
+
* Use ProgressStack for **categorical breakdowns** where the visual
|
|
113
|
+
* decomposition is the point: storage used by type (Documents / Media /
|
|
114
|
+
* System), budget allocation by team, skill proficiency across domains.
|
|
115
|
+
*
|
|
116
|
+
* Sources: Mantine (Progress with `sections` array), Bootstrap stacked
|
|
117
|
+
* progress, shadcn dashboard card examples.
|
|
118
|
+
*
|
|
119
|
+
* Accessibility: the track is `role="img"` with an `aria-label`. A
|
|
120
|
+
* visually-hidden description list below the track announces each segment's
|
|
121
|
+
* label and percentage to screen readers. Never rely on color alone — the
|
|
122
|
+
* legend and the sr-only list both carry the labels.
|
|
123
|
+
*
|
|
124
|
+
* Motion: each segment animates its width from 0 to its final percentage on
|
|
125
|
+
* mount via a CSS transition keyed to `--duration-slow` + `--ease-out`.
|
|
126
|
+
* Segments stagger by 40 ms per index. Reduced-motion users get the final
|
|
127
|
+
* state immediately — the base-layer `prefers-reduced-motion` rule collapses
|
|
128
|
+
* the transition to 0.01 ms.
|
|
129
|
+
*/
|
|
130
|
+
function ProgressStack({
|
|
131
|
+
className,
|
|
132
|
+
size,
|
|
133
|
+
segments,
|
|
134
|
+
max,
|
|
135
|
+
showLegend = false,
|
|
136
|
+
showValues = false,
|
|
137
|
+
formatValue,
|
|
138
|
+
"aria-label": ariaLabel,
|
|
139
|
+
...props
|
|
140
|
+
}: ProgressStackProps & {
|
|
141
|
+
/**
|
|
142
|
+
* Accessible name for the whole bar. Required — without it screen readers
|
|
143
|
+
* have no way to announce what this chart represents. Pass a short
|
|
144
|
+
* description, e.g. `"Storage breakdown"` or `"Q3 budget allocation"`.
|
|
145
|
+
*/
|
|
146
|
+
"aria-label": string
|
|
147
|
+
}) {
|
|
148
|
+
const total = max ?? segments.reduce((acc, s) => acc + s.value, 0)
|
|
149
|
+
const safeTotal = total === 0 ? 1 : total
|
|
150
|
+
const fmt = formatValue ?? ((v: number, t: number) => `${Math.round((v / t) * 100)}%`)
|
|
151
|
+
|
|
152
|
+
// Mount animation: start at 0-width, transition to final width on the
|
|
153
|
+
// first animation frame so the browser paints the 0-width state first and
|
|
154
|
+
// the entrance always plays.
|
|
155
|
+
const [mounted, setMounted] = React.useState(false)
|
|
156
|
+
React.useEffect(() => {
|
|
157
|
+
const id = requestAnimationFrame(() => setMounted(true))
|
|
158
|
+
return () => cancelAnimationFrame(id)
|
|
159
|
+
}, [])
|
|
160
|
+
|
|
161
|
+
return (
|
|
162
|
+
<div
|
|
163
|
+
data-slot="progress-stack-root"
|
|
164
|
+
className={cn("flex flex-col gap-3", className)}
|
|
165
|
+
{...props}
|
|
166
|
+
>
|
|
167
|
+
{/* Visual track — role="img" with the aria-label as the accessible name */}
|
|
168
|
+
<div
|
|
169
|
+
data-slot="progress-stack"
|
|
170
|
+
role="img"
|
|
171
|
+
aria-label={ariaLabel}
|
|
172
|
+
className={cn(progressStackVariants({ size }), "gap-0.5")}
|
|
173
|
+
>
|
|
174
|
+
{segments.map((seg, idx) => {
|
|
175
|
+
const pct = (seg.value / safeTotal) * 100
|
|
176
|
+
const color = seg.color ?? CHART_COLORS[idx % CHART_COLORS.length]
|
|
177
|
+
return (
|
|
178
|
+
<div
|
|
179
|
+
key={idx}
|
|
180
|
+
data-slot="progress-stack-segment"
|
|
181
|
+
data-index={idx}
|
|
182
|
+
aria-hidden
|
|
183
|
+
// First / last get the outer radius so the track feels like one
|
|
184
|
+
// continuous bar; middle segments are square (gap handles the
|
|
185
|
+
// visual break). rounded-sm on inner segments matches the track
|
|
186
|
+
// height at each size without looking lumpy.
|
|
187
|
+
className="h-full flex-none rounded-sm first:rounded-l-full last:rounded-r-full"
|
|
188
|
+
style={{
|
|
189
|
+
width: mounted ? `${pct}%` : "0%",
|
|
190
|
+
backgroundColor: color,
|
|
191
|
+
transitionProperty: "width",
|
|
192
|
+
transitionDuration: "var(--duration-slow)",
|
|
193
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
194
|
+
// Stagger each segment 40 ms later than the previous so they
|
|
195
|
+
// grow in sequence rather than all at once.
|
|
196
|
+
transitionDelay: mounted ? `${idx * 40}ms` : "0ms",
|
|
197
|
+
// Minimum rendered width so a very-small segment is always
|
|
198
|
+
// visible rather than rendering as an invisible sliver. 4px is
|
|
199
|
+
// enough for the color swatch to read.
|
|
200
|
+
minWidth: mounted && pct > 0 ? "4px" : "0px",
|
|
201
|
+
}}
|
|
202
|
+
/>
|
|
203
|
+
)
|
|
204
|
+
})}
|
|
205
|
+
</div>
|
|
206
|
+
|
|
207
|
+
{/* Screen-reader segment list — visually hidden, but gives AT users the
|
|
208
|
+
same per-segment breakdown the sighted legend provides. Placed after
|
|
209
|
+
the track so it follows naturally when the bar is focused / navigated. */}
|
|
210
|
+
<ul
|
|
211
|
+
aria-label={`${ariaLabel} breakdown`}
|
|
212
|
+
className="sr-only"
|
|
213
|
+
role="list"
|
|
214
|
+
>
|
|
215
|
+
{segments.map((seg, idx) => (
|
|
216
|
+
<li key={idx}>
|
|
217
|
+
{seg.label}: {fmt(seg.value, safeTotal)}
|
|
218
|
+
</li>
|
|
219
|
+
))}
|
|
220
|
+
</ul>
|
|
221
|
+
|
|
222
|
+
{/* Legend (opt-in) — aria-hidden because the sr-only list above already
|
|
223
|
+
carries the same information for screen readers. */}
|
|
224
|
+
{showLegend && (
|
|
225
|
+
<div
|
|
226
|
+
data-slot="progress-stack-legend"
|
|
227
|
+
aria-hidden
|
|
228
|
+
className="flex flex-wrap gap-x-4 gap-y-1.5"
|
|
229
|
+
>
|
|
230
|
+
{segments.map((seg, idx) => {
|
|
231
|
+
const color = seg.color ?? CHART_COLORS[idx % CHART_COLORS.length]
|
|
232
|
+
return (
|
|
233
|
+
<div
|
|
234
|
+
key={idx}
|
|
235
|
+
data-slot="progress-stack-legend-item"
|
|
236
|
+
className="flex items-center gap-1.5 text-sm"
|
|
237
|
+
>
|
|
238
|
+
<span
|
|
239
|
+
aria-hidden
|
|
240
|
+
className="size-2.5 shrink-0 rounded-sm"
|
|
241
|
+
style={{ backgroundColor: color }}
|
|
242
|
+
/>
|
|
243
|
+
<span className="text-muted-foreground">{seg.label}</span>
|
|
244
|
+
{showValues && (
|
|
245
|
+
<span className="font-medium tabular-nums text-foreground">
|
|
246
|
+
{fmt(seg.value, safeTotal)}
|
|
247
|
+
</span>
|
|
248
|
+
)}
|
|
249
|
+
</div>
|
|
250
|
+
)
|
|
251
|
+
})}
|
|
252
|
+
</div>
|
|
253
|
+
)}
|
|
254
|
+
</div>
|
|
255
|
+
)
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export { ProgressStack, progressStackVariants }
|
|
@@ -1,16 +1,69 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
|
|
3
3
|
import * as React from "react"
|
|
4
|
-
import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from "lucide-react"
|
|
4
|
+
import { CheckIcon, ChevronDownIcon, ChevronUpIcon, XIcon } from "lucide-react"
|
|
5
5
|
import * as SelectPrimitive from "@radix-ui/react-select"
|
|
6
6
|
|
|
7
7
|
import { cn } from "../../lib/utils"
|
|
8
8
|
import { usePortalThemeClass } from "../../hooks/use-portal-theme-class"
|
|
9
9
|
|
|
10
|
+
// Context threads clearable state from Select root to SelectTrigger
|
|
11
|
+
// without prop-drilling through compound-component consumers.
|
|
12
|
+
const SelectClearContext = React.createContext<{
|
|
13
|
+
clearable: boolean
|
|
14
|
+
hasValue: boolean
|
|
15
|
+
onClear: () => void
|
|
16
|
+
}>({ clearable: false, hasValue: false, onClear: () => {} })
|
|
17
|
+
|
|
10
18
|
function Select({
|
|
19
|
+
clearable,
|
|
20
|
+
value,
|
|
21
|
+
defaultValue,
|
|
22
|
+
onValueChange,
|
|
11
23
|
...props
|
|
12
|
-
}: React.ComponentProps<typeof SelectPrimitive.Root>
|
|
13
|
-
|
|
24
|
+
}: React.ComponentProps<typeof SelectPrimitive.Root> & {
|
|
25
|
+
/**
|
|
26
|
+
* Shows an × button in the trigger to clear the current selection.
|
|
27
|
+
* Works in both controlled (pass `value` + `onValueChange`) and
|
|
28
|
+
* uncontrolled modes. In controlled mode, `onValueChange` is called
|
|
29
|
+
* with `""` on clear — reset your state variable to `""` or `undefined`.
|
|
30
|
+
*
|
|
31
|
+
* Peer parity: Mantine clearable, Chakra UI clearable, Ant Design allowClear.
|
|
32
|
+
*/
|
|
33
|
+
clearable?: boolean
|
|
34
|
+
}) {
|
|
35
|
+
// Track internal value only when in uncontrolled + clearable mode.
|
|
36
|
+
const [internalValue, setInternalValue] = React.useState<string | undefined>(
|
|
37
|
+
defaultValue
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
const resolvedHasValue = clearable
|
|
41
|
+
? Boolean(value !== undefined ? value : internalValue)
|
|
42
|
+
: false
|
|
43
|
+
|
|
44
|
+
function handleValueChange(v: string) {
|
|
45
|
+
if (clearable && value === undefined) setInternalValue(v)
|
|
46
|
+
onValueChange?.(v)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function handleClear() {
|
|
50
|
+
if (value === undefined) setInternalValue(undefined)
|
|
51
|
+
onValueChange?.("")
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<SelectClearContext.Provider
|
|
56
|
+
value={{ clearable: !!clearable, hasValue: resolvedHasValue, onClear: handleClear }}
|
|
57
|
+
>
|
|
58
|
+
<SelectPrimitive.Root
|
|
59
|
+
data-slot="select"
|
|
60
|
+
value={value}
|
|
61
|
+
defaultValue={defaultValue}
|
|
62
|
+
onValueChange={handleValueChange}
|
|
63
|
+
{...props}
|
|
64
|
+
/>
|
|
65
|
+
</SelectClearContext.Provider>
|
|
66
|
+
)
|
|
14
67
|
}
|
|
15
68
|
|
|
16
69
|
function SelectGroup({
|
|
@@ -33,12 +86,16 @@ function SelectTrigger({
|
|
|
33
86
|
}: React.ComponentProps<typeof SelectPrimitive.Trigger> & {
|
|
34
87
|
size?: "sm" | "default" | "lg" | "xl"
|
|
35
88
|
}) {
|
|
36
|
-
|
|
89
|
+
const { clearable, hasValue, onClear } = React.useContext(SelectClearContext)
|
|
90
|
+
|
|
91
|
+
const trigger = (
|
|
37
92
|
<SelectPrimitive.Trigger
|
|
38
93
|
data-slot="select-trigger"
|
|
39
94
|
data-size={size}
|
|
40
95
|
className={cn(
|
|
41
96
|
"flex w-fit items-center justify-between gap-2 rounded-md border border-input bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[placeholder]:text-muted-foreground data-[size=sm]:h-8 data-[size=default]:h-9 data-[size=lg]:h-10 data-[size=xl]:h-11 data-[size=xl]:text-base *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",
|
|
97
|
+
// reserve horizontal space for the clear button when it will render
|
|
98
|
+
clearable && hasValue && "pr-7",
|
|
42
99
|
className
|
|
43
100
|
)}
|
|
44
101
|
{...props}
|
|
@@ -49,6 +106,34 @@ function SelectTrigger({
|
|
|
49
106
|
</SelectPrimitive.Icon>
|
|
50
107
|
</SelectPrimitive.Trigger>
|
|
51
108
|
)
|
|
109
|
+
|
|
110
|
+
if (!clearable) return trigger
|
|
111
|
+
|
|
112
|
+
return (
|
|
113
|
+
// Relative wrapper enables the clear button to be positioned absolutely
|
|
114
|
+
// OUTSIDE the trigger button — nesting buttons is invalid HTML and some
|
|
115
|
+
// browsers silently discard nested button clicks.
|
|
116
|
+
<div className="relative inline-flex">
|
|
117
|
+
{trigger}
|
|
118
|
+
{hasValue && (
|
|
119
|
+
<button
|
|
120
|
+
type="button"
|
|
121
|
+
aria-label="Clear selection"
|
|
122
|
+
onClick={(e) => {
|
|
123
|
+
e.stopPropagation()
|
|
124
|
+
onClear()
|
|
125
|
+
}}
|
|
126
|
+
className="absolute right-7 top-1/2 z-10 flex size-4 -translate-y-1/2 items-center justify-center rounded text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1"
|
|
127
|
+
style={{
|
|
128
|
+
transitionDuration: "var(--duration-fast)",
|
|
129
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
130
|
+
}}
|
|
131
|
+
>
|
|
132
|
+
<XIcon strokeWidth={1.5} className="size-3" />
|
|
133
|
+
</button>
|
|
134
|
+
)}
|
|
135
|
+
</div>
|
|
136
|
+
)
|
|
52
137
|
}
|
|
53
138
|
|
|
54
139
|
function SelectContent({
|
|
@@ -5,6 +5,7 @@ import * as SeparatorPrimitive from "@radix-ui/react-separator"
|
|
|
5
5
|
|
|
6
6
|
import { cn } from "../../lib/utils"
|
|
7
7
|
|
|
8
|
+
// @recipe-note: Separator always renders a `<div>` (both the label and no-label paths). Nesting it inside a `<p>` is invalid HTML and throws React hydration error #418 at runtime even though `next build` reports success — put it between block elements, not inside one.
|
|
8
9
|
type SeparatorProps = React.ComponentProps<typeof SeparatorPrimitive.Root> & {
|
|
9
10
|
/**
|
|
10
11
|
* Optional label rendered inline, splitting the rule into two segments (an
|
|
@@ -11,6 +11,12 @@ import { cn } from "../../lib/utils"
|
|
|
11
11
|
*/
|
|
12
12
|
type SliderMark = number | { value: number; label?: React.ReactNode }
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* When the per-thumb value bubble shows. `auto` = on hover / focus / drag
|
|
16
|
+
* (drag focuses the thumb in Radix), `always` = persistent, `never` = off.
|
|
17
|
+
*/
|
|
18
|
+
type SliderValueLabelMode = "auto" | "always" | "never"
|
|
19
|
+
|
|
14
20
|
function Slider({
|
|
15
21
|
className,
|
|
16
22
|
defaultValue,
|
|
@@ -19,6 +25,9 @@ function Slider({
|
|
|
19
25
|
max = 100,
|
|
20
26
|
orientation = "horizontal",
|
|
21
27
|
marks,
|
|
28
|
+
valueLabel = "never",
|
|
29
|
+
valueLabelFormat,
|
|
30
|
+
onValueChange,
|
|
22
31
|
"aria-label": ariaLabel,
|
|
23
32
|
"aria-labelledby": ariaLabelledby,
|
|
24
33
|
...props
|
|
@@ -29,6 +38,17 @@ function Slider({
|
|
|
29
38
|
* the slider's default rendering when omitted.
|
|
30
39
|
*/
|
|
31
40
|
marks?: SliderMark[]
|
|
41
|
+
/**
|
|
42
|
+
* Thumb-anchored current-value bubble (Mantine `label`, MUI
|
|
43
|
+
* `valueLabelDisplay`, Ant `tooltip`). Default `never` — the slider renders
|
|
44
|
+
* byte-identically to before when omitted. The bubble is `aria-hidden`:
|
|
45
|
+
* the thumb already announces `aria-valuenow`, and a string returned by
|
|
46
|
+
* `valueLabelFormat` is mirrored to `aria-valuetext` so screen readers hear
|
|
47
|
+
* the same formatted value.
|
|
48
|
+
*/
|
|
49
|
+
valueLabel?: SliderValueLabelMode
|
|
50
|
+
/** Formats the bubble text, e.g. `(v) => \`$${v}\``. Defaults to the raw number. */
|
|
51
|
+
valueLabelFormat?: (value: number) => React.ReactNode
|
|
32
52
|
}) {
|
|
33
53
|
const _values = React.useMemo(
|
|
34
54
|
() =>
|
|
@@ -40,6 +60,22 @@ function Slider({
|
|
|
40
60
|
[value, defaultValue, min, max]
|
|
41
61
|
)
|
|
42
62
|
|
|
63
|
+
// Mirror the live values so the value bubble can render in uncontrolled
|
|
64
|
+
// mode (Radix owns the state; we only tap onValueChange). Controlled mode
|
|
65
|
+
// reads `value` directly.
|
|
66
|
+
const [tracked, setTracked] = React.useState<number[]>(
|
|
67
|
+
() => value ?? defaultValue ?? [min]
|
|
68
|
+
)
|
|
69
|
+
const currentValues = value ?? tracked
|
|
70
|
+
const handleValueChange = React.useCallback(
|
|
71
|
+
(next: number[]) => {
|
|
72
|
+
setTracked(next)
|
|
73
|
+
onValueChange?.(next)
|
|
74
|
+
},
|
|
75
|
+
[onValueChange]
|
|
76
|
+
)
|
|
77
|
+
const showValueLabel = valueLabel !== "never"
|
|
78
|
+
|
|
43
79
|
const _marks = React.useMemo(
|
|
44
80
|
() =>
|
|
45
81
|
(marks ?? []).map((m) =>
|
|
@@ -61,10 +97,15 @@ function Slider({
|
|
|
61
97
|
min={min}
|
|
62
98
|
max={max}
|
|
63
99
|
orientation={orientation}
|
|
100
|
+
onValueChange={handleValueChange}
|
|
64
101
|
className={cn(
|
|
65
102
|
"relative flex w-full touch-none items-center select-none data-[disabled]:opacity-50 data-[orientation=vertical]:h-full data-[orientation=vertical]:min-h-44 data-[orientation=vertical]:w-auto data-[orientation=vertical]:flex-col",
|
|
66
103
|
// Reserve room for mark labels so they never overlap following content.
|
|
67
104
|
hasLabels && (isVertical ? "mr-12" : "mb-7"),
|
|
105
|
+
// A persistent value bubble sits above (or beside) the thumb — reserve
|
|
106
|
+
// room for it the same way. `auto` bubbles are transient, like a
|
|
107
|
+
// tooltip, so they may overlap and reserve nothing.
|
|
108
|
+
valueLabel === "always" && (isVertical ? "mr-16" : "mt-9"),
|
|
68
109
|
className
|
|
69
110
|
)}
|
|
70
111
|
{...props}
|
|
@@ -150,14 +191,53 @@ function Slider({
|
|
|
150
191
|
ariaLabel && _values.length > 1
|
|
151
192
|
? `${ariaLabel} ${index === 0 ? "minimum" : "maximum"}`
|
|
152
193
|
: ariaLabel
|
|
194
|
+
const rawValue = currentValues[index] ?? min
|
|
195
|
+
const formatted = valueLabelFormat ? valueLabelFormat(rawValue) : rawValue
|
|
196
|
+
// Only a string/number formatter result can be announced; a ReactNode
|
|
197
|
+
// label falls back to Radix's own aria-valuenow.
|
|
198
|
+
const valueText =
|
|
199
|
+
valueLabelFormat &&
|
|
200
|
+
(typeof formatted === "string" || typeof formatted === "number")
|
|
201
|
+
? String(formatted)
|
|
202
|
+
: undefined
|
|
153
203
|
return (
|
|
154
204
|
<SliderPrimitive.Thumb
|
|
155
205
|
data-slot="slider-thumb"
|
|
156
206
|
key={index}
|
|
157
207
|
aria-label={thumbLabel}
|
|
158
208
|
aria-labelledby={ariaLabelledby}
|
|
159
|
-
|
|
160
|
-
|
|
209
|
+
aria-valuetext={valueText}
|
|
210
|
+
className="group/thumb relative block size-8 shrink-0 rounded-full border-2 border-primary bg-white shadow-sm ring-ring/50 transition-[color,box-shadow] hover:ring-4 focus-visible:ring-4 focus-visible:outline-hidden disabled:pointer-events-none disabled:opacity-50"
|
|
211
|
+
>
|
|
212
|
+
{showValueLabel && (
|
|
213
|
+
// Inverted surface, same audited pair Tooltip uses
|
|
214
|
+
// (bg-foreground / text-background). aria-hidden: the thumb
|
|
215
|
+
// announces the value. Pattern-c motion for the fade + lift.
|
|
216
|
+
<span
|
|
217
|
+
data-slot="slider-value-label"
|
|
218
|
+
aria-hidden
|
|
219
|
+
className={cn(
|
|
220
|
+
"pointer-events-none absolute rounded-md bg-foreground px-2 py-0.5 text-xs font-medium whitespace-nowrap tabular-nums text-background shadow-sm transition-[opacity,transform]",
|
|
221
|
+
isVertical
|
|
222
|
+
? "top-1/2 left-full ml-3 -translate-y-1/2"
|
|
223
|
+
: "bottom-full left-1/2 mb-2 -translate-x-1/2",
|
|
224
|
+
valueLabel === "auto" &&
|
|
225
|
+
cn(
|
|
226
|
+
"opacity-0 group-hover/thumb:opacity-100 group-focus/thumb:opacity-100",
|
|
227
|
+
isVertical
|
|
228
|
+
? "translate-x-1 group-hover/thumb:translate-x-0 group-focus/thumb:translate-x-0"
|
|
229
|
+
: "translate-y-1 group-hover/thumb:translate-y-0 group-focus/thumb:translate-y-0"
|
|
230
|
+
)
|
|
231
|
+
)}
|
|
232
|
+
style={{
|
|
233
|
+
transitionDuration: "var(--duration-fast)",
|
|
234
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
235
|
+
}}
|
|
236
|
+
>
|
|
237
|
+
{formatted}
|
|
238
|
+
</span>
|
|
239
|
+
)}
|
|
240
|
+
</SliderPrimitive.Thumb>
|
|
161
241
|
)
|
|
162
242
|
})}
|
|
163
243
|
</SliderPrimitive.Root>
|
|
@@ -165,4 +245,4 @@ function Slider({
|
|
|
165
245
|
}
|
|
166
246
|
|
|
167
247
|
export { Slider }
|
|
168
|
-
export type { SliderMark }
|
|
248
|
+
export type { SliderMark, SliderValueLabelMode }
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
} from "recharts"
|
|
13
13
|
|
|
14
14
|
import { cn } from "../../lib/utils"
|
|
15
|
+
import { useReducedMotion } from "../../hooks/use-reduced-motion"
|
|
15
16
|
|
|
16
17
|
export interface SparklineProps extends React.ComponentProps<"span"> {
|
|
17
18
|
/**
|
|
@@ -49,19 +50,6 @@ export interface SparklineProps extends React.ComponentProps<"span"> {
|
|
|
49
50
|
// Each Sparkline instance gets its own gradient so multiple sparklines on
|
|
50
51
|
// the same page don't share gradient ids and create incorrect fill colors.
|
|
51
52
|
|
|
52
|
-
function usePrefersReducedMotion(): boolean {
|
|
53
|
-
const [reduced, setReduced] = React.useState(false)
|
|
54
|
-
React.useEffect(() => {
|
|
55
|
-
if (typeof window === "undefined" || !window.matchMedia) return
|
|
56
|
-
const mql = window.matchMedia("(prefers-reduced-motion: reduce)")
|
|
57
|
-
setReduced(mql.matches)
|
|
58
|
-
const onChange = (e: MediaQueryListEvent) => setReduced(e.matches)
|
|
59
|
-
mql.addEventListener("change", onChange)
|
|
60
|
-
return () => mql.removeEventListener("change", onChange)
|
|
61
|
-
}, [])
|
|
62
|
-
return reduced
|
|
63
|
-
}
|
|
64
|
-
|
|
65
53
|
/**
|
|
66
54
|
* Compact inline sparkline for trend visualization. Renders a mini area or
|
|
67
55
|
* line chart with no axes, no labels, and no tooltip — just the data shape.
|
|
@@ -91,7 +79,7 @@ function Sparkline({
|
|
|
91
79
|
const uniqueId = React.useId()
|
|
92
80
|
const gradientId = `sparkline-grad-${uniqueId.replace(/:/g, "")}`
|
|
93
81
|
|
|
94
|
-
const prefersReducedMotion =
|
|
82
|
+
const prefersReducedMotion = useReducedMotion()
|
|
95
83
|
const animate = !prefersReducedMotion
|
|
96
84
|
|
|
97
85
|
// ResizeObserver gate — same pattern as ChartContainer.
|
|
@@ -36,6 +36,17 @@ interface TextareaProps
|
|
|
36
36
|
maxLength?: number
|
|
37
37
|
/** Label id for the character count `<output>` element. Auto-derived when omitted. */
|
|
38
38
|
countId?: string
|
|
39
|
+
/**
|
|
40
|
+
* Cap auto-grow height at this many text rows. Works in tandem with
|
|
41
|
+
* `field-sizing-content` (the CSS auto-resize baseline): the textarea
|
|
42
|
+
* still grows freely up to this limit, then scrolls.
|
|
43
|
+
*
|
|
44
|
+
* Uses 1lh (line height) units for precision. 1lh resolves to the
|
|
45
|
+
* element's computed line-height so the cap tracks the font size.
|
|
46
|
+
*
|
|
47
|
+
* Peer parity: Mantine autosize maxRows, MUI maxRows, Ant Design autoSize.maxRows.
|
|
48
|
+
*/
|
|
49
|
+
maxRows?: number
|
|
39
50
|
}
|
|
40
51
|
|
|
41
52
|
function Textarea({
|
|
@@ -44,6 +55,7 @@ function Textarea({
|
|
|
44
55
|
showCount = false,
|
|
45
56
|
maxLength,
|
|
46
57
|
countId,
|
|
58
|
+
maxRows,
|
|
47
59
|
onChange,
|
|
48
60
|
defaultValue,
|
|
49
61
|
value,
|
|
@@ -69,7 +81,22 @@ function Textarea({
|
|
|
69
81
|
data-slot="textarea"
|
|
70
82
|
maxLength={maxLength}
|
|
71
83
|
aria-describedby={showCount ? resolvedCountId : undefined}
|
|
72
|
-
className={cn(
|
|
84
|
+
className={cn(
|
|
85
|
+
textareaVariants({ size }),
|
|
86
|
+
// When maxRows is set, cap the auto-grow height and let excess scroll.
|
|
87
|
+
maxRows != null && "overflow-y-auto",
|
|
88
|
+
className
|
|
89
|
+
)}
|
|
90
|
+
style={
|
|
91
|
+
maxRows != null
|
|
92
|
+
? {
|
|
93
|
+
// 1lh = computed line-height (Chrome 109+, Safari 16.4+).
|
|
94
|
+
// totalPy accounts for the top + bottom padding of each size tier.
|
|
95
|
+
// 2px covers the 1px border on each side.
|
|
96
|
+
maxHeight: `calc(${maxRows} * 1lh + ${{ sm: "0.75rem", default: "1rem", lg: "1.25rem", xl: "1.5rem" }[String(size ?? "default")] ?? "1rem"} + 2px)`,
|
|
97
|
+
}
|
|
98
|
+
: undefined
|
|
99
|
+
}
|
|
73
100
|
value={value}
|
|
74
101
|
defaultValue={defaultValue}
|
|
75
102
|
onChange={handleChange}
|
package/src/data/docs-index.ts
CHANGED
|
@@ -39,6 +39,7 @@ export const DOCS_INDEX: DocGroup[] = [
|
|
|
39
39
|
entries: [
|
|
40
40
|
{ title: "README", path: "README.md", summary: "The first thing to read — what BADS is, how to run it, where to look next." },
|
|
41
41
|
{ title: "Brief", path: "BRIEF.md", summary: "The one-pager — what BADS is, who it's for, what it refuses." },
|
|
42
|
+
{ title: "Product record", path: "PRODUCT.md", summary: "Durable product truth for the design skills: users, positioning, constraints, principles, and what must never be fabricated." },
|
|
42
43
|
{ title: "Design system stack", path: "DESIGN_SYSTEM_STACK.md", summary: "The 10-layer architecture in one document." },
|
|
43
44
|
{ title: "Tech stack", path: "docs/tech-stack.md", summary: "What BADS is built on and why — framework, tokens, testing, AI layer — plus the 30-second spoken answer." },
|
|
44
45
|
{ title: "Sync model", path: "BADS_SYNC.md", summary: "How forks pull upstream BADS improvements." },
|
|
@@ -17,10 +17,16 @@ export function prefersReducedMotion(): boolean {
|
|
|
17
17
|
);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Reactive reduced-motion preference. Starts `false` (SSR and first client
|
|
22
|
+
* render agree), then tracks the media query. Guarded on `matchMedia` for
|
|
23
|
+
* environments that don't implement it, matching `prefersReducedMotion()`.
|
|
24
|
+
*/
|
|
20
25
|
export function useReducedMotion(): boolean {
|
|
21
26
|
const [reduced, setReduced] = React.useState(false);
|
|
22
27
|
|
|
23
28
|
React.useEffect(() => {
|
|
29
|
+
if (typeof window.matchMedia !== "function") return;
|
|
24
30
|
const mql = window.matchMedia(QUERY);
|
|
25
31
|
const update = () => setReduced(mql.matches);
|
|
26
32
|
update();
|