@behavioral-agentic-design-system/core 0.39.0 → 0.40.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 (78) hide show
  1. package/package.json +8 -3
  2. package/scripts/a11y-lint.cjs +93 -39
  3. package/scripts/a11y-ratchet.mjs +10 -23
  4. package/scripts/bads-components.mjs +118 -0
  5. package/scripts/build-tokens.cjs +175 -17
  6. package/scripts/check-stories.mjs +1 -1
  7. package/scripts/health-report.mjs +52 -10
  8. package/scripts/lib/scan-roots.cjs +143 -0
  9. package/scripts/lint-component-source.mjs +100 -0
  10. package/scripts/lint-microanimation.mjs +267 -0
  11. package/scripts/lint-slop.mjs +21 -28
  12. package/scripts/lint-token-intent.mjs +10 -16
  13. package/scripts/size-audit.cjs +94 -27
  14. package/scripts/source-of-truth.cjs +58 -0
  15. package/scripts/ux-smoke.mjs +438 -0
  16. package/scripts/wcag-audit.cjs +49 -1
  17. package/src/api/layers/file.ts +2 -0
  18. package/src/app/preview/components/page.tsx +972 -0
  19. package/src/app/preview/health/page.tsx +8 -5
  20. package/src/app/preview/history/page.tsx +11 -0
  21. package/src/app/shell.tsx +261 -87
  22. package/src/components/customize/brand-mark-section.tsx +4 -2
  23. package/src/components/customize/design-controls.tsx +1 -1
  24. package/src/components/customize/discipline-section.tsx +91 -0
  25. package/src/components/customize/font-pickers.tsx +1 -1
  26. package/src/components/customize/letter-spacing.tsx +1 -1
  27. package/src/components/customize/save-bar.tsx +2 -2
  28. package/src/components/customize/theme-io.tsx +7 -7
  29. package/src/components/customize/type-scale.tsx +1 -1
  30. package/src/components/customize-tab.tsx +9 -4
  31. package/src/components/home-tab.tsx +3 -0
  32. package/src/components/ui/accordion.tsx +7 -0
  33. package/src/components/ui/alert.tsx +1 -0
  34. package/src/components/ui/announcement-bar.tsx +256 -0
  35. package/src/components/ui/badge.tsx +1 -0
  36. package/src/components/ui/callout.tsx +218 -0
  37. package/src/components/ui/chart.tsx +2 -14
  38. package/src/components/ui/color-picker.tsx +1 -1
  39. package/src/components/ui/format-relative-time.tsx +139 -0
  40. package/src/components/ui/grid.tsx +255 -0
  41. package/src/components/ui/icon.tsx +108 -0
  42. package/src/components/ui/index.ts +8 -0
  43. package/src/components/ui/page-header.tsx +63 -0
  44. package/src/components/ui/portal.tsx +111 -0
  45. package/src/components/ui/presence.tsx +172 -0
  46. package/src/components/ui/progress-stack.tsx +258 -0
  47. package/src/components/ui/select.tsx +89 -4
  48. package/src/components/ui/separator.tsx +1 -0
  49. package/src/components/ui/slider.tsx +83 -3
  50. package/src/components/ui/sparkline.tsx +15 -15
  51. package/src/components/ui/textarea.tsx +28 -1
  52. package/src/data/docs-index.ts +5 -0
  53. package/src/data/history.json +269 -0
  54. package/src/hooks/use-reduced-motion.ts +6 -0
  55. package/src/stories/Accordion.stories.tsx +59 -0
  56. package/src/stories/Alert.stories.tsx +3 -1
  57. package/src/stories/AnnouncementBar.stories.tsx +261 -0
  58. package/src/stories/Badge.stories.tsx +3 -0
  59. package/src/stories/Calendar.stories.tsx +1 -1
  60. package/src/stories/Callout.stories.tsx +219 -0
  61. package/src/stories/Chart.stories.tsx +4 -0
  62. package/src/stories/ColorPicker.stories.tsx +23 -0
  63. package/src/stories/FormatRelativeTime.stories.tsx +116 -0
  64. package/src/stories/Grid.stories.tsx +197 -0
  65. package/src/stories/Icon.stories.tsx +175 -0
  66. package/src/stories/MultiSelect.stories.tsx +1 -1
  67. package/src/stories/PageHeader.stories.tsx +102 -0
  68. package/src/stories/Portal.stories.tsx +189 -0
  69. package/src/stories/Presence.stories.tsx +228 -0
  70. package/src/stories/ProgressStack.stories.tsx +287 -0
  71. package/src/stories/Select.stories.tsx +25 -0
  72. package/src/stories/Separator.stories.tsx +3 -0
  73. package/src/stories/Sheet.stories.tsx +9 -3
  74. package/src/stories/Slider.stories.tsx +54 -5
  75. package/src/stories/Sparkline.stories.tsx +39 -0
  76. package/src/stories/Textarea.stories.tsx +18 -0
  77. package/src/stories/story-groups.json +14 -5
  78. package/src/styles.css +133 -12
@@ -376,7 +376,7 @@ export function SaveBar() {
376
376
  <div className="flex items-center gap-2 shrink-0">
377
377
  <Button
378
378
  variant="ghost"
379
- size="sm"
379
+ size="xl"
380
380
  onClick={handleResetAll}
381
381
  disabled={status === "saving"}
382
382
  className="gap-2"
@@ -385,7 +385,7 @@ export function SaveBar() {
385
385
  Reset all
386
386
  </Button>
387
387
  <Button
388
- size="sm"
388
+ size="xl"
389
389
  onClick={handleSave}
390
390
  disabled={status === "saving" || count === 0}
391
391
  className="gap-2"
@@ -122,7 +122,7 @@ export function ThemeIO() {
122
122
  <div className="flex flex-wrap gap-2">
123
123
  <Dialog open={importOpen} onOpenChange={setImportOpen}>
124
124
  <DialogTrigger asChild>
125
- <Button variant="outline" size="sm" className="gap-2">
125
+ <Button variant="outline" size="xl" className="gap-2">
126
126
  <Upload className="h-4 w-4" />
127
127
  Import theme
128
128
  </Button>
@@ -161,7 +161,7 @@ export function ThemeIO() {
161
161
  <DialogFooter>
162
162
  <Button
163
163
  variant="outline"
164
- size="sm"
164
+ size="xl"
165
165
  onClick={() => {
166
166
  setImportOpen(false);
167
167
  setImportValue("");
@@ -170,7 +170,7 @@ export function ThemeIO() {
170
170
  >
171
171
  Cancel
172
172
  </Button>
173
- <Button size="sm" onClick={handleImport} disabled={!importValue.trim()}>
173
+ <Button size="xl" onClick={handleImport} disabled={!importValue.trim()}>
174
174
  Apply theme
175
175
  </Button>
176
176
  </DialogFooter>
@@ -179,7 +179,7 @@ export function ThemeIO() {
179
179
 
180
180
  <Dialog open={exportOpen} onOpenChange={setExportOpen}>
181
181
  <DialogTrigger asChild>
182
- <Button variant="outline" size="sm" className="gap-2" onClick={handleOpenExport}>
182
+ <Button variant="outline" size="xl" className="gap-2" onClick={handleOpenExport}>
183
183
  <Download className="h-4 w-4" />
184
184
  Export theme
185
185
  </Button>
@@ -213,10 +213,10 @@ export function ThemeIO() {
213
213
  onFocus={(e) => e.currentTarget.select()}
214
214
  />
215
215
  <DialogFooter>
216
- <Button variant="outline" size="sm" onClick={() => setExportOpen(false)}>
216
+ <Button variant="outline" size="xl" onClick={() => setExportOpen(false)}>
217
217
  Close
218
218
  </Button>
219
- <Button size="sm" onClick={handleCopy} className="gap-2">
219
+ <Button size="xl" onClick={handleCopy} className="gap-2">
220
220
  {copied ? (
221
221
  <>
222
222
  <Check className="h-4 w-4" />
@@ -234,7 +234,7 @@ export function ThemeIO() {
234
234
  </Dialog>
235
235
 
236
236
  {hasTheme && (
237
- <Button variant="ghost" size="sm" className="gap-2" onClick={clearTheme}>
237
+ <Button variant="ghost" size="xl" className="gap-2" onClick={clearTheme}>
238
238
  <RotateCcw className="h-4 w-4" />
239
239
  Reset to default
240
240
  </Button>
@@ -46,7 +46,7 @@ export function TypeScalePanel() {
46
46
  whole hierarchy stays harmonic when you change either control.
47
47
  </p>
48
48
 
49
- <div className="grid grid-cols-1 lg:grid-cols-2 gap-x-10 gap-y-8 mb-10">
49
+ <div className="grid grid-cols-1 @2xl/panel:grid-cols-2 gap-x-10 gap-y-8 mb-10">
50
50
  <div className="space-y-3">
51
51
  <div className="flex items-baseline justify-between gap-3">
52
52
  <label className="text-sm font-semibold">Base Size</label>
@@ -36,6 +36,7 @@ import {
36
36
  import { TypeScalePanel } from "@behavioral-agentic-design-system/core/components/customize/type-scale";
37
37
  import { LetterSpacingPanel } from "@behavioral-agentic-design-system/core/components/customize/letter-spacing";
38
38
  import { SaveBar } from "@behavioral-agentic-design-system/core/components/customize/save-bar";
39
+ import { DisciplineSection } from "@behavioral-agentic-design-system/core/components/customize/discipline-section";
39
40
  import { nameFromHex } from "@behavioral-agentic-design-system/core/lib/color-name";
40
41
 
41
42
  type TokenSwatchPickerCtx = {
@@ -252,7 +253,7 @@ function ColorSection({
252
253
  <h4 className="text-base font-semibold">{title}</h4>
253
254
  {action}
254
255
  </div>
255
- <div className="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-3">
256
+ <div className="grid grid-cols-2 @lg/panel:grid-cols-3 @xl/panel:grid-cols-4 @2xl/panel:grid-cols-5 gap-3">
256
257
  {children}
257
258
  </div>
258
259
  </div>
@@ -639,7 +640,7 @@ function PrimaryColorPicker() {
639
640
  </div>
640
641
  )}
641
642
 
642
- <div className="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-4 xl:grid-cols-8 gap-3">
643
+ <div className="grid grid-cols-2 @lg/panel:grid-cols-3 @xl/panel:grid-cols-4 @2xl/panel:grid-cols-4 @3xl/panel:grid-cols-8 gap-3">
643
644
  {keys.map((key) => {
644
645
  const opt = options[key];
645
646
  const isCustom = key in customs;
@@ -672,7 +673,7 @@ function PrimaryColorPicker() {
672
673
  );
673
674
  }
674
675
 
675
- function ColorPalette() {
676
+ export function ColorPalette() {
676
677
  const { options, addCustomSilent } = useGlobalPrimaryColor();
677
678
  const { overrides, updateOverride, remove } = useTokenOverrides();
678
679
  const swatchCtx = useMemo<TokenSwatchPickerCtx>(
@@ -682,7 +683,10 @@ function ColorPalette() {
682
683
 
683
684
  return (
684
685
  <TokenSwatchPicker.Provider value={swatchCtx}>
685
- <div className="p-4 sm:p-6 lg:p-8 pb-32 max-w-7xl mx-auto space-y-12 sm:space-y-20">
686
+ {/* No padding here: Studio's column already pads. Two layers cost 96px of
687
+ a 400px column. No max-w/mx-auto either — this is a panel, not a page.
688
+ gap-6 is the DESIGN.md section rhythm; space-y-20 was page rhythm. */}
689
+ <div className="flex flex-col gap-10">
686
690
  <ThemeIO />
687
691
  <PrimaryColorPicker />
688
692
  <BrandMarkSection />
@@ -776,6 +780,7 @@ export function CustomizeTab() {
776
780
  return (
777
781
  <ScrollArea className="size-full">
778
782
  <div className="motion-safe:animate-in motion-safe:fade-in motion-safe:slide-in-from-bottom-2 motion-safe:duration-500">
783
+ <DisciplineSection />
779
784
  <ColorPalette />
780
785
  </div>
781
786
  </ScrollArea>
@@ -238,6 +238,9 @@ function PromptCard({
238
238
  <p className="line-clamp-3 rounded-md border bg-muted/40 p-2.5 font-mono text-xs leading-relaxed text-muted-foreground">
239
239
  {prompt}
240
240
  </p>
241
+ {/* allow-small-cta: copy-to-clipboard changes no flow — no route, no
242
+ modal, no filter — so the 44px CTA floor does not apply. It is
243
+ full-width to line up with the card's prompt block above it. */}
241
244
  <Button
242
245
  size="sm"
243
246
  variant={copied ? "default" : "outline"}
@@ -41,6 +41,10 @@ function Accordion({
41
41
  <AccordionPrimitive.Root
42
42
  data-slot="accordion"
43
43
  data-variant={variant}
44
+ // A primitive is the layer that draws a card surface, so it cannot
45
+ // compose Card to get one, and these classes belong on Radix's own
46
+ // Root, which a wrapping Card would displace.
47
+ // lint-disable: card-bypass
44
48
  className={cn(
45
49
  // contained: shared card — divide-y handles item separators so
46
50
  // AccordionItem needs no border of its own.
@@ -64,6 +68,9 @@ function AccordionItem({
64
68
  return (
65
69
  <AccordionPrimitive.Item
66
70
  data-slot="accordion-item"
71
+ // Same reason as the Root above. The separated variant's per-item card is
72
+ // this primitive's own surface, not a consumer hand-rolling one.
73
+ // lint-disable: card-bypass
67
74
  className={cn(
68
75
  // default: bottom border on every item except the last.
69
76
  variant === "default" && "border-b last:border-b-0",
@@ -33,6 +33,7 @@ const alertVariants = cva(
33
33
  // emitted), so the color silently fell through to the `:root *`
34
34
  // `border-border` base reset (the bug that made these accents render
35
35
  // grey). Arbitrary values always generate; `!` wins over `:root *`.
36
+ // @recipe-note: The left-accent and border colors are set with `!` (border-l-[var(--primary)]!). An override must match that importance — `border-l-transparent` alone will not beat it. Use `border-l-transparent!` to remove the accent, not `border-l-transparent`.
36
37
  default: "border-border border-l-4 border-l-[var(--primary)]! bg-primary/5 text-foreground [&>svg]:text-primary dark:bg-primary/10",
37
38
  // Full red border (all four sides) so the error reads as an error at a
38
39
  // glance, with the 4px left bar as the accent. bg-destructive/5 tint
@@ -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 }
@@ -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 }