@behavioral-agentic-design-system/core 0.39.1 → 0.42.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 (115) hide show
  1. package/README.md +2 -0
  2. package/package.json +26 -5
  3. package/scripts/a11y-lint.cjs +88 -8
  4. package/scripts/bads-components.mjs +118 -0
  5. package/scripts/build-tokens.cjs +133 -12
  6. package/scripts/check-stories.mjs +1 -1
  7. package/scripts/health-report.mjs +16 -2
  8. package/scripts/lint-component-source.mjs +100 -0
  9. package/scripts/lint-microanimation.mjs +267 -0
  10. package/scripts/lint-slop.mjs +25 -1
  11. package/scripts/size-audit.cjs +79 -0
  12. package/scripts/source-of-truth.cjs +58 -0
  13. package/scripts/ux-smoke.mjs +438 -0
  14. package/scripts/wcag-audit.cjs +121 -6
  15. package/src/api/layers/file.ts +1 -0
  16. package/src/app/opengraph-image.tsx +5 -0
  17. package/src/app/preview/components/page.tsx +2237 -2
  18. package/src/app/shell.tsx +17 -16
  19. package/src/components/Foundations/Motion.stories.tsx +1 -0
  20. package/src/components/customize/brand-mark-section.tsx +4 -2
  21. package/src/components/customize/design-controls.tsx +17 -2
  22. package/src/components/customize/discipline-section.tsx +3 -6
  23. package/src/components/customize/font-pickers.tsx +1 -1
  24. package/src/components/customize/letter-spacing.tsx +1 -1
  25. package/src/components/customize/save-bar.tsx +2 -2
  26. package/src/components/customize/theme-io.tsx +7 -7
  27. package/src/components/customize/type-scale.tsx +1 -1
  28. package/src/components/customize-tab.tsx +7 -4
  29. package/src/components/home-tab.tsx +3 -0
  30. package/src/components/studio/studio.tsx +153 -0
  31. package/src/components/ui/accordion.tsx +7 -0
  32. package/src/components/ui/alert.tsx +1 -0
  33. package/src/components/ui/anchor.tsx +37 -3
  34. package/src/components/ui/announcement-bar.tsx +256 -0
  35. package/src/components/ui/attachment.tsx +211 -0
  36. package/src/components/ui/badge.tsx +1 -0
  37. package/src/components/ui/callout.tsx +218 -0
  38. package/src/components/ui/chart.tsx +5 -14
  39. package/src/components/ui/code.tsx +1 -1
  40. package/src/components/ui/color-picker.tsx +2 -2
  41. package/src/components/ui/format-relative-time.tsx +139 -0
  42. package/src/components/ui/gauge-chart.tsx +238 -0
  43. package/src/components/ui/grid.tsx +255 -0
  44. package/src/components/ui/heatmap.tsx +256 -0
  45. package/src/components/ui/icon.tsx +108 -0
  46. package/src/components/ui/index.ts +17 -0
  47. package/src/components/ui/infinite-scroll.tsx +103 -0
  48. package/src/components/ui/json-input.tsx +351 -0
  49. package/src/components/ui/navigation-progress.tsx +281 -0
  50. package/src/components/ui/number-input.tsx +1 -4
  51. package/src/components/ui/page-header.tsx +63 -0
  52. package/src/components/ui/password-input.tsx +2 -1
  53. package/src/components/ui/password-strength-input.tsx +288 -0
  54. package/src/components/ui/pill.tsx +140 -0
  55. package/src/components/ui/popover.tsx +27 -4
  56. package/src/components/ui/portal.tsx +111 -0
  57. package/src/components/ui/presence.tsx +172 -0
  58. package/src/components/ui/progress-stack.tsx +258 -0
  59. package/src/components/ui/scroll-progress.tsx +100 -0
  60. package/src/components/ui/select.tsx +89 -4
  61. package/src/components/ui/separator.tsx +1 -0
  62. package/src/components/ui/slider.tsx +83 -3
  63. package/src/components/ui/snackbar.tsx +393 -0
  64. package/src/components/ui/sortable-list.tsx +342 -0
  65. package/src/components/ui/sparkline.tsx +2 -14
  66. package/src/components/ui/squircle.tsx +1 -1
  67. package/src/components/ui/table.tsx +1 -1
  68. package/src/components/ui/textarea.tsx +28 -1
  69. package/src/components/ui/tour.tsx +1 -3
  70. package/src/data/docs-index.ts +25 -0
  71. package/src/hooks/use-reduced-motion.ts +6 -0
  72. package/src/lib/clamp.ts +2 -0
  73. package/src/stories/Accordion.stories.tsx +59 -0
  74. package/src/stories/Alert.stories.tsx +3 -1
  75. package/src/stories/Anchor.stories.tsx +54 -0
  76. package/src/stories/AnnouncementBar.stories.tsx +261 -0
  77. package/src/stories/Attachment.stories.tsx +189 -0
  78. package/src/stories/Badge.stories.tsx +3 -0
  79. package/src/stories/Calendar.stories.tsx +1 -1
  80. package/src/stories/Callout.stories.tsx +219 -0
  81. package/src/stories/Chart.stories.tsx +8 -0
  82. package/src/stories/Code.stories.tsx +1 -0
  83. package/src/stories/ColorPicker.stories.tsx +24 -0
  84. package/src/stories/FormatRelativeTime.stories.tsx +116 -0
  85. package/src/stories/GaugeChart.stories.tsx +163 -0
  86. package/src/stories/Grid.stories.tsx +197 -0
  87. package/src/stories/Heatmap.stories.tsx +172 -0
  88. package/src/stories/Icon.stories.tsx +175 -0
  89. package/src/stories/InfiniteScroll.stories.tsx +225 -0
  90. package/src/stories/JsonInput.stories.tsx +212 -0
  91. package/src/stories/MultiSelect.stories.tsx +1 -1
  92. package/src/stories/NavigationProgress.stories.tsx +159 -0
  93. package/src/stories/NumberInput.stories.tsx +1 -0
  94. package/src/stories/PageHeader.stories.tsx +102 -0
  95. package/src/stories/PasswordInput.stories.tsx +4 -0
  96. package/src/stories/PasswordStrengthInput.stories.tsx +211 -0
  97. package/src/stories/Pill.stories.tsx +201 -0
  98. package/src/stories/Popover.stories.tsx +29 -1
  99. package/src/stories/Portal.stories.tsx +191 -0
  100. package/src/stories/Presence.stories.tsx +228 -0
  101. package/src/stories/ProgressStack.stories.tsx +287 -0
  102. package/src/stories/ScrollProgress.stories.tsx +117 -0
  103. package/src/stories/Select.stories.tsx +25 -0
  104. package/src/stories/Separator.stories.tsx +3 -0
  105. package/src/stories/Slider.stories.tsx +54 -5
  106. package/src/stories/Snackbar.stories.tsx +315 -0
  107. package/src/stories/SortableList.stories.tsx +263 -0
  108. package/src/stories/Sparkline.stories.tsx +3 -0
  109. package/src/stories/Squircle.stories.tsx +1 -0
  110. package/src/stories/Table.stories.tsx +1 -0
  111. package/src/stories/Textarea.stories.tsx +18 -0
  112. package/src/stories/Tour.stories.tsx +1 -0
  113. package/src/stories/story-groups.json +26 -6
  114. package/src/styles.css +133 -12
  115. package/LICENSE +0 -21
@@ -0,0 +1,256 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import { X, InfoIcon, CheckCircle2Icon, TriangleAlertIcon, OctagonAlertIcon } from "lucide-react"
5
+ import { cva, type VariantProps } from "class-variance-authority"
6
+
7
+ import { cn } from "../../lib/utils"
8
+
9
+ // ─── AnnouncementBar ──────────────────────────────────────────────────────────
10
+ //
11
+ // A full-width, persistent banner for page-level or site-level messages:
12
+ // maintenance windows, feature launches, free-tier limits, service disruption,
13
+ // and cookie/consent notices.
14
+ //
15
+ // How it differs from the rest of the feedback family:
16
+ // - Alert: inline, role="alert", nested inside content
17
+ // - Notification: persisted feed item, inside an inbox/drawer
18
+ // - Sonner: ephemeral auto-dismissing toast overlay
19
+ // - Callout: editorial annotation inside prose
20
+ // - AnnouncementBar: full-width strip intended to sit ABOVE the main shell.
21
+ // It persists until explicitly dismissed (`onDismiss`) or until the
22
+ // triggering condition clears. It is NOT ephemeral, and it is not inline.
23
+ //
24
+ // Sources: GitHub's yellow notice banners, Vercel status/announcement strips,
25
+ // Linear free-plan limits, Stripe tax/compliance banners, common SaaS patterns.
26
+ //
27
+ // Layout: icon (optional) | message | action link (optional) | dismiss (optional)
28
+ // All three slots center-align on a single row. On narrow viewports the layout
29
+ // stacks: message + dismiss stay on one row; the action wraps below if provided
30
+ // and the viewport is very narrow.
31
+ //
32
+ // Accessibility:
33
+ // - role="banner" is reserved for the <header> landmark. AnnouncementBar uses
34
+ // role="region" with an aria-label so screen readers can navigate to it.
35
+ // - When `onDismiss` is provided the dismiss button announces "Dismiss
36
+ // [aria-label of the bar]" via aria-label, so its purpose is clear
37
+ // independent of the message text.
38
+ //
39
+ // Motion:
40
+ // - The bar enters by sliding in from the top on mount (translateY -100% →
41
+ // 0), using --duration-base + --ease-out. This is pattern (c): inline
42
+ // transitionDuration / transitionTimingFunction pointing to token vars.
43
+ // - On dismiss, the caller controls removal from the DOM; if they remove it
44
+ // instantly the slide-out is skipped. Pass the dismissed state as a prop
45
+ // and conditionally render to control the lifetime.
46
+ // - prefers-reduced-motion is handled by the base layer's 0.01ms override.
47
+
48
+ // ─── Variants ─────────────────────────────────────────────────────────────────
49
+
50
+ const announcementBarVariants = cva(
51
+ [
52
+ "relative w-full",
53
+ "flex items-center justify-center gap-2",
54
+ "px-4 py-2.5 min-h-11",
55
+ "text-sm font-medium",
56
+ ],
57
+ {
58
+ variants: {
59
+ /**
60
+ * Visual intent for the bar.
61
+ *
62
+ * default — primary brand accent. Feature launches, product updates.
63
+ * info — info accent. Neutral reference or contextual notice.
64
+ * success — success accent. Positive status, confirmed resolutions.
65
+ * warning — warning accent. Caution before an impending change.
66
+ * destructive — destructive accent. Active incidents, data-loss risk.
67
+ */
68
+ variant: {
69
+ // Solid primary background — the accent IS the signal here, unlike
70
+ // Alert's subtle tint. For an announcement, the color communicates
71
+ // importance proportionally to how much it pops above the shell.
72
+ default: "bg-primary text-primary-foreground [&_[data-slot=announcement-icon]]:text-primary-foreground",
73
+ info: "bg-info/15 text-foreground border-b border-[var(--info)]/20 [&_[data-slot=announcement-icon]]:text-[var(--info)]",
74
+ success: "bg-success/15 text-foreground border-b border-[var(--success)]/20 [&_[data-slot=announcement-icon]]:text-[var(--success)]",
75
+ warning: "bg-warning/20 text-foreground border-b border-[var(--warning)]/30 [&_[data-slot=announcement-icon]]:text-[var(--warning)]",
76
+ destructive: "bg-destructive/10 text-foreground border-b border-[var(--destructive)]/30 [&_[data-slot=announcement-icon]]:text-destructive",
77
+ },
78
+ },
79
+ defaultVariants: {
80
+ variant: "default",
81
+ },
82
+ }
83
+ )
84
+
85
+ // ─── Types ────────────────────────────────────────────────────────────────────
86
+
87
+ type AnnouncementBarVariant = NonNullable<
88
+ VariantProps<typeof announcementBarVariants>["variant"]
89
+ >
90
+
91
+ export interface AnnouncementBarProps
92
+ extends React.ComponentProps<"div">,
93
+ VariantProps<typeof announcementBarVariants> {
94
+ /**
95
+ * Called when the dismiss button is clicked. Providing this prop renders the
96
+ * dismiss button; omit it for a non-dismissible bar.
97
+ */
98
+ onDismiss?: () => void
99
+ /**
100
+ * Optional trailing CTA rendered after the message — a link, a Button, or
101
+ * any inline element. Renders inline in the message flow on wide viewports;
102
+ * can wrap on narrow ones.
103
+ */
104
+ action?: React.ReactNode
105
+ /**
106
+ * Custom icon to replace the default. Pass `null` to suppress. The default
107
+ * icon is chosen per variant (info → InfoIcon, success → CheckCircle2,
108
+ * warning → TriangleAlert, destructive → OctagonAlert, default → none).
109
+ */
110
+ icon?: React.ReactNode | null
111
+ /**
112
+ * Accessible name for the region. Defaults to "Announcement". Override
113
+ * when multiple bars may be present on the same page so screen readers
114
+ * can distinguish them.
115
+ */
116
+ "aria-label"?: string
117
+ }
118
+
119
+ // ─── Default icons ────────────────────────────────────────────────────────────
120
+
121
+ const DEFAULT_ICONS: Partial<Record<AnnouncementBarVariant, React.ElementType>> = {
122
+ info: InfoIcon,
123
+ success: CheckCircle2Icon,
124
+ warning: TriangleAlertIcon,
125
+ destructive: OctagonAlertIcon,
126
+ // default: no icon (brand announcements are self-explanatory by color)
127
+ }
128
+
129
+ // ─── Component ────────────────────────────────────────────────────────────────
130
+
131
+ /**
132
+ * AnnouncementBar — a full-width persistent strip for site-level messages.
133
+ *
134
+ * Place it above the main shell layout (outside the sidebar, above the
135
+ * top-bar) so it appears above all other chrome. Pair with a `useState`
136
+ * flag to dismiss it:
137
+ *
138
+ * ```tsx
139
+ * const [show, setShow] = useState(true);
140
+ * {show && (
141
+ * <AnnouncementBar
142
+ * variant="info"
143
+ * onDismiss={() => setShow(false)}
144
+ * action={<a href="/changelog" className="underline">View changelog</a>}
145
+ * >
146
+ * BADS v2.4 is now available with 12 new components.
147
+ * </AnnouncementBar>
148
+ * )}
149
+ * ```
150
+ *
151
+ * For persistence across page loads, store the dismissed state in
152
+ * `localStorage` keyed to the announcement's ID.
153
+ */
154
+ function AnnouncementBar({
155
+ className,
156
+ variant = "default",
157
+ onDismiss,
158
+ action,
159
+ icon,
160
+ children,
161
+ "aria-label": ariaLabel = "Announcement",
162
+ ...props
163
+ }: AnnouncementBarProps) {
164
+ // Resolve icon: explicit null suppresses, explicit ReactNode overrides,
165
+ // undefined falls back to the per-variant default (if any).
166
+ const DefaultIconComp = DEFAULT_ICONS[variant ?? "default"]
167
+ const resolvedIcon =
168
+ icon === null
169
+ ? null
170
+ : icon !== undefined
171
+ ? icon
172
+ : DefaultIconComp
173
+ ? (
174
+ <DefaultIconComp
175
+ data-slot="announcement-icon"
176
+ aria-hidden
177
+ strokeWidth={1.5}
178
+ className="size-4 shrink-0"
179
+ />
180
+ )
181
+ : null
182
+
183
+ // Mount animation: enter from the top. The initial translateY is set via
184
+ // inline style driven by the mounted state — one rAF before setMounted(true)
185
+ // gives the browser a frame to paint the off-screen start position.
186
+ const [mounted, setMounted] = React.useState(false)
187
+ React.useEffect(() => {
188
+ const id = requestAnimationFrame(() => setMounted(true))
189
+ return () => cancelAnimationFrame(id)
190
+ }, [])
191
+
192
+ return (
193
+ <div
194
+ data-slot="announcement-bar"
195
+ data-variant={variant}
196
+ role="region"
197
+ aria-label={ariaLabel}
198
+ className={cn(
199
+ announcementBarVariants({ variant }),
200
+ // Right padding for dismiss button so message text doesn't slide under it.
201
+ onDismiss && "pr-12",
202
+ className
203
+ )}
204
+ style={{
205
+ transform: mounted ? "translateY(0)" : "translateY(-100%)",
206
+ transitionProperty: "transform",
207
+ transitionDuration: "var(--duration-base)",
208
+ transitionTimingFunction: "var(--ease-out)",
209
+ }}
210
+ {...props}
211
+ >
212
+ {/* Icon (optional) */}
213
+ {resolvedIcon}
214
+
215
+ {/* Message + action inline */}
216
+ <div
217
+ data-slot="announcement-message"
218
+ className="flex flex-wrap items-center justify-center gap-x-2 gap-y-1 text-center"
219
+ >
220
+ {children}
221
+ {action && (
222
+ <span
223
+ data-slot="announcement-action"
224
+ className="shrink-0"
225
+ >
226
+ {action}
227
+ </span>
228
+ )}
229
+ </div>
230
+
231
+ {/* Dismiss */}
232
+ {onDismiss && (
233
+ <button
234
+ type="button"
235
+ aria-label={`Dismiss ${ariaLabel}`}
236
+ onClick={onDismiss}
237
+ className={cn(
238
+ "absolute right-3 rounded-sm p-1",
239
+ "opacity-70 hover:opacity-100",
240
+ "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-current focus-visible:ring-offset-1",
241
+ "transition-opacity",
242
+ )}
243
+ style={{
244
+ transitionDuration: "var(--duration-fast)",
245
+ transitionTimingFunction: "var(--ease-out)",
246
+ }}
247
+ >
248
+ <X className="size-4 shrink-0" strokeWidth={1.5} aria-hidden />
249
+ </button>
250
+ )}
251
+ </div>
252
+ )
253
+ }
254
+
255
+ export { AnnouncementBar, announcementBarVariants }
256
+ export type { AnnouncementBarVariant }
@@ -0,0 +1,211 @@
1
+ "use client"
2
+
3
+ /**
4
+ * Attachment — pre-send file chip for a chat composer.
5
+ *
6
+ * Appears inside the composer input area after a user picks a file and
7
+ * before the message is sent: file-type icon, truncated file name, formatted
8
+ * size, and a remove control. Pairs with ChatInput (the composer) and
9
+ * FileButton (the picker). It is the third leg of the attach flow — pick
10
+ * (FileButton) → review (Attachment) → send (ChatInput).
11
+ *
12
+ * Sources: shadcn/ui July 2026 chat release (Attachment); Mantine FileButton
13
+ * + Pill attachment pattern. Convention: Slack, Linear, and Intercom composer
14
+ * chips.
15
+ *
16
+ * NOT a drop zone (FileUpload) and NOT a post-send file card in the
17
+ * conversation (FileCard). Attachment is the chip the user can still back out
18
+ * of.
19
+ *
20
+ * Composition (bucket C): CloseButton for the remove control (inherits
21
+ * Button's focus ring, disabled handling, and 1.5-stroke X) and FormatByte
22
+ * for the size (SI scale, exact byte count on title). No new tokens.
23
+ *
24
+ * Accessibility:
25
+ * - root is role="group" with aria-label "Attached file: <name>" so a screen
26
+ * reader hears the chip as one unit before reaching the remove button
27
+ * - remove button is a 44px CloseButton (size="icon-xl", SC 2.5.5 Enhanced)
28
+ * with aria-label "Remove <name>" — the chip is a flow-changing control
29
+ * inside a composer, so the dense-chrome 36px exception does not apply
30
+ * - file name truncates (min-w-0 truncate) and rides the title attribute so
31
+ * the full string is recoverable on hover; the group's aria-label carries
32
+ * it for assistive tech
33
+ *
34
+ * Motion (spec §4c): remove-button hover is transition-colors driven by
35
+ * --duration-fast / --ease-out. No entrance or exit animation — the chip
36
+ * mounts and unmounts with the composer's own layout; animating removal
37
+ * would delay the user's undo-the-mistake action.
38
+ */
39
+
40
+ import * as React from "react"
41
+ import {
42
+ File,
43
+ FileArchive,
44
+ FileAudio,
45
+ FileCode,
46
+ FileImage,
47
+ FileText,
48
+ FileVideo,
49
+ type LucideIcon,
50
+ } from "lucide-react"
51
+
52
+ import { cn } from "../../lib/utils"
53
+ import { CloseButton } from "./close-button"
54
+ import { FormatByte } from "./format-byte"
55
+
56
+ const CODE_MIME = new Set([
57
+ "application/json",
58
+ "application/javascript",
59
+ "application/typescript",
60
+ "application/xml",
61
+ "application/x-sh",
62
+ "application/x-yaml",
63
+ "text/javascript",
64
+ "text/typescript",
65
+ "text/css",
66
+ "text/html",
67
+ "text/xml",
68
+ "text/markdown",
69
+ "text/x-python",
70
+ "text/x-java-source",
71
+ "text/x-c",
72
+ "text/yaml",
73
+ ])
74
+
75
+ const ARCHIVE_MIME = new Set([
76
+ "application/zip",
77
+ "application/x-zip-compressed",
78
+ "application/gzip",
79
+ "application/x-gzip",
80
+ "application/x-tar",
81
+ "application/x-7z-compressed",
82
+ "application/x-rar-compressed",
83
+ "application/vnd.rar",
84
+ "application/x-bzip2",
85
+ ])
86
+
87
+ const CODE_EXT = new Set([
88
+ "js", "jsx", "ts", "tsx", "mjs", "cjs", "json", "css", "scss", "html",
89
+ "xml", "yml", "yaml", "md", "py", "rb", "go", "rs", "java", "kt", "swift",
90
+ "c", "h", "cpp", "cs", "sh", "sql", "toml",
91
+ ])
92
+
93
+ const ARCHIVE_EXT = new Set(["zip", "gz", "tgz", "tar", "7z", "rar", "bz2"])
94
+ const IMAGE_EXT = new Set(["png", "jpg", "jpeg", "gif", "webp", "svg", "avif", "heic"])
95
+ const TEXT_EXT = new Set(["pdf", "txt", "doc", "docx", "rtf", "csv", "odt"])
96
+ const AUDIO_EXT = new Set(["mp3", "wav", "m4a", "ogg", "flac", "aac"])
97
+ const VIDEO_EXT = new Set(["mp4", "mov", "webm", "mkv", "avi"])
98
+
99
+ /**
100
+ * Picks the lucide glyph for a file. MIME type wins (it is what
101
+ * `File.type` reports); the extension is the fallback when the browser gives
102
+ * an empty or generic type (`application/octet-stream` is common on Windows
103
+ * for anything it does not recognize).
104
+ */
105
+ function iconForFile(fileName: string, fileType?: string): LucideIcon {
106
+ const mime = (fileType ?? "").toLowerCase()
107
+
108
+ if (mime.startsWith("image/")) return FileImage
109
+ if (mime.startsWith("audio/")) return FileAudio
110
+ if (mime.startsWith("video/")) return FileVideo
111
+ if (CODE_MIME.has(mime)) return FileCode
112
+ if (ARCHIVE_MIME.has(mime)) return FileArchive
113
+ if (mime === "application/pdf" || mime.startsWith("text/")) return FileText
114
+ if (mime.startsWith("application/vnd.") || mime === "application/msword")
115
+ return FileText
116
+
117
+ const dot = fileName.lastIndexOf(".")
118
+ const ext = dot >= 0 ? fileName.slice(dot + 1).toLowerCase() : ""
119
+ if (IMAGE_EXT.has(ext)) return FileImage
120
+ if (AUDIO_EXT.has(ext)) return FileAudio
121
+ if (VIDEO_EXT.has(ext)) return FileVideo
122
+ if (CODE_EXT.has(ext)) return FileCode
123
+ if (ARCHIVE_EXT.has(ext)) return FileArchive
124
+ if (TEXT_EXT.has(ext)) return FileText
125
+
126
+ return File
127
+ }
128
+
129
+ export interface AttachmentProps
130
+ extends Omit<React.ComponentProps<"div">, "children"> {
131
+ /** The file's name, shown truncated; the full value rides `title` and the group's aria-label. */
132
+ fileName: string
133
+ /** Size in bytes. Rendered via FormatByte (SI scale: 42.7 KB, 1.5 MB). Omit to hide. */
134
+ fileSize?: number
135
+ /** MIME type (`File.type`) used to pick the icon. Falls back to the file extension. */
136
+ fileType?: string
137
+ /**
138
+ * Called when the user activates the remove control. When absent the
139
+ * remove button is not rendered — the chip becomes read-only.
140
+ */
141
+ onRemove?: () => void
142
+ /** Dims the chip and disables the remove control (for example while the message is sending). */
143
+ disabled?: boolean
144
+ }
145
+
146
+ function Attachment({
147
+ fileName,
148
+ fileSize,
149
+ fileType,
150
+ onRemove,
151
+ disabled = false,
152
+ className,
153
+ ...props
154
+ }: AttachmentProps) {
155
+ const Icon = iconForFile(fileName, fileType)
156
+
157
+ return (
158
+ <div
159
+ role="group"
160
+ aria-label={`Attached file: ${fileName}`}
161
+ aria-disabled={disabled || undefined}
162
+ data-slot="attachment"
163
+ data-disabled={disabled || undefined}
164
+ className={cn(
165
+ "inline-flex min-h-11 max-w-xs min-w-0 items-center gap-2 overflow-hidden rounded-lg border bg-muted/50 py-1 pl-3 text-foreground",
166
+ onRemove ? "pr-1" : "pr-3",
167
+ disabled && "opacity-50",
168
+ className
169
+ )}
170
+ {...props}
171
+ >
172
+ <Icon
173
+ strokeWidth={1.5}
174
+ aria-hidden="true"
175
+ className="size-5 shrink-0 text-muted-foreground"
176
+ />
177
+ <span className="flex min-w-0 flex-1 flex-col leading-tight">
178
+ <span
179
+ data-slot="attachment-name"
180
+ className="min-w-0 truncate text-sm font-medium"
181
+ title={fileName}
182
+ >
183
+ {fileName}
184
+ </span>
185
+ {typeof fileSize === "number" && (
186
+ <FormatByte
187
+ data-slot="attachment-size"
188
+ value={fileSize}
189
+ className="text-xs text-muted-foreground"
190
+ />
191
+ )}
192
+ </span>
193
+ {onRemove && (
194
+ <CloseButton
195
+ data-slot="attachment-remove"
196
+ size="icon-xl"
197
+ aria-label={`Remove ${fileName}`}
198
+ disabled={disabled}
199
+ onClick={onRemove}
200
+ className="-my-1"
201
+ style={{
202
+ transitionDuration: "var(--duration-fast)",
203
+ transitionTimingFunction: "var(--ease-out)",
204
+ }}
205
+ />
206
+ )}
207
+ </div>
208
+ )
209
+ }
210
+
211
+ export { Attachment }
@@ -31,6 +31,7 @@ const badgeVariants = cva(
31
31
  // named border-color utilities don't generate a rule in this
32
32
  // Tailwind v4 setup (see the same note in alert.tsx) and `!` beats
33
33
  // the base `border-transparent`.
34
+ // @recipe-note: The success/warning/info border color is set with `!` (border-[var(--success)]!). An override must match that importance — `border-transparent` alone will not beat it. Use `border-transparent!` to remove the border, not `border-transparent`.
34
35
  success:
35
36
  "border-[var(--success)]! bg-success/10 text-foreground [&>svg]:text-success dark:bg-success/15",
36
37
  warning:
@@ -0,0 +1,218 @@
1
+ import * as React from "react"
2
+ import {
3
+ InfoIcon,
4
+ LightbulbIcon,
5
+ TriangleAlertIcon,
6
+ OctagonAlertIcon,
7
+ CircleAlertIcon,
8
+ } from "lucide-react"
9
+ import { cva, type VariantProps } from "class-variance-authority"
10
+
11
+ import { cn } from "../../lib/utils"
12
+
13
+ // ─── Callout — the prose / documentation callout block ───────────────────────
14
+ //
15
+ // The editorial sibling of Alert, Notification, and Sonner. Use it to draw
16
+ // attention to a block of content inside prose or documentation, not to
17
+ // communicate system feedback.
18
+ //
19
+ // How it differs from Alert:
20
+ // - No `role="alert"`: a callout is contextual annotation, not urgent feedback.
21
+ // Screen readers should announce it in reading order, not interrupt.
22
+ // - Richer content slot: the body can hold headings, lists, inline code, and
23
+ // multiple paragraphs — no single-line constraint.
24
+ // - No dismiss button or action row (editorial asides are not dismissed).
25
+ // - Variants named for editorial convention: note / tip / warning / danger / info.
26
+ //
27
+ // Sources: GitHub Markdown callout syntax (> [!NOTE]), Nextra, VitePress,
28
+ // Docusaurus admonitions, Notion callout block, Tailwind CSS docs.
29
+ //
30
+ // Motion: none — callouts are display-only annotation; entrance animation
31
+ // would distract from the prose flow around them.
32
+
33
+ // ─── Variants ─────────────────────────────────────────────────────────────────
34
+
35
+ const calloutVariants = cva(
36
+ // Grid with icon pinned to col-1 row-1, same layout as Alert. The icon
37
+ // column activates only when an icon is rendered (has-[>svg]). Padding is
38
+ // slightly more generous than Alert-sm to give body text room to breathe.
39
+ [
40
+ "relative grid w-full grid-cols-[0_1fr] items-start rounded-lg border",
41
+ "[&>svg]:row-start-1 [&>svg]:col-start-1 [&>svg]:text-current",
42
+ "has-[>svg]:grid-cols-[calc(var(--spacing)*5)_1fr] has-[>svg]:gap-x-3",
43
+ "px-5 py-4 gap-y-1.5 [&>svg]:size-5 [&>svg]:mt-0.5",
44
+ ],
45
+ {
46
+ variants: {
47
+ /**
48
+ * Semantic intent for the callout. The intent drives icon, border
49
+ * accent, and background tint; the label color stays text-foreground
50
+ * (AAA floor). Never rely on color alone — the default icon and
51
+ * (optionally) the `title` text carry the semantic label visually.
52
+ *
53
+ * note — primary accent (blue). General informational aside.
54
+ * tip — success accent (green). Helpful shortcut or best practice.
55
+ * warning — warning accent (amber). Caution: risk or potential issue.
56
+ * danger — destructive accent (red). Stop: breaking change or data loss.
57
+ * info — info accent. Neutral reference that isn't an error or tip.
58
+ */
59
+ variant: {
60
+ // NOTE: accent colors use the arbitrary `border-l-[var(--token)]!`
61
+ // form — named border-color utilities don't generate a rule in this
62
+ // Tailwind v4 setup. Same pattern as Alert and Notification.
63
+ note: [
64
+ "border-border border-l-4 border-l-[var(--primary)]!",
65
+ "bg-primary/5 dark:bg-primary/10",
66
+ "[&>svg]:text-primary",
67
+ ],
68
+ tip: [
69
+ "border-border border-l-4 border-l-[var(--success)]!",
70
+ "bg-success/5 dark:bg-success/10",
71
+ "[&>svg]:text-[var(--success)]",
72
+ ],
73
+ warning: [
74
+ "border-border border-l-4 border-l-[var(--warning)]!",
75
+ "bg-warning/5 dark:bg-warning/10",
76
+ "[&>svg]:text-[var(--warning)]",
77
+ ],
78
+ danger: [
79
+ "border-[var(--destructive)]! border-l-4",
80
+ "bg-destructive/5 dark:bg-destructive/10",
81
+ "[&>svg]:text-destructive",
82
+ ],
83
+ info: [
84
+ "border-border border-l-4 border-l-[var(--info)]!",
85
+ "bg-info/5 dark:bg-info/10",
86
+ "[&>svg]:text-[var(--info)]",
87
+ ],
88
+ },
89
+ },
90
+ defaultVariants: {
91
+ variant: "note",
92
+ },
93
+ }
94
+ )
95
+
96
+ // ─── Types ────────────────────────────────────────────────────────────────────
97
+
98
+ type CalloutVariant = NonNullable<VariantProps<typeof calloutVariants>["variant"]>
99
+
100
+ export interface CalloutProps
101
+ extends Omit<React.ComponentProps<"aside">, "title">,
102
+ VariantProps<typeof calloutVariants> {
103
+ /**
104
+ * Custom icon to replace the default. Pass `null` to suppress the icon
105
+ * entirely and let the callout render without one. The default icon is
106
+ * chosen per variant (note → Info, tip → Lightbulb, warning → TriangleAlert,
107
+ * danger → OctagonAlert, info → CircleAlert).
108
+ */
109
+ icon?: React.ReactNode | null
110
+ /**
111
+ * Optional short header rendered above the body. Use for the "Note",
112
+ * "Warning", etc. label or a custom heading. When omitted, the callout has
113
+ * no visible heading — the icon alone carries the variant signal.
114
+ */
115
+ title?: React.ReactNode
116
+ }
117
+
118
+ // ─── Default icons per variant ────────────────────────────────────────────────
119
+
120
+ const DEFAULT_ICONS: Record<CalloutVariant, React.ElementType> = {
121
+ note: InfoIcon,
122
+ tip: LightbulbIcon,
123
+ warning: TriangleAlertIcon,
124
+ danger: OctagonAlertIcon,
125
+ info: CircleAlertIcon,
126
+ }
127
+
128
+ // ─── Sub-components ───────────────────────────────────────────────────────────
129
+
130
+ function CalloutTitle({ className, ...props }: React.ComponentProps<"p">) {
131
+ return (
132
+ <p
133
+ data-slot="callout-title"
134
+ className={cn("col-start-2 text-sm font-medium leading-snug", className)}
135
+ {...props}
136
+ />
137
+ )
138
+ }
139
+
140
+ function CalloutBody({ className, ...props }: React.ComponentProps<"div">) {
141
+ return (
142
+ <div
143
+ data-slot="callout-body"
144
+ className={cn(
145
+ "col-start-2 text-sm text-muted-foreground",
146
+ // Let inline headings, lists, and code render cleanly inside the body.
147
+ // Prose spacing: small gap between children.
148
+ "[&>*+*]:mt-2",
149
+ className
150
+ )}
151
+ {...props}
152
+ />
153
+ )
154
+ }
155
+
156
+ // ─── Root ─────────────────────────────────────────────────────────────────────
157
+
158
+ /**
159
+ * Callout — a documentation/editorial aside that highlights contextual
160
+ * information inside prose.
161
+ *
162
+ * Use `<Callout>` for inline editorial annotation: a note about a gotcha, a
163
+ * tip about a shortcut, a warning before a destructive operation's docs.
164
+ *
165
+ * Five variants (note / tip / warning / danger / info) map to the same
166
+ * intent family as Alert and Notification so all three surfaces read as one
167
+ * system, but with a different visual treatment — left-border accent only,
168
+ * no dismiss, no action, no `role="alert"` urgency.
169
+ *
170
+ * @example
171
+ * ```tsx
172
+ * <Callout variant="tip" title="Tip">
173
+ * Run <Code>pnpm build:tokens</Code> after editing <Code>tokens.json</Code>.
174
+ * Both CSS files regenerate automatically.
175
+ * </Callout>
176
+ *
177
+ * <Callout variant="danger" title="Breaking change">
178
+ * <p>The <Code>size</Code> prop on Button was renamed to <Code>buttonSize</Code>.</p>
179
+ * <p>Update every usage before upgrading to v3.</p>
180
+ * </Callout>
181
+ * ```
182
+ */
183
+ function Callout({
184
+ className,
185
+ variant = "note",
186
+ icon,
187
+ title,
188
+ children,
189
+ ...props
190
+ }: CalloutProps) {
191
+ // Resolve icon: explicit null suppresses, explicit ReactNode overrides,
192
+ // undefined falls back to the default for the variant.
193
+ const DefaultIcon = DEFAULT_ICONS[variant ?? "note"]
194
+ const resolvedIcon =
195
+ icon === null ? null : icon !== undefined ? icon : (
196
+ <DefaultIcon
197
+ data-slot="callout-icon"
198
+ strokeWidth={1.5}
199
+ aria-hidden
200
+ />
201
+ )
202
+
203
+ return (
204
+ <aside
205
+ data-slot="callout"
206
+ data-variant={variant}
207
+ className={cn(calloutVariants({ variant }), className)}
208
+ {...props}
209
+ >
210
+ {resolvedIcon}
211
+ {title && <CalloutTitle>{title}</CalloutTitle>}
212
+ <CalloutBody>{children}</CalloutBody>
213
+ </aside>
214
+ )
215
+ }
216
+
217
+ export { Callout, CalloutTitle, CalloutBody, calloutVariants }
218
+ export type { CalloutVariant }