@behavioral-agentic-design-system/core 0.29.0 → 0.32.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.
Files changed (42) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +2 -1
  3. package/scripts/build-tokens.cjs +59 -10
  4. package/scripts/wcag-audit.cjs +30 -4
  5. package/src/app/preview/components/page.tsx +305 -1
  6. package/src/app/preview/health/page.tsx +201 -0
  7. package/src/app/shell.tsx +40 -4
  8. package/src/components/docs-tab.tsx +26 -9
  9. package/src/components/home-tab.tsx +12 -3
  10. package/src/components/ui/badge.tsx +16 -2
  11. package/src/components/ui/button.tsx +10 -0
  12. package/src/components/ui/checkbox.tsx +21 -6
  13. package/src/components/ui/index.ts +1 -0
  14. package/src/components/ui/input-clear-button.tsx +52 -0
  15. package/src/components/ui/input.tsx +5 -21
  16. package/src/components/ui/multi-select.tsx +20 -6
  17. package/src/components/ui/progress.tsx +23 -1
  18. package/src/components/ui/questionnaire.tsx +352 -0
  19. package/src/components/ui/sidebar.tsx +5 -0
  20. package/src/components/ui/skeleton.tsx +83 -1
  21. package/src/components/ui/tabs.tsx +34 -0
  22. package/src/components/ui/textarea.tsx +5 -0
  23. package/src/components/ui/toggle-tip.tsx +125 -0
  24. package/src/data/docs-index.ts +51 -3
  25. package/src/fonts-cdn.css +25 -0
  26. package/src/lib/fork.ts +21 -0
  27. package/src/lib/get-icon-color.ts +66 -0
  28. package/src/stories/Badge.stories.tsx +66 -0
  29. package/src/stories/Button.stories.tsx +3 -0
  30. package/src/stories/Checkbox.stories.tsx +58 -4
  31. package/src/stories/Input.stories.tsx +3 -0
  32. package/src/stories/InputClearButton.stories.tsx +53 -0
  33. package/src/stories/MultiSelect.stories.tsx +6 -2
  34. package/src/stories/Progress.stories.tsx +56 -4
  35. package/src/stories/Questionnaire.stories.tsx +287 -0
  36. package/src/stories/Sidebar.stories.tsx +2 -0
  37. package/src/stories/SkeletonTable.stories.tsx +97 -0
  38. package/src/stories/Stack.stories.tsx +2 -1
  39. package/src/stories/Tabs.stories.tsx +56 -8
  40. package/src/stories/Textarea.stories.tsx +2 -0
  41. package/src/stories/ToggleTip.stories.tsx +106 -0
  42. package/src/styles.css +22 -10
@@ -31,6 +31,15 @@ type ProgressProps = React.ComponentProps<typeof ProgressPrimitive.Root> & {
31
31
  * className still wins for one-off values.
32
32
  */
33
33
  size?: "sm" | "default" | "lg"
34
+ /**
35
+ * Semantic color intent for the indicator fill (peer parity: Mantine
36
+ * Progress `color`, MUI LinearProgress `color`, Chakra `colorScheme`,
37
+ * Ant Design Progress `status`). Changes only the filled portion — the
38
+ * track stays primary-tinted so the empty rail is always neutral.
39
+ * Intent is purely visual: never use it as the sole signal of status;
40
+ * pair with a label or aria-label that names the state.
41
+ */
42
+ intent?: "default" | "success" | "warning" | "error" | "info"
34
43
  }
35
44
 
36
45
  // Mirrors Radix Progress's built-in getValueLabel default so the visible
@@ -39,6 +48,14 @@ function defaultGetValueLabel(value: number, max: number) {
39
48
  return `${Math.round((value / max) * 100)}%`
40
49
  }
41
50
 
51
+ const intentIndicatorClass = {
52
+ default: "bg-primary",
53
+ success: "bg-success",
54
+ warning: "bg-warning",
55
+ error: "bg-destructive",
56
+ info: "bg-info",
57
+ } as const
58
+
42
59
  function Progress({
43
60
  className,
44
61
  value,
@@ -47,6 +64,7 @@ function Progress({
47
64
  label,
48
65
  showValue,
49
66
  size = "default",
67
+ intent = "default",
50
68
  ...props
51
69
  }: ProgressProps) {
52
70
  const labelId = React.useId()
@@ -100,7 +118,11 @@ function Progress({
100
118
  >
101
119
  <ProgressPrimitive.Indicator
102
120
  data-slot="progress-indicator"
103
- className="h-full w-full flex-1 bg-primary transition-transform"
121
+ data-intent={intent}
122
+ className={cn(
123
+ "h-full w-full flex-1 transition-transform",
124
+ intentIndicatorClass[intent]
125
+ )}
104
126
  style={{ transform: `translateX(-${100 - fillPercent}%)` }}
105
127
  />
106
128
  </ProgressPrimitive.Root>
@@ -0,0 +1,352 @@
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
+ *
293
+ * Two groups with justify-between, and flex-wrap, rather than one row
294
+ * with a flex-1 spacer. On the final step of a skippable question all
295
+ * three controls are present at once (Back + the skip label + Finish),
296
+ * and a skip label is author-supplied prose — "No context needed" in the
297
+ * showcase. Flex children default to min-width:auto, so none of the
298
+ * three would shrink; without wrapping the row simply overflowed its
299
+ * card and Finish rendered outside the border.
300
+ *
301
+ * Not solved with min-w-0 + truncate: these are the CTA labels, and a
302
+ * clipped "No context need…" is worse than a second line. Not solved by
303
+ * shortening the label either — the component cannot bound what a
304
+ * consumer passes. Wrapping is the only fix that holds for any label
305
+ * length, which is what CLAUDE.md's long-label contract asks for.
306
+ */}
307
+ <div className="flex flex-wrap items-center justify-between gap-2 pt-1">
308
+ <div className="flex min-w-0 items-center gap-2">
309
+ {step > 0 && (
310
+ <Button
311
+ variant="ghost"
312
+ size="default"
313
+ className="min-h-11"
314
+ onClick={goBack}
315
+ aria-label="Previous question"
316
+ >
317
+ <ChevronLeftIcon className="size-4" strokeWidth={1.5} />
318
+ Back
319
+ </Button>
320
+ )}
321
+ </div>
322
+ <div className="flex min-w-0 flex-wrap items-center justify-end gap-2">
323
+ {question.skippable && (
324
+ <Button
325
+ variant="ghost"
326
+ size="default"
327
+ className="min-h-11"
328
+ onClick={() => advance(true)}
329
+ >
330
+ {question.skipLabel ?? "Skip"}
331
+ <ChevronsRightIcon className="size-4" strokeWidth={1.5} />
332
+ </Button>
333
+ )}
334
+ <Button
335
+ size="xl"
336
+ disabled={!canAdvance}
337
+ onClick={() => advance(false)}
338
+ >
339
+ {step < questions.length - 1 ? (
340
+ <>
341
+ Next
342
+ <ChevronRightIcon className="size-4" strokeWidth={1.5} />
343
+ </>
344
+ ) : (
345
+ "Finish"
346
+ )}
347
+ </Button>
348
+ </div>
349
+ </div>
350
+ </div>
351
+ )
352
+ }
@@ -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";
@@ -116,4 +116,86 @@ function SkeletonRegion({
116
116
  )
117
117
  }
118
118
 
119
- export { Skeleton, SkeletonRegion }
119
+ // Pre-seeded width pattern so cells look organic across rows and columns.
120
+ const CELL_WIDTHS = ["75%", "90%", "60%", "80%", "70%", "85%", "65%", "95%"]
121
+
122
+ type SkeletonTableProps = React.ComponentProps<"div"> & {
123
+ /**
124
+ * Number of data rows (not counting the header). Default 5.
125
+ */
126
+ rows?: number
127
+ /**
128
+ * Number of columns. Default 4.
129
+ */
130
+ columns?: number
131
+ /**
132
+ * Render a header row above the data rows. Default true.
133
+ */
134
+ showHeader?: boolean
135
+ /** Loading motion — same contract as Skeleton. */
136
+ animation?: "pulse" | "wave" | false
137
+ }
138
+
139
+ function SkeletonTable({
140
+ className,
141
+ rows = 5,
142
+ columns = 4,
143
+ showHeader = true,
144
+ animation = "pulse",
145
+ ...props
146
+ }: SkeletonTableProps) {
147
+ const rowCount = Math.max(1, Math.floor(rows))
148
+ const colCount = Math.max(1, Math.floor(columns))
149
+ const dataAnimation =
150
+ animation === "pulse" ? undefined : animation === false ? "none" : "wave"
151
+ const baseClass =
152
+ animation === "pulse" ? "animate-pulse rounded-md bg-accent" : "rounded-md bg-accent"
153
+
154
+ return (
155
+ <div
156
+ data-slot="skeleton-table"
157
+ role="status"
158
+ aria-label="Loading table data"
159
+ className={cn("w-full overflow-x-auto", className)}
160
+ {...props}
161
+ >
162
+ <span className="sr-only">Loading…</span>
163
+ <div className="min-w-full" aria-hidden>
164
+ {showHeader && (
165
+ <div className="flex gap-3 border-b border-border pb-3 mb-3">
166
+ {Array.from({ length: colCount }, (_, i) => (
167
+ <div key={i} className="min-w-0 flex-1">
168
+ <div
169
+ data-slot="skeleton-line"
170
+ data-animation={dataAnimation}
171
+ className={cn(baseClass, "h-4")}
172
+ style={{ width: CELL_WIDTHS[i % CELL_WIDTHS.length] }}
173
+ />
174
+ </div>
175
+ ))}
176
+ </div>
177
+ )}
178
+ <div className="flex flex-col divide-y divide-border">
179
+ {Array.from({ length: rowCount }, (_, r) => (
180
+ <div key={r} className="flex gap-3 py-2.5">
181
+ {Array.from({ length: colCount }, (_, c) => (
182
+ <div key={c} className="min-w-0 flex-1">
183
+ <div
184
+ data-slot="skeleton-line"
185
+ data-animation={dataAnimation}
186
+ className={cn(baseClass, "h-4")}
187
+ style={{
188
+ width: CELL_WIDTHS[(r * colCount + c) % CELL_WIDTHS.length],
189
+ }}
190
+ />
191
+ </div>
192
+ ))}
193
+ </div>
194
+ ))}
195
+ </div>
196
+ </div>
197
+ </div>
198
+ )
199
+ }
200
+
201
+ export { Skeleton, SkeletonRegion, SkeletonTable }
@@ -191,6 +191,21 @@ function TabsContent({
191
191
  * unreliable across browsers; absolute-fill of an explicit-size relative
192
192
  * ancestor is the bulletproof pattern.
193
193
  *
194
+ * Scrolling requirement:
195
+ * When a panel's content overflows, put the overflow on the TabsContent
196
+ * ITSELF (`className="size-full overflow-y-auto"`) — never on a child div
197
+ * inside it. Radix gives TabsContent `role="tabpanel"`, `tabindex="0"`, and
198
+ * an accessible name from its trigger, so a scrollable TabsContent is
199
+ * keyboard-reachable and announced for free. A nested `overflow-y-auto` div
200
+ * is none of those things: it becomes a scrollable region no keyboard user
201
+ * can reach, which axe fails as `scrollable-region-focusable` (serious) —
202
+ * the exact violation that took `main` red on 2026-08-25. It also puts the
203
+ * scroll container one level BELOW the element this component z-orders,
204
+ * re-opening the Safari async-scrolling hit-test problem the z-10/z-0 rules
205
+ * above exist to close. One element that both stacks and scrolls is the
206
+ * whole fix; two nested ones reintroduce both bugs. `RealisticUse` in
207
+ * Tabs.stories.tsx is the worked example, and its a11y test is the guard.
208
+ *
194
209
  * Behavior:
195
210
  * - Inactive panels: opacity 0, pointer-events: none.
196
211
  * - Active panel: opacity 1, full pointer events.
@@ -224,6 +239,25 @@ function TabsPanels({
224
239
  "[&>[data-slot=tabs-content][data-state=inactive]]:opacity-0",
225
240
  "[&>[data-slot=tabs-content][data-state=inactive]]:pointer-events-none",
226
241
  "[&>[data-slot=tabs-content][data-state=active]]:opacity-100",
242
+ // Explicit stacking: the active panel paints ON TOP of the inactive
243
+ // ones. Without this the panels stack in DOM order, so any tab that
244
+ // isn't last sits UNDER its later siblings.
245
+ //
246
+ // In every other engine that's invisible (the siblings are opacity-0 +
247
+ // pointer-events-none). Safari/WebKit resolves wheel scrolling in its
248
+ // async scrolling tree, which hit-tests overlapping scroll containers
249
+ // WITHOUT honouring `pointer-events: none` — so a transparent sibling
250
+ // stacked above the active panel silently swallows the gesture and the
251
+ // tab "won't scroll" (mouse wheel and trackpad; keyboard and
252
+ // programmatic scrollTop still work, which is what makes it look like a
253
+ // rendering bug rather than a stacking one). Ordering the active panel
254
+ // on top removes the overlay from the scrolling hit-test entirely.
255
+ //
256
+ // z-10/z-0 (not z-index on the container) keeps this local: TabsPanels
257
+ // consumers wrap it in an `isolate` ancestor, so the stacking context
258
+ // never leaks past the panel area.
259
+ "[&>[data-slot=tabs-content][data-state=inactive]]:z-0",
260
+ "[&>[data-slot=tabs-content][data-state=active]]:z-10",
227
261
  className
228
262
  )}
229
263
  {...props}
@@ -1,3 +1,8 @@
1
+ "use client"
2
+
3
+ // Textarea holds the character-count in React.useState, so it cannot render in
4
+ // a server component at all. See the note in button.tsx for why the components
5
+ // that merely forward an optional callback are left server-renderable.
1
6
  import * as React from "react"
2
7
 
3
8
  import { cn } from "../../lib/utils"
@@ -0,0 +1,125 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import * as PopoverPrimitive from "@radix-ui/react-popover"
5
+
6
+ import { cn } from "../../lib/utils"
7
+ import { usePortalThemeClass } from "../../hooks/use-portal-theme-class"
8
+
9
+ interface ToggleTipProps {
10
+ /** The tip body. Informational, non-interactive by default. */
11
+ content: React.ReactNode
12
+ /**
13
+ * The trigger element — rendered via Radix `asChild`, so the consumer
14
+ * supplies the actual interactive element (usually an icon Button).
15
+ */
16
+ children: React.ReactNode
17
+ /** Preferred side for the tip. Matches Tooltip's default register. */
18
+ side?: "top" | "bottom" | "left" | "right"
19
+ /**
20
+ * Prevents the tip from opening. Gated on the wrapper's controlled open
21
+ * state (not just the trigger's native `disabled`) so it holds even when
22
+ * the asChild child is not a native button.
23
+ */
24
+ disabled?: boolean
25
+ /** Merged onto the content surface. */
26
+ className?: string
27
+ }
28
+
29
+ /**
30
+ * ToggleTip — a click-triggered, toggleable information overlay.
31
+ *
32
+ * Unlike Tooltip (hover/focus only — unreachable on touch devices and for
33
+ * users who can't hover), ToggleTip opens on click / tap / Enter / Space and
34
+ * toggles closed the same way. Canonical placement: an "info" icon button
35
+ * next to a form label. Ships an arrow like Tooltip but rides the normal
36
+ * Popover token surface (bg-popover), so normal semantic tokens are safe
37
+ * inside — it is NOT the inverted Tooltip surface.
38
+ *
39
+ * Cross-library primitive: Ark UI ToggleTip + Base UI both ship this shape.
40
+ */
41
+ function ToggleTip({
42
+ content,
43
+ children,
44
+ side = "top",
45
+ disabled = false,
46
+ className,
47
+ }: ToggleTipProps) {
48
+ const [open, setOpen] = React.useState(false)
49
+ // See use-portal-theme-class.ts: lets a PortalThemeProvider scope class
50
+ // (e.g. "atrium-theme") apply to portal content so theme-scoped CSS
51
+ // variables resolve inside the portal.
52
+ const portalThemeClass = usePortalThemeClass()
53
+
54
+ return (
55
+ <PopoverPrimitive.Root
56
+ data-slot="toggle-tip"
57
+ open={disabled ? false : open}
58
+ onOpenChange={(next) => {
59
+ if (!disabled) setOpen(next)
60
+ }}
61
+ >
62
+ <PopoverPrimitive.Trigger
63
+ data-slot="toggle-tip-trigger"
64
+ asChild
65
+ disabled={disabled}
66
+ >
67
+ {children}
68
+ </PopoverPrimitive.Trigger>
69
+ <PopoverPrimitive.Portal>
70
+ <PopoverPrimitive.Content
71
+ data-slot="toggle-tip-content"
72
+ side={side}
73
+ sideOffset={4}
74
+ className={cn(
75
+ "group z-50 w-fit max-w-72 origin-(--radix-popover-content-transform-origin) rounded-md border bg-popover px-3 py-1.5 text-sm text-balance text-popover-foreground shadow-md outline-hidden transition-colors data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
76
+ portalThemeClass,
77
+ className
78
+ )}
79
+ style={{
80
+ transitionDuration: "var(--duration-fast)",
81
+ transitionTimingFunction: "var(--ease-out)",
82
+ }}
83
+ >
84
+ {content}
85
+ {/* The arrow is a rotated square, not Radix's filled polygon — the
86
+ * shadcn Tooltip pattern. Tooltip can leave it borderless because
87
+ * its surface is a solid inverted fill with no border; ToggleTip
88
+ * rides the bordered, shadowed popover surface, so an unbordered
89
+ * arrow reads as a detached white triangle hanging off the panel.
90
+ *
91
+ * A 45°-rotated square points at a corner, and only the TWO edges
92
+ * meeting at that corner are outside the panel — the other two are
93
+ * tucked under it, where a border would draw a line across the
94
+ * panel's own edge. So the borders are applied per side, keyed off
95
+ * the data-side Radix sets on the content (hence `group` above):
96
+ *
97
+ * side=top arrow points down → bottom + right edges
98
+ * side=bottom arrow points up → top + left edges
99
+ * side=left arrow points right → top + right edges
100
+ * side=right arrow points left → bottom + left edges
101
+ *
102
+ * shadow-md matches the panel so the elevation continues around the
103
+ * arrow instead of stopping at the panel edge. -translate 2px past
104
+ * half keeps the panel's own border from cutting across the base.
105
+ */}
106
+ <PopoverPrimitive.Arrow asChild>
107
+ <div
108
+ data-slot="toggle-tip-arrow"
109
+ className={cn(
110
+ "z-50 size-2.5 rotate-45 rounded-[2px] border border-border bg-popover shadow-md",
111
+ "group-data-[side=top]:translate-y-[calc(-50%_-_2px)] group-data-[side=top]:border-t-0 group-data-[side=top]:border-l-0",
112
+ "group-data-[side=bottom]:translate-y-[calc(50%_+_2px)] group-data-[side=bottom]:border-b-0 group-data-[side=bottom]:border-r-0",
113
+ "group-data-[side=left]:translate-x-[calc(-50%_-_2px)] group-data-[side=left]:border-b-0 group-data-[side=left]:border-l-0",
114
+ "group-data-[side=right]:translate-x-[calc(50%_+_2px)] group-data-[side=right]:border-t-0 group-data-[side=right]:border-r-0"
115
+ )}
116
+ />
117
+ </PopoverPrimitive.Arrow>
118
+ </PopoverPrimitive.Content>
119
+ </PopoverPrimitive.Portal>
120
+ </PopoverPrimitive.Root>
121
+ )
122
+ }
123
+
124
+ export { ToggleTip }
125
+ export default ToggleTip