@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
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/multi-select.tsx"],"sourcesContent":["import { useMemo } from \"react\";\nimport type { ReactNode } from \"react\";\nimport { Check } from \"lucide-react\";\nimport { FieldChevron, FieldLabel, FIELD_TRIGGER, FIELD_INVALID, FIELD_FLOATING_PAD } from \"./ui\";\nimport { cn } from \"../lib/cn\";\nimport { DropdownPanel, DropdownSearchHeader, useDropdownSearch } from \"./dropdown\";\n\nexport interface MultiSelectOption {\n value: string | number;\n label: string;\n hint?: string;\n}\n\ninterface Props {\n options: MultiSelectOption[];\n values: (string | number)[];\n onChange: (next: (string | number)[]) => void;\n /** Displayed when no value is selected (i.e. \"all\"). Defaults to \"All\"; pass a\n * translated string for i18n. */\n allLabel?: string;\n /** Singular/plural countable label, used when 1+ items are selected. */\n itemLabel?: (count: number) => string;\n placeholder?: string;\n /** Embedded top-boundary label, matching the native Input/Select fields. */\n label?: ReactNode;\n /** Search-box placeholder (default \"Search\"). */\n searchLabel?: string;\n /** \"Select all\" action label (default \"Select all\"). */\n selectAllLabel?: string;\n /** \"Clear\" action label (default \"Clear\"). */\n clearLabel?: string;\n className?: string;\n /** Extra classes for the open dropdown PANEL — the way to widen it past its\n * 16rem default when the rows carry more than a label (Keksdose feedback #147). */\n panelClassName?: string;\n /** Required and unanswered — {@link FIELD_INVALID}, the same rose border the\n * native `Select` has worn since feedback #235. Every field-styled control in\n * this package carries it now, so a form can mark any of its fields rather than\n * only the one that happened to have it first. */\n invalid?: boolean;\n}\n\nexport function MultiSelect({\n options,\n values,\n onChange,\n allLabel,\n itemLabel,\n placeholder,\n label,\n searchLabel = \"Search\",\n selectAllLabel = \"Select all\",\n clearLabel = \"Clear\",\n className,\n panelClassName,\n invalid,\n}: Props) {\n const { open, setOpen, wrapperRef, query, setQuery, inputRef } = useDropdownSearch();\n\n const filtered = useMemo(() => {\n const q = query.trim().toLowerCase();\n if (!q) return options;\n return options.filter(\n (o) =>\n o.label.toLowerCase().includes(q) ||\n (o.hint ?? \"\").toLowerCase().includes(q),\n );\n }, [options, query]);\n\n const valueSet = useMemo(() => new Set(values), [values]);\n const allChecked = options.length > 0 && options.every((o) => valueSet.has(o.value));\n const anyChecked = values.length > 0;\n const selectedSummary = (() => {\n if (!anyChecked) return allLabel ?? placeholder ?? \"All\";\n if (allChecked) return allLabel ?? placeholder ?? \"All\";\n return itemLabel ? itemLabel(values.length) : `${values.length}`;\n })();\n\n const toggle = (val: string | number) => {\n if (valueSet.has(val)) onChange(values.filter((v) => v !== val));\n else onChange([...values, val]);\n };\n\n const selectAll = () => onChange(options.map((o) => o.value));\n const clearAll = () => onChange([]);\n\n return (\n <div ref={wrapperRef} className={cn(\"relative\", className)}>\n {label !== undefined && <FieldLabel>{label}</FieldLabel>}\n <button\n type=\"button\"\n onClick={() => setOpen((v) => !v)}\n aria-invalid={invalid || undefined}\n className={cn(FIELD_TRIGGER, \"pr-9\", label !== undefined && FIELD_FLOATING_PAD, invalid && FIELD_INVALID)}\n >\n {/* The summary IS the field's value, so it inherits FIELD_BASE's ink rather\n than restating a lighter one (Keksdose dev#477). */}\n <span className=\"truncate\">{selectedSummary}</span>\n <FieldChevron />\n </button>\n {open && (\n <DropdownPanel\n // 16rem by default; `panelClassName` is how a caller widens it (Keksdose\n // feedback #147: the market picker's rows carry a postcode, a town, a\n // distance and a receipt count, all of which were being truncated). The\n // override used to be applied from the OUTSIDE with a\n // `[&>div]:w-full` descendant selector, which worked and was a hack —\n // \"change the package\" was the right call.\n className={cn(\"w-64\", panelClassName)}\n empty={filtered.length === 0}\n header={\n <>\n <DropdownSearchHeader\n query={query}\n onQueryChange={setQuery}\n inputRef={inputRef}\n placeholder={searchLabel}\n />\n <div className=\"flex items-center justify-between gap-2 px-2 py-1.5 text-xs\">\n <button\n type=\"button\"\n onClick={selectAll}\n disabled={allChecked}\n className=\"rounded px-2 py-0.5 text-slate-600 hover:bg-slate-100 disabled:opacity-40 dark:text-slate-300 dark:hover:bg-slate-800\"\n >\n {selectAllLabel}\n </button>\n <button\n type=\"button\"\n onClick={clearAll}\n disabled={!anyChecked}\n className=\"rounded px-2 py-0.5 text-slate-600 hover:bg-slate-100 disabled:opacity-40 dark:text-slate-300 dark:hover:bg-slate-800\"\n >\n {clearLabel}\n </button>\n </div>\n </>\n }\n >\n {filtered.map((o) => {\n const checked = valueSet.has(o.value);\n return (\n <li key={o.value}>\n <button\n type=\"button\"\n onClick={() => toggle(o.value)}\n className={cn(\n \"flex w-full items-center justify-between gap-2 px-3 py-1.5 text-sm text-left hover:bg-slate-50 dark:hover:bg-slate-800\",\n checked && \"bg-slate-100/60 dark:bg-slate-800/60\",\n )}\n >\n <span className=\"flex items-center gap-2 min-w-0\">\n <span\n className={cn(\n \"flex size-4 shrink-0 items-center justify-center rounded border\",\n checked\n ? \"border-slate-900 bg-slate-900 text-white dark:border-slate-100 dark:bg-slate-100 dark:text-slate-900\"\n : \"border-slate-300 bg-white dark:border-slate-600 dark:bg-slate-900\",\n )}\n >\n {checked && <Check className=\"size-3\" />}\n </span>\n <span className=\"truncate text-slate-900 dark:text-slate-100\">{o.label}</span>\n {o.hint && (\n <span className=\"truncate text-xs text-slate-400 dark:text-slate-500\">\n {o.hint}\n </span>\n )}\n </span>\n </button>\n </li>\n );\n })}\n </DropdownPanel>\n )}\n </div>\n );\n}\n"],"mappings":"AAwF8B,SAuBlB,UAvBkB,KACxB,YADwB;AAxF9B,SAAS,eAAe;AAExB,SAAS,aAAa;AACtB,SAAS,cAAc,YAAY,eAAe,eAAe,0BAA0B;AAC3F,SAAS,UAAU;AACnB,SAAS,eAAe,sBAAsB,yBAAyB;AAqChE,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,cAAc;AAAA,EACd,iBAAiB;AAAA,EACjB,aAAa;AAAA,EACb;AAAA,EACA;AAAA,EACA;AACF,GAAU;AACR,QAAM,EAAE,MAAM,SAAS,YAAY,OAAO,UAAU,SAAS,IAAI,kBAAkB;AAEnF,QAAM,WAAW,QAAQ,MAAM;AAC7B,UAAM,IAAI,MAAM,KAAK,EAAE,YAAY;AACnC,QAAI,CAAC,EAAG,QAAO;AACf,W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{"version":3,"sources":["../../src/components/multi-select.tsx"],"sourcesContent":["import { useId, useMemo, useState } from \"react\";\nimport type {\n ComponentPropsWithoutRef,\n KeyboardEvent as ReactKeyboardEvent,\n ReactNode,\n} from \"react\";\nimport { Check } from \"lucide-react\";\nimport { FieldChevron, FieldLabel, FIELD_TRIGGER, FIELD_INVALID, FIELD_FLOATING_PAD } from \"./ui\";\nimport { cn } from \"../lib/cn\";\nimport { DropdownPanel, DropdownSearchHeader, useDropdownSearch } from \"./dropdown\";\nimport { useActiveOptionScroll } from \"./combobox-core\";\nimport {\n DEFAULT_COMMON_LABELS,\n DEFAULT_MULTI_SELECT_LABELS,\n useKitLabels,\n} from \"../i18n/kit-labels\";\n\nexport interface MultiSelectOption {\n value: string | number;\n label: string;\n hint?: string;\n}\n\n/** `onChange` is the kit's — \"the selection changed\", carrying the new values —\n * rather than the div's form event. */\nexport interface MultiSelectProps extends Omit<ComponentPropsWithoutRef<\"div\">, \"onChange\"> {\n options: MultiSelectOption[];\n values: (string | number)[];\n onChange: (next: (string | number)[]) => void;\n /** Displayed when no value is selected (i.e. \"all\"). Defaults to `placeholder`,\n * then to `multiSelect.all` from the {@link UiKitProvider}, then \"All\". */\n allLabel?: string;\n /** Singular/plural countable label, used when 1+ items are selected. Default:\n * `multiSelect.selectedCount` from the provider — the bare count in English. */\n itemLabel?: (count: number) => string;\n placeholder?: string;\n /** Embedded top-boundary label, matching the native Input/Select fields. */\n label?: ReactNode;\n /** Search-box placeholder. Default: `multiSelect.search` from the provider, else \"Search\". */\n searchLabel?: string;\n /** \"Select all\" action label. Default: `multiSelect.selectAll`, else \"Select all\". */\n selectAllLabel?: string;\n /** \"Clear\" action label. Default: `multiSelect.clear`, else \"Clear\". */\n clearLabel?: string;\n /** Extra classes for the open dropdown PANEL — the way to widen it past its\n * 16rem default when the rows carry more than a label (Keksdose feedback #147). */\n panelClassName?: string;\n /** Required and unanswered — {@link FIELD_INVALID}, the same rose border the\n * native `Select` has worn since feedback #235. Every field-styled control in\n * this package carries it now, so a form can mark any of its fields rather than\n * only the one that happened to have it first. */\n invalid?: boolean;\n}\n\nexport function MultiSelect({\n options,\n values,\n onChange,\n allLabel,\n itemLabel,\n placeholder,\n label,\n searchLabel,\n selectAllLabel,\n clearLabel,\n className,\n panelClassName,\n invalid,\n \"aria-label\": ariaLabel,\n ...rest\n}: MultiSelectProps) {\n const { open, setOpen, wrapperRef, triggerRef, closeToTrigger, query, setQuery, inputRef } =\n useDropdownSearch();\n // `allLabel` is deliberately NOT folded in here: between it and the provider's\n // `all` sits `placeholder`, which has always doubled as the \"nothing picked\" text,\n // and a caller who set it must keep seeing it.\n const labels = useKitLabels(\"multiSelect\", DEFAULT_MULTI_SELECT_LABELS, {\n search: searchLabel,\n selectAll: selectAllLabel,\n clear: clearLabel,\n selectedCount: itemLabel,\n });\n const common = useKitLabels(\"common\", DEFAULT_COMMON_LABELS);\n // One id per instance: `aria-controls` on the trigger names the list while the\n // list is still closed.\n const uid = useId();\n const listboxId = `${uid}-listbox`;\n const optionId = (index: number) => `${uid}-option-${index}`;\n // Which row the arrow keys are on. Reset from the handlers that change what the\n // list contains rather than from an effect — a render pass is not where this\n // decision belongs, and the two callers that move the list are right here.\n const [active, setActive] = useState(0);\n\n const filtered = useMemo(() => {\n const q = query.trim().toLowerCase();\n if (!q) return options;\n return options.filter(\n (o) =>\n o.label.toLowerCase().includes(q) ||\n (o.hint ?? \"\").toLowerCase().includes(q),\n );\n }, [options, query]);\n\n const valueSet = useMemo(() => new Set(values), [values]);\n const allChecked = options.length > 0 && options.every((o) => valueSet.has(o.value));\n const anyChecked = values.length > 0;\n const selectedSummary = (() => {\n if (!anyChecked || allChecked) return allLabel ?? placeholder ?? labels.all;\n return labels.selectedCount(values.length);\n })();\n\n const toggle = (val: string | number) => {\n if (valueSet.has(val)) onChange(values.filter((v) => v !== val));\n else onChange([...values, val]);\n };\n\n const selectAll = () => onChange(options.map((o) => o.value));\n const clearAll = () => onChange([]);\n\n const activeId = active >= 0 && active < filtered.length ? optionId(active) : undefined;\n useActiveOptionScroll(activeId);\n\n // The WAI-ARIA APG's listbox keyboard, handled on the search box because that is\n // where focus is while the panel is up. Escape is `useDropdown`'s, on the document.\n const onListKeyDown = (e: ReactKeyboardEvent<HTMLInputElement>) => {\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n setActive((i) => Math.min(i + 1, filtered.length - 1));\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n setActive((i) => Math.max(i - 1, 0));\n } else if (e.key === \"Home\") {\n e.preventDefault();\n setActive(0);\n } else if (e.key === \"End\") {\n e.preventDefault();\n setActive(filtered.length - 1);\n } else if (e.key === \"Enter\") {\n e.preventDefault();\n // Toggling keeps the panel open, exactly as clicking a row does: this control\n // exists to answer \"which of these\", which is rarely one of them.\n if (filtered[active]) toggle(filtered[active].value);\n } else if (e.key === \"Tab\") {\n e.preventDefault();\n closeToTrigger();\n }\n };\n\n return (\n // `rest` dresses the wrapper; the name belongs to the trigger below it, which is\n // the thing with a role. Spread FIRST so the ARIA the trigger composes, and the\n // handlers that open the list, cannot be replaced by accident from outside.\n <div {...rest} ref={wrapperRef} className={cn(\"relative\", className)}>\n {label !== undefined && <FieldLabel>{label}</FieldLabel>}\n <button\n ref={triggerRef}\n type=\"button\"\n // A combobox, not a bare button: this trigger carried `aria-invalid`, which\n // `button` does not support, so a required-and-empty filter painted its rose\n // border and announced nothing (ESLint's `role-supports-aria-props`, the\n // audit's §a11y). The role that describes it is the one that also supports\n // the attribute.\n role=\"combobox\"\n aria-expanded={open}\n aria-controls={listboxId}\n aria-haspopup=\"listbox\"\n // The label is a floating <span>, not a <label for>, so without this the\n // trigger announces only its summary — \"3 selected\", with nothing saying\n // three of WHAT. The label AND the summary, because `aria-label` replaces\n // the content rather than adding to it; the same composition its two\n // siblings use, so a form row of pickers reads the same way throughout.\n // A caller's own name wins: two filters labelled \"Accounts\" on one screen have\n // to be told apart, and only the caller knows by what.\n aria-label={\n ariaLabel ?? (typeof label === \"string\" ? common.fieldValue(label, selectedSummary) : undefined)\n }\n onClick={() => {\n setOpen((v) => !v);\n setActive(0);\n }}\n // Down/Up opens the list from the closed trigger, per the APG; Enter and\n // Space already do through the button's own click.\n onKeyDown={(e) => {\n if (e.key === \"ArrowDown\" || e.key === \"ArrowUp\") {\n e.preventDefault();\n setOpen(true);\n setActive(0);\n }\n }}\n aria-invalid={invalid || undefined}\n className={cn(FIELD_TRIGGER, \"pr-9\", label !== undefined && FIELD_FLOATING_PAD, invalid && FIELD_INVALID)}\n >\n {/* The summary IS the field's value, so it inherits FIELD_BASE's ink rather\n than restating a lighter one (Keksdose dev#477). */}\n <span className=\"truncate\">{selectedSummary}</span>\n <FieldChevron />\n </button>\n {open && (\n <DropdownPanel\n // 16rem by default; `panelClassName` is how a caller widens it (Keksdose\n // feedback #147: the market picker's rows carry a postcode, a town, a\n // distance and a receipt count, all of which were being truncated). The\n // override used to be applied from the OUTSIDE with a\n // `[&>div]:w-full` descendant selector, which worked and was a hack —\n // \"change the package\" was the right call.\n className={cn(\"w-64\", panelClassName)}\n empty={filtered.length === 0}\n // The rows below are options, so the list around them has to be a listbox\n // — and one that says several answers are allowed, which is the only thing\n // that made the trigger's \"3 selected\" make sense to a reader.\n listProps={{ id: listboxId, role: \"listbox\", \"aria-multiselectable\": true }}\n header={\n <>\n <DropdownSearchHeader\n query={query}\n onQueryChange={(v) => {\n setQuery(v);\n // The list under the highlight just changed; keeping the old index\n // would point `aria-activedescendant` at a different option than\n // the one the user was on.\n setActive(0);\n }}\n inputRef={inputRef}\n placeholder={labels.search}\n listboxId={listboxId}\n activeId={activeId}\n onKeyDown={onListKeyDown}\n />\n <div className=\"flex items-center justify-between gap-2 px-2 py-1.5 text-xs\">\n <button\n type=\"button\"\n onClick={selectAll}\n disabled={allChecked}\n className=\"rounded px-2 py-0.5 text-[var(--text-secondary)] hover:bg-[var(--bg-hover)] disabled:opacity-40\"\n >\n {labels.selectAll}\n </button>\n <button\n type=\"button\"\n onClick={clearAll}\n disabled={!anyChecked}\n className=\"rounded px-2 py-0.5 text-[var(--text-secondary)] hover:bg-[var(--bg-hover)] disabled:opacity-40\"\n >\n {labels.clear}\n </button>\n </div>\n </>\n }\n >\n {filtered.map((o, i) => {\n const checked = valueSet.has(o.value);\n return (\n <li key={o.value} role=\"presentation\">\n <button\n type=\"button\"\n id={optionId(i)}\n // The checked state used to exist ONLY as the decorative span\n // below (the audit's §a11y): the row said its label and nothing\n // else, so \"selected\" was imperceptible without sight. This is\n // the same state, in the one place a reader looks for it.\n role=\"option\"\n aria-selected={checked}\n // Focus stays in the search box — that is what\n // `aria-activedescendant` is for — so the rows are not tab stops.\n tabIndex={-1}\n onClick={() => toggle(o.value)}\n onMouseEnter={() => setActive(i)}\n className={cn(\n \"flex w-full items-center justify-between gap-2 px-3 py-1.5 text-sm text-left hover:bg-[var(--bg-hover)]\",\n checked && \"bg-[var(--bg-active)]\",\n i === active && \"bg-[var(--bg-hover)]\",\n )}\n >\n <span className=\"flex items-center gap-2 min-w-0\">\n <span\n // A picture of `aria-selected` above; a reader that met both\n // would be told twice.\n aria-hidden\n className={cn(\n \"flex size-4 shrink-0 items-center justify-center rounded border\",\n checked\n ? \"border-[var(--bg-inverse)] bg-[var(--bg-inverse)] text-[var(--text-inverse)]\"\n : \"border-[var(--border-strong)] bg-[var(--bg-surface)]\",\n )}\n >\n {checked && <Check className=\"size-3\" />}\n </span>\n <span className=\"truncate text-[var(--text-primary)]\">{o.label}</span>\n {o.hint && (\n <span className=\"truncate text-xs text-[var(--text-placeholder)]\">\n {o.hint}\n </span>\n )}\n </span>\n </button>\n </li>\n );\n })}\n </DropdownPanel>\n )}\n </div>\n );\n}\n"],"mappings":";AAyJ8B,SA2DlB,UA3DkB,KACxB,YADwB;AAzJ9B,SAAS,OAAO,SAAS,gBAAgB;AAMzC,SAAS,aAAa;AACtB,SAAS,cAAc,YAAY,eAAe,eAAe,0BAA0B;AAC3F,SAAS,UAAU;AACnB,SAAS,eAAe,sBAAsB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kBAET,iBAAO;AAAA;AAAA,cACV;AAAA,cACA;AAAA,gBAAC;AAAA;AAAA,kBACC,MAAK;AAAA,kBACL,SAAS;AAAA,kBACT,UAAU,CAAC;AAAA,kBACX,WAAU;AAAA,kBAET,iBAAO;AAAA;AAAA,cACV;AAAA,eACF;AAAA,aACF;AAAA,UAGD,mBAAS,IAAI,CAAC,GAAG,MAAM;AACpB,kBAAM,UAAU,SAAS,IAAI,EAAE,KAAK;AACpC,mBACE,oBAAC,QAAiB,MAAK,gBACrB;AAAA,cAAC;AAAA;AAAA,gBACC,MAAK;AAAA,gBACL,IAAI,SAAS,CAAC;AAAA,gBAKd,MAAK;AAAA,gBACL,iBAAe;AAAA,gBAGf,UAAU;AAAA,gBACV,SAAS,MAAM,OAAO,EAAE,KAAK;AAAA,gBAC7B,cAAc,MAAM,UAAU,CAAC;AAAA,gBAC/B,WAAW;AAAA,kBACT;AAAA,kBACA,WAAW;AAAA,kBACX,MAAM,UAAU;AAAA,gBAClB;AAAA,gBAEA,+BAAC,UAAK,WAAU,mCACd;AAAA;AAAA,oBAAC;AAAA;AAAA,sBAGC,eAAW;AAAA,sBACX,WAAW;AAAA,wBACT;AAAA,wBACA,UACI,iFACA;AAAA,sBACN;AAAA,sBAEC,qBAAW,oBAAC,SAAM,WAAU,UAAS;AAAA;AAAA,kBACxC;AAAA,kBACA,oBAAC,UAAK,WAAU,uCAAuC,YAAE,OAAM;AAAA,kBAC9D,EAAE,QACD,oBAAC,UAAK,WAAU,mDACb,YAAE,MACL;AAAA,mBAEJ;AAAA;AAAA,YACF,KA1CO,EAAE,KA2CX;AAAA,UAEJ,CAAC;AAAA;AAAA,MACL;AAAA,OAEJ;AAAA;AAEJ;","names":[]}
@@ -0,0 +1,92 @@
1
+ import * as react from 'react';
2
+ import { ComponentProps, ReactNode } from 'react';
3
+ import { NumberInput } from './number-input.js';
4
+ import './calculator.js';
5
+ import '../i18n/kit-labels.js';
6
+ import './data-table-labels.js';
7
+ import './mini-calendar.js';
8
+ import './popover.js';
9
+ import './chip.js';
10
+ import 'lucide-react';
11
+ import './field-sync.js';
12
+ import './ui.js';
13
+ import '../wizard/types.js';
14
+ import '../tour/tour.js';
15
+ import '../search/command-palette.js';
16
+ import './month-picker.js';
17
+ import './page-contents.js';
18
+ import './series-chart-labels.js';
19
+ import './sparkline.js';
20
+ import './stat-tile.js';
21
+ import './signature-pad.js';
22
+ import './password-strength.js';
23
+ import './numpad-sheet.js';
24
+
25
+ type NumberInputProps = ComponentProps<typeof NumberInput>;
26
+ interface NumberFieldProps extends Omit<NumberInputProps, "value" | "onChange" | "onCommit" | "suffix" | "invalid"> {
27
+ /** The committed number. `null` is "no value" — shown as an empty field. */
28
+ value: number | null;
29
+ /**
30
+ * The parsed number, on blur or Enter — never per keystroke — and only when it
31
+ * differs from the last one committed. Already rounded to `digits` and clamped
32
+ * into `[min, max]`. `null` only when `nullable` and the field was emptied.
33
+ */
34
+ onCommit: (value: number | null) => void;
35
+ /** Round to this many decimals on commit, and show at most this many (trailing
36
+ * zeros are trimmed: `digits={2}` shows 12.5, not 12.50). Omit for no rounding. */
37
+ digits?: number;
38
+ /** Clamp the committed number into `[min, max]`. Applied after rounding. */
39
+ min?: number;
40
+ max?: number;
41
+ /** An emptied field commits `null`. Without it an empty field is not an answer
42
+ * and snaps back to the last value, like any other unparsable text. */
43
+ nullable?: boolean;
44
+ /** The unit — "mm", "%", "km/h". */
45
+ unit?: ReactNode;
46
+ /** Where `unit` goes: `"suffix"` (default) is NumberInput's read-out at the
47
+ * field's end edge; `"label"` appends it to the label as "Label (unit)", for rows
48
+ * of narrow fields where a suffix would eat the digits. */
49
+ unitPlacement?: "suffix" | "label";
50
+ /** BCP 47 tag for the decimal mark, else the `<UiKitProvider locale>`, else the
51
+ * runtime's. */
52
+ locale?: string;
53
+ /** See {@link Input}'s `invalid`. */
54
+ invalid?: boolean;
55
+ /** See {@link Input}'s `error`: shown under the field, attached via
56
+ * `aria-describedby`, implies `invalid`. */
57
+ error?: ReactNode;
58
+ /** Merged with the error's id. Accepted so a form library's control slot (which
59
+ * injects `id` / `aria-describedby` / `aria-invalid`) can wrap this directly. */
60
+ "aria-describedby"?: string;
61
+ "aria-invalid"?: boolean | "true" | "false";
62
+ }
63
+ /**
64
+ * A number field whose value IS a number: {@link NumberInput}'s text, calculator and
65
+ * numpad, with the parse/commit/revert loop every consumer was writing on top of it.
66
+ *
67
+ * WHY THE DRAFT. Half-typed values — "-", "1,", "12+" — are not numbers, and
68
+ * reformatting them mid-keystroke moves the caret and fights the typist; committing
69
+ * per keystroke would also fire whatever a commit fires (a recalculation, a save) for
70
+ * every meaningless intermediate. So the field keeps a draft STRING while it is being
71
+ * typed and resolves it on blur/Enter:
72
+ *
73
+ * - a number (or a calculation, "2700+50") → rounded to `digits`, clamped into
74
+ * `[min, max]`, committed, and the draft re-rendered from the result;
75
+ * - empty → `null` when `nullable`, otherwise the same as the next case — `Number("")`
76
+ * is 0, and clearing a wheelbase and tabbing away must not set it to zero;
77
+ * - anything else unparsable → the draft SNAPS BACK to the last committed value
78
+ * rather than sending NaN on for a server to reject.
79
+ *
80
+ * The draft follows `value` when it changes from outside (a reset, a loaded record);
81
+ * a change that came from here arrives back identical and is a no-op.
82
+ *
83
+ * LOCALE. The decimal mark is the locale's: a German user sees and types "1,5".
84
+ * NumberInput normalises every keystroke to a dot (so its evaluator reads one
85
+ * alphabet); this field maps the dot back before the draft is shown, which also
86
+ * means the numpad's "." key types the mark the field is displaying. There is no
87
+ * digit grouping — "1.000" would read as a thousand in German and as one in English,
88
+ * and a field that parses its own display back must not have that ambiguity.
89
+ */
90
+ declare function NumberField({ value, onCommit, digits, min, max, nullable, unit, unitPlacement, locale: localeProp, label, invalid, error, id, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, ...rest }: NumberFieldProps): react.JSX.Element;
91
+
92
+ export { NumberField, type NumberFieldProps };
@@ -0,0 +1,111 @@
1
+ "use client";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ import { useEffect, useId, useState } from "react";
4
+ import { NumberInput } from "./number-input.js";
5
+ import { formatResult } from "../lib/calc.js";
6
+ import { useKitLocale } from "../i18n/kit-labels.js";
7
+ function decimalMark(locale) {
8
+ try {
9
+ const part = new Intl.NumberFormat(locale).formatToParts(1.5).find((p) => p.type === "decimal");
10
+ return part?.value === "," ? "," : ".";
11
+ } catch {
12
+ return ".";
13
+ }
14
+ }
15
+ function roundTo(n, digits) {
16
+ if (digits === void 0) return n;
17
+ const d = Math.min(Math.max(Math.trunc(digits), 0), 100);
18
+ const rounded = Number(n.toFixed(d));
19
+ return Number.isFinite(rounded) ? rounded : n;
20
+ }
21
+ const FIELD_ERROR_CLASS = "mt-1 text-[11px] leading-tight text-[var(--danger)]";
22
+ function NumberField({
23
+ value,
24
+ onCommit,
25
+ digits,
26
+ min,
27
+ max,
28
+ nullable = false,
29
+ unit,
30
+ unitPlacement = "suffix",
31
+ locale: localeProp,
32
+ label,
33
+ invalid,
34
+ error,
35
+ id,
36
+ "aria-describedby": ariaDescribedBy,
37
+ "aria-invalid": ariaInvalid,
38
+ ...rest
39
+ }) {
40
+ const locale = useKitLocale(localeProp);
41
+ const mark = decimalMark(locale);
42
+ const localize = (text) => mark === "," ? text.replace(/\./g, ",") : text;
43
+ const format = (n) => n === null || !Number.isFinite(n) ? "" : localize(formatResult(roundTo(n, digits)));
44
+ const [draft, setDraft] = useState(() => format(value));
45
+ const shownFor = `${value}|${mark}|${digits}`;
46
+ const [seen, setSeen] = useState(shownFor);
47
+ const [committed, setCommitted] = useState(value);
48
+ if (shownFor !== seen) {
49
+ setSeen(shownFor);
50
+ setDraft(format(value));
51
+ setCommitted(value);
52
+ }
53
+ const commit = (text) => {
54
+ const trimmed = text.trim();
55
+ let next;
56
+ if (trimmed === "") {
57
+ if (!nullable) return setDraft(format(committed));
58
+ next = null;
59
+ } else {
60
+ const parsed = Number(trimmed.replace(/,/g, "."));
61
+ if (!Number.isFinite(parsed)) return setDraft(format(committed));
62
+ next = roundTo(parsed, digits);
63
+ if (min !== void 0) next = Math.max(min, next);
64
+ if (max !== void 0) next = Math.min(max, next);
65
+ }
66
+ setDraft(format(next));
67
+ if (next !== committed) {
68
+ setCommitted(next);
69
+ onCommit(next);
70
+ }
71
+ };
72
+ const generatedId = useId();
73
+ const fieldId = id ?? generatedId;
74
+ const errorId = useId();
75
+ const hasError = error !== void 0 && error !== null && error !== false && error !== "";
76
+ const describedBy = [ariaDescribedBy, hasError ? errorId : void 0].filter(Boolean).join(" ");
77
+ useEffect(() => {
78
+ const input = document.getElementById(fieldId);
79
+ if (!input) return;
80
+ if (describedBy) input.setAttribute("aria-describedby", describedBy);
81
+ else input.removeAttribute("aria-describedby");
82
+ }, [fieldId, describedBy]);
83
+ const labelWithUnit = unit !== void 0 && unitPlacement === "label" ? label === void 0 || label === "" ? unit : typeof label === "string" && typeof unit === "string" ? `${label} (${unit})` : /* @__PURE__ */ jsxs(Fragment, { children: [
84
+ label,
85
+ " (",
86
+ unit,
87
+ ")"
88
+ ] }) : label;
89
+ const field = /* @__PURE__ */ jsx(
90
+ NumberInput,
91
+ {
92
+ ...rest,
93
+ id: fieldId,
94
+ label: labelWithUnit,
95
+ value: draft,
96
+ onChange: (text) => setDraft(localize(text)),
97
+ onCommit: commit,
98
+ suffix: unitPlacement === "suffix" ? unit : void 0,
99
+ invalid: invalid || hasError || ariaInvalid === true || ariaInvalid === "true"
100
+ }
101
+ );
102
+ if (!hasError) return field;
103
+ return /* @__PURE__ */ jsxs("div", { children: [
104
+ field,
105
+ /* @__PURE__ */ jsx("p", { id: errorId, className: FIELD_ERROR_CLASS, children: error })
106
+ ] });
107
+ }
108
+ export {
109
+ NumberField
110
+ };
111
+ //# sourceMappingURL=number-field.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/components/number-field.tsx"],"sourcesContent":["import { useEffect, useId, useState } from \"react\";\nimport type { ComponentProps, ReactNode } from \"react\";\nimport { NumberInput } from \"./number-input\";\nimport { formatResult } from \"../lib/calc\";\nimport { useKitLocale } from \"../i18n/kit-labels\";\n\ntype NumberInputProps = ComponentProps<typeof NumberInput>;\n\nexport interface NumberFieldProps\n extends Omit<NumberInputProps, \"value\" | \"onChange\" | \"onCommit\" | \"suffix\" | \"invalid\"> {\n /** The committed number. `null` is \"no value\" — shown as an empty field. */\n value: number | null;\n /**\n * The parsed number, on blur or Enter — never per keystroke — and only when it\n * differs from the last one committed. Already rounded to `digits` and clamped\n * into `[min, max]`. `null` only when `nullable` and the field was emptied.\n */\n onCommit: (value: number | null) => void;\n /** Round to this many decimals on commit, and show at most this many (trailing\n * zeros are trimmed: `digits={2}` shows 12.5, not 12.50). Omit for no rounding. */\n digits?: number;\n /** Clamp the committed number into `[min, max]`. Applied after rounding. */\n min?: number;\n max?: number;\n /** An emptied field commits `null`. Without it an empty field is not an answer\n * and snaps back to the last value, like any other unparsable text. */\n nullable?: boolean;\n /** The unit — \"mm\", \"%\", \"km/h\". */\n unit?: ReactNode;\n /** Where `unit` goes: `\"suffix\"` (default) is NumberInput's read-out at the\n * field's end edge; `\"label\"` appends it to the label as \"Label (unit)\", for rows\n * of narrow fields where a suffix would eat the digits. */\n unitPlacement?: \"suffix\" | \"label\";\n /** BCP 47 tag for the decimal mark, else the `<UiKitProvider locale>`, else the\n * runtime's. */\n locale?: string;\n /** See {@link Input}'s `invalid`. */\n invalid?: boolean;\n /** See {@link Input}'s `error`: shown under the field, attached via\n * `aria-describedby`, implies `invalid`. */\n error?: ReactNode;\n /** Merged with the error's id. Accepted so a form library's control slot (which\n * injects `id` / `aria-describedby` / `aria-invalid`) can wrap this directly. */\n \"aria-describedby\"?: string;\n \"aria-invalid\"?: boolean | \"true\" | \"false\";\n}\n\n/** The locale's decimal mark, as far as this field can type it: \",\" or \".\". A mark\n * outside those two (Arabic's \"٫\") is not something {@link sanitizeLive} lets\n * through, so those locales keep the dot rather than get a field that eats keys. */\nfunction decimalMark(locale: string | undefined): \",\" | \".\" {\n try {\n const part = new Intl.NumberFormat(locale).formatToParts(1.5).find((p) => p.type === \"decimal\");\n return part?.value === \",\" ? \",\" : \".\";\n } catch {\n // An invalid tag throws a RangeError; a typo in a locale prop must not take the\n // form down with it.\n return \".\";\n }\n}\n\n/** `toFixed` rounding rather than `Math.round(n * 10^d)`, which turns 1.005 into\n * 1.00 by way of 100.49999999999999 — the same choice the lenkbank field made. */\nfunction roundTo(n: number, digits: number | undefined): number {\n if (digits === undefined) return n;\n const d = Math.min(Math.max(Math.trunc(digits), 0), 100);\n const rounded = Number(n.toFixed(d));\n return Number.isFinite(rounded) ? rounded : n;\n}\n\n// The error line under a field — the same type as `ui.tsx`'s (module-private) one,\n// so a NumberField's message is indistinguishable from an Input's.\nconst FIELD_ERROR_CLASS = \"mt-1 text-[11px] leading-tight text-[var(--danger)]\";\n\n/**\n * A number field whose value IS a number: {@link NumberInput}'s text, calculator and\n * numpad, with the parse/commit/revert loop every consumer was writing on top of it.\n *\n * WHY THE DRAFT. Half-typed values — \"-\", \"1,\", \"12+\" — are not numbers, and\n * reformatting them mid-keystroke moves the caret and fights the typist; committing\n * per keystroke would also fire whatever a commit fires (a recalculation, a save) for\n * every meaningless intermediate. So the field keeps a draft STRING while it is being\n * typed and resolves it on blur/Enter:\n *\n * - a number (or a calculation, \"2700+50\") → rounded to `digits`, clamped into\n * `[min, max]`, committed, and the draft re-rendered from the result;\n * - empty → `null` when `nullable`, otherwise the same as the next case — `Number(\"\")`\n * is 0, and clearing a wheelbase and tabbing away must not set it to zero;\n * - anything else unparsable → the draft SNAPS BACK to the last committed value\n * rather than sending NaN on for a server to reject.\n *\n * The draft follows `value` when it changes from outside (a reset, a loaded record);\n * a change that came from here arrives back identical and is a no-op.\n *\n * LOCALE. The decimal mark is the locale's: a German user sees and types \"1,5\".\n * NumberInput normalises every keystroke to a dot (so its evaluator reads one\n * alphabet); this field maps the dot back before the draft is shown, which also\n * means the numpad's \".\" key types the mark the field is displaying. There is no\n * digit grouping — \"1.000\" would read as a thousand in German and as one in English,\n * and a field that parses its own display back must not have that ambiguity.\n */\nexport function NumberField({\n value,\n onCommit,\n digits,\n min,\n max,\n nullable = false,\n unit,\n unitPlacement = \"suffix\",\n locale: localeProp,\n label,\n invalid,\n error,\n id,\n \"aria-describedby\": ariaDescribedBy,\n \"aria-invalid\": ariaInvalid,\n ...rest\n}: NumberFieldProps) {\n const locale = useKitLocale(localeProp);\n const mark = decimalMark(locale);\n const localize = (text: string) => (mark === \",\" ? text.replace(/\\./g, \",\") : text);\n // `formatResult` for fixed notation: `String(1e-7)` is \"1e-7\", which the field\n // would read back as 17 (see calc.ts).\n const format = (n: number | null) =>\n n === null || !Number.isFinite(n) ? \"\" : localize(formatResult(roundTo(n, digits)));\n\n const [draft, setDraft] = useState(() => format(value));\n // Everything the displayed text depends on, not just `value`: switching the\n // provider's language or a field's `digits` has to re-render the draft too.\n const shownFor = `${value}|${mark}|${digits}`;\n const [seen, setSeen] = useState(shownFor);\n // The last number handed to `onCommit`, so Enter-then-blur (both commit) and a\n // parent that does not echo the value back cannot commit the same number twice.\n // State rather than a ref because the external-change branch below resets it\n // during render, and a ref may not be written there.\n const [committed, setCommitted] = useState(value);\n\n // Adjust state during render rather than in an effect: React re-renders at once\n // with the new draft, before anything is painted, so there is no frame showing\n // the old text.\n if (shownFor !== seen) {\n setSeen(shownFor);\n setDraft(format(value));\n setCommitted(value);\n }\n\n const commit = (text: string) => {\n const trimmed = text.trim();\n let next: number | null;\n if (trimmed === \"\") {\n if (!nullable) return setDraft(format(committed));\n next = null;\n } else {\n // `text` is NumberInput's committed form: an evaluated calculation, dot-decimal.\n // What survives its digits-only fallback can still be \"-\" or \".\" alone.\n const parsed = Number(trimmed.replace(/,/g, \".\"));\n if (!Number.isFinite(parsed)) return setDraft(format(committed));\n next = roundTo(parsed, digits);\n if (min !== undefined) next = Math.max(min, next);\n if (max !== undefined) next = Math.min(max, next);\n }\n // Always re-render the draft from the result — \"007\" becomes \"7\", a clamped 500\n // shows the 100 it was clamped to — even when there is nothing new to commit.\n setDraft(format(next));\n if (next !== committed) {\n setCommitted(next);\n onCommit(next);\n }\n };\n\n const generatedId = useId();\n const fieldId = id ?? generatedId;\n const errorId = useId();\n // `null`/`false`/`\"\"` are what `touched && errors.x` evaluates to on the happy path.\n const hasError = error !== undefined && error !== null && error !== false && error !== \"\";\n const describedBy = [ariaDescribedBy, hasError ? errorId : undefined].filter(Boolean).join(\" \");\n\n // NumberInput takes no `aria-describedby` of its own, so the reference is set on\n // its <input> directly, found by the id this field hands it. React never renders\n // that attribute there, so nothing reconciles it away again.\n useEffect(() => {\n const input = document.getElementById(fieldId);\n if (!input) return;\n if (describedBy) input.setAttribute(\"aria-describedby\", describedBy);\n else input.removeAttribute(\"aria-describedby\");\n }, [fieldId, describedBy]);\n\n const labelWithUnit =\n unit !== undefined && unitPlacement === \"label\"\n ? label === undefined || label === \"\"\n ? unit\n : typeof label === \"string\" && typeof unit === \"string\"\n ? `${label} (${unit})`\n : (\n <>\n {label} ({unit})\n </>\n )\n : label;\n\n const field = (\n <NumberInput\n {...rest}\n id={fieldId}\n label={labelWithUnit}\n value={draft}\n onChange={(text) => setDraft(localize(text))}\n onCommit={commit}\n suffix={unitPlacement === \"suffix\" ? unit : undefined}\n invalid={invalid || hasError || ariaInvalid === true || ariaInvalid === \"true\"}\n />\n );\n // Same shape as Input's FieldGroup: no wrapper at all without a message, so adding\n // `error` support changed nothing about the DOM a flex row lays out.\n if (!hasError) return field;\n return (\n <div>\n {field}\n <p id={errorId} className={FIELD_ERROR_CLASS}>\n {error}\n </p>\n </div>\n );\n}\n"],"mappings":";AAmMY,mBAOR,KAPQ;AAnMZ,SAAS,WAAW,OAAO,gBAAgB;AAE3C,SAAS,mBAAmB;AAC5B,SAAS,oBAAoB;AAC7B,SAAS,oBAAoB;AA8C7B,SAAS,YAAY,QAAuC;AAC1D,MAAI;AACF,UAAM,OAAO,IAAI,KAAK,aAAa,MAAM,EAAE,cAAc,GAAG,EAAE,KAAK,CAAC,MAAM,EAAE,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AA;AAAA,MACE,GAAG;AAAA,MACJ,IAAI;AAAA,MACJ,OAAO;AAAA,MACP,OAAO;AAAA,MACP,UAAU,CAAC,SAAS,SAAS,SAAS,IAAI,CAAC;AAAA,MAC3C,UAAU;AAAA,MACV,QAAQ,kBAAkB,WAAW,OAAO;AAAA,MAC5C,SAAS,WAAW,YAAY,gBAAgB,QAAQ,gBAAgB;AAAA;AAAA,EAC1E;AAIF,MAAI,CAAC,SAAU,QAAO;AACtB,SACE,qBAAC,SACE;AAAA;AAAA,IACD,oBAAC,OAAE,IAAI,SAAS,WAAW,mBACxB,iBACH;AAAA,KACF;AAEJ;","names":[]}
@@ -2,6 +2,24 @@ import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
3
  import { CalculatorButtonLabels } from './calculator.js';
4
4
  import { NumberPadSheetLabels } from './numpad-sheet.js';
5
+ import '../i18n/kit-labels.js';
6
+ import './data-table-labels.js';
7
+ import './mini-calendar.js';
8
+ import './popover.js';
9
+ import './chip.js';
10
+ import 'lucide-react';
11
+ import './field-sync.js';
12
+ import './ui.js';
13
+ import '../wizard/types.js';
14
+ import '../tour/tour.js';
15
+ import '../search/command-palette.js';
16
+ import './month-picker.js';
17
+ import './page-contents.js';
18
+ import './series-chart-labels.js';
19
+ import './sparkline.js';
20
+ import './stat-tile.js';
21
+ import './signature-pad.js';
22
+ import './password-strength.js';
5
23
 
6
24
  interface NumberInputProps {
7
25
  value: string;
@@ -14,8 +32,9 @@ interface NumberInputProps {
14
32
  label?: ReactNode;
15
33
  ariaLabel?: string;
16
34
  /** Names for the calculator this field renders — its trigger, and the controls
17
- * inside the popover — and for the numpad sheet it opens on a phone. English
18
- * defaults, so a host that does not translate is unaffected.
35
+ * inside the popover — and for the numpad sheet it opens on a phone. Overrides
36
+ * for THIS field only: both resolve the `calculator` namespace of
37
+ * `<UiKitProvider labels>` themselves, then fall back to English.
19
38
  *
20
39
  * `pad` is not optional plumbing: this field renders a {@link NumberPadSheet}
21
40
  * exactly as {@link AmountInput} does, but had no way to pass it anything, so
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { jsx, jsxs } from "react/jsx-runtime";
2
3
  import { useId, useRef, useState } from "react";
3
4
  import { CalculatorButton } from "./calculator.js";
@@ -98,7 +99,7 @@ function NumberInput({
98
99
  "span",
99
100
  {
100
101
  "aria-hidden": true,
101
- className: "pointer-events-none pr-3 text-xs font-medium text-slate-500 dark:text-slate-400",
102
+ className: "pointer-events-none pr-3 text-xs font-medium text-[var(--text-muted)]",
102
103
  children: suffix
103
104
  }
104
105
  )
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/number-input.tsx"],"sourcesContent":["import { useId, useRef, useState } from \"react\";\nimport type { KeyboardEvent, ReactNode } from \"react\";\nimport { CalculatorButton, type CalculatorButtonLabels } from \"./calculator\";\nimport { NumberPadSheet, type NumberPadSheetLabels } from \"./numpad-sheet\";\nimport { FIELD_BASE, FIELD_DISPLAY, FIELD_INVALID, FLOATING_INPUT_CLASS, FloatingField, PHONE_QUERY } from \"./ui\";\nimport { cn } from \"../lib/cn\";\nimport { commitExpression, sanitizeLive } from \"../lib/calc\";\nimport { useMediaQuery } from \"../hooks/use-media-query\";\n\ninterface NumberInputProps {\n value: string;\n /** Fired on every keystroke with the raw text (comma → dot, operators kept so\n * a typed expression survives). */\n onChange: (value: string) => void;\n /** Fired on blur/Enter with the *evaluated* value — use this for save-on-blur\n * fields so the save always sees the resolved number, never \"10+5\". */\n onCommit?: (value: string) => void;\n label?: ReactNode;\n ariaLabel?: string;\n /** Names for the calculator this field renders — its trigger, and the controls\n * inside the popover — and for the numpad sheet it opens on a phone. English\n * defaults, so a host that does not translate is unaffected.\n *\n * `pad` is not optional plumbing: this field renders a {@link NumberPadSheet}\n * exactly as {@link AmountInput} does, but had no way to pass it anything, so\n * the SAME keypad announced itself in German when a money field opened it and in\n * English when a goal target did. */\n labels?: {\n calculatorTrigger?: string;\n calculator?: CalculatorButtonLabels;\n pad?: NumberPadSheetLabels;\n };\n placeholder?: string;\n disabled?: boolean;\n autoFocus?: boolean;\n /** Wrapper class. */\n className?: string;\n /** Overrides the input's own styling (merged after the field base). */\n inputClassName?: string;\n id?: string;\n /** Show the calculator-popover trigger (default true). Set false for fields in\n * an ephemeral close-on-blur editor, where clicking the icon would blur away\n * and tear the editor down before the popover could open — inline typing\n * (e.g. \"200+50\" → Enter) still evaluates there. */\n calculator?: boolean;\n /** {@link FIELD_DISPLAY} — on a phone, the figure at display size with the field\n * chrome dropped. The currency-free half of the same treatment `AmountInput`\n * carries, for a dialog whose whole point is the one number (a budget goal's\n * target); not for a field among many, and never for the compact inline\n * editors this control also serves. */\n variant?: \"field\" | \"display\";\n /** A {@link FieldHint} \"?\" on the label's own line, beside the label rather\n * than at the far end of the strip — the far end is where the calculator\n * lives, and a hint placed there landed on top of it (steering-design\n * feedback #48). */\n hint?: ReactNode;\n /** Required and unanswered — {@link FIELD_INVALID}. See {@link Input}'s `invalid`. */\n invalid?: boolean;\n /**\n * A static unit shown at the field's right edge — \"%\", \"kg\", \"km/h\".\n *\n * The read-out half of {@link AmountInput}'s currency chip, and it exists for the\n * same reason that one does: a unit belongs to the FIELD, not to the text, so\n * typing it is a way to get it into the value. Keksdose had a percentage spelled\n * three different ways across three screens — `<Input type=\"number\" step=\"0.01\">`\n * for a loan rate, `step=\"0.1\"` for a tax rate, `inputMode=\"decimal\"` for a VAT\n * rate — and none of the three showed a \"%\" anywhere near the box, so what the\n * digits meant was a question the label alone had to answer.\n *\n * `aria-hidden`, like the currency read-out: it is a property of the field that\n * the label already names (\"Interest rate (%)\"), and announcing it again after\n * every value reads as part of the number.\n */\n suffix?: ReactNode;\n}\n\n/**\n * A numeric text field with a built-in calculator: type a calculation straight\n * in (e.g. \"12+5\", evaluated on blur/Enter) or click the trailing calculator\n * icon for a keypad. String `value`/`onChange` contract, mirroring\n * {@link AmountInput} — the currency-free counterpart for budgets, goals,\n * invoice totals and split lines.\n */\nexport function NumberInput({\n value,\n onChange,\n onCommit,\n label,\n ariaLabel,\n labels,\n placeholder,\n disabled,\n autoFocus,\n className,\n inputClassName,\n id,\n calculator = true,\n variant = \"field\",\n hint,\n invalid,\n suffix,\n}: NumberInputProps) {\n const generatedId = useId();\n const fieldId = id ?? generatedId;\n const labelled = label !== undefined;\n // On phones we suppress the OS keyboard (inputMode=\"none\" below) for our own\n // calculator numpad, so the desktop popover trigger is hidden (feedback #334).\n const isMobile = useMediaQuery(PHONE_QUERY, false);\n const asDisplay = isMobile && variant === \"display\";\n const showCalc = calculator && !disabled && !isMobile;\n const [focused, setFocused] = useState(false);\n // On mobile, focusing opens the numpad bottom sheet instead of the native\n // keyboard (#334); the ref lets its \"Done\" blur → commit + close.\n const showNumpad = isMobile && !disabled && focused;\n const inputRef = useRef<HTMLInputElement>(null);\n\n const commit = () => {\n const next = commitExpression(value);\n if (next !== value) onChange(next);\n onCommit?.(next);\n };\n\n const onKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {\n if (e.key === \"Enter\") commit();\n };\n\n return (\n <FloatingField\n className={cn(\"w-full\", className)}\n htmlFor={fieldId}\n label={label}\n srOnlyLabel={asDisplay}\n hint={hint}\n >\n <input\n ref={inputRef}\n id={fieldId}\n aria-label={ariaLabel}\n type=\"text\"\n // Mobile: suppress the OS keyboard so the numpad sheet owns entry (field\n // keeps focus/caret); desktop keeps the native decimal keypad.\n inputMode={isMobile ? \"none\" : \"decimal\"}\n autoComplete=\"off\"\n autoFocus={autoFocus}\n disabled={disabled}\n // Display mode has no floating label to feed the blank-placeholder trick,\n // and an empty borderless figure shows nothing — so it keeps whatever\n // placeholder the caller gave, falling back to a zero to aim at.\n placeholder={asDisplay ? (placeholder ?? \"0\") : labelled ? \" \" : placeholder}\n value={value}\n onChange={(e) => onChange(sanitizeLive(e.target.value))}\n onFocus={() => setFocused(true)}\n onBlur={() => {\n commit();\n setFocused(false);\n }}\n onKeyDown={onKeyDown}\n aria-invalid={invalid || undefined}\n // The right-padding sits last so it always wins over an inputClassName that\n // sets its own px. Both trailing controls can be on at once, so the room\n // they need is reserved together rather than by whichever happens to render:\n // the calculator is ~36px and a short unit ~24px, and a field that reserved\n // only one of them would let the digits run under the other.\n className={cn(\n asDisplay\n ? cn(FIELD_DISPLAY, \"text-4xl font-semibold leading-tight tracking-tight tabular-nums\")\n : labelled\n ? FLOATING_INPUT_CLASS\n : FIELD_BASE,\n inputClassName,\n showCalc && suffix !== undefined ? \"pr-16\" : showCalc ? \"pr-9\" : suffix !== undefined ? \"pr-8\" : undefined,\n invalid && FIELD_INVALID,\n )}\n />\n {(showCalc || suffix !== undefined) && (\n // One flex track for both, so the unit and the calculator sit side by side\n // instead of stacking on the same corner — AmountInput's arrangement, which\n // has carried a chip and a calculator together since #430.\n <div className=\"absolute inset-y-0 right-0 flex items-center\">\n {showCalc && (\n <CalculatorButton\n value={value}\n onChange={onChange}\n className=\"self-stretch px-2.5\"\n ariaLabel={labels?.calculatorTrigger}\n labels={labels?.calculator}\n />\n )}\n {suffix !== undefined && (\n <span\n aria-hidden\n className=\"pointer-events-none pr-3 text-xs font-medium text-slate-500 dark:text-slate-400\"\n >\n {suffix}\n </span>\n )}\n </div>\n )}\n {showNumpad && (\n <NumberPadSheet\n value={value}\n onChange={onChange}\n onDone={() => inputRef.current?.blur()}\n label={label}\n labels={labels?.pad}\n />\n )}\n </FloatingField>\n );\n}\n"],"mappings":"AAsIM,cA4CE,YA5CF;AAtIN,SAAS,OAAO,QAAQ,gBAAgB;AAExC,SAAS,wBAAqD;AAC9D,SAAS,sBAAiD;AAC1D,SAAS,YAAY,eAAe,eAAe,sBAAsB,eAAe,mBAAmB;AAC3G,SAAS,UAAU;AACnB,SAAS,kBAAkB,oBAAoB;AAC/C,SAAS,qBAAqB;AA4EvB,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,aAAa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,WAAW,SAAY,UAAU,WAAW,SAAS,WAAW,SAAY,SAAS;AAAA,cACjG,WAAW;AAAA,YACb;AAAA;AAAA,QACF;AAAA,SACE,YAAY,WAAW;AAAA;AAAA;AAAA,QAIvB,qBAAC,SAAI,WAAU,gDACZ;AAAA,sBACC;AAAA,YAAC;AAAA;AAAA,cACC;AAAA,cACA;AAAA,cACA,WAAU;AAAA,cACV,WAAW,QAAQ;AAAA,cACnB,QAAQ,QAAQ;AAAA;AAAA,UAClB;AAAA,UAED,WAAW,UACV;AAAA,YAAC;AAAA;AAAA,cACC,eAAW;AAAA,cACX,WAAU;AAAA,cAET;AAAA;AAAA,UACH;AAAA,WAEJ;AAAA,QAED,cACC;AAAA,UAAC;AAAA;AAAA,YACC;AAAA,YACA;AAAA,YACA,QAAQ,MAAM,SAAS,SAAS,KAAK;AAAA,YACrC;AAAA,YACA,QAAQ,QAAQ;AAAA;AAAA,QAClB;AAAA;AAAA;AAAA,EAEJ;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../src/components/number-input.tsx"],"sourcesContent":["import { useId, useRef, useState } from \"react\";\nimport type { KeyboardEvent, ReactNode } from \"react\";\nimport { CalculatorButton, type CalculatorButtonLabels } from \"./calculator\";\nimport { NumberPadSheet, type NumberPadSheetLabels } from \"./numpad-sheet\";\nimport { FIELD_BASE, FIELD_DISPLAY, FIELD_INVALID, FLOATING_INPUT_CLASS, FloatingField, PHONE_QUERY } from \"./ui\";\nimport { cn } from \"../lib/cn\";\nimport { commitExpression, sanitizeLive } from \"../lib/calc\";\nimport { useMediaQuery } from \"../hooks/use-media-query\";\n\ninterface NumberInputProps {\n value: string;\n /** Fired on every keystroke with the raw text (comma → dot, operators kept so\n * a typed expression survives). */\n onChange: (value: string) => void;\n /** Fired on blur/Enter with the *evaluated* value — use this for save-on-blur\n * fields so the save always sees the resolved number, never \"10+5\". */\n onCommit?: (value: string) => void;\n label?: ReactNode;\n ariaLabel?: string;\n /** Names for the calculator this field renders — its trigger, and the controls\n * inside the popover — and for the numpad sheet it opens on a phone. Overrides\n * for THIS field only: both resolve the `calculator` namespace of\n * `<UiKitProvider labels>` themselves, then fall back to English.\n *\n * `pad` is not optional plumbing: this field renders a {@link NumberPadSheet}\n * exactly as {@link AmountInput} does, but had no way to pass it anything, so\n * the SAME keypad announced itself in German when a money field opened it and in\n * English when a goal target did. */\n labels?: {\n calculatorTrigger?: string;\n calculator?: CalculatorButtonLabels;\n pad?: NumberPadSheetLabels;\n };\n placeholder?: string;\n disabled?: boolean;\n autoFocus?: boolean;\n /** Wrapper class. */\n className?: string;\n /** Overrides the input's own styling (merged after the field base). */\n inputClassName?: string;\n id?: string;\n /** Show the calculator-popover trigger (default true). Set false for fields in\n * an ephemeral close-on-blur editor, where clicking the icon would blur away\n * and tear the editor down before the popover could open — inline typing\n * (e.g. \"200+50\" → Enter) still evaluates there. */\n calculator?: boolean;\n /** {@link FIELD_DISPLAY} — on a phone, the figure at display size with the field\n * chrome dropped. The currency-free half of the same treatment `AmountInput`\n * carries, for a dialog whose whole point is the one number (a budget goal's\n * target); not for a field among many, and never for the compact inline\n * editors this control also serves. */\n variant?: \"field\" | \"display\";\n /** A {@link FieldHint} \"?\" on the label's own line, beside the label rather\n * than at the far end of the strip — the far end is where the calculator\n * lives, and a hint placed there landed on top of it (steering-design\n * feedback #48). */\n hint?: ReactNode;\n /** Required and unanswered — {@link FIELD_INVALID}. See {@link Input}'s `invalid`. */\n invalid?: boolean;\n /**\n * A static unit shown at the field's right edge — \"%\", \"kg\", \"km/h\".\n *\n * The read-out half of {@link AmountInput}'s currency chip, and it exists for the\n * same reason that one does: a unit belongs to the FIELD, not to the text, so\n * typing it is a way to get it into the value. Keksdose had a percentage spelled\n * three different ways across three screens — `<Input type=\"number\" step=\"0.01\">`\n * for a loan rate, `step=\"0.1\"` for a tax rate, `inputMode=\"decimal\"` for a VAT\n * rate — and none of the three showed a \"%\" anywhere near the box, so what the\n * digits meant was a question the label alone had to answer.\n *\n * `aria-hidden`, like the currency read-out: it is a property of the field that\n * the label already names (\"Interest rate (%)\"), and announcing it again after\n * every value reads as part of the number.\n */\n suffix?: ReactNode;\n}\n\n/**\n * A numeric text field with a built-in calculator: type a calculation straight\n * in (e.g. \"12+5\", evaluated on blur/Enter) or click the trailing calculator\n * icon for a keypad. String `value`/`onChange` contract, mirroring\n * {@link AmountInput} — the currency-free counterpart for budgets, goals,\n * invoice totals and split lines.\n */\nexport function NumberInput({\n value,\n onChange,\n onCommit,\n label,\n ariaLabel,\n labels,\n placeholder,\n disabled,\n autoFocus,\n className,\n inputClassName,\n id,\n calculator = true,\n variant = \"field\",\n hint,\n invalid,\n suffix,\n}: NumberInputProps) {\n const generatedId = useId();\n const fieldId = id ?? generatedId;\n const labelled = label !== undefined;\n // On phones we suppress the OS keyboard (inputMode=\"none\" below) for our own\n // calculator numpad, so the desktop popover trigger is hidden (feedback #334).\n const isMobile = useMediaQuery(PHONE_QUERY, false);\n const asDisplay = isMobile && variant === \"display\";\n const showCalc = calculator && !disabled && !isMobile;\n const [focused, setFocused] = useState(false);\n // On mobile, focusing opens the numpad bottom sheet instead of the native\n // keyboard (#334); the ref lets its \"Done\" blur → commit + close.\n const showNumpad = isMobile && !disabled && focused;\n const inputRef = useRef<HTMLInputElement>(null);\n\n const commit = () => {\n const next = commitExpression(value);\n if (next !== value) onChange(next);\n onCommit?.(next);\n };\n\n const onKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {\n if (e.key === \"Enter\") commit();\n };\n\n return (\n <FloatingField\n className={cn(\"w-full\", className)}\n htmlFor={fieldId}\n label={label}\n srOnlyLabel={asDisplay}\n hint={hint}\n >\n <input\n ref={inputRef}\n id={fieldId}\n aria-label={ariaLabel}\n type=\"text\"\n // Mobile: suppress the OS keyboard so the numpad sheet owns entry (field\n // keeps focus/caret); desktop keeps the native decimal keypad.\n inputMode={isMobile ? \"none\" : \"decimal\"}\n autoComplete=\"off\"\n autoFocus={autoFocus}\n disabled={disabled}\n // Display mode has no floating label to feed the blank-placeholder trick,\n // and an empty borderless figure shows nothing — so it keeps whatever\n // placeholder the caller gave, falling back to a zero to aim at.\n placeholder={asDisplay ? (placeholder ?? \"0\") : labelled ? \" \" : placeholder}\n value={value}\n onChange={(e) => onChange(sanitizeLive(e.target.value))}\n onFocus={() => setFocused(true)}\n onBlur={() => {\n commit();\n setFocused(false);\n }}\n onKeyDown={onKeyDown}\n aria-invalid={invalid || undefined}\n // The right-padding sits last so it always wins over an inputClassName that\n // sets its own px. Both trailing controls can be on at once, so the room\n // they need is reserved together rather than by whichever happens to render:\n // the calculator is ~36px and a short unit ~24px, and a field that reserved\n // only one of them would let the digits run under the other.\n className={cn(\n asDisplay\n ? cn(FIELD_DISPLAY, \"text-4xl font-semibold leading-tight tracking-tight tabular-nums\")\n : labelled\n ? FLOATING_INPUT_CLASS\n : FIELD_BASE,\n inputClassName,\n showCalc && suffix !== undefined ? \"pr-16\" : showCalc ? \"pr-9\" : suffix !== undefined ? \"pr-8\" : undefined,\n invalid && FIELD_INVALID,\n )}\n />\n {(showCalc || suffix !== undefined) && (\n // One flex track for both, so the unit and the calculator sit side by side\n // instead of stacking on the same corner — AmountInput's arrangement, which\n // has carried a chip and a calculator together since #430.\n <div className=\"absolute inset-y-0 right-0 flex items-center\">\n {showCalc && (\n <CalculatorButton\n value={value}\n onChange={onChange}\n className=\"self-stretch px-2.5\"\n ariaLabel={labels?.calculatorTrigger}\n labels={labels?.calculator}\n />\n )}\n {suffix !== undefined && (\n <span\n aria-hidden\n className=\"pointer-events-none pr-3 text-xs font-medium text-[var(--text-muted)]\"\n >\n {suffix}\n </span>\n )}\n </div>\n )}\n {showNumpad && (\n <NumberPadSheet\n value={value}\n onChange={onChange}\n onDone={() => inputRef.current?.blur()}\n label={label}\n labels={labels?.pad}\n />\n )}\n </FloatingField>\n );\n}\n"],"mappings":";AAuIM,cA4CE,YA5CF;AAvIN,SAAS,OAAO,QAAQ,gBAAgB;AAExC,SAAS,wBAAqD;AAC9D,SAAS,sBAAiD;A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AU,CAAC,MAAM,SAAS,aAAa,EAAE,OAAO,KAAK,CAAC;AAAA,YACtD,SAAS,MAAM,WAAW,IAAI;AAAA,YAC9B,QAAQ,MAAM;AACZ,qBAAO;AACP,yBAAW,KAAK;AAAA,YAClB;AAAA,YACA;AAAA,YACA,gBAAc,WAAW;AAAA,YAMzB,WAAW;AAAA,cACT,YACI,GAAG,eAAe,kEAAkE,IACpF,WACE,uBACA;AAAA,cACN;AAAA,cACA,YAAY,WAAW,SAAY,UAAU,WAAW,SAAS,WAAW,SAAY,SAAS;AAAA,cACjG,WAAW;AAAA,YACb;AAAA;AAAA,QACF;AAAA,SACE,YAAY,WAAW;AAAA;AAAA;AAAA,QAIvB,qBAAC,SAAI,WAAU,gDACZ;AAAA,sBACC;AAAA,YAAC;AAAA;AAAA,cACC;AAAA,cACA;AAAA,cACA,WAAU;AAAA,cACV,WAAW,QAAQ;AAAA,cACnB,QAAQ,QAAQ;AAAA;AAAA,UAClB;AAAA,UAED,WAAW,UACV;AAAA,YAAC;AAAA;AAAA,cACC,eAAW;AAAA,cACX,WAAU;AAAA,cAET;AAAA;AAAA,UACH;AAAA,WAEJ;AAAA,QAED,cACC;AAAA,UAAC;AAAA;AAAA,YACC;AAAA,YACA;AAAA,YACA,QAAQ,MAAM,SAAS,SAAS,KAAK;AAAA,YACrC;AAAA,YACA,QAAQ,QAAQ;AAAA;AAAA,QAClB;AAAA;AAAA;AAAA,EAEJ;AAEJ;","names":[]}
@@ -1,5 +1,23 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
+ import { CalculatorLabels } from '../i18n/kit-labels.js';
4
+ import './data-table-labels.js';
5
+ import './mini-calendar.js';
6
+ import './popover.js';
7
+ import './chip.js';
8
+ import 'lucide-react';
9
+ import './field-sync.js';
10
+ import './ui.js';
11
+ import '../wizard/types.js';
12
+ import '../tour/tour.js';
13
+ import '../search/command-palette.js';
14
+ import './month-picker.js';
15
+ import './page-contents.js';
16
+ import './series-chart-labels.js';
17
+ import './sparkline.js';
18
+ import './stat-tile.js';
19
+ import './signature-pad.js';
20
+ import './password-strength.js';
3
21
 
4
22
  /**
5
23
  * A full calculator keypad rendered as a bottom sheet — the mobile counterpart to
@@ -24,7 +42,8 @@ import { ReactNode } from 'react';
24
42
  * the brand-filled primary button — and it was a hardcoded English literal while
25
43
  * its three neighbours each took an override, so a German phone showed "Done"
26
44
  * among German labels with no prop able to change it. */
27
- interface NumberPadSheetLabels {
45
+ interface NumberPadSheetLabels extends Partial<CalculatorLabels> {
46
+ /** The pad's own name — the `calculator.panel` key under its older name here. */
28
47
  pad?: string;
29
48
  backspace?: string;
30
49
  clear?: string;
@@ -43,9 +62,11 @@ declare function NumberPadSheet({ value, onChange, onDone, label, labels, }: {
43
62
  /** Optional field label, echoed in the sheet header so the user still knows
44
63
  * which field they're editing when the sheet covers it. */
45
64
  label?: ReactNode;
46
- /** Names for the pad itself and its four non-digit keys — screen-reader names,
47
- * except `done`, which is the visible text on the primary key. The digits and
48
- * operators need none: their visible glyph IS the name. */
65
+ /** Names for the pad itself and its non-digit keys — screen-reader names, except
66
+ * `done`, which is the visible text on the primary key. Merged over `calculator`
67
+ * from `<UiKitProvider labels>`: this is the same keypad as `CalculatorButton`'s,
68
+ * on a phone, and one translation covers both. Digits need no name — their glyph
69
+ * IS the name; the operators do (see {@link CalculatorLabels.plus}). */
49
70
  labels?: NumberPadSheetLabels;
50
71
  }): react.ReactPortal;
51
72
 
@@ -1,27 +1,34 @@
1
+ "use client";
1
2
  import { jsx, jsxs } from "react/jsx-runtime";
2
3
  import { createPortal } from "react-dom";
3
4
  import { Delete } from "lucide-react";
5
+ import { useMemo } from "react";
4
6
  import { cn } from "../lib/cn.js";
7
+ import { useEscapeKey } from "../hooks/use-dismiss.js";
5
8
  import { evaluateExpression, formatResult, sanitizeLive } from "../lib/calc.js";
9
+ import {
10
+ DEFAULT_CALCULATOR_LABELS,
11
+ useKitLabels
12
+ } from "../i18n/kit-labels.js";
6
13
  const PAD_KEYS = [
7
14
  { kind: "ins", label: "7", ins: "7" },
8
15
  { kind: "ins", label: "8", ins: "8" },
9
16
  { kind: "ins", label: "9", ins: "9" },
10
- { kind: "ins", label: "\xF7", ins: "\xF7", accent: true },
17
+ { kind: "ins", label: "\xF7", ins: "\xF7", accent: true, name: "divide" },
11
18
  { kind: "ins", label: "4", ins: "4" },
12
19
  { kind: "ins", label: "5", ins: "5" },
13
20
  { kind: "ins", label: "6", ins: "6" },
14
- { kind: "ins", label: "\xD7", ins: "\xD7", accent: true },
21
+ { kind: "ins", label: "\xD7", ins: "\xD7", accent: true, name: "times" },
15
22
  { kind: "ins", label: "1", ins: "1" },
16
23
  { kind: "ins", label: "2", ins: "2" },
17
24
  { kind: "ins", label: "3", ins: "3" },
18
- { kind: "ins", label: "\u2212", ins: "-", accent: true },
19
- { kind: "ins", label: ".", ins: "." },
25
+ { kind: "ins", label: "\u2212", ins: "-", accent: true, name: "minus" },
26
+ { kind: "ins", label: ".", ins: ".", name: "decimal" },
20
27
  { kind: "ins", label: "0", ins: "0" },
21
28
  { kind: "back" },
22
- { kind: "ins", label: "+", ins: "+", accent: true }
29
+ { kind: "ins", label: "+", ins: "+", accent: true, name: "plus" }
23
30
  ];
24
- const PAD_BTN = "flex h-14 items-center justify-center rounded-lg text-lg font-medium transition-transform select-none focus:outline-none active:scale-[0.97]";
31
+ const PAD_BTN = "flex h-14 items-center justify-center rounded-lg text-lg font-medium transition-transform select-none focus:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--brand)] active:scale-[0.97]";
25
32
  const PAD_DIGIT = "bg-[var(--bg-surface-2)] text-[var(--text-primary)] active:bg-[var(--border)]";
26
33
  const PAD_ACCENT = "bg-[var(--border)] text-[var(--text-primary)] active:bg-[var(--bg-surface-2)]";
27
34
  function NumberPadSheet({
@@ -31,6 +38,13 @@ function NumberPadSheet({
31
38
  label,
32
39
  labels
33
40
  }) {
41
+ const fromProps = useMemo(() => {
42
+ if (!labels) return void 0;
43
+ const { pad, ...rest } = labels;
44
+ return pad === void 0 ? rest : { ...rest, panel: pad };
45
+ }, [labels]);
46
+ const text = useKitLabels("calculator", DEFAULT_CALCULATOR_LABELS, fromProps);
47
+ useEscapeKey(onDone);
34
48
  const result = evaluateExpression(value);
35
49
  const preview = result !== null && formatResult(result) !== value.trim() ? `= ${formatResult(result)}` : "";
36
50
  const insert = (ch) => onChange(sanitizeLive(value + ch));
@@ -43,7 +57,7 @@ function NumberPadSheet({
43
57
  "div",
44
58
  {
45
59
  role: "group",
46
- "aria-label": labels?.pad ?? "Number pad",
60
+ "aria-label": text.panel,
47
61
  onPointerDown: (e) => e.preventDefault(),
48
62
  className: "fixed inset-x-0 bottom-0 z-50 border-t border-[var(--border)] bg-[var(--bg-surface)] px-2 pt-2 shadow-[0_-4px_24px_rgba(0,0,0,0.12)]",
49
63
  style: { paddingBottom: "max(0.5rem, env(safe-area-inset-bottom))" },
@@ -60,7 +74,7 @@ function NumberPadSheet({
60
74
  "button",
61
75
  {
62
76
  type: "button",
63
- "aria-label": labels?.backspace ?? "Backspace",
77
+ "aria-label": text.backspace,
64
78
  onClick: backspace,
65
79
  className: cn(PAD_BTN, PAD_ACCENT),
66
80
  children: /* @__PURE__ */ jsx(Delete, { className: "size-5" })
@@ -70,7 +84,7 @@ function NumberPadSheet({
70
84
  "button",
71
85
  {
72
86
  type: "button",
73
- "aria-label": key.label,
87
+ "aria-label": key.name ? text[key.name] : key.label,
74
88
  onClick: () => insert(key.ins),
75
89
  className: cn(PAD_BTN, key.accent ? PAD_ACCENT : PAD_DIGIT),
76
90
  children: key.label
@@ -79,15 +93,18 @@ function NumberPadSheet({
79
93
  )
80
94
  ) }),
81
95
  /* @__PURE__ */ jsxs("div", { className: "mt-1.5 grid grid-cols-4 gap-1.5", children: [
82
- /* @__PURE__ */ jsx("button", { type: "button", "aria-label": labels?.clear ?? "Clear", onClick: clearAll, className: cn(PAD_BTN, PAD_ACCENT), children: "C" }),
83
- /* @__PURE__ */ jsx("button", { type: "button", "aria-label": labels?.equals ?? "Equals", onClick: equals, className: cn(PAD_BTN, PAD_ACCENT), children: "=" }),
96
+ /* @__PURE__ */ jsx("button", { type: "button", "aria-label": text.clear, onClick: clearAll, className: cn(PAD_BTN, PAD_ACCENT), children: "C" }),
97
+ /* @__PURE__ */ jsx("button", { type: "button", "aria-label": text.equals, onClick: equals, className: cn(PAD_BTN, PAD_ACCENT), children: "=" }),
84
98
  /* @__PURE__ */ jsx(
85
99
  "button",
86
100
  {
87
101
  type: "button",
88
102
  onClick: onDone,
89
- className: cn(PAD_BTN, "col-span-2 bg-[var(--brand)] text-[var(--brand-contrast)] active:bg-[var(--brand-hover)]"),
90
- children: labels?.done ?? "Done"
103
+ className: cn(
104
+ PAD_BTN,
105
+ "col-span-2 bg-[var(--brand)] text-[var(--brand-contrast)] focus-visible:ring-[var(--brand-contrast)] active:bg-[var(--brand-hover)]"
106
+ ),
107
+ children: text.done
91
108
  }
92
109
  )
93
110
  ] })