@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
|
@@ -143,6 +143,12 @@ export function LayersTab() {
|
|
|
143
143
|
// null = loading; [] = loaded-but-empty. Only used by the synthetic
|
|
144
144
|
// semantic-tokens view.
|
|
145
145
|
const [semanticTokens, setSemanticTokens] = useState<SemanticToken[] | null>(null);
|
|
146
|
+
// Content-fetch lifecycle for the reading pane. Without this the pane
|
|
147
|
+
// rendered a SILENT BLANK on a slow/failed `/api/layers/file` fetch (the
|
|
148
|
+
// symptom Sir hit on a just-deployed Vercel function before its doc files
|
|
149
|
+
// were traced in). "loading" shows a spinner; "error" shows a retry.
|
|
150
|
+
const [fileStatus, setFileStatus] = useState<"idle" | "loading" | "error">("idle");
|
|
151
|
+
const [reloadKey, setReloadKey] = useState(0);
|
|
146
152
|
|
|
147
153
|
// Load tree
|
|
148
154
|
useEffect(() => {
|
|
@@ -162,6 +168,7 @@ export function LayersTab() {
|
|
|
162
168
|
if (!activePath) return;
|
|
163
169
|
setStatus("idle");
|
|
164
170
|
setStatusMessage("");
|
|
171
|
+
setFileStatus("idle");
|
|
165
172
|
|
|
166
173
|
// Markdown files default to the rendered preview so they're never blank.
|
|
167
174
|
if (isMarkdown(activePath)) {
|
|
@@ -197,18 +204,27 @@ export function LayersTab() {
|
|
|
197
204
|
}
|
|
198
205
|
|
|
199
206
|
setFileType(getFileType(activePath));
|
|
207
|
+
setFileStatus("loading");
|
|
200
208
|
fetch(`/api/layers/file?path=${encodeURIComponent(activePath)}`)
|
|
201
|
-
.then((r) =>
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
209
|
+
.then(async (r) => {
|
|
210
|
+
const data = await r.json().catch(() => ({}));
|
|
211
|
+
// The API returns { error } with a non-2xx status for not-found /
|
|
212
|
+
// invalid paths; treat a missing string body as a failure too, so a
|
|
213
|
+
// transient 404 surfaces as an error state instead of a blank pane.
|
|
214
|
+
if (!r.ok || typeof data.content !== "string") {
|
|
215
|
+
throw new Error(data.error ?? "Failed to load");
|
|
216
|
+
}
|
|
217
|
+
setContent(data.content);
|
|
218
|
+
setOriginalContent(data.content);
|
|
205
219
|
setCommitMessage(`docs: edit ${activePath}`);
|
|
220
|
+
setFileStatus("idle");
|
|
206
221
|
})
|
|
207
222
|
.catch(() => {
|
|
208
223
|
setContent("");
|
|
209
224
|
setOriginalContent("");
|
|
225
|
+
setFileStatus("error");
|
|
210
226
|
});
|
|
211
|
-
}, [activePath]);
|
|
227
|
+
}, [activePath, reloadKey]);
|
|
212
228
|
|
|
213
229
|
const dirty = content !== originalContent;
|
|
214
230
|
|
|
@@ -424,6 +440,22 @@ export function LayersTab() {
|
|
|
424
440
|
|
|
425
441
|
{activePath === SEMANTIC_VIEW ? (
|
|
426
442
|
<SemanticTokensView tokens={semanticTokens} />
|
|
443
|
+
) : fileStatus === "loading" ? (
|
|
444
|
+
<div className="flex-1 flex items-center justify-center text-muted-foreground">
|
|
445
|
+
<Loader2 className="h-4 w-4 animate-spin" strokeWidth={1.5} />
|
|
446
|
+
<span className="ml-2 text-sm">Loading…</span>
|
|
447
|
+
</div>
|
|
448
|
+
) : fileStatus === "error" ? (
|
|
449
|
+
<div className="flex-1 flex items-center justify-center px-6">
|
|
450
|
+
<div className="text-center">
|
|
451
|
+
<AlertCircle className="h-8 w-8 mx-auto mb-3 text-muted-foreground" strokeWidth={1.5} />
|
|
452
|
+
<p className="text-sm text-foreground mb-1">Couldn't load this document.</p>
|
|
453
|
+
<p className="text-xs text-muted-foreground font-mono mb-4 break-all">{activePath}</p>
|
|
454
|
+
<Button variant="outline" size="sm" onClick={() => setReloadKey((k) => k + 1)}>
|
|
455
|
+
Retry
|
|
456
|
+
</Button>
|
|
457
|
+
</div>
|
|
458
|
+
</div>
|
|
427
459
|
) : fileType === "read-only" ? (
|
|
428
460
|
<div className="flex-1 rounded-none border-0 font-mono text-sm leading-relaxed overflow-auto bg-muted/30 p-6">
|
|
429
461
|
<pre className="whitespace-pre-wrap break-words text-foreground/80">
|
|
@@ -36,6 +36,18 @@ const alertVariants = cva(
|
|
|
36
36
|
// destructive tokens should re-check with `pnpm wcag:audit`.
|
|
37
37
|
destructive:
|
|
38
38
|
"border-[var(--destructive)]! border-l-4 bg-destructive/5 text-destructive *:data-[slot=alert-description]:text-destructive/90 [&>svg]:text-current dark:bg-destructive/10",
|
|
39
|
+
// Semantic status variants: left-bar accent pattern (same as default)
|
|
40
|
+
// so alerts and Sonner toasts read as one system. text-foreground keeps
|
|
41
|
+
// body text at AAA contrast; icon and accent use the semantic token.
|
|
42
|
+
// bg-success/warning/info uses the new --color-* @theme inline entries
|
|
43
|
+
// so opacity modifiers compile. Non-text AAA: success 4.5:1 ≥ 3:1 ✓,
|
|
44
|
+
// warning 4.4:1 ≥ 3:1 ✓, info 4.8:1 ≥ 3:1 ✓ (wcag:audit).
|
|
45
|
+
success:
|
|
46
|
+
"border-border border-l-4 border-l-[var(--success)]! bg-success/5 text-foreground [&>svg]:text-success dark:bg-success/10",
|
|
47
|
+
warning:
|
|
48
|
+
"border-border border-l-4 border-l-[var(--warning)]! bg-warning/5 text-foreground [&>svg]:text-warning dark:bg-warning/10",
|
|
49
|
+
info:
|
|
50
|
+
"border-border border-l-4 border-l-[var(--info)]! bg-info/5 text-foreground [&>svg]:text-info dark:bg-info/10",
|
|
39
51
|
},
|
|
40
52
|
},
|
|
41
53
|
defaultVariants: {
|
|
@@ -18,6 +18,25 @@ const badgeVariants = cva(
|
|
|
18
18
|
"border-border text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground",
|
|
19
19
|
ghost: "[a&]:hover:bg-accent [a&]:hover:text-accent-foreground",
|
|
20
20
|
link: "text-primary underline-offset-4 [a&]:hover:underline",
|
|
21
|
+
// Semantic status variants (peer parity: Mantine Badge color,
|
|
22
|
+
// Chakra colorPalette, Ant Design status Tags). Same color language
|
|
23
|
+
// as Alert's status variants so badges and alerts read as one
|
|
24
|
+
// system: semantic-token border + subtle tinted background + icon in
|
|
25
|
+
// the semantic color. Text stays text-foreground — the raw
|
|
26
|
+
// success/warning/info tokens sit at ~4.4-4.8:1 in light mode, which
|
|
27
|
+
// passes the 3:1 non-text floor (border/icon) but NOT the 7:1 AAA
|
|
28
|
+
// text floor, so the label never takes the semantic color.
|
|
29
|
+
//
|
|
30
|
+
// NOTE: border color uses arbitrary `border-[var(--token)]!` — the
|
|
31
|
+
// named border-color utilities don't generate a rule in this
|
|
32
|
+
// Tailwind v4 setup (see the same note in alert.tsx) and `!` beats
|
|
33
|
+
// the base `border-transparent`.
|
|
34
|
+
success:
|
|
35
|
+
"border-[var(--success)]! bg-success/10 text-foreground [&>svg]:text-success dark:bg-success/15",
|
|
36
|
+
warning:
|
|
37
|
+
"border-[var(--warning)]! bg-warning/10 text-foreground [&>svg]:text-warning dark:bg-warning/15",
|
|
38
|
+
info:
|
|
39
|
+
"border-[var(--info)]! bg-info/10 text-foreground [&>svg]:text-info dark:bg-info/15",
|
|
21
40
|
},
|
|
22
41
|
},
|
|
23
42
|
defaultVariants: {
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
// Button always attaches an internal onClick/onKeyDown (handleClick guards the
|
|
4
|
+
// aria-disabled pattern, handleKeyDown blocks Enter/Space on it), so it hands a
|
|
5
|
+
// function to the DOM on every render — even when the caller passes no
|
|
6
|
+
// callbacks at all. Rendered from a server component that fails at prerender
|
|
7
|
+
// with "Event handlers cannot be passed to Client Component props". Alert, Tag,
|
|
8
|
+
// Input and Notification deliberately do NOT carry this directive: they only
|
|
9
|
+
// attach a handler when the consumer passes one, which is inherently a
|
|
10
|
+
// client-side act, so they stay server-renderable.
|
|
1
11
|
import * as React from "react"
|
|
2
12
|
import { cva, type VariantProps } from "class-variance-authority"
|
|
3
13
|
import { Slot } from "@radix-ui/react-slot"
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ChatMarker — inline date, status, or session separator for chat flows.
|
|
5
|
+
*
|
|
6
|
+
* Sources: shadcn/ui June 2026 chat release (Marker); standard chat UI
|
|
7
|
+
* convention (iMessage, WhatsApp, Telegram, Slack date dividers).
|
|
8
|
+
*
|
|
9
|
+
* Usage: drop between groups of <ChatBubble> messages to separate by date
|
|
10
|
+
* ("Today", "Yesterday"), status ("Seen", "Delivered"), or session break
|
|
11
|
+
* (plain horizontal rule variant).
|
|
12
|
+
*
|
|
13
|
+
* Accessibility: role="separator" + aria-label for screen readers. The label
|
|
14
|
+
* defaults to the visible text; callers may pass a more descriptive
|
|
15
|
+
* aria-label when the visible label is ambiguous (e.g. "Mon" → "Monday").
|
|
16
|
+
*
|
|
17
|
+
* Motion (spec §4):
|
|
18
|
+
* - entrance: animate-in fade-in-0 (pattern a, same vocabulary as tooltips)
|
|
19
|
+
* - no hover state — this is a presentational separator
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import * as React from "react"
|
|
23
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
24
|
+
|
|
25
|
+
import { cn } from "../../lib/utils"
|
|
26
|
+
|
|
27
|
+
const chatMarkerVariants = cva(
|
|
28
|
+
[
|
|
29
|
+
"my-3 flex items-center gap-3 animate-in fade-in-0",
|
|
30
|
+
"text-xs text-muted-foreground select-none",
|
|
31
|
+
],
|
|
32
|
+
{
|
|
33
|
+
variants: {
|
|
34
|
+
variant: {
|
|
35
|
+
/** Label flanked by horizontal rules — for dates and session breaks. */
|
|
36
|
+
default: "",
|
|
37
|
+
/** Unadorned centered text — for status lines ("Seen 2:14 PM"). */
|
|
38
|
+
status: "justify-center",
|
|
39
|
+
/** Full-width rule with no text — a silent session break. */
|
|
40
|
+
divider: "",
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
defaultVariants: {
|
|
44
|
+
variant: "default",
|
|
45
|
+
},
|
|
46
|
+
}
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
export interface ChatMarkerProps
|
|
50
|
+
extends Omit<React.ComponentProps<"div">, "children">,
|
|
51
|
+
VariantProps<typeof chatMarkerVariants> {
|
|
52
|
+
/** Visible label text. Omit for the `divider` variant. */
|
|
53
|
+
label?: string
|
|
54
|
+
/** Accessible label override when the visible text is abbreviated. */
|
|
55
|
+
"aria-label"?: string
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function ChatMarker({
|
|
59
|
+
label,
|
|
60
|
+
variant = "default",
|
|
61
|
+
className,
|
|
62
|
+
"aria-label": ariaLabel,
|
|
63
|
+
...props
|
|
64
|
+
}: ChatMarkerProps) {
|
|
65
|
+
const effectiveAriaLabel = ariaLabel ?? label
|
|
66
|
+
|
|
67
|
+
if (variant === "divider") {
|
|
68
|
+
return (
|
|
69
|
+
<div
|
|
70
|
+
role="separator"
|
|
71
|
+
aria-label="conversation break"
|
|
72
|
+
data-slot="chat-marker"
|
|
73
|
+
data-variant="divider"
|
|
74
|
+
className={cn("my-4 h-px w-full bg-border/60", className)}
|
|
75
|
+
{...props}
|
|
76
|
+
/>
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (variant === "status") {
|
|
81
|
+
return (
|
|
82
|
+
<div
|
|
83
|
+
role="separator"
|
|
84
|
+
aria-label={effectiveAriaLabel}
|
|
85
|
+
data-slot="chat-marker"
|
|
86
|
+
data-variant="status"
|
|
87
|
+
className={cn(chatMarkerVariants({ variant }), className)}
|
|
88
|
+
{...props}
|
|
89
|
+
>
|
|
90
|
+
{label && <span>{label}</span>}
|
|
91
|
+
</div>
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// default: label flanked by lines
|
|
96
|
+
return (
|
|
97
|
+
<div
|
|
98
|
+
role="separator"
|
|
99
|
+
aria-label={effectiveAriaLabel}
|
|
100
|
+
data-slot="chat-marker"
|
|
101
|
+
data-variant="default"
|
|
102
|
+
className={cn(chatMarkerVariants({ variant }), className)}
|
|
103
|
+
{...props}
|
|
104
|
+
>
|
|
105
|
+
<span
|
|
106
|
+
className="h-px flex-1 bg-border/60"
|
|
107
|
+
style={{
|
|
108
|
+
transitionDuration: "var(--duration-fast)",
|
|
109
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
110
|
+
}}
|
|
111
|
+
/>
|
|
112
|
+
{label && (
|
|
113
|
+
<span className="shrink-0 font-medium">{label}</span>
|
|
114
|
+
)}
|
|
115
|
+
<span className="h-px flex-1 bg-border/60" />
|
|
116
|
+
</div>
|
|
117
|
+
)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export { ChatMarker, chatMarkerVariants }
|
|
@@ -14,7 +14,15 @@ function Checkbox({
|
|
|
14
14
|
<CheckboxPrimitive.Root
|
|
15
15
|
data-slot="checkbox"
|
|
16
16
|
className={cn(
|
|
17
|
-
|
|
17
|
+
// The visible box stays 32px (size-8) for tonal density, but the
|
|
18
|
+
// POINTER TARGET must hit WCAG 2.2 SC 2.5.5 Enhanced (44×44, the AAA
|
|
19
|
+
// floor). A centered transparent ::before overlay (before:size-11 =
|
|
20
|
+
// 44px) extends the interactive area without enlarging the box — a
|
|
21
|
+
// pseudo-element hit-tests to its host, so clicks in the padding toggle
|
|
22
|
+
// the checkbox. It's absolutely positioned, so it adds zero layout
|
|
23
|
+
// (respects the no-jump / layout-stability principle) and never touches
|
|
24
|
+
// a neighbor's flow. Focus ring stays on the visible 32px box.
|
|
25
|
+
"peer relative inline-flex size-8 shrink-0 items-center justify-center rounded-[4px] border-2 border-muted-foreground/60 bg-white leading-none shadow-xs transition-[background-color,border-color,color] duration-[210ms] ease-in-out outline-none before:absolute before:left-1/2 before:top-1/2 before:size-11 before:-translate-x-1/2 before:-translate-y-1/2 before:content-[''] focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground data-[state=indeterminate]:border-primary data-[state=indeterminate]:bg-primary data-[state=indeterminate]:text-primary-foreground dark:aria-invalid:ring-destructive/40",
|
|
18
26
|
className
|
|
19
27
|
)}
|
|
20
28
|
{...props}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { XIcon } from "lucide-react";
|
|
5
|
+
import type { VariantProps } from "class-variance-authority";
|
|
6
|
+
import { cn } from "../../lib/utils";
|
|
7
|
+
import { Button, buttonVariants } from "./button";
|
|
8
|
+
|
|
9
|
+
// ─── CloseButton ───────────────────────────────────────────────────────────────
|
|
10
|
+
//
|
|
11
|
+
// Standardized dismiss affordance: a ghost icon Button with a built-in
|
|
12
|
+
// 1.5-stroke X and a guaranteed accessible name (default aria-label "Close",
|
|
13
|
+
// always overridable). Exists so every hand-rolled close X — dismissible
|
|
14
|
+
// banners, filter pills, side panels, inline previews — ships with the
|
|
15
|
+
// accessible name and the system stroke weight by default, instead of
|
|
16
|
+
// re-triggering the "icon-only button with no accessible name" a11y-lint
|
|
17
|
+
// finding one surface at a time.
|
|
18
|
+
//
|
|
19
|
+
// Inherits Button's focus ring, disabled handling, and hover/press color
|
|
20
|
+
// motion (transition-colors) wholesale. Cross-system references: Mantine
|
|
21
|
+
// CloseButton, Chakra UI CloseButton.
|
|
22
|
+
//
|
|
23
|
+
// NOT for: Dialog/Sheet content (they ship their own corner X — don't double
|
|
24
|
+
// up), or destructive deletion (that's Button variant="destructive" behind an
|
|
25
|
+
// AlertDialog confirm).
|
|
26
|
+
|
|
27
|
+
type IconSize = "icon-xs" | "icon-sm" | "icon" | "icon-lg" | "icon-xl";
|
|
28
|
+
|
|
29
|
+
export interface CloseButtonProps
|
|
30
|
+
extends Omit<React.ComponentPropsWithoutRef<"button">, "children">,
|
|
31
|
+
Pick<VariantProps<typeof buttonVariants>, "variant"> {
|
|
32
|
+
/**
|
|
33
|
+
* Icon-button size from the Button scale. Default "icon" (36px) — the
|
|
34
|
+
* Dialog/Sheet corner-chrome register (documented dense-chrome exception
|
|
35
|
+
* to the 44px floor). When the close IS the surface's primary
|
|
36
|
+
* flow-changing dismiss affordance, use "icon-lg" (40px) or "icon-xl"
|
|
37
|
+
* (44px, meets SC 2.5.5 Enhanced).
|
|
38
|
+
*/
|
|
39
|
+
size?: IconSize;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const CloseButton = React.forwardRef<
|
|
43
|
+
HTMLButtonElement,
|
|
44
|
+
CloseButtonProps
|
|
45
|
+
>(
|
|
46
|
+
(
|
|
47
|
+
{
|
|
48
|
+
className,
|
|
49
|
+
variant = "ghost",
|
|
50
|
+
size = "icon",
|
|
51
|
+
"aria-label": ariaLabel = "Close",
|
|
52
|
+
type = "button",
|
|
53
|
+
...props
|
|
54
|
+
},
|
|
55
|
+
ref
|
|
56
|
+
) => (
|
|
57
|
+
<Button
|
|
58
|
+
ref={ref}
|
|
59
|
+
data-slot="close-button"
|
|
60
|
+
type={type}
|
|
61
|
+
variant={variant}
|
|
62
|
+
size={size}
|
|
63
|
+
aria-label={ariaLabel}
|
|
64
|
+
className={cn("shrink-0", className)}
|
|
65
|
+
{...props}
|
|
66
|
+
>
|
|
67
|
+
<XIcon strokeWidth={1.5} aria-hidden="true" />
|
|
68
|
+
</Button>
|
|
69
|
+
)
|
|
70
|
+
);
|
|
71
|
+
CloseButton.displayName = "CloseButton";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
|
|
3
3
|
import * as React from "react"
|
|
4
|
-
import { CheckIcon, ChevronsUpDownIcon } from "lucide-react"
|
|
4
|
+
import { CheckIcon, ChevronsUpDownIcon, PlusIcon } from "lucide-react"
|
|
5
5
|
|
|
6
6
|
import { cn } from "../../lib/utils"
|
|
7
7
|
import { Button } from "./button"
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
CommandInput,
|
|
13
13
|
CommandItem,
|
|
14
14
|
CommandList,
|
|
15
|
+
CommandSeparator,
|
|
15
16
|
} from "./command"
|
|
16
17
|
import { Popover, PopoverContent, PopoverTrigger } from "./popover"
|
|
17
18
|
|
|
@@ -30,6 +31,17 @@ export interface ComboboxProps {
|
|
|
30
31
|
emptyText?: string
|
|
31
32
|
disabled?: boolean
|
|
32
33
|
className?: string
|
|
34
|
+
/**
|
|
35
|
+
* When true, shows a "Create [typed text]" option at the bottom of the dropdown
|
|
36
|
+
* if the typed text does not exactly match any existing option label.
|
|
37
|
+
* Pair with `onCreateOption` to handle the creation event.
|
|
38
|
+
*/
|
|
39
|
+
creatable?: boolean
|
|
40
|
+
/**
|
|
41
|
+
* Called with the trimmed text the user typed when they select the "Create" item.
|
|
42
|
+
* Use this to add the new option to the `options` array and update `value`.
|
|
43
|
+
*/
|
|
44
|
+
onCreateOption?: (value: string) => void
|
|
33
45
|
}
|
|
34
46
|
|
|
35
47
|
function Combobox({
|
|
@@ -41,13 +53,30 @@ function Combobox({
|
|
|
41
53
|
emptyText = "No results found.",
|
|
42
54
|
disabled = false,
|
|
43
55
|
className,
|
|
56
|
+
creatable = false,
|
|
57
|
+
onCreateOption,
|
|
44
58
|
}: ComboboxProps) {
|
|
45
59
|
const [open, setOpen] = React.useState(false)
|
|
60
|
+
const [inputValue, setInputValue] = React.useState("")
|
|
46
61
|
|
|
47
62
|
const selected = options.find((o) => o.value === value)
|
|
48
63
|
|
|
64
|
+
// Derived values for creatable — computed unconditionally but only used when
|
|
65
|
+
// creatable=true, so there is no cost to the non-creatable code path.
|
|
66
|
+
const trimmedInput = inputValue.trim()
|
|
67
|
+
const hasExactMatch =
|
|
68
|
+
trimmedInput.length > 0 &&
|
|
69
|
+
options.some((o) => o.label.toLowerCase() === trimmedInput.toLowerCase())
|
|
70
|
+
const showCreateItem = creatable && trimmedInput.length > 0 && !hasExactMatch
|
|
71
|
+
|
|
49
72
|
return (
|
|
50
|
-
<Popover
|
|
73
|
+
<Popover
|
|
74
|
+
open={open}
|
|
75
|
+
onOpenChange={(isOpen) => {
|
|
76
|
+
setOpen(isOpen)
|
|
77
|
+
if (!isOpen) setInputValue("")
|
|
78
|
+
}}
|
|
79
|
+
>
|
|
51
80
|
<PopoverTrigger asChild>
|
|
52
81
|
<Button
|
|
53
82
|
data-slot="combobox"
|
|
@@ -72,7 +101,12 @@ function Combobox({
|
|
|
72
101
|
</PopoverTrigger>
|
|
73
102
|
<PopoverContent className="w-[var(--radix-popover-trigger-width)] min-w-[200px] p-0">
|
|
74
103
|
<Command>
|
|
75
|
-
<CommandInput
|
|
104
|
+
<CommandInput
|
|
105
|
+
placeholder={searchPlaceholder}
|
|
106
|
+
{...(creatable
|
|
107
|
+
? { value: inputValue, onValueChange: setInputValue }
|
|
108
|
+
: {})}
|
|
109
|
+
/>
|
|
76
110
|
<CommandList>
|
|
77
111
|
<CommandEmpty>{emptyText}</CommandEmpty>
|
|
78
112
|
<CommandGroup>
|
|
@@ -97,6 +131,31 @@ function Combobox({
|
|
|
97
131
|
</CommandItem>
|
|
98
132
|
))}
|
|
99
133
|
</CommandGroup>
|
|
134
|
+
{showCreateItem && (
|
|
135
|
+
<>
|
|
136
|
+
<CommandSeparator />
|
|
137
|
+
<CommandGroup>
|
|
138
|
+
<CommandItem
|
|
139
|
+
// forceMount bypasses cmdk's text-match filter so the Create
|
|
140
|
+
// item is always visible while the user is typing a new value.
|
|
141
|
+
forceMount
|
|
142
|
+
value={`__create__${trimmedInput}`}
|
|
143
|
+
onSelect={() => {
|
|
144
|
+
onCreateOption?.(trimmedInput)
|
|
145
|
+
onValueChange?.(trimmedInput)
|
|
146
|
+
setInputValue("")
|
|
147
|
+
setOpen(false)
|
|
148
|
+
}}
|
|
149
|
+
>
|
|
150
|
+
<PlusIcon
|
|
151
|
+
strokeWidth={1.5}
|
|
152
|
+
className="mr-2 size-4 shrink-0 text-muted-foreground"
|
|
153
|
+
/>
|
|
154
|
+
Create “{trimmedInput}”
|
|
155
|
+
</CommandItem>
|
|
156
|
+
</CommandGroup>
|
|
157
|
+
</>
|
|
158
|
+
)}
|
|
100
159
|
</CommandList>
|
|
101
160
|
</Command>
|
|
102
161
|
</PopoverContent>
|
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
// ─── Container ─────────────────────────────────────────────────────────────────
|
|
8
|
+
//
|
|
9
|
+
// Centered max-width content wrapper. Replaces the ad-hoc
|
|
10
|
+
// `<div className="mx-auto w-full max-w-6xl px-4">` boilerplate with a
|
|
11
|
+
// token-keyed size scale, so every screen picks its content width from the
|
|
12
|
+
// same five stops instead of guessing between max-w-5xl / 6xl / 7xl.
|
|
13
|
+
//
|
|
14
|
+
// Layout-only primitive (same class as Stack/Group): no ARIA, no interaction,
|
|
15
|
+
// no motion. Cross-system references: Mantine Container, MUI Container,
|
|
16
|
+
// Chakra Container.
|
|
17
|
+
|
|
18
|
+
const containerVariants = cva("mx-auto w-full", {
|
|
19
|
+
variants: {
|
|
20
|
+
/**
|
|
21
|
+
* Maximum content width. sm → 672px (reading column), md → 896px (forms,
|
|
22
|
+
* article + aside), lg → 1152px (standard app/marketing content, default),
|
|
23
|
+
* xl → 1280px (wide dashboards), full → no cap (edge-to-edge sections
|
|
24
|
+
* that still want the shared gutters).
|
|
25
|
+
*/
|
|
26
|
+
size: {
|
|
27
|
+
sm: "max-w-2xl",
|
|
28
|
+
md: "max-w-4xl",
|
|
29
|
+
lg: "max-w-6xl",
|
|
30
|
+
xl: "max-w-7xl",
|
|
31
|
+
full: "max-w-full",
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
defaultVariants: {
|
|
35
|
+
size: "lg",
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export interface ContainerProps
|
|
40
|
+
extends React.HTMLAttributes<HTMLDivElement>,
|
|
41
|
+
VariantProps<typeof containerVariants> {
|
|
42
|
+
/**
|
|
43
|
+
* Horizontal padding (px-4, sm:px-6) so content never touches the viewport
|
|
44
|
+
* edge on small screens. Default: true. Set false when a parent already
|
|
45
|
+
* provides page gutters (avoid double gutters from nested Containers —
|
|
46
|
+
* prefer not nesting at all).
|
|
47
|
+
*/
|
|
48
|
+
gutters?: boolean;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const Container = React.forwardRef<HTMLDivElement, ContainerProps>(
|
|
52
|
+
({ className, size, gutters = true, ...props }, ref) => (
|
|
53
|
+
<div
|
|
54
|
+
ref={ref}
|
|
55
|
+
data-slot="container"
|
|
56
|
+
className={cn(
|
|
57
|
+
containerVariants({ size }),
|
|
58
|
+
gutters && "px-4 sm:px-6",
|
|
59
|
+
className
|
|
60
|
+
)}
|
|
61
|
+
{...props}
|
|
62
|
+
/>
|
|
63
|
+
)
|
|
64
|
+
);
|
|
65
|
+
Container.displayName = "Container";
|