@eifi1/ui-kit 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (410) 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 +128 -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 +91 -20
  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 +107 -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 +232 -94
  61. package/dist/components/date-picker.js.map +1 -1
  62. package/dist/components/dropdown.d.ts +96 -20
  63. package/dist/components/dropdown.js +77 -33
  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 +38 -6
  75. package/dist/components/file-dropzone.js +34 -9
  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 +342 -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 +28 -2
  105. package/dist/components/number-input.js +12 -2
  106. package/dist/components/number-input.js.map +1 -1
  107. package/dist/components/numpad-sheet.d.ts +32 -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 +52 -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/ui.d.ts +159 -46
  168. package/dist/components/ui.js +220 -115
  169. package/dist/components/ui.js.map +1 -1
  170. package/dist/components/use-mobile-reveal.js +1 -0
  171. package/dist/components/use-mobile-reveal.js.map +1 -1
  172. package/dist/components/use-table-state.d.ts +1 -1
  173. package/dist/components/use-table-state.js +38 -17
  174. package/dist/components/use-table-state.js.map +1 -1
  175. package/dist/components/user-avatar.d.ts +15 -4
  176. package/dist/components/user-avatar.js +5 -4
  177. package/dist/components/user-avatar.js.map +1 -1
  178. package/dist/components/wizard-stepper.js +3 -2
  179. package/dist/components/wizard-stepper.js.map +1 -1
  180. package/dist/{data-table-filters-aXyf0Xub.d.ts → data-table-filters-DM1auUfH.d.ts} +27 -5
  181. package/dist/data-table.d.ts +7 -0
  182. package/dist/data-table.js +12 -0
  183. package/dist/data-table.js.map +1 -0
  184. package/dist/feedback/feedback-attachment.js +12 -11
  185. package/dist/feedback/feedback-attachment.js.map +1 -1
  186. package/dist/feedback/feedback-dialog.js +2 -1
  187. package/dist/feedback/feedback-dialog.js.map +1 -1
  188. package/dist/feedback/feedback-inbox.d.ts +33 -7
  189. package/dist/feedback/feedback-inbox.js +49 -37
  190. package/dist/feedback/feedback-inbox.js.map +1 -1
  191. package/dist/feedback.d.ts +5 -0
  192. package/dist/feedback.js +5 -0
  193. package/dist/feedback.js.map +1 -0
  194. package/dist/hooks/use-anchored-panel.js +1 -0
  195. package/dist/hooks/use-anchored-panel.js.map +1 -1
  196. package/dist/hooks/use-anchored-rect.js +1 -0
  197. package/dist/hooks/use-anchored-rect.js.map +1 -1
  198. package/dist/hooks/use-announce.d.ts +46 -0
  199. package/dist/hooks/use-announce.js +37 -0
  200. package/dist/hooks/use-announce.js.map +1 -0
  201. package/dist/hooks/use-body-scroll-lock.js +1 -0
  202. package/dist/hooks/use-body-scroll-lock.js.map +1 -1
  203. package/dist/hooks/use-close-transition.js +1 -0
  204. package/dist/hooks/use-close-transition.js.map +1 -1
  205. package/dist/hooks/use-dismiss.js +1 -0
  206. package/dist/hooks/use-dismiss.js.map +1 -1
  207. package/dist/hooks/use-focus-trap.d.ts +16 -0
  208. package/dist/hooks/use-focus-trap.js +67 -0
  209. package/dist/hooks/use-focus-trap.js.map +1 -0
  210. package/dist/hooks/use-media-query.js +1 -0
  211. package/dist/hooks/use-media-query.js.map +1 -1
  212. package/dist/hooks/use-overlay-history.js +27 -1
  213. package/dist/hooks/use-overlay-history.js.map +1 -1
  214. package/dist/hooks/use-row-swipe.js +1 -0
  215. package/dist/hooks/use-row-swipe.js.map +1 -1
  216. package/dist/i18n/defaults.d.ts +31 -0
  217. package/dist/i18n/defaults.js +63 -0
  218. package/dist/i18n/defaults.js.map +1 -0
  219. package/dist/i18n/kit-labels.d.ts +250 -0
  220. package/dist/i18n/kit-labels.js +184 -0
  221. package/dist/i18n/kit-labels.js.map +1 -0
  222. package/dist/index.d.ts +47 -22
  223. package/dist/index.js +28 -0
  224. package/dist/index.js.map +1 -1
  225. package/dist/lib/calc.js +1 -0
  226. package/dist/lib/calc.js.map +1 -1
  227. package/dist/lib/cn.js +1 -0
  228. package/dist/lib/cn.js.map +1 -1
  229. package/dist/lib/dates.js +1 -0
  230. package/dist/lib/dates.js.map +1 -1
  231. package/dist/lib/logger.js +1 -0
  232. package/dist/lib/logger.js.map +1 -1
  233. package/dist/lib/safe-storage.js +1 -0
  234. package/dist/lib/safe-storage.js.map +1 -1
  235. package/dist/search/command-palette.d.ts +11 -1
  236. package/dist/search/command-palette.js +21 -15
  237. package/dist/search/command-palette.js.map +1 -1
  238. package/dist/search.d.ts +2 -0
  239. package/dist/search.js +3 -0
  240. package/dist/search.js.map +1 -0
  241. package/dist/shell/app-shell.d.ts +33 -4
  242. package/dist/shell/app-shell.js +275 -78
  243. package/dist/shell/app-shell.js.map +1 -1
  244. package/dist/shell/option-switcher-menu.js +3 -2
  245. package/dist/shell/option-switcher-menu.js.map +1 -1
  246. package/dist/shell/role-switcher.d.ts +6 -0
  247. package/dist/shell/role-switcher.js +7 -4
  248. package/dist/shell/role-switcher.js.map +1 -1
  249. package/dist/shell/top-bar.d.ts +15 -7
  250. package/dist/shell/top-bar.js +3 -5
  251. package/dist/shell/top-bar.js.map +1 -1
  252. package/dist/shell/topbar-action-menu.js +3 -2
  253. package/dist/shell/topbar-action-menu.js.map +1 -1
  254. package/dist/shell/topbar-controls.d.ts +5 -2
  255. package/dist/shell/topbar-controls.js +20 -15
  256. package/dist/shell/topbar-controls.js.map +1 -1
  257. package/dist/shell.d.ts +13 -0
  258. package/dist/shell.js +8 -0
  259. package/dist/shell.js.map +1 -0
  260. package/dist/theme/chart-palette.d.ts +19 -12
  261. package/dist/theme/chart-palette.js +24 -30
  262. package/dist/theme/chart-palette.js.map +1 -1
  263. package/dist/theme/color.d.ts +78 -0
  264. package/dist/theme/color.js +148 -0
  265. package/dist/theme/color.js.map +1 -0
  266. package/dist/theme/palette-derive.d.ts +140 -0
  267. package/dist/theme/palette-derive.js +376 -0
  268. package/dist/theme/palette-derive.js.map +1 -0
  269. package/dist/theme/palette-presets.d.ts +27 -5
  270. package/dist/theme/palette-presets.js +231 -33
  271. package/dist/theme/palette-presets.js.map +1 -1
  272. package/dist/theme/palette-store.js +1 -0
  273. package/dist/theme/palette-store.js.map +1 -1
  274. package/dist/theme/theme-store.js +1 -0
  275. package/dist/theme/theme-store.js.map +1 -1
  276. package/dist/tour/tour.d.ts +2 -1
  277. package/dist/tour/tour.js +15 -9
  278. package/dist/tour/tour.js.map +1 -1
  279. package/dist/tour.d.ts +2 -0
  280. package/dist/tour.js +3 -0
  281. package/dist/tour.js.map +1 -0
  282. package/dist/wizard/stepper-nav.js +10 -8
  283. package/dist/wizard/stepper-nav.js.map +1 -1
  284. package/dist/wizard/types.d.ts +18 -2
  285. package/dist/wizard/types.js +4 -1
  286. package/dist/wizard/types.js.map +1 -1
  287. package/dist/wizard/use-wizard.js +12 -4
  288. package/dist/wizard/use-wizard.js.map +1 -1
  289. package/dist/wizard/validation.js +1 -0
  290. package/dist/wizard/validation.js.map +1 -1
  291. package/dist/wizard/wizard-context.js +1 -0
  292. package/dist/wizard/wizard-context.js.map +1 -1
  293. package/dist/wizard/wizard-step.js +1 -0
  294. package/dist/wizard/wizard-step.js.map +1 -1
  295. package/dist/wizard/wizard-summary.js +5 -3
  296. package/dist/wizard/wizard-summary.js.map +1 -1
  297. package/dist/wizard.d.ts +8 -0
  298. package/dist/wizard.js +9 -0
  299. package/dist/wizard.js.map +1 -0
  300. package/package.json +67 -14
  301. package/src/chart.ts +22 -0
  302. package/src/components/account-settings.tsx +275 -0
  303. package/src/components/alert-banner.tsx +75 -0
  304. package/src/components/amount-input.tsx +471 -0
  305. package/src/components/calculator.tsx +252 -0
  306. package/src/components/chart-zoom.tsx +499 -0
  307. package/src/components/chart.tsx +363 -0
  308. package/src/components/checkbox.tsx +222 -0
  309. package/src/components/chip.tsx +570 -0
  310. package/src/components/choice-parts.ts +33 -0
  311. package/src/components/combobox-core.tsx +540 -0
  312. package/src/components/combobox.tsx +1026 -0
  313. package/src/components/currency-select.tsx +269 -0
  314. package/src/components/data-table-filter-popover.tsx +252 -0
  315. package/src/components/data-table-filters.ts +176 -0
  316. package/src/components/data-table-labels.ts +190 -0
  317. package/src/components/data-table-pagination.tsx +126 -0
  318. package/src/components/data-table-sort.ts +70 -0
  319. package/src/components/data-table.tsx +1740 -0
  320. package/src/components/date-picker.tsx +631 -0
  321. package/src/components/dropdown.tsx +341 -0
  322. package/src/components/entity-combobox.tsx +215 -0
  323. package/src/components/facing-pair.ts +86 -0
  324. package/src/components/field-sync.tsx +472 -0
  325. package/src/components/file-dropzone.tsx +181 -0
  326. package/src/components/full-bleed-dialog.tsx +179 -0
  327. package/src/components/grouped-picker.tsx +157 -0
  328. package/src/components/hover-menu.tsx +183 -0
  329. package/src/components/mini-calendar.tsx +554 -0
  330. package/src/components/modal.tsx +287 -0
  331. package/src/components/month-picker.tsx +549 -0
  332. package/src/components/multi-entity-combobox.tsx +226 -0
  333. package/src/components/multi-select.tsx +303 -0
  334. package/src/components/number-field.tsx +225 -0
  335. package/src/components/number-input.tsx +211 -0
  336. package/src/components/numpad-sheet.tsx +264 -0
  337. package/src/components/page-contents.tsx +289 -0
  338. package/src/components/password-strength.tsx +258 -0
  339. package/src/components/picker-sheet.tsx +251 -0
  340. package/src/components/popover.tsx +195 -0
  341. package/src/components/search-field.tsx +146 -0
  342. package/src/components/series-chart-labels.ts +26 -0
  343. package/src/components/series-chart.tsx +481 -0
  344. package/src/components/settings-fields.tsx +68 -0
  345. package/src/components/signature-pad.tsx +630 -0
  346. package/src/components/slider.tsx +313 -0
  347. package/src/components/sparkline.tsx +329 -0
  348. package/src/components/stat-tile.tsx +448 -0
  349. package/src/components/swipeable-row.tsx +271 -0
  350. package/src/components/switch.tsx +170 -0
  351. package/src/components/time-input.tsx +107 -0
  352. package/src/components/toggle-group.tsx +153 -0
  353. package/src/components/toggle-legend.tsx +229 -0
  354. package/src/components/tooltip.tsx +477 -0
  355. package/src/components/treemap.tsx +390 -0
  356. package/src/components/ui.tsx +1284 -0
  357. package/src/components/use-mobile-reveal.ts +54 -0
  358. package/src/components/use-table-state.ts +295 -0
  359. package/src/components/user-avatar.tsx +61 -0
  360. package/src/components/wizard-stepper.tsx +37 -0
  361. package/src/data-table.ts +19 -0
  362. package/src/feedback/feedback-attachment.tsx +246 -0
  363. package/src/feedback/feedback-dialog.tsx +209 -0
  364. package/src/feedback/feedback-inbox.tsx +615 -0
  365. package/src/feedback.ts +8 -0
  366. package/src/hooks/use-anchored-panel.ts +169 -0
  367. package/src/hooks/use-anchored-rect.ts +78 -0
  368. package/src/hooks/use-announce.ts +85 -0
  369. package/src/hooks/use-body-scroll-lock.ts +94 -0
  370. package/src/hooks/use-close-transition.ts +99 -0
  371. package/src/hooks/use-dismiss.ts +77 -0
  372. package/src/hooks/use-focus-trap.ts +160 -0
  373. package/src/hooks/use-media-query.ts +23 -0
  374. package/src/hooks/use-overlay-history.ts +345 -0
  375. package/src/hooks/use-row-swipe.ts +212 -0
  376. package/src/i18n/defaults.ts +68 -0
  377. package/src/i18n/kit-labels.tsx +447 -0
  378. package/src/index.ts +169 -0
  379. package/src/lib/calc.ts +309 -0
  380. package/src/lib/cn.ts +5 -0
  381. package/src/lib/dates.ts +187 -0
  382. package/src/lib/logger.ts +73 -0
  383. package/src/lib/safe-storage.ts +37 -0
  384. package/src/search/command-palette.tsx +342 -0
  385. package/src/search.ts +3 -0
  386. package/src/shell/app-shell.tsx +772 -0
  387. package/src/shell/option-switcher-menu.tsx +72 -0
  388. package/src/shell/role-switcher.tsx +46 -0
  389. package/src/shell/top-bar.tsx +39 -0
  390. package/src/shell/topbar-action-menu.tsx +91 -0
  391. package/src/shell/topbar-controls.tsx +229 -0
  392. package/src/shell.ts +10 -0
  393. package/src/theme/chart-palette.ts +145 -0
  394. package/src/theme/color.ts +266 -0
  395. package/src/theme/palette-derive.ts +681 -0
  396. package/src/theme/palette-presets.ts +760 -0
  397. package/src/theme/palette-store.ts +94 -0
  398. package/src/theme/theme-store.ts +145 -0
  399. package/src/tour/tour.tsx +586 -0
  400. package/src/tour.ts +3 -0
  401. package/src/vite-env.d.ts +26 -0
  402. package/src/wizard/stepper-nav.tsx +221 -0
  403. package/src/wizard/types.ts +178 -0
  404. package/src/wizard/use-wizard.ts +345 -0
  405. package/src/wizard/validation.ts +37 -0
  406. package/src/wizard/wizard-context.tsx +29 -0
  407. package/src/wizard/wizard-step.tsx +14 -0
  408. package/src/wizard/wizard-summary.tsx +69 -0
  409. package/src/wizard.ts +14 -0
  410. package/tokens.css +222 -20
@@ -0,0 +1,341 @@
1
+ import { useCallback, useEffect, useRef, useState } from "react";
2
+ import type {
3
+ ComponentPropsWithoutRef,
4
+ KeyboardEvent as ReactKeyboardEvent,
5
+ ReactNode,
6
+ RefObject,
7
+ } from "react";
8
+ import { createPortal } from "react-dom";
9
+ import { Search } from "lucide-react";
10
+ import { useAnchoredPanel } from "../hooks/use-anchored-panel";
11
+ import { useEscapeKey, useOutsideClick } from "../hooks/use-dismiss";
12
+ import { useOverlayHistory } from "../hooks/use-overlay-history";
13
+ import { cn } from "../lib/cn";
14
+
15
+ /**
16
+ * Open state + close-on-outside-click for the custom dropdowns (MultiSelect,
17
+ * CurrencySelect, AmountInput's currency picker, Combobox). Attach `wrapperRef`
18
+ * to the relatively-positioned container; the popover lives inside it so a click
19
+ * anywhere else closes it.
20
+ *
21
+ * ## Back closes the list, not the page behind it
22
+ *
23
+ * Keksdose live #309 rework: *"It shall only close it if it is prior open, and not
24
+ * when I am seeing the dialog."* Round one wired {@link PickerSheet} — the shape
25
+ * these lists take on a PHONE — into {@link useOverlayHistory}, and left the pointer
26
+ * shape out. So on a desktop one Back press over an open list still went past it to
27
+ * the dialog underneath: measured on his own budget, the transfer form's account list
28
+ * was showing and Back took the entire add card, amount and all. That is the same
29
+ * loss round one called *"discarding an edit in progress in order to dismiss a
30
+ * list"*, in the other shell.
31
+ *
32
+ * Every dropdown built on this hook is dismissible and is the topmost thing on screen
33
+ * while it is up, so the rule is the hook's rather than each caller's. `backCloses`
34
+ * is for the ONE case where a second entry would be wrong: a caller whose panel is
35
+ * itself a `PickerSheet`, which already registers one — both comboboxes swap shape at
36
+ * {@link PHONE_QUERY}, and two entries would cost two Back presses to close one sheet.
37
+ *
38
+ * ## One outside-click rule for the whole package
39
+ *
40
+ * This hand-rolled a second document listener, on `mousedown`, months after
41
+ * {@link useOutsideClick} — the hook the entity pickers dismiss through — was moved to
42
+ * `pointerdown` for a reason that applies here word for word: on a touch platform
43
+ * `mousedown` is SYNTHESISED, the browser emits it for most taps but is not obliged
44
+ * to, and MultiSelect, CurrencySelect, GroupedPicker, AmountInput's currency picker
45
+ * and both comboboxes all dismiss through this. Two copies of one rule is one copy
46
+ * too many; this now delegates, so the package has a single answer to "what is an
47
+ * outside press".
48
+ *
49
+ * `panelIsSheet` is what that delegation needs. A {@link PickerSheet} is modal and
50
+ * fills the screen, so it has no outside — and being portalled to `<body>`, it is
51
+ * inside neither `wrapperRef` nor `panelRef`, so a listener left running would read
52
+ * every tap in it as a press outside and close it at finger-down. The sheet's own
53
+ * `onMouseDown` stopPropagation guard used to hide that from this hook; it cannot
54
+ * stop a `pointerdown`. It defaults to `!backCloses` because the two ask the same
55
+ * question — "is this caller's panel a sheet?" — and the one caller that answers yes
56
+ * already says so; they are separate props so a future caller can answer them apart.
57
+ *
58
+ * ## Escape, and where focus lands after it
59
+ *
60
+ * This hook had no Escape at all (the audit's §a11y): Back closed these lists, an
61
+ * outside press closed them, and the one key every other dismissible surface in the
62
+ * package answers to did nothing — so a keyboard user who opened a list had no way
63
+ * out of it that did not also choose something. {@link useEscapeKey} is the listener
64
+ * `Modal`, `Popover` and `useComboboxCore` already dismiss through, so the package
65
+ * keeps one answer to "what does Escape do" rather than growing a fifth.
66
+ *
67
+ * Escape RESTORES FOCUS; an outside press does not. A press has already put focus
68
+ * where the user pointed, and dragging it back from there would be the bug. Attach
69
+ * `triggerRef` to the control that opens the panel and the keyboard paths — Escape,
70
+ * Tab, a commit — hand focus back to it; leave it unattached and they simply close,
71
+ * which is what the callers written before this get.
72
+ */
73
+ export function useDropdown<T extends HTMLElement = HTMLDivElement>({
74
+ backCloses = true,
75
+ panelIsSheet = !backCloses,
76
+ }: { backCloses?: boolean; panelIsSheet?: boolean } = {}) {
77
+ const [open, setOpen] = useState(false);
78
+ const wrapperRef = useRef<T>(null);
79
+ // The control that opens the panel — see the note above on why only the keyboard
80
+ // paths read it, and why attaching it is the caller's choice.
81
+ const triggerRef = useRef<HTMLButtonElement>(null);
82
+ // The panel, once it is PORTALLED (see {@link DropdownPanel}'s `anchorRef`): it is
83
+ // then a child of <body> rather than of the wrapper, so "did the click land inside
84
+ // the wrapper" answers no for every click on the list itself and the first option a
85
+ // user picked closed the dropdown without picking anything.
86
+ const panelRef = useRef<HTMLDivElement>(null);
87
+ const close = useCallback(() => setOpen(false), []);
88
+ // Closing unmounts whatever held focus — the search box, the row the keyboard was
89
+ // on — and the browser then drops focus on <body>: the caret vanishes and the next
90
+ // Tab restarts at the top of the document. Whoever closed the list with a key gets
91
+ // it handed back to the trigger they opened it from.
92
+ const closeToTrigger = useCallback(() => {
93
+ setOpen(false);
94
+ triggerRef.current?.focus();
95
+ }, []);
96
+ useOutsideClick([wrapperRef, panelRef], close, open && !panelIsSheet);
97
+ useEscapeKey(closeToTrigger, open);
98
+ // Same close path Escape and an outside click take, so a list dismissed by Back
99
+ // cannot end up in a different state from one dismissed any other way.
100
+ useOverlayHistory(open && backCloses, close);
101
+ return { open, setOpen, wrapperRef, panelRef, triggerRef, closeToTrigger };
102
+ }
103
+
104
+ /**
105
+ * {@link useDropdown} plus a search box: clears the query and focuses the search
106
+ * input each time the panel opens, so typing filters immediately.
107
+ */
108
+ export function useDropdownSearch<T extends HTMLElement = HTMLDivElement>() {
109
+ const { open, setOpen, wrapperRef, panelRef, triggerRef, closeToTrigger } =
110
+ useDropdown<T>();
111
+ const [query, setQuery] = useState("");
112
+ const inputRef = useRef<HTMLInputElement>(null);
113
+ useEffect(() => {
114
+ if (open) {
115
+ // eslint-disable-next-line react-hooks/set-state-in-effect -- reset the query on open
116
+ setQuery("");
117
+ requestAnimationFrame(() => inputRef.current?.focus());
118
+ }
119
+ }, [open]);
120
+ return {
121
+ open,
122
+ setOpen,
123
+ wrapperRef,
124
+ panelRef,
125
+ triggerRef,
126
+ closeToTrigger,
127
+ query,
128
+ setQuery,
129
+ inputRef,
130
+ };
131
+ }
132
+
133
+ /** `onKeyDown` is the INPUT's, not the wrapper's — the list's keyboard is handled
134
+ * where the focus is (see the note above), so the div's own handler signature is
135
+ * omitted in favour of it. */
136
+ export interface DropdownSearchHeaderProps
137
+ extends Omit<ComponentPropsWithoutRef<"div">, "onKeyDown"> {
138
+ query: string;
139
+ onQueryChange: (v: string) => void;
140
+ inputRef: RefObject<HTMLInputElement | null>;
141
+ placeholder?: string;
142
+ /** The `<ul role="listbox">` this box filters. */
143
+ listboxId?: string;
144
+ /** The id of the option the arrow keys are currently on, if any. */
145
+ activeId?: string;
146
+ /** Arrow/Home/End/Enter/Tab — the list's keyboard, handled where the focus is. */
147
+ onKeyDown?: (e: ReactKeyboardEvent<HTMLInputElement>) => void;
148
+ }
149
+
150
+ /** The search row (magnifier + text input) shared by the searchable dropdowns.
151
+ *
152
+ * The input had `outline-none` and nothing in its place (the audit's §a11y, the same
153
+ * finding as the numpad's keys). That mattered more here than the bare class suggests:
154
+ * {@link useDropdownSearch} focuses this box the moment a panel opens, so the caret is
155
+ * the ONLY evidence of where the next keystroke goes — and a caret in an empty field
156
+ * showing a placeholder is a single blinking pixel column. The ring is what says "this
157
+ * list is being typed into"; it appears whenever the field holds focus, which for a
158
+ * text input is exactly when it is true.
159
+ *
160
+ * ## Why this box is a plain textbox and the TRIGGER is the combobox
161
+ *
162
+ * The panels this header sits in are opened by a field-shaped trigger, and that
163
+ * trigger is what carries `role="combobox"` (see {@link MultiSelect},
164
+ * {@link EntityCombobox}). Two comboboxes for one list would be one too many — a
165
+ * reader tabbing back to the field would meet a second one describing the same
166
+ * choice. So this stays a textbox, which ARIA lets own `aria-activedescendant` and
167
+ * `aria-controls` exactly as a combobox does: focus is HERE while the list is up, so
168
+ * this is what has to say which option the arrow keys are on.
169
+ *
170
+ * Pass `listboxId` and the wiring appears; omit it and the box is what it always
171
+ * was, for the callers that have no listbox to point at. */
172
+ export function DropdownSearchHeader({
173
+ query,
174
+ onQueryChange,
175
+ inputRef,
176
+ placeholder,
177
+ listboxId,
178
+ activeId,
179
+ onKeyDown,
180
+ "aria-label": ariaLabel,
181
+ className,
182
+ ...rest
183
+ }: DropdownSearchHeaderProps) {
184
+ return (
185
+ // `rest` dresses the header row; the NAME goes on the box below it. A search
186
+ // input whose only name is its placeholder has none the moment a character is
187
+ // typed into it — the placeholder disappears — which is why this is worth a prop
188
+ // at all rather than something a caller could add from outside.
189
+ <div
190
+ {...rest}
191
+ className={cn(
192
+ "flex items-center gap-2 border-b border-[var(--border)] px-2 py-1.5",
193
+ className,
194
+ )}
195
+ >
196
+ <Search className="size-4 text-[var(--text-placeholder)]" />
197
+ <input
198
+ ref={inputRef}
199
+ type="text"
200
+ value={query}
201
+ onChange={(e) => onQueryChange(e.target.value)}
202
+ onKeyDown={onKeyDown}
203
+ placeholder={placeholder}
204
+ aria-label={ariaLabel}
205
+ aria-controls={listboxId}
206
+ aria-activedescendant={activeId}
207
+ aria-autocomplete={listboxId ? "list" : undefined}
208
+ className="w-full rounded-sm bg-transparent text-sm outline-none placeholder:text-[var(--text-placeholder)] text-[var(--text-primary)] focus-visible:ring-2 focus-visible:ring-[var(--brand)]"
209
+ />
210
+ </div>
211
+ );
212
+ }
213
+
214
+ export interface DropdownPanelProps extends ComponentPropsWithoutRef<"div"> {
215
+ header?: ReactNode;
216
+ empty?: boolean;
217
+ /** Attributes for the `<ul>` itself — how a caller whose children are options
218
+ * gives the list its `role="listbox"`, its id and `aria-multiselectable`. The
219
+ * panel owns the scrolling and the padding, so `className` here is merged rather
220
+ * than replaced. */
221
+ listProps?: ComponentPropsWithoutRef<"ul">;
222
+ /** The trigger to hang off. Given, the panel portals and goes `fixed`. */
223
+ anchorRef?: RefObject<HTMLElement | null>;
224
+ /** {@link useDropdown}'s `panelRef`, so an outside-click sees this as inside. */
225
+ panelRef?: RefObject<HTMLDivElement | null>;
226
+ /** Panel width in px, for the anchored form (the CSS `w-*` cannot be measured). */
227
+ width?: number;
228
+ /** Which of the panel's edges lines up with the trigger's, room permitting. */
229
+ align?: "left" | "right";
230
+ children: ReactNode;
231
+ }
232
+
233
+ /**
234
+ * The floating popover surface for the searchable dropdowns: bordered/shadowed
235
+ * panel, an optional `header` slot (search box, plus any actions), and a
236
+ * scrollable `<ul>` of `children` with an "empty" row when nothing matches.
237
+ *
238
+ * ## Anchored, or merely absolute
239
+ *
240
+ * Without `anchorRef` the panel is `position: absolute` inside whatever relative box
241
+ * the caller put it in, and the caller places it with `className` (`w-64`,
242
+ * `right-0 top-full`). That is fine in a page that does not scroll around it, and
243
+ * wrong the moment an ancestor has `overflow` — the panel is then CLIPPED by that
244
+ * ancestor's box, with no error and no scrollbar, just a list with its side sliced
245
+ * off. Keksdose dev#548 is what that looks like in practice: the app's own content
246
+ * scroller starts 280px from the left, the amount field's currency picker opens
247
+ * right-aligned and 256px wide, and in the transaction row editor its left third —
248
+ * the search box's first letter, and every row's currency symbol — was cut away.
249
+ *
250
+ * With `anchorRef` the panel is PORTALLED to `<body>` and positioned `fixed` against
251
+ * that trigger's rect, so no ancestor can clip it: the same treatment {@link Popover}
252
+ * already gives the calculator, and the same reason. It re-aligns on scroll and
253
+ * resize, flips above the trigger when the room is there instead (a phone keyboard
254
+ * eats the bottom of the screen), and is clamped to the viewport's edges so a trigger
255
+ * near either side cannot push it off-screen.
256
+ *
257
+ * Pass `panelRef` from {@link useDropdown} along with it: once portalled the panel is
258
+ * no longer inside the wrapper, so the outside-click handler has to be told about it
259
+ * or the first click on an option closes the list instead of choosing from it.
260
+ */
261
+ export function DropdownPanel({
262
+ header,
263
+ empty,
264
+ className,
265
+ listProps,
266
+ anchorRef,
267
+ panelRef,
268
+ width = 256,
269
+ align = "right",
270
+ children,
271
+ style,
272
+ ...rest
273
+ }: DropdownPanelProps) {
274
+ const anchored = useAnchoredPanel(anchorRef ?? EMPTY_REF, Boolean(anchorRef));
275
+ const body = (
276
+ <>
277
+ {header}
278
+ {/* The anchored form caps its own height against the VISIBLE viewport and lets
279
+ this list have the rest; the absolute form keeps the fixed `max-h-64` it has
280
+ always had, applied by the wrapper below. */}
281
+ <ul {...listProps} className={cn("overflow-y-auto py-1", listProps?.className)}>
282
+ {children}
283
+ {/* `presentation`, so that a caller who made this list a `listbox` does not
284
+ end up with one child that is not an option. The em dash still reads — it
285
+ is the row's semantics that are dropped, not its text. */}
286
+ {empty && (
287
+ <li role="presentation" className="px-3 py-2 text-sm text-[var(--text-muted)]">
288
+ —
289
+ </li>
290
+ )}
291
+ </ul>
292
+ </>
293
+ );
294
+
295
+ if (!anchorRef) {
296
+ return (
297
+ <div
298
+ {...rest}
299
+ style={style}
300
+ ref={panelRef}
301
+ className={cn(
302
+ "absolute z-30 mt-1 rounded-md border border-[var(--border)] bg-[var(--bg-surface)] shadow-lg",
303
+ "[&>ul]:max-h-64",
304
+ className,
305
+ )}
306
+ >
307
+ {body}
308
+ </div>
309
+ );
310
+ }
311
+
312
+ const rect = anchored.rect;
313
+ if (!rect) return null;
314
+ // Clamped exactly as `Popover` clamps: the panel may leave the trigger's edge to
315
+ // stay on screen, because a list half off the viewport is the bug this exists for.
316
+ const wanted = align === "right" ? rect.right - width : rect.left;
317
+ const left = Math.min(Math.max(8, wanted), window.innerWidth - width - 8);
318
+ return createPortal(
319
+ <div
320
+ {...rest}
321
+ ref={panelRef}
322
+ // The caller's `style` is kept underneath, but the placement is measured rather
323
+ // than chosen (dev#548: an `overflow` ancestor clipped a third of this panel
324
+ // away), so those five values are the panel's own.
325
+ style={{ ...style, position: "fixed", top: anchored.top, left, width, maxHeight: anchored.maxHeight }}
326
+ className={cn(
327
+ "z-50 flex flex-col overflow-hidden rounded-md border border-[var(--border)] bg-[var(--bg-surface)] shadow-lg",
328
+ // The list, not the panel, is what scrolls: the search header has to stay put
329
+ // while the options move under it.
330
+ "[&>ul]:min-h-0 [&>ul]:flex-1",
331
+ className,
332
+ )}
333
+ >
334
+ {body}
335
+ </div>,
336
+ document.body,
337
+ );
338
+ }
339
+
340
+ /** A ref that is always null, for the un-anchored form — hooks may not be conditional. */
341
+ const EMPTY_REF: RefObject<HTMLElement | null> = { current: null };
@@ -0,0 +1,215 @@
1
+ import { useId } from "react";
2
+ import type { ComponentPropsWithoutRef, ReactNode } from "react";
3
+ import { X } from "lucide-react";
4
+ import { cn } from "../lib/cn";
5
+ import { FieldChevron, FieldLabel, FIELD_TRIGGER, FIELD_FLOATING_PAD, FIELD_INVALID } from "./ui";
6
+ import { ComboboxPanel, useComboboxCore, type ComboOption } from "./combobox-core";
7
+ import { DEFAULT_COMBOBOX_LABELS, DEFAULT_COMMON_LABELS, useKitLabels } from "../i18n/kit-labels";
8
+
9
+ export type { ComboOption } from "./combobox-core";
10
+
11
+ /** `onChange` is the kit's — "a selection was made", carrying values — rather
12
+ * than the div's form event, so the DOM's spelling of it is omitted. */
13
+ export interface EntityComboboxProps<V extends string | number>
14
+ extends Omit<ComponentPropsWithoutRef<"div">, "onChange"> {
15
+ /** Selected id, or null/undefined when nothing is selected. */
16
+ value: V | null | undefined;
17
+ /** Selecting an option emits its value; the clear button emits `null`. */
18
+ onChange: (value: V | null) => void;
19
+ /** Already-loaded options (client-side filtered). Also used to resolve the
20
+ * trigger label for the current `value`. */
21
+ options?: ComboOption<V>[];
22
+ /** Async option source, debounced and called on open + as the query changes.
23
+ * Stale responses are ignored. When set, `options` is used only for label
24
+ * resolution, not as the result list. */
25
+ loadOptions?: (query: string) => Promise<ComboOption<V>[]>;
26
+ /** External loading flag (OR-ed with the internal async state). */
27
+ loading?: boolean;
28
+ label?: ReactNode;
29
+ placeholder?: string;
30
+ searchPlaceholder?: string;
31
+ emptyLabel?: string;
32
+ clearable?: boolean;
33
+ clearLabel?: string;
34
+ /** The phone sheet's close button. Its own prop rather than a reuse of
35
+ * `clearLabel`: "clear the selection" and "close this screen" are different
36
+ * actions, and on a full-screen sheet the close button is the only way out —
37
+ * so it is the one control here that MUST be in the reader's language. */
38
+ closeLabel?: string;
39
+ disabled?: boolean;
40
+ /** When set, a "create" row appears for a non-empty query with no exact match. */
41
+ onCreate?: (query: string) => void;
42
+ createLabel?: (query: string) => string;
43
+ /** Required and unanswered — {@link FIELD_INVALID}. See {@link Input}'s `invalid`. */
44
+ invalid?: boolean;
45
+ }
46
+
47
+ /**
48
+ * An id-keyed, searchable entity picker: a field-styled trigger showing the
49
+ * selected item's label, and a portalled dropdown of `{label, sublabel, icon}`
50
+ * options — loaded up front via `options` or lazily via `loadOptions`. Built on
51
+ * the shared field/anchor/dismiss/search primitives (no cmdk/Radix). For picking
52
+ * several entities use {@link MultiEntityCombobox}.
53
+ */
54
+ export function EntityCombobox<V extends string | number>({
55
+ value,
56
+ onChange,
57
+ options,
58
+ loadOptions,
59
+ loading,
60
+ label,
61
+ placeholder,
62
+ searchPlaceholder,
63
+ emptyLabel,
64
+ clearable,
65
+ clearLabel,
66
+ closeLabel,
67
+ disabled,
68
+ onCreate,
69
+ createLabel,
70
+ className,
71
+ invalid,
72
+ "aria-label": ariaLabel,
73
+ ...rest
74
+ }: EntityComboboxProps<V>) {
75
+ const core = useComboboxCore<V>({ options, loadOptions, loading });
76
+ // The props are the per-instance overrides, the provider the app-wide ones; a
77
+ // prop left `undefined` falls through to the provider rather than masking it.
78
+ const labels = useKitLabels("combobox", DEFAULT_COMBOBOX_LABELS, {
79
+ search: searchPlaceholder,
80
+ noResults: emptyLabel,
81
+ clear: clearLabel,
82
+ create: createLabel,
83
+ });
84
+ const common = useKitLabels("common", DEFAULT_COMMON_LABELS);
85
+ const { open, results, resolve, setOpen } = core;
86
+ // One id per instance, generated here rather than in the core: `aria-controls` on
87
+ // the trigger has to name the list while the list is still closed, so the id
88
+ // belongs to whoever renders both ends of it.
89
+ const listboxId = useId();
90
+
91
+ const selectedOption = value == null ? null : resolve(value);
92
+ const q = core.query.trim();
93
+ const showCreate =
94
+ Boolean(onCreate) && q.length > 0 && !results.some((o) => o.label.toLowerCase() === q.toLowerCase());
95
+ const showClear = Boolean(clearable && value != null && !disabled);
96
+ /** What the closed control is showing — the second half of its accessible name. */
97
+ const triggerText = selectedOption?.label ?? placeholder ?? "";
98
+
99
+ const choose = (o: ComboOption<V>) => {
100
+ core.cacheRef.current.set(o.value, o);
101
+ onChange(o.value);
102
+ // Back to the trigger, not to <body>: the panel that held focus is about to
103
+ // unmount, and a keyboard user who just answered this field should be standing
104
+ // on it, ready to Tab to the next one.
105
+ core.closeToTrigger();
106
+ };
107
+
108
+ return (
109
+ // `rest` dresses the wrapper, which has no role; the accessible NAME goes on
110
+ // the trigger, which has one. Spread FIRST so the trigger's ARIA and the
111
+ // handlers that open the panel cannot be clobbered from outside.
112
+ <div {...rest} className={cn("relative", className)}>
113
+ {label !== undefined && <FieldLabel>{label}</FieldLabel>}
114
+ <button
115
+ ref={core.triggerRef}
116
+ type="button"
117
+ // A combobox, not a button. The distinction is not pedantry: this control
118
+ // carried `aria-invalid`, which `button` does not support, so a required
119
+ // field left empty painted a rose border and told a reader nothing at all —
120
+ // and ESLint flagged it as exactly that (`role-supports-aria-props`). The
121
+ // fix the audit asked for is the role that describes what this IS: a closed
122
+ // choice that expands into the list named below. `combobox` supports
123
+ // `aria-invalid`, so the border and the announcement finally agree.
124
+ role="combobox"
125
+ aria-expanded={open}
126
+ aria-controls={listboxId}
127
+ aria-haspopup="listbox"
128
+ // The label is a floating <span>, not a <label for>, so without this the
129
+ // trigger's accessible name is whatever value happens to be selected —
130
+ // "Checking" with nothing saying it is the account. The label AND the
131
+ // value, because `aria-label` replaces the content rather than adding to
132
+ // it, and a control that announces only its name has lost the answer.
133
+ // A caller's own name wins over the composition: two fields labelled
134
+ // "Account" on a transfer form are the from and the to, and only the
135
+ // caller knows which is which.
136
+ aria-label={
137
+ ariaLabel ??
138
+ (typeof label === "string" ? common.fieldValue(label, triggerText) : undefined)
139
+ }
140
+ disabled={disabled}
141
+ aria-invalid={invalid || undefined}
142
+ onClick={() => !disabled && setOpen((o) => !o)}
143
+ // Down/Up opens the list from the closed trigger, per the APG. Enter and
144
+ // Space already do it through the button's own click.
145
+ onKeyDown={(e) => {
146
+ if (disabled) return;
147
+ if (e.key === "ArrowDown" || e.key === "ArrowUp") {
148
+ e.preventDefault();
149
+ setOpen(true);
150
+ }
151
+ }}
152
+ className={cn(
153
+ FIELD_TRIGGER,
154
+ "pr-9",
155
+ label !== undefined && FIELD_FLOATING_PAD,
156
+ disabled && "cursor-not-allowed opacity-50",
157
+ invalid && FIELD_INVALID,
158
+ )}
159
+ >
160
+ <span className="flex min-w-0 items-center gap-2">
161
+ {selectedOption?.icon && <span className="shrink-0">{selectedOption.icon}</span>}
162
+ <span
163
+ className={cn(
164
+ "truncate",
165
+ // A chosen value is the field's VALUE, so it is set in the same ink an
166
+ // <input>'s value is — FIELD_BASE's own text colour, inherited rather
167
+ // than restated (Keksdose dev#477). It used to be one notch lighter
168
+ // than the typeahead fields beside it, which is visible when a picker
169
+ // and a text field share a form row. Nothing selected keeps the
170
+ // placeholder tone (`--text-placeholder`), which every field here
171
+ // agrees on.
172
+ !selectedOption && "text-[var(--text-placeholder)]",
173
+ )}
174
+ >
175
+ {selectedOption?.label ?? placeholder ?? ""}
176
+ </span>
177
+ </span>
178
+ {showClear ? (
179
+ <span
180
+ role="button"
181
+ tabIndex={-1}
182
+ aria-label={labels.clear}
183
+ onClick={(e) => {
184
+ e.stopPropagation();
185
+ onChange(null);
186
+ }}
187
+ className="absolute right-2 top-1/2 -translate-y-1/2 rounded p-0.5 text-[var(--text-placeholder)] hover:text-[var(--text-secondary)]"
188
+ >
189
+ <X className="size-4" />
190
+ </span>
191
+ ) : (
192
+ <FieldChevron />
193
+ )}
194
+ </button>
195
+ <ComboboxPanel
196
+ core={core}
197
+ listboxId={listboxId}
198
+ // On a phone the panel becomes a full-screen sheet, which needs the field's
199
+ // own label to say what it is asking for (live #200).
200
+ sheetTitle={label ?? placeholder}
201
+ searchPlaceholder={labels.search}
202
+ emptyLabel={labels.noResults}
203
+ closeLabel={closeLabel}
204
+ isSelected={(v) => v === value}
205
+ onChoose={choose}
206
+ showCreate={showCreate}
207
+ onCreate={() => {
208
+ onCreate?.(q);
209
+ core.closeToTrigger();
210
+ }}
211
+ createContent={labels.create(q)}
212
+ />
213
+ </div>
214
+ );
215
+ }
@@ -0,0 +1,86 @@
1
+ // Two series charts side by side that are MIRROR IMAGES of each other — the two sides
2
+ // of a symmetric system, read against each other — and the arithmetic that keeps their
3
+ // plots the same width. Lifted out of lenkbank, where four hand-assembled copies of
4
+ // these rules had already drifted apart.
5
+ //
6
+ // The rules:
7
+ // * The ticks stand on the OUTSIDE: the left chart's on its left, the right chart's on
8
+ // its right. The two plots meet in the middle with nothing between them, and neither
9
+ // column of numbers stands between a picture and the one it is compared with.
10
+ // * The quantity is named ONCE, on the left chart; the right title would be the same
11
+ // words twice.
12
+ // * The untitled right axis still RESERVES the title's strip. Reserve only what its
13
+ // ticks need and its plot comes out `AXIS_TITLE_STRIP` px wider than its neighbour's
14
+ // — inside one shared x window, the same abscissa then lands on different pixels.
15
+ // * A heading sits over the PLOT, not over the column, padded by the axis band on the
16
+ // side that column's axis stands on.
17
+ //
18
+ // Only the geometry is here. The grid the pair stands in — column widths, where the
19
+ // legend goes, the chart height — is a screen's layout, and stays with the screen.
20
+ import type { CSSProperties } from "react";
21
+ import { DEFAULT_Y_AXIS } from "./chart-zoom";
22
+ import { AXIS_TICK_WIDTH, axisBandWidth, type SeriesChartAxis } from "./series-chart";
23
+
24
+ /** Which chart of a facing pair. Physical, like the axes: charts do not mirror in RTL. */
25
+ export type FacingSide = "left" | "right";
26
+
27
+ /** The two sides, in the order the columns stand. */
28
+ export const FACING_SIDES: readonly FacingSide[] = ["left", "right"];
29
+
30
+ /** The whole band a facing y axis occupies: its ticks, and the strip the rotated title
31
+ * is drawn in — whether or not this chart is the one that spends it. */
32
+ export function facingBand(tickWidth: number = AXIS_TICK_WIDTH): number {
33
+ return axisBandWidth(tickWidth, true);
34
+ }
35
+
36
+ /**
37
+ * The y axis of one chart of a facing pair.
38
+ *
39
+ * The left one carries the row's quantity and the ticks' own width; the right one has
40
+ * no title, stands on the right and reserves the whole band, so the two plots come out
41
+ * the same width. Both may be pinned to one `domain` — whether they are is a statement
42
+ * about the measurement, so it is the caller's.
43
+ */
44
+ export function facingAxes({
45
+ side,
46
+ title,
47
+ format,
48
+ tickWidth = AXIS_TICK_WIDTH,
49
+ domain,
50
+ color,
51
+ }: {
52
+ side: FacingSide;
53
+ /** The row's quantity, with its unit. Drawn on the left chart only. */
54
+ title: string;
55
+ format?: (value: number) => string;
56
+ tickWidth?: number;
57
+ domain?: [number, number];
58
+ color?: string;
59
+ }): SeriesChartAxis[] {
60
+ if (side === "right") {
61
+ return [
62
+ {
63
+ id: DEFAULT_Y_AXIS,
64
+ orientation: "right",
65
+ width: facingBand(tickWidth),
66
+ title: "",
67
+ format,
68
+ domain,
69
+ color,
70
+ },
71
+ ];
72
+ }
73
+ return [{ id: DEFAULT_Y_AXIS, width: tickWidth, title, format, domain, color }];
74
+ }
75
+
76
+ /** What a column heading is padded by to sit over the PLOT rather than the column: the
77
+ * axis band, on the side that column's axis stands on. Physical padding on purpose —
78
+ * the chart under it does not flip in RTL, so neither may the heading's offset. */
79
+ export function facingHeadingPad(
80
+ side: FacingSide,
81
+ tickWidth: number = AXIS_TICK_WIDTH,
82
+ ): Pick<CSSProperties, "paddingLeft" | "paddingRight"> {
83
+ return side === "left"
84
+ ? { paddingLeft: facingBand(tickWidth) }
85
+ : { paddingRight: facingBand(tickWidth) };
86
+ }