@eifi1/ui-kit 0.4.1 → 0.5.1

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 (414) hide show
  1. package/LICENSE +32 -0
  2. package/README.md +498 -57
  3. package/dist/chart.d.ts +10 -0
  4. package/dist/chart.js +10 -0
  5. package/dist/chart.js.map +1 -0
  6. package/dist/components/account-settings.d.ts +11 -0
  7. package/dist/components/account-settings.js +19 -12
  8. package/dist/components/account-settings.js.map +1 -1
  9. package/dist/components/alert-banner.d.ts +10 -6
  10. package/dist/components/alert-banner.js +20 -16
  11. package/dist/components/alert-banner.js.map +1 -1
  12. package/dist/components/amount-input.d.ts +30 -4
  13. package/dist/components/amount-input.js +36 -14
  14. package/dist/components/amount-input.js.map +1 -1
  15. package/dist/components/calculator.d.ts +24 -7
  16. package/dist/components/calculator.js +37 -20
  17. package/dist/components/calculator.js.map +1 -1
  18. package/dist/components/chart-zoom.d.ts +156 -0
  19. package/dist/components/chart-zoom.js +262 -0
  20. package/dist/components/chart-zoom.js.map +1 -0
  21. package/dist/components/chart.d.ts +28 -3
  22. package/dist/components/chart.js +71 -32
  23. package/dist/components/chart.js.map +1 -1
  24. package/dist/components/checkbox.d.ts +51 -0
  25. package/dist/components/checkbox.js +123 -0
  26. package/dist/components/checkbox.js.map +1 -0
  27. package/dist/components/chip.d.ts +142 -0
  28. package/dist/components/chip.js +357 -0
  29. package/dist/components/chip.js.map +1 -0
  30. package/dist/components/choice-parts.d.ts +24 -0
  31. package/dist/components/choice-parts.js +18 -0
  32. package/dist/components/choice-parts.js.map +1 -0
  33. package/dist/components/combobox-core.d.ts +52 -9
  34. package/dist/components/combobox-core.js +89 -19
  35. package/dist/components/combobox-core.js.map +1 -1
  36. package/dist/components/combobox.d.ts +43 -33
  37. package/dist/components/combobox.js +409 -340
  38. package/dist/components/combobox.js.map +1 -1
  39. package/dist/components/currency-select.d.ts +48 -8
  40. package/dist/components/currency-select.js +115 -65
  41. package/dist/components/currency-select.js.map +1 -1
  42. package/dist/components/data-table-filter-popover.d.ts +15 -3
  43. package/dist/components/data-table-filter-popover.js +23 -17
  44. package/dist/components/data-table-filter-popover.js.map +1 -1
  45. package/dist/components/data-table-filters.d.ts +1 -1
  46. package/dist/components/data-table-filters.js +3 -2
  47. package/dist/components/data-table-filters.js.map +1 -1
  48. package/dist/components/data-table-labels.d.ts +53 -2
  49. package/dist/components/data-table-labels.js +31 -2
  50. package/dist/components/data-table-labels.js.map +1 -1
  51. package/dist/components/data-table-pagination.d.ts +3 -1
  52. package/dist/components/data-table-pagination.js +16 -10
  53. package/dist/components/data-table-pagination.js.map +1 -1
  54. package/dist/components/data-table-sort.js +1 -0
  55. package/dist/components/data-table-sort.js.map +1 -1
  56. package/dist/components/data-table.d.ts +1 -1
  57. package/dist/components/data-table.js +201 -85
  58. package/dist/components/data-table.js.map +1 -1
  59. package/dist/components/date-picker.d.ts +25 -9
  60. package/dist/components/date-picker.js +244 -94
  61. package/dist/components/date-picker.js.map +1 -1
  62. package/dist/components/dropdown.d.ts +74 -19
  63. package/dist/components/dropdown.js +72 -22
  64. package/dist/components/dropdown.js.map +1 -1
  65. package/dist/components/entity-combobox.d.ts +5 -4
  66. package/dist/components/entity-combobox.js +107 -76
  67. package/dist/components/entity-combobox.js.map +1 -1
  68. package/dist/components/facing-pair.d.ts +36 -0
  69. package/dist/components/facing-pair.js +40 -0
  70. package/dist/components/facing-pair.js.map +1 -0
  71. package/dist/components/field-sync.d.ts +164 -0
  72. package/dist/components/field-sync.js +264 -0
  73. package/dist/components/field-sync.js.map +1 -0
  74. package/dist/components/file-dropzone.d.ts +21 -7
  75. package/dist/components/file-dropzone.js +28 -7
  76. package/dist/components/file-dropzone.js.map +1 -1
  77. package/dist/components/full-bleed-dialog.d.ts +37 -26
  78. package/dist/components/full-bleed-dialog.js +20 -5
  79. package/dist/components/full-bleed-dialog.js.map +1 -1
  80. package/dist/components/grouped-picker.d.ts +21 -10
  81. package/dist/components/grouped-picker.js +66 -52
  82. package/dist/components/grouped-picker.js.map +1 -1
  83. package/dist/components/hover-menu.d.ts +20 -4
  84. package/dist/components/hover-menu.js +15 -4
  85. package/dist/components/hover-menu.js.map +1 -1
  86. package/dist/components/mini-calendar.d.ts +102 -14
  87. package/dist/components/mini-calendar.js +256 -70
  88. package/dist/components/mini-calendar.js.map +1 -1
  89. package/dist/components/modal.d.ts +9 -3
  90. package/dist/components/modal.js +34 -45
  91. package/dist/components/modal.js.map +1 -1
  92. package/dist/components/month-picker.d.ts +79 -0
  93. package/dist/components/month-picker.js +353 -0
  94. package/dist/components/month-picker.js.map +1 -0
  95. package/dist/components/multi-entity-combobox.d.ts +7 -6
  96. package/dist/components/multi-entity-combobox.js +112 -72
  97. package/dist/components/multi-entity-combobox.js.map +1 -1
  98. package/dist/components/multi-select.d.ts +13 -11
  99. package/dist/components/multi-select.js +161 -84
  100. package/dist/components/multi-select.js.map +1 -1
  101. package/dist/components/number-field.d.ts +92 -0
  102. package/dist/components/number-field.js +111 -0
  103. package/dist/components/number-field.js.map +1 -0
  104. package/dist/components/number-input.d.ts +21 -2
  105. package/dist/components/number-input.js +2 -1
  106. package/dist/components/number-input.js.map +1 -1
  107. package/dist/components/numpad-sheet.d.ts +25 -4
  108. package/dist/components/numpad-sheet.js +30 -13
  109. package/dist/components/numpad-sheet.js.map +1 -1
  110. package/dist/components/page-contents.d.ts +90 -0
  111. package/dist/components/page-contents.js +170 -0
  112. package/dist/components/page-contents.js.map +1 -0
  113. package/dist/components/password-strength.d.ts +106 -0
  114. package/dist/components/password-strength.js +132 -0
  115. package/dist/components/password-strength.js.map +1 -0
  116. package/dist/components/picker-sheet.d.ts +23 -15
  117. package/dist/components/picker-sheet.js +34 -14
  118. package/dist/components/picker-sheet.js.map +1 -1
  119. package/dist/components/popover.d.ts +62 -4
  120. package/dist/components/popover.js +55 -2
  121. package/dist/components/popover.js.map +1 -1
  122. package/dist/components/search-field.d.ts +25 -7
  123. package/dist/components/search-field.js +7 -5
  124. package/dist/components/search-field.js.map +1 -1
  125. package/dist/components/series-chart-labels.d.ts +14 -0
  126. package/dist/components/series-chart-labels.js +11 -0
  127. package/dist/components/series-chart-labels.js.map +1 -0
  128. package/dist/components/series-chart.d.ts +207 -0
  129. package/dist/components/series-chart.js +223 -0
  130. package/dist/components/series-chart.js.map +1 -0
  131. package/dist/components/settings-fields.d.ts +14 -4
  132. package/dist/components/settings-fields.js +19 -8
  133. package/dist/components/settings-fields.js.map +1 -1
  134. package/dist/components/signature-pad.d.ts +119 -0
  135. package/dist/components/signature-pad.js +405 -0
  136. package/dist/components/signature-pad.js.map +1 -0
  137. package/dist/components/slider.d.ts +80 -0
  138. package/dist/components/slider.js +155 -0
  139. package/dist/components/slider.js.map +1 -0
  140. package/dist/components/sparkline.d.ts +93 -0
  141. package/dist/components/sparkline.js +205 -0
  142. package/dist/components/sparkline.js.map +1 -0
  143. package/dist/components/stat-tile.d.ts +151 -0
  144. package/dist/components/stat-tile.js +236 -0
  145. package/dist/components/stat-tile.js.map +1 -0
  146. package/dist/components/swipeable-row.d.ts +25 -2
  147. package/dist/components/swipeable-row.js +31 -0
  148. package/dist/components/swipeable-row.js.map +1 -1
  149. package/dist/components/switch.d.ts +60 -0
  150. package/dist/components/switch.js +81 -0
  151. package/dist/components/switch.js.map +1 -0
  152. package/dist/components/time-input.d.ts +58 -0
  153. package/dist/components/time-input.js +50 -0
  154. package/dist/components/time-input.js.map +1 -0
  155. package/dist/components/toggle-group.d.ts +18 -3
  156. package/dist/components/toggle-group.js +10 -6
  157. package/dist/components/toggle-group.js.map +1 -1
  158. package/dist/components/toggle-legend.d.ts +115 -0
  159. package/dist/components/toggle-legend.js +114 -0
  160. package/dist/components/toggle-legend.js.map +1 -0
  161. package/dist/components/tooltip.d.ts +40 -11
  162. package/dist/components/tooltip.js +77 -20
  163. package/dist/components/tooltip.js.map +1 -1
  164. package/dist/components/treemap.d.ts +132 -0
  165. package/dist/components/treemap.js +179 -0
  166. package/dist/components/treemap.js.map +1 -0
  167. package/dist/components/trigger-aria.d.ts +18 -0
  168. package/dist/components/trigger-aria.js +25 -0
  169. package/dist/components/trigger-aria.js.map +1 -0
  170. package/dist/components/ui.d.ts +167 -46
  171. package/dist/components/ui.js +225 -121
  172. package/dist/components/ui.js.map +1 -1
  173. package/dist/components/use-mobile-reveal.js +1 -0
  174. package/dist/components/use-mobile-reveal.js.map +1 -1
  175. package/dist/components/use-table-state.d.ts +1 -1
  176. package/dist/components/use-table-state.js +38 -17
  177. package/dist/components/use-table-state.js.map +1 -1
  178. package/dist/components/user-avatar.d.ts +5 -3
  179. package/dist/components/user-avatar.js +4 -2
  180. package/dist/components/user-avatar.js.map +1 -1
  181. package/dist/components/wizard-stepper.js +3 -2
  182. package/dist/components/wizard-stepper.js.map +1 -1
  183. package/dist/{data-table-filters-aXyf0Xub.d.ts → data-table-filters-DM1auUfH.d.ts} +27 -5
  184. package/dist/data-table.d.ts +7 -0
  185. package/dist/data-table.js +12 -0
  186. package/dist/data-table.js.map +1 -0
  187. package/dist/feedback/feedback-attachment.js +12 -11
  188. package/dist/feedback/feedback-attachment.js.map +1 -1
  189. package/dist/feedback/feedback-dialog.js +2 -1
  190. package/dist/feedback/feedback-dialog.js.map +1 -1
  191. package/dist/feedback/feedback-inbox.d.ts +33 -7
  192. package/dist/feedback/feedback-inbox.js +49 -37
  193. package/dist/feedback/feedback-inbox.js.map +1 -1
  194. package/dist/feedback.d.ts +5 -0
  195. package/dist/feedback.js +5 -0
  196. package/dist/feedback.js.map +1 -0
  197. package/dist/hooks/use-anchored-panel.js +1 -0
  198. package/dist/hooks/use-anchored-panel.js.map +1 -1
  199. package/dist/hooks/use-anchored-rect.js +1 -0
  200. package/dist/hooks/use-anchored-rect.js.map +1 -1
  201. package/dist/hooks/use-announce.d.ts +46 -0
  202. package/dist/hooks/use-announce.js +37 -0
  203. package/dist/hooks/use-announce.js.map +1 -0
  204. package/dist/hooks/use-body-scroll-lock.js +1 -0
  205. package/dist/hooks/use-body-scroll-lock.js.map +1 -1
  206. package/dist/hooks/use-close-transition.js +1 -0
  207. package/dist/hooks/use-close-transition.js.map +1 -1
  208. package/dist/hooks/use-dismiss.js +1 -0
  209. package/dist/hooks/use-dismiss.js.map +1 -1
  210. package/dist/hooks/use-focus-trap.d.ts +16 -0
  211. package/dist/hooks/use-focus-trap.js +67 -0
  212. package/dist/hooks/use-focus-trap.js.map +1 -0
  213. package/dist/hooks/use-media-query.js +1 -0
  214. package/dist/hooks/use-media-query.js.map +1 -1
  215. package/dist/hooks/use-overlay-history.js +27 -1
  216. package/dist/hooks/use-overlay-history.js.map +1 -1
  217. package/dist/hooks/use-row-swipe.js +1 -0
  218. package/dist/hooks/use-row-swipe.js.map +1 -1
  219. package/dist/i18n/defaults.d.ts +31 -0
  220. package/dist/i18n/defaults.js +63 -0
  221. package/dist/i18n/defaults.js.map +1 -0
  222. package/dist/i18n/kit-labels.d.ts +250 -0
  223. package/dist/i18n/kit-labels.js +184 -0
  224. package/dist/i18n/kit-labels.js.map +1 -0
  225. package/dist/index.d.ts +47 -22
  226. package/dist/index.js +28 -0
  227. package/dist/index.js.map +1 -1
  228. package/dist/lib/calc.js +1 -0
  229. package/dist/lib/calc.js.map +1 -1
  230. package/dist/lib/cn.js +1 -0
  231. package/dist/lib/cn.js.map +1 -1
  232. package/dist/lib/dates.js +1 -0
  233. package/dist/lib/dates.js.map +1 -1
  234. package/dist/lib/logger.js +1 -0
  235. package/dist/lib/logger.js.map +1 -1
  236. package/dist/lib/safe-storage.js +1 -0
  237. package/dist/lib/safe-storage.js.map +1 -1
  238. package/dist/search/command-palette.d.ts +11 -1
  239. package/dist/search/command-palette.js +21 -15
  240. package/dist/search/command-palette.js.map +1 -1
  241. package/dist/search.d.ts +2 -0
  242. package/dist/search.js +3 -0
  243. package/dist/search.js.map +1 -0
  244. package/dist/shell/app-shell.d.ts +33 -4
  245. package/dist/shell/app-shell.js +275 -78
  246. package/dist/shell/app-shell.js.map +1 -1
  247. package/dist/shell/option-switcher-menu.js +3 -2
  248. package/dist/shell/option-switcher-menu.js.map +1 -1
  249. package/dist/shell/role-switcher.d.ts +6 -0
  250. package/dist/shell/role-switcher.js +7 -4
  251. package/dist/shell/role-switcher.js.map +1 -1
  252. package/dist/shell/top-bar.d.ts +15 -7
  253. package/dist/shell/top-bar.js +3 -5
  254. package/dist/shell/top-bar.js.map +1 -1
  255. package/dist/shell/topbar-action-menu.js +3 -2
  256. package/dist/shell/topbar-action-menu.js.map +1 -1
  257. package/dist/shell/topbar-controls.d.ts +5 -2
  258. package/dist/shell/topbar-controls.js +20 -15
  259. package/dist/shell/topbar-controls.js.map +1 -1
  260. package/dist/shell.d.ts +13 -0
  261. package/dist/shell.js +8 -0
  262. package/dist/shell.js.map +1 -0
  263. package/dist/theme/chart-palette.d.ts +19 -12
  264. package/dist/theme/chart-palette.js +24 -30
  265. package/dist/theme/chart-palette.js.map +1 -1
  266. package/dist/theme/color.d.ts +78 -0
  267. package/dist/theme/color.js +148 -0
  268. package/dist/theme/color.js.map +1 -0
  269. package/dist/theme/palette-derive.d.ts +140 -0
  270. package/dist/theme/palette-derive.js +376 -0
  271. package/dist/theme/palette-derive.js.map +1 -0
  272. package/dist/theme/palette-presets.d.ts +14 -1
  273. package/dist/theme/palette-presets.js +231 -3
  274. package/dist/theme/palette-presets.js.map +1 -1
  275. package/dist/theme/palette-store.js +1 -0
  276. package/dist/theme/palette-store.js.map +1 -1
  277. package/dist/theme/theme-store.js +1 -0
  278. package/dist/theme/theme-store.js.map +1 -1
  279. package/dist/tour/tour.d.ts +2 -1
  280. package/dist/tour/tour.js +15 -9
  281. package/dist/tour/tour.js.map +1 -1
  282. package/dist/tour.d.ts +2 -0
  283. package/dist/tour.js +3 -0
  284. package/dist/tour.js.map +1 -0
  285. package/dist/wizard/stepper-nav.js +10 -8
  286. package/dist/wizard/stepper-nav.js.map +1 -1
  287. package/dist/wizard/types.d.ts +18 -2
  288. package/dist/wizard/types.js +4 -1
  289. package/dist/wizard/types.js.map +1 -1
  290. package/dist/wizard/use-wizard.js +12 -4
  291. package/dist/wizard/use-wizard.js.map +1 -1
  292. package/dist/wizard/validation.js +1 -0
  293. package/dist/wizard/validation.js.map +1 -1
  294. package/dist/wizard/wizard-context.js +1 -0
  295. package/dist/wizard/wizard-context.js.map +1 -1
  296. package/dist/wizard/wizard-step.js +1 -0
  297. package/dist/wizard/wizard-step.js.map +1 -1
  298. package/dist/wizard/wizard-summary.js +5 -3
  299. package/dist/wizard/wizard-summary.js.map +1 -1
  300. package/dist/wizard.d.ts +8 -0
  301. package/dist/wizard.js +9 -0
  302. package/dist/wizard.js.map +1 -0
  303. package/package.json +66 -13
  304. package/src/chart.ts +22 -0
  305. package/src/components/account-settings.tsx +275 -0
  306. package/src/components/alert-banner.tsx +75 -0
  307. package/src/components/amount-input.tsx +471 -0
  308. package/src/components/calculator.tsx +252 -0
  309. package/src/components/chart-zoom.tsx +499 -0
  310. package/src/components/chart.tsx +363 -0
  311. package/src/components/checkbox.tsx +222 -0
  312. package/src/components/chip.tsx +584 -0
  313. package/src/components/choice-parts.ts +33 -0
  314. package/src/components/combobox-core.tsx +540 -0
  315. package/src/components/combobox.tsx +1026 -0
  316. package/src/components/currency-select.tsx +283 -0
  317. package/src/components/data-table-filter-popover.tsx +252 -0
  318. package/src/components/data-table-filters.ts +176 -0
  319. package/src/components/data-table-labels.ts +190 -0
  320. package/src/components/data-table-pagination.tsx +126 -0
  321. package/src/components/data-table-sort.ts +70 -0
  322. package/src/components/data-table.tsx +1740 -0
  323. package/src/components/date-picker.tsx +656 -0
  324. package/src/components/dropdown.tsx +341 -0
  325. package/src/components/entity-combobox.tsx +215 -0
  326. package/src/components/facing-pair.ts +86 -0
  327. package/src/components/field-sync.tsx +472 -0
  328. package/src/components/file-dropzone.tsx +181 -0
  329. package/src/components/full-bleed-dialog.tsx +179 -0
  330. package/src/components/grouped-picker.tsx +157 -0
  331. package/src/components/hover-menu.tsx +183 -0
  332. package/src/components/mini-calendar.tsx +554 -0
  333. package/src/components/modal.tsx +287 -0
  334. package/src/components/month-picker.tsx +567 -0
  335. package/src/components/multi-entity-combobox.tsx +226 -0
  336. package/src/components/multi-select.tsx +303 -0
  337. package/src/components/number-field.tsx +225 -0
  338. package/src/components/number-input.tsx +211 -0
  339. package/src/components/numpad-sheet.tsx +264 -0
  340. package/src/components/page-contents.tsx +289 -0
  341. package/src/components/password-strength.tsx +258 -0
  342. package/src/components/picker-sheet.tsx +251 -0
  343. package/src/components/popover.tsx +198 -0
  344. package/src/components/search-field.tsx +146 -0
  345. package/src/components/series-chart-labels.ts +26 -0
  346. package/src/components/series-chart.tsx +481 -0
  347. package/src/components/settings-fields.tsx +68 -0
  348. package/src/components/signature-pad.tsx +630 -0
  349. package/src/components/slider.tsx +313 -0
  350. package/src/components/sparkline.tsx +329 -0
  351. package/src/components/stat-tile.tsx +448 -0
  352. package/src/components/swipeable-row.tsx +271 -0
  353. package/src/components/switch.tsx +170 -0
  354. package/src/components/time-input.tsx +107 -0
  355. package/src/components/toggle-group.tsx +153 -0
  356. package/src/components/toggle-legend.tsx +229 -0
  357. package/src/components/tooltip.tsx +477 -0
  358. package/src/components/treemap.tsx +390 -0
  359. package/src/components/trigger-aria.ts +42 -0
  360. package/src/components/ui.tsx +1295 -0
  361. package/src/components/use-mobile-reveal.ts +54 -0
  362. package/src/components/use-table-state.ts +295 -0
  363. package/src/components/user-avatar.tsx +61 -0
  364. package/src/components/wizard-stepper.tsx +37 -0
  365. package/src/data-table.ts +19 -0
  366. package/src/feedback/feedback-attachment.tsx +246 -0
  367. package/src/feedback/feedback-dialog.tsx +209 -0
  368. package/src/feedback/feedback-inbox.tsx +615 -0
  369. package/src/feedback.ts +8 -0
  370. package/src/hooks/use-anchored-panel.ts +169 -0
  371. package/src/hooks/use-anchored-rect.ts +78 -0
  372. package/src/hooks/use-announce.ts +85 -0
  373. package/src/hooks/use-body-scroll-lock.ts +94 -0
  374. package/src/hooks/use-close-transition.ts +99 -0
  375. package/src/hooks/use-dismiss.ts +77 -0
  376. package/src/hooks/use-focus-trap.ts +160 -0
  377. package/src/hooks/use-media-query.ts +23 -0
  378. package/src/hooks/use-overlay-history.ts +345 -0
  379. package/src/hooks/use-row-swipe.ts +212 -0
  380. package/src/i18n/defaults.ts +68 -0
  381. package/src/i18n/kit-labels.tsx +447 -0
  382. package/src/index.ts +169 -0
  383. package/src/lib/calc.ts +309 -0
  384. package/src/lib/cn.ts +5 -0
  385. package/src/lib/dates.ts +187 -0
  386. package/src/lib/logger.ts +73 -0
  387. package/src/lib/safe-storage.ts +37 -0
  388. package/src/search/command-palette.tsx +342 -0
  389. package/src/search.ts +3 -0
  390. package/src/shell/app-shell.tsx +772 -0
  391. package/src/shell/option-switcher-menu.tsx +72 -0
  392. package/src/shell/role-switcher.tsx +46 -0
  393. package/src/shell/top-bar.tsx +39 -0
  394. package/src/shell/topbar-action-menu.tsx +91 -0
  395. package/src/shell/topbar-controls.tsx +229 -0
  396. package/src/shell.ts +10 -0
  397. package/src/theme/chart-palette.ts +145 -0
  398. package/src/theme/color.ts +266 -0
  399. package/src/theme/palette-derive.ts +681 -0
  400. package/src/theme/palette-presets.ts +760 -0
  401. package/src/theme/palette-store.ts +94 -0
  402. package/src/theme/theme-store.ts +145 -0
  403. package/src/tour/tour.tsx +586 -0
  404. package/src/tour.ts +3 -0
  405. package/src/vite-env.d.ts +26 -0
  406. package/src/wizard/stepper-nav.tsx +221 -0
  407. package/src/wizard/types.ts +178 -0
  408. package/src/wizard/use-wizard.ts +345 -0
  409. package/src/wizard/validation.ts +37 -0
  410. package/src/wizard/wizard-context.tsx +29 -0
  411. package/src/wizard/wizard-step.tsx +14 -0
  412. package/src/wizard/wizard-summary.tsx +69 -0
  413. package/src/wizard.ts +14 -0
  414. package/tokens.css +222 -20
@@ -0,0 +1,584 @@
1
+ import { forwardRef, useId, useRef, useState } from "react";
2
+ import type { ComponentPropsWithoutRef, KeyboardEvent, MouseEvent, ReactNode } from "react";
3
+ import { X } from "lucide-react";
4
+ import type { LucideIcon } from "lucide-react";
5
+ import { cn } from "../lib/cn";
6
+ import { FIELD_INVALID } from "./ui";
7
+ import { DEFAULT_COMMON_LABELS, useKitLabels, useKitLocale } from "../i18n/kit-labels";
8
+
9
+ /**
10
+ * A chip: a compact pill carrying one value.
11
+ *
12
+ * Three jobs, deliberately one component. A chip can be inert (a tag on a row), a link
13
+ * (a jump to a section), or a toggle (a filter that is on or off) — and the difference is
14
+ * which prop you pass, not which component you pick. Keeping them together is what stops
15
+ * an app growing three near-identical pills that drift apart; it is the shape this kit
16
+ * already uses for `Button`, which is a link when it is given an href.
17
+ *
18
+ * A chip is not a `Button`. It is smaller, it is rounded to a pill, and it reads as a
19
+ * VALUE rather than as an action — which matters because a row of eight buttons says
20
+ * "choose one of eight things to do" and a row of eight chips says "here are eight
21
+ * things". Using `Button` for both is the mistake this exists to prevent.
22
+ */
23
+
24
+ export type ChipTone = "neutral" | "brand" | "danger" | "warning" | "success" | "info";
25
+ export type ChipSize = "sm" | "md";
26
+
27
+ const TONE: Record<ChipTone, { idle: string; selected: string }> = {
28
+ neutral: {
29
+ idle: "border-[var(--border)] bg-[var(--bg-surface-2)] text-[var(--text-secondary)]",
30
+ selected: "border-[var(--border-strong)] bg-[var(--bg-active)] text-[var(--text-primary)]",
31
+ },
32
+ brand: {
33
+ idle: "border-[var(--border)] bg-[var(--brand-bg)] text-[var(--brand-muted)]",
34
+ selected: "border-[var(--brand)] bg-[var(--brand)] text-[var(--brand-contrast)]",
35
+ },
36
+ danger: {
37
+ idle: "border-[var(--danger-border)] bg-[var(--danger-bg)] text-[var(--danger)]",
38
+ selected: "border-[var(--danger)] bg-[var(--danger)] text-[var(--danger-contrast)]",
39
+ },
40
+ warning: {
41
+ idle: "border-[var(--warning-border)] bg-[var(--warning-bg)] text-[var(--warning)]",
42
+ selected: "border-[var(--warning)] bg-[var(--warning-bg)] text-[var(--warning)]",
43
+ },
44
+ success: {
45
+ idle: "border-[var(--success-border)] bg-[var(--success-bg)] text-[var(--success)]",
46
+ selected: "border-[var(--success)] bg-[var(--success-bg)] text-[var(--success)]",
47
+ },
48
+ info: {
49
+ idle: "border-[var(--info-border)] bg-[var(--info-bg)] text-[var(--info)]",
50
+ selected: "border-[var(--info)] bg-[var(--info-bg)] text-[var(--info)]",
51
+ },
52
+ };
53
+
54
+ const SIZE: Record<ChipSize, { body: string; icon: string; remove: string }> = {
55
+ sm: { body: "gap-1 px-2 py-0.5 text-xs", icon: "size-3", remove: "size-3" },
56
+ md: { body: "gap-1.5 px-2.5 py-1 text-sm", icon: "size-3.5", remove: "size-3.5" },
57
+ };
58
+
59
+ const CHIP_BASE =
60
+ "inline-flex max-w-full items-center rounded-full border transition-colors " +
61
+ // `focus-visible`, not `focus`: a chip commonly receives focus programmatically (the
62
+ // ChipInput moves focus onto one after a removal) and a ring that appears on a
63
+ // pointer click reads as a stuck selection.
64
+ "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--brand)] focus-visible:ring-offset-1 focus-visible:ring-offset-[var(--bg-surface)]";
65
+
66
+ export interface ChipProps {
67
+ children: ReactNode;
68
+ tone?: ChipTone;
69
+ size?: ChipSize;
70
+ icon?: LucideIcon;
71
+ /**
72
+ * Marks the chip as the current one — `aria-current` on a link, `aria-pressed` on a
73
+ * toggle.
74
+ *
75
+ * On a toggle, keep the LABEL the same in both states and let `selected` carry the
76
+ * state. A label that flips with it ("Skip this month" / "Ask again this month") is
77
+ * announced together with "pressed", and then says the opposite of what it does.
78
+ */
79
+ selected?: boolean;
80
+ /** Renders the chip as a link. Mutually exclusive with `onClick`. */
81
+ href?: string;
82
+ /** Renders the chip as a toggle button. Mutually exclusive with `href`. Receives the
83
+ * click, so a chip inside a clickable row can `stopPropagation()`. */
84
+ onClick?: (event: MouseEvent<HTMLButtonElement>) => void;
85
+ /** Renders a dismiss affordance. Works alongside `href`/`onClick` — see the note below. */
86
+ onRemove?: () => void;
87
+ /** Accessible name for the dismiss button. Default: `common.remove` from the
88
+ * {@link UiKitProvider}, else "Remove". */
89
+ removeLabel?: string;
90
+ disabled?: boolean;
91
+ className?: string;
92
+ /**
93
+ * Roving focus, for a container that manages a row of chips (see {@link ChipInput}).
94
+ * A chip with no `href`/`onClick` is inert and unfocusable by default; give it a
95
+ * `tabIndex` and a `role` and it becomes the thing arrow keys move between.
96
+ */
97
+ tabIndex?: number;
98
+ role?: string;
99
+ onKeyDown?: (e: KeyboardEvent<HTMLElement>) => void;
100
+ onFocus?: () => void;
101
+ /** Accessible name, when the visible text is not the whole story. */
102
+ "aria-label"?: string;
103
+ /** Any other ARIA attribute — `aria-describedby`, `aria-expanded`, `aria-controls`,
104
+ * `aria-haspopup` — reaches the chip's interactive element. */
105
+ [key: `aria-${string}`]: string | boolean | number | undefined;
106
+ /** A test id, a `data-tour` anchor, or any other data attribute. */
107
+ [key: `data-${string}`]: unknown;
108
+ id?: string;
109
+ /** A native tooltip. For anything a user must read, prefer the kit's `Tooltip`. */
110
+ title?: string;
111
+ }
112
+
113
+ /**
114
+ * Note on `onRemove` with `href`/`onClick`: a button cannot be nested inside a button or
115
+ * a link, so when both are present the chip renders a wrapper holding TWO siblings — the
116
+ * interactive body and the dismiss control. That is why the outer element is not always
117
+ * the interactive one, and why the focus ring is drawn on the body rather than the
118
+ * wrapper.
119
+ */
120
+ export const Chip = forwardRef<HTMLElement, ChipProps>(function Chip(
121
+ {
122
+ children,
123
+ tone = "neutral",
124
+ size = "md",
125
+ icon: Icon,
126
+ selected = false,
127
+ href,
128
+ onClick,
129
+ onRemove,
130
+ removeLabel,
131
+ disabled = false,
132
+ className,
133
+ tabIndex,
134
+ role,
135
+ onKeyDown,
136
+ onFocus,
137
+ ...rest
138
+ },
139
+ ref,
140
+ ) {
141
+ const common = useKitLabels("common", DEFAULT_COMMON_LABELS, { remove: removeLabel });
142
+ const s = SIZE[size];
143
+ const palette = TONE[tone];
144
+ const interactive = !!href || !!onClick;
145
+ const look = cn(
146
+ CHIP_BASE,
147
+ s.body,
148
+ selected ? palette.selected : palette.idle,
149
+ interactive && !disabled && "cursor-pointer hover:brightness-[0.97] dark:hover:brightness-110",
150
+ disabled && "cursor-default opacity-50",
151
+ className,
152
+ );
153
+
154
+ const body = (
155
+ <>
156
+ {Icon && <Icon className={cn(s.icon, "shrink-0")} aria-hidden />}
157
+ <span className="min-w-0 truncate">{children}</span>
158
+ </>
159
+ );
160
+
161
+ const remove = onRemove ? (
162
+ <button
163
+ type="button"
164
+ // The name carries WHAT is being removed, not just "Remove" — a screen-reader user
165
+ // tabbing a row of eight dismiss buttons otherwise hears the same word eight times
166
+ // with no way to tell which one they are on.
167
+ // Composed through `common.fieldValue` because the punctuation between the two
168
+ // halves is the language's, not ours. A chip whose content is not plain text
169
+ // has no value to name, and gets the bare verb rather than a dangling colon.
170
+ aria-label={
171
+ typeof children === "string" && children
172
+ ? common.fieldValue(common.remove, children)
173
+ : common.remove
174
+ }
175
+ onClick={(e) => {
176
+ // The chip may itself be a link; removing it must not also follow it.
177
+ e.preventDefault();
178
+ e.stopPropagation();
179
+ onRemove();
180
+ }}
181
+ disabled={disabled}
182
+ className={cn(
183
+ "-mr-0.5 ml-0.5 shrink-0 rounded-full p-0.5 transition-colors",
184
+ "hover:bg-[var(--bg-active)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--brand)]",
185
+ disabled && "pointer-events-none",
186
+ )}
187
+ >
188
+ <X className={s.remove} aria-hidden />
189
+ </button>
190
+ ) : null;
191
+
192
+ // ── The three shapes.
193
+ if (href && !disabled) {
194
+ const link = (
195
+ <a
196
+ ref={ref as React.Ref<HTMLAnchorElement>}
197
+ href={href}
198
+ aria-current={selected ? "true" : undefined}
199
+ className={cn(look, remove && "pr-1.5")}
200
+ {...rest}
201
+ >
202
+ {body}
203
+ {!remove && null}
204
+ </a>
205
+ );
206
+ return remove ? (
207
+ <span className="inline-flex items-center">
208
+ {link}
209
+ {remove}
210
+ </span>
211
+ ) : (
212
+ link
213
+ );
214
+ }
215
+
216
+ if (onClick) {
217
+ const button = (
218
+ <button
219
+ ref={ref as React.Ref<HTMLButtonElement>}
220
+ type="button"
221
+ onClick={onClick}
222
+ disabled={disabled}
223
+ aria-pressed={selected}
224
+ className={cn(look, remove && "pr-1.5")}
225
+ {...rest}
226
+ >
227
+ {body}
228
+ </button>
229
+ );
230
+ return remove ? (
231
+ <span className="inline-flex items-center">
232
+ {button}
233
+ {remove}
234
+ </span>
235
+ ) : (
236
+ button
237
+ );
238
+ }
239
+
240
+ return (
241
+ <span
242
+ ref={ref as React.Ref<HTMLSpanElement>}
243
+ className={look}
244
+ tabIndex={tabIndex}
245
+ role={role}
246
+ onKeyDown={onKeyDown}
247
+ onFocus={onFocus}
248
+ {...rest}
249
+ >
250
+ {body}
251
+ {remove}
252
+ </span>
253
+ );
254
+ });
255
+
256
+ /* ── ChipInput ────────────────────────────────────────────────────────────── */
257
+
258
+ export interface ChipInputLabels {
259
+ /** Announced after a value is added. Receives the value. */
260
+ added: (value: string) => string;
261
+ /** Announced after a value is removed. Receives the value. */
262
+ removed: (value: string) => string;
263
+ /** Accessible name for each chip's dismiss button. */
264
+ remove: string;
265
+ /** Shown when `max` is reached. Receives the limit. */
266
+ atLimit: (max: number) => string;
267
+ /** Shown when a duplicate is rejected. Receives the value. */
268
+ duplicate: (value: string) => string;
269
+ }
270
+
271
+ export const DEFAULT_CHIP_INPUT_LABELS: ChipInputLabels = {
272
+ added: (v) => `${v} added`,
273
+ removed: (v) => `${v} removed`,
274
+ remove: "Remove",
275
+ atLimit: (max) => `Limit of ${max} reached`,
276
+ duplicate: (v) => `${v} is already in the list`,
277
+ };
278
+
279
+ export function resolveChipInputLabels(labels?: Partial<ChipInputLabels>): ChipInputLabels {
280
+ return labels ? { ...DEFAULT_CHIP_INPUT_LABELS, ...labels } : DEFAULT_CHIP_INPUT_LABELS;
281
+ }
282
+
283
+ /**
284
+ * `onChange` is the field's own — the whole LIST, not a DOM event — so the wrapper
285
+ * div's `onChange` is omitted rather than shadowed. `placeholder` is likewise this
286
+ * component's, forwarded to the inner `<input>`; the div has none of its own.
287
+ */
288
+ export interface ChipInputProps
289
+ extends Omit<ComponentPropsWithoutRef<"div">, "onChange" | "placeholder" | "children"> {
290
+ value: string[];
291
+ onChange: (next: string[]) => void;
292
+ placeholder?: string;
293
+ /** Visible label, rendered above the field. Without one, name the field with
294
+ * `aria-label`. */
295
+ label?: string;
296
+ /**
297
+ * @deprecated Pass `aria-label` instead — the DOM spelling the rest of this kit
298
+ * now uses. Still honoured, and still second to `aria-label` when both are given.
299
+ */
300
+ ariaLabel?: string;
301
+ /** Reject or rewrite a value on commit. Return a string to reject WITH that message. */
302
+ validate?: (raw: string) => string | null;
303
+ /** Characters that commit the current text, besides Enter. Default: comma. */
304
+ separators?: string[];
305
+ allowDuplicates?: boolean;
306
+ max?: number;
307
+ tone?: ChipTone;
308
+ size?: ChipSize;
309
+ disabled?: boolean;
310
+ invalid?: boolean;
311
+ /** Error text. Wires `aria-describedby` and implies `invalid`. */
312
+ error?: ReactNode;
313
+ labels?: Partial<ChipInputLabels>;
314
+ className?: string;
315
+ }
316
+
317
+ /**
318
+ * A field whose value is a LIST, entered as chips.
319
+ *
320
+ * The keyboard model is the whole component; the pills are the easy part. Per the WAI
321
+ * pattern for a "tag" input:
322
+ *
323
+ * Enter, or any separator commit the typed text
324
+ * Backspace on empty text move focus to the last chip (does NOT delete it)
325
+ * ← → while on a chip move between chips
326
+ * Backspace / Delete remove the focused chip, focus its neighbour
327
+ * Escape clear what is typed but keep the committed chips
328
+ * paste splits on the separators, so a pasted CSV becomes chips
329
+ *
330
+ * The Backspace-on-empty behaviour is the one worth arguing about. Deleting immediately
331
+ * is more common and is a trap: it is a destructive action with no feedback on a key
332
+ * people hit by reflex, and the value it destroys may have taken a while to type. Moving
333
+ * focus first makes the second Backspace a deliberate one, and it is what lets a
334
+ * keyboard user reach a chip at all.
335
+ */
336
+ export function ChipInput({
337
+ value,
338
+ onChange,
339
+ placeholder,
340
+ label,
341
+ ariaLabel,
342
+ validate,
343
+ separators = [","],
344
+ allowDuplicates = false,
345
+ max,
346
+ tone = "neutral",
347
+ size = "md",
348
+ disabled = false,
349
+ invalid = false,
350
+ error,
351
+ labels,
352
+ className,
353
+ "aria-label": ariaLabelAttr,
354
+ ...rest
355
+ }: ChipInputProps) {
356
+ // `labels` over the provider's `chipInput` over English — the same order
357
+ // `resolveChipInputLabels` gives outside a provider.
358
+ const text = useKitLabels("chipInput", DEFAULT_CHIP_INPUT_LABELS, labels);
359
+ // A batch of pasted values is announced as one list, joined the way the language
360
+ // joins a list in a sentence ("a, b and c added") — hence the long conjunction,
361
+ // where a trigger's summary would use the narrow one.
362
+ const locale = useKitLocale();
363
+ const [draft, setDraft] = useState("");
364
+ const [message, setMessage] = useState("");
365
+ const [focusedChip, setFocusedChip] = useState<number | null>(null);
366
+ const inputRef = useRef<HTMLInputElement>(null);
367
+ const chipRefs = useRef<Array<HTMLElement | null>>([]);
368
+ const id = useId();
369
+ const listId = `${id}-list`;
370
+ const errorId = `${id}-error`;
371
+ const isInvalid = invalid || !!error;
372
+
373
+ const focusChip = (index: number | null) => {
374
+ setFocusedChip(index);
375
+ if (index === null) inputRef.current?.focus();
376
+ else chipRefs.current[index]?.focus();
377
+ };
378
+
379
+ /**
380
+ * Try to add every candidate, as ONE change.
381
+ *
382
+ * Batched rather than looped for a reason that bites immediately: `commit` closes over
383
+ * `value`, so calling it once per pasted item makes every call compute its result from
384
+ * the list as it was BEFORE the paste, and each `onChange` overwrites the last. A
385
+ * pasted "one,two,three" left only "three". Accumulating locally and emitting once is
386
+ * also the correct behaviour for an undo stack — a paste is one action.
387
+ */
388
+ const commitMany = (raws: string[]): { added: string[]; rejection: string | null } => {
389
+ const next = [...value];
390
+ const added: string[] = [];
391
+ let rejection: string | null = null;
392
+
393
+ for (const raw of raws) {
394
+ const candidate = raw.trim();
395
+ if (!candidate) continue;
396
+ if (max !== undefined && next.length >= max) {
397
+ rejection ??= text.atLimit(max);
398
+ break;
399
+ }
400
+ if (!allowDuplicates && next.includes(candidate)) {
401
+ rejection ??= text.duplicate(candidate);
402
+ continue;
403
+ }
404
+ const invalidReason = validate?.(candidate);
405
+ if (invalidReason) {
406
+ rejection ??= invalidReason;
407
+ continue;
408
+ }
409
+ next.push(candidate);
410
+ added.push(candidate);
411
+ }
412
+
413
+ if (added.length) onChange(next);
414
+ // A rejection is the more useful thing to say: "three added" is obvious from the
415
+ // chips appearing, whereas "already in the list" is the only sign of what did not.
416
+ const addedList = new Intl.ListFormat(locale, { type: "conjunction", style: "long" });
417
+ setMessage(rejection ?? (added.length ? text.added(addedList.format(added)) : ""));
418
+ return { added, rejection };
419
+ };
420
+
421
+ const commit = (raw: string): boolean => commitMany([raw]).added.length > 0;
422
+
423
+ const removeAt = (index: number) => {
424
+ const removed = value[index];
425
+ onChange(value.filter((_, i) => i !== index));
426
+ setMessage(text.removed(removed));
427
+ // Focus the neighbour that takes its place, or the input when the list empties —
428
+ // dropping focus to <body> here is how a keyboard user loses the field entirely.
429
+ const next = index >= value.length - 1 ? null : index;
430
+ requestAnimationFrame(() => focusChip(value.length - 1 === 0 ? null : next));
431
+ };
432
+
433
+ const onInputKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {
434
+ if (e.key === "Enter") {
435
+ // Only when there is something to commit: an empty Enter belongs to the form.
436
+ if (draft.trim()) {
437
+ e.preventDefault();
438
+ if (commit(draft)) setDraft("");
439
+ }
440
+ return;
441
+ }
442
+ if (separators.includes(e.key)) {
443
+ e.preventDefault();
444
+ if (commit(draft)) setDraft("");
445
+ return;
446
+ }
447
+ if (e.key === "Escape" && draft) {
448
+ e.preventDefault();
449
+ setDraft("");
450
+ return;
451
+ }
452
+ if (e.key === "Backspace" && !draft && value.length) {
453
+ e.preventDefault();
454
+ focusChip(value.length - 1);
455
+ }
456
+ };
457
+
458
+ const onChipKeyDown = (e: KeyboardEvent<HTMLElement>, index: number) => {
459
+ if (e.key === "Backspace" || e.key === "Delete") {
460
+ e.preventDefault();
461
+ removeAt(index);
462
+ return;
463
+ }
464
+ if (e.key === "ArrowLeft" && index > 0) {
465
+ e.preventDefault();
466
+ focusChip(index - 1);
467
+ return;
468
+ }
469
+ if (e.key === "ArrowRight") {
470
+ e.preventDefault();
471
+ focusChip(index === value.length - 1 ? null : index + 1);
472
+ return;
473
+ }
474
+ if (e.key === "Escape") {
475
+ e.preventDefault();
476
+ focusChip(null);
477
+ }
478
+ };
479
+
480
+ return (
481
+ // The rest lands on the OUTER box — the thing a `data-tour` step or a test id
482
+ // wants to point at — while the accessible name below goes on the `<input>`,
483
+ // because that is what a screen-reader user actually lands in. Spreading the two
484
+ // to the same element would have named a decorative wrapper and left the field
485
+ // anonymous.
486
+ <div {...rest} className={cn("space-y-1", className)}>
487
+ {label && (
488
+ <label htmlFor={`${id}-input`} className="block text-sm text-[var(--text-secondary)]">
489
+ {label}
490
+ </label>
491
+ )}
492
+ <div
493
+ // `relative` so the live region below can be `sr-only` without escaping to the
494
+ // initial containing block and inflating the document height.
495
+ className={cn(
496
+ "relative flex flex-wrap items-center gap-1.5 rounded-md border border-[var(--border)] bg-[var(--bg-surface)] px-2 py-1.5 shadow-sm",
497
+ "focus-within:border-[var(--brand)] focus-within:ring-1 focus-within:ring-[var(--brand)]",
498
+ disabled && "cursor-default bg-[var(--bg-surface-2)]",
499
+ isInvalid && FIELD_INVALID,
500
+ )}
501
+ onClick={() => !disabled && inputRef.current?.focus()}
502
+ >
503
+ {/* `display: contents` on the wrappers so the chips participate in the field's
504
+ own flex wrap rather than forming a nested row. The list semantics are
505
+ restored with explicit roles, because `contents` removes the ul/li boxes from
506
+ the accessibility tree in several engines. */}
507
+ {/* eslint-disable-next-line jsx-a11y/no-redundant-roles -- NOT redundant here: the
508
+ `contents` display below removes the ul and li boxes from the box tree, and
509
+ several engines drop the list semantics with them. The explicit role is what
510
+ puts "list, 3 items" back. */}
511
+ <ul id={listId} role="list" className="contents">
512
+ {value.map((v, i) => (
513
+ <li key={`${v}-${i}`} role="presentation" className="contents">
514
+ <Chip
515
+ ref={(el: HTMLElement | null) => {
516
+ chipRefs.current[i] = el;
517
+ }}
518
+ tone={tone}
519
+ size={size}
520
+ disabled={disabled}
521
+ removeLabel={text.remove}
522
+ onRemove={disabled ? undefined : () => removeAt(i)}
523
+ // A ROVING tabIndex: only the focused chip is tabbable, so Tab leaves
524
+ // the field instead of walking through every value in it — the reason a
525
+ // list of twenty tags is otherwise a twenty-stop detour for a keyboard.
526
+ tabIndex={focusedChip === i ? 0 : -1}
527
+ role="listitem"
528
+ aria-label={v}
529
+ onKeyDown={(e) => onChipKeyDown(e, i)}
530
+ onFocus={() => setFocusedChip(i)}
531
+ data-chip-index={i}
532
+ >
533
+ {v}
534
+ </Chip>
535
+ </li>
536
+ ))}
537
+ </ul>
538
+ <input
539
+ id={`${id}-input`}
540
+ ref={inputRef}
541
+ value={draft}
542
+ onChange={(e) => {
543
+ setDraft(e.target.value);
544
+ setMessage("");
545
+ }}
546
+ onKeyDown={onInputKeyDown}
547
+ onBlur={() => {
548
+ // Commit on blur: a value typed and then clicked away from is a value the
549
+ // user meant to add, and losing it silently is the commonest complaint
550
+ // about this pattern.
551
+ if (draft.trim() && commit(draft)) setDraft("");
552
+ }}
553
+ onPaste={(e) => {
554
+ const pasted = e.clipboardData.getData("text");
555
+ const pattern = new RegExp(`[${separators.map((s) => `\\${s}`).join("")}\n\r]`);
556
+ if (!pattern.test(pasted)) return;
557
+ e.preventDefault();
558
+ if (commitMany(pasted.split(pattern)).added.length) setDraft("");
559
+ }}
560
+ placeholder={value.length ? undefined : placeholder}
561
+ disabled={disabled}
562
+ // A visible `label` is already wired through `htmlFor`, so adding a name
563
+ // here would give the field two. Failing that, the DOM spelling wins and
564
+ // the deprecated `ariaLabel` is the fallback.
565
+ aria-label={label ? undefined : (ariaLabelAttr ?? ariaLabel)}
566
+ aria-describedby={error ? errorId : undefined}
567
+ aria-invalid={isInvalid || undefined}
568
+ className="min-w-[6rem] flex-1 bg-transparent py-0.5 text-sm text-[var(--text-primary)] outline-none placeholder:text-[var(--text-placeholder)] disabled:cursor-default"
569
+ />
570
+ {/* Additions, removals and rejections move no focus, so nothing would announce
571
+ them. `sr-only-fixed` rather than `sr-only`: this sits inside a consumer's
572
+ markup and must not extend the document height. */}
573
+ <span role="status" aria-live="polite" aria-atomic className="sr-only-fixed">
574
+ {message}
575
+ </span>
576
+ </div>
577
+ {error && (
578
+ <p id={errorId} className="text-xs text-[var(--danger)]">
579
+ {error}
580
+ </p>
581
+ )}
582
+ </div>
583
+ );
584
+ }
@@ -0,0 +1,33 @@
1
+ import type { ReactNode, Ref } from "react";
2
+
3
+ /**
4
+ * Small pieces the native choice controls (`Checkbox`, `Switch`) share. Private to
5
+ * the package — not re-exported from the barrel.
6
+ *
7
+ * `mergeDescribedBy` and `hasMessage` restate two rules ui.tsx's `useFieldError`
8
+ * keeps for Input/Select/Textarea; that hook is module-private and shaped around a
9
+ * single error node, while these controls also describe themselves with a
10
+ * `description`, so they compose the ids themselves under the same rules.
11
+ */
12
+
13
+ /** Ids to describe the control by, merged in reading order: whatever the caller
14
+ * already pointed at (standing advice), then the description, then the error (the
15
+ * news). Merge, never replace — the rule ui.tsx's `useFieldError` keeps for Input.
16
+ * An empty list is `undefined`, never `""`: a dangling attribute describes the
17
+ * control as nothing at all. */
18
+ export function mergeDescribedBy(...ids: Array<string | false | null | undefined>): string | undefined {
19
+ const list = ids.filter(Boolean);
20
+ return list.length ? list.join(" ") : undefined;
21
+ }
22
+
23
+ /** `null`, `false` and `""` are what `touched && errors.x` evaluates to on the happy
24
+ * path. None of them is a message. */
25
+ export function hasMessage(node: ReactNode): boolean {
26
+ return node !== undefined && node !== null && node !== false && node !== "";
27
+ }
28
+
29
+ /** Point a forwarded ref and a local one at the same node. */
30
+ export function assignRef<T>(ref: Ref<T> | undefined, node: T | null) {
31
+ if (typeof ref === "function") ref(node);
32
+ else if (ref) (ref as { current: T | null }).current = node;
33
+ }