@behavioral-agentic-design-system/core 0.42.0 → 0.47.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 (314) hide show
  1. package/package.json +38 -8
  2. package/scripts/a11y-lint.cjs +101 -14
  3. package/scripts/bads-sync.mjs +1 -1
  4. package/scripts/build-tokens.cjs +122 -7
  5. package/scripts/check-dark-contrast.mjs +204 -0
  6. package/scripts/check-flush-edges.mjs +245 -0
  7. package/scripts/check-spec.mjs +73 -0
  8. package/scripts/deal-directions.mjs +186 -0
  9. package/scripts/design-system-advisory/README.md +239 -0
  10. package/scripts/design-system-advisory/check-copy-punctuation.mjs +44 -0
  11. package/scripts/design-system-advisory/check-even-padding.mjs +35 -0
  12. package/scripts/design-system-advisory/check-hand-built-button.mjs +46 -0
  13. package/scripts/design-system-advisory/check-html-nesting.mjs +51 -0
  14. package/scripts/design-system-advisory/check-icon-sizing.mjs +79 -0
  15. package/scripts/design-system-advisory/check-label-case.mjs +92 -0
  16. package/scripts/design-system-advisory/check-native-form-controls.mjs +53 -0
  17. package/scripts/design-system-advisory/check-radius.mjs +56 -0
  18. package/scripts/design-system-advisory/check-raw-values.mjs +61 -0
  19. package/scripts/design-system-advisory/check-small-text.mjs +72 -0
  20. package/scripts/design-system-advisory/check-tap-target.mjs +70 -0
  21. package/scripts/design-system-advisory/defaults.mjs +90 -0
  22. package/scripts/design-system-advisory/fixtures/clean.tsx.fixture +12 -0
  23. package/scripts/design-system-advisory/fixtures/violations.tsx.fixture +19 -0
  24. package/scripts/design-system-advisory/lib.mjs +255 -0
  25. package/scripts/design-system-advisory/run.mjs +189 -0
  26. package/scripts/design-system-advisory/workflow.yml +82 -0
  27. package/scripts/health-report.mjs +20 -14
  28. package/scripts/lib/copy-strings.mjs +146 -0
  29. package/scripts/lib/counted-lint.mjs +100 -0
  30. package/scripts/lib/dark-contrast.mjs +120 -0
  31. package/scripts/lib/flush-edges.mjs +294 -0
  32. package/scripts/lib/lab-lint.mjs +62 -0
  33. package/scripts/lib/marketing-library.mjs +129 -0
  34. package/scripts/lib/mount-page.mjs +25 -0
  35. package/scripts/lib/on-system.mjs +249 -0
  36. package/scripts/lib/random.mjs +22 -0
  37. package/scripts/lib/source-scan.mjs +173 -0
  38. package/scripts/lib/spec-parse.d.mts +25 -0
  39. package/scripts/lib/spec-parse.mjs +188 -0
  40. package/scripts/lib/tells.mjs +366 -0
  41. package/scripts/lint-arbitrary-tokens.mjs +47 -0
  42. package/scripts/lint-component-token-refs.mjs +63 -0
  43. package/scripts/lint-content-hierarchy.mjs +114 -0
  44. package/scripts/lint-control-baseline.mjs +72 -0
  45. package/scripts/lint-copy-punctuation.mjs +60 -0
  46. package/scripts/lint-css-vars.mjs +175 -0
  47. package/scripts/lint-even-padding.mjs +58 -0
  48. package/scripts/lint-html-nesting.mjs +116 -0
  49. package/scripts/lint-label-case.mjs +219 -0
  50. package/scripts/lint-live-ctas.mjs +138 -0
  51. package/scripts/lint-microanimation.mjs +2 -2
  52. package/scripts/lint-proximity.mjs +181 -0
  53. package/scripts/lint-slop.mjs +1 -1
  54. package/scripts/lint-spacing-scale.mjs +78 -0
  55. package/scripts/lint-target-size.cjs +132 -0
  56. package/scripts/lint-token-primitives.mjs +307 -0
  57. package/scripts/on-system-score.mjs +95 -0
  58. package/scripts/size-audit.cjs +2 -2
  59. package/scripts/slop-rules.mjs +1 -1
  60. package/scripts/source-images.mjs +180 -0
  61. package/scripts/ux-tells.mjs +80 -0
  62. package/scripts/wcag-audit.cjs +25 -4
  63. package/src/api/brand-colors.ts +3 -0
  64. package/src/api/brand-fonts.ts +3 -0
  65. package/src/api/brand-mark.ts +6 -1
  66. package/src/api/dev-write-guard.ts +53 -0
  67. package/src/api/layers/file.ts +9 -4
  68. package/src/api/onboarding-extract.ts +85 -30
  69. package/src/api/onboarding.ts +3 -0
  70. package/src/api/save-tokens.ts +3 -0
  71. package/src/api/site-auth.ts +14 -2
  72. package/src/app/layout.tsx +6 -0
  73. package/src/app/preview/canvas/page.tsx +12 -0
  74. package/src/app/preview/components/page.tsx +828 -14
  75. package/src/app/preview/sticker-sheet/page.tsx +329 -0
  76. package/src/app/preview/sticker-sheet/specimens.tsx +296 -0
  77. package/src/app/preview/studio/blank-screen.tsx +143 -0
  78. package/src/app/preview/studio/page.tsx +7 -0
  79. package/src/app/shell.tsx +164 -47
  80. package/src/components/Foundations/Colors.stories.tsx +119 -8
  81. package/src/components/canvas/canvas.tsx +458 -0
  82. package/src/components/canvas/layout.ts +72 -0
  83. package/src/components/canvas/parse-canvas.ts +32 -0
  84. package/src/components/canvas/sample.ts +90 -0
  85. package/src/components/canvas/spec-frame.tsx +43 -0
  86. package/src/components/canvas/types.ts +33 -0
  87. package/src/components/docs-tab.tsx +7 -7
  88. package/src/components/home-recent.tsx +73 -0
  89. package/src/components/home-tab.tsx +19 -14
  90. package/src/components/layers-tab.tsx +2 -2
  91. package/src/components/markdown-preview.tsx +60 -12
  92. package/src/components/onboarding-wizard.tsx +1 -1
  93. package/src/components/studio/control-panel.tsx +299 -0
  94. package/src/components/studio/control-row.tsx +77 -0
  95. package/src/components/studio/preview-frame.tsx +165 -0
  96. package/src/components/studio/preview-pane.tsx +247 -0
  97. package/src/components/studio/studio.tsx +133 -128
  98. package/src/components/studio/types.ts +218 -0
  99. package/src/components/studio/use-studio-tweaks.ts +128 -0
  100. package/src/components/studio/use-studio-view-state.ts +72 -0
  101. package/src/components/ui/autocomplete.tsx +1 -1
  102. package/src/components/ui/avatar.tsx +4 -0
  103. package/src/components/ui/chart.tsx +134 -42
  104. package/src/components/ui/checkbox-group.tsx +1 -1
  105. package/src/components/ui/checkbox.tsx +1 -1
  106. package/src/components/ui/color-picker.tsx +20 -4
  107. package/src/components/ui/combobox.tsx +1 -0
  108. package/src/components/ui/command.tsx +1 -1
  109. package/src/components/ui/data-table.tsx +64 -3
  110. package/src/components/ui/date-field.tsx +1 -1
  111. package/src/components/ui/date-picker.tsx +2 -0
  112. package/src/components/ui/date-range-picker.tsx +4 -0
  113. package/src/components/ui/editable.tsx +1 -0
  114. package/src/components/ui/faceted-filter.tsx +187 -0
  115. package/src/components/ui/file-upload.tsx +21 -2
  116. package/src/components/ui/gauge-chart.tsx +18 -4
  117. package/src/components/ui/heatmap.tsx +3 -1
  118. package/src/components/ui/inline-edit.tsx +175 -0
  119. package/src/components/ui/input-group.tsx +5 -2
  120. package/src/components/ui/month-picker.tsx +1 -1
  121. package/src/components/ui/multi-select.tsx +1 -0
  122. package/src/components/ui/number-input.tsx +28 -5
  123. package/src/components/ui/otp-input.tsx +208 -0
  124. package/src/components/ui/phone-input.tsx +274 -0
  125. package/src/components/ui/radio-group.tsx +2 -2
  126. package/src/components/ui/search-input.tsx +1 -1
  127. package/src/components/ui/sparkline.tsx +33 -4
  128. package/src/components/ui/spinner.tsx +23 -4
  129. package/src/components/ui/table.tsx +9 -0
  130. package/src/components/ui/tags-input.tsx +1 -1
  131. package/src/components/ui/timer.tsx +1 -0
  132. package/src/components/ui/transfer-list.tsx +13 -26
  133. package/src/components/ui/week-picker.tsx +1 -13
  134. package/src/components/ui/year-picker.tsx +1 -1
  135. package/src/data/component-added.json +966 -0
  136. package/src/data/docs-index.ts +35 -2
  137. package/src/data/history.json +161 -161
  138. package/src/data/sticker-sheet.json +9244 -0
  139. package/src/docs-trace-globs.json +1 -0
  140. package/src/hooks/use-global-mono-font.ts +1 -0
  141. package/src/hooks/use-global-primary-color.ts +1 -0
  142. package/src/hooks/use-global-sans-font.ts +1 -0
  143. package/src/hooks/use-global-serif-font.ts +1 -0
  144. package/src/hooks/use-global-type-scale.ts +17 -2
  145. package/src/hooks/use-mobile.ts +2 -0
  146. package/src/hooks/use-sync-type-scale.ts +7 -11
  147. package/src/lib/chart-motion.ts +41 -0
  148. package/src/lib/get-icon-color.ts +1 -1
  149. package/src/lib/spec-parse.ts +4 -0
  150. package/src/lib/svg-sanitize.ts +19 -9
  151. package/src/stories/Accordion.stories.tsx +7 -0
  152. package/src/stories/ActionBar.stories.tsx +5 -0
  153. package/src/stories/Affix.stories.tsx +4 -0
  154. package/src/stories/AiBadge.stories.tsx +9 -7
  155. package/src/stories/Alert.stories.tsx +13 -0
  156. package/src/stories/AlertDialog.stories.tsx +4 -0
  157. package/src/stories/Anchor.stories.tsx +5 -0
  158. package/src/stories/AngleSlider.stories.tsx +6 -3
  159. package/src/stories/AspectRatio.stories.tsx +4 -0
  160. package/src/stories/Autocomplete.stories.tsx +8 -0
  161. package/src/stories/Avatar.stories.tsx +10 -0
  162. package/src/stories/Badge.stories.tsx +14 -6
  163. package/src/stories/Blockquote.stories.tsx +6 -0
  164. package/src/stories/BottomNavigation.stories.tsx +4 -0
  165. package/src/stories/Breadcrumb.stories.tsx +3 -0
  166. package/src/stories/Burger.stories.tsx +1 -0
  167. package/src/stories/Button.stories.tsx +24 -0
  168. package/src/stories/ButtonGroup.stories.tsx +9 -0
  169. package/src/stories/Calendar.stories.tsx +3 -0
  170. package/src/stories/Canvas.stories.tsx +45 -0
  171. package/src/stories/Card.stories.tsx +4 -0
  172. package/src/stories/Carousel.stories.tsx +6 -0
  173. package/src/stories/Cascader.stories.tsx +4 -0
  174. package/src/stories/Chart.stories.tsx +46 -1
  175. package/src/stories/ChatBubble.stories.tsx +8 -2
  176. package/src/stories/ChatMarker.stories.tsx +1 -0
  177. package/src/stories/Checkbox.stories.tsx +40 -0
  178. package/src/stories/CheckboxCard.stories.tsx +8 -0
  179. package/src/stories/CheckboxGroup.stories.tsx +19 -0
  180. package/src/stories/Chip.stories.tsx +10 -19
  181. package/src/stories/CircularProgress.stories.tsx +13 -27
  182. package/src/stories/Clipboard.stories.tsx +6 -0
  183. package/src/stories/CloseButton.stories.tsx +6 -4
  184. package/src/stories/Code.stories.tsx +8 -1
  185. package/src/stories/Collapsible.stories.tsx +2 -0
  186. package/src/stories/ColorPicker.stories.tsx +46 -0
  187. package/src/stories/ColorSwatch.stories.tsx +1 -0
  188. package/src/stories/Combobox.stories.tsx +9 -0
  189. package/src/stories/Command.stories.tsx +2 -0
  190. package/src/stories/Container.stories.tsx +8 -0
  191. package/src/stories/ContextMenu.stories.tsx +9 -0
  192. package/src/stories/CopyButton.stories.tsx +12 -36
  193. package/src/stories/DataList.stories.tsx +8 -0
  194. package/src/stories/DataTable.stories.tsx +39 -0
  195. package/src/stories/DateField.stories.tsx +28 -0
  196. package/src/stories/DatePicker.stories.tsx +34 -0
  197. package/src/stories/DateRangePicker.stories.tsx +32 -0
  198. package/src/stories/Dialog.stories.tsx +8 -0
  199. package/src/stories/Drawer.stories.tsx +6 -0
  200. package/src/stories/DropdownMenu.stories.tsx +2 -0
  201. package/src/stories/Editable.stories.tsx +12 -0
  202. package/src/stories/EmptyState.stories.tsx +9 -0
  203. package/src/stories/FacetedFilter.stories.tsx +197 -0
  204. package/src/stories/Field.stories.tsx +7 -0
  205. package/src/stories/Fieldset.stories.tsx +8 -0
  206. package/src/stories/FileButton.stories.tsx +4 -0
  207. package/src/stories/FileUpload.stories.tsx +16 -17
  208. package/src/stories/FloatLabel.stories.tsx +3 -8
  209. package/src/stories/FloatingActionButton.stories.tsx +10 -0
  210. package/src/stories/FloatingIndicator.stories.tsx +4 -0
  211. package/src/stories/FloatingPanel.stories.tsx +6 -0
  212. package/src/stories/FocusTrap.stories.tsx +5 -0
  213. package/src/stories/FormatByte.stories.tsx +6 -0
  214. package/src/stories/FormatDate.stories.tsx +8 -0
  215. package/src/stories/FormatNumber.stories.tsx +9 -0
  216. package/src/stories/GaugeChart.stories.tsx +9 -3
  217. package/src/stories/Heatmap.stories.tsx +11 -0
  218. package/src/stories/Highlight.stories.tsx +6 -0
  219. package/src/stories/HoverCard.stories.tsx +4 -0
  220. package/src/stories/Image.stories.tsx +9 -0
  221. package/src/stories/Indicator.stories.tsx +19 -0
  222. package/src/stories/InlineEdit.stories.tsx +106 -0
  223. package/src/stories/Input.stories.tsx +7 -0
  224. package/src/stories/InputClearButton.stories.tsx +3 -0
  225. package/src/stories/InputGroup.stories.tsx +40 -0
  226. package/src/stories/Kbd.stories.tsx +7 -1
  227. package/src/stories/KeyboardShortcut.stories.tsx +2 -0
  228. package/src/stories/Label.stories.tsx +2 -0
  229. package/src/stories/Link.stories.tsx +9 -0
  230. package/src/stories/List.stories.tsx +8 -0
  231. package/src/stories/Listbox.stories.tsx +1 -0
  232. package/src/stories/LoadingDots.stories.tsx +5 -3
  233. package/src/stories/LoadingOverlay.stories.tsx +5 -1
  234. package/src/stories/Mark.stories.tsx +5 -0
  235. package/src/stories/MarkdownPreview.stories.tsx +53 -0
  236. package/src/stories/Marquee.stories.tsx +4 -0
  237. package/src/stories/Masonry.stories.tsx +5 -0
  238. package/src/stories/Menubar.stories.tsx +3 -0
  239. package/src/stories/Meter.stories.tsx +11 -17
  240. package/src/stories/MonthPicker.stories.tsx +26 -1
  241. package/src/stories/MotionToggle.stories.tsx +1 -0
  242. package/src/stories/MultiSelect.stories.tsx +9 -0
  243. package/src/stories/NativeSelect.stories.tsx +1 -0
  244. package/src/stories/NavLink.stories.tsx +7 -0
  245. package/src/stories/NavigationMenu.stories.tsx +5 -0
  246. package/src/stories/NavigationRail.stories.tsx +10 -0
  247. package/src/stories/Notification.stories.tsx +13 -34
  248. package/src/stories/NumberInput.stories.tsx +33 -1
  249. package/src/stories/OtpInput.stories.tsx +110 -0
  250. package/src/stories/Overlay.stories.tsx +5 -1
  251. package/src/stories/Pagination.stories.tsx +8 -0
  252. package/src/stories/PasswordInput.stories.tsx +2 -0
  253. package/src/stories/PhoneInput.stories.tsx +127 -0
  254. package/src/stories/PinInput.stories.tsx +9 -2
  255. package/src/stories/Popover.stories.tsx +2 -0
  256. package/src/stories/Progress.stories.tsx +6 -1
  257. package/src/stories/Prose.stories.tsx +8 -0
  258. package/src/stories/QrCode.stories.tsx +2 -0
  259. package/src/stories/Questionnaire.stories.tsx +7 -0
  260. package/src/stories/RadioGroup.stories.tsx +40 -0
  261. package/src/stories/RatingGroup.stories.tsx +8 -4
  262. package/src/stories/Resizable.stories.tsx +4 -2
  263. package/src/stories/Result.stories.tsx +3 -0
  264. package/src/stories/Reveal.stories.tsx +2 -0
  265. package/src/stories/RollingNumber.stories.tsx +5 -0
  266. package/src/stories/ScrollArea.stories.tsx +3 -1
  267. package/src/stories/SearchInput.stories.tsx +10 -6
  268. package/src/stories/SegmentedControl.stories.tsx +11 -0
  269. package/src/stories/Select.stories.tsx +7 -0
  270. package/src/stories/Separator.stories.tsx +6 -0
  271. package/src/stories/Sheet.stories.tsx +5 -0
  272. package/src/stories/Sidebar.stories.tsx +40 -1
  273. package/src/stories/SimpleGrid.stories.tsx +5 -0
  274. package/src/stories/Skeleton.stories.tsx +8 -0
  275. package/src/stories/SkeletonTable.stories.tsx +6 -5
  276. package/src/stories/SkipLink.stories.tsx +3 -0
  277. package/src/stories/Slider.stories.tsx +2 -1
  278. package/src/stories/Sonner.stories.tsx +7 -0
  279. package/src/stories/Sparkline.stories.tsx +14 -1
  280. package/src/stories/Spinner.stories.tsx +20 -10
  281. package/src/stories/Spoiler.stories.tsx +5 -0
  282. package/src/stories/Squircle.stories.tsx +7 -0
  283. package/src/stories/Stack.stories.tsx +7 -0
  284. package/src/stories/StatusBadge.stories.tsx +12 -6
  285. package/src/stories/Stepper.stories.tsx +5 -0
  286. package/src/stories/Switch.stories.tsx +4 -0
  287. package/src/stories/Table.stories.tsx +10 -1
  288. package/src/stories/Tabs.stories.tsx +8 -0
  289. package/src/stories/Tag.stories.tsx +13 -5
  290. package/src/stories/TagsInput.stories.tsx +15 -0
  291. package/src/stories/Text.stories.tsx +12 -0
  292. package/src/stories/Textarea.stories.tsx +9 -0
  293. package/src/stories/ThemeIcon.stories.tsx +6 -3
  294. package/src/stories/TimePicker.stories.tsx +2 -0
  295. package/src/stories/Timeline.stories.tsx +12 -0
  296. package/src/stories/Timer.stories.tsx +30 -0
  297. package/src/stories/Toggle.stories.tsx +7 -5
  298. package/src/stories/ToggleGroup.stories.tsx +5 -0
  299. package/src/stories/ToggleTip.stories.tsx +4 -0
  300. package/src/stories/Toolbar.stories.tsx +6 -0
  301. package/src/stories/Tooltip.stories.tsx +3 -0
  302. package/src/stories/Tour.stories.tsx +3 -0
  303. package/src/stories/TransferList.stories.tsx +7 -0
  304. package/src/stories/TreeSelect.stories.tsx +4 -0
  305. package/src/stories/TreeView.stories.tsx +5 -0
  306. package/src/stories/TypingIndicator.stories.tsx +4 -0
  307. package/src/stories/VisuallyHidden.stories.tsx +3 -0
  308. package/src/stories/Watermark.stories.tsx +6 -0
  309. package/src/stories/WeekPicker.stories.tsx +25 -1
  310. package/src/stories/WordRotate.stories.tsx +5 -0
  311. package/src/stories/YearPicker.stories.tsx +26 -11
  312. package/src/stories/story-groups.json +22 -16
  313. package/src/styles.css +50 -2
  314. package/src/tokens.json +86 -58
@@ -0,0 +1,274 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import { cn } from "../../lib/utils";
5
+
6
+ /**
7
+ * International phone number input that composes a country dial-code select
8
+ * with a tel Input into a single E.164-formatted field.
9
+ *
10
+ * No libphonenumber validation — just UI composition. The consuming form is
11
+ * responsible for any deeper phone-number validation it needs.
12
+ *
13
+ * Usage:
14
+ * <PhoneInput
15
+ * value={phone}
16
+ * onChange={setPhone}
17
+ * defaultCountry="GB"
18
+ * aria-label="Phone number"
19
+ * />
20
+ *
21
+ * Accessibility: the outer element is role="group" with an aria-label or
22
+ * aria-labelledby so screen readers announce it as a composite field. Tab
23
+ * moves from the country select to the number input.
24
+ */
25
+
26
+ export type Country = {
27
+ iso: string;
28
+ dialCode: string;
29
+ flag: string;
30
+ name: string;
31
+ };
32
+
33
+ export const COUNTRIES: Country[] = [
34
+ { iso: "US", dialCode: "+1", flag: "🇺🇸", name: "United States" },
35
+ { iso: "CA", dialCode: "+1", flag: "🇨🇦", name: "Canada" },
36
+ { iso: "GB", dialCode: "+44", flag: "🇬🇧", name: "United Kingdom" },
37
+ { iso: "AU", dialCode: "+61", flag: "🇦🇺", name: "Australia" },
38
+ { iso: "DE", dialCode: "+49", flag: "🇩🇪", name: "Germany" },
39
+ { iso: "FR", dialCode: "+33", flag: "🇫🇷", name: "France" },
40
+ { iso: "JP", dialCode: "+81", flag: "🇯🇵", name: "Japan" },
41
+ { iso: "BR", dialCode: "+55", flag: "🇧🇷", name: "Brazil" },
42
+ { iso: "IN", dialCode: "+91", flag: "🇮🇳", name: "India" },
43
+ { iso: "MX", dialCode: "+52", flag: "🇲🇽", name: "Mexico" },
44
+ { iso: "IT", dialCode: "+39", flag: "🇮🇹", name: "Italy" },
45
+ { iso: "ES", dialCode: "+34", flag: "🇪🇸", name: "Spain" },
46
+ { iso: "NL", dialCode: "+31", flag: "🇳🇱", name: "Netherlands" },
47
+ { iso: "KR", dialCode: "+82", flag: "🇰🇷", name: "South Korea" },
48
+ { iso: "SG", dialCode: "+65", flag: "🇸🇬", name: "Singapore" },
49
+ { iso: "SE", dialCode: "+46", flag: "🇸🇪", name: "Sweden" },
50
+ { iso: "NO", dialCode: "+47", flag: "🇳🇴", name: "Norway" },
51
+ { iso: "DK", dialCode: "+45", flag: "🇩🇰", name: "Denmark" },
52
+ { iso: "NZ", dialCode: "+64", flag: "🇳🇿", name: "New Zealand" },
53
+ { iso: "ZA", dialCode: "+27", flag: "🇿🇦", name: "South Africa" },
54
+ ];
55
+
56
+ function findCountry(iso: string): Country {
57
+ return COUNTRIES.find((c) => c.iso === iso) ?? COUNTRIES[0];
58
+ }
59
+
60
+ /**
61
+ * Parse an E.164 value (+<dialCode><localNumber>) back into its parts.
62
+ * Returns null when the value doesn't start with "+".
63
+ */
64
+ function parseE164(
65
+ value: string,
66
+ countries: Country[],
67
+ ): { country: Country; localNumber: string } | null {
68
+ if (!value.startsWith("+")) return null;
69
+ // Try longest dial code first so "+1" doesn't greedily match "+10" countries.
70
+ const sorted = [...countries].sort((a, b) => b.dialCode.length - a.dialCode.length);
71
+ for (const country of sorted) {
72
+ if (value.startsWith(country.dialCode)) {
73
+ return { country, localNumber: value.slice(country.dialCode.length) };
74
+ }
75
+ }
76
+ return null;
77
+ }
78
+
79
+ export interface PhoneInputProps
80
+ extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "onChange" | "value"> {
81
+ /** E.164 formatted phone number value (e.g. "+14155550182"). Omit for uncontrolled. */
82
+ value?: string;
83
+ /** Called with the new E.164 string whenever the country or number changes. */
84
+ onChange?: (value: string) => void;
85
+ /** ISO 2-letter country code, default "US". */
86
+ defaultCountry?: string;
87
+ disabled?: boolean;
88
+ /** When true, applies the destructive ring/border to both the select and the input. */
89
+ error?: boolean;
90
+ className?: string;
91
+ }
92
+
93
+ const PhoneInput = React.forwardRef<HTMLInputElement, PhoneInputProps>(
94
+ (
95
+ {
96
+ value,
97
+ onChange,
98
+ defaultCountry = "US",
99
+ disabled = false,
100
+ error = false,
101
+ className,
102
+ id,
103
+ "aria-label": ariaLabel,
104
+ "aria-labelledby": ariaLabelledby,
105
+ "aria-describedby": ariaDescribedby,
106
+ name,
107
+ ...rest
108
+ },
109
+ ref,
110
+ ) => {
111
+ const isControlled = value !== undefined;
112
+
113
+ const controlled = React.useMemo(() => {
114
+ if (!isControlled || !value) return null;
115
+ return parseE164(value, COUNTRIES);
116
+ }, [isControlled, value]);
117
+
118
+ // The chosen country is always state. Re-deriving it from the value alone loses the choice for countries that
119
+ // share a dial code (US and CA are both +1), so Canada snapped back to the United States.
120
+ const [country, setCountry] = React.useState<Country>(
121
+ () => controlled?.country ?? findCountry(defaultCountry),
122
+ );
123
+ // What the user typed, with their spaces and brackets. The emitted value is digits only.
124
+ const [typed, setTyped] = React.useState(controlled?.localNumber ?? "");
125
+
126
+ // A controlled value that points at a different dial code is an outside change (a form reset, a loaded
127
+ // record): follow it. The same dial code keeps whichever country the user picked.
128
+ React.useEffect(() => {
129
+ if (!isControlled) return;
130
+ if (controlled && controlled.country.dialCode !== country.dialCode) setCountry(controlled.country);
131
+ }, [isControlled, controlled, country.dialCode]);
132
+
133
+ const activeCountry = country;
134
+ const digitsOf = (text: string) => text.replace(/\D/g, "");
135
+ // Show what was typed while it still matches the controlled value's digits; otherwise show the value.
136
+ const activeLocalNumber =
137
+ isControlled && digitsOf(typed) !== (controlled?.localNumber ?? "")
138
+ ? (controlled?.localNumber ?? "")
139
+ : typed;
140
+ const e164 = digitsOf(activeLocalNumber) ? `${activeCountry.dialCode}${digitsOf(activeLocalNumber)}` : "";
141
+
142
+ function handleCountryChange(e: React.ChangeEvent<HTMLSelectElement>) {
143
+ const next = findCountry(e.target.value);
144
+ setCountry(next);
145
+ const digits = digitsOf(activeLocalNumber);
146
+ onChange?.(digits ? `${next.dialCode}${digits}` : "");
147
+ }
148
+
149
+ function handleNumberChange(e: React.ChangeEvent<HTMLInputElement>) {
150
+ // Keep digits and the punctuation people type; emit digits only, so "(415) 555-0182" is "+14155550182".
151
+ const raw = e.target.value.replace(/[^\d\s\-().]/g, "");
152
+ setTyped(raw);
153
+ const digits = digitsOf(raw);
154
+ onChange?.(digits ? `${activeCountry.dialCode}${digits}` : "");
155
+ }
156
+
157
+ const reactId = React.useId();
158
+ const inputId = id ?? `phone-input-${reactId}`;
159
+ const selectId = `${inputId}-country`;
160
+
161
+ const groupAriaProps: React.AriaAttributes & { role: string } = {
162
+ role: "group",
163
+ };
164
+ if (ariaLabel) {
165
+ groupAriaProps["aria-label"] = ariaLabel;
166
+ } else if (ariaLabelledby) {
167
+ groupAriaProps["aria-labelledby"] = ariaLabelledby;
168
+ } else {
169
+ groupAriaProps["aria-label"] = "Phone number";
170
+ }
171
+
172
+ return (
173
+ <div
174
+ data-slot="phone-input"
175
+ data-disabled={disabled || undefined}
176
+ data-invalid={error || undefined}
177
+ className={cn("flex w-full min-w-0", className)}
178
+ {...groupAriaProps}
179
+ >
180
+ {/* Country dial-code select */}
181
+ <div className="relative shrink-0">
182
+ <select
183
+ id={selectId}
184
+ data-slot="phone-input-country"
185
+ value={activeCountry.iso}
186
+ onChange={handleCountryChange}
187
+ disabled={disabled}
188
+ aria-label={`Country code — ${activeCountry.name} (${activeCountry.dialCode})`}
189
+ aria-invalid={error || undefined}
190
+ className={cn(
191
+ // Base
192
+ "h-9 min-w-0 appearance-none rounded-l-md rounded-r-none border border-r-0 border-input",
193
+ "bg-transparent px-2 pr-7 text-base text-foreground outline-none",
194
+ "dark:bg-input/30 md:text-sm",
195
+ // States
196
+ "disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50",
197
+ "focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",
198
+ // Error
199
+ error &&
200
+ "border-destructive ring-destructive/20 focus-visible:ring-destructive/40 dark:ring-destructive/40",
201
+ )}
202
+ style={{
203
+ transitionProperty: "color, box-shadow",
204
+ transitionDuration: "var(--duration-fast)",
205
+ transitionTimingFunction: "var(--ease-out)",
206
+ }}
207
+ >
208
+ {COUNTRIES.map((country) => (
209
+ <option key={country.iso} value={country.iso}>
210
+ {country.flag} {country.dialCode}
211
+ </option>
212
+ ))}
213
+ </select>
214
+ {/* Chevron icon */}
215
+ <svg
216
+ aria-hidden="true"
217
+ viewBox="0 0 16 16"
218
+ className="pointer-events-none absolute right-1.5 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground"
219
+ fill="none"
220
+ stroke="currentColor"
221
+ strokeWidth={1.5}
222
+ strokeLinecap="round"
223
+ strokeLinejoin="round"
224
+ >
225
+ <path d="M4 6l4 4 4-4" />
226
+ </svg>
227
+ </div>
228
+
229
+ {/* A plain <form> posts this: the visible input holds only the local part, so it carries no name. */}
230
+ {name ? <input type="hidden" name={name} value={e164} /> : null}
231
+
232
+ {/* Local number input */}
233
+ <input
234
+ ref={ref}
235
+ id={inputId}
236
+ data-slot="phone-input-number"
237
+ type="tel"
238
+ inputMode="tel"
239
+ autoComplete="tel-national"
240
+ value={activeLocalNumber}
241
+ onChange={handleNumberChange}
242
+ disabled={disabled}
243
+ aria-invalid={error || undefined}
244
+ aria-describedby={ariaDescribedby}
245
+ placeholder="(555) 000-0000"
246
+ className={cn(
247
+ // Base
248
+ "min-w-0 flex-1 rounded-l-none rounded-r-md border border-l-0 border-input",
249
+ "h-9 bg-transparent px-3 py-1 text-base outline-none",
250
+ "selection:bg-primary selection:text-primary-foreground md:text-sm",
251
+ "dark:bg-input/30",
252
+ // States
253
+ "placeholder:text-muted-foreground",
254
+ "disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50",
255
+ "focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",
256
+ // Error
257
+ error &&
258
+ "border-destructive ring-destructive/20 focus-visible:ring-destructive/40 dark:ring-destructive/40",
259
+ )}
260
+ style={{
261
+ transitionProperty: "color, box-shadow",
262
+ transitionDuration: "var(--duration-fast)",
263
+ transitionTimingFunction: "var(--ease-out)",
264
+ }}
265
+ {...rest}
266
+ />
267
+ </div>
268
+ );
269
+ },
270
+ );
271
+
272
+ PhoneInput.displayName = "PhoneInput";
273
+
274
+ export { PhoneInput };
@@ -19,7 +19,7 @@ function RadioGroup({
19
19
  className={cn(
20
20
  orientation === "horizontal"
21
21
  ? "flex flex-row flex-wrap gap-x-6 gap-y-3"
22
- : "grid gap-3",
22
+ : "grid grid-cols-1 gap-3",
23
23
  className
24
24
  )}
25
25
  {...props}
@@ -28,7 +28,7 @@ function RadioGroup({
28
28
  }
29
29
 
30
30
  const radioGroupItemVariants = cva(
31
- "aspect-square shrink-0 rounded-full border-2 border-muted-foreground/60 bg-white text-primary shadow-xs transition-[background-color,border-color,color] duration-[210ms] ease-in-out outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 data-[state=checked]:bg-primary data-[state=checked]:border-primary",
31
+ "aspect-square shrink-0 rounded-full border-2 border-muted-foreground/60 bg-background dark:data-[state=unchecked]:bg-input/30 text-primary shadow-xs transition-[background-color,border-color,color] duration-[210ms] ease-in-out outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 data-[state=checked]:bg-primary data-[state=checked]:border-primary",
32
32
  {
33
33
  variants: {
34
34
  size: {
@@ -40,7 +40,7 @@ function SearchInput({
40
40
  }
41
41
 
42
42
  function handleKeyDown(e: React.KeyboardEvent<HTMLInputElement>) {
43
- if (e.key === "Enter") {
43
+ if (e.key === "Enter" && !e.nativeEvent.isComposing) {
44
44
  onSearch?.(value ?? "")
45
45
  }
46
46
  if (e.key === "Escape") {
@@ -13,6 +13,7 @@ import {
13
13
 
14
14
  import { cn } from "../../lib/utils"
15
15
  import { useReducedMotion } from "../../hooks/use-reduced-motion"
16
+ import { readChartMotion, type ChartMotion } from "../../lib/chart-motion"
16
17
 
17
18
  export interface SparklineProps extends React.ComponentProps<"span"> {
18
19
  /**
@@ -85,10 +86,14 @@ function Sparkline({
85
86
  // ResizeObserver gate — same pattern as ChartContainer.
86
87
  const containerRef = React.useRef<HTMLSpanElement | null>(null)
87
88
  const [hasSize, setHasSize] = React.useState(false)
89
+ // Draw timing from the BADS motion tokens (see lib/chart-motion.ts), read
90
+ // once the span is mounted.
91
+ const [motion, setMotion] = React.useState<ChartMotion | null>(null)
88
92
 
89
93
  React.useEffect(() => {
90
94
  const el = containerRef.current
91
95
  if (!el) return
96
+ setMotion(readChartMotion(el))
92
97
  const observer = new ResizeObserver((entries) => {
93
98
  for (const entry of entries) {
94
99
  const { width, height: h } = entry.contentRect
@@ -114,8 +119,23 @@ function Sparkline({
114
119
  const padding = max === min ? 1 : (max - min) * 0.1
115
120
  const domain: [number, number] = [min - padding, max + padding]
116
121
 
117
- // Last-point dot: rendered via Recharts' customized dot prop.
122
+ // Last-point dot: rendered via Recharts' customized dot prop. For
123
+ // type="line" Recharts mounts it at its final position straight away while
124
+ // the stroke takes the whole draw to reach the right edge, so on its own the
125
+ // dot lands well before the line does. Hold it until the draw has finished,
126
+ // then fade it in over --duration-slow / --ease-out. type="area" needs
127
+ // nothing: the dot sits inside the area's left-to-right reveal clip and
128
+ // arrives with it. No delay or fade when not animating (reduced motion).
118
129
  const lastIndex = data.length - 1
130
+ const dotEntrance: React.CSSProperties | undefined =
131
+ animate && motion && type === "line"
132
+ ? {
133
+ animationDuration: "var(--duration-slow)",
134
+ animationTimingFunction: "var(--ease-out)",
135
+ animationDelay: `${motion.drawMs}ms`,
136
+ animationFillMode: "both",
137
+ }
138
+ : undefined
119
139
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
120
140
  const renderDot = withDot
121
141
  ? (dotProps: any) => {
@@ -129,6 +149,8 @@ function Sparkline({
129
149
  fill={color}
130
150
  stroke="var(--color-background, #fff)"
131
151
  strokeWidth={1.5}
152
+ className={dotEntrance ? "animate-in fade-in-0" : undefined}
153
+ style={dotEntrance}
132
154
  />
133
155
  )
134
156
  }
@@ -141,8 +163,15 @@ function Sparkline({
141
163
  strokeWidth: 1.5,
142
164
  dot: renderDot,
143
165
  isAnimationActive: animate,
166
+ animationDuration: motion?.drawMs,
167
+ animationEasing: motion?.drawEasing as "ease-in-out" | undefined,
144
168
  } as const
145
169
 
170
+ // The last-point dot (r=3 plus a 1.5 stroke) sits on the plot edge; give it
171
+ // room so it is not clipped by the chart surface.
172
+ const inset = withDot ? 5 : 2
173
+ const margin = { top: inset, right: inset, bottom: inset, left: 2 }
174
+
146
175
  return (
147
176
  <span
148
177
  ref={containerRef}
@@ -153,12 +182,12 @@ function Sparkline({
153
182
  style={{ height }}
154
183
  {...props}
155
184
  >
156
- {hasSize ? (
185
+ {hasSize && motion ? (
157
186
  <ResponsiveContainer width="100%" height="100%">
158
187
  {type === "area" ? (
159
188
  <AreaChart
160
189
  data={chartData}
161
- margin={{ top: 2, right: 2, bottom: 2, left: 2 }}
190
+ margin={margin}
162
191
  >
163
192
  <defs>
164
193
  <linearGradient id={gradientId} x1="0" y1="0" x2="0" y2="1">
@@ -183,7 +212,7 @@ function Sparkline({
183
212
  ) : (
184
213
  <LineChart
185
214
  data={chartData}
186
- margin={{ top: 2, right: 2, bottom: 2, left: 2 }}
215
+ margin={margin}
187
216
  >
188
217
  <YAxis domain={domain} hide yAxisId={0} />
189
218
  <Line {...commonLineProps} yAxisId={0} />
@@ -2,7 +2,14 @@ import * as React from "react"
2
2
  import { cva, type VariantProps } from "class-variance-authority"
3
3
  import { cn } from "../../lib/utils"
4
4
 
5
- const spinnerVariants = cva("animate-spin", {
5
+ // The ring is drawn in currentColor. `default` sets no color of its own, so
6
+ // the spinner takes the color of the text around it: inside a primary Button
7
+ // it is primary-foreground, inside muted copy it is muted. It used to force
8
+ // text-foreground on the <svg>, which drew a light ring on a light primary
9
+ // button in dark mode (and a dark ring on a dark one in light mode).
10
+ // The variant color is applied to the outer span, so a `className` color
11
+ // (e.g. text-primary-foreground) overrides it instead of being ignored.
12
+ const spinnerVariants = cva("", {
6
13
  variants: {
7
14
  size: {
8
15
  xs: "size-4",
@@ -11,7 +18,7 @@ const spinnerVariants = cva("animate-spin", {
11
18
  lg: "size-8",
12
19
  },
13
20
  variant: {
14
- default: "text-foreground",
21
+ default: "",
15
22
  muted: "text-muted-foreground",
16
23
  primary: "text-primary",
17
24
  },
@@ -22,6 +29,14 @@ const spinnerVariants = cva("animate-spin", {
22
29
  },
23
30
  })
24
31
 
32
+ // Color lives on the outer span (see the note above spinnerVariants), kept
33
+ // apart from the size classes so the span never picks up a size of its own.
34
+ const spinnerColor = {
35
+ default: "",
36
+ muted: "text-muted-foreground",
37
+ primary: "text-primary",
38
+ } as const
39
+
25
40
  type SpinnerProps = React.HTMLAttributes<HTMLSpanElement> &
26
41
  VariantProps<typeof spinnerVariants> & {
27
42
  label?: string
@@ -39,11 +54,15 @@ function Spinner({
39
54
  data-slot="spinner"
40
55
  role="status"
41
56
  aria-label={label}
42
- className={cn("inline-flex items-center justify-center", className)}
57
+ className={cn(
58
+ "inline-flex items-center justify-center",
59
+ spinnerColor[variant ?? "default"],
60
+ className
61
+ )}
43
62
  {...props}
44
63
  >
45
64
  <svg
46
- className={spinnerVariants({ size, variant })}
65
+ className={cn("animate-spin", spinnerVariants({ size, variant: "default" }))}
47
66
  xmlns="http://www.w3.org/2000/svg"
48
67
  fill="none"
49
68
  viewBox="0 0 24 24"
@@ -31,9 +31,18 @@ interface TableProps extends React.ComponentProps<"table"> {
31
31
 
32
32
  function Table({ className, wrapperClassName, wrapperStyle, striped = false, bordered = false, compact = false, ...props }: TableProps) {
33
33
  const variants = React.useMemo(() => ({ striped, bordered, compact }), [striped, bordered, compact])
34
+ // The scroll container is a focusable region. A focusable region with no role and no name is announced as nothing
35
+ // in particular, so when the table is labelled the container carries the same name as a region (WCAG 1.4.10: a
36
+ // table may scroll sideways, but only inside a region a keyboard or screen reader user can find).
37
+ const label = props["aria-label"]
38
+ const labelledBy = props["aria-labelledby"]
39
+ const named = Boolean(label || labelledBy)
34
40
  return (
35
41
  <TableVariantContext.Provider value={variants}>
36
42
  <div data-slot="table-container" tabIndex={0}
43
+ role={named ? "region" : undefined}
44
+ aria-label={label}
45
+ aria-labelledby={labelledBy}
37
46
  className={cn(
38
47
  "relative w-full overflow-x-auto [scrollbar-width:thin] [scrollbar-color:theme(colors.border)_transparent]",
39
48
  bordered && "rounded-md border",
@@ -197,7 +197,7 @@ export function TagsInput({
197
197
  setActiveIndex((i) => (i <= 0 ? 0 : i - 1));
198
198
  return;
199
199
  }
200
- if (e.key === "Enter") {
200
+ if (e.key === "Enter" && !e.nativeEvent.isComposing) {
201
201
  e.preventDefault();
202
202
  if (isOpen && activeIndex >= 0) {
203
203
  selectSuggestion(filteredSuggestions[activeIndex]);
@@ -172,6 +172,7 @@ function Timer({
172
172
  {/* Entering the DOM on completion triggers exactly one polite
173
173
  announcement — the only tick worth interrupting for. */}
174
174
  {completed && (
175
+ // allow-conditional-aria-live intentional one-shot completion announce — mounting triggers a single polite read and the region then leaves the DOM
175
176
  <span data-slot="timer-announcement" role="status" className="sr-only">
176
177
  {completeAnnouncement}
177
178
  </span>
@@ -11,6 +11,7 @@ import {
11
11
  import { cn } from "../../lib/utils"
12
12
  import { Button } from "../ui/button"
13
13
  import { Badge } from "../ui/badge"
14
+ import { Checkbox } from "../ui/checkbox"
14
15
  import { Input } from "../ui/input"
15
16
 
16
17
  // ────────────────────────────────────────────────────────────────────────────
@@ -154,32 +155,18 @@ function Panel({ label, items, checked, onToggle, searchable }: PanelProps) {
154
155
  transitionTimingFunction: "var(--ease-out)",
155
156
  }}
156
157
  >
157
- {/* Visual checkbox indicator */}
158
- <span
159
- aria-hidden="true"
160
- className={cn(
161
- "inline-flex shrink-0 size-4 items-center justify-center rounded-sm border",
162
- isChecked
163
- ? "border-primary bg-primary text-primary-foreground"
164
- : "border-muted-foreground/60 bg-background"
165
- )}
166
- >
167
- {isChecked && (
168
- <svg
169
- width="10"
170
- height="8"
171
- viewBox="0 0 10 8"
172
- fill="none"
173
- stroke="currentColor"
174
- strokeWidth="1.5"
175
- strokeLinecap="round"
176
- strokeLinejoin="round"
177
- aria-hidden="true"
178
- >
179
- <polyline points="1 4 3.5 6.5 9 1" />
180
- </svg>
181
- )}
182
- </span>
158
+ {/* Decorative, not the real control: the <li role="option"> above already
159
+ handles the click/toggle. A second focusable checkbox nested in the
160
+ same row would double the controls a screen reader announces for one
161
+ choice — tabIndex, pointer-events, and aria-hidden are what make the
162
+ real Checkbox primitive safe to use purely as a visual here. */}
163
+ <Checkbox
164
+ size="sm"
165
+ checked={isChecked}
166
+ tabIndex={-1}
167
+ aria-hidden
168
+ className="pointer-events-none"
169
+ />
183
170
  <span className="min-w-0 truncate" title={item}>
184
171
  {item}
185
172
  </span>
@@ -76,18 +76,6 @@ function isoWeekYear(d: Date): number {
76
76
  return thursday.getFullYear()
77
77
  }
78
78
 
79
- /** Returns the number of ISO weeks in a given year (52 or 53). */
80
- function isoWeeksInYear(year: number): number {
81
- // A year has 53 ISO weeks if Jan 1 is Thursday, or if it's a leap year
82
- // whose Jan 1 is Wednesday.
83
- const jan1 = new Date(year, 0, 1).getDay() // 0=Sun
84
- return jan1 === 4 || (jan1 === 3 && isLeapYear(year)) ? 53 : 52
85
- }
86
-
87
- function isLeapYear(year: number): boolean {
88
- return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0
89
- }
90
-
91
79
  /** Number of days in a given month (0-indexed). */
92
80
  function daysInMonth(year: number, month: number): number {
93
81
  return new Date(year, month + 1, 0).getDate()
@@ -147,7 +135,7 @@ function WeekPicker({
147
135
  className,
148
136
  id,
149
137
  }: WeekPickerProps) {
150
- const isControlled = value !== undefined
138
+ const isControlled = value !== undefined || onValueChange !== undefined
151
139
  const [internalValue, setInternalValue] = React.useState<Date | undefined>(
152
140
  defaultValue ? isoWeekStart(defaultValue) : undefined
153
141
  )
@@ -64,7 +64,7 @@ function YearPicker({
64
64
  const resolvedMin = minYear ?? currentYear - 100
65
65
  const resolvedMax = maxYear ?? currentYear + 10
66
66
 
67
- const isControlled = value !== undefined
67
+ const isControlled = value !== undefined || onValueChange !== undefined
68
68
  const [internalValue, setInternalValue] = React.useState<number | undefined>(
69
69
  defaultValue
70
70
  )