@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.
- package/package.json +5 -2
- package/scripts/build-tokens.cjs +79 -5
- package/src/app/preview/components/page.tsx +4474 -208
- package/src/app/shell.tsx +18 -6
- package/src/components/customize/brand-mark-section.tsx +1 -1
- package/src/components/customize-tab.tsx +2 -2
- package/src/components/home-tab.tsx +2 -2
- package/src/components/ui/action-bar.tsx +142 -0
- package/src/components/ui/affix.tsx +109 -0
- package/src/components/ui/alert.tsx +37 -3
- package/src/components/ui/anchor.tsx +136 -0
- package/src/components/ui/angle-slider.tsx +265 -0
- package/src/components/ui/autocomplete.tsx +223 -0
- package/src/components/ui/avatar.tsx +8 -2
- package/src/components/ui/blockquote.tsx +112 -0
- package/src/components/ui/bottom-navigation.tsx +144 -0
- package/src/components/ui/burger.tsx +117 -0
- package/src/components/ui/button.tsx +101 -3
- package/src/components/ui/calendar.tsx +1 -1
- package/src/components/ui/card.tsx +43 -5
- package/src/components/ui/carousel.tsx +10 -5
- package/src/components/ui/cascader.tsx +253 -0
- package/src/components/ui/checkbox-card.tsx +176 -0
- package/src/components/ui/checkbox-group.tsx +231 -0
- package/src/components/ui/checkbox.tsx +14 -3
- package/src/components/ui/chip.tsx +143 -0
- package/src/components/ui/circular-progress.tsx +2 -2
- package/src/components/ui/color-swatch.tsx +73 -0
- package/src/components/ui/copy-button.tsx +21 -4
- package/src/components/ui/date-picker.tsx +6 -3
- package/src/components/ui/date-range-picker.tsx +6 -3
- package/src/components/ui/float-label.tsx +114 -0
- package/src/components/ui/floating-panel.tsx +129 -0
- package/src/components/ui/format-number.tsx +122 -0
- package/src/components/ui/highlight.tsx +85 -0
- package/src/components/ui/image.tsx +195 -0
- package/src/components/ui/index.ts +50 -0
- package/src/components/ui/indicator.tsx +2 -2
- package/src/components/ui/input.tsx +48 -4
- package/src/components/ui/kbd.tsx +1 -1
- package/src/components/ui/link.tsx +158 -0
- package/src/components/ui/listbox.tsx +426 -0
- package/src/components/ui/loading-overlay.tsx +80 -0
- package/src/components/ui/marquee.tsx +193 -0
- package/src/components/ui/masonry.tsx +164 -0
- package/src/components/ui/meter.tsx +186 -0
- package/src/components/ui/motion-toggle.tsx +170 -0
- package/src/components/ui/notification.tsx +175 -0
- package/src/components/ui/overlay.tsx +63 -0
- package/src/components/ui/progress.tsx +95 -4
- package/src/components/ui/rating-group.tsx +1 -0
- package/src/components/ui/separator.tsx +57 -1
- package/src/components/ui/sidebar.tsx +1 -1
- package/src/components/ui/signature-pad.tsx +381 -0
- package/src/components/ui/skeleton.tsx +59 -2
- package/src/components/ui/skip-link.tsx +117 -0
- package/src/components/ui/slider.tsx +86 -1
- package/src/components/ui/spoiler.tsx +131 -0
- package/src/components/ui/tabs.tsx +1 -1
- package/src/components/ui/text.tsx +135 -0
- package/src/components/ui/textarea.tsx +66 -2
- package/src/components/ui/timeline.tsx +71 -14
- package/src/components/ui/timer.tsx +183 -0
- package/src/components/ui/tour.tsx +332 -0
- package/src/components/ui/transfer-list.tsx +308 -0
- package/src/components/ui/visually-hidden.tsx +42 -0
- package/src/components/ui/watermark.tsx +0 -0
- package/src/data/docs-index.ts +9 -2
- package/src/stories/ActionBar.stories.tsx +201 -0
- package/src/stories/Affix.stories.tsx +165 -0
- package/src/stories/Alert.stories.tsx +58 -0
- package/src/stories/Anchor.stories.tsx +236 -0
- package/src/stories/AngleSlider.stories.tsx +128 -0
- package/src/stories/Autocomplete.stories.tsx +216 -0
- package/src/stories/Avatar.stories.tsx +73 -1
- package/src/stories/Blockquote.stories.tsx +148 -0
- package/src/stories/BottomNavigation.stories.tsx +195 -0
- package/src/stories/Burger.stories.tsx +79 -0
- package/src/stories/Button.stories.tsx +103 -2
- package/src/stories/Calendar.stories.tsx +4 -0
- package/src/stories/Card.stories.tsx +30 -0
- package/src/stories/Carousel.stories.tsx +2 -1
- package/src/stories/Cascader.stories.tsx +285 -0
- package/src/stories/Checkbox.stories.tsx +13 -0
- package/src/stories/CheckboxCard.stories.tsx +210 -0
- package/src/stories/CheckboxGroup.stories.tsx +186 -0
- package/src/stories/Chip.stories.tsx +173 -0
- package/src/stories/CircularProgress.stories.tsx +3 -0
- package/src/stories/ColorSwatch.stories.tsx +81 -0
- package/src/stories/CopyButton.stories.tsx +3 -3
- package/src/stories/DatePicker.stories.tsx +3 -0
- package/src/stories/DateRangePicker.stories.tsx +3 -0
- package/src/stories/Editable.stories.tsx +14 -0
- package/src/stories/FloatLabel.stories.tsx +148 -0
- package/src/stories/FloatingPanel.stories.tsx +176 -0
- package/src/stories/FormatNumber.stories.tsx +308 -0
- package/src/stories/Highlight.stories.tsx +140 -0
- package/src/stories/Image.stories.tsx +141 -0
- package/src/stories/Indicator.stories.tsx +3 -0
- package/src/stories/Input.stories.tsx +33 -0
- package/src/stories/Kbd.stories.tsx +3 -0
- package/src/stories/Link.stories.tsx +198 -0
- package/src/stories/Listbox.stories.tsx +240 -0
- package/src/stories/LoadingOverlay.stories.tsx +148 -0
- package/src/stories/Marquee.stories.tsx +170 -0
- package/src/stories/Masonry.stories.tsx +227 -0
- package/src/stories/Meter.stories.tsx +143 -0
- package/src/stories/MotionToggle.stories.tsx +85 -0
- package/src/stories/Notification.stories.tsx +264 -0
- package/src/stories/Overlay.stories.tsx +169 -0
- package/src/stories/PasswordInput.stories.tsx +4 -0
- package/src/stories/Progress.stories.tsx +70 -27
- package/src/stories/RatingGroup.stories.tsx +5 -0
- package/src/stories/Separator.stories.tsx +41 -5
- package/src/stories/Sidebar.stories.tsx +2 -1
- package/src/stories/SignaturePad.stories.tsx +112 -0
- package/src/stories/Skeleton.stories.tsx +23 -4
- package/src/stories/SkipLink.stories.tsx +137 -0
- package/src/stories/Slider.stories.tsx +28 -0
- package/src/stories/Spoiler.stories.tsx +122 -0
- package/src/stories/Tabs.stories.tsx +2 -1
- package/src/stories/Text.stories.tsx +191 -0
- package/src/stories/Textarea.stories.tsx +58 -6
- package/src/stories/Timeline.stories.tsx +82 -0
- package/src/stories/Timer.stories.tsx +160 -0
- package/src/stories/Tour.stories.tsx +191 -0
- package/src/stories/TransferList.stories.tsx +169 -0
- package/src/stories/VisuallyHidden.stories.tsx +105 -0
- package/src/stories/Watermark.stories.tsx +212 -0
- package/src/styles.css +80 -6
- package/src/tokens.json +2 -2
|
@@ -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
|
+
// Dim on the wrapper when a header exists (so label + value dim
|
|
122
|
+
// too) — dimming both would compound to 25% opacity.
|
|
123
|
+
disabled && !hasHeader && "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={cn("flex w-full flex-col gap-2", disabled && "opacity-50")}
|
|
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 }
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { Monitor, Pause, Play } from "lucide-react";
|
|
5
|
+
|
|
6
|
+
import { cn } from "../../lib/utils";
|
|
7
|
+
import { storageKey, readMigrated } from "../../lib/storage";
|
|
8
|
+
import {
|
|
9
|
+
SegmentedControl,
|
|
10
|
+
SegmentedControlItem,
|
|
11
|
+
} from "./segmented-control";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Motion preference, mirrored onto the `data-motion` attribute the base layer
|
|
15
|
+
* reads (see `packages/core/scripts/build-tokens.cjs` → the reduced-motion
|
|
16
|
+
* block). Three states, not a boolean, because "off" is ambiguous when the OS
|
|
17
|
+
* is already reducing motion:
|
|
18
|
+
* • `system` — no attribute; the OS `prefers-reduced-motion` query governs.
|
|
19
|
+
* • `reduce` — force motion OFF on this site regardless of the OS.
|
|
20
|
+
* • `full` — force motion ON even if the OS prefers reduce (some users set
|
|
21
|
+
* OS reduce globally but trust a given site with motion).
|
|
22
|
+
*/
|
|
23
|
+
export type MotionPreference = "system" | "reduce" | "full";
|
|
24
|
+
|
|
25
|
+
const OPTIONS: {
|
|
26
|
+
value: MotionPreference;
|
|
27
|
+
label: string;
|
|
28
|
+
icon: React.ReactNode;
|
|
29
|
+
hint: string;
|
|
30
|
+
}[] = [
|
|
31
|
+
{
|
|
32
|
+
value: "system",
|
|
33
|
+
label: "System",
|
|
34
|
+
icon: <Monitor />,
|
|
35
|
+
hint: "Follow your device's reduce-motion setting.",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
value: "reduce",
|
|
39
|
+
label: "Reduced",
|
|
40
|
+
icon: <Pause />,
|
|
41
|
+
hint: "Turn off animations on this site.",
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
value: "full",
|
|
45
|
+
label: "Full",
|
|
46
|
+
icon: <Play />,
|
|
47
|
+
hint: "Keep animations even if your device reduces motion.",
|
|
48
|
+
},
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Reflect a preference onto <html>. `system` REMOVES the attribute so the OS
|
|
53
|
+
* media query is the sole authority again — setting `data-motion="system"`
|
|
54
|
+
* would be inert but leaves a stale attribute around, so we clear it.
|
|
55
|
+
*/
|
|
56
|
+
function applyMotionPreference(pref: MotionPreference) {
|
|
57
|
+
if (typeof document === "undefined") return;
|
|
58
|
+
const root = document.documentElement;
|
|
59
|
+
if (pref === "system") root.removeAttribute("data-motion");
|
|
60
|
+
else root.setAttribute("data-motion", pref);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface MotionToggleProps {
|
|
64
|
+
/**
|
|
65
|
+
* localStorage suffix, prefixed per-fork via `storageKey()` (e.g.
|
|
66
|
+
* `BADS.motion` / `CLAP.motion`). Default `"motion"`.
|
|
67
|
+
*/
|
|
68
|
+
storageSuffix?: string;
|
|
69
|
+
/** Size passthrough to the underlying SegmentedControl. */
|
|
70
|
+
size?: "sm" | "default" | "lg";
|
|
71
|
+
/** Fires after a new preference is applied + persisted. */
|
|
72
|
+
onPreferenceChange?: (pref: MotionPreference) => void;
|
|
73
|
+
/**
|
|
74
|
+
* Render the active option's one-line hint as muted helper text beneath the
|
|
75
|
+
* control. Off by default so the bare control stays compact; the showcase
|
|
76
|
+
* and settings surfaces turn it on.
|
|
77
|
+
*/
|
|
78
|
+
showHint?: boolean;
|
|
79
|
+
/** Accessible label for the radiogroup. Default `"Motion"`. */
|
|
80
|
+
label?: string;
|
|
81
|
+
className?: string;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* In-app motion preference control — an **opt-in** companion to the OS
|
|
86
|
+
* reduce-motion setting. NOT mounted in the default BADS shell; a fork drops
|
|
87
|
+
* it into its own settings/appearance surface when it wants to give users an
|
|
88
|
+
* in-product motion switch (some users can't change their OS setting, or want
|
|
89
|
+
* to override it for one site).
|
|
90
|
+
*
|
|
91
|
+
* Composes {@link SegmentedControl} (radiogroup semantics, roving tabindex,
|
|
92
|
+
* token-driven sliding indicator) and persists to localStorage via the
|
|
93
|
+
* shared `storageKey`/`readMigrated` helpers, so a renamed fork keeps its
|
|
94
|
+
* per-slug prefix. The base layer does the actual motion suppression off the
|
|
95
|
+
* `data-motion` attribute this writes — the component only owns state, not the
|
|
96
|
+
* `!important` kill rules.
|
|
97
|
+
*
|
|
98
|
+
* Flash caveat: the preference is read in an effect, so a user who chose
|
|
99
|
+
* `reduce` while their OS does NOT prefer reduce may see one frame of motion on
|
|
100
|
+
* first load before the attribute lands. Users who set OS reduce see no flash
|
|
101
|
+
* (pure-CSS suppression, no JS needed). A fork wanting zero-flash for the
|
|
102
|
+
* in-app override can mirror this read in its existing theme-init inline
|
|
103
|
+
* `<head>` script, after `window.__BADS_SLUG__` is set.
|
|
104
|
+
*/
|
|
105
|
+
export function MotionToggle({
|
|
106
|
+
storageSuffix = "motion",
|
|
107
|
+
size = "default",
|
|
108
|
+
onPreferenceChange,
|
|
109
|
+
showHint = false,
|
|
110
|
+
label = "Motion",
|
|
111
|
+
className,
|
|
112
|
+
}: MotionToggleProps) {
|
|
113
|
+
const [pref, setPref] = React.useState<MotionPreference>("system");
|
|
114
|
+
|
|
115
|
+
// Hydrate from storage on mount and reflect it onto <html>. Client-only;
|
|
116
|
+
// SSR renders the `system` default (no attribute), matching the pre-toggle
|
|
117
|
+
// behavior so there's no hydration mismatch for forks that don't persist a
|
|
118
|
+
// value yet.
|
|
119
|
+
React.useEffect(() => {
|
|
120
|
+
const stored = readMigrated(storageSuffix);
|
|
121
|
+
if (stored === "reduce" || stored === "full" || stored === "system") {
|
|
122
|
+
setPref(stored);
|
|
123
|
+
applyMotionPreference(stored);
|
|
124
|
+
}
|
|
125
|
+
}, [storageSuffix]);
|
|
126
|
+
|
|
127
|
+
const handleChange = (value: string) => {
|
|
128
|
+
const next = value as MotionPreference;
|
|
129
|
+
setPref(next);
|
|
130
|
+
applyMotionPreference(next);
|
|
131
|
+
try {
|
|
132
|
+
window.localStorage.setItem(storageKey(storageSuffix), next);
|
|
133
|
+
} catch {
|
|
134
|
+
// Quota exceeded / privacy mode — the in-memory + attribute state still
|
|
135
|
+
// applies for this session; only cross-reload persistence is lost.
|
|
136
|
+
}
|
|
137
|
+
onPreferenceChange?.(next);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const activeHint = OPTIONS.find((o) => o.value === pref)?.hint;
|
|
141
|
+
|
|
142
|
+
return (
|
|
143
|
+
<div className={cn("inline-flex flex-col gap-1.5", className)}>
|
|
144
|
+
<SegmentedControl
|
|
145
|
+
value={pref}
|
|
146
|
+
onValueChange={handleChange}
|
|
147
|
+
size={size}
|
|
148
|
+
label={label}
|
|
149
|
+
>
|
|
150
|
+
{OPTIONS.map((o) => (
|
|
151
|
+
<SegmentedControlItem
|
|
152
|
+
key={o.value}
|
|
153
|
+
value={o.value}
|
|
154
|
+
icon={o.icon}
|
|
155
|
+
title={o.hint}
|
|
156
|
+
>
|
|
157
|
+
{o.label}
|
|
158
|
+
</SegmentedControlItem>
|
|
159
|
+
))}
|
|
160
|
+
</SegmentedControl>
|
|
161
|
+
{showHint && activeHint ? (
|
|
162
|
+
// aria-live so the reason for the current mode is announced when the
|
|
163
|
+
// selection changes (the title tooltip isn't keyboard-reachable).
|
|
164
|
+
<p className="text-xs text-muted-foreground" aria-live="polite">
|
|
165
|
+
{activeHint}
|
|
166
|
+
</p>
|
|
167
|
+
) : null}
|
|
168
|
+
</div>
|
|
169
|
+
);
|
|
170
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
3
|
+
import { X } from "lucide-react"
|
|
4
|
+
|
|
5
|
+
import { cn } from "../../lib/utils"
|
|
6
|
+
import { Spinner } from "./spinner"
|
|
7
|
+
|
|
8
|
+
// Notification is the persisted feed/inbox item between Alert (static inline
|
|
9
|
+
// callout, role="alert", no dismiss) and Sonner (ephemeral auto-dismissing
|
|
10
|
+
// toast overlay). It shares their 4px left-accent-bar visual language so the
|
|
11
|
+
// three status surfaces read as one family.
|
|
12
|
+
//
|
|
13
|
+
// NOTE: the accent colors use arbitrary `border-l-[var(--token)]` with `!`,
|
|
14
|
+
// NOT the named `border-l-primary` utilities — in this Tailwind v4 setup the
|
|
15
|
+
// named border-color utilities don't emit a rule (see alert.tsx for the full
|
|
16
|
+
// story), so the accent would silently fall through to the `:root *`
|
|
17
|
+
// border-border reset. Also load-bearing: `--success` / `--warning` are oklch
|
|
18
|
+
// tokens, so they're consumed as `[var(--success)]` — wrapping them in
|
|
19
|
+
// `hsl(var(--success))` produces invalid CSS that fails silently.
|
|
20
|
+
const notificationVariants = cva(
|
|
21
|
+
// The variant hue lives ONLY in the non-text accent bar + icon (both
|
|
22
|
+
// audited ≥3:1 non-text). Title/description/timestamp stay foreground /
|
|
23
|
+
// muted-foreground in every variant so text holds the AAA 7:1 floor.
|
|
24
|
+
"relative flex w-full gap-3 overflow-hidden rounded-lg border border-border border-l-4 bg-card px-4 py-3 text-sm transition-[background-color,opacity]",
|
|
25
|
+
{
|
|
26
|
+
variants: {
|
|
27
|
+
variant: {
|
|
28
|
+
default:
|
|
29
|
+
"border-l-[var(--primary)]! bg-primary/5 dark:bg-primary/10 [&_[data-slot=notification-icon]]:text-primary",
|
|
30
|
+
destructive:
|
|
31
|
+
"border-l-[var(--destructive)]! bg-destructive/5 dark:bg-destructive/10 [&_[data-slot=notification-icon]]:text-destructive",
|
|
32
|
+
success:
|
|
33
|
+
"border-l-[var(--success)]! bg-[var(--success)]/5 dark:bg-[var(--success)]/10 [&_[data-slot=notification-icon]]:text-[var(--success)]",
|
|
34
|
+
warning:
|
|
35
|
+
"border-l-[var(--warning)]! bg-[var(--warning)]/5 dark:bg-[var(--warning)]/10 [&_[data-slot=notification-icon]]:text-[var(--warning)]",
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
defaultVariants: {
|
|
39
|
+
variant: "default",
|
|
40
|
+
},
|
|
41
|
+
}
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
// Omit the native div `title` (a tooltip string) — Notification's `title` is
|
|
45
|
+
// the ReactNode heading of the card.
|
|
46
|
+
type NotificationProps = Omit<React.ComponentProps<"div">, "title"> &
|
|
47
|
+
VariantProps<typeof notificationVariants> & {
|
|
48
|
+
/** Optional heading. Rendered single-line with truncation. */
|
|
49
|
+
title?: React.ReactNode
|
|
50
|
+
/** Body text below the title. */
|
|
51
|
+
description?: React.ReactNode
|
|
52
|
+
/** Leading icon or avatar. Replaced by a Spinner while `loading`. */
|
|
53
|
+
icon?: React.ReactNode
|
|
54
|
+
/** Meta line, e.g. "2 min ago" / "Just now". */
|
|
55
|
+
timestamp?: React.ReactNode
|
|
56
|
+
/** Marks the item unread: renders the dot indicator + `data-unread`. */
|
|
57
|
+
unread?: boolean
|
|
58
|
+
/** Shows a Spinner in the icon slot and sets `aria-busy` on the root. */
|
|
59
|
+
loading?: boolean
|
|
60
|
+
/** When provided, renders the built-in dismiss (X) button. */
|
|
61
|
+
onDismiss?: () => void
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function Notification({
|
|
65
|
+
className,
|
|
66
|
+
variant,
|
|
67
|
+
title,
|
|
68
|
+
description,
|
|
69
|
+
icon,
|
|
70
|
+
timestamp,
|
|
71
|
+
unread,
|
|
72
|
+
loading,
|
|
73
|
+
onDismiss,
|
|
74
|
+
...props
|
|
75
|
+
}: NotificationProps) {
|
|
76
|
+
// The close button needs a real string name — `title` may be a ReactNode,
|
|
77
|
+
// so only fold it into the aria-label when it's actually a string.
|
|
78
|
+
const dismissLabel =
|
|
79
|
+
typeof title === "string" ? `Dismiss: ${title}` : "Dismiss notification"
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<div
|
|
83
|
+
data-slot="notification"
|
|
84
|
+
data-unread={unread || undefined}
|
|
85
|
+
aria-busy={loading || undefined}
|
|
86
|
+
className={cn(notificationVariants({ variant }), className)}
|
|
87
|
+
// Pattern (c) motion: token-driven duration/easing resolved at runtime
|
|
88
|
+
// against :root. Never `duration-fast` (compiles to nothing in v4) or
|
|
89
|
+
// duration-[var(--x)] form (unreliable scanner pickup in v4).
|
|
90
|
+
style={{
|
|
91
|
+
transitionDuration: "var(--duration-fast)",
|
|
92
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
93
|
+
}}
|
|
94
|
+
{...props}
|
|
95
|
+
>
|
|
96
|
+
{/* Unread dot — decorative; machine-readable state is `data-unread`
|
|
97
|
+
on the root. Positioned clear of the dismiss button. */}
|
|
98
|
+
{unread && (
|
|
99
|
+
<span
|
|
100
|
+
aria-hidden="true"
|
|
101
|
+
data-slot="notification-unread-dot"
|
|
102
|
+
className={cn(
|
|
103
|
+
"absolute top-3 size-2 shrink-0 rounded-full bg-primary",
|
|
104
|
+
onDismiss ? "right-10" : "right-3"
|
|
105
|
+
)}
|
|
106
|
+
/>
|
|
107
|
+
)}
|
|
108
|
+
|
|
109
|
+
{/* Icon / avatar slot. Spinner takes over while loading. */}
|
|
110
|
+
{(icon || loading) && (
|
|
111
|
+
<div
|
|
112
|
+
data-slot="notification-icon"
|
|
113
|
+
className="mt-0.5 shrink-0 [&>svg]:size-5 [&_svg]:shrink-0"
|
|
114
|
+
>
|
|
115
|
+
{loading ? <Spinner size="sm" variant="muted" /> : icon}
|
|
116
|
+
</div>
|
|
117
|
+
)}
|
|
118
|
+
|
|
119
|
+
{/* Content column — min-w-0 so truncate can fire inside flex. */}
|
|
120
|
+
<div className="min-w-0 flex-1 space-y-1">
|
|
121
|
+
{title && (
|
|
122
|
+
<div
|
|
123
|
+
data-slot="notification-title"
|
|
124
|
+
className="min-w-0 truncate pr-6 text-sm font-medium leading-tight text-foreground"
|
|
125
|
+
>
|
|
126
|
+
{title}
|
|
127
|
+
</div>
|
|
128
|
+
)}
|
|
129
|
+
{description && (
|
|
130
|
+
<div
|
|
131
|
+
data-slot="notification-description"
|
|
132
|
+
className="min-w-0 text-sm leading-relaxed text-muted-foreground [overflow-wrap:anywhere]"
|
|
133
|
+
>
|
|
134
|
+
{description}
|
|
135
|
+
</div>
|
|
136
|
+
)}
|
|
137
|
+
{timestamp && (
|
|
138
|
+
<div
|
|
139
|
+
data-slot="notification-timestamp"
|
|
140
|
+
className="text-xs tabular-nums text-muted-foreground"
|
|
141
|
+
>
|
|
142
|
+
{timestamp}
|
|
143
|
+
</div>
|
|
144
|
+
)}
|
|
145
|
+
</div>
|
|
146
|
+
|
|
147
|
+
{/* Built-in dismiss. A small utility action (Tag/Sonner-close class),
|
|
148
|
+
not a flow-changing CTA — so no min-h-11 (SC 2.5.5 Enhanced applies
|
|
149
|
+
only to flow-changing controls per BADS policy).
|
|
150
|
+
SC 2.5.8 AA: size-6 = 24×24px. The offset-exception applies — the
|
|
151
|
+
dismiss button is separated from the notification body text (its nearest
|
|
152
|
+
interactive neighbour) by ≥24 px of padding on all sides via ml-auto +
|
|
153
|
+
self-start layout. Mirror of the InputClearable precedent in PR #209.
|
|
154
|
+
The focus ring is instant (box-shadow deliberately excluded from the
|
|
155
|
+
transition list). */}
|
|
156
|
+
{onDismiss && (
|
|
157
|
+
<button
|
|
158
|
+
type="button"
|
|
159
|
+
data-slot="notification-dismiss"
|
|
160
|
+
aria-label={dismissLabel}
|
|
161
|
+
onClick={onDismiss}
|
|
162
|
+
className="ml-auto flex size-6 shrink-0 items-center justify-center self-start rounded-sm text-muted-foreground opacity-70 transition-[opacity,transform,color] hover:opacity-100 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 active:scale-95"
|
|
163
|
+
style={{
|
|
164
|
+
transitionDuration: "var(--duration-fast)",
|
|
165
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
166
|
+
}}
|
|
167
|
+
>
|
|
168
|
+
<X strokeWidth={1.5} className="size-4" aria-hidden="true" />
|
|
169
|
+
</button>
|
|
170
|
+
)}
|
|
171
|
+
</div>
|
|
172
|
+
)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export { Notification, notificationVariants, type NotificationProps }
|