@behavioral-agentic-design-system/core 0.23.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 +8 -4
- package/scripts/build-tokens.cjs +79 -5
- package/src/app/preview/components/page.tsx +4760 -213
- 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/data-list.tsx +169 -0
- package/src/components/ui/date-picker.tsx +6 -3
- package/src/components/ui/date-range-picker.tsx +6 -3
- package/src/components/ui/fieldset.tsx +8 -2
- 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 +52 -0
- package/src/components/ui/indicator.tsx +2 -2
- package/src/components/ui/input-group.tsx +11 -1
- 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/qr-code.tsx +107 -0
- 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 +10 -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/DataList.stories.tsx +160 -0
- 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/Fieldset.stories.tsx +4 -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/InputGroup.stories.tsx +39 -41
- 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/QrCode.stories.tsx +146 -0
- 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,144 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { cn } from "../../lib/utils";
|
|
5
|
+
|
|
6
|
+
// ─── Context ──────────────────────────────────────────────────────────────────
|
|
7
|
+
|
|
8
|
+
interface BottomNavigationContextValue {
|
|
9
|
+
value: string;
|
|
10
|
+
onValueChange: (value: string) => void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const BottomNavigationContext = React.createContext<BottomNavigationContextValue>({
|
|
14
|
+
value: "",
|
|
15
|
+
onValueChange: () => {},
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// ─── Root ─────────────────────────────────────────────────────────────────────
|
|
19
|
+
|
|
20
|
+
export interface BottomNavigationProps
|
|
21
|
+
extends Omit<React.HTMLAttributes<HTMLElement>, "onChange"> {
|
|
22
|
+
/** The value of the currently active destination. */
|
|
23
|
+
value: string;
|
|
24
|
+
/** Callback fired when the user activates a destination. */
|
|
25
|
+
onValueChange: (value: string) => void;
|
|
26
|
+
/**
|
|
27
|
+
* Accessible label for the navigation landmark. Keeps multiple nav
|
|
28
|
+
* landmarks on a page distinguishable to screen readers.
|
|
29
|
+
*/
|
|
30
|
+
label?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Fix the bar to the bottom of the viewport (z-50) and pad for the
|
|
33
|
+
* device safe-area inset. Off by default so the bar can live inside
|
|
34
|
+
* a layout container (previews, phone frames, sticky footers).
|
|
35
|
+
*/
|
|
36
|
+
fixed?: boolean;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Mobile-first bottom navigation bar — a `<nav>` landmark holding 3–5
|
|
41
|
+
* icon+label destination buttons, one of which is current.
|
|
42
|
+
*
|
|
43
|
+
* NOT a tablist: it navigates between top-level destinations
|
|
44
|
+
* (`role="navigation"` + `aria-current="page"` on the active item),
|
|
45
|
+
* it does not switch visible content panels in place. For in-place
|
|
46
|
+
* content switching use Tabs; for value picking use SegmentedControl.
|
|
47
|
+
*/
|
|
48
|
+
export function BottomNavigation({
|
|
49
|
+
value,
|
|
50
|
+
onValueChange,
|
|
51
|
+
label = "Bottom navigation",
|
|
52
|
+
fixed = false,
|
|
53
|
+
className,
|
|
54
|
+
children,
|
|
55
|
+
...props
|
|
56
|
+
}: BottomNavigationProps) {
|
|
57
|
+
return (
|
|
58
|
+
<BottomNavigationContext.Provider value={{ value, onValueChange }}>
|
|
59
|
+
<nav
|
|
60
|
+
aria-label={label}
|
|
61
|
+
data-slot="bottom-navigation"
|
|
62
|
+
className={cn(
|
|
63
|
+
"flex w-full items-stretch justify-around border-t border-border bg-background",
|
|
64
|
+
fixed && "fixed inset-x-0 bottom-0 z-50 pb-[env(safe-area-inset-bottom)]",
|
|
65
|
+
className
|
|
66
|
+
)}
|
|
67
|
+
{...props}
|
|
68
|
+
>
|
|
69
|
+
{children}
|
|
70
|
+
</nav>
|
|
71
|
+
</BottomNavigationContext.Provider>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// ─── Item ─────────────────────────────────────────────────────────────────────
|
|
76
|
+
|
|
77
|
+
export interface BottomNavigationItemProps
|
|
78
|
+
extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
79
|
+
/** The destination value this item represents. */
|
|
80
|
+
value: string;
|
|
81
|
+
/** Icon rendered above the label. Must be a Lucide icon with strokeWidth={1.5}. */
|
|
82
|
+
icon: React.ReactNode;
|
|
83
|
+
/** Visible text label. Always shown — hiding labels hurts comprehension. */
|
|
84
|
+
label: string;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function BottomNavigationItem({
|
|
88
|
+
value,
|
|
89
|
+
icon,
|
|
90
|
+
label,
|
|
91
|
+
className,
|
|
92
|
+
disabled,
|
|
93
|
+
onClick,
|
|
94
|
+
...props
|
|
95
|
+
}: BottomNavigationItemProps) {
|
|
96
|
+
const { value: activeValue, onValueChange } = React.useContext(BottomNavigationContext);
|
|
97
|
+
const isActive = activeValue === value;
|
|
98
|
+
|
|
99
|
+
return (
|
|
100
|
+
<button
|
|
101
|
+
type="button"
|
|
102
|
+
aria-current={isActive ? "page" : undefined}
|
|
103
|
+
data-slot="bottom-navigation-item"
|
|
104
|
+
data-state={isActive ? "active" : "inactive"}
|
|
105
|
+
disabled={disabled}
|
|
106
|
+
onClick={(event) => {
|
|
107
|
+
onClick?.(event);
|
|
108
|
+
if (!event.defaultPrevented && !disabled) onValueChange(value);
|
|
109
|
+
}}
|
|
110
|
+
className={cn(
|
|
111
|
+
"group flex min-h-14 min-w-16 flex-1 cursor-pointer select-none flex-col items-center justify-center gap-0.5 px-2 py-1.5",
|
|
112
|
+
"text-muted-foreground transition-colors",
|
|
113
|
+
"hover:text-foreground",
|
|
114
|
+
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",
|
|
115
|
+
"disabled:pointer-events-none disabled:opacity-50",
|
|
116
|
+
"data-[state=active]:text-primary",
|
|
117
|
+
className
|
|
118
|
+
)}
|
|
119
|
+
style={{
|
|
120
|
+
transitionDuration: "var(--duration-fast)",
|
|
121
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
122
|
+
}}
|
|
123
|
+
{...props}
|
|
124
|
+
>
|
|
125
|
+
<span
|
|
126
|
+
aria-hidden="true"
|
|
127
|
+
data-slot="bottom-navigation-icon"
|
|
128
|
+
className="shrink-0 transition-transform group-data-[state=active]:-translate-y-0.5 [&>svg]:size-5 [&>svg]:stroke-[1.5]"
|
|
129
|
+
style={{
|
|
130
|
+
transitionDuration: "var(--duration-base)",
|
|
131
|
+
transitionTimingFunction: "var(--ease-spring)",
|
|
132
|
+
}}
|
|
133
|
+
>
|
|
134
|
+
{icon}
|
|
135
|
+
</span>
|
|
136
|
+
<span
|
|
137
|
+
data-slot="bottom-navigation-label"
|
|
138
|
+
className="max-w-full truncate text-xs font-medium group-data-[state=active]:font-semibold"
|
|
139
|
+
>
|
|
140
|
+
{label}
|
|
141
|
+
</span>
|
|
142
|
+
</button>
|
|
143
|
+
);
|
|
144
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
|
|
5
|
+
import { cn } from "../../lib/utils"
|
|
6
|
+
|
|
7
|
+
type BurgerSize = "sm" | "md" | "lg"
|
|
8
|
+
|
|
9
|
+
// Glyph geometry per size. The button hit area is always min-h-11/min-w-11
|
|
10
|
+
// (44×44px — SC 2.5.5 Enhanced) regardless of glyph size; only the spans scale.
|
|
11
|
+
// `travel` = span height + gap: the distance the outer spans move to meet in
|
|
12
|
+
// the middle before rotating into the X.
|
|
13
|
+
const sizeMap: Record<
|
|
14
|
+
BurgerSize,
|
|
15
|
+
{ span: string; gap: string; travel: number }
|
|
16
|
+
> = {
|
|
17
|
+
sm: { span: "h-0.5 w-4", gap: "gap-[3px]", travel: 5 },
|
|
18
|
+
md: { span: "h-0.5 w-5", gap: "gap-[4px]", travel: 6 },
|
|
19
|
+
lg: { span: "h-[3px] w-6", gap: "gap-[5px]", travel: 8 },
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface BurgerProps
|
|
23
|
+
extends Omit<React.ComponentProps<"button">, "aria-label"> {
|
|
24
|
+
/** Controlled open state — true renders the X, false the hamburger. */
|
|
25
|
+
opened?: boolean
|
|
26
|
+
/** Glyph size. The 44×44px touch target is constant across sizes. */
|
|
27
|
+
size?: BurgerSize
|
|
28
|
+
/**
|
|
29
|
+
* Required — the button has no visible text. Name what it controls
|
|
30
|
+
* (e.g. "Toggle navigation"), and pass `aria-controls` with the id of
|
|
31
|
+
* the menu/sheet/drawer it opens.
|
|
32
|
+
*/
|
|
33
|
+
"aria-label": string
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Shared inline motion tokens for the span morph (pattern c — inline style
|
|
37
|
+
// with CSS vars; resolves against :root, propagates via `pnpm build:tokens`).
|
|
38
|
+
const spanMotion: React.CSSProperties = {
|
|
39
|
+
transitionDuration: "var(--duration-base)",
|
|
40
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const Burger = React.forwardRef<HTMLButtonElement, BurgerProps>(
|
|
44
|
+
function Burger(
|
|
45
|
+
{ opened = false, size = "md", className, ...props },
|
|
46
|
+
ref
|
|
47
|
+
) {
|
|
48
|
+
const { span, gap, travel } = sizeMap[size]
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<button
|
|
52
|
+
ref={ref}
|
|
53
|
+
type="button"
|
|
54
|
+
data-slot="burger"
|
|
55
|
+
data-state={opened ? "open" : "closed"}
|
|
56
|
+
aria-expanded={opened}
|
|
57
|
+
className={cn(
|
|
58
|
+
"inline-flex min-h-11 min-w-11 flex-col items-center justify-center rounded-md border border-transparent bg-transparent text-foreground outline-none transition-colors",
|
|
59
|
+
gap,
|
|
60
|
+
"hover:bg-accent hover:text-accent-foreground",
|
|
61
|
+
"focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",
|
|
62
|
+
"disabled:pointer-events-none disabled:opacity-50",
|
|
63
|
+
className
|
|
64
|
+
)}
|
|
65
|
+
style={{
|
|
66
|
+
transitionDuration: "var(--duration-fast)",
|
|
67
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
68
|
+
}}
|
|
69
|
+
{...props}
|
|
70
|
+
>
|
|
71
|
+
{/* Top span — travels down and rotates +45° into one arm of the X */}
|
|
72
|
+
<span
|
|
73
|
+
aria-hidden="true"
|
|
74
|
+
className={cn(
|
|
75
|
+
"block origin-center rounded-full bg-current transition-[transform,opacity]",
|
|
76
|
+
span
|
|
77
|
+
)}
|
|
78
|
+
style={{
|
|
79
|
+
...spanMotion,
|
|
80
|
+
transform: opened
|
|
81
|
+
? `translateY(${travel}px) rotate(45deg)`
|
|
82
|
+
: "none",
|
|
83
|
+
}}
|
|
84
|
+
/>
|
|
85
|
+
{/* Middle span — fades out; the shape morph (not the fade) carries state */}
|
|
86
|
+
<span
|
|
87
|
+
aria-hidden="true"
|
|
88
|
+
className={cn(
|
|
89
|
+
"block rounded-full bg-current transition-[transform,opacity]",
|
|
90
|
+
span,
|
|
91
|
+
opened ? "opacity-0" : "opacity-100"
|
|
92
|
+
)}
|
|
93
|
+
style={{
|
|
94
|
+
...spanMotion,
|
|
95
|
+
transform: opened ? "scaleX(0.6)" : "none",
|
|
96
|
+
}}
|
|
97
|
+
/>
|
|
98
|
+
{/* Bottom span — travels up and rotates −45° into the other arm */}
|
|
99
|
+
<span
|
|
100
|
+
aria-hidden="true"
|
|
101
|
+
className={cn(
|
|
102
|
+
"block origin-center rounded-full bg-current transition-[transform,opacity]",
|
|
103
|
+
span
|
|
104
|
+
)}
|
|
105
|
+
style={{
|
|
106
|
+
...spanMotion,
|
|
107
|
+
transform: opened
|
|
108
|
+
? `translateY(-${travel}px) rotate(-45deg)`
|
|
109
|
+
: "none",
|
|
110
|
+
}}
|
|
111
|
+
/>
|
|
112
|
+
</button>
|
|
113
|
+
)
|
|
114
|
+
}
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
export { Burger }
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import * as React from "react"
|
|
2
2
|
import { cva, type VariantProps } from "class-variance-authority"
|
|
3
3
|
import { Slot } from "@radix-ui/react-slot"
|
|
4
|
+
import { Loader2Icon } from "lucide-react"
|
|
4
5
|
|
|
5
6
|
import { cn } from "../../lib/utils"
|
|
6
7
|
|
|
7
8
|
const buttonVariants = cva(
|
|
8
|
-
"inline-flex shrink-0 items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap transition-
|
|
9
|
+
"inline-flex shrink-0 items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap transition-colors outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-disabled:opacity-50 aria-disabled:cursor-not-allowed aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
9
10
|
{
|
|
10
11
|
variants: {
|
|
11
12
|
variant: {
|
|
@@ -47,22 +48,119 @@ function Button({
|
|
|
47
48
|
variant = "default",
|
|
48
49
|
size = "default",
|
|
49
50
|
asChild = false,
|
|
51
|
+
loading = false,
|
|
52
|
+
disabled,
|
|
53
|
+
disabledReason,
|
|
54
|
+
children,
|
|
55
|
+
onClick,
|
|
56
|
+
onKeyDown,
|
|
57
|
+
"aria-describedby": ariaDescribedBy,
|
|
50
58
|
...props
|
|
51
59
|
}: React.ComponentProps<"button"> &
|
|
52
60
|
VariantProps<typeof buttonVariants> & {
|
|
53
61
|
asChild?: boolean
|
|
62
|
+
/**
|
|
63
|
+
* When true, shows a spinner ahead of the label, marks the button
|
|
64
|
+
* aria-busy, and disables it so an in-flight action can't be re-fired.
|
|
65
|
+
* Ignored with asChild (Slot requires a single child) — inject your own
|
|
66
|
+
* spinner into the slotted element in that case.
|
|
67
|
+
*/
|
|
68
|
+
loading?: boolean
|
|
69
|
+
/**
|
|
70
|
+
* Optional reason the control is unavailable. When set (and not asChild
|
|
71
|
+
* or loading), the button uses the **aria-disabled pattern** instead of
|
|
72
|
+
* native `disabled`: it STAYS focusable so keyboard / screen-reader users
|
|
73
|
+
* can reach it and hear WHY it's unavailable (a natively-`disabled` button
|
|
74
|
+
* drops out of the tab order, so the reason is undiscoverable). Activation
|
|
75
|
+
* is blocked in JS (click + Enter/Space) and the reason is announced via
|
|
76
|
+
* `aria-describedby` → an sr-only sibling (kept OUTSIDE the button so the
|
|
77
|
+
* accessible NAME stays just the label). Prefer this over `disabled` on
|
|
78
|
+
* form-gating buttons ("Submit" unavailable until required fields are
|
|
79
|
+
* filled). Ignored with `asChild` and `loading`.
|
|
80
|
+
*/
|
|
81
|
+
disabledReason?: string
|
|
54
82
|
}) {
|
|
55
83
|
const Comp = asChild ? Slot : "button"
|
|
84
|
+
const reasonId = React.useId()
|
|
85
|
+
const ariaDisabled = !asChild && !loading && Boolean(disabledReason)
|
|
56
86
|
|
|
57
|
-
|
|
87
|
+
const handleClick: React.MouseEventHandler<HTMLButtonElement> = (e) => {
|
|
88
|
+
if (ariaDisabled) {
|
|
89
|
+
e.preventDefault()
|
|
90
|
+
e.stopPropagation()
|
|
91
|
+
return
|
|
92
|
+
}
|
|
93
|
+
onClick?.(e)
|
|
94
|
+
}
|
|
95
|
+
const handleKeyDown: React.KeyboardEventHandler<HTMLButtonElement> = (e) => {
|
|
96
|
+
if (ariaDisabled && (e.key === "Enter" || e.key === " ")) {
|
|
97
|
+
e.preventDefault()
|
|
98
|
+
return
|
|
99
|
+
}
|
|
100
|
+
onKeyDown?.(e)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const button = (
|
|
58
104
|
<Comp
|
|
59
105
|
data-slot="button"
|
|
60
106
|
data-variant={variant}
|
|
61
107
|
data-size={size}
|
|
108
|
+
data-loading={loading || undefined}
|
|
109
|
+
data-disabled={ariaDisabled || undefined}
|
|
110
|
+
aria-busy={loading || undefined}
|
|
111
|
+
aria-disabled={ariaDisabled || undefined}
|
|
112
|
+
aria-describedby={
|
|
113
|
+
ariaDisabled ? cn(ariaDescribedBy, reasonId) : ariaDescribedBy
|
|
114
|
+
}
|
|
115
|
+
// Native `disabled` ONLY when not in aria-disabled mode — an aria-disabled
|
|
116
|
+
// button must stay focusable so its reason is reachable.
|
|
117
|
+
disabled={
|
|
118
|
+
Comp === "button" && !ariaDisabled ? disabled || loading : undefined
|
|
119
|
+
}
|
|
120
|
+
onClick={Comp === "button" ? handleClick : onClick}
|
|
121
|
+
onKeyDown={Comp === "button" ? handleKeyDown : onKeyDown}
|
|
62
122
|
className={cn(buttonVariants({ variant, size, className }))}
|
|
63
123
|
{...props}
|
|
64
|
-
|
|
124
|
+
>
|
|
125
|
+
{asChild ? (
|
|
126
|
+
// Slot forwards to the single child element and calls
|
|
127
|
+
// React.Children.only — it must receive exactly ONE child. Passing
|
|
128
|
+
// `children` alone (no sibling spinner-or-null) is required: a
|
|
129
|
+
// `{cond ? x : null}{children}` pair emits a 2-element array even when
|
|
130
|
+
// the first is null, which throws at render/prerender. The `loading`
|
|
131
|
+
// and `disabledReason` affordances are no-ops with asChild by contract.
|
|
132
|
+
children
|
|
133
|
+
) : (
|
|
134
|
+
<>
|
|
135
|
+
{loading ? (
|
|
136
|
+
// animate-spin is an existing keyframe utility (motion rule form a);
|
|
137
|
+
// aria-hidden — aria-busy on the button already announces the state.
|
|
138
|
+
<Loader2Icon
|
|
139
|
+
strokeWidth={1.5}
|
|
140
|
+
className="animate-spin"
|
|
141
|
+
aria-hidden="true"
|
|
142
|
+
/>
|
|
143
|
+
) : null}
|
|
144
|
+
{children}
|
|
145
|
+
</>
|
|
146
|
+
)}
|
|
147
|
+
</Comp>
|
|
65
148
|
)
|
|
149
|
+
|
|
150
|
+
// The reason lives OUTSIDE the button — an sr-only sibling referenced by
|
|
151
|
+
// aria-describedby. Inside the button it would pollute the accessible NAME
|
|
152
|
+
// (name-from-contents includes sr-only text); outside, it's description-only.
|
|
153
|
+
if (ariaDisabled) {
|
|
154
|
+
return (
|
|
155
|
+
<>
|
|
156
|
+
{button}
|
|
157
|
+
<span id={reasonId} className="sr-only">
|
|
158
|
+
{disabledReason}
|
|
159
|
+
</span>
|
|
160
|
+
</>
|
|
161
|
+
)
|
|
162
|
+
}
|
|
163
|
+
return button
|
|
66
164
|
}
|
|
67
165
|
|
|
68
166
|
export { Button, buttonVariants }
|
|
@@ -88,7 +88,7 @@ function Calendar({
|
|
|
88
88
|
: "flex h-8 items-center gap-1 rounded-md pr-1 pl-2 text-sm [&>svg]:size-3.5 [&>svg]:text-muted-foreground",
|
|
89
89
|
defaultClassNames.caption_label
|
|
90
90
|
),
|
|
91
|
-
|
|
91
|
+
month_grid: cn("w-full border-collapse", defaultClassNames.month_grid),
|
|
92
92
|
weekdays: cn("flex", defaultClassNames.weekdays),
|
|
93
93
|
weekday: cn(
|
|
94
94
|
"flex-1 rounded-md text-[0.8rem] font-normal text-muted-foreground select-none text-center",
|
|
@@ -1,15 +1,52 @@
|
|
|
1
1
|
import * as React from "react"
|
|
2
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
2
3
|
|
|
3
4
|
import { cn } from "../../lib/utils"
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
const cardVariants = cva(
|
|
7
|
+
// The base string MUST stay byte-identical to the pre-variant class list so
|
|
8
|
+
// a bare <Card /> renders exactly as before (Tier-4 additive contract) —
|
|
9
|
+
// don't reorder or split it.
|
|
10
|
+
"flex flex-col gap-4 rounded-lg border bg-card text-card-foreground shadow-sm",
|
|
11
|
+
{
|
|
12
|
+
variants: {
|
|
13
|
+
variant: {
|
|
14
|
+
default: "",
|
|
15
|
+
// shadow-2xl is the tokens.json "lifted card surface" tier (30px blur,
|
|
16
|
+
// pulled-in spread — under the 40px anti-slop glow ceiling; respects
|
|
17
|
+
// the Customize-tab shadow-opacity slider). ring-1 ring-white/10 is
|
|
18
|
+
// the same dark-mode elevation edge Dialog/AlertDialog ship, so the
|
|
19
|
+
// lift still reads on dark canvases where black shadows vanish. The
|
|
20
|
+
// border is unchanged — it stays the forced-colors / 3:1 non-text
|
|
21
|
+
// fallback in both variants.
|
|
22
|
+
elevated: "shadow-2xl ring-1 ring-white/10",
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
defaultVariants: {
|
|
26
|
+
variant: "default",
|
|
27
|
+
},
|
|
28
|
+
}
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
type CardProps = React.ComponentProps<"div"> & {
|
|
32
|
+
/**
|
|
33
|
+
* Surface prominence. `default` is the bordered `shadow-sm` card;
|
|
34
|
+
* `elevated` lifts the card to the `shadow-2xl` "lifted card surface"
|
|
35
|
+
* token tier (plus the Dialog dark-mode ring edge). Elevation
|
|
36
|
+
* communicates the priority of a surface — don't apply it to every
|
|
37
|
+
* card on a page, and don't use it to imply interactivity.
|
|
38
|
+
*/
|
|
39
|
+
variant?: VariantProps<typeof cardVariants>["variant"]
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function Card({ className, variant, ...props }: CardProps) {
|
|
6
43
|
return (
|
|
7
44
|
<div
|
|
8
45
|
data-slot="card"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
)}
|
|
46
|
+
// data-variant is omitted for the default variant so a bare <Card />
|
|
47
|
+
// stays byte-identical to the pre-variant render.
|
|
48
|
+
data-variant={variant && variant !== "default" ? variant : undefined}
|
|
49
|
+
className={cn(cardVariants({ variant }), className)}
|
|
13
50
|
{...props}
|
|
14
51
|
/>
|
|
15
52
|
)
|
|
@@ -83,6 +120,7 @@ function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
|
|
|
83
120
|
|
|
84
121
|
export {
|
|
85
122
|
Card,
|
|
123
|
+
cardVariants,
|
|
86
124
|
CardHeader,
|
|
87
125
|
CardFooter,
|
|
88
126
|
CardTitle,
|
|
@@ -301,7 +301,13 @@ function CarouselIndicators({ className, ...props }: React.ComponentPropsWithout
|
|
|
301
301
|
return (
|
|
302
302
|
<div
|
|
303
303
|
data-slot="carousel-indicators"
|
|
304
|
-
role=
|
|
304
|
+
// role=group, not tablist: these dots are a picker of plain buttons, not
|
|
305
|
+
// tabs. tab/tablist/aria-selected implies each tab controls a tabpanel
|
|
306
|
+
// (aria-controls) — the slides are role=group aria-roledescription=slide,
|
|
307
|
+
// NOT tabpanels, so tab semantics were an ARIA anti-pattern (a tab that
|
|
308
|
+
// controls no panel). The APG carousel dot pattern uses buttons with
|
|
309
|
+
// aria-current on the active one.
|
|
310
|
+
role="group"
|
|
305
311
|
aria-label="Slide indicators"
|
|
306
312
|
className={cn("flex items-center justify-center gap-1 pt-4", className)}
|
|
307
313
|
{...props}
|
|
@@ -309,15 +315,14 @@ function CarouselIndicators({ className, ...props }: React.ComponentPropsWithout
|
|
|
309
315
|
{Array.from({ length: totalSlides }).map((_, i) => (
|
|
310
316
|
<button
|
|
311
317
|
key={i}
|
|
312
|
-
|
|
318
|
+
type="button"
|
|
313
319
|
aria-label={`Go to slide ${i + 1}`}
|
|
314
|
-
aria-
|
|
320
|
+
aria-current={i === currentIndex ? "true" : undefined}
|
|
315
321
|
onClick={() => scrollToIndex(i)}
|
|
316
322
|
// Tap area stays a full 44px tall (SC 2.5.5 height) but hugs the dot
|
|
317
323
|
// horizontally so the indicators read as a tight cluster. Width is
|
|
318
324
|
// set explicitly (w-6) rather than via padding: with border-box, a
|
|
319
|
-
// stray global
|
|
320
|
-
// injects for its own UI tabs — can't inflate the button and spread
|
|
325
|
+
// stray global padding reset can't inflate the button and spread
|
|
321
326
|
// the dots. The dot is centred and overflows the (zeroed) content box
|
|
322
327
|
// harmlessly if such padding is inherited.
|
|
323
328
|
className={cn(
|