@behavioral-agentic-design-system/core 0.15.0 → 0.16.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 -2
- package/scripts/a11y-lint.cjs +229 -0
- package/scripts/build-tokens.cjs +3 -3
- package/scripts/check-stories.mjs +109 -0
- package/scripts/fix-stories.mjs +785 -0
- package/scripts/generate-stories.cjs +101 -0
- package/scripts/oklch-to-hex.cjs +156 -0
- package/scripts/wcag-audit.cjs +444 -0
- package/src/app/preview/components/page.tsx +373 -1
- package/src/components/dev-identity-badge.tsx +1 -1
- package/src/components/ui/button-group.tsx +57 -0
- package/src/components/ui/calendar.tsx +4 -0
- package/src/components/ui/circular-progress.tsx +120 -0
- package/src/components/ui/copy-button.tsx +114 -0
- package/src/components/ui/empty-state.tsx +115 -0
- package/src/components/ui/indicator.tsx +144 -0
- package/src/components/ui/list.tsx +70 -0
- package/src/components/ui/multi-select.tsx +196 -0
- package/src/hooks/use-global-primary-color.ts +1 -1
- package/src/styles.css +2 -2
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { CheckIcon, CopyIcon } from "lucide-react"
|
|
5
|
+
import { cn } from "../../lib/utils"
|
|
6
|
+
import { Button, buttonVariants } from "./button"
|
|
7
|
+
import type { VariantProps } from "class-variance-authority"
|
|
8
|
+
|
|
9
|
+
export type CopyButtonProps = Omit<
|
|
10
|
+
React.ComponentPropsWithoutRef<"button">,
|
|
11
|
+
"onClick" | "value" | "children"
|
|
12
|
+
> &
|
|
13
|
+
VariantProps<typeof buttonVariants> & {
|
|
14
|
+
/** The text value to copy to the clipboard. Required. */
|
|
15
|
+
value: string
|
|
16
|
+
/** Milliseconds the "copied" state is held before resetting. Default 2000. */
|
|
17
|
+
copiedDuration?: number
|
|
18
|
+
/** Called after a successful clipboard write. */
|
|
19
|
+
onCopy?: (value: string) => void
|
|
20
|
+
/** Label shown at rest. Omit for icon-only mode. */
|
|
21
|
+
children?: React.ReactNode
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function CopyButton({
|
|
25
|
+
value,
|
|
26
|
+
copiedDuration = 2000,
|
|
27
|
+
onCopy,
|
|
28
|
+
children,
|
|
29
|
+
variant = "outline",
|
|
30
|
+
size = "default",
|
|
31
|
+
className,
|
|
32
|
+
disabled,
|
|
33
|
+
"aria-label": ariaLabel,
|
|
34
|
+
...props
|
|
35
|
+
}: CopyButtonProps) {
|
|
36
|
+
const [copied, setCopied] = React.useState(false)
|
|
37
|
+
|
|
38
|
+
const handleCopy = React.useCallback(async () => {
|
|
39
|
+
if (copied) return
|
|
40
|
+
try {
|
|
41
|
+
await navigator.clipboard.writeText(value)
|
|
42
|
+
} catch {
|
|
43
|
+
// Fallback for environments without clipboard API
|
|
44
|
+
const el = document.createElement("textarea")
|
|
45
|
+
el.value = value
|
|
46
|
+
el.style.position = "fixed"
|
|
47
|
+
el.style.opacity = "0"
|
|
48
|
+
document.body.appendChild(el)
|
|
49
|
+
el.focus()
|
|
50
|
+
el.select()
|
|
51
|
+
document.execCommand("copy")
|
|
52
|
+
document.body.removeChild(el)
|
|
53
|
+
}
|
|
54
|
+
setCopied(true)
|
|
55
|
+
onCopy?.(value)
|
|
56
|
+
const timer = setTimeout(() => setCopied(false), copiedDuration)
|
|
57
|
+
return () => clearTimeout(timer)
|
|
58
|
+
}, [value, copied, copiedDuration, onCopy])
|
|
59
|
+
|
|
60
|
+
const iconOnly = children === undefined
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<>
|
|
64
|
+
<Button
|
|
65
|
+
data-slot="copy-button"
|
|
66
|
+
data-copied={copied ? "true" : undefined}
|
|
67
|
+
variant={variant}
|
|
68
|
+
size={size}
|
|
69
|
+
disabled={disabled || copied}
|
|
70
|
+
onClick={handleCopy}
|
|
71
|
+
aria-label={ariaLabel ?? (iconOnly ? (copied ? "Copied" : "Copy") : undefined)}
|
|
72
|
+
className={cn("relative overflow-hidden", className)}
|
|
73
|
+
{...props}
|
|
74
|
+
>
|
|
75
|
+
{/* In labeled mode this span provides the button's accessible name — not aria-hidden */}
|
|
76
|
+
<span
|
|
77
|
+
className={cn(
|
|
78
|
+
"inline-flex items-center gap-2 transition-all",
|
|
79
|
+
copied ? "opacity-0 scale-75" : "opacity-100 scale-100"
|
|
80
|
+
)}
|
|
81
|
+
style={{
|
|
82
|
+
transitionDuration: "var(--duration-fast)",
|
|
83
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
84
|
+
}}
|
|
85
|
+
aria-hidden={iconOnly ? "true" : undefined}
|
|
86
|
+
>
|
|
87
|
+
<CopyIcon strokeWidth={1.5} aria-hidden="true" />
|
|
88
|
+
{!iconOnly && (children ?? "Copy")}
|
|
89
|
+
</span>
|
|
90
|
+
{/* Always hidden — state announced by the aria-live region */}
|
|
91
|
+
<span
|
|
92
|
+
className={cn(
|
|
93
|
+
"absolute inset-0 inline-flex items-center justify-center gap-2 transition-all",
|
|
94
|
+
copied ? "opacity-100 scale-100" : "opacity-0 scale-75"
|
|
95
|
+
)}
|
|
96
|
+
style={{
|
|
97
|
+
transitionDuration: "var(--duration-fast)",
|
|
98
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
99
|
+
}}
|
|
100
|
+
aria-hidden="true"
|
|
101
|
+
>
|
|
102
|
+
<CheckIcon strokeWidth={1.5} />
|
|
103
|
+
{!iconOnly && "Copied!"}
|
|
104
|
+
</span>
|
|
105
|
+
</Button>
|
|
106
|
+
{/* Screen-reader live region — announces state change without focus move */}
|
|
107
|
+
<span className="sr-only" aria-live="polite" aria-atomic="true">
|
|
108
|
+
{copied ? "Copied to clipboard" : ""}
|
|
109
|
+
</span>
|
|
110
|
+
</>
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export { CopyButton }
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
3
|
+
|
|
4
|
+
import { cn } from "../../lib/utils"
|
|
5
|
+
|
|
6
|
+
// ─── EmptyState root ──────────────────────────────────────────────────────────
|
|
7
|
+
|
|
8
|
+
const emptyStateVariants = cva(
|
|
9
|
+
"flex flex-col items-center text-center",
|
|
10
|
+
{
|
|
11
|
+
variants: {
|
|
12
|
+
size: {
|
|
13
|
+
sm: "gap-2 py-6 px-4",
|
|
14
|
+
default: "gap-3 py-10 px-6",
|
|
15
|
+
lg: "gap-4 py-16 px-8",
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
defaultVariants: {
|
|
19
|
+
size: "default",
|
|
20
|
+
},
|
|
21
|
+
}
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
export interface EmptyStateProps
|
|
25
|
+
extends React.ComponentPropsWithoutRef<"div">,
|
|
26
|
+
VariantProps<typeof emptyStateVariants> {}
|
|
27
|
+
|
|
28
|
+
function EmptyState({ className, size, children, ...props }: EmptyStateProps) {
|
|
29
|
+
return (
|
|
30
|
+
<div
|
|
31
|
+
data-slot="empty-state"
|
|
32
|
+
className={cn(emptyStateVariants({ size }), className)}
|
|
33
|
+
{...props}
|
|
34
|
+
>
|
|
35
|
+
{children}
|
|
36
|
+
</div>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// ─── EmptyStateIcon ───────────────────────────────────────────────────────────
|
|
41
|
+
|
|
42
|
+
export interface EmptyStateIconProps extends React.ComponentPropsWithoutRef<"div"> {}
|
|
43
|
+
|
|
44
|
+
function EmptyStateIcon({ className, children, ...props }: EmptyStateIconProps) {
|
|
45
|
+
return (
|
|
46
|
+
<div
|
|
47
|
+
data-slot="empty-state-icon"
|
|
48
|
+
className={cn(
|
|
49
|
+
"flex items-center justify-center rounded-full bg-muted text-muted-foreground",
|
|
50
|
+
"size-12 [&>svg]:size-6 [&>svg]:stroke-[1.5]",
|
|
51
|
+
className
|
|
52
|
+
)}
|
|
53
|
+
{...props}
|
|
54
|
+
>
|
|
55
|
+
{children}
|
|
56
|
+
</div>
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// ─── EmptyStateTitle ──────────────────────────────────────────────────────────
|
|
61
|
+
|
|
62
|
+
export interface EmptyStateTitleProps extends React.ComponentPropsWithoutRef<"p"> {}
|
|
63
|
+
|
|
64
|
+
function EmptyStateTitle({ className, children, ...props }: EmptyStateTitleProps) {
|
|
65
|
+
return (
|
|
66
|
+
<p
|
|
67
|
+
data-slot="empty-state-title"
|
|
68
|
+
className={cn("text-sm font-semibold text-foreground", className)}
|
|
69
|
+
{...props}
|
|
70
|
+
>
|
|
71
|
+
{children}
|
|
72
|
+
</p>
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// ─── EmptyStateDescription ────────────────────────────────────────────────────
|
|
77
|
+
|
|
78
|
+
export interface EmptyStateDescriptionProps extends React.ComponentPropsWithoutRef<"p"> {}
|
|
79
|
+
|
|
80
|
+
function EmptyStateDescription({ className, children, ...props }: EmptyStateDescriptionProps) {
|
|
81
|
+
return (
|
|
82
|
+
<p
|
|
83
|
+
data-slot="empty-state-description"
|
|
84
|
+
className={cn("text-sm text-muted-foreground max-w-xs leading-relaxed", className)}
|
|
85
|
+
{...props}
|
|
86
|
+
>
|
|
87
|
+
{children}
|
|
88
|
+
</p>
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// ─── EmptyStateAction ─────────────────────────────────────────────────────────
|
|
93
|
+
|
|
94
|
+
export interface EmptyStateActionProps extends React.ComponentPropsWithoutRef<"div"> {}
|
|
95
|
+
|
|
96
|
+
function EmptyStateAction({ className, children, ...props }: EmptyStateActionProps) {
|
|
97
|
+
return (
|
|
98
|
+
<div
|
|
99
|
+
data-slot="empty-state-action"
|
|
100
|
+
className={cn("flex items-center gap-2 pt-1", className)}
|
|
101
|
+
{...props}
|
|
102
|
+
>
|
|
103
|
+
{children}
|
|
104
|
+
</div>
|
|
105
|
+
)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export {
|
|
109
|
+
EmptyState,
|
|
110
|
+
emptyStateVariants,
|
|
111
|
+
EmptyStateIcon,
|
|
112
|
+
EmptyStateTitle,
|
|
113
|
+
EmptyStateDescription,
|
|
114
|
+
EmptyStateAction,
|
|
115
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
5
|
+
import { cn } from "../../lib/utils"
|
|
6
|
+
|
|
7
|
+
type Position =
|
|
8
|
+
| "top-right"
|
|
9
|
+
| "top-left"
|
|
10
|
+
| "bottom-right"
|
|
11
|
+
| "bottom-left"
|
|
12
|
+
| "middle-right"
|
|
13
|
+
| "middle-left"
|
|
14
|
+
|
|
15
|
+
// Dot sizes — no text baked in; labeled mode adds text-xs + height overrides separately
|
|
16
|
+
const indicatorDotVariants = cva(
|
|
17
|
+
"absolute inline-flex items-center justify-center rounded-full font-medium",
|
|
18
|
+
{
|
|
19
|
+
variants: {
|
|
20
|
+
variant: {
|
|
21
|
+
default: "bg-primary text-primary-foreground",
|
|
22
|
+
secondary: "bg-secondary text-secondary-foreground",
|
|
23
|
+
destructive: "bg-destructive text-white",
|
|
24
|
+
success: "bg-[hsl(var(--success))] text-white",
|
|
25
|
+
warning: "bg-[hsl(var(--warning))] text-white",
|
|
26
|
+
},
|
|
27
|
+
size: {
|
|
28
|
+
// Dot-only base dimensions; labeled mode overrides height + min-width below
|
|
29
|
+
sm: "size-1.5",
|
|
30
|
+
default: "size-2.5",
|
|
31
|
+
lg: "size-3.5",
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
defaultVariants: {
|
|
35
|
+
variant: "default",
|
|
36
|
+
size: "default",
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
const positionMap: Record<Position, string> = {
|
|
42
|
+
"top-right": "top-0 right-0 -translate-y-1/2 translate-x-1/2",
|
|
43
|
+
"top-left": "top-0 left-0 -translate-y-1/2 -translate-x-1/2",
|
|
44
|
+
"bottom-right": "bottom-0 right-0 translate-y-1/2 translate-x-1/2",
|
|
45
|
+
"bottom-left": "bottom-0 left-0 translate-y-1/2 -translate-x-1/2",
|
|
46
|
+
"middle-right": "top-1/2 right-0 -translate-y-1/2 translate-x-1/2",
|
|
47
|
+
"middle-left": "top-1/2 left-0 -translate-y-1/2 -translate-x-1/2",
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface IndicatorProps
|
|
51
|
+
extends Omit<React.HTMLAttributes<HTMLSpanElement>, "children">,
|
|
52
|
+
VariantProps<typeof indicatorDotVariants> {
|
|
53
|
+
/** Element to attach the indicator badge to. Required. */
|
|
54
|
+
children: React.ReactNode
|
|
55
|
+
/** Corner / side position of the dot. Default "top-right". */
|
|
56
|
+
position?: Position
|
|
57
|
+
/** Content inside the dot (count, icon). Omit for a plain dot. Ignored when size="sm". */
|
|
58
|
+
label?: React.ReactNode
|
|
59
|
+
/** Adds a 2px background ring around the dot for contrast on any surface. */
|
|
60
|
+
withBorder?: boolean
|
|
61
|
+
/** Pulsing ping animation — use for live / unread signals. */
|
|
62
|
+
processing?: boolean
|
|
63
|
+
/** Hides the dot, rendering only the children. */
|
|
64
|
+
disabled?: boolean
|
|
65
|
+
/** aria-label for the indicator region. Defaults to the string value of label. */
|
|
66
|
+
indicatorLabel?: string
|
|
67
|
+
/** className forwarded to the dot span. */
|
|
68
|
+
indicatorClassName?: string
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function Indicator({
|
|
72
|
+
children,
|
|
73
|
+
position = "top-right",
|
|
74
|
+
label,
|
|
75
|
+
withBorder = false,
|
|
76
|
+
processing = false,
|
|
77
|
+
disabled = false,
|
|
78
|
+
variant = "default",
|
|
79
|
+
size = "default",
|
|
80
|
+
indicatorLabel,
|
|
81
|
+
indicatorClassName,
|
|
82
|
+
className,
|
|
83
|
+
...props
|
|
84
|
+
}: IndicatorProps) {
|
|
85
|
+
const hasContent = label !== undefined && label !== null && label !== ""
|
|
86
|
+
// sm is always dot-only; for other sizes only show label if content exists
|
|
87
|
+
const showLabel = hasContent && size !== "sm"
|
|
88
|
+
|
|
89
|
+
const displayLabel =
|
|
90
|
+
typeof label === "number" && label > 99 ? "99+" : label
|
|
91
|
+
|
|
92
|
+
const dotAriaLabel =
|
|
93
|
+
indicatorLabel ??
|
|
94
|
+
(typeof label === "string" || typeof label === "number" ? String(label) : undefined)
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<span
|
|
98
|
+
data-slot="indicator"
|
|
99
|
+
className={cn("relative inline-flex shrink-0", className)}
|
|
100
|
+
{...props}
|
|
101
|
+
>
|
|
102
|
+
{children}
|
|
103
|
+
{!disabled && (
|
|
104
|
+
<>
|
|
105
|
+
{/* Ping ring for processing state (renders behind the solid dot) */}
|
|
106
|
+
{processing && (
|
|
107
|
+
<span
|
|
108
|
+
aria-hidden="true"
|
|
109
|
+
className={cn(
|
|
110
|
+
"absolute rounded-full animate-ping opacity-60",
|
|
111
|
+
positionMap[position],
|
|
112
|
+
indicatorDotVariants({ variant, size })
|
|
113
|
+
)}
|
|
114
|
+
/>
|
|
115
|
+
)}
|
|
116
|
+
<span
|
|
117
|
+
data-slot="indicator-dot"
|
|
118
|
+
role={dotAriaLabel ? "status" : undefined}
|
|
119
|
+
aria-label={dotAriaLabel}
|
|
120
|
+
aria-hidden={!dotAriaLabel ? "true" : undefined}
|
|
121
|
+
style={{
|
|
122
|
+
transitionDuration: "var(--duration-fast)",
|
|
123
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
124
|
+
}}
|
|
125
|
+
className={cn(
|
|
126
|
+
indicatorDotVariants({ variant, size }),
|
|
127
|
+
positionMap[position],
|
|
128
|
+
// Labeled mode: override to minimum 14px text + taller dot (AAA SC 1.4.4)
|
|
129
|
+
showLabel && "text-xs leading-none px-1",
|
|
130
|
+
showLabel && size === "default" && "h-4 min-w-4",
|
|
131
|
+
showLabel && size === "lg" && "h-5 min-w-5",
|
|
132
|
+
withBorder && "ring-2 ring-background",
|
|
133
|
+
indicatorClassName
|
|
134
|
+
)}
|
|
135
|
+
>
|
|
136
|
+
{showLabel ? displayLabel : null}
|
|
137
|
+
</span>
|
|
138
|
+
</>
|
|
139
|
+
)}
|
|
140
|
+
</span>
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export { Indicator, indicatorDotVariants }
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
3
|
+
|
|
4
|
+
import { cn } from "../../lib/utils"
|
|
5
|
+
|
|
6
|
+
// ─── List root ────────────────────────────────────────────────────────────────
|
|
7
|
+
|
|
8
|
+
const listVariants = cva("flex flex-col list-none p-0 m-0", {
|
|
9
|
+
variants: {
|
|
10
|
+
spacing: {
|
|
11
|
+
sm: "gap-1",
|
|
12
|
+
default: "gap-2",
|
|
13
|
+
lg: "gap-3",
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
defaultVariants: {
|
|
17
|
+
spacing: "default",
|
|
18
|
+
},
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
export interface ListProps
|
|
22
|
+
extends React.ComponentPropsWithoutRef<"ul">,
|
|
23
|
+
VariantProps<typeof listVariants> {
|
|
24
|
+
/** "ul" (default) or "ol" — controls the semantic element rendered */
|
|
25
|
+
type?: "ul" | "ol"
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function List({ className, type = "ul", spacing, children, ...props }: ListProps) {
|
|
29
|
+
const Tag = type as React.ElementType
|
|
30
|
+
return (
|
|
31
|
+
<Tag
|
|
32
|
+
data-slot="list"
|
|
33
|
+
className={cn(listVariants({ spacing }), className)}
|
|
34
|
+
{...props}
|
|
35
|
+
>
|
|
36
|
+
{children}
|
|
37
|
+
</Tag>
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// ─── ListItem ─────────────────────────────────────────────────────────────────
|
|
42
|
+
|
|
43
|
+
export interface ListItemProps extends React.ComponentPropsWithoutRef<"li"> {
|
|
44
|
+
/** Optional icon rendered before the text — sized at 16 px and aligned to the first line */
|
|
45
|
+
icon?: React.ReactNode
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function ListItem({ className, icon, children, ...props }: ListItemProps) {
|
|
49
|
+
return (
|
|
50
|
+
<li
|
|
51
|
+
data-slot="list-item"
|
|
52
|
+
className={cn("flex items-start gap-2 text-sm leading-relaxed", className)}
|
|
53
|
+
{...props}
|
|
54
|
+
>
|
|
55
|
+
{icon ? (
|
|
56
|
+
<span
|
|
57
|
+
data-slot="list-item-icon"
|
|
58
|
+
className="mt-0.5 shrink-0 text-muted-foreground [&>svg]:size-4 [&>svg]:stroke-[1.5]"
|
|
59
|
+
>
|
|
60
|
+
{icon}
|
|
61
|
+
</span>
|
|
62
|
+
) : null}
|
|
63
|
+
<span data-slot="list-item-content" className="flex-1 min-w-0">
|
|
64
|
+
{children}
|
|
65
|
+
</span>
|
|
66
|
+
</li>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export { List, listVariants, ListItem }
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { CheckIcon, ChevronsUpDownIcon, XIcon } from "lucide-react"
|
|
5
|
+
import { cn } from "../../lib/utils"
|
|
6
|
+
import { Badge } from "./badge"
|
|
7
|
+
import {
|
|
8
|
+
Command,
|
|
9
|
+
CommandEmpty,
|
|
10
|
+
CommandGroup,
|
|
11
|
+
CommandInput,
|
|
12
|
+
CommandItem,
|
|
13
|
+
CommandList,
|
|
14
|
+
} from "./command"
|
|
15
|
+
import { Popover, PopoverContent, PopoverTrigger } from "./popover"
|
|
16
|
+
|
|
17
|
+
export interface MultiSelectOption {
|
|
18
|
+
value: string
|
|
19
|
+
label: string
|
|
20
|
+
disabled?: boolean
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface MultiSelectProps {
|
|
24
|
+
options: MultiSelectOption[]
|
|
25
|
+
value?: string[]
|
|
26
|
+
onValueChange?: (values: string[]) => void
|
|
27
|
+
placeholder?: string
|
|
28
|
+
searchPlaceholder?: string
|
|
29
|
+
emptyText?: string
|
|
30
|
+
disabled?: boolean
|
|
31
|
+
maxCount?: number
|
|
32
|
+
className?: string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function MultiSelect({
|
|
36
|
+
options,
|
|
37
|
+
value = [],
|
|
38
|
+
onValueChange,
|
|
39
|
+
placeholder = "Select options...",
|
|
40
|
+
searchPlaceholder = "Search...",
|
|
41
|
+
emptyText = "No results found.",
|
|
42
|
+
disabled = false,
|
|
43
|
+
maxCount,
|
|
44
|
+
className,
|
|
45
|
+
}: MultiSelectProps) {
|
|
46
|
+
const [open, setOpen] = React.useState(false)
|
|
47
|
+
|
|
48
|
+
function toggle(optValue: string) {
|
|
49
|
+
const next = value.includes(optValue)
|
|
50
|
+
? value.filter((v) => v !== optValue)
|
|
51
|
+
: [...value, optValue]
|
|
52
|
+
onValueChange?.(next)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function removeAt(optValue: string, e: React.MouseEvent) {
|
|
56
|
+
e.stopPropagation()
|
|
57
|
+
onValueChange?.(value.filter((v) => v !== optValue))
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const selectedOptions = options.filter((o) => value.includes(o.value))
|
|
61
|
+
const visibleSelected = maxCount
|
|
62
|
+
? selectedOptions.slice(0, maxCount)
|
|
63
|
+
: selectedOptions
|
|
64
|
+
const overflowCount =
|
|
65
|
+
maxCount && selectedOptions.length > maxCount
|
|
66
|
+
? selectedOptions.length - maxCount
|
|
67
|
+
: 0
|
|
68
|
+
|
|
69
|
+
const triggerLabel =
|
|
70
|
+
value.length > 0
|
|
71
|
+
? `${value.length} option${value.length === 1 ? "" : "s"} selected`
|
|
72
|
+
: placeholder
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
76
|
+
{/*
|
|
77
|
+
* Architecture: absolutely-positioned transparent <button> is the PopoverTrigger,
|
|
78
|
+
* filling the visual container via inset-0. This satisfies axe because:
|
|
79
|
+
* 1. aria-expanded / aria-controls from Radix land on a <button> — valid per ARIA.
|
|
80
|
+
* 2. X-remove <button> pills live in a sibling z-10 span, NOT nested inside the
|
|
81
|
+
* trigger button — no axe nested-interactive violation.
|
|
82
|
+
* DOM order: trigger button first → Tab lands on the trigger before X buttons.
|
|
83
|
+
* Focus ring: has-[:focus-visible] on the container lights up for both the trigger
|
|
84
|
+
* button and individual X buttons, keeping the whole component visually in focus.
|
|
85
|
+
*/}
|
|
86
|
+
<div
|
|
87
|
+
data-slot="multi-select"
|
|
88
|
+
className={cn(
|
|
89
|
+
"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
|
+
"cursor-default select-none",
|
|
91
|
+
"hover:bg-accent/50",
|
|
92
|
+
"has-[:focus-visible]:outline-none has-[:focus-visible]:ring-[3px] has-[:focus-visible]:ring-ring/50 has-[:focus-visible]:border-ring",
|
|
93
|
+
disabled && "pointer-events-none cursor-not-allowed opacity-50",
|
|
94
|
+
className
|
|
95
|
+
)}
|
|
96
|
+
style={{
|
|
97
|
+
transitionDuration: "var(--duration-fast)",
|
|
98
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
99
|
+
}}
|
|
100
|
+
>
|
|
101
|
+
{/* Trigger: absolute-fill transparent button — first in DOM for correct tab order */}
|
|
102
|
+
<PopoverTrigger asChild>
|
|
103
|
+
<button
|
|
104
|
+
type="button"
|
|
105
|
+
aria-haspopup="listbox"
|
|
106
|
+
aria-label={triggerLabel}
|
|
107
|
+
disabled={disabled}
|
|
108
|
+
tabIndex={disabled ? -1 : 0}
|
|
109
|
+
className="absolute inset-0 z-0 rounded-md focus-visible:outline-none"
|
|
110
|
+
/>
|
|
111
|
+
</PopoverTrigger>
|
|
112
|
+
|
|
113
|
+
{/* Pills + placeholder: z-10 so they render above the trigger button.
|
|
114
|
+
pointer-events-none lets clicks on badge labels fall through to the
|
|
115
|
+
trigger button; X buttons restore pointer-events-auto for themselves. */}
|
|
116
|
+
<span className="relative z-10 flex flex-wrap gap-1 min-w-0 flex-1 pointer-events-none">
|
|
117
|
+
{visibleSelected.length > 0 ? (
|
|
118
|
+
<>
|
|
119
|
+
{visibleSelected.map((opt) => (
|
|
120
|
+
<Badge
|
|
121
|
+
key={opt.value}
|
|
122
|
+
variant="secondary"
|
|
123
|
+
className="gap-1 pr-1 font-normal py-0 min-h-6"
|
|
124
|
+
>
|
|
125
|
+
<span className="truncate max-w-[120px]">{opt.label}</span>
|
|
126
|
+
<button
|
|
127
|
+
type="button"
|
|
128
|
+
aria-label={`Remove ${opt.label}`}
|
|
129
|
+
onClick={(e) => removeAt(opt.value, e)}
|
|
130
|
+
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"
|
|
131
|
+
style={{
|
|
132
|
+
transitionDuration: "var(--duration-fast)",
|
|
133
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
134
|
+
}}
|
|
135
|
+
>
|
|
136
|
+
<XIcon size={10} strokeWidth={1.5} />
|
|
137
|
+
</button>
|
|
138
|
+
</Badge>
|
|
139
|
+
))}
|
|
140
|
+
{overflowCount > 0 && (
|
|
141
|
+
<Badge variant="secondary" className="font-normal">
|
|
142
|
+
+{overflowCount} more
|
|
143
|
+
</Badge>
|
|
144
|
+
)}
|
|
145
|
+
</>
|
|
146
|
+
) : (
|
|
147
|
+
<span className="text-muted-foreground">{placeholder}</span>
|
|
148
|
+
)}
|
|
149
|
+
</span>
|
|
150
|
+
|
|
151
|
+
{/* Chevron: z-10 and pointer-events-none — the trigger button beneath handles clicks */}
|
|
152
|
+
<ChevronsUpDownIcon
|
|
153
|
+
strokeWidth={1.5}
|
|
154
|
+
className="relative z-10 ml-2 size-4 shrink-0 opacity-50 pointer-events-none transition-[opacity,transform]"
|
|
155
|
+
style={{
|
|
156
|
+
transitionDuration: "var(--duration-fast)",
|
|
157
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
158
|
+
}}
|
|
159
|
+
/>
|
|
160
|
+
</div>
|
|
161
|
+
<PopoverContent className="w-[var(--radix-popover-trigger-width)] min-w-[200px] p-0">
|
|
162
|
+
<Command>
|
|
163
|
+
<CommandInput placeholder={searchPlaceholder} />
|
|
164
|
+
<CommandList>
|
|
165
|
+
<CommandEmpty>{emptyText}</CommandEmpty>
|
|
166
|
+
<CommandGroup>
|
|
167
|
+
{options.map((option) => (
|
|
168
|
+
<CommandItem
|
|
169
|
+
key={option.value}
|
|
170
|
+
value={option.value}
|
|
171
|
+
disabled={option.disabled}
|
|
172
|
+
onSelect={() => toggle(option.value)}
|
|
173
|
+
>
|
|
174
|
+
<CheckIcon
|
|
175
|
+
strokeWidth={1.5}
|
|
176
|
+
className={cn(
|
|
177
|
+
"mr-2 size-4 shrink-0 transition-opacity",
|
|
178
|
+
value.includes(option.value) ? "opacity-100" : "opacity-0"
|
|
179
|
+
)}
|
|
180
|
+
style={{
|
|
181
|
+
transitionDuration: "var(--duration-fast)",
|
|
182
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
183
|
+
}}
|
|
184
|
+
/>
|
|
185
|
+
{option.label}
|
|
186
|
+
</CommandItem>
|
|
187
|
+
))}
|
|
188
|
+
</CommandGroup>
|
|
189
|
+
</CommandList>
|
|
190
|
+
</Command>
|
|
191
|
+
</PopoverContent>
|
|
192
|
+
</Popover>
|
|
193
|
+
)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export { MultiSelect }
|
|
@@ -24,7 +24,7 @@ export type PrimaryColorOption = {
|
|
|
24
24
|
custom?: boolean;
|
|
25
25
|
/**
|
|
26
26
|
* Optional override for the picker swatch when the displayed color should
|
|
27
|
-
* differ from the applied primary. Carried over from
|
|
27
|
+
* differ from the applied primary. Carried over from a client fork's customize
|
|
28
28
|
* tab (e.g. an "Off White" option that applies dark in light mode but the
|
|
29
29
|
* picker still reads off-white). BADS' built-in palette doesn't set these.
|
|
30
30
|
*/
|
package/src/styles.css
CHANGED
|
@@ -480,7 +480,7 @@
|
|
|
480
480
|
* role. Disabled state → cursor: not-allowed so "off" reads as
|
|
481
481
|
* intentional rather than broken.
|
|
482
482
|
*
|
|
483
|
-
* Promoted from
|
|
483
|
+
* Promoted from a client fork's globals.css (2026-06-10) per
|
|
484
484
|
* Sir's "if it's clickable, the cursor says so" rule. */
|
|
485
485
|
button:not(:disabled),
|
|
486
486
|
a[href]:not([aria-disabled="true"]),
|
|
@@ -524,7 +524,7 @@ html, body {
|
|
|
524
524
|
written to --x / --y on <html> before startViewTransition fires (see
|
|
525
525
|
app/page.tsx toggleDark).
|
|
526
526
|
|
|
527
|
-
Two deliberate choices, both learned the hard way (
|
|
527
|
+
Two deliberate choices, both learned the hard way (a client fork, 2026-06):
|
|
528
528
|
1. Radius is a VIEWPORT unit (150vmax), not a percentage. circle(150%)
|
|
529
529
|
resolves against the snapshot box, so on a large/wide desktop the wipe
|
|
530
530
|
can finish before it has covered the viewport — a glitch at the END of
|