@behavioral-agentic-design-system/core 0.39.1 → 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 (69) hide show
  1. package/package.json +8 -3
  2. package/scripts/a11y-lint.cjs +47 -6
  3. package/scripts/bads-components.mjs +118 -0
  4. package/scripts/build-tokens.cjs +133 -12
  5. package/scripts/check-stories.mjs +1 -1
  6. package/scripts/lint-component-source.mjs +100 -0
  7. package/scripts/lint-microanimation.mjs +267 -0
  8. package/scripts/size-audit.cjs +79 -0
  9. package/scripts/source-of-truth.cjs +58 -0
  10. package/scripts/ux-smoke.mjs +438 -0
  11. package/scripts/wcag-audit.cjs +49 -1
  12. package/src/api/layers/file.ts +1 -0
  13. package/src/app/preview/components/page.tsx +968 -0
  14. package/src/app/shell.tsx +11 -13
  15. package/src/components/customize/brand-mark-section.tsx +4 -2
  16. package/src/components/customize/design-controls.tsx +1 -1
  17. package/src/components/customize/discipline-section.tsx +3 -6
  18. package/src/components/customize/font-pickers.tsx +1 -1
  19. package/src/components/customize/letter-spacing.tsx +1 -1
  20. package/src/components/customize/save-bar.tsx +2 -2
  21. package/src/components/customize/theme-io.tsx +7 -7
  22. package/src/components/customize/type-scale.tsx +1 -1
  23. package/src/components/customize-tab.tsx +7 -4
  24. package/src/components/home-tab.tsx +3 -0
  25. package/src/components/ui/accordion.tsx +7 -0
  26. package/src/components/ui/alert.tsx +1 -0
  27. package/src/components/ui/announcement-bar.tsx +256 -0
  28. package/src/components/ui/badge.tsx +1 -0
  29. package/src/components/ui/callout.tsx +218 -0
  30. package/src/components/ui/chart.tsx +2 -14
  31. package/src/components/ui/color-picker.tsx +1 -1
  32. package/src/components/ui/format-relative-time.tsx +139 -0
  33. package/src/components/ui/grid.tsx +255 -0
  34. package/src/components/ui/icon.tsx +108 -0
  35. package/src/components/ui/index.ts +8 -0
  36. package/src/components/ui/page-header.tsx +63 -0
  37. package/src/components/ui/portal.tsx +111 -0
  38. package/src/components/ui/presence.tsx +172 -0
  39. package/src/components/ui/progress-stack.tsx +258 -0
  40. package/src/components/ui/select.tsx +89 -4
  41. package/src/components/ui/separator.tsx +1 -0
  42. package/src/components/ui/slider.tsx +83 -3
  43. package/src/components/ui/sparkline.tsx +2 -14
  44. package/src/components/ui/textarea.tsx +28 -1
  45. package/src/data/docs-index.ts +1 -0
  46. package/src/hooks/use-reduced-motion.ts +6 -0
  47. package/src/stories/Accordion.stories.tsx +59 -0
  48. package/src/stories/Alert.stories.tsx +3 -1
  49. package/src/stories/AnnouncementBar.stories.tsx +261 -0
  50. package/src/stories/Badge.stories.tsx +3 -0
  51. package/src/stories/Calendar.stories.tsx +1 -1
  52. package/src/stories/Callout.stories.tsx +219 -0
  53. package/src/stories/Chart.stories.tsx +4 -0
  54. package/src/stories/ColorPicker.stories.tsx +23 -0
  55. package/src/stories/FormatRelativeTime.stories.tsx +116 -0
  56. package/src/stories/Grid.stories.tsx +197 -0
  57. package/src/stories/Icon.stories.tsx +175 -0
  58. package/src/stories/MultiSelect.stories.tsx +1 -1
  59. package/src/stories/PageHeader.stories.tsx +102 -0
  60. package/src/stories/Portal.stories.tsx +189 -0
  61. package/src/stories/Presence.stories.tsx +228 -0
  62. package/src/stories/ProgressStack.stories.tsx +287 -0
  63. package/src/stories/Select.stories.tsx +25 -0
  64. package/src/stories/Separator.stories.tsx +3 -0
  65. package/src/stories/Slider.stories.tsx +54 -5
  66. package/src/stories/Sparkline.stories.tsx +3 -0
  67. package/src/stories/Textarea.stories.tsx +18 -0
  68. package/src/stories/story-groups.json +14 -5
  69. package/src/styles.css +133 -12
package/src/app/shell.tsx CHANGED
@@ -6,8 +6,8 @@ import { Sheet, SheetContent, SheetHeader, SheetTitle } from "@behavioral-agenti
6
6
  import { Button } from "@behavioral-agentic-design-system/core/components/ui/button";
7
7
  import {
8
8
  Sun, Moon, BookOpen, X, ExternalLink, Menu,
9
- House, Blocks, LayoutGrid, LayoutDashboard, SlidersHorizontal,
10
- Type, Shapes, FileText, Layers as LayersIcon, Activity, GitCommitHorizontal,
9
+ House, Blocks, LayoutGrid, LayoutDashboard,
10
+ Type, Shapes, FileText, Layers as LayersIcon, Activity, GitCommitHorizontal, SlidersHorizontal as StudioIcon,
11
11
  } from "lucide-react";
12
12
  import registry from "@/layer-5-component-registry/component-registry.json";
13
13
 
@@ -31,7 +31,7 @@ function GithubMark({ className }: { className?: string }) {
31
31
  );
32
32
  }
33
33
  import { brand } from "@/brand.config";
34
- import { CustomizeTab } from "@behavioral-agentic-design-system/core/components/customize-tab";
34
+ import Studio from "@/components/examples/studio/studio";
35
35
  import { LayersTab } from "@behavioral-agentic-design-system/core/components/layers-tab";
36
36
  import { HomeTab } from "@behavioral-agentic-design-system/core/components/home-tab";
37
37
  import { DocsTab } from "@behavioral-agentic-design-system/core/components/docs-tab";
@@ -224,10 +224,10 @@ export type ShellProps = {
224
224
  export const DEFAULT_TABS: ShellTab[] = [
225
225
  { value: "home", label: "Home", icon: House, render: ({ goToTab }) => <HomeTab onBrowseDocs={() => goToTab("docs")} onBrowseComponents={() => goToTab("components")} /> },
226
226
 
227
+ // Studio absorbs what Customize, Cards and Dashboard used to be: you tune a
228
+ // value and the specimens beside it repaint, instead of navigating to find out.
229
+ { value: "studio", label: "Studio", group: "build", icon: StudioIcon, render: () => <Studio /> },
227
230
  { value: "components", label: "Components", group: "build", icon: Blocks, count: COMPONENT_COUNT, render: ({ dark }) => <IframePreview dark={dark} src="/preview/components" title="Components preview" /> },
228
- { value: "cards", label: "Cards", group: "build", icon: LayoutGrid, render: ({ dark }) => <IframePreview dark={dark} src="/preview/cards" title="Cards preview" /> },
229
- { value: "dashboard", label: "Dashboard", group: "build", icon: LayoutDashboard, hidden: "md", render: ({ dark }) => <IframePreview dark={dark} src="/preview/dashboard" minWidth="1400px" title="Dashboard preview" /> },
230
- { value: "customize", label: "Customize", group: "build", icon: SlidersHorizontal, render: () => <CustomizeTab /> },
231
231
 
232
232
  // Typography was a route with no way to reach it — /preview/typography has
233
233
  // rendered fine and been unlinked. The Foundations group is where it belongs.
@@ -716,8 +716,8 @@ export function Shell({ tabs, defaultTab }: ShellProps) {
716
716
  documents under "Theme transition and sticky chrome", not the fix.
717
717
  The panel area scrolls inside itself, which is what keeps the rail
718
718
  out of sticky-chrome territory in the first place. */}
719
- <aside className="hidden w-60 shrink-0 flex-col border-r bg-card md:flex">
720
- <div className="flex h-14 shrink-0 items-center border-b px-4">
719
+ <aside className="hidden w-72 shrink-0 flex-col bg-card md:flex">
720
+ <div className="flex shrink-0 items-center px-4 py-3">
721
721
  <div className="flex items-center gap-2 min-w-0">
722
722
  {brand.logo?.lockup ? (
723
723
  // Full lockup slot: a brand whose identity is a combined
@@ -748,11 +748,9 @@ export function Shell({ tabs, defaultTab }: ShellProps) {
748
748
  (it is brand identity, not decoration) and truncate keeps
749
749
  an arbitrary-length fork tagline inside the rail. */}
750
750
  <span className="flex min-w-0 flex-col leading-tight">
751
- <span className="truncate text-base font-semibold">{brand.name}</span>
751
+ <span className="text-base font-semibold">{brand.name}</span>
752
752
  {brand.tagline ? (
753
- <span className="truncate text-xs text-muted-foreground" title={brand.tagline}>
754
- {brand.tagline}
755
- </span>
753
+ <span className="text-xs text-muted-foreground">{brand.tagline}</span>
756
754
  ) : null}
757
755
  </span>
758
756
  </>
@@ -787,7 +785,7 @@ export function Shell({ tabs, defaultTab }: ShellProps) {
787
785
  </TabsList>
788
786
  </nav>
789
787
 
790
- <div className="shrink-0 border-t p-3">
788
+ <div className="shrink-0 p-3">
791
789
  <div className="flex flex-wrap items-center gap-1.5 sm:gap-2 shrink-0">
792
790
  {/* Fork-configurable header links — set `headerLinks` in brand.config
793
791
  to add buttons (e.g. a link to a fork's prototypes site) without
@@ -143,7 +143,7 @@ export function BrandMarkSection() {
143
143
  <code className="font-mono text-xs">brand-mark.json</code>.
144
144
  </p>
145
145
 
146
- <div className="grid gap-6 lg:grid-cols-2">
146
+ <div className="grid gap-6 @2xl/panel:grid-cols-2">
147
147
  {/* Inputs column */}
148
148
  <div className="flex flex-col gap-4">
149
149
  <div className="flex flex-col gap-2">
@@ -235,7 +235,9 @@ function PreviewTile({ mode, svg }: { mode: "light" | "dark"; svg: string | null
235
235
  isLight ? "bg-white text-zinc-900" : "bg-zinc-950 text-zinc-50"
236
236
  }`}
237
237
  >
238
- <div className="flex items-center gap-4">
238
+ {/* wrap: this row is re-housed into Studio's ~400px controls column,
239
+ narrower than the full-width tab it was built for. */}
240
+ <div className="flex flex-wrap items-center gap-4">
239
241
  {/* 32px size — matches header rhythm */}
240
242
  <Mark size={32} svg={svg} mode={mode} />
241
243
  {/* 96px size — login/branded surfaces */}
@@ -132,7 +132,7 @@ export function DesignControlsPanel() {
132
132
  preview screen and persist on refresh.
133
133
  </p>
134
134
 
135
- <div className="grid grid-cols-1 lg:grid-cols-2 gap-x-10 gap-y-8">
135
+ <div className="grid grid-cols-1 @2xl/panel:grid-cols-2 gap-x-10 gap-y-8">
136
136
  <ControlRow
137
137
  label="Border Radius"
138
138
  description="Drives every rounded corner. sm/md/lg/xl scale from this base."
@@ -70,12 +70,9 @@ export function DisciplineSection() {
70
70
 
71
71
  return (
72
72
  <div>
73
- <h2 className="mb-2 text-2xl font-semibold tracking-tight">Discipline</h2>
74
- <p className="mb-5 max-w-prose text-sm text-muted-foreground">
75
- Which rule tree agents load for this work. Product covers app surfaces
76
- such as dashboards, forms and settings. Marketing covers expressive brand
77
- surfaces such as landing pages, email and campaigns. The accessibility
78
- and ethics floors load for both either way.
73
+ <h2 className="mb-2 text-base font-semibold">Discipline</h2>
74
+ <p className="mb-4 text-sm text-muted-foreground">
75
+ Which rule tree agents load. Both keep the accessibility and ethics floors.
79
76
  </p>
80
77
  <SegmentedControl
81
78
  value={discipline}
@@ -320,7 +320,7 @@ function FontCardGrid<K extends string>({
320
320
  }) {
321
321
  const keys = Object.keys(options) as K[];
322
322
  return (
323
- <div className="grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-3">
323
+ <div className="grid grid-cols-2 @lg/panel:grid-cols-3 @2xl/panel:grid-cols-4 @3xl/panel:grid-cols-5 gap-3">
324
324
  {keys.map((key) => {
325
325
  const opt = options[key];
326
326
  const isActive = key === active;
@@ -47,7 +47,7 @@ export function LetterSpacingPanel() {
47
47
  labels all retrack live as you slide.
48
48
  </p>
49
49
 
50
- <div className="grid grid-cols-1 lg:grid-cols-2 gap-x-10 gap-y-8 mb-10">
50
+ <div className="grid grid-cols-1 @2xl/panel:grid-cols-2 gap-x-10 gap-y-8 mb-10">
51
51
  <div className="space-y-3">
52
52
  <div className="flex items-baseline justify-between gap-3">
53
53
  <label className="text-sm font-semibold">Tracking</label>
@@ -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>
@@ -253,7 +253,7 @@ function ColorSection({
253
253
  <h4 className="text-base font-semibold">{title}</h4>
254
254
  {action}
255
255
  </div>
256
- <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">
257
257
  {children}
258
258
  </div>
259
259
  </div>
@@ -640,7 +640,7 @@ function PrimaryColorPicker() {
640
640
  </div>
641
641
  )}
642
642
 
643
- <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">
644
644
  {keys.map((key) => {
645
645
  const opt = options[key];
646
646
  const isCustom = key in customs;
@@ -673,7 +673,7 @@ function PrimaryColorPicker() {
673
673
  );
674
674
  }
675
675
 
676
- function ColorPalette() {
676
+ export function ColorPalette() {
677
677
  const { options, addCustomSilent } = useGlobalPrimaryColor();
678
678
  const { overrides, updateOverride, remove } = useTokenOverrides();
679
679
  const swatchCtx = useMemo<TokenSwatchPickerCtx>(
@@ -683,7 +683,10 @@ function ColorPalette() {
683
683
 
684
684
  return (
685
685
  <TokenSwatchPicker.Provider value={swatchCtx}>
686
- <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">
687
690
  <ThemeIO />
688
691
  <PrimaryColorPicker />
689
692
  <BrandMarkSection />
@@ -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: