@behavioral-agentic-design-system/core 0.28.0 → 0.30.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 +2 -2
- package/scripts/a11y-lint.cjs +78 -9
- package/scripts/build-tokens.cjs +273 -15
- package/scripts/wcag-audit.cjs +67 -11
- package/src/api/layers/file.ts +1 -0
- package/src/app/font-ready.tsx +6 -5
- package/src/app/layout.tsx +54 -3
- package/src/app/preview/components/page.tsx +5679 -3073
- package/src/app/preview/health/page.tsx +201 -0
- package/src/app/preview/layout.tsx +4 -1
- package/src/app/preview/showcase-filter.tsx +66 -0
- package/src/app/preview/tab-replay.tsx +63 -0
- package/src/app/shell.tsx +74 -18
- package/src/components/customize/save-bar.tsx +19 -6
- package/src/components/docs-tab.tsx +36 -24
- package/src/components/layers-tab.tsx +37 -5
- package/src/components/ui/alert.tsx +12 -0
- package/src/components/ui/badge.tsx +19 -0
- package/src/components/ui/button.tsx +10 -0
- package/src/components/ui/chat-marker.tsx +120 -0
- package/src/components/ui/checkbox.tsx +9 -1
- package/src/components/ui/close-button.tsx +71 -0
- package/src/components/ui/combobox.tsx +62 -3
- package/src/components/ui/container.tsx +65 -0
- package/src/components/ui/date-field.tsx +368 -0
- package/src/components/ui/drawer.tsx +334 -0
- package/src/components/ui/file-button.tsx +145 -0
- package/src/components/ui/floating-indicator.tsx +217 -0
- package/src/components/ui/format-byte.tsx +113 -0
- package/src/components/ui/index.ts +21 -0
- package/src/components/ui/input-clear-button.tsx +52 -0
- package/src/components/ui/input.tsx +39 -20
- package/src/components/ui/keyboard-shortcut.tsx +146 -0
- package/src/components/ui/loading-dots.tsx +99 -0
- package/src/components/ui/month-picker.tsx +296 -0
- package/src/components/ui/multi-select.tsx +35 -19
- package/src/components/ui/nav-link.tsx +200 -0
- package/src/components/ui/navigation-rail.tsx +256 -0
- package/src/components/ui/notification.tsx +20 -0
- package/src/components/ui/password-input.tsx +34 -1
- package/src/components/ui/progress.tsx +15 -1
- package/src/components/ui/prose.tsx +62 -0
- package/src/components/ui/questionnaire.tsx +334 -0
- package/src/components/ui/result.tsx +151 -0
- package/src/components/ui/rolling-number.tsx +1 -0
- package/src/components/ui/sidebar.tsx +5 -0
- package/src/components/ui/simple-grid.tsx +110 -0
- package/src/components/ui/skeleton.tsx +52 -3
- package/src/components/ui/squircle.tsx +274 -0
- package/src/components/ui/stack.tsx +105 -0
- package/src/components/ui/status-badge.tsx +93 -0
- package/src/components/ui/tabs.tsx +34 -7
- package/src/components/ui/tag.tsx +46 -5
- package/src/components/ui/textarea.tsx +5 -0
- package/src/components/ui/theme-icon.tsx +138 -0
- package/src/components/ui/timeline.tsx +27 -10
- package/src/components/ui/tooltip.tsx +12 -1
- package/src/components/ui/tree-select.tsx +386 -0
- package/src/components/ui/year-picker.tsx +307 -0
- package/src/data/docs-index.ts +12 -0
- package/src/hooks/use-global-primary-color.ts +57 -6
- package/src/lib/get-icon-color.ts +66 -0
- package/src/stories/Alert.stories.tsx +31 -1
- package/src/stories/Badge.stories.tsx +63 -6
- package/src/stories/Button.stories.tsx +3 -0
- package/src/stories/ChatMarker.stories.tsx +59 -0
- package/src/stories/Checkbox.stories.tsx +5 -0
- package/src/stories/CloseButton.stories.tsx +65 -0
- package/src/stories/Combobox.stories.tsx +74 -3
- package/src/stories/Container.stories.tsx +134 -0
- package/src/stories/DateField.stories.tsx +114 -0
- package/src/stories/Drawer.stories.tsx +211 -0
- package/src/stories/FileButton.stories.tsx +117 -0
- package/src/stories/FloatingIndicator.stories.tsx +343 -0
- package/src/stories/FormatByte.stories.tsx +142 -0
- package/src/stories/Input.stories.tsx +94 -0
- package/src/stories/InputClearButton.stories.tsx +53 -0
- package/src/stories/KeyboardShortcut.stories.tsx +87 -0
- package/src/stories/LoadingDots.stories.tsx +73 -0
- package/src/stories/MonthPicker.stories.tsx +99 -0
- package/src/stories/MultiSelect.stories.tsx +7 -1
- package/src/stories/NavLink.stories.tsx +213 -0
- package/src/stories/NavigationRail.stories.tsx +413 -0
- package/src/stories/Notification.stories.tsx +53 -0
- package/src/stories/PasswordInput.stories.tsx +21 -0
- package/src/stories/Progress.stories.tsx +38 -0
- package/src/stories/Prose.stories.tsx +232 -0
- package/src/stories/Questionnaire.stories.tsx +287 -0
- package/src/stories/Result.stories.tsx +145 -0
- package/src/stories/RollingNumber.stories.tsx +1 -1
- package/src/stories/Sidebar.stories.tsx +2 -0
- package/src/stories/SimpleGrid.stories.tsx +130 -0
- package/src/stories/Skeleton.stories.tsx +62 -1
- package/src/stories/Squircle.stories.tsx +127 -0
- package/src/stories/Stack.stories.tsx +140 -0
- package/src/stories/StatusBadge.stories.tsx +125 -0
- package/src/stories/Tabs.stories.tsx +56 -1
- package/src/stories/Tag.stories.tsx +31 -0
- package/src/stories/Textarea.stories.tsx +2 -0
- package/src/stories/ThemeIcon.stories.tsx +97 -0
- package/src/stories/Timeline.stories.tsx +69 -0
- package/src/stories/Tooltip.stories.tsx +18 -0
- package/src/stories/TreeSelect.stories.tsx +222 -0
- package/src/stories/YearPicker.stories.tsx +100 -0
- package/src/styles.css +289 -15
- package/src/tokens.json +96 -1
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* KeyboardShortcut — displays a keyboard shortcut as a sequence of Kbd keys
|
|
5
|
+
* separated by a "+" or "then" separator.
|
|
6
|
+
*
|
|
7
|
+
* Composes the existing Kbd primitive. Handles platform-specific modifier
|
|
8
|
+
* symbols (⌘, ⌃, ⌥, ⇧ on Mac; Ctrl, Alt, Shift on Windows/Linux).
|
|
9
|
+
*
|
|
10
|
+
* Sources: Linear, Raycast, VS Code, GitHub command palette shortcut display
|
|
11
|
+
* patterns. Kbd is the single-key primitive; KeyboardShortcut is the
|
|
12
|
+
* multi-key composition with correct semantic markup and platform awareness.
|
|
13
|
+
*
|
|
14
|
+
* Accessibility: wraps in <kbd> with aria-label describing the full
|
|
15
|
+
* combination in plain text so screen readers announce "Command K" rather
|
|
16
|
+
* than reading each symbol separately.
|
|
17
|
+
*
|
|
18
|
+
* Motion: none — shortcut labels are presentational, no interaction.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import * as React from "react"
|
|
22
|
+
|
|
23
|
+
import { cn } from "../../lib/utils"
|
|
24
|
+
import { Kbd, type KbdProps } from "./kbd"
|
|
25
|
+
|
|
26
|
+
/** Canonical key names that map to platform-specific display symbols. */
|
|
27
|
+
export type ModifierKey = "meta" | "ctrl" | "alt" | "shift"
|
|
28
|
+
|
|
29
|
+
const macSymbols: Record<ModifierKey, string> = {
|
|
30
|
+
meta: "⌘",
|
|
31
|
+
ctrl: "⌃",
|
|
32
|
+
alt: "⌥",
|
|
33
|
+
shift: "⇧",
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const windowsLabels: Record<ModifierKey, string> = {
|
|
37
|
+
meta: "Win",
|
|
38
|
+
ctrl: "Ctrl",
|
|
39
|
+
alt: "Alt",
|
|
40
|
+
shift: "Shift",
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function isModifier(key: string): key is ModifierKey {
|
|
44
|
+
return key === "meta" || key === "ctrl" || key === "alt" || key === "shift"
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface KeyboardShortcutProps extends React.ComponentProps<"kbd"> {
|
|
48
|
+
/**
|
|
49
|
+
* Array of key strings. Use lowercase modifier names ("meta", "ctrl",
|
|
50
|
+
* "alt", "shift") and literal key characters ("K", "Enter", "Tab", "↑").
|
|
51
|
+
* Order: modifiers first, then the main key.
|
|
52
|
+
* @example ["meta", "K"] → ⌘K
|
|
53
|
+
* @example ["ctrl", "shift", "P"] → Ctrl+Shift+P
|
|
54
|
+
*/
|
|
55
|
+
keys: string[]
|
|
56
|
+
/**
|
|
57
|
+
* Separator rendered between keys.
|
|
58
|
+
* @default "+"
|
|
59
|
+
*/
|
|
60
|
+
separator?: string
|
|
61
|
+
/**
|
|
62
|
+
* Controls modifier display style.
|
|
63
|
+
* - "mac" renders ⌘⌃⌥⇧ symbols (default)
|
|
64
|
+
* - "windows" renders Ctrl/Alt/Shift/Win labels
|
|
65
|
+
* - "auto" detects via navigator.platform (SSR-safe: falls back to "mac")
|
|
66
|
+
*/
|
|
67
|
+
platform?: "mac" | "windows" | "auto"
|
|
68
|
+
/** Size forwarded to each Kbd element. */
|
|
69
|
+
size?: KbdProps["size"]
|
|
70
|
+
/** Variant forwarded to each Kbd element. */
|
|
71
|
+
variant?: KbdProps["variant"]
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function resolveKey(
|
|
75
|
+
key: string,
|
|
76
|
+
platform: "mac" | "windows"
|
|
77
|
+
): string {
|
|
78
|
+
if (isModifier(key)) {
|
|
79
|
+
return platform === "mac" ? macSymbols[key] : windowsLabels[key]
|
|
80
|
+
}
|
|
81
|
+
return key
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function buildAriaLabel(keys: string[]): string {
|
|
85
|
+
return keys
|
|
86
|
+
.map((k) =>
|
|
87
|
+
isModifier(k)
|
|
88
|
+
? k === "meta"
|
|
89
|
+
? "Command"
|
|
90
|
+
: k === "ctrl"
|
|
91
|
+
? "Control"
|
|
92
|
+
: k === "alt"
|
|
93
|
+
? "Alt"
|
|
94
|
+
: "Shift"
|
|
95
|
+
: k
|
|
96
|
+
)
|
|
97
|
+
.join(" ")
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function KeyboardShortcut({
|
|
101
|
+
keys,
|
|
102
|
+
separator = "+",
|
|
103
|
+
platform = "mac",
|
|
104
|
+
size,
|
|
105
|
+
variant,
|
|
106
|
+
className,
|
|
107
|
+
...props
|
|
108
|
+
}: KeyboardShortcutProps) {
|
|
109
|
+
const resolvedPlatform: "mac" | "windows" =
|
|
110
|
+
platform === "auto"
|
|
111
|
+
? typeof navigator !== "undefined" &&
|
|
112
|
+
navigator.platform.toLowerCase().includes("win")
|
|
113
|
+
? "windows"
|
|
114
|
+
: "mac"
|
|
115
|
+
: platform
|
|
116
|
+
|
|
117
|
+
const displayKeys = keys.map((k) => resolveKey(k, resolvedPlatform))
|
|
118
|
+
const ariaLabel = buildAriaLabel(keys)
|
|
119
|
+
|
|
120
|
+
return (
|
|
121
|
+
<kbd
|
|
122
|
+
aria-label={ariaLabel}
|
|
123
|
+
data-slot="keyboard-shortcut"
|
|
124
|
+
className={cn("inline-flex items-center gap-0.5", className)}
|
|
125
|
+
{...props}
|
|
126
|
+
>
|
|
127
|
+
{displayKeys.map((key, i) => (
|
|
128
|
+
<React.Fragment key={i}>
|
|
129
|
+
{i > 0 && (
|
|
130
|
+
<span
|
|
131
|
+
aria-hidden="true"
|
|
132
|
+
className="text-[0.65em] text-muted-foreground select-none"
|
|
133
|
+
>
|
|
134
|
+
{separator}
|
|
135
|
+
</span>
|
|
136
|
+
)}
|
|
137
|
+
<Kbd size={size} variant={variant}>
|
|
138
|
+
{key}
|
|
139
|
+
</Kbd>
|
|
140
|
+
</React.Fragment>
|
|
141
|
+
))}
|
|
142
|
+
</kbd>
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export { KeyboardShortcut }
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* LoadingDots — three-dot inline loading indicator for async states.
|
|
5
|
+
*
|
|
6
|
+
* Distinct from TypingIndicator (chat-specific "person is typing" widget).
|
|
7
|
+
* LoadingDots is a general-purpose inline spinner substitute — used inside
|
|
8
|
+
* buttons during submission, in list placeholders, in nav items that are
|
|
9
|
+
* fetching, and anywhere a compact animated signal replaces a full spinner.
|
|
10
|
+
*
|
|
11
|
+
* Sources: common cross-library pattern (GitHub, Vercel, Linear, Notion);
|
|
12
|
+
* inline button-loading convention established in shadcn/ui + Base UI.
|
|
13
|
+
*
|
|
14
|
+
* Motion (spec §4):
|
|
15
|
+
* - reuses the `typing-dot` @keyframe from styles.css (pattern b delivery,
|
|
16
|
+
* keyed off [data-slot="chat-bubble-typing"] → we use the same keyframe
|
|
17
|
+
* by name, with inline animationDelay per dot for stagger — pattern c).
|
|
18
|
+
* - reduced-motion: base layer forces animation-duration to 0.01ms.
|
|
19
|
+
*
|
|
20
|
+
* Accessibility: aria-label defaults to "Loading" — override when the
|
|
21
|
+
* context is more specific ("Saving", "Sending"). role="status" surfaces
|
|
22
|
+
* it as a live region so screen readers announce the state.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import * as React from "react"
|
|
26
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
27
|
+
|
|
28
|
+
import { cn } from "../../lib/utils"
|
|
29
|
+
|
|
30
|
+
const loadingDotsVariants = cva(
|
|
31
|
+
"inline-flex items-center gap-[0.2em]",
|
|
32
|
+
{
|
|
33
|
+
variants: {
|
|
34
|
+
size: {
|
|
35
|
+
xs: "h-3",
|
|
36
|
+
sm: "h-4",
|
|
37
|
+
default: "h-5",
|
|
38
|
+
lg: "h-6",
|
|
39
|
+
},
|
|
40
|
+
tone: {
|
|
41
|
+
current: "",
|
|
42
|
+
muted: "text-muted-foreground",
|
|
43
|
+
primary: "text-primary",
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
defaultVariants: {
|
|
47
|
+
size: "default",
|
|
48
|
+
tone: "current",
|
|
49
|
+
},
|
|
50
|
+
}
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
const dotSizeMap: Record<string, string> = {
|
|
54
|
+
xs: "size-1",
|
|
55
|
+
sm: "size-1.5",
|
|
56
|
+
default: "size-2",
|
|
57
|
+
lg: "size-2.5",
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface LoadingDotsProps
|
|
61
|
+
extends React.ComponentProps<"span">,
|
|
62
|
+
VariantProps<typeof loadingDotsVariants> {
|
|
63
|
+
/** Accessible label for the loading state. */
|
|
64
|
+
"aria-label"?: string
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function LoadingDots({
|
|
68
|
+
size = "default",
|
|
69
|
+
tone = "current",
|
|
70
|
+
className,
|
|
71
|
+
"aria-label": ariaLabel = "Loading",
|
|
72
|
+
...props
|
|
73
|
+
}: LoadingDotsProps) {
|
|
74
|
+
const dotClass = dotSizeMap[size ?? "default"]
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<span
|
|
78
|
+
role="status"
|
|
79
|
+
aria-label={ariaLabel}
|
|
80
|
+
data-slot="loading-dots"
|
|
81
|
+
className={cn(loadingDotsVariants({ size, tone }), className)}
|
|
82
|
+
{...props}
|
|
83
|
+
>
|
|
84
|
+
{[0, 1, 2].map((i) => (
|
|
85
|
+
<span
|
|
86
|
+
key={i}
|
|
87
|
+
aria-hidden="true"
|
|
88
|
+
className={cn("rounded-full bg-current", dotClass)}
|
|
89
|
+
style={{
|
|
90
|
+
animation: "typing-dot 1.2s ease-in-out infinite",
|
|
91
|
+
animationDelay: `${i * 0.2}s`,
|
|
92
|
+
}}
|
|
93
|
+
/>
|
|
94
|
+
))}
|
|
95
|
+
</span>
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export { LoadingDots, loadingDotsVariants }
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react"
|
|
5
|
+
|
|
6
|
+
import { cn } from "../../lib/utils"
|
|
7
|
+
import { Button } from "./button"
|
|
8
|
+
|
|
9
|
+
export interface MonthPickerProps {
|
|
10
|
+
/** Controlled selected month. The day-of-month is normalized to the 1st. */
|
|
11
|
+
value?: Date
|
|
12
|
+
/** Uncontrolled initial selection. */
|
|
13
|
+
defaultValue?: Date
|
|
14
|
+
/** Fires with the first day of the picked month (local time). */
|
|
15
|
+
onChange?: (date: Date) => void
|
|
16
|
+
/** Disables the entire control — year navigation and every month cell. */
|
|
17
|
+
disabled?: boolean
|
|
18
|
+
/**
|
|
19
|
+
* Predicate disabling specific months. Receives the first day of the
|
|
20
|
+
* candidate month (local time) — never rely on the day-of-month.
|
|
21
|
+
*/
|
|
22
|
+
disabledMonths?: (date: Date) => boolean
|
|
23
|
+
className?: string
|
|
24
|
+
id?: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Explicit locale so server and client render identical labels (no hydration
|
|
28
|
+
// mismatch) — same convention as FormatNumber.
|
|
29
|
+
const MONTH_SHORT = Array.from({ length: 12 }, (_, m) =>
|
|
30
|
+
new Date(2000, m, 1).toLocaleString("en-US", { month: "short" })
|
|
31
|
+
)
|
|
32
|
+
const MONTH_LONG = Array.from({ length: 12 }, (_, m) =>
|
|
33
|
+
new Date(2000, m, 1).toLocaleString("en-US", { month: "long" })
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
// 3-column × 4-row month grid — the cross-library consensus shape
|
|
37
|
+
// (Mantine MonthPicker, MUI-X MonthCalendar, Ant Design picker="month",
|
|
38
|
+
// Ark UI DatePicker view=month).
|
|
39
|
+
const ROWS = [
|
|
40
|
+
[0, 1, 2],
|
|
41
|
+
[3, 4, 5],
|
|
42
|
+
[6, 7, 8],
|
|
43
|
+
[9, 10, 11],
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Calendar grid of 12 month cells for a given year — yields a month + year
|
|
48
|
+
* selection without drilling into individual dates. Use for billing periods,
|
|
49
|
+
* report month filters, and archive navigation; for a specific day, use
|
|
50
|
+
* DatePicker instead.
|
|
51
|
+
*
|
|
52
|
+
* ARIA grid pattern: grid → row → gridcell buttons with roving tabindex.
|
|
53
|
+
* Arrow keys move ±1 / ±3 months, Home/End jump to first/last enabled month,
|
|
54
|
+
* PageUp/PageDown page the displayed year.
|
|
55
|
+
*/
|
|
56
|
+
function MonthPicker({
|
|
57
|
+
value,
|
|
58
|
+
defaultValue,
|
|
59
|
+
onChange,
|
|
60
|
+
disabled = false,
|
|
61
|
+
disabledMonths,
|
|
62
|
+
className,
|
|
63
|
+
id,
|
|
64
|
+
}: MonthPickerProps) {
|
|
65
|
+
const isControlled = value !== undefined
|
|
66
|
+
const [internalValue, setInternalValue] = React.useState<Date | undefined>(
|
|
67
|
+
defaultValue
|
|
68
|
+
)
|
|
69
|
+
const selected = isControlled ? value : internalValue
|
|
70
|
+
|
|
71
|
+
const [viewYear, setViewYear] = React.useState<number>(() =>
|
|
72
|
+
(selected ?? new Date()).getFullYear()
|
|
73
|
+
)
|
|
74
|
+
// Roving tabindex: the month index the user last focused, if any.
|
|
75
|
+
const [focusedMonth, setFocusedMonth] = React.useState<number | null>(null)
|
|
76
|
+
const cellRefs = React.useRef<Array<HTMLButtonElement | null>>([])
|
|
77
|
+
|
|
78
|
+
// Follow a controlled value into its year so the selection stays visible.
|
|
79
|
+
const valueTime = value?.getTime()
|
|
80
|
+
React.useEffect(() => {
|
|
81
|
+
if (valueTime !== undefined) {
|
|
82
|
+
setViewYear(new Date(valueTime).getFullYear())
|
|
83
|
+
}
|
|
84
|
+
}, [valueTime])
|
|
85
|
+
|
|
86
|
+
const isMonthDisabled = React.useCallback(
|
|
87
|
+
(month: number) =>
|
|
88
|
+
disabled || (disabledMonths?.(new Date(viewYear, month, 1)) ?? false),
|
|
89
|
+
[disabled, disabledMonths, viewYear]
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
const today = new Date()
|
|
93
|
+
const selectedMonthInView =
|
|
94
|
+
selected && selected.getFullYear() === viewYear ? selected.getMonth() : null
|
|
95
|
+
const todayMonthInView =
|
|
96
|
+
today.getFullYear() === viewYear ? today.getMonth() : null
|
|
97
|
+
|
|
98
|
+
// Which cell carries tabIndex=0: last-focused, else selected, else today's
|
|
99
|
+
// month, else the first enabled month in the displayed year.
|
|
100
|
+
// When every cell is disabled (disabled prop or disabledMonths covers all 12)
|
|
101
|
+
// no button can carry tabIndex=0 — the grid div itself becomes the tab stop.
|
|
102
|
+
const allDisabled = React.useMemo(
|
|
103
|
+
() => Array.from({ length: 12 }, (_, m) => m).every((m) => isMonthDisabled(m)),
|
|
104
|
+
[isMonthDisabled]
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
const defaultTabbable = React.useMemo(() => {
|
|
108
|
+
if (selectedMonthInView !== null && !isMonthDisabled(selectedMonthInView)) {
|
|
109
|
+
return selectedMonthInView
|
|
110
|
+
}
|
|
111
|
+
if (todayMonthInView !== null && !isMonthDisabled(todayMonthInView)) {
|
|
112
|
+
return todayMonthInView
|
|
113
|
+
}
|
|
114
|
+
for (let m = 0; m < 12; m++) {
|
|
115
|
+
if (!isMonthDisabled(m)) return m
|
|
116
|
+
}
|
|
117
|
+
return 0
|
|
118
|
+
}, [selectedMonthInView, todayMonthInView, isMonthDisabled])
|
|
119
|
+
const tabbableMonth =
|
|
120
|
+
focusedMonth !== null && !isMonthDisabled(focusedMonth)
|
|
121
|
+
? focusedMonth
|
|
122
|
+
: defaultTabbable
|
|
123
|
+
|
|
124
|
+
function selectMonth(month: number) {
|
|
125
|
+
if (isMonthDisabled(month)) return
|
|
126
|
+
const next = new Date(viewYear, month, 1)
|
|
127
|
+
if (!isControlled) setInternalValue(next)
|
|
128
|
+
onChange?.(next)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function focusCell(month: number) {
|
|
132
|
+
cellRefs.current[month]?.focus()
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function handleGridKeyDown(event: React.KeyboardEvent<HTMLDivElement>) {
|
|
136
|
+
const from = focusedMonth ?? tabbableMonth
|
|
137
|
+
let delta = 0
|
|
138
|
+
switch (event.key) {
|
|
139
|
+
case "ArrowLeft":
|
|
140
|
+
delta = -1
|
|
141
|
+
break
|
|
142
|
+
case "ArrowRight":
|
|
143
|
+
delta = 1
|
|
144
|
+
break
|
|
145
|
+
case "ArrowUp":
|
|
146
|
+
delta = -3
|
|
147
|
+
break
|
|
148
|
+
case "ArrowDown":
|
|
149
|
+
delta = 3
|
|
150
|
+
break
|
|
151
|
+
case "Home": {
|
|
152
|
+
event.preventDefault()
|
|
153
|
+
for (let m = 0; m < 12; m++) {
|
|
154
|
+
if (!isMonthDisabled(m)) {
|
|
155
|
+
focusCell(m)
|
|
156
|
+
return
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return
|
|
160
|
+
}
|
|
161
|
+
case "End": {
|
|
162
|
+
event.preventDefault()
|
|
163
|
+
for (let m = 11; m >= 0; m--) {
|
|
164
|
+
if (!isMonthDisabled(m)) {
|
|
165
|
+
focusCell(m)
|
|
166
|
+
return
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return
|
|
170
|
+
}
|
|
171
|
+
case "PageUp":
|
|
172
|
+
event.preventDefault()
|
|
173
|
+
if (!disabled) setViewYear((y) => y - 1)
|
|
174
|
+
return
|
|
175
|
+
case "PageDown":
|
|
176
|
+
event.preventDefault()
|
|
177
|
+
if (!disabled) setViewYear((y) => y + 1)
|
|
178
|
+
return
|
|
179
|
+
default:
|
|
180
|
+
return
|
|
181
|
+
}
|
|
182
|
+
event.preventDefault()
|
|
183
|
+
// Skip over disabled cells in the direction of travel.
|
|
184
|
+
let next = from + delta
|
|
185
|
+
while (next >= 0 && next <= 11 && isMonthDisabled(next)) {
|
|
186
|
+
next += delta
|
|
187
|
+
}
|
|
188
|
+
if (next < 0 || next > 11) return
|
|
189
|
+
focusCell(next)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return (
|
|
193
|
+
<div
|
|
194
|
+
id={id}
|
|
195
|
+
data-slot="month-picker"
|
|
196
|
+
data-disabled={disabled || undefined}
|
|
197
|
+
className={cn("w-fit bg-background p-3", className)}
|
|
198
|
+
>
|
|
199
|
+
<div
|
|
200
|
+
data-slot="month-picker-header"
|
|
201
|
+
className="mb-2 flex items-center justify-between gap-1"
|
|
202
|
+
>
|
|
203
|
+
<Button
|
|
204
|
+
type="button"
|
|
205
|
+
variant="ghost"
|
|
206
|
+
size="icon-xl"
|
|
207
|
+
aria-label="Previous year"
|
|
208
|
+
disabled={disabled}
|
|
209
|
+
onClick={() => setViewYear((y) => y - 1)}
|
|
210
|
+
>
|
|
211
|
+
<ChevronLeftIcon strokeWidth={1.5} aria-hidden="true" />
|
|
212
|
+
</Button>
|
|
213
|
+
<span
|
|
214
|
+
aria-live="polite"
|
|
215
|
+
className={cn(
|
|
216
|
+
"text-sm font-medium tabular-nums select-none",
|
|
217
|
+
disabled ? "text-muted-foreground" : "text-foreground"
|
|
218
|
+
)}
|
|
219
|
+
>
|
|
220
|
+
{viewYear}
|
|
221
|
+
</span>
|
|
222
|
+
<Button
|
|
223
|
+
type="button"
|
|
224
|
+
variant="ghost"
|
|
225
|
+
size="icon-xl"
|
|
226
|
+
aria-label="Next year"
|
|
227
|
+
disabled={disabled}
|
|
228
|
+
onClick={() => setViewYear((y) => y + 1)}
|
|
229
|
+
>
|
|
230
|
+
<ChevronRightIcon strokeWidth={1.5} aria-hidden="true" />
|
|
231
|
+
</Button>
|
|
232
|
+
</div>
|
|
233
|
+
<div
|
|
234
|
+
role="grid"
|
|
235
|
+
aria-label="Month picker"
|
|
236
|
+
aria-disabled={disabled || undefined}
|
|
237
|
+
data-slot="month-picker-grid"
|
|
238
|
+
tabIndex={allDisabled ? 0 : -1}
|
|
239
|
+
onKeyDown={handleGridKeyDown}
|
|
240
|
+
className="w-64 space-y-1"
|
|
241
|
+
>
|
|
242
|
+
{ROWS.map((row) => (
|
|
243
|
+
<div key={row[0]} role="row" className="grid grid-cols-3 gap-1">
|
|
244
|
+
{row.map((month) => {
|
|
245
|
+
const isSelected = selectedMonthInView === month
|
|
246
|
+
const isToday = todayMonthInView === month
|
|
247
|
+
const isDisabled = isMonthDisabled(month)
|
|
248
|
+
return (
|
|
249
|
+
<button
|
|
250
|
+
key={month}
|
|
251
|
+
ref={(el) => {
|
|
252
|
+
cellRefs.current[month] = el
|
|
253
|
+
}}
|
|
254
|
+
type="button"
|
|
255
|
+
role="gridcell"
|
|
256
|
+
data-slot="month-picker-cell"
|
|
257
|
+
data-selected={isSelected || undefined}
|
|
258
|
+
data-today={isToday || undefined}
|
|
259
|
+
aria-label={`${MONTH_LONG[month]} ${viewYear}`}
|
|
260
|
+
aria-selected={isSelected}
|
|
261
|
+
aria-disabled={isDisabled || undefined}
|
|
262
|
+
disabled={isDisabled}
|
|
263
|
+
tabIndex={!isDisabled && month === tabbableMonth ? 0 : -1}
|
|
264
|
+
onClick={() => selectMonth(month)}
|
|
265
|
+
onFocus={() => setFocusedMonth(month)}
|
|
266
|
+
// Motion pattern (c): token-driven one-off transition —
|
|
267
|
+
// never Tailwind duration-* classes (silent failure in v4).
|
|
268
|
+
style={{
|
|
269
|
+
transitionDuration: "var(--duration-fast)",
|
|
270
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
271
|
+
}}
|
|
272
|
+
className={cn(
|
|
273
|
+
"inline-flex min-h-11 items-center justify-center rounded-md px-2 py-2 text-sm select-none",
|
|
274
|
+
"transition-colors outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",
|
|
275
|
+
"disabled:pointer-events-none disabled:opacity-50",
|
|
276
|
+
isSelected
|
|
277
|
+
? "bg-primary text-primary-foreground hover:bg-primary/90"
|
|
278
|
+
: "text-foreground hover:bg-accent hover:text-accent-foreground",
|
|
279
|
+
// Today's month: underline + weight, never color alone.
|
|
280
|
+
isToday &&
|
|
281
|
+
!isSelected &&
|
|
282
|
+
"font-medium text-primary underline underline-offset-4"
|
|
283
|
+
)}
|
|
284
|
+
>
|
|
285
|
+
{MONTH_SHORT[month]}
|
|
286
|
+
</button>
|
|
287
|
+
)
|
|
288
|
+
})}
|
|
289
|
+
</div>
|
|
290
|
+
))}
|
|
291
|
+
</div>
|
|
292
|
+
</div>
|
|
293
|
+
)
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export { MonthPicker }
|
|
@@ -85,6 +85,7 @@ function MultiSelect({
|
|
|
85
85
|
*/}
|
|
86
86
|
<div
|
|
87
87
|
data-slot="multi-select"
|
|
88
|
+
aria-disabled={disabled || undefined}
|
|
88
89
|
className={cn(
|
|
89
90
|
"relative flex w-full min-h-9 h-auto items-center justify-between gap-1 rounded-md border border-input bg-background px-3 py-1.5 text-sm font-medium shadow-xs",
|
|
90
91
|
"cursor-default select-none",
|
|
@@ -98,17 +99,30 @@ function MultiSelect({
|
|
|
98
99
|
transitionTimingFunction: "var(--ease-out)",
|
|
99
100
|
}}
|
|
100
101
|
>
|
|
101
|
-
{/*
|
|
102
|
-
|
|
102
|
+
{/*
|
|
103
|
+
* Trigger: absolute-fill transparent button — first in DOM for correct tab order.
|
|
104
|
+
* When disabled: skip PopoverTrigger entirely so Radix doesn't add aria-controls
|
|
105
|
+
* pointing to an unmounted PopoverContent (would fail axe aria-valid-attr-value).
|
|
106
|
+
*/}
|
|
107
|
+
{disabled ? (
|
|
103
108
|
<button
|
|
104
109
|
type="button"
|
|
105
|
-
aria-haspopup="listbox"
|
|
106
110
|
aria-label={triggerLabel}
|
|
107
|
-
disabled
|
|
108
|
-
tabIndex={
|
|
111
|
+
disabled
|
|
112
|
+
tabIndex={-1}
|
|
109
113
|
className="absolute inset-0 z-0 rounded-md focus-visible:outline-none"
|
|
110
114
|
/>
|
|
111
|
-
|
|
115
|
+
) : (
|
|
116
|
+
<PopoverTrigger asChild>
|
|
117
|
+
<button
|
|
118
|
+
type="button"
|
|
119
|
+
aria-haspopup="listbox"
|
|
120
|
+
aria-label={triggerLabel}
|
|
121
|
+
tabIndex={0}
|
|
122
|
+
className="absolute inset-0 z-0 rounded-md focus-visible:outline-none"
|
|
123
|
+
/>
|
|
124
|
+
</PopoverTrigger>
|
|
125
|
+
)}
|
|
112
126
|
|
|
113
127
|
{/* Pills + placeholder: z-10 so they render above the trigger button.
|
|
114
128
|
pointer-events-none lets clicks on badge labels fall through to the
|
|
@@ -120,21 +134,23 @@ function MultiSelect({
|
|
|
120
134
|
<Badge
|
|
121
135
|
key={opt.value}
|
|
122
136
|
variant="secondary"
|
|
123
|
-
className="gap-1
|
|
137
|
+
className={cn("gap-1 font-normal py-0 min-h-6", !disabled && "pr-1")}
|
|
124
138
|
>
|
|
125
139
|
<span className="truncate max-w-[120px]">{opt.label}</span>
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
140
|
+
{!disabled && (
|
|
141
|
+
<button
|
|
142
|
+
type="button"
|
|
143
|
+
aria-label={`Remove ${opt.label}`}
|
|
144
|
+
onClick={(e) => removeAt(opt.value, e)}
|
|
145
|
+
className="pointer-events-auto h-6 w-6 flex items-center justify-center rounded-sm opacity-60 hover:opacity-100 outline-none focus-visible:ring-1 focus-visible:ring-ring transition-opacity"
|
|
146
|
+
style={{
|
|
147
|
+
transitionDuration: "var(--duration-fast)",
|
|
148
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
149
|
+
}}
|
|
150
|
+
>
|
|
151
|
+
<XIcon size={10} strokeWidth={1.5} />
|
|
152
|
+
</button>
|
|
153
|
+
)}
|
|
138
154
|
</Badge>
|
|
139
155
|
))}
|
|
140
156
|
{overflowCount > 0 && (
|