@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,334 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { ChevronLeftIcon, ChevronRightIcon, ChevronsRightIcon } from "lucide-react"
|
|
5
|
+
import { cn } from "../../lib/utils"
|
|
6
|
+
import { Button } from "./button"
|
|
7
|
+
import { Checkbox } from "./checkbox"
|
|
8
|
+
import { RadioGroup, RadioGroupItem } from "./radio-group"
|
|
9
|
+
import { Textarea } from "./textarea"
|
|
10
|
+
|
|
11
|
+
// ─── Types ────────────────────────────────────────────────────────────────────
|
|
12
|
+
|
|
13
|
+
export type QuestionType = "single" | "multiple" | "freeform"
|
|
14
|
+
|
|
15
|
+
export interface QuestionnaireOption {
|
|
16
|
+
value: string
|
|
17
|
+
label: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface QuestionnaireQuestion {
|
|
21
|
+
/** Unique identifier — used as the key in the answers record. */
|
|
22
|
+
id: string
|
|
23
|
+
/** The question text shown to the user. */
|
|
24
|
+
prompt: string
|
|
25
|
+
/** Input type: radio, multi-checkbox, or freeform textarea. */
|
|
26
|
+
type: QuestionType
|
|
27
|
+
/** Required for type="single" and type="multiple". */
|
|
28
|
+
options?: QuestionnaireOption[]
|
|
29
|
+
/** When true, a Skip button appears alongside Next. */
|
|
30
|
+
skippable?: boolean
|
|
31
|
+
/** Override the Skip button label. Defaults to "Skip". */
|
|
32
|
+
skipLabel?: string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type QuestionnaireAnswers = Record<string, string | string[] | null>
|
|
36
|
+
|
|
37
|
+
export interface QuestionnaireProps {
|
|
38
|
+
/** Ordered list of questions. The component steps through them one at a time. */
|
|
39
|
+
questions: QuestionnaireQuestion[]
|
|
40
|
+
/** Called when every question has been answered or skipped. */
|
|
41
|
+
onComplete?: (answers: QuestionnaireAnswers) => void
|
|
42
|
+
/** Called when a question is skipped — answer is recorded as null. */
|
|
43
|
+
onSkip?: (questionId: string) => void
|
|
44
|
+
className?: string
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// ─── Internal QuestionStep ────────────────────────────────────────────────────
|
|
48
|
+
|
|
49
|
+
function QuestionStep({
|
|
50
|
+
question,
|
|
51
|
+
answer,
|
|
52
|
+
direction,
|
|
53
|
+
onAnswerChange,
|
|
54
|
+
onAdvance,
|
|
55
|
+
}: {
|
|
56
|
+
question: QuestionnaireQuestion
|
|
57
|
+
answer: string | string[] | null
|
|
58
|
+
direction: "forward" | "backward"
|
|
59
|
+
onAnswerChange: (answer: string | string[] | null) => void
|
|
60
|
+
onAdvance: () => void
|
|
61
|
+
}) {
|
|
62
|
+
const [visible, setVisible] = React.useState(false)
|
|
63
|
+
const stepId = React.useId()
|
|
64
|
+
|
|
65
|
+
// Fade + slide in from the travel direction on mount
|
|
66
|
+
React.useEffect(() => {
|
|
67
|
+
const id = requestAnimationFrame(() => setVisible(true))
|
|
68
|
+
return () => cancelAnimationFrame(id)
|
|
69
|
+
}, [])
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<div
|
|
73
|
+
role="group"
|
|
74
|
+
aria-labelledby={`${stepId}-prompt`}
|
|
75
|
+
style={{
|
|
76
|
+
opacity: visible ? 1 : 0,
|
|
77
|
+
transform: visible
|
|
78
|
+
? "translateX(0)"
|
|
79
|
+
: direction === "forward"
|
|
80
|
+
? "translateX(16px)"
|
|
81
|
+
: "translateX(-16px)",
|
|
82
|
+
transitionProperty: "opacity, transform",
|
|
83
|
+
transitionDuration: "var(--duration-base)",
|
|
84
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
85
|
+
}}
|
|
86
|
+
>
|
|
87
|
+
<p id={`${stepId}-prompt`} className="mb-4 text-base font-medium text-foreground">
|
|
88
|
+
{question.prompt}
|
|
89
|
+
</p>
|
|
90
|
+
|
|
91
|
+
{/* Single choice — radio group */}
|
|
92
|
+
{question.type === "single" && question.options && (
|
|
93
|
+
<RadioGroup
|
|
94
|
+
value={(answer as string) ?? ""}
|
|
95
|
+
onValueChange={(v) => onAnswerChange(v)}
|
|
96
|
+
className="space-y-2"
|
|
97
|
+
>
|
|
98
|
+
{question.options.map((opt) => (
|
|
99
|
+
<label
|
|
100
|
+
key={opt.value}
|
|
101
|
+
htmlFor={`${stepId}-${opt.value}`}
|
|
102
|
+
className={cn(
|
|
103
|
+
"flex cursor-pointer items-center gap-3 rounded-md border px-3 py-2.5 transition-colors",
|
|
104
|
+
(answer as string) === opt.value
|
|
105
|
+
? "border-ring bg-primary/5"
|
|
106
|
+
: "border-border hover:bg-accent/50"
|
|
107
|
+
)}
|
|
108
|
+
style={{
|
|
109
|
+
transitionDuration: "var(--duration-fast)",
|
|
110
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
111
|
+
}}
|
|
112
|
+
>
|
|
113
|
+
<RadioGroupItem value={opt.value} id={`${stepId}-${opt.value}`} />
|
|
114
|
+
<span className="text-sm font-medium leading-snug">{opt.label}</span>
|
|
115
|
+
</label>
|
|
116
|
+
))}
|
|
117
|
+
</RadioGroup>
|
|
118
|
+
)}
|
|
119
|
+
|
|
120
|
+
{/* Multiple choice — checkboxes */}
|
|
121
|
+
{question.type === "multiple" && question.options && (
|
|
122
|
+
<div className="space-y-2">
|
|
123
|
+
{question.options.map((opt) => {
|
|
124
|
+
const selected = Array.isArray(answer) && answer.includes(opt.value)
|
|
125
|
+
return (
|
|
126
|
+
<label
|
|
127
|
+
key={opt.value}
|
|
128
|
+
htmlFor={`${stepId}-${opt.value}`}
|
|
129
|
+
className={cn(
|
|
130
|
+
"flex cursor-pointer items-center gap-3 rounded-md border px-3 py-2.5 transition-colors",
|
|
131
|
+
selected ? "border-ring bg-primary/5" : "border-border hover:bg-accent/50"
|
|
132
|
+
)}
|
|
133
|
+
style={{
|
|
134
|
+
transitionDuration: "var(--duration-fast)",
|
|
135
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
136
|
+
}}
|
|
137
|
+
>
|
|
138
|
+
<Checkbox
|
|
139
|
+
id={`${stepId}-${opt.value}`}
|
|
140
|
+
checked={selected}
|
|
141
|
+
onCheckedChange={(checked) => {
|
|
142
|
+
const current = Array.isArray(answer) ? answer : []
|
|
143
|
+
const next = checked
|
|
144
|
+
? [...current, opt.value]
|
|
145
|
+
: current.filter((v) => v !== opt.value)
|
|
146
|
+
onAnswerChange(next.length > 0 ? next : null)
|
|
147
|
+
}}
|
|
148
|
+
/>
|
|
149
|
+
<span className="text-sm font-medium leading-snug">{opt.label}</span>
|
|
150
|
+
</label>
|
|
151
|
+
)
|
|
152
|
+
})}
|
|
153
|
+
</div>
|
|
154
|
+
)}
|
|
155
|
+
|
|
156
|
+
{/* Freeform — textarea; ⌘/Ctrl+Enter advances */}
|
|
157
|
+
{question.type === "freeform" && (
|
|
158
|
+
<Textarea
|
|
159
|
+
value={(answer as string) ?? ""}
|
|
160
|
+
onChange={(e) => onAnswerChange(e.target.value || null)}
|
|
161
|
+
onKeyDown={(e) => {
|
|
162
|
+
if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {
|
|
163
|
+
e.preventDefault()
|
|
164
|
+
onAdvance()
|
|
165
|
+
}
|
|
166
|
+
}}
|
|
167
|
+
placeholder="Your answer…"
|
|
168
|
+
rows={4}
|
|
169
|
+
className="resize-none"
|
|
170
|
+
/>
|
|
171
|
+
)}
|
|
172
|
+
</div>
|
|
173
|
+
)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// ─── Questionnaire ────────────────────────────────────────────────────────────
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Questionnaire — one-question-at-a-time form primitive.
|
|
180
|
+
*
|
|
181
|
+
* Designed for agentic clarification prompts, onboarding flows, intake forms,
|
|
182
|
+
* and configuration wizards. Supports single-choice (radio), multiple-choice
|
|
183
|
+
* (checkboxes), freeform (textarea), and skippable questions in any combination.
|
|
184
|
+
* Questions animate in from the travel direction on each step change.
|
|
185
|
+
*/
|
|
186
|
+
export function Questionnaire({
|
|
187
|
+
questions,
|
|
188
|
+
onComplete,
|
|
189
|
+
onSkip,
|
|
190
|
+
className,
|
|
191
|
+
}: QuestionnaireProps) {
|
|
192
|
+
const [step, setStep] = React.useState(0)
|
|
193
|
+
const [direction, setDirection] = React.useState<"forward" | "backward">("forward")
|
|
194
|
+
const [answers, setAnswers] = React.useState<QuestionnaireAnswers>({})
|
|
195
|
+
const [done, setDone] = React.useState(false)
|
|
196
|
+
|
|
197
|
+
if (questions.length === 0) return null
|
|
198
|
+
|
|
199
|
+
const question = questions[step]
|
|
200
|
+
const currentAnswer = answers[question.id] ?? null
|
|
201
|
+
|
|
202
|
+
const canAdvance =
|
|
203
|
+
question.type === "freeform"
|
|
204
|
+
? Boolean((currentAnswer as string)?.trim())
|
|
205
|
+
: question.type === "multiple"
|
|
206
|
+
? Array.isArray(currentAnswer) && currentAnswer.length > 0
|
|
207
|
+
: Boolean(currentAnswer)
|
|
208
|
+
|
|
209
|
+
const handleAnswerChange = (answer: string | string[] | null) => {
|
|
210
|
+
setAnswers((prev) => ({ ...prev, [question.id]: answer }))
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const advance = (skip = false) => {
|
|
214
|
+
const nextAnswers = skip ? { ...answers, [question.id]: null } : answers
|
|
215
|
+
if (skip) {
|
|
216
|
+
setAnswers(nextAnswers)
|
|
217
|
+
onSkip?.(question.id)
|
|
218
|
+
}
|
|
219
|
+
if (step < questions.length - 1) {
|
|
220
|
+
setDirection("forward")
|
|
221
|
+
setStep((s) => s + 1)
|
|
222
|
+
} else {
|
|
223
|
+
setDone(true)
|
|
224
|
+
onComplete?.(nextAnswers)
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const goBack = () => {
|
|
229
|
+
setDirection("backward")
|
|
230
|
+
setStep((s) => s - 1)
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (done) {
|
|
234
|
+
return (
|
|
235
|
+
<div
|
|
236
|
+
data-slot="questionnaire"
|
|
237
|
+
data-state="complete"
|
|
238
|
+
role="status"
|
|
239
|
+
aria-live="polite"
|
|
240
|
+
className={cn(
|
|
241
|
+
"flex flex-col items-center justify-center gap-2 py-10 text-center",
|
|
242
|
+
className
|
|
243
|
+
)}
|
|
244
|
+
>
|
|
245
|
+
<p className="text-base font-semibold text-foreground">All done!</p>
|
|
246
|
+
<p className="text-sm text-muted-foreground">Your answers have been recorded.</p>
|
|
247
|
+
</div>
|
|
248
|
+
)
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return (
|
|
252
|
+
<div data-slot="questionnaire" className={cn("flex flex-col gap-5", className)}>
|
|
253
|
+
{/* Progress bar */}
|
|
254
|
+
<div className="flex items-center gap-3">
|
|
255
|
+
<div
|
|
256
|
+
className="h-1 flex-1 overflow-hidden rounded-full bg-muted"
|
|
257
|
+
role="progressbar"
|
|
258
|
+
aria-valuenow={step}
|
|
259
|
+
aria-valuemin={0}
|
|
260
|
+
aria-valuemax={questions.length}
|
|
261
|
+
aria-label="Question progress"
|
|
262
|
+
>
|
|
263
|
+
<div
|
|
264
|
+
className="h-full rounded-full bg-primary"
|
|
265
|
+
style={{
|
|
266
|
+
width: `${(step / questions.length) * 100}%`,
|
|
267
|
+
transitionProperty: "width",
|
|
268
|
+
transitionDuration: "var(--duration-base)",
|
|
269
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
270
|
+
}}
|
|
271
|
+
/>
|
|
272
|
+
</div>
|
|
273
|
+
<span
|
|
274
|
+
className="shrink-0 text-xs tabular-nums text-muted-foreground"
|
|
275
|
+
aria-hidden="true"
|
|
276
|
+
>
|
|
277
|
+
{step + 1} / {questions.length}
|
|
278
|
+
</span>
|
|
279
|
+
</div>
|
|
280
|
+
|
|
281
|
+
{/* Question — keyed so the mount animation fires on every step change */}
|
|
282
|
+
<QuestionStep
|
|
283
|
+
key={`q-${step}`}
|
|
284
|
+
question={question}
|
|
285
|
+
answer={currentAnswer}
|
|
286
|
+
direction={direction}
|
|
287
|
+
onAnswerChange={handleAnswerChange}
|
|
288
|
+
onAdvance={() => canAdvance && advance(false)}
|
|
289
|
+
/>
|
|
290
|
+
|
|
291
|
+
{/* Navigation */}
|
|
292
|
+
<div className="flex items-center gap-2 pt-1">
|
|
293
|
+
{step > 0 ? (
|
|
294
|
+
<Button
|
|
295
|
+
variant="ghost"
|
|
296
|
+
size="xl"
|
|
297
|
+
onClick={goBack}
|
|
298
|
+
aria-label="Previous question"
|
|
299
|
+
>
|
|
300
|
+
<ChevronLeftIcon className="size-4" strokeWidth={1.5} />
|
|
301
|
+
Back
|
|
302
|
+
</Button>
|
|
303
|
+
) : (
|
|
304
|
+
<div />
|
|
305
|
+
)}
|
|
306
|
+
<div className="flex-1" />
|
|
307
|
+
{question.skippable && (
|
|
308
|
+
<Button
|
|
309
|
+
variant="ghost"
|
|
310
|
+
size="xl"
|
|
311
|
+
onClick={() => advance(true)}
|
|
312
|
+
>
|
|
313
|
+
{question.skipLabel ?? "Skip"}
|
|
314
|
+
<ChevronsRightIcon className="size-4" strokeWidth={1.5} />
|
|
315
|
+
</Button>
|
|
316
|
+
)}
|
|
317
|
+
<Button
|
|
318
|
+
size="xl"
|
|
319
|
+
disabled={!canAdvance}
|
|
320
|
+
onClick={() => advance(false)}
|
|
321
|
+
>
|
|
322
|
+
{step < questions.length - 1 ? (
|
|
323
|
+
<>
|
|
324
|
+
Next
|
|
325
|
+
<ChevronRightIcon className="size-4" strokeWidth={1.5} />
|
|
326
|
+
</>
|
|
327
|
+
) : (
|
|
328
|
+
"Finish"
|
|
329
|
+
)}
|
|
330
|
+
</Button>
|
|
331
|
+
</div>
|
|
332
|
+
</div>
|
|
333
|
+
)
|
|
334
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
3
|
+
import { CheckCircle2, XCircle, AlertTriangle, Info } from "lucide-react"
|
|
4
|
+
|
|
5
|
+
import { cn } from "../../lib/utils"
|
|
6
|
+
|
|
7
|
+
// Result — feedback primitive for the outcome of a concluded operation
|
|
8
|
+
// (form submitted, payment confirmed, sync failed, onboarding complete).
|
|
9
|
+
// Distinct from EmptyState (no data yet — nothing happened) and from
|
|
10
|
+
// Sonner/Notification (transient or list-bound feedback): Result owns the
|
|
11
|
+
// surface after the operation ends.
|
|
12
|
+
//
|
|
13
|
+
// Status colors use the `text-[var(--success)]` arbitrary form — the
|
|
14
|
+
// Sonner / Meter / CircularProgress-proven pattern. The theme tokens are raw
|
|
15
|
+
// oklch values, so wrapping them in `hsl(var(--success))` produces invalid
|
|
16
|
+
// CSS that fails silently. `error` maps to the audited `text-destructive`
|
|
17
|
+
// utility. Zero new tokens.
|
|
18
|
+
//
|
|
19
|
+
// Motion (spec §4 pattern c): the icon wrapper enters via tw-animate-css
|
|
20
|
+
// `animate-in fade-in zoom-in-50` with token-driven timing supplied inline
|
|
21
|
+
// (`animationDuration: var(--duration-base)`, `animationTimingFunction:
|
|
22
|
+
// var(--ease-spring)`). No `duration-*` token utility classes — Tailwind v4
|
|
23
|
+
// has no `--duration-*` namespace and those classes compile to nothing.
|
|
24
|
+
// Reduced-motion is handled by the base layer (0.01ms override).
|
|
25
|
+
|
|
26
|
+
const resultVariants = cva("flex flex-col items-center text-center", {
|
|
27
|
+
variants: {
|
|
28
|
+
size: {
|
|
29
|
+
default: "gap-4 px-8 py-12",
|
|
30
|
+
sm: "gap-3 px-6 py-8",
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
defaultVariants: {
|
|
34
|
+
size: "default",
|
|
35
|
+
},
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
const resultIconVariants = cva(
|
|
39
|
+
"animate-in fade-in zoom-in-50 [&>svg]:shrink-0",
|
|
40
|
+
{
|
|
41
|
+
variants: {
|
|
42
|
+
status: {
|
|
43
|
+
success: "text-[var(--success)]",
|
|
44
|
+
error: "text-destructive",
|
|
45
|
+
warning: "text-[var(--warning)]",
|
|
46
|
+
info: "text-[var(--info)]",
|
|
47
|
+
},
|
|
48
|
+
size: {
|
|
49
|
+
default: "[&>svg]:size-12",
|
|
50
|
+
sm: "[&>svg]:size-10",
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
defaultVariants: {
|
|
54
|
+
size: "default",
|
|
55
|
+
},
|
|
56
|
+
}
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
const DEFAULT_STATUS_ICONS: Record<
|
|
60
|
+
NonNullable<ResultProps["status"]>,
|
|
61
|
+
React.ComponentType<React.SVGProps<SVGSVGElement> & { strokeWidth?: number }>
|
|
62
|
+
> = {
|
|
63
|
+
success: CheckCircle2,
|
|
64
|
+
error: XCircle,
|
|
65
|
+
warning: AlertTriangle,
|
|
66
|
+
info: Info,
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface ResultProps
|
|
70
|
+
extends React.ComponentPropsWithoutRef<"div">,
|
|
71
|
+
VariantProps<typeof resultVariants> {
|
|
72
|
+
/** Semantic outcome — controls the default icon and its color. */
|
|
73
|
+
status: "success" | "error" | "warning" | "info"
|
|
74
|
+
/** Primary outcome statement. */
|
|
75
|
+
title: string
|
|
76
|
+
/** Supporting detail rendered below the title. */
|
|
77
|
+
subtitle?: string
|
|
78
|
+
/**
|
|
79
|
+
* Custom icon or illustration — replaces the default status icon when
|
|
80
|
+
* provided. The wrapper still carries the status color, so a custom SVG
|
|
81
|
+
* using `currentColor` inherits it.
|
|
82
|
+
*/
|
|
83
|
+
icon?: React.ReactNode
|
|
84
|
+
/** Action row below title + subtitle — Buttons, links, extra detail. */
|
|
85
|
+
extra?: React.ReactNode
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function Result({
|
|
89
|
+
className,
|
|
90
|
+
status,
|
|
91
|
+
size,
|
|
92
|
+
title,
|
|
93
|
+
subtitle,
|
|
94
|
+
icon,
|
|
95
|
+
extra,
|
|
96
|
+
...props
|
|
97
|
+
}: ResultProps) {
|
|
98
|
+
const DefaultIcon = DEFAULT_STATUS_ICONS[status]
|
|
99
|
+
return (
|
|
100
|
+
<div
|
|
101
|
+
data-slot="result"
|
|
102
|
+
data-status={status}
|
|
103
|
+
// Outcome surfaces announce politely; errors announce assertively.
|
|
104
|
+
// Overridable — the spread below wins. Note: live regions only fire
|
|
105
|
+
// reliably when the Result is injected into an already-rendered
|
|
106
|
+
// container; a fresh-route render should not rely on the announcement.
|
|
107
|
+
role={status === "error" ? "alert" : "status"}
|
|
108
|
+
className={cn(resultVariants({ size }), className)}
|
|
109
|
+
{...props}
|
|
110
|
+
>
|
|
111
|
+
<div
|
|
112
|
+
data-slot="result-icon"
|
|
113
|
+
aria-hidden="true"
|
|
114
|
+
className={resultIconVariants({ status, size })}
|
|
115
|
+
style={{
|
|
116
|
+
animationDuration: "var(--duration-base)",
|
|
117
|
+
animationTimingFunction: "var(--ease-spring)",
|
|
118
|
+
}}
|
|
119
|
+
>
|
|
120
|
+
{icon ?? <DefaultIcon strokeWidth={1.5} />}
|
|
121
|
+
</div>
|
|
122
|
+
<div
|
|
123
|
+
data-slot="result-title"
|
|
124
|
+
className={cn(
|
|
125
|
+
"font-semibold tracking-tight text-foreground",
|
|
126
|
+
size === "sm" ? "text-lg" : "text-2xl"
|
|
127
|
+
)}
|
|
128
|
+
>
|
|
129
|
+
{title}
|
|
130
|
+
</div>
|
|
131
|
+
{subtitle && (
|
|
132
|
+
<p
|
|
133
|
+
data-slot="result-subtitle"
|
|
134
|
+
className="max-w-md text-sm leading-relaxed text-muted-foreground"
|
|
135
|
+
>
|
|
136
|
+
{subtitle}
|
|
137
|
+
</p>
|
|
138
|
+
)}
|
|
139
|
+
{extra && (
|
|
140
|
+
<div
|
|
141
|
+
data-slot="result-extra"
|
|
142
|
+
className="flex flex-wrap items-center justify-center gap-2 pt-2"
|
|
143
|
+
>
|
|
144
|
+
{extra}
|
|
145
|
+
</div>
|
|
146
|
+
)}
|
|
147
|
+
</div>
|
|
148
|
+
)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export { Result, resultVariants }
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// Sidebar builds a React context (createContext) and drives open/collapsed
|
|
4
|
+
// state through useState/useEffect, none of which exist in a server component.
|
|
5
|
+
// See the note in button.tsx for the boundary rule this follows.
|
|
1
6
|
import * as React from "react";
|
|
2
7
|
import * as SlotPrimitive from "@radix-ui/react-slot";
|
|
3
8
|
import { VariantProps, cva } from "class-variance-authority";
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { cn } from "../../lib/utils";
|
|
5
|
+
|
|
6
|
+
// ─── SimpleGrid ────────────────────────────────────────────────────────────────
|
|
7
|
+
//
|
|
8
|
+
// Responsive equal-column CSS grid. Replaces boilerplate
|
|
9
|
+
// `<div className="grid gap-6 sm:grid-cols-2 lg:grid-cols-3">` with a
|
|
10
|
+
// statically-safe API: every column count maps to a literal Tailwind class
|
|
11
|
+
// from the lookup tables below, so the classes always survive the Tailwind v4
|
|
12
|
+
// scanner (a template-string `grid-cols-${n}` silently compiles to nothing).
|
|
13
|
+
//
|
|
14
|
+
// For variable-height content that should pack (Pinterest-style), use Masonry.
|
|
15
|
+
// For tabular data, use Table/DataTable. SimpleGrid is for equal-width cells
|
|
16
|
+
// in row-aligned tracks: card grids, stat rows, settings tiles, galleries.
|
|
17
|
+
//
|
|
18
|
+
// Layout-only primitive (same class as Stack/Group/Container): no ARIA, no
|
|
19
|
+
// interaction, no motion. Cross-system references: Mantine SimpleGrid,
|
|
20
|
+
// Chakra SimpleGrid; MUI Grid.
|
|
21
|
+
|
|
22
|
+
type Cols = 1 | 2 | 3 | 4 | 5 | 6;
|
|
23
|
+
|
|
24
|
+
/** Column counts per breakpoint. `base` applies from 0px up; sm/md/lg override upward. */
|
|
25
|
+
export interface ResponsiveCols {
|
|
26
|
+
base?: Cols;
|
|
27
|
+
sm?: Cols;
|
|
28
|
+
md?: Cols;
|
|
29
|
+
lg?: Cols;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Literal class maps — every generated class must be spelled out so the
|
|
33
|
+
// Tailwind scanner ships it. Never build these strings dynamically.
|
|
34
|
+
const BASE_COLS: Record<Cols, string> = {
|
|
35
|
+
1: "grid-cols-1",
|
|
36
|
+
2: "grid-cols-2",
|
|
37
|
+
3: "grid-cols-3",
|
|
38
|
+
4: "grid-cols-4",
|
|
39
|
+
5: "grid-cols-5",
|
|
40
|
+
6: "grid-cols-6",
|
|
41
|
+
};
|
|
42
|
+
const SM_COLS: Record<Cols, string> = {
|
|
43
|
+
1: "sm:grid-cols-1",
|
|
44
|
+
2: "sm:grid-cols-2",
|
|
45
|
+
3: "sm:grid-cols-3",
|
|
46
|
+
4: "sm:grid-cols-4",
|
|
47
|
+
5: "sm:grid-cols-5",
|
|
48
|
+
6: "sm:grid-cols-6",
|
|
49
|
+
};
|
|
50
|
+
const MD_COLS: Record<Cols, string> = {
|
|
51
|
+
1: "md:grid-cols-1",
|
|
52
|
+
2: "md:grid-cols-2",
|
|
53
|
+
3: "md:grid-cols-3",
|
|
54
|
+
4: "md:grid-cols-4",
|
|
55
|
+
5: "md:grid-cols-5",
|
|
56
|
+
6: "md:grid-cols-6",
|
|
57
|
+
};
|
|
58
|
+
const LG_COLS: Record<Cols, string> = {
|
|
59
|
+
1: "lg:grid-cols-1",
|
|
60
|
+
2: "lg:grid-cols-2",
|
|
61
|
+
3: "lg:grid-cols-3",
|
|
62
|
+
4: "lg:grid-cols-4",
|
|
63
|
+
5: "lg:grid-cols-5",
|
|
64
|
+
6: "lg:grid-cols-6",
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/** Same token-keyed gap scale as Stack/Group (gap-0/1/2/4/6/8 → 0/4/8/16/24/32px). */
|
|
68
|
+
const GAP: Record<"none" | "xs" | "sm" | "md" | "lg" | "xl", string> = {
|
|
69
|
+
none: "gap-0",
|
|
70
|
+
xs: "gap-1",
|
|
71
|
+
sm: "gap-2",
|
|
72
|
+
md: "gap-4",
|
|
73
|
+
lg: "gap-6",
|
|
74
|
+
xl: "gap-8",
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export interface SimpleGridProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
78
|
+
/**
|
|
79
|
+
* Column count — a single number (fixed at all widths) or a responsive
|
|
80
|
+
* object, e.g. `{ base: 1, sm: 2, lg: 3 }`. Values clamp to 1–6.
|
|
81
|
+
* Default: `{ base: 1, sm: 2, lg: 3 }` — the standard card-grid shape.
|
|
82
|
+
*/
|
|
83
|
+
cols?: Cols | ResponsiveCols;
|
|
84
|
+
/** Gap between cells, keyed to the BADS spacing scale. Default: "lg" (24px) — the canonical card-grid gap. */
|
|
85
|
+
gap?: keyof typeof GAP;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function colsClasses(cols: Cols | ResponsiveCols): string[] {
|
|
89
|
+
if (typeof cols === "number") return [BASE_COLS[cols]];
|
|
90
|
+
const out: string[] = [BASE_COLS[cols.base ?? 1]];
|
|
91
|
+
if (cols.sm) out.push(SM_COLS[cols.sm]);
|
|
92
|
+
if (cols.md) out.push(MD_COLS[cols.md]);
|
|
93
|
+
if (cols.lg) out.push(LG_COLS[cols.lg]);
|
|
94
|
+
return out;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export const SimpleGrid = React.forwardRef<HTMLDivElement, SimpleGridProps>(
|
|
98
|
+
(
|
|
99
|
+
{ className, cols = { base: 1, sm: 2, lg: 3 }, gap = "lg", ...props },
|
|
100
|
+
ref
|
|
101
|
+
) => (
|
|
102
|
+
<div
|
|
103
|
+
ref={ref}
|
|
104
|
+
data-slot="simple-grid"
|
|
105
|
+
className={cn("grid", ...colsClasses(cols), GAP[gap], className)}
|
|
106
|
+
{...props}
|
|
107
|
+
/>
|
|
108
|
+
)
|
|
109
|
+
);
|
|
110
|
+
SimpleGrid.displayName = "SimpleGrid";
|