@behavioral-agentic-design-system/core 0.27.0 → 0.29.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 (113) hide show
  1. package/package.json +5 -5
  2. package/scripts/a11y-lint.cjs +78 -9
  3. package/scripts/build-tokens.cjs +273 -15
  4. package/scripts/wcag-audit.cjs +37 -7
  5. package/src/api/layers/file.ts +1 -0
  6. package/src/app/font-ready.tsx +6 -5
  7. package/src/app/layout.tsx +54 -3
  8. package/src/app/preview/components/page.tsx +5735 -2500
  9. package/src/app/preview/layout.tsx +4 -1
  10. package/src/app/preview/showcase-filter.tsx +66 -0
  11. package/src/app/preview/tab-replay.tsx +63 -0
  12. package/src/app/shell.tsx +91 -18
  13. package/src/components/customize/save-bar.tsx +19 -6
  14. package/src/components/docs-tab.tsx +36 -24
  15. package/src/components/layers-tab.tsx +37 -5
  16. package/src/components/ui/ai-badge.tsx +74 -0
  17. package/src/components/ui/alert.tsx +12 -0
  18. package/src/components/ui/badge.tsx +19 -0
  19. package/src/components/ui/chat-bubble.tsx +298 -0
  20. package/src/components/ui/chat-marker.tsx +120 -0
  21. package/src/components/ui/checkbox.tsx +9 -1
  22. package/src/components/ui/clipboard.tsx +291 -0
  23. package/src/components/ui/close-button.tsx +71 -0
  24. package/src/components/ui/combobox.tsx +62 -3
  25. package/src/components/ui/container.tsx +65 -0
  26. package/src/components/ui/copy-button.tsx +5 -1
  27. package/src/components/ui/data-table.tsx +388 -0
  28. package/src/components/ui/date-field.tsx +368 -0
  29. package/src/components/ui/drawer.tsx +334 -0
  30. package/src/components/ui/file-button.tsx +145 -0
  31. package/src/components/ui/floating-indicator.tsx +217 -0
  32. package/src/components/ui/focus-trap.tsx +184 -0
  33. package/src/components/ui/format-byte.tsx +113 -0
  34. package/src/components/ui/index.ts +28 -0
  35. package/src/components/ui/input.tsx +38 -3
  36. package/src/components/ui/keyboard-shortcut.tsx +146 -0
  37. package/src/components/ui/loading-dots.tsx +99 -0
  38. package/src/components/ui/mark.tsx +69 -0
  39. package/src/components/ui/month-picker.tsx +296 -0
  40. package/src/components/ui/multi-select.tsx +15 -13
  41. package/src/components/ui/nav-link.tsx +200 -0
  42. package/src/components/ui/navigation-rail.tsx +256 -0
  43. package/src/components/ui/notification.tsx +20 -0
  44. package/src/components/ui/password-input.tsx +34 -1
  45. package/src/components/ui/progress.tsx +15 -1
  46. package/src/components/ui/prose.tsx +62 -0
  47. package/src/components/ui/result.tsx +151 -0
  48. package/src/components/ui/rolling-number.tsx +201 -0
  49. package/src/components/ui/simple-grid.tsx +110 -0
  50. package/src/components/ui/skeleton.tsx +52 -3
  51. package/src/components/ui/squircle.tsx +274 -0
  52. package/src/components/ui/stack.tsx +105 -0
  53. package/src/components/ui/status-badge.tsx +93 -0
  54. package/src/components/ui/tabs.tsx +34 -7
  55. package/src/components/ui/tag.tsx +46 -5
  56. package/src/components/ui/theme-icon.tsx +138 -0
  57. package/src/components/ui/timeline.tsx +27 -10
  58. package/src/components/ui/tooltip.tsx +12 -1
  59. package/src/components/ui/tree-select.tsx +386 -0
  60. package/src/components/ui/typing-indicator.tsx +2 -2
  61. package/src/components/ui/word-rotate.tsx +6 -1
  62. package/src/components/ui/year-picker.tsx +307 -0
  63. package/src/data/docs-index.ts +10 -0
  64. package/src/hooks/use-global-primary-color.ts +57 -6
  65. package/src/stories/AiBadge.stories.tsx +67 -0
  66. package/src/stories/Alert.stories.tsx +31 -1
  67. package/src/stories/Badge.stories.tsx +63 -6
  68. package/src/stories/ChatBubble.stories.tsx +222 -0
  69. package/src/stories/ChatMarker.stories.tsx +59 -0
  70. package/src/stories/Checkbox.stories.tsx +5 -0
  71. package/src/stories/Clipboard.stories.tsx +136 -0
  72. package/src/stories/CloseButton.stories.tsx +65 -0
  73. package/src/stories/Combobox.stories.tsx +74 -3
  74. package/src/stories/Container.stories.tsx +134 -0
  75. package/src/stories/CopyButton.stories.tsx +2 -0
  76. package/src/stories/DataTable.stories.tsx +271 -0
  77. package/src/stories/DateField.stories.tsx +114 -0
  78. package/src/stories/Drawer.stories.tsx +211 -0
  79. package/src/stories/FileButton.stories.tsx +117 -0
  80. package/src/stories/FloatingIndicator.stories.tsx +343 -0
  81. package/src/stories/FocusTrap.stories.tsx +218 -0
  82. package/src/stories/FormatByte.stories.tsx +142 -0
  83. package/src/stories/Input.stories.tsx +91 -0
  84. package/src/stories/KeyboardShortcut.stories.tsx +87 -0
  85. package/src/stories/LoadingDots.stories.tsx +73 -0
  86. package/src/stories/Mark.stories.tsx +84 -0
  87. package/src/stories/MonthPicker.stories.tsx +99 -0
  88. package/src/stories/MultiSelect.stories.tsx +3 -1
  89. package/src/stories/NavLink.stories.tsx +213 -0
  90. package/src/stories/NavigationRail.stories.tsx +413 -0
  91. package/src/stories/Notification.stories.tsx +53 -0
  92. package/src/stories/PasswordInput.stories.tsx +21 -0
  93. package/src/stories/Progress.stories.tsx +38 -0
  94. package/src/stories/Prose.stories.tsx +232 -0
  95. package/src/stories/Result.stories.tsx +145 -0
  96. package/src/stories/RollingNumber.stories.tsx +226 -0
  97. package/src/stories/SimpleGrid.stories.tsx +130 -0
  98. package/src/stories/Skeleton.stories.tsx +62 -1
  99. package/src/stories/Squircle.stories.tsx +127 -0
  100. package/src/stories/Stack.stories.tsx +139 -0
  101. package/src/stories/StatusBadge.stories.tsx +125 -0
  102. package/src/stories/Tabs.stories.tsx +56 -1
  103. package/src/stories/Tag.stories.tsx +31 -0
  104. package/src/stories/ThemeIcon.stories.tsx +97 -0
  105. package/src/stories/Timeline.stories.tsx +69 -0
  106. package/src/stories/Tooltip.stories.tsx +18 -0
  107. package/src/stories/TreeSelect.stories.tsx +222 -0
  108. package/src/stories/TypingIndicator.stories.tsx +1 -0
  109. package/src/stories/WordRotate.stories.tsx +1 -0
  110. package/src/stories/YearPicker.stories.tsx +100 -0
  111. package/src/styles.css +289 -15
  112. package/src/tokens.json +96 -1
  113. package/LICENSE +0 -21
@@ -0,0 +1,105 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import { cva, type VariantProps } from "class-variance-authority";
5
+ import { cn } from "../../lib/utils";
6
+
7
+ // ─── Shared variants ──────────────────────────────────────────────────────────
8
+
9
+ const layoutVariants = cva("flex", {
10
+ variants: {
11
+ /**
12
+ * Gap between child elements. Maps to Tailwind gap utilities keyed to the
13
+ * BADS spacing scale (gap-0 / 1 / 2 / 4 / 6 / 8 → 0 / 4px / 8px / 16px /
14
+ * 24px / 32px). Default: "md" for Stack, "sm" for Group.
15
+ */
16
+ gap: {
17
+ none: "gap-0",
18
+ xs: "gap-1",
19
+ sm: "gap-2",
20
+ md: "gap-4",
21
+ lg: "gap-6",
22
+ xl: "gap-8",
23
+ },
24
+ /**
25
+ * Cross-axis alignment (align-items). Default: "stretch" for Stack so
26
+ * children fill the container width; "center" for Group so inline items
27
+ * baseline-align naturally.
28
+ */
29
+ align: {
30
+ start: "items-start",
31
+ center: "items-center",
32
+ end: "items-end",
33
+ baseline: "items-baseline",
34
+ stretch: "items-stretch",
35
+ },
36
+ /**
37
+ * Main-axis distribution (justify-content).
38
+ */
39
+ justify: {
40
+ start: "justify-start",
41
+ center: "justify-center",
42
+ end: "justify-end",
43
+ between: "justify-between",
44
+ around: "justify-around",
45
+ evenly: "justify-evenly",
46
+ },
47
+ },
48
+ defaultVariants: {
49
+ gap: "md",
50
+ align: "stretch",
51
+ justify: "start",
52
+ },
53
+ });
54
+
55
+ // ─── Stack ─────────────────────────────────────────────────────────────────────
56
+ //
57
+ // Vertical flex column. Replaces boilerplate `<div className="flex flex-col gap-4">`.
58
+ // Children fill the container width by default (align="stretch").
59
+
60
+ export interface StackProps
61
+ extends React.HTMLAttributes<HTMLDivElement>,
62
+ VariantProps<typeof layoutVariants> {}
63
+
64
+ export const Stack = React.forwardRef<HTMLDivElement, StackProps>(
65
+ ({ className, gap, align, justify, ...props }, ref) => (
66
+ <div
67
+ ref={ref}
68
+ data-slot="stack"
69
+ className={cn("flex flex-col", layoutVariants({ gap, align, justify }), className)}
70
+ {...props}
71
+ />
72
+ )
73
+ );
74
+ Stack.displayName = "Stack";
75
+
76
+ // ─── Group ─────────────────────────────────────────────────────────────────────
77
+ //
78
+ // Horizontal flex row. Replaces boilerplate `<div className="flex flex-row flex-wrap gap-2 items-center">`.
79
+ // Items wrap by default; set wrap={false} for a strict single-line row.
80
+ // align defaults to "center" so inline items (tags, buttons, icons) sit on the
81
+ // same baseline without extra class wiring.
82
+
83
+ export interface GroupProps
84
+ extends React.HTMLAttributes<HTMLDivElement>,
85
+ VariantProps<typeof layoutVariants> {
86
+ /** Wrap items when the container is full. Default: true. */
87
+ wrap?: boolean;
88
+ }
89
+
90
+ export const Group = React.forwardRef<HTMLDivElement, GroupProps>(
91
+ ({ className, gap = "sm", align = "center", justify, wrap = true, ...props }, ref) => (
92
+ <div
93
+ ref={ref}
94
+ data-slot="group"
95
+ className={cn(
96
+ "flex flex-row",
97
+ wrap ? "flex-wrap" : "flex-nowrap",
98
+ layoutVariants({ gap, align, justify }),
99
+ className
100
+ )}
101
+ {...props}
102
+ />
103
+ )
104
+ );
105
+ Group.displayName = "Group";
@@ -0,0 +1,93 @@
1
+ import * as React from "react"
2
+
3
+ import { cn } from "../../lib/utils"
4
+
5
+ type StatusVariant =
6
+ | "active"
7
+ | "pending"
8
+ | "processing"
9
+ | "error"
10
+ | "offline"
11
+ | "warning"
12
+
13
+ const STATUS_LABELS: Record<StatusVariant, string> = {
14
+ active: "Active",
15
+ pending: "Pending",
16
+ processing: "Processing",
17
+ error: "Error",
18
+ offline: "Offline",
19
+ warning: "Warning",
20
+ }
21
+
22
+ // Dot color maps directly to semantic tokens. Text stays text-foreground so
23
+ // the 7:1 AAA floor is unconditional — the dot is the non-text signal (3:1).
24
+ const DOT_COLORS: Record<StatusVariant, string> = {
25
+ active: "bg-success",
26
+ pending: "bg-warning",
27
+ processing: "bg-info",
28
+ error: "bg-destructive",
29
+ offline: "bg-muted-foreground",
30
+ warning: "bg-warning",
31
+ }
32
+
33
+ const DOT_SIZES = {
34
+ sm: "size-1.5",
35
+ default: "size-2",
36
+ lg: "size-2.5",
37
+ } as const
38
+
39
+ const TEXT_SIZES = {
40
+ sm: "text-xs",
41
+ default: "text-sm",
42
+ lg: "text-base",
43
+ } as const
44
+
45
+ type StatusBadgeProps = React.ComponentProps<"span"> & {
46
+ /** The semantic status — drives dot color and default label. */
47
+ status: StatusVariant
48
+ /** Override the default capitalized status name. */
49
+ label?: string
50
+ /** Scales dot and text together. */
51
+ size?: "sm" | "default" | "lg"
52
+ }
53
+
54
+ function StatusBadge({
55
+ className,
56
+ status,
57
+ label,
58
+ size = "default",
59
+ ...props
60
+ }: StatusBadgeProps) {
61
+ const displayLabel = label ?? STATUS_LABELS[status]
62
+
63
+ return (
64
+ <span
65
+ data-slot="status-badge"
66
+ data-status={status}
67
+ className={cn(
68
+ "inline-flex items-center gap-1.5 font-medium",
69
+ TEXT_SIZES[size],
70
+ className
71
+ )}
72
+ {...props}
73
+ >
74
+ {/* aria-hidden: dot color is non-text signal only; the label carries a11y meaning */}
75
+ <span
76
+ aria-hidden
77
+ data-slot="status-dot"
78
+ className={cn(
79
+ "shrink-0 rounded-full",
80
+ DOT_SIZES[size],
81
+ DOT_COLORS[status],
82
+ // processing: pulsing dot signals in-flight work. The base layer's
83
+ // prefers-reduced-motion rule stills it automatically.
84
+ status === "processing" && "animate-pulse"
85
+ )}
86
+ />
87
+ {displayLabel}
88
+ </span>
89
+ )
90
+ }
91
+
92
+ export { StatusBadge }
93
+ export type { StatusVariant }
@@ -28,12 +28,15 @@ function Tabs({
28
28
  }
29
29
 
30
30
  const tabsListVariants = cva(
31
- "group/tabs-list inline-flex h-10 w-fit items-center justify-center rounded-md p-1 text-muted-foreground group-data-[orientation=vertical]/tabs:h-fit group-data-[orientation=vertical]/tabs:flex-col data-[variant=line]:rounded-none",
31
+ "group/tabs-list inline-flex h-10 w-fit items-center justify-center rounded-md p-1 text-muted-foreground group-data-[orientation=vertical]/tabs:h-fit group-data-[orientation=vertical]/tabs:flex-col data-[variant=line]:rounded-none data-[variant=pill]:rounded-none data-[variant=pill]:p-0",
32
32
  {
33
33
  variants: {
34
34
  variant: {
35
35
  default: "bg-muted",
36
36
  line: "gap-1 bg-transparent",
37
+ // Each trigger is an independently-shaped pill; the list is just
38
+ // a flex row with a gap — no shared container background.
39
+ pill: "gap-1.5 bg-transparent",
37
40
  },
38
41
  },
39
42
  defaultVariants: {
@@ -73,11 +76,30 @@ function TabsList({
73
76
  el.scrollLeft + el.clientWidth < el.scrollWidth - 1
74
77
  el.toggleAttribute("data-overflowing", overflowing)
75
78
  }
76
- // Keep the active trigger visible when the selection changes.
79
+ // Keep the active trigger visible when the selection changes — but scroll
80
+ // ONLY this list's own horizontal overflow, never Element.scrollIntoView.
81
+ // scrollIntoView also scrolls vertical ancestors (the whole page) to bring
82
+ // the trigger into the viewport, so a scrollable tab row below the fold
83
+ // yanks the entire page down to itself on mount (corrections.md #012, the
84
+ // "Tabs & Dialog" recurrence). Same rule the Carousel documents. We nudge
85
+ // el.scrollLeft directly, which can only move this row horizontally.
77
86
  const scrollActiveIntoView = () => {
78
- el
79
- .querySelector<HTMLElement>('[data-slot="tabs-trigger"][data-state="active"]')
80
- ?.scrollIntoView({ inline: "nearest", block: "nearest", behavior: "smooth" })
87
+ const active = el.querySelector<HTMLElement>(
88
+ '[data-slot="tabs-trigger"][data-state="active"]'
89
+ )
90
+ if (!active) return
91
+ const pad = 16
92
+ const viewLeft = el.scrollLeft
93
+ const viewRight = viewLeft + el.clientWidth
94
+ const aLeft = active.offsetLeft
95
+ const aRight = aLeft + active.offsetWidth
96
+ let next = viewLeft
97
+ if (aLeft < viewLeft + pad) next = aLeft - pad
98
+ else if (aRight > viewRight - pad) next = aRight - el.clientWidth + pad
99
+ next = Math.max(0, Math.min(next, el.scrollWidth - el.clientWidth))
100
+ if (Math.abs(next - viewLeft) > 1) {
101
+ el.scrollTo({ left: next, behavior: "smooth" })
102
+ }
81
103
  }
82
104
 
83
105
  update()
@@ -125,7 +147,12 @@ function TabsTrigger({
125
147
  // Active state uses --primary / --primary-foreground so the selected tab
126
148
  // always reflects the fork's brand color. bg-accent broke forks where
127
149
  // --accent is a dark brand color (e.g. plum), rendering the pill illegibly dark.
128
- "inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-xs font-medium text-muted-foreground hover:text-foreground ring-offset-background transition-colors focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-primary data-[state=active]:text-primary-foreground data-[state=active]:shadow-xs",
150
+ // Base layout and interactive states shared across all variants.
151
+ // `group-data-[variant=pill]/tabs-list:*` overrides shape + active
152
+ // coloring when the parent TabsList is in pill mode: rounded-full
153
+ // container with a softer brand tint (bg-primary/10 text-primary)
154
+ // instead of the solid filled slab of the default variant.
155
+ "inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-xs font-medium text-muted-foreground hover:text-foreground ring-offset-background transition-colors focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-primary data-[state=active]:text-primary-foreground data-[state=active]:shadow-xs group-data-[variant=pill]/tabs-list:rounded-full group-data-[variant=pill]/tabs-list:px-4 group-data-[variant=pill]/tabs-list:data-[state=active]:shadow-none group-data-[variant=pill]/tabs-list:data-[state=active]:bg-primary/10 group-data-[variant=pill]/tabs-list:data-[state=active]:text-primary",
129
156
  className
130
157
  )}
131
158
  {...props}
@@ -140,7 +167,7 @@ function TabsContent({
140
167
  return (
141
168
  <TabsPrimitive.Content
142
169
  data-slot="tabs-content"
143
- className={cn("mt-2 ring-offset-background focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2", className)}
170
+ className={cn("mt-2 ring-offset-background focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 scrollbar-gutter-stable", className)}
144
171
  {...props}
145
172
  />
146
173
  )
@@ -3,39 +3,80 @@ import { X } from "lucide-react"
3
3
  import { cn } from "../../lib/utils"
4
4
 
5
5
  const tagVariants = cva(
6
- "inline-flex items-center gap-1 rounded-full px-3 py-1 text-sm font-medium transition-colors",
6
+ "inline-flex items-center rounded-full font-medium transition-colors",
7
7
  {
8
8
  variants: {
9
9
  variant: {
10
10
  default: "bg-primary text-primary-foreground",
11
+ // TODO(token-discipline): success/warning/error/info use hardcoded
12
+ // Tailwind palette utilities rather than semantic tokens. Pre-existing
13
+ // issue kept byte-identical here (fixing it changes existing rendering);
14
+ // migrate to semantic tokens in a dedicated pass.
11
15
  success: "bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-100",
12
16
  warning: "bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-100",
13
17
  error: "bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-100",
14
18
  info: "bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-100",
15
19
  },
20
+ size: {
21
+ xs: "gap-0.5 px-1.5 py-0.5 text-xs",
22
+ sm: "gap-1 px-2 py-0.5 text-xs",
23
+ md: "gap-1 px-3 py-1 text-sm",
24
+ lg: "gap-1.5 px-4 py-1.5 text-sm font-semibold",
25
+ },
16
26
  },
17
27
  defaultVariants: {
18
28
  variant: "default",
29
+ size: "md",
19
30
  },
20
31
  }
21
32
  )
22
33
 
34
+ // Close-button scaling per size. At xs/sm the icon drops to size-3 (12px) and
35
+ // the button carries an explicit 20px (min-h-5/min-w-5) hit area — larger than
36
+ // the bare 16px icon target md ships today, but still below the 44px SC 2.5.5
37
+ // Enhanced floor. Known, documented exception (mirrors the registry entry's
38
+ // targetSize note): Tag is passive display chrome (metadata labels,
39
+ // notification tags), not a flow-changing CTA, so the CTA size contract does
40
+ // not apply. Where tags are user-managed on touch, provide a list-level
41
+ // removal path.
42
+ const closeButtonBySize = {
43
+ xs: { button: "ml-0.5 flex min-h-5 min-w-5 items-center justify-center", icon: "size-3" },
44
+ sm: { button: "ml-0.5 flex min-h-5 min-w-5 items-center justify-center", icon: "size-3" },
45
+ md: { button: "ml-1", icon: "size-4" },
46
+ lg: { button: "ml-1", icon: "size-4" },
47
+ } as const
48
+
23
49
  interface TagProps extends React.ComponentProps<"div">, VariantProps<typeof tagVariants> {
24
50
  label: string
25
51
  onClose?: () => void
26
52
  }
27
53
 
28
- function Tag({ className, variant, label, onClose, ...props }: TagProps) {
54
+ function Tag({ className, variant, size, label, onClose, style, ...props }: TagProps) {
55
+ const resolvedSize = size ?? "md"
56
+ const closeButton = closeButtonBySize[resolvedSize]
29
57
  return (
30
- <div className={cn(tagVariants({ variant }), className)} {...props}>
58
+ <div
59
+ data-size={resolvedSize}
60
+ className={cn(tagVariants({ variant, size }), className)}
61
+ style={{
62
+ transitionDuration: "var(--duration-fast)",
63
+ transitionTimingFunction: "var(--ease-out)",
64
+ ...style,
65
+ }}
66
+ {...props}
67
+ >
31
68
  <span>{label}</span>
32
69
  {onClose && (
33
70
  <button
34
71
  onClick={onClose}
35
- className="ml-1 hover:opacity-70"
72
+ className={cn("transition-opacity hover:opacity-70", closeButton.button)}
73
+ style={{
74
+ transitionDuration: "var(--duration-fast)",
75
+ transitionTimingFunction: "var(--ease-out)",
76
+ }}
36
77
  aria-label="Remove tag"
37
78
  >
38
- <X className="size-4" />
79
+ <X className={closeButton.icon} strokeWidth={1.5} />
39
80
  </button>
40
81
  )}
41
82
  </div>
@@ -0,0 +1,138 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import { MoonIcon, SunIcon } from "lucide-react"
5
+
6
+ import { cn } from "../../lib/utils"
7
+
8
+ export interface ThemeIconProps
9
+ extends Omit<React.ComponentProps<"span">, "children"> {
10
+ /** Size in pixels for both icons. Default 16. */
11
+ size?: number
12
+ /** Override the icon to show in light mode. Default: <Sun> */
13
+ lightIcon?: React.ReactNode
14
+ /** Override the icon to show in dark mode. Default: <Moon> */
15
+ darkIcon?: React.ReactNode
16
+ /** strokeWidth forwarded to the default Sun/Moon icons. Default 1.5 */
17
+ strokeWidth?: number
18
+ }
19
+
20
+ type ResolvedTheme = "light" | "dark"
21
+
22
+ const DARK_QUERY = "(prefers-color-scheme: dark)"
23
+
24
+ /**
25
+ * Resolve the active theme from the document, in precedence order:
26
+ *
27
+ * 1. An explicit `data-theme="dark" | "light"` stamp on `<html>` (the
28
+ * three-state theme contract — an explicit user choice stamps the
29
+ * attribute; "system" stamps nothing).
30
+ * 2. The `dark` class on `<html>` — how BADS' own shell (and most Tailwind
31
+ * consumers) flip modes.
32
+ * 3. The `prefers-color-scheme` media query as the system-preference
33
+ * fallback when nothing is stamped.
34
+ */
35
+ function readTheme(): ResolvedTheme {
36
+ const root = document.documentElement
37
+ const attr = root.getAttribute("data-theme")
38
+ if (attr === "dark") return "dark"
39
+ if (attr === "light") return "light"
40
+ if (root.classList.contains("dark")) return "dark"
41
+ if (
42
+ typeof window.matchMedia === "function" &&
43
+ window.matchMedia(DARK_QUERY).matches
44
+ ) {
45
+ return "dark"
46
+ }
47
+ return "light"
48
+ }
49
+
50
+ /**
51
+ * Subscribe to every signal that can change the resolved theme: the `class`
52
+ * and `data-theme` attributes on `<html>` (MutationObserver) and the system
53
+ * color-scheme media query.
54
+ */
55
+ function subscribeToTheme(onChange: () => void): () => void {
56
+ const observer = new MutationObserver(onChange)
57
+ observer.observe(document.documentElement, {
58
+ attributes: true,
59
+ attributeFilter: ["class", "data-theme"],
60
+ })
61
+ const mql =
62
+ typeof window.matchMedia === "function"
63
+ ? window.matchMedia(DARK_QUERY)
64
+ : null
65
+ mql?.addEventListener?.("change", onChange)
66
+ return () => {
67
+ observer.disconnect()
68
+ mql?.removeEventListener?.("change", onChange)
69
+ }
70
+ }
71
+
72
+ // On the server there is no document to read — resolve to null and render a
73
+ // neutral placeholder (both icons at opacity 0, container size reserved) so
74
+ // hydration never flashes the wrong icon.
75
+ const getServerTheme = (): ResolvedTheme | null => null
76
+
77
+ // Token-driven crossfade timing — the CSS vars resolve at runtime against
78
+ // :root in the generated styles.css, so token changes propagate via
79
+ // `pnpm build:tokens`. (The base layer's prefers-reduced-motion override
80
+ // collapses the transition to 0.01ms for users who opt out.)
81
+ const crossfadeStyle: React.CSSProperties = {
82
+ transitionDuration: "var(--duration-base)",
83
+ transitionTimingFunction: "var(--ease-spring)",
84
+ }
85
+
86
+ /**
87
+ * Renders the icon for the active theme mode — a sun in light mode, a moon in
88
+ * dark mode — crossfading between the two with a contained spring rotation
89
+ * when the theme flips. The reusable atom inside a ThemeToggle: it only reads
90
+ * the theme, it never sets it, and it is decorative (`aria-hidden`) — the
91
+ * wrapping control must carry its own accessible label.
92
+ */
93
+ function ThemeIcon({
94
+ size = 16,
95
+ lightIcon,
96
+ darkIcon,
97
+ strokeWidth = 1.5,
98
+ className,
99
+ style,
100
+ ...props
101
+ }: ThemeIconProps) {
102
+ const theme = React.useSyncExternalStore(
103
+ subscribeToTheme,
104
+ readTheme,
105
+ getServerTheme,
106
+ )
107
+
108
+ const layerClass = (active: boolean, exitRotation: string) =>
109
+ cn(
110
+ "absolute inset-0 flex items-center justify-center transition-[opacity,transform]",
111
+ active ? "rotate-0 scale-100 opacity-100" : cn("scale-75 opacity-0", exitRotation),
112
+ )
113
+
114
+ return (
115
+ <span
116
+ data-slot="theme-icon"
117
+ data-resolved-theme={theme ?? "pending"}
118
+ aria-hidden="true"
119
+ {...props}
120
+ className={cn(
121
+ "relative inline-flex shrink-0 items-center justify-center align-middle",
122
+ className,
123
+ )}
124
+ // Runtime-numeric sizing (like Lucide's own `size` prop), not a design
125
+ // token — the icon box must match whatever pixel size the caller picked.
126
+ style={{ width: size, height: size, ...style }}
127
+ >
128
+ <span className={layerClass(theme === "light", "-rotate-90")} style={crossfadeStyle}>
129
+ {lightIcon ?? <SunIcon size={size} strokeWidth={strokeWidth} />}
130
+ </span>
131
+ <span className={layerClass(theme === "dark", "rotate-90")} style={crossfadeStyle}>
132
+ {darkIcon ?? <MoonIcon size={size} strokeWidth={strokeWidth} />}
133
+ </span>
134
+ </span>
135
+ )
136
+ }
137
+
138
+ export { ThemeIcon }
@@ -9,7 +9,7 @@ import { cn } from "../../lib/utils";
9
9
 
10
10
  export type TimelineStatus = "default" | "complete" | "active" | "pending";
11
11
 
12
- export type TimelineOrientation = "vertical" | "alternate";
12
+ export type TimelineOrientation = "vertical" | "alternate" | "horizontal";
13
13
 
14
14
  /**
15
15
  * Orientation flows from the Timeline root to each TimelineItem via context so
@@ -54,6 +54,10 @@ export interface TimelineProps extends React.HTMLAttributes<HTMLOListElement> {
54
54
  * alternating columns don't fit. Alternation is CSS-only — the `<ol>`/`<li>`
55
55
  * DOM and reading order stay top-to-bottom for screen readers and keyboard
56
56
  * users regardless of orientation.
57
+ * - `"horizontal"` — items arranged in a horizontal row with dots at the top
58
+ * and content below. A connector line runs through all dot centers. Scrolls
59
+ * horizontally when items overflow the container. Reduced-motion safe via
60
+ * the base-layer prefers-reduced-motion rule.
57
61
  */
58
62
  orientation?: TimelineOrientation;
59
63
  }
@@ -68,8 +72,14 @@ export function Timeline({
68
72
  <TimelineOrientationContext.Provider value={orientation}>
69
73
  <ol
70
74
  data-slot="timeline"
71
- data-orientation={orientation === "alternate" ? "alternate" : undefined}
72
- className={cn("relative space-y-0", className)}
75
+ data-orientation={orientation !== "vertical" ? orientation : undefined}
76
+ className={cn(
77
+ "relative",
78
+ orientation === "horizontal"
79
+ ? "flex flex-row items-start overflow-x-auto"
80
+ : "space-y-0",
81
+ className
82
+ )}
73
83
  {...props}
74
84
  >
75
85
  {children}
@@ -123,18 +133,21 @@ export function TimelineItem({
123
133
 
124
134
  // "alternate" repositions dot/connector onto a centered spine and flips the
125
135
  // content column per :nth-child odd/even — CSS-only, gated on md:+ so narrow
126
- // viewports keep the vertical layout. When "vertical" (the default), every
127
- // conditional below is false and the rendered output is identical to
136
+ // viewports keep the vertical layout. "horizontal" switches to a flex-row
137
+ // layout with dots centered above content. When "vertical" (the default),
138
+ // every conditional below is false and the rendered output is identical to
128
139
  // previous releases.
129
140
  const orientation = React.useContext(TimelineOrientationContext);
130
141
  const alternate = orientation === "alternate";
142
+ const horizontal = orientation === "horizontal";
131
143
 
132
144
  return (
133
145
  <li
134
146
  data-slot="timeline-item"
135
147
  data-status={status}
136
148
  className={cn(
137
- "group relative pb-6 pl-8 last:pb-0",
149
+ "group relative",
150
+ horizontal ? "pt-8 flex-1" : "pb-6 pl-8 last:pb-0",
138
151
  alternate && "md:pl-0",
139
152
  className
140
153
  )}
@@ -146,10 +159,12 @@ export function TimelineItem({
146
159
  aria-hidden
147
160
  data-slot="timeline-connector"
148
161
  className={cn(
149
- "absolute left-[9px] top-5 bottom-0 w-px",
150
162
  "group-last:hidden",
163
+ horizontal
164
+ ? "absolute left-0 right-0 top-[14px] h-px"
165
+ : "absolute left-[9px] top-5 bottom-0 w-px",
151
166
  status === "pending" ? "bg-border/30" : "bg-border",
152
- alternate && "md:left-1/2 md:-translate-x-1/2"
167
+ !horizontal && alternate && "md:left-1/2 md:-translate-x-1/2"
153
168
  )}
154
169
  style={{
155
170
  transitionProperty: "background-color",
@@ -164,7 +179,8 @@ export function TimelineItem({
164
179
  data-slot="timeline-dot"
165
180
  className={cn(
166
181
  dotVariants({ status }),
167
- alternate && "md:left-1/2 md:-translate-x-1/2"
182
+ horizontal && "left-1/2 -translate-x-1/2",
183
+ !horizontal && alternate && "md:left-1/2 md:-translate-x-1/2"
168
184
  )}
169
185
  style={{
170
186
  transitionProperty: "background-color, border-color",
@@ -181,7 +197,8 @@ export function TimelineItem({
181
197
  data-slot="timeline-content"
182
198
  className={cn(
183
199
  "min-w-0 pt-0.5",
184
- alternate &&
200
+ horizontal && "text-center",
201
+ !horizontal && alternate &&
185
202
  "md:w-1/2 md:group-odd:pr-8 md:group-odd:text-right md:group-even:ml-auto md:group-even:pl-8"
186
203
  )}
187
204
  >
@@ -37,7 +37,18 @@ function TooltipContent({
37
37
  children,
38
38
  ...props
39
39
  }: React.ComponentProps<typeof TooltipPrimitive.Content>) {
40
- // See use-portal-theme-class.ts.
40
+ // INVERTED SURFACE — read before styling children. TooltipContent is
41
+ // deliberately inverted (`bg-foreground text-background`) so the box reads as
42
+ // solid high-contrast in both light and dark mode. That inversion is a trap
43
+ // for consumer children: any normal-surface semantic token used inside — most
44
+ // commonly `text-muted-foreground` — is calibrated to pair against
45
+ // `--background`/`--muted`, but here it renders against `--foreground` (now
46
+ // the box's background), collapsing to ~2:1 and failing WCAG. For de-emphasized
47
+ // text inside a tooltip, use `text-background/70`–`/80` (measures AAA against
48
+ // the inverted surface); for hairlines use `border-background/20`, not
49
+ // `border-border`. Same class of bug as the portal-scope rule below, but here
50
+ // the surface itself is inverted, so even ordinary fork-local tokens misfire.
51
+ // See use-portal-theme-class.ts for the portal-scope mechanism.
41
52
  const portalThemeClass = usePortalThemeClass()
42
53
  return (
43
54
  <TooltipPrimitive.Portal>