@eifi1/ui-kit 0.11.0 → 0.13.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 (397) hide show
  1. package/README.md +59 -34
  2. package/dist/chart.d.ts +3 -1
  3. package/dist/chart.js +2 -0
  4. package/dist/chart.js.map +1 -1
  5. package/dist/components/account-settings-labels.d.ts +105 -0
  6. package/dist/components/account-settings-labels.js +81 -0
  7. package/dist/components/account-settings-labels.js.map +1 -0
  8. package/dist/components/account-settings.d.ts +36 -52
  9. package/dist/components/account-settings.js +44 -8
  10. package/dist/components/account-settings.js.map +1 -1
  11. package/dist/components/amount-input.d.ts +40 -4
  12. package/dist/components/amount-input.js +50 -12
  13. package/dist/components/amount-input.js.map +1 -1
  14. package/dist/components/authed-image.d.ts +68 -0
  15. package/dist/components/authed-image.js +117 -0
  16. package/dist/components/authed-image.js.map +1 -0
  17. package/dist/components/breadcrumbs.d.ts +2 -1
  18. package/dist/components/breadcrumbs.js +5 -2
  19. package/dist/components/breadcrumbs.js.map +1 -1
  20. package/dist/components/bulk-action-bar.d.ts +10 -2
  21. package/dist/components/bulk-action-bar.js.map +1 -1
  22. package/dist/components/button-group.d.ts +51 -2
  23. package/dist/components/button-group.js +5 -1
  24. package/dist/components/button-group.js.map +1 -1
  25. package/dist/components/calculator.d.ts +15 -4
  26. package/dist/components/calendar-heatmap.d.ts +41 -3
  27. package/dist/components/calendar-heatmap.js +48 -7
  28. package/dist/components/calendar-heatmap.js.map +1 -1
  29. package/dist/components/chart.js +14 -8
  30. package/dist/components/chart.js.map +1 -1
  31. package/dist/components/chip.d.ts +2 -1
  32. package/dist/components/chip.js +26 -18
  33. package/dist/components/chip.js.map +1 -1
  34. package/dist/components/choice-card.d.ts +35 -3
  35. package/dist/components/choice-card.js +83 -25
  36. package/dist/components/choice-card.js.map +1 -1
  37. package/dist/components/combobox-core.d.ts +3 -1
  38. package/dist/components/combobox-core.js +18 -5
  39. package/dist/components/combobox-core.js.map +1 -1
  40. package/dist/components/combobox.d.ts +2 -2
  41. package/dist/components/combobox.js +31 -9
  42. package/dist/components/combobox.js.map +1 -1
  43. package/dist/components/copy-button.d.ts +51 -70
  44. package/dist/components/copy-button.js +1 -1
  45. package/dist/components/copy-button.js.map +1 -1
  46. package/dist/components/data-table-cells.d.ts +63 -0
  47. package/dist/components/data-table-cells.js +64 -0
  48. package/dist/components/data-table-cells.js.map +1 -0
  49. package/dist/components/data-table-filter-popover.d.ts +1 -1
  50. package/dist/components/data-table-filter-popover.js +8 -1
  51. package/dist/components/data-table-filter-popover.js.map +1 -1
  52. package/dist/components/data-table-filters.d.ts +1 -1
  53. package/dist/components/data-table-filters.js +31 -1
  54. package/dist/components/data-table-filters.js.map +1 -1
  55. package/dist/components/data-table-labels.d.ts +13 -0
  56. package/dist/components/data-table-labels.js +8 -1
  57. package/dist/components/data-table-labels.js.map +1 -1
  58. package/dist/components/data-table.d.ts +1 -1
  59. package/dist/components/data-table.js +125 -27
  60. package/dist/components/data-table.js.map +1 -1
  61. package/dist/components/date-picker.d.ts +3 -1
  62. package/dist/components/date-picker.js +15 -2
  63. package/dist/components/date-picker.js.map +1 -1
  64. package/dist/components/description-list.d.ts +23 -3
  65. package/dist/components/description-list.js +23 -3
  66. package/dist/components/description-list.js.map +1 -1
  67. package/dist/components/dialog-frame.d.ts +1 -0
  68. package/dist/components/entity-combobox.d.ts +1 -1
  69. package/dist/components/entity-combobox.js +40 -20
  70. package/dist/components/entity-combobox.js.map +1 -1
  71. package/dist/components/error-boundary.d.ts +281 -0
  72. package/dist/components/error-boundary.js +302 -0
  73. package/dist/components/error-boundary.js.map +1 -0
  74. package/dist/components/field-sync.js +90 -83
  75. package/dist/components/field-sync.js.map +1 -1
  76. package/dist/components/field.d.ts +30 -4
  77. package/dist/components/field.js +40 -17
  78. package/dist/components/field.js.map +1 -1
  79. package/dist/components/file-button.d.ts +50 -208
  80. package/dist/components/file-dropzone.d.ts +49 -2
  81. package/dist/components/floating-panel.d.ts +13 -4
  82. package/dist/components/floating-panel.js +7 -3
  83. package/dist/components/floating-panel.js.map +1 -1
  84. package/dist/components/form-actions.d.ts +53 -0
  85. package/dist/components/form-actions.js +98 -0
  86. package/dist/components/form-actions.js.map +1 -0
  87. package/dist/components/full-bleed-dialog.js +4 -0
  88. package/dist/components/full-bleed-dialog.js.map +1 -1
  89. package/dist/components/hover-menu.js +64 -56
  90. package/dist/components/hover-menu.js.map +1 -1
  91. package/dist/components/image-grid.d.ts +67 -0
  92. package/dist/components/image-grid.js +112 -0
  93. package/dist/components/image-grid.js.map +1 -0
  94. package/dist/components/lightbox.d.ts +104 -0
  95. package/dist/components/lightbox.js +229 -0
  96. package/dist/components/lightbox.js.map +1 -0
  97. package/dist/components/line-items.d.ts +114 -0
  98. package/dist/components/line-items.js +238 -0
  99. package/dist/components/line-items.js.map +1 -0
  100. package/dist/components/list.d.ts +37 -4
  101. package/dist/components/list.js +35 -14
  102. package/dist/components/list.js.map +1 -1
  103. package/dist/components/loading-state.d.ts +24 -0
  104. package/dist/components/loading-state.js +32 -0
  105. package/dist/components/loading-state.js.map +1 -0
  106. package/dist/components/menu-item.d.ts +2 -1
  107. package/dist/components/menu-item.js +5 -1
  108. package/dist/components/menu-item.js.map +1 -1
  109. package/dist/components/mini-calendar.d.ts +13 -1
  110. package/dist/components/mini-calendar.js +46 -2
  111. package/dist/components/mini-calendar.js.map +1 -1
  112. package/dist/components/modal.d.ts +20 -1
  113. package/dist/components/modal.js +26 -2
  114. package/dist/components/modal.js.map +1 -1
  115. package/dist/components/month-picker.d.ts +21 -1
  116. package/dist/components/month-picker.js +139 -26
  117. package/dist/components/month-picker.js.map +1 -1
  118. package/dist/components/multi-entity-combobox.d.ts +1 -1
  119. package/dist/components/multi-entity-combobox.js +42 -20
  120. package/dist/components/multi-entity-combobox.js.map +1 -1
  121. package/dist/components/nav-pills.d.ts +2 -1
  122. package/dist/components/nav-pills.js +5 -1
  123. package/dist/components/nav-pills.js.map +1 -1
  124. package/dist/components/number-field.d.ts +24 -5
  125. package/dist/components/number-field.js +5 -7
  126. package/dist/components/number-field.js.map +1 -1
  127. package/dist/components/number-input.d.ts +25 -5
  128. package/dist/components/number-input.js +7 -1
  129. package/dist/components/number-input.js.map +1 -1
  130. package/dist/components/numpad-sheet.d.ts +20 -5
  131. package/dist/components/numpad-sheet.js +3 -2
  132. package/dist/components/numpad-sheet.js.map +1 -1
  133. package/dist/components/page-header.d.ts +35 -6
  134. package/dist/components/page-header.js +7 -1
  135. package/dist/components/page-header.js.map +1 -1
  136. package/dist/components/passkeys-setting.d.ts +67 -0
  137. package/dist/components/passkeys-setting.js +214 -0
  138. package/dist/components/passkeys-setting.js.map +1 -0
  139. package/dist/components/picker-sheet.js +5 -1
  140. package/dist/components/picker-sheet.js.map +1 -1
  141. package/dist/components/pie-chart-labels.d.ts +20 -0
  142. package/dist/components/pie-chart-labels.js +12 -0
  143. package/dist/components/pie-chart-labels.js.map +1 -0
  144. package/dist/components/pie-chart.d.ts +101 -0
  145. package/dist/components/pie-chart.js +283 -0
  146. package/dist/components/pie-chart.js.map +1 -0
  147. package/dist/components/popover.js +3 -0
  148. package/dist/components/popover.js.map +1 -1
  149. package/dist/components/progress-bar.d.ts +44 -3
  150. package/dist/components/progress-bar.js +58 -22
  151. package/dist/components/progress-bar.js.map +1 -1
  152. package/dist/components/qr-code.d.ts +34 -0
  153. package/dist/components/qr-code.js +57 -0
  154. package/dist/components/qr-code.js.map +1 -0
  155. package/dist/components/search-field.d.ts +15 -3
  156. package/dist/components/search-field.js +5 -1
  157. package/dist/components/search-field.js.map +1 -1
  158. package/dist/components/settings-fields.d.ts +49 -1
  159. package/dist/components/signed-amount.d.ts +122 -0
  160. package/dist/components/signed-amount.js +152 -0
  161. package/dist/components/signed-amount.js.map +1 -0
  162. package/dist/components/skeleton.d.ts +10 -3
  163. package/dist/components/skeleton.js +12 -2
  164. package/dist/components/skeleton.js.map +1 -1
  165. package/dist/components/stat-tile.d.ts +2 -1
  166. package/dist/components/stat-tile.js +6 -3
  167. package/dist/components/stat-tile.js.map +1 -1
  168. package/dist/components/swipeable-row.js +4 -3
  169. package/dist/components/swipeable-row.js.map +1 -1
  170. package/dist/components/table.d.ts +39 -5
  171. package/dist/components/table.js +45 -11
  172. package/dist/components/table.js.map +1 -1
  173. package/dist/components/text-link.d.ts +238 -0
  174. package/dist/components/text-link.js +144 -0
  175. package/dist/components/text-link.js.map +1 -0
  176. package/dist/components/text.d.ts +26 -2
  177. package/dist/components/text.js +16 -2
  178. package/dist/components/text.js.map +1 -1
  179. package/dist/components/time-input.d.ts +49 -1
  180. package/dist/components/toggle-group.d.ts +35 -0
  181. package/dist/components/toggle-group.js +43 -14
  182. package/dist/components/toggle-group.js.map +1 -1
  183. package/dist/components/toggle-legend.d.ts +53 -3
  184. package/dist/components/toggle-legend.js +54 -1
  185. package/dist/components/toggle-legend.js.map +1 -1
  186. package/dist/components/tooltip.d.ts +51 -1
  187. package/dist/components/tooltip.js +59 -35
  188. package/dist/components/tooltip.js.map +1 -1
  189. package/dist/components/ui.d.ts +51 -779
  190. package/dist/components/ui.js +364 -34
  191. package/dist/components/ui.js.map +1 -1
  192. package/dist/components/use-table-state.d.ts +3 -52
  193. package/dist/components/use-table-state.js +128 -30
  194. package/dist/components/use-table-state.js.map +1 -1
  195. package/dist/{data-table-filters-Dh9uF_S-.d.ts → data-table-Drun8Fk9.d.ts} +305 -61
  196. package/dist/data-table.d.ts +2 -1
  197. package/dist/data-table.js +5 -1
  198. package/dist/data-table.js.map +1 -1
  199. package/dist/feedback/feedback-attachment.js +4 -6
  200. package/dist/feedback/feedback-attachment.js.map +1 -1
  201. package/dist/feedback/feedback-dialog.d.ts +26 -3
  202. package/dist/feedback/feedback-dialog.js +21 -5
  203. package/dist/feedback/feedback-dialog.js.map +1 -1
  204. package/dist/feedback/feedback-inbox.js +86 -75
  205. package/dist/feedback/feedback-inbox.js.map +1 -1
  206. package/dist/feedback/feedback-thread.d.ts +173 -0
  207. package/dist/feedback/feedback-thread.js +264 -0
  208. package/dist/feedback/feedback-thread.js.map +1 -0
  209. package/dist/feedback.d.ts +2 -1
  210. package/dist/feedback.js +1 -0
  211. package/dist/feedback.js.map +1 -1
  212. package/dist/hooks/use-authed-src.d.ts +71 -0
  213. package/dist/hooks/use-authed-src.js +63 -0
  214. package/dist/hooks/use-authed-src.js.map +1 -0
  215. package/dist/hooks/use-file-drop.d.ts +49 -2
  216. package/dist/hooks/use-hotkey.d.ts +59 -0
  217. package/dist/hooks/use-hotkey.js +105 -0
  218. package/dist/hooks/use-hotkey.js.map +1 -0
  219. package/dist/hooks/use-search-param-state.d.ts +83 -0
  220. package/dist/hooks/use-search-param-state.js +94 -0
  221. package/dist/hooks/use-search-param-state.js.map +1 -0
  222. package/dist/i18n/defaults.d.ts +15 -4
  223. package/dist/i18n/defaults.js +31 -1
  224. package/dist/i18n/defaults.js.map +1 -1
  225. package/dist/i18n/kit-labels.d.ts +46 -312
  226. package/dist/i18n/kit-labels.js +20 -5
  227. package/dist/i18n/kit-labels.js.map +1 -1
  228. package/dist/i18n/locales/de-CH-informal.d.ts +15 -4
  229. package/dist/i18n/locales/de-CH.d.ts +15 -4
  230. package/dist/i18n/locales/de-informal.d.ts +15 -4
  231. package/dist/i18n/locales/de.d.ts +15 -4
  232. package/dist/i18n/locales/de.js +164 -3
  233. package/dist/i18n/locales/de.js.map +1 -1
  234. package/dist/i18n/locales/es.d.ts +15 -4
  235. package/dist/i18n/locales/es.js +161 -3
  236. package/dist/i18n/locales/es.js.map +1 -1
  237. package/dist/i18n/locales/fr.d.ts +15 -4
  238. package/dist/i18n/locales/fr.js +161 -3
  239. package/dist/i18n/locales/fr.js.map +1 -1
  240. package/dist/i18n/locales/hu.d.ts +15 -4
  241. package/dist/i18n/locales/hu.js +161 -3
  242. package/dist/i18n/locales/hu.js.map +1 -1
  243. package/dist/i18n/locales/it.d.ts +15 -4
  244. package/dist/i18n/locales/it.js +161 -3
  245. package/dist/i18n/locales/it.js.map +1 -1
  246. package/dist/i18n/locales/zh.d.ts +15 -4
  247. package/dist/i18n/locales/zh.js +161 -3
  248. package/dist/i18n/locales/zh.js.map +1 -1
  249. package/dist/index.d.ts +39 -19
  250. package/dist/index.js +40 -1
  251. package/dist/index.js.map +1 -1
  252. package/dist/kit-labels-Mz8zZHIF.d.ts +1744 -0
  253. package/dist/lib/format.d.ts +162 -0
  254. package/dist/lib/format.js +151 -0
  255. package/dist/lib/format.js.map +1 -0
  256. package/dist/lib/qr-encode.d.ts +44 -0
  257. package/dist/lib/qr-encode.js +338 -0
  258. package/dist/lib/qr-encode.js.map +1 -0
  259. package/dist/rhf/fields.d.ts +283 -0
  260. package/dist/rhf/fields.js +631 -0
  261. package/dist/rhf/fields.js.map +1 -0
  262. package/dist/rhf/form.d.ts +49 -1
  263. package/dist/rhf/line-items.d.ts +31 -0
  264. package/dist/rhf/line-items.js +59 -0
  265. package/dist/rhf/line-items.js.map +1 -0
  266. package/dist/rhf.d.ts +61 -1
  267. package/dist/rhf.js +2 -0
  268. package/dist/rhf.js.map +1 -1
  269. package/dist/search/command-palette.js +20 -14
  270. package/dist/search/command-palette.js.map +1 -1
  271. package/dist/shell/app-shell.d.ts +99 -2
  272. package/dist/shell/app-shell.js +120 -57
  273. package/dist/shell/app-shell.js.map +1 -1
  274. package/dist/shell/auth-layout.d.ts +74 -0
  275. package/dist/shell/auth-layout.js +97 -0
  276. package/dist/shell/auth-layout.js.map +1 -0
  277. package/dist/shell/top-bar-brand.d.ts +81 -0
  278. package/dist/shell/top-bar-brand.js +47 -0
  279. package/dist/shell/top-bar-brand.js.map +1 -0
  280. package/dist/shell/topbar-action-menu.d.ts +21 -4
  281. package/dist/shell/topbar-action-menu.js +18 -2
  282. package/dist/shell/topbar-action-menu.js.map +1 -1
  283. package/dist/shell.d.ts +56 -1
  284. package/dist/shell.js +2 -0
  285. package/dist/shell.js.map +1 -1
  286. package/dist/tour/tour.js +10 -4
  287. package/dist/tour/tour.js.map +1 -1
  288. package/dist/wizard/stepper-nav.d.ts +48 -1
  289. package/dist/wizard/use-wizard.js +4 -2
  290. package/dist/wizard/use-wizard.js.map +1 -1
  291. package/dist/wizard/wizard-context.d.ts +24 -1
  292. package/dist/wizard/wizard-context.js +19 -2
  293. package/dist/wizard/wizard-context.js.map +1 -1
  294. package/dist/wizard/wizard-step.d.ts +30 -5
  295. package/dist/wizard/wizard-step.js +34 -3
  296. package/dist/wizard/wizard-step.js.map +1 -1
  297. package/dist/wizard.d.ts +50 -3
  298. package/package.json +6 -6
  299. package/src/chart.ts +4 -0
  300. package/src/components/account-settings-labels.ts +190 -0
  301. package/src/components/account-settings.tsx +110 -63
  302. package/src/components/amount-input.tsx +109 -10
  303. package/src/components/authed-image.tsx +190 -0
  304. package/src/components/breadcrumbs.tsx +8 -2
  305. package/src/components/bulk-action-bar.tsx +16 -3
  306. package/src/components/button-group.tsx +7 -2
  307. package/src/components/calendar-heatmap.tsx +105 -10
  308. package/src/components/chart.tsx +19 -8
  309. package/src/components/chip.tsx +14 -4
  310. package/src/components/choice-card.tsx +136 -25
  311. package/src/components/combobox-core.tsx +33 -9
  312. package/src/components/combobox.tsx +33 -9
  313. package/src/components/copy-button.tsx +3 -2
  314. package/src/components/data-table-cells.tsx +119 -0
  315. package/src/components/data-table-filter-popover.tsx +13 -5
  316. package/src/components/data-table-filters.ts +77 -0
  317. package/src/components/data-table-labels.ts +23 -0
  318. package/src/components/data-table.tsx +230 -13
  319. package/src/components/date-picker.tsx +19 -3
  320. package/src/components/description-list.tsx +52 -3
  321. package/src/components/entity-combobox.tsx +25 -7
  322. package/src/components/error-boundary.tsx +640 -0
  323. package/src/components/field-sync.tsx +48 -40
  324. package/src/components/field.tsx +56 -5
  325. package/src/components/floating-panel.tsx +20 -7
  326. package/src/components/form-actions.tsx +191 -0
  327. package/src/components/full-bleed-dialog.tsx +4 -0
  328. package/src/components/hover-menu.tsx +26 -17
  329. package/src/components/image-grid.tsx +181 -0
  330. package/src/components/lightbox.tsx +374 -0
  331. package/src/components/line-items.tsx +385 -0
  332. package/src/components/list.tsx +82 -19
  333. package/src/components/loading-state.tsx +47 -0
  334. package/src/components/menu-item.tsx +7 -2
  335. package/src/components/mini-calendar.tsx +72 -3
  336. package/src/components/modal.tsx +65 -3
  337. package/src/components/month-picker.tsx +181 -26
  338. package/src/components/multi-entity-combobox.tsx +27 -7
  339. package/src/components/nav-pills.tsx +8 -1
  340. package/src/components/number-field.tsx +15 -10
  341. package/src/components/number-input.tsx +17 -1
  342. package/src/components/numpad-sheet.tsx +6 -1
  343. package/src/components/page-header.tsx +42 -5
  344. package/src/components/passkeys-setting.tsx +331 -0
  345. package/src/components/picker-sheet.tsx +10 -1
  346. package/src/components/pie-chart-labels.ts +32 -0
  347. package/src/components/pie-chart.tsx +479 -0
  348. package/src/components/popover.tsx +3 -0
  349. package/src/components/progress-bar.tsx +129 -19
  350. package/src/components/qr-code.tsx +83 -0
  351. package/src/components/search-field.tsx +20 -4
  352. package/src/components/signed-amount.tsx +295 -0
  353. package/src/components/skeleton.tsx +21 -3
  354. package/src/components/stat-tile.tsx +11 -3
  355. package/src/components/swipeable-row.tsx +7 -7
  356. package/src/components/table.tsx +102 -13
  357. package/src/components/text-link.tsx +356 -0
  358. package/src/components/text.tsx +46 -2
  359. package/src/components/toggle-group.tsx +93 -20
  360. package/src/components/toggle-legend.tsx +108 -2
  361. package/src/components/tooltip.tsx +79 -8
  362. package/src/components/ui.tsx +707 -49
  363. package/src/components/use-table-state.ts +265 -33
  364. package/src/data-table.ts +10 -0
  365. package/src/feedback/feedback-attachment.tsx +10 -7
  366. package/src/feedback/feedback-dialog.tsx +49 -7
  367. package/src/feedback/feedback-inbox.tsx +7 -0
  368. package/src/feedback/feedback-thread.tsx +510 -0
  369. package/src/feedback.ts +1 -0
  370. package/src/hooks/use-authed-src.ts +161 -0
  371. package/src/hooks/use-hotkey.ts +172 -0
  372. package/src/hooks/use-search-param-state.ts +187 -0
  373. package/src/i18n/defaults.ts +30 -0
  374. package/src/i18n/kit-labels.tsx +118 -8
  375. package/src/i18n/locales/de.ts +161 -0
  376. package/src/i18n/locales/es.ts +158 -0
  377. package/src/i18n/locales/fr.ts +161 -0
  378. package/src/i18n/locales/hu.ts +159 -0
  379. package/src/i18n/locales/it.ts +159 -0
  380. package/src/i18n/locales/zh.ts +158 -0
  381. package/src/index.ts +59 -0
  382. package/src/lib/format.ts +348 -0
  383. package/src/lib/qr-encode.ts +420 -0
  384. package/src/rhf/fields.tsx +1135 -0
  385. package/src/rhf/line-items.tsx +130 -0
  386. package/src/rhf.ts +6 -0
  387. package/src/search/command-palette.tsx +29 -19
  388. package/src/shell/app-shell.tsx +153 -3
  389. package/src/shell/auth-layout.tsx +190 -0
  390. package/src/shell/top-bar-brand.tsx +76 -0
  391. package/src/shell/topbar-action-menu.tsx +32 -4
  392. package/src/shell.ts +2 -0
  393. package/src/tour/tour.tsx +16 -5
  394. package/src/wizard/use-wizard.ts +8 -4
  395. package/src/wizard/wizard-context.tsx +41 -1
  396. package/src/wizard/wizard-step.tsx +75 -6
  397. package/tokens.css +12 -0
@@ -61,6 +61,19 @@ interface ToggleGroupBaseProps<T extends string> extends Omit<ComponentPropsWith
61
61
  * group's own box is dropped: two nested borders read as a control in a control.
62
62
  */
63
63
  label?: ReactNode;
64
+ /**
65
+ * Where `label` goes. `"field"` (default): the field chrome described under `label`.
66
+ * `"above"`: the kit's {@link Label} over the bare group — the shape of a {@link Field}
67
+ * — with `hint` beside the label and `error` under the group, for a form that sets
68
+ * its labels above its fields (kastlan's international-rent-calculator.tsx, whose DE
69
+ * cap pair sits in a `Field` column between two labelled-above inputs, where the
70
+ * chrome's inner label would be the only one of its kind).
71
+ *
72
+ * Inside a `Field`, pass no `label` at all and spread the render-prop instead —
73
+ * `{(ids, { labelId }) => <ToggleGroup {...ids} aria-labelledby={labelId} … />}` —
74
+ * so the Field's label names the group and its hint and error describe it.
75
+ */
76
+ labelPlacement?: "field" | "above";
64
77
  /** A {@link FieldHint} on the label line, as on a labelled {@link Select}. Only with
65
78
  * `label`. */
66
79
  hint?: ReactNode;
@@ -83,6 +96,25 @@ type ToggleGroupCaption<V> = ReactNode | ((value: V) => ReactNode);
83
96
  /** The group as it has always been: one option is always the answer. */
84
97
  interface ToggleGroupRequiredProps<T extends string> extends ToggleGroupBaseProps<T> {
85
98
  allowEmpty?: false;
99
+ /**
100
+ * What the options ARE to a screen reader, separately from whether the group can be
101
+ * emptied (kastlan feedback #47).
102
+ *
103
+ * - `"radio"` (default) — a `radiogroup` of radios: one Tab stop, arrow keys MOVE the
104
+ * choice. Right for a choice between answers ("Monthly / Yearly").
105
+ * - `"pressed"` — a `group` of toggle buttons (`aria-pressed`), each its own Tab stop,
106
+ * Space/Enter to press; still one option always pressed. Right for a row that reads
107
+ * as a set of switches — a view mode, a toolbar-like filter — where arrows moving the
108
+ * selection on focus would be a surprise.
109
+ *
110
+ * Before this the only way to `aria-pressed` was `allowEmpty`, which also let a second
111
+ * press clear the choice — so kastlan took the clearable shape and threw the `null`
112
+ * away in `onChange` (`(v) => v && setMode(v)`), a group announcing that a press would
113
+ * unpress what it would not. Here a press on the pressed option re-sends its value, as
114
+ * the radio shape does, and nothing is ever unpressed. A clearable group
115
+ * (`allowEmpty`) is always `"pressed"`: a radio cannot be unchecked by activating it.
116
+ */
117
+ semantics?: "radio" | "pressed";
86
118
  value: T;
87
119
  onChange: (value: T) => void;
88
120
  /** See {@link ToggleGroupCaption}. */
@@ -100,6 +132,9 @@ interface ToggleGroupRequiredProps<T extends string> extends ToggleGroupBaseProp
100
132
  */
101
133
  interface ToggleGroupClearableProps<T extends string> extends ToggleGroupBaseProps<T> {
102
134
  allowEmpty: true;
135
+ /** Always toggle buttons — see {@link ToggleGroupRequiredProps.semantics}. Accepted so
136
+ * a wrapper can forward one `semantics` to either shape. */
137
+ semantics?: "pressed";
103
138
  value: T | null;
104
139
  onChange: (value: T | null) => void;
105
140
  /** See {@link ToggleGroupCaption}. `null` while nothing is chosen. */
@@ -3,7 +3,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
3
3
  import { useId } from "react";
4
4
  import { cn } from "../lib/cn.js";
5
5
  import { horizontalStep } from "../lib/direction.js";
6
- import { FIELD_INVALID, FloatingField } from "./ui.js";
6
+ import { FIELD_INVALID, FloatingField, Label } from "./ui.js";
7
7
  function ToggleGroup(props) {
8
8
  const {
9
9
  value,
@@ -14,6 +14,7 @@ function ToggleGroup(props) {
14
14
  disabled = false,
15
15
  size = "md",
16
16
  label,
17
+ labelPlacement = "field",
17
18
  hint,
18
19
  error,
19
20
  "aria-label": ariaLabelAttr,
@@ -21,9 +22,12 @@ function ToggleGroup(props) {
21
22
  } = props;
22
23
  const labelId = useId();
23
24
  const errorId = useId();
24
- const field = label !== void 0 && label !== null && label !== false && label !== "";
25
- const hasError = field && error !== void 0 && error !== null && error !== false && error !== "";
26
- const { allowEmpty: _allowEmpty, onChange: _onChange, caption, ...rest } = restWithMode;
25
+ const labelled = label !== void 0 && label !== null && label !== false && label !== "";
26
+ const field = labelled && labelPlacement === "field";
27
+ const above = labelled && labelPlacement === "above";
28
+ const hasError = labelled && error !== void 0 && error !== null && error !== false && error !== "";
29
+ const { allowEmpty: _allowEmpty, onChange: _onChange, caption, semantics: _semantics, ...rest } = restWithMode;
30
+ const outsideInvalid = rest["aria-invalid"] === true || rest["aria-invalid"] === "true";
27
31
  const captionId = useId();
28
32
  const captionIsLive = typeof caption === "function";
29
33
  const captionNode = captionIsLive ? caption(value) : caption;
@@ -32,7 +36,7 @@ function ToggleGroup(props) {
32
36
  if (props.allowEmpty) props.onChange(next === value ? null : next);
33
37
  else props.onChange(next);
34
38
  };
35
- const clearable = props.allowEmpty === true;
39
+ const pressed = props.allowEmpty === true || props.semantics === "pressed";
36
40
  const tabStop = options.some((o) => o.value === value) ? value : options[0]?.value;
37
41
  const onRadioKey = (e, index) => {
38
42
  const last = options.length - 1;
@@ -54,9 +58,9 @@ function ToggleGroup(props) {
54
58
  "div",
55
59
  {
56
60
  ...rest,
57
- role: clearable ? "group" : "radiogroup",
61
+ role: pressed ? "group" : "radiogroup",
58
62
  "aria-label": ariaLabelAttr ?? ariaLabel,
59
- "aria-labelledby": field && ariaLabelAttr === void 0 && ariaLabel === void 0 ? labelId : rest["aria-labelledby"],
63
+ "aria-labelledby": labelled && ariaLabelAttr === void 0 && ariaLabel === void 0 ? labelId : rest["aria-labelledby"],
60
64
  "aria-invalid": hasError || rest["aria-invalid"] || void 0,
61
65
  "aria-describedby": [rest["aria-describedby"], hasCaption && captionId, hasError && errorId].filter(Boolean).join(" ") || void 0,
62
66
  "aria-disabled": disabled || void 0,
@@ -78,10 +82,12 @@ function ToggleGroup(props) {
78
82
  // package does; `cursor-not-allowed` is on the buttons, which is what a
79
83
  // pointer is actually over.
80
84
  disabled && "opacity-60",
85
+ // The bare group (no chrome to paint) wears the invalid border itself.
86
+ !field && (outsideInvalid || above && hasError) && FIELD_INVALID,
81
87
  // Inside the field's chrome the group is only a row of segments: no border, no
82
88
  // surface, no padding of its own, and the field (not the group) is what dims.
83
89
  field && "border-0 bg-transparent p-0 shadow-none opacity-100",
84
- !field && className
90
+ !labelled && className
85
91
  ),
86
92
  children: options.map((opt, index) => {
87
93
  const active = opt.value === value;
@@ -89,12 +95,12 @@ function ToggleGroup(props) {
89
95
  "button",
90
96
  {
91
97
  type: "button",
92
- role: clearable ? void 0 : "radio",
93
- "aria-checked": clearable ? void 0 : active,
94
- "aria-pressed": clearable ? active : void 0,
98
+ role: pressed ? void 0 : "radio",
99
+ "aria-checked": pressed ? void 0 : active,
100
+ "aria-pressed": pressed ? active : void 0,
95
101
  disabled,
96
- tabIndex: clearable ? void 0 : opt.value === tabStop ? 0 : -1,
97
- onKeyDown: clearable ? void 0 : (e) => onRadioKey(e, index),
102
+ tabIndex: pressed ? void 0 : opt.value === tabStop ? 0 : -1,
103
+ onKeyDown: pressed ? void 0 : (e) => onRadioKey(e, index),
98
104
  onClick: () => choose(opt.value),
99
105
  className: cn(
100
106
  // `truncate` (which carries whitespace-nowrap) rather than letting a
@@ -148,6 +154,29 @@ function ToggleGroup(props) {
148
154
  children: hasCaption ? captionNode : null
149
155
  }
150
156
  ) : null;
157
+ const errorEl = hasError ? /* @__PURE__ */ jsx("p", { id: errorId, className: "mt-1 text-[11px] leading-tight text-[var(--danger)]", children: error }) : null;
158
+ if (above) {
159
+ return /* @__PURE__ */ jsxs("div", { className: cn("relative grid min-w-0 gap-1.5", className), children: [
160
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
161
+ /* @__PURE__ */ jsx(
162
+ Label,
163
+ {
164
+ id: labelId,
165
+ disabled,
166
+ "data-error": hasError || void 0,
167
+ className: "data-[error=true]:text-[var(--danger)]",
168
+ children: label
169
+ }
170
+ ),
171
+ hint
172
+ ] }),
173
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
174
+ group,
175
+ captionEl,
176
+ errorEl
177
+ ] })
178
+ ] });
179
+ }
151
180
  if (!field) {
152
181
  if (!captionEl) return group;
153
182
  return /* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
@@ -180,7 +209,7 @@ function ToggleGroup(props) {
180
209
  }
181
210
  ),
182
211
  captionEl,
183
- hasError && /* @__PURE__ */ jsx("p", { id: errorId, className: "mt-1 text-[11px] leading-tight text-[var(--danger)]", children: error })
212
+ errorEl
184
213
  ] })
185
214
  );
186
215
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/toggle-group.tsx"],"sourcesContent":["import { useId } from \"react\";\nimport type { ComponentPropsWithoutRef, KeyboardEvent, ReactElement, ReactNode } from \"react\";\nimport { cn } from \"../lib/cn\";\nimport { horizontalStep } from \"../lib/direction\";\nimport { FIELD_INVALID, FloatingField } from \"./ui\";\n\nexport interface ToggleOption<T extends string> {\n value: T;\n label: string;\n className?: string;\n}\n\n/**\n * `onChange` is the group's own — the chosen VALUE, not a DOM event — so the div's\n * `onChange` is omitted rather than shadowed: leaving both in scope would give the\n * prop two incompatible meanings depending on which overload TypeScript picked.\n *\n * `children` is omitted too: this renders its `options` and nothing else, so a `children` the type\n * accepted and the component ignored would be a prop that silently does nothing —\n * worse than one that does not compile.\n */\nexport interface ToggleGroupBaseProps<T extends string>\n extends Omit<ComponentPropsWithoutRef<\"div\">, \"onChange\" | \"children\"> {\n options: ToggleOption<T>[];\n className?: string;\n /** Applied to every option button (e.g. to tune height/rounding to match\n * adjacent fields). Per-option `className` still wins over this. */\n optionClassName?: string;\n /**\n * @deprecated Pass `aria-label` instead — the DOM spelling, which every other\n * control in this kit now answers to. Kept working because three applications ship\n * this one today; it names the group only when `aria-label` is absent.\n */\n ariaLabel?: string;\n /**\n * Show, refuse the change (Keksdose live #288: a payment dated in the future has no\n * state to set).\n *\n * Whatever `value` says stays pressed and keeps its own fill rather than going grey\n * with the rest — a reader who cannot see WHICH option is chosen has been told less\n * than before it was disabled. A caller with nothing to show passes no value, and\n * the group renders dimmed with nothing pressed, which is the shape Keksdose's\n * status picker uses for a row whose status does not exist yet.\n *\n * On the whole GROUP, not per option: a segmented control where some segments are\n * live and others are not is a menu with holes in it, and no caller here wants one.\n */\n disabled?: boolean;\n /**\n * `sm`: 12px options with `px-2 py-1` — the compact group keksdose's rule editor\n * (rule-editor:204) writes as `optionClassName=\"px-2 py-1 text-xs\"` beside a small\n * caption. `md` (default) is the size every other group has.\n */\n size?: \"sm\" | \"md\";\n /**\n * Stand in a form row as a FIELD: with a label the group wears the field's chrome —\n * border, surface, the top strip with a small static label in it, a labelled\n * {@link Select}'s height — so beside an Input or a Select it reads as one of them\n * rather than as a control with a caption over it. lenkbank builds exactly this by\n * hand as `ToggleField` (features/gear/common.tsx:97, feedback #69), and its notes\n * are why the chrome STRETCHES to its row as well as matching the select's padding:\n * a native select's height is the browser's, so a toggle a few pixels short of it\n * is levelled up by the row rather than by arithmetic.\n *\n * The label names the group (`aria-labelledby`), so `aria-label` is not needed. With\n * a label, `className` styles the field's wrapper — as on {@link Select} — and the\n * group's own box is dropped: two nested borders read as a control in a control.\n */\n label?: ReactNode;\n /** A {@link FieldHint} on the label line, as on a labelled {@link Select}. Only with\n * `label`. */\n hint?: ReactNode;\n /** The message under the field when it is wrong: paints the field's border with\n * `--danger`, marks the group `aria-invalid` and describes it with the message, as\n * {@link Select}'s `error` does. Only with `label`. */\n error?: ReactNode;\n}\n\n/**\n * A line under the group saying what the CHOSEN option means — lenkbank's ToggleField\n * `hint` (features/gear/common.tsx:97): not help behind a \"?\" but a caption, and one\n * that changes as the choice does. Pass a function of the value for that; it is\n * attached with `aria-describedby`, and a function caption is also a polite live\n * region, because a description is read when the group is entered and not again when\n * an arrow key changes the choice underneath it.\n *\n * In muted 11px text under the field (or the bare group), above an `error`.\n */\ntype ToggleGroupCaption<V> = ReactNode | ((value: V) => ReactNode);\n\n/** The group as it has always been: one option is always the answer. */\nexport interface ToggleGroupRequiredProps<T extends string> extends ToggleGroupBaseProps<T> {\n allowEmpty?: false;\n value: T;\n onChange: (value: T) => void;\n /** See {@link ToggleGroupCaption}. */\n caption?: ToggleGroupCaption<T>;\n}\n\n/**\n * A group that can be emptied: clicking the active option clears it, and `onChange`\n * receives `null` (Keksdose's support-panel filters, where \"no filter\" is reached by\n * clicking the filter that is on).\n *\n * The options become TOGGLE BUTTONS (`aria-pressed`, in a `role=\"group\"`) rather than\n * radios. A radio cannot be unchecked by activating it — no screen reader user expects\n * a second press on \"Open, radio, checked\" to leave nothing checked, and nothing would\n * tell them it had. \"Open, toggle button, pressed\" says exactly what a press will do.\n */\nexport interface ToggleGroupClearableProps<T extends string> extends ToggleGroupBaseProps<T> {\n allowEmpty: true;\n value: T | null;\n onChange: (value: T | null) => void;\n /** See {@link ToggleGroupCaption}. `null` while nothing is chosen. */\n caption?: ToggleGroupCaption<T | null>;\n}\n\n/** `allowEmpty` picks the shape, so `onChange` is typed `(T) => void` unless the group\n * can actually emit `null` — no existing caller has a `null` to handle. */\nexport type ToggleGroupProps<T extends string> =\n | ToggleGroupRequiredProps<T>\n | ToggleGroupClearableProps<T>;\n\n/**\n * Overloaded rather than typed by the union alone (keksdose, \"Gaps found adopting\n * 0.6.0\" #7). Inferring `T` through a union of prop shapes let TypeScript settle on\n * `string`, so `<ToggleGroup allowEmpty value={filter} onChange={setFilter} />` over a\n * `useState<Status | null>` did not compile unless the caller spelled\n * `<ToggleGroup<Status>>`. One signature per mode lets each infer `T` from its own\n * `value`/`onChange`/`options`; the third keeps a caller that forwards a\n * {@link ToggleGroupProps} union (a wrapper component) compiling.\n */\nexport function ToggleGroup<T extends string>(props: ToggleGroupClearableProps<T>): ReactElement;\nexport function ToggleGroup<T extends string>(props: ToggleGroupRequiredProps<T>): ReactElement;\nexport function ToggleGroup<T extends string>(props: ToggleGroupProps<T>): ReactElement;\nexport function ToggleGroup<T extends string>(props: ToggleGroupProps<T>): ReactElement {\n const {\n value,\n options,\n className,\n optionClassName,\n ariaLabel,\n disabled = false,\n size = \"md\",\n label,\n hint,\n error,\n \"aria-label\": ariaLabelAttr,\n ...restWithMode\n } = props;\n const labelId = useId();\n const errorId = useId();\n const field = label !== undefined && label !== null && label !== false && label !== \"\";\n const hasError = field && error !== undefined && error !== null && error !== false && error !== \"\";\n // Taken off the rest so neither reaches the DOM; `props` keeps them paired, which is\n // what lets the `onChange` below be called with `null` only in the mode that allows it.\n const { allowEmpty: _allowEmpty, onChange: _onChange, caption, ...rest } = restWithMode;\n const captionId = useId();\n const captionIsLive = typeof caption === \"function\";\n const captionNode = captionIsLive ? (caption as (v: T | null) => ReactNode)(value) : caption;\n const hasCaption = captionNode !== undefined && captionNode !== null && captionNode !== false && captionNode !== \"\";\n const choose = (next: T) => {\n if (props.allowEmpty) props.onChange(next === value ? null : next);\n else props.onChange(next);\n };\n const clearable = props.allowEmpty === true;\n // A radio group is ONE tab stop (the checked radio, else the first) and arrows move\n // the choice — the pattern `role=\"radiogroup\"` promises a screen-reader user. Before\n // 0.7.0 each segment was its own tab stop with no arrow keys. The clearable mode is a\n // row of toggle buttons, where separate tab stops are the pattern.\n const tabStop = options.some((o) => o.value === value) ? value : options[0]?.value;\n const onRadioKey = (e: KeyboardEvent<HTMLButtonElement>, index: number) => {\n const last = options.length - 1;\n let next: number | null = null;\n const step = horizontalStep(e.key, e.currentTarget);\n if (step !== 0) next = index + step;\n else if (e.key === \"ArrowDown\") next = index + 1;\n else if (e.key === \"ArrowUp\") next = index - 1;\n else if (e.key === \"Home\") next = 0;\n else if (e.key === \"End\") next = last;\n if (next === null) return;\n e.preventDefault();\n next = next < 0 ? last : next > last ? 0 : next;\n const buttons = e.currentTarget.parentElement?.querySelectorAll<HTMLButtonElement>(\":scope > button\");\n buttons?.[next]?.focus();\n choose(options[next].value);\n };\n const group = (\n <div\n // The audit's named example of a closed prop list (§\"Public API design\"): the\n // tour locates a step by CSS SELECTOR, so a component that drops every attribute\n // it was not expecting cannot be spotlighted at all — and Keksdose's rule editor\n // carries a comment explaining that it wraps this group in a bare <div> for\n // exactly that reason.\n //\n // `...rest` first, then the attributes the group cannot do without: a caller\n // hanging an anchor or a test id on the group must not be able to overwrite the\n // radiogroup role or the disabled state by accident. `className` is destructured\n // out entirely and merged through `cn`, so it is never in here.\n {...rest}\n role={clearable ? \"group\" : \"radiogroup\"}\n // The DOM spelling wins; `ariaLabel` is the fallback for the call sites that\n // have not moved yet.\n aria-label={ariaLabelAttr ?? ariaLabel}\n aria-labelledby={field && ariaLabelAttr === undefined && ariaLabel === undefined ? labelId : rest[\"aria-labelledby\"]}\n aria-invalid={hasError || rest[\"aria-invalid\"] || undefined}\n aria-describedby={\n [rest[\"aria-describedby\"], hasCaption && captionId, hasError && errorId].filter(Boolean).join(\" \") || undefined\n }\n // `aria-disabled` on the group as well as `disabled` on each button: a radio\n // group is what the user is being refused, and a screen reader announcing\n // three separately-disabled radios does not say that.\n aria-disabled={disabled || undefined}\n className={cn(\n // `gap-0.5` — the same 2px as the container's own padding, so EVERY segment\n // sits in a uniform 2px moat and no two fills ever touch. Flush segments were\n // Keksdose live #268's rework: the pressed segment wears a saturated fill and\n // an unpressed neighbour wears a pale hover fill, and with a shared edge the\n // two rectangles read as one smeared shape — *\"the boundary of the selected\n // option and hovering next to it overlays the boundary of the selected\n // button\"*. A gap is what makes each segment its own chip; it cannot be\n // undone by a caller's per-option colour, which a hover-only fix could.\n //\n // (The hover fill is the DESKTOP half of that report: Tailwind v4 wraps every\n // `hover:` in `@media (hover: hover)`, so a phone never paints it. The half a\n // phone does see is the focus ring — see the segment's own note below.)\n \"inline-flex w-full gap-0.5 rounded-md border border-[var(--border-strong)] bg-[var(--bg-surface)] p-0.5 shadow-sm\",\n // The whole group fades, the way every other disabled control in this\n // package does; `cursor-not-allowed` is on the buttons, which is what a\n // pointer is actually over.\n disabled && \"opacity-60\",\n // Inside the field's chrome the group is only a row of segments: no border, no\n // surface, no padding of its own, and the field (not the group) is what dims.\n field && \"border-0 bg-transparent p-0 shadow-none opacity-100\",\n !field && className,\n )}\n >\n {options.map((opt, index) => {\n const active = opt.value === value;\n return (\n <button\n key={opt.value}\n type=\"button\"\n role={clearable ? undefined : \"radio\"}\n aria-checked={clearable ? undefined : active}\n aria-pressed={clearable ? active : undefined}\n disabled={disabled}\n tabIndex={clearable ? undefined : opt.value === tabStop ? 0 : -1}\n onKeyDown={clearable ? undefined : (e) => onRadioKey(e, index)}\n onClick={() => choose(opt.value)}\n className={cn(\n // `truncate` (which carries whitespace-nowrap) rather than letting a\n // label wrap: a segmented control sizes its whole row to the tallest\n // option, so one two-word option — Keksdose feedback #147's \"Where I\n // am\" — silently doubles the height of every segment beside it.\n //\n // `basis-auto` is what keeps that ellipsis a LAST resort rather than\n // the normal state (Keksdose dev#475). With flex-1's `basis-0`, a\n // shrink-to-fit group (`w-auto`) still resolves to the sum of the\n // labels' widths — and then splits it EQUALLY, so the short option\n // got 66px it did not need and \"Where I am\" got 66 of the 81 it did:\n // truncated at 1778px of free screen. Basing each segment on its own\n // content and sharing only the LEFTOVER space keeps a full-width\n // group's segments near-equal and an auto-width group's exact.\n //\n // `focus-visible` + `ring-inset`, not `focus` + an outset ring. A ring\n // is a box-shadow that spreads OUTWARD, so on a flush group it painted\n // 2px of ring over both neighbours and over the container's own border\n // — and on a phone it appeared on every TAP, because a tap focuses the\n // button. That is the other half of what live #268's rework saw\n // overlaying the selected segment's boundary. Inset keeps the ring\n // inside the segment it belongs to; focus-visible keeps it for the\n // keyboard, which is the only input that needs it.\n \"min-w-0 flex-1 basis-auto truncate rounded px-3 py-1.5 text-sm font-medium transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--border-strong)]\",\n size === \"sm\" && \"px-2 py-1 text-xs\",\n // In a field: no vertical padding and a 20px line — a `text-sm` line, the\n // same line a labelled Select holds under its label strip — so the field's\n // own `pt-4 pb-1` decides the height, as it does for the select.\n field && \"py-0 leading-5\",\n active\n ? \"bg-[var(--bg-inverse)] text-[var(--text-inverse)]\"\n : \"text-[var(--text-secondary)] hover:bg-[var(--bg-hover)]\",\n // No hover fill on a group that cannot be changed — a segment that\n // lights up under the pointer is an offer, and there is none here.\n disabled && \"cursor-not-allowed hover:bg-transparent dark:hover:bg-transparent\",\n optionClassName,\n opt.className,\n )}\n >\n {opt.label}\n </button>\n );\n })}\n </div>\n );\n // Rendered whenever the caption is — `aria-live` must be on the element BEFORE its\n // text changes, or the change is not announced — but empty (no height, no margin)\n // when there is nothing to say, so a function caption that returns null for some\n // options leaves no gap. Empty rather than `hidden`: some readers do not announce\n // text that appears inside an element coming back from `display: none`.\n const captionEl =\n hasCaption || captionIsLive ? (\n <p\n id={captionId}\n aria-live={captionIsLive ? \"polite\" : undefined}\n className={cn(\"text-[11px] leading-snug text-[var(--text-muted)]\", hasCaption && \"mt-1\")}\n >\n {hasCaption ? captionNode : null}\n </p>\n ) : null;\n if (!field) {\n if (!captionEl) return group;\n // The group keeps its `className`, as without a caption; the wrapper only stacks.\n return (\n <div className=\"min-w-0\">\n {group}\n {captionEl}\n </div>\n );\n }\n return (\n // `h-full` + `flex-1`: the chrome fills a grid or stretched flex row, which is what\n // levels it with a select beside it whatever the browser makes of the select.\n <div className={cn(\"flex h-full flex-col\", className)}>\n <FloatingField\n className=\"flex flex-1 flex-col\"\n label={<span id={labelId}>{label}</span>}\n staticLabel\n hint={hint}\n >\n <div\n className={cn(\n \"flex flex-1 flex-col justify-center rounded-md border border-[var(--border)] bg-[var(--bg-surface)] px-1 pt-4 pb-1 shadow-sm\",\n disabled && \"bg-[var(--bg-surface-2)] opacity-60\",\n hasError && FIELD_INVALID,\n )}\n >\n {group}\n </div>\n </FloatingField>\n {captionEl}\n {hasError && (\n <p id={errorId} className=\"mt-1 text-[11px] leading-tight text-[var(--danger)]\">\n {error}\n </p>\n )}\n </div>\n );\n}\n"],"mappings":";AAgPU,cA0EJ,YA1EI;AAhPV,SAAS,aAAa;AAEtB,SAAS,UAAU;AACnB,SAAS,sBAAsB;AAC/B,SAAS,eAAe,qBAAqB;AAmItC,SAAS,YAA8B,OAA0C;AACtF,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX,OAAO;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd,GAAG;AAAA,EACL,IAAI;AACJ,QAAM,UAAU,MAAM;AACtB,QAAM,UAAU,MAAM;AACtB,QAAM,QAAQ,UAAU,UAAa,UAAU,QAAQ,UAAU,SAAS,UAAU;AACpF,QAAM,WAAW,SAAS,UAAU,UAAa,UAAU,QAAQ,UAAU,SAAS,UAAU;AAGhG,QAAM,EAAE,YAAY,aAAa,UAAU,WAAW,SAAS,GAAG,KAAK,IAAI;AAC3E,QAAM,YAAY,MAAM;AACxB,QAAM,gBAAgB,OAAO,YAAY;AACzC,QAAM,cAAc,gBAAiB,QAAuC,KAAK,IAAI;AACrF,QAAM,aAAa,gBAAgB,UAAa,gBAAgB,QAAQ,gBAAgB,SAAS,gBAAgB;AACjH,QAAM,SAAS,CAAC,SAAY;AAC1B,QAAI,MAAM,WAAY,OAAM,SAAS,SA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AAA;AAAA,IAGE,qBAAC,SAAI,WAAW,GAAG,wBAAwB,SAAS,GAClD;AAAA;AAAA,QAAC;AAAA;AAAA,UACC,WAAU;AAAA,UACV,OAAO,oBAAC,UAAK,IAAI,SAAU,iBAAM;AAAA,UACjC,aAAW;AAAA,UACX;AAAA,UAEA;AAAA,YAAC;AAAA;AAAA,cACC,WAAW;AAAA,gBACT;AAAA,gBACA,YAAY;AAAA,gBACZ,YAAY;AAAA,cACd;AAAA,cAEC;AAAA;AAAA,UACH;AAAA;AAAA,MACF;AAAA,MACC;AAAA,MACA,YACC,oBAAC,OAAE,IAAI,SAAS,WAAU,uDACvB,iBACH;AAAA,OAEJ;AAAA;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../src/components/toggle-group.tsx"],"sourcesContent":["import { useId } from \"react\";\nimport type { ComponentPropsWithoutRef, KeyboardEvent, ReactElement, ReactNode } from \"react\";\nimport { cn } from \"../lib/cn\";\nimport { horizontalStep } from \"../lib/direction\";\nimport { FIELD_INVALID, FloatingField, Label } from \"./ui\";\n\nexport interface ToggleOption<T extends string> {\n value: T;\n label: string;\n className?: string;\n}\n\n/**\n * `onChange` is the group's own — the chosen VALUE, not a DOM event — so the div's\n * `onChange` is omitted rather than shadowed: leaving both in scope would give the\n * prop two incompatible meanings depending on which overload TypeScript picked.\n *\n * `children` is omitted too: this renders its `options` and nothing else, so a `children` the type\n * accepted and the component ignored would be a prop that silently does nothing —\n * worse than one that does not compile.\n */\nexport interface ToggleGroupBaseProps<T extends string>\n extends Omit<ComponentPropsWithoutRef<\"div\">, \"onChange\" | \"children\"> {\n options: ToggleOption<T>[];\n className?: string;\n /** Applied to every option button (e.g. to tune height/rounding to match\n * adjacent fields). Per-option `className` still wins over this. */\n optionClassName?: string;\n /**\n * @deprecated Pass `aria-label` instead — the DOM spelling, which every other\n * control in this kit now answers to. Kept working because three applications ship\n * this one today; it names the group only when `aria-label` is absent.\n */\n ariaLabel?: string;\n /**\n * Show, refuse the change (Keksdose live #288: a payment dated in the future has no\n * state to set).\n *\n * Whatever `value` says stays pressed and keeps its own fill rather than going grey\n * with the rest — a reader who cannot see WHICH option is chosen has been told less\n * than before it was disabled. A caller with nothing to show passes no value, and\n * the group renders dimmed with nothing pressed, which is the shape Keksdose's\n * status picker uses for a row whose status does not exist yet.\n *\n * On the whole GROUP, not per option: a segmented control where some segments are\n * live and others are not is a menu with holes in it, and no caller here wants one.\n */\n disabled?: boolean;\n /**\n * `sm`: 12px options with `px-2 py-1` — the compact group keksdose's rule editor\n * (rule-editor:204) writes as `optionClassName=\"px-2 py-1 text-xs\"` beside a small\n * caption. `md` (default) is the size every other group has.\n */\n size?: \"sm\" | \"md\";\n /**\n * Stand in a form row as a FIELD: with a label the group wears the field's chrome —\n * border, surface, the top strip with a small static label in it, a labelled\n * {@link Select}'s height — so beside an Input or a Select it reads as one of them\n * rather than as a control with a caption over it. lenkbank builds exactly this by\n * hand as `ToggleField` (features/gear/common.tsx:97, feedback #69), and its notes\n * are why the chrome STRETCHES to its row as well as matching the select's padding:\n * a native select's height is the browser's, so a toggle a few pixels short of it\n * is levelled up by the row rather than by arithmetic.\n *\n * The label names the group (`aria-labelledby`), so `aria-label` is not needed. With\n * a label, `className` styles the field's wrapper — as on {@link Select} — and the\n * group's own box is dropped: two nested borders read as a control in a control.\n */\n label?: ReactNode;\n /**\n * Where `label` goes. `\"field\"` (default): the field chrome described under `label`.\n * `\"above\"`: the kit's {@link Label} over the bare group — the shape of a {@link Field}\n * — with `hint` beside the label and `error` under the group, for a form that sets\n * its labels above its fields (kastlan's international-rent-calculator.tsx, whose DE\n * cap pair sits in a `Field` column between two labelled-above inputs, where the\n * chrome's inner label would be the only one of its kind).\n *\n * Inside a `Field`, pass no `label` at all and spread the render-prop instead —\n * `{(ids, { labelId }) => <ToggleGroup {...ids} aria-labelledby={labelId} … />}` —\n * so the Field's label names the group and its hint and error describe it.\n */\n labelPlacement?: \"field\" | \"above\";\n /** A {@link FieldHint} on the label line, as on a labelled {@link Select}. Only with\n * `label`. */\n hint?: ReactNode;\n /** The message under the field when it is wrong: paints the field's border with\n * `--danger`, marks the group `aria-invalid` and describes it with the message, as\n * {@link Select}'s `error` does. Only with `label`. */\n error?: ReactNode;\n}\n\n/**\n * A line under the group saying what the CHOSEN option means — lenkbank's ToggleField\n * `hint` (features/gear/common.tsx:97): not help behind a \"?\" but a caption, and one\n * that changes as the choice does. Pass a function of the value for that; it is\n * attached with `aria-describedby`, and a function caption is also a polite live\n * region, because a description is read when the group is entered and not again when\n * an arrow key changes the choice underneath it.\n *\n * In muted 11px text under the field (or the bare group), above an `error`.\n */\ntype ToggleGroupCaption<V> = ReactNode | ((value: V) => ReactNode);\n\n/** The group as it has always been: one option is always the answer. */\nexport interface ToggleGroupRequiredProps<T extends string> extends ToggleGroupBaseProps<T> {\n allowEmpty?: false;\n /**\n * What the options ARE to a screen reader, separately from whether the group can be\n * emptied (kastlan feedback #47).\n *\n * - `\"radio\"` (default) — a `radiogroup` of radios: one Tab stop, arrow keys MOVE the\n * choice. Right for a choice between answers (\"Monthly / Yearly\").\n * - `\"pressed\"` — a `group` of toggle buttons (`aria-pressed`), each its own Tab stop,\n * Space/Enter to press; still one option always pressed. Right for a row that reads\n * as a set of switches — a view mode, a toolbar-like filter — where arrows moving the\n * selection on focus would be a surprise.\n *\n * Before this the only way to `aria-pressed` was `allowEmpty`, which also let a second\n * press clear the choice — so kastlan took the clearable shape and threw the `null`\n * away in `onChange` (`(v) => v && setMode(v)`), a group announcing that a press would\n * unpress what it would not. Here a press on the pressed option re-sends its value, as\n * the radio shape does, and nothing is ever unpressed. A clearable group\n * (`allowEmpty`) is always `\"pressed\"`: a radio cannot be unchecked by activating it.\n */\n semantics?: \"radio\" | \"pressed\";\n value: T;\n onChange: (value: T) => void;\n /** See {@link ToggleGroupCaption}. */\n caption?: ToggleGroupCaption<T>;\n}\n\n/**\n * A group that can be emptied: clicking the active option clears it, and `onChange`\n * receives `null` (Keksdose's support-panel filters, where \"no filter\" is reached by\n * clicking the filter that is on).\n *\n * The options become TOGGLE BUTTONS (`aria-pressed`, in a `role=\"group\"`) rather than\n * radios. A radio cannot be unchecked by activating it — no screen reader user expects\n * a second press on \"Open, radio, checked\" to leave nothing checked, and nothing would\n * tell them it had. \"Open, toggle button, pressed\" says exactly what a press will do.\n */\nexport interface ToggleGroupClearableProps<T extends string> extends ToggleGroupBaseProps<T> {\n allowEmpty: true;\n /** Always toggle buttons — see {@link ToggleGroupRequiredProps.semantics}. Accepted so\n * a wrapper can forward one `semantics` to either shape. */\n semantics?: \"pressed\";\n value: T | null;\n onChange: (value: T | null) => void;\n /** See {@link ToggleGroupCaption}. `null` while nothing is chosen. */\n caption?: ToggleGroupCaption<T | null>;\n}\n\n/** `allowEmpty` picks the shape, so `onChange` is typed `(T) => void` unless the group\n * can actually emit `null` — no existing caller has a `null` to handle. */\nexport type ToggleGroupProps<T extends string> =\n | ToggleGroupRequiredProps<T>\n | ToggleGroupClearableProps<T>;\n\n/**\n * Overloaded rather than typed by the union alone (keksdose, \"Gaps found adopting\n * 0.6.0\" #7). Inferring `T` through a union of prop shapes let TypeScript settle on\n * `string`, so `<ToggleGroup allowEmpty value={filter} onChange={setFilter} />` over a\n * `useState<Status | null>` did not compile unless the caller spelled\n * `<ToggleGroup<Status>>`. One signature per mode lets each infer `T` from its own\n * `value`/`onChange`/`options`; the third keeps a caller that forwards a\n * {@link ToggleGroupProps} union (a wrapper component) compiling.\n */\nexport function ToggleGroup<T extends string>(props: ToggleGroupClearableProps<T>): ReactElement;\nexport function ToggleGroup<T extends string>(props: ToggleGroupRequiredProps<T>): ReactElement;\nexport function ToggleGroup<T extends string>(props: ToggleGroupProps<T>): ReactElement;\nexport function ToggleGroup<T extends string>(props: ToggleGroupProps<T>): ReactElement {\n const {\n value,\n options,\n className,\n optionClassName,\n ariaLabel,\n disabled = false,\n size = \"md\",\n label,\n labelPlacement = \"field\",\n hint,\n error,\n \"aria-label\": ariaLabelAttr,\n ...restWithMode\n } = props;\n const labelId = useId();\n const errorId = useId();\n const labelled = label !== undefined && label !== null && label !== false && label !== \"\";\n // `field` is the chrome; a label placed above keeps the bare group's own box.\n const field = labelled && labelPlacement === \"field\";\n const above = labelled && labelPlacement === \"above\";\n const hasError = labelled && error !== undefined && error !== null && error !== false && error !== \"\";\n // Taken off the rest so neither reaches the DOM; `props` keeps them paired, which is\n // what lets the `onChange` below be called with `null` only in the mode that allows it.\n const { allowEmpty: _allowEmpty, onChange: _onChange, caption, semantics: _semantics, ...rest } = restWithMode;\n // Invalid from outside too: a `Field` hands the bare group `aria-invalid`, and the\n // border has to say what the attribute says.\n const outsideInvalid = rest[\"aria-invalid\"] === true || rest[\"aria-invalid\"] === \"true\";\n const captionId = useId();\n const captionIsLive = typeof caption === \"function\";\n const captionNode = captionIsLive ? (caption as (v: T | null) => ReactNode)(value) : caption;\n const hasCaption = captionNode !== undefined && captionNode !== null && captionNode !== false && captionNode !== \"\";\n const choose = (next: T) => {\n if (props.allowEmpty) props.onChange(next === value ? null : next);\n else props.onChange(next);\n };\n // `pressed`: toggle buttons. Every clearable group is; a required one is when it asks\n // (kastlan #47) — the role, and not whether a second press clears, is what this flag\n // decides from here on, so `choose` above still keys off `allowEmpty` alone.\n const pressed = props.allowEmpty === true || props.semantics === \"pressed\";\n // A radio group is ONE tab stop (the checked radio, else the first) and arrows move\n // the choice — the pattern `role=\"radiogroup\"` promises a screen-reader user. Before\n // 0.7.0 each segment was its own tab stop with no arrow keys. The toggle-button shape\n // is a row of buttons, where separate tab stops are the pattern.\n const tabStop = options.some((o) => o.value === value) ? value : options[0]?.value;\n const onRadioKey = (e: KeyboardEvent<HTMLButtonElement>, index: number) => {\n const last = options.length - 1;\n let next: number | null = null;\n const step = horizontalStep(e.key, e.currentTarget);\n if (step !== 0) next = index + step;\n else if (e.key === \"ArrowDown\") next = index + 1;\n else if (e.key === \"ArrowUp\") next = index - 1;\n else if (e.key === \"Home\") next = 0;\n else if (e.key === \"End\") next = last;\n if (next === null) return;\n e.preventDefault();\n next = next < 0 ? last : next > last ? 0 : next;\n const buttons = e.currentTarget.parentElement?.querySelectorAll<HTMLButtonElement>(\":scope > button\");\n buttons?.[next]?.focus();\n choose(options[next].value);\n };\n const group = (\n <div\n // The audit's named example of a closed prop list (§\"Public API design\"): the\n // tour locates a step by CSS SELECTOR, so a component that drops every attribute\n // it was not expecting cannot be spotlighted at all — and Keksdose's rule editor\n // carries a comment explaining that it wraps this group in a bare <div> for\n // exactly that reason.\n //\n // `...rest` first, then the attributes the group cannot do without: a caller\n // hanging an anchor or a test id on the group must not be able to overwrite the\n // radiogroup role or the disabled state by accident. `className` is destructured\n // out entirely and merged through `cn`, so it is never in here.\n {...rest}\n role={pressed ? \"group\" : \"radiogroup\"}\n // The DOM spelling wins; `ariaLabel` is the fallback for the call sites that\n // have not moved yet.\n aria-label={ariaLabelAttr ?? ariaLabel}\n aria-labelledby={labelled && ariaLabelAttr === undefined && ariaLabel === undefined ? labelId : rest[\"aria-labelledby\"]}\n aria-invalid={hasError || rest[\"aria-invalid\"] || undefined}\n aria-describedby={\n [rest[\"aria-describedby\"], hasCaption && captionId, hasError && errorId].filter(Boolean).join(\" \") || undefined\n }\n // `aria-disabled` on the group as well as `disabled` on each button: a radio\n // group is what the user is being refused, and a screen reader announcing\n // three separately-disabled radios does not say that.\n aria-disabled={disabled || undefined}\n className={cn(\n // `gap-0.5` — the same 2px as the container's own padding, so EVERY segment\n // sits in a uniform 2px moat and no two fills ever touch. Flush segments were\n // Keksdose live #268's rework: the pressed segment wears a saturated fill and\n // an unpressed neighbour wears a pale hover fill, and with a shared edge the\n // two rectangles read as one smeared shape — *\"the boundary of the selected\n // option and hovering next to it overlays the boundary of the selected\n // button\"*. A gap is what makes each segment its own chip; it cannot be\n // undone by a caller's per-option colour, which a hover-only fix could.\n //\n // (The hover fill is the DESKTOP half of that report: Tailwind v4 wraps every\n // `hover:` in `@media (hover: hover)`, so a phone never paints it. The half a\n // phone does see is the focus ring — see the segment's own note below.)\n \"inline-flex w-full gap-0.5 rounded-md border border-[var(--border-strong)] bg-[var(--bg-surface)] p-0.5 shadow-sm\",\n // The whole group fades, the way every other disabled control in this\n // package does; `cursor-not-allowed` is on the buttons, which is what a\n // pointer is actually over.\n disabled && \"opacity-60\",\n // The bare group (no chrome to paint) wears the invalid border itself.\n !field && (outsideInvalid || (above && hasError)) && FIELD_INVALID,\n // Inside the field's chrome the group is only a row of segments: no border, no\n // surface, no padding of its own, and the field (not the group) is what dims.\n field && \"border-0 bg-transparent p-0 shadow-none opacity-100\",\n !labelled && className,\n )}\n >\n {options.map((opt, index) => {\n const active = opt.value === value;\n return (\n <button\n key={opt.value}\n type=\"button\"\n role={pressed ? undefined : \"radio\"}\n aria-checked={pressed ? undefined : active}\n aria-pressed={pressed ? active : undefined}\n disabled={disabled}\n tabIndex={pressed ? undefined : opt.value === tabStop ? 0 : -1}\n onKeyDown={pressed ? undefined : (e) => onRadioKey(e, index)}\n onClick={() => choose(opt.value)}\n className={cn(\n // `truncate` (which carries whitespace-nowrap) rather than letting a\n // label wrap: a segmented control sizes its whole row to the tallest\n // option, so one two-word option — Keksdose feedback #147's \"Where I\n // am\" — silently doubles the height of every segment beside it.\n //\n // `basis-auto` is what keeps that ellipsis a LAST resort rather than\n // the normal state (Keksdose dev#475). With flex-1's `basis-0`, a\n // shrink-to-fit group (`w-auto`) still resolves to the sum of the\n // labels' widths — and then splits it EQUALLY, so the short option\n // got 66px it did not need and \"Where I am\" got 66 of the 81 it did:\n // truncated at 1778px of free screen. Basing each segment on its own\n // content and sharing only the LEFTOVER space keeps a full-width\n // group's segments near-equal and an auto-width group's exact.\n //\n // `focus-visible` + `ring-inset`, not `focus` + an outset ring. A ring\n // is a box-shadow that spreads OUTWARD, so on a flush group it painted\n // 2px of ring over both neighbours and over the container's own border\n // — and on a phone it appeared on every TAP, because a tap focuses the\n // button. That is the other half of what live #268's rework saw\n // overlaying the selected segment's boundary. Inset keeps the ring\n // inside the segment it belongs to; focus-visible keeps it for the\n // keyboard, which is the only input that needs it.\n \"min-w-0 flex-1 basis-auto truncate rounded px-3 py-1.5 text-sm font-medium transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--border-strong)]\",\n size === \"sm\" && \"px-2 py-1 text-xs\",\n // In a field: no vertical padding and a 20px line — a `text-sm` line, the\n // same line a labelled Select holds under its label strip — so the field's\n // own `pt-4 pb-1` decides the height, as it does for the select.\n field && \"py-0 leading-5\",\n active\n ? \"bg-[var(--bg-inverse)] text-[var(--text-inverse)]\"\n : \"text-[var(--text-secondary)] hover:bg-[var(--bg-hover)]\",\n // No hover fill on a group that cannot be changed — a segment that\n // lights up under the pointer is an offer, and there is none here.\n disabled && \"cursor-not-allowed hover:bg-transparent dark:hover:bg-transparent\",\n optionClassName,\n opt.className,\n )}\n >\n {opt.label}\n </button>\n );\n })}\n </div>\n );\n // Rendered whenever the caption is — `aria-live` must be on the element BEFORE its\n // text changes, or the change is not announced — but empty (no height, no margin)\n // when there is nothing to say, so a function caption that returns null for some\n // options leaves no gap. Empty rather than `hidden`: some readers do not announce\n // text that appears inside an element coming back from `display: none`.\n const captionEl =\n hasCaption || captionIsLive ? (\n <p\n id={captionId}\n aria-live={captionIsLive ? \"polite\" : undefined}\n className={cn(\"text-[11px] leading-snug text-[var(--text-muted)]\", hasCaption && \"mt-1\")}\n >\n {hasCaption ? captionNode : null}\n </p>\n ) : null;\n const errorEl = hasError ? (\n <p id={errorId} className=\"mt-1 text-[11px] leading-tight text-[var(--danger)]\">\n {error}\n </p>\n ) : null;\n if (above) {\n // `relative` so a caller's `sr-only` label cannot escape (sr-only-containment).\n return (\n <div className={cn(\"relative grid min-w-0 gap-1.5\", className)}>\n <div className=\"flex items-center gap-1\">\n {/* A `<label>` with no `htmlFor`: a group is not labelable, so it is named\n by `aria-labelledby` on the group; the element keeps the Field look. */}\n <Label\n id={labelId}\n disabled={disabled}\n data-error={hasError || undefined}\n className=\"data-[error=true]:text-[var(--danger)]\"\n >\n {label}\n </Label>\n {hint}\n </div>\n <div className=\"min-w-0\">\n {group}\n {captionEl}\n {errorEl}\n </div>\n </div>\n );\n }\n if (!field) {\n if (!captionEl) return group;\n // The group keeps its `className`, as without a caption; the wrapper only stacks.\n return (\n <div className=\"min-w-0\">\n {group}\n {captionEl}\n </div>\n );\n }\n return (\n // `h-full` + `flex-1`: the chrome fills a grid or stretched flex row, which is what\n // levels it with a select beside it whatever the browser makes of the select.\n <div className={cn(\"flex h-full flex-col\", className)}>\n <FloatingField\n className=\"flex flex-1 flex-col\"\n label={<span id={labelId}>{label}</span>}\n staticLabel\n hint={hint}\n >\n <div\n className={cn(\n \"flex flex-1 flex-col justify-center rounded-md border border-[var(--border)] bg-[var(--bg-surface)] px-1 pt-4 pb-1 shadow-sm\",\n disabled && \"bg-[var(--bg-surface-2)] opacity-60\",\n hasError && FIELD_INVALID,\n )}\n >\n {group}\n </div>\n </FloatingField>\n {captionEl}\n {errorEl}\n </div>\n );\n}\n"],"mappings":";AA+RU,cA+EF,YA/EE;AA/RV,SAAS,aAAa;AAEtB,SAAS,UAAU;AACnB,SAAS,sBAAsB;AAC/B,SAAS,eAAe,eAAe,aAAa;AAsK7C,SAAS,YAA8B,OAA0C;AACtF,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX,OAAO;AAAA,IACP;AAAA,IACA,iBAAiB;AAAA,IACjB;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd,GAAG;AAAA,EACL,IAAI;AACJ,QAAM,UAAU,MAAM;AACtB,QAAM,UAAU,MAAM;AACtB,QAAM,WAAW,UAAU,UAAa,UAAU,QAAQ,UAAU,SAAS,UAAU;AAEvF,QAAM,QAAQ,YAAY,mBAAmB;AAC7C,QAAM,QAAQ,YAAY,mBAAmB;AAC7C,QAAM,WAAW,YAAY,UAAU,UAAa,UAAU,QAAQ,UAAU,SAAS,UAAU;AAGnG,QAAM,EAAE,YAAY,aAA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":[]}
@@ -44,14 +44,38 @@ interface LegendEntry {
44
44
  /**
45
45
  * What the entry's mark looks like. `swatch` — a filled square, the default — says
46
46
  * WHICH MEASUREMENT. `stroke` says WHICH QUANTITY, for the charts that carry both at
47
- * once and tell them apart by colour and by dash.
47
+ * once and tell them apart by colour and by dash. `dot` is a round mark, for a
48
+ * MARKER on the chart (a point, an event) rather than a series.
48
49
  */
49
- marker?: "swatch" | "stroke";
50
+ marker?: "swatch" | "stroke" | "dot";
50
51
  /** Which of {@link STROKE_PATTERNS}, when the marker is a stroke — the same index
51
52
  * `SeriesChartSeries.dash` takes, so a legend cannot promise a dot-dash the plot
52
53
  * draws dashed. Or the same custom `stroke-dasharray` string the series draws with
53
54
  * (keksdose's `"4 3"`). */
54
55
  dash?: number | string;
56
+ /**
57
+ * A mark of the caller's own, drawn in place of {@link marker} — for a key whose
58
+ * mark is not a colour at all (a fading bar for "open-ended", a hairline for
59
+ * "today"). Decorative: it is wrapped `aria-hidden`, and the label is the name.
60
+ */
61
+ icon?: ReactNode;
62
+ /**
63
+ * `"end"`: push this entry to the legend's inline END — the far right in LTR, the far
64
+ * left in RTL — with everything before it kept at the start. kastlan's lease gantt
65
+ * (feedback #49) keys its bars at the start and its "today" hairline at the end, over
66
+ * the time axis whose end "today" is nearest, and wrote it as
67
+ * `className="[&>li:last-child]:ms-auto"` — a selector that breaks the moment the
68
+ * entries are reordered and that reaches into the legend's markup.
69
+ *
70
+ * An auto inline-start margin, so it is logical (RTL mirrors it) and it takes only the
71
+ * row's LEFTOVER space: on a narrow screen where the row wraps, the entry wraps with it
72
+ * and sits at the end of its own line rather than overflowing. Give it to the LAST
73
+ * entry — auto margins push everything after them too, so an end entry in the middle
74
+ * drags the rest over with it (which is also how to end-align a GROUP: mark its first).
75
+ * In a vertical legend it sits at the column's inline end. Honoured by both
76
+ * {@link StaticLegend} and {@link ToggleLegend}, which share this entry type.
77
+ */
78
+ align?: "start" | "end";
55
79
  }
56
80
  interface ToggleLegendProps {
57
81
  entries: LegendEntry[];
@@ -90,6 +114,32 @@ interface ToggleLegendProps {
90
114
  * so Tab reaches every switch and Space/Enter flips it.
91
115
  */
92
116
  declare function ToggleLegend({ entries, hidden, onToggle, orientation, showSingle, className, labels: labelsProp, }: ToggleLegendProps): react.JSX.Element | null;
117
+ interface StaticLegendProps {
118
+ entries: LegendEntry[];
119
+ /** See {@link ToggleLegendProps.orientation}. */
120
+ orientation?: "horizontal" | "vertical";
121
+ /** The list's accessible name. Default: the `seriesChart.legend` label. */
122
+ "aria-label"?: string;
123
+ className?: string;
124
+ /** Per-instance strings over `<UiKitProvider labels={{ seriesChart }}>`. */
125
+ labels?: Partial<SeriesChartLabels>;
126
+ }
127
+ /**
128
+ * A legend that is a KEY, not a control: the same entries and marks as
129
+ * {@link ToggleLegend} — swatch, stroke (with the chart's own dash), dot, or a mark of
130
+ * the caller's own — but nothing to press.
131
+ *
132
+ * A separate component rather than `ToggleLegend` without `onToggle`, because the two
133
+ * are different things to a screen reader: a group of switches announces a pressed
134
+ * state on every entry, a key is a LIST, read as "list, 4 items" and walked with the
135
+ * list keys, and costs no tab stops. The apps drew this by hand under the charts that
136
+ * say what a colour or a dash means without letting you switch it (kastlan's lease
137
+ * timeline, keksdose's cash buffer).
138
+ *
139
+ * Unlike `ToggleLegend` it draws a single entry: a key with one line still says what
140
+ * the one mark on the chart means.
141
+ */
142
+ declare function StaticLegend({ entries, orientation, "aria-label": ariaLabel, className, labels: labelsProp, }: StaticLegendProps): react.JSX.Element | null;
93
143
  /**
94
144
  * The column a vertical legend stands in: beside the charts, on their horizontal
95
145
  * centre line. `h-full` + `justify-center`, so it centres in a grid cell or a flex row
@@ -113,4 +163,4 @@ declare function LegendGroup({ title, children }: {
113
163
  children: ReactNode;
114
164
  }): react.JSX.Element;
115
165
 
116
- export { LegendColumn, type LegendEntry, LegendGroup, STEP_DASH, STROKE_PATTERNS, ToggleLegend, type ToggleLegendProps, strokeDash, toggleHidden };
166
+ export { LegendColumn, type LegendEntry, LegendGroup, STEP_DASH, STROKE_PATTERNS, StaticLegend, type StaticLegendProps, ToggleLegend, type ToggleLegendProps, strokeDash, toggleHidden };
@@ -52,7 +52,8 @@ function ToggleLegend({
52
52
  className: cn(
53
53
  "flex items-center gap-1.5 rounded text-start text-[11px] text-[var(--text-secondary)] transition-opacity hover:opacity-80",
54
54
  "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--brand)]",
55
- off && "opacity-35"
55
+ off && "opacity-35",
56
+ entry.align === "end" && "ms-auto"
56
57
  ),
57
58
  children: [
58
59
  /* @__PURE__ */ jsx(LegendMark, { entry, off }),
@@ -65,6 +66,41 @@ function ToggleLegend({
65
66
  }
66
67
  );
67
68
  }
69
+ function StaticLegend({
70
+ entries,
71
+ orientation = "horizontal",
72
+ "aria-label": ariaLabel,
73
+ className,
74
+ labels: labelsProp
75
+ }) {
76
+ const labels = useKitLabels("seriesChart", DEFAULT_SERIES_CHART_LABELS, labelsProp);
77
+ if (entries.length === 0) return null;
78
+ return /* @__PURE__ */ jsx(
79
+ "ul",
80
+ {
81
+ "aria-label": ariaLabel ?? labels.legend,
82
+ className: cn(
83
+ "m-0 flex list-none gap-x-3 gap-y-1 p-0",
84
+ orientation === "vertical" ? "flex-col items-start justify-center" : "mt-2 flex-wrap items-center",
85
+ className
86
+ ),
87
+ children: entries.map((entry) => /* @__PURE__ */ jsxs(
88
+ "li",
89
+ {
90
+ className: cn(
91
+ "flex items-center gap-1.5 text-[11px] text-[var(--text-secondary)]",
92
+ entry.align === "end" && "ms-auto"
93
+ ),
94
+ children: [
95
+ /* @__PURE__ */ jsx(LegendMark, { entry, off: false }),
96
+ entry.label
97
+ ]
98
+ },
99
+ entry.key
100
+ ))
101
+ }
102
+ );
103
+ }
68
104
  function LegendColumn({ children, className }) {
69
105
  return /* @__PURE__ */ jsx("div", { className: cn("flex h-full flex-col justify-center gap-3", className), children });
70
106
  }
@@ -75,6 +111,22 @@ function LegendGroup({ title, children }) {
75
111
  ] });
76
112
  }
77
113
  function LegendMark({ entry, off }) {
114
+ if (entry.icon != null) {
115
+ return /* @__PURE__ */ jsx("span", { "aria-hidden": true, className: "inline-flex shrink-0 items-center", children: entry.icon });
116
+ }
117
+ if (entry.marker === "dot") {
118
+ return /* @__PURE__ */ jsx(
119
+ "span",
120
+ {
121
+ "aria-hidden": true,
122
+ className: "size-2 shrink-0 rounded-full",
123
+ style: {
124
+ backgroundColor: off ? "transparent" : entry.color,
125
+ boxShadow: `inset 0 0 0 1.5px ${entry.color}`
126
+ }
127
+ }
128
+ );
129
+ }
78
130
  if (entry.marker === "stroke") {
79
131
  return /* @__PURE__ */ jsx("svg", { "aria-hidden": true, viewBox: "0 0 20 2", className: "h-0.5 w-5 shrink-0 overflow-visible", children: /* @__PURE__ */ jsx(
80
132
  "line",
@@ -106,6 +158,7 @@ export {
106
158
  LegendGroup,
107
159
  STEP_DASH,
108
160
  STROKE_PATTERNS,
161
+ StaticLegend,
109
162
  ToggleLegend,
110
163
  strokeDash,
111
164
  toggleHidden
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/toggle-legend.tsx"],"sourcesContent":["// A legend whose entries are SWITCHES — and the stroke table it shares with\n// `SeriesChart`. Lifted out of lenkbank's measurement plots, where ten legends over\n// thirteen charts took channels on and off the picture.\n//\n// No recharts in this module: a legend of switches is plain buttons, and it is as\n// useful under a chart the consumer drew by hand as under `SeriesChart`.\nimport type { ReactNode } from \"react\";\nimport { cn } from \"../lib/cn\";\nimport { useKitLabels } from \"../i18n/kit-labels\";\nimport { DEFAULT_SERIES_CHART_LABELS, type SeriesChartLabels } from \"./series-chart-labels\";\n\n/**\n * The strokes a reader can tell apart, in the order they are handed out.\n *\n * For the charts where the colour is already spoken for: a comparison draws each\n * measurement in its own colour, so a chart carrying several CHANNELS of each has\n * nothing left but the stroke — and \"solid versus dashed\" only gets you two.\n *\n * **Five, and the fifth is the last one.** They are the draughtsman's line types, in\n * the draughtsman's order — continuous, dashed, dotted, dash-dot, dash-dot-dot — the\n * one family of five a century of drawings has already proved legible at a hair's\n * width. A sixth is not distinguishable from one of these at two pixels wide, so a\n * chart needing one is a chart that should be split.\n *\n * Kept here, beside the legend's own mark, and read by `SeriesChart` from here — so\n * the key under a chart and the lines on it cannot disagree.\n */\nexport const STROKE_PATTERNS: readonly (string | undefined)[] = [\n undefined,\n \"5 4\",\n \"1 3\",\n \"9 3 2 3\",\n \"9 3 2 3 2 3\",\n];\n\n/** The dash array for the nth pattern, wrapping past the fifth. */\nexport function strokeDash(order: number): string | undefined {\n const n = STROKE_PATTERNS.length;\n return STROKE_PATTERNS[((Math.trunc(order) % n) + n) % n];\n}\n\n/** Which of the patterns a `step` series is drawn in.\n *\n * A whole-number channel that jumps rather than travels is drawn dashed, and it has\n * to be one of {@link STROKE_PATTERNS} rather than a dash array written out at the\n * call site: a legend entry says its pattern by index, so a step line drawn in\n * anything else would be a legend promising a solid line for a dashed one. */\nexport const STEP_DASH = 1;\n\n/**\n * One key switched, as a new hidden set.\n *\n * Every caller writes `onToggle={(key) => setHidden(toggleHidden(hidden, key))}`. A\n * new set rather than a mutated one, because the state is read during render and a\n * mutation of something a component already holds is invisible to React.\n */\nexport function toggleHidden(hidden: ReadonlySet<string>, key: string): ReadonlySet<string> {\n const next = new Set(hidden);\n if (!next.delete(key)) next.add(key);\n return next;\n}\n\nexport interface LegendEntry {\n key: string;\n label: ReactNode;\n /** Any CSS colour — `paletteFor(i)` for the kit's own ramp. */\n color: string;\n /**\n * What the entry's mark looks like. `swatch` — a filled square, the default — says\n * WHICH MEASUREMENT. `stroke` says WHICH QUANTITY, for the charts that carry both at\n * once and tell them apart by colour and by dash.\n */\n marker?: \"swatch\" | \"stroke\";\n /** Which of {@link STROKE_PATTERNS}, when the marker is a stroke — the same index\n * `SeriesChartSeries.dash` takes, so a legend cannot promise a dot-dash the plot\n * draws dashed. Or the same custom `stroke-dasharray` string the series draws with\n * (keksdose's `\"4 3\"`). */\n dash?: number | string;\n}\n\nexport interface ToggleLegendProps {\n entries: LegendEntry[];\n /** The keys currently off the chart. */\n hidden: ReadonlySet<string>;\n onToggle: (key: string) => void;\n /** `vertical` is for a legend standing BESIDE the charts rather than under them —\n * what a row of charts sharing one legend wants, since under two charts there is\n * no \"under\", and putting it under one says it belongs to that one. */\n orientation?: \"horizontal\" | \"vertical\";\n /**\n * Draw a legend of ONE entry rather than nothing.\n *\n * A single line's legend is usually noise. It is not where the legend is the only\n * SWITCH that line has — a series that starts hidden and has no entry to bring it\n * back is gone for good.\n */\n showSingle?: boolean;\n className?: string;\n /** Per-instance strings over `<UiKitProvider labels={{ seriesChart }}>`. */\n labels?: Partial<SeriesChartLabels>;\n}\n\n/**\n * A legend whose entries are switches.\n *\n * `ChartLegendContent` with `onItemClick`/`activeKey` is the other kind: clicking an\n * entry HIGHLIGHTS it and dims the rest, which is right when every series belongs on\n * the chart and one of them is momentarily interesting. This is for the opposite —\n * three coordinates on one axis where y runs to 800 and z barely moves, and the only\n * way to see z is to take y off the chart entirely. Any number may be off at once.\n *\n * A hidden entry keeps its mark and its place. Removing it would reflow the legend on\n * every click and lose the one thing it is for: saying what COULD be shown.\n *\n * Each entry is a real `<button>` with `aria-pressed` — pressed means \"on the chart\" —\n * so Tab reaches every switch and Space/Enter flips it.\n */\nexport function ToggleLegend({\n entries,\n hidden,\n onToggle,\n orientation = \"horizontal\",\n showSingle = false,\n className,\n labels: labelsProp,\n}: ToggleLegendProps) {\n const labels = useKitLabels(\"seriesChart\", DEFAULT_SERIES_CHART_LABELS, labelsProp);\n if (entries.length < (showSingle ? 1 : 2)) return null;\n return (\n <div\n role=\"group\"\n aria-label={labels.legend}\n className={cn(\n \"flex gap-x-3 gap-y-1\",\n orientation === \"vertical\"\n ? \"flex-col items-start justify-center\"\n : \"mt-2 flex-wrap items-center\",\n className,\n )}\n >\n {entries.map((entry) => {\n const off = hidden.has(entry.key);\n return (\n <button\n key={entry.key}\n type=\"button\"\n // Pressed rather than a checkbox: it is a control over what the chart\n // draws, and \"not pressed\" is the same sentence the dimmed mark says.\n aria-pressed={!off}\n onClick={() => onToggle(entry.key)}\n className={cn(\n \"flex items-center gap-1.5 rounded text-start text-[11px] text-[var(--text-secondary)] transition-opacity hover:opacity-80\",\n \"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--brand)]\",\n off && \"opacity-35\",\n )}\n >\n <LegendMark entry={entry} off={off} />\n {entry.label}\n </button>\n );\n })}\n </div>\n );\n}\n\n/**\n * The column a vertical legend stands in: beside the charts, on their horizontal\n * centre line. `h-full` + `justify-center`, so it centres in a grid cell or a flex row\n * that stretches it — and stacks whatever it is given, which is what a panel showing\n * two legends at once needs. The width is the caller's: how wide a legend column is\n * is a fact about that screen's layout.\n */\nexport function LegendColumn({ children, className }: { children: ReactNode; className?: string }) {\n return (\n <div className={cn(\"flex h-full flex-col justify-center gap-3\", className)}>{children}</div>\n );\n}\n\n/**\n * A legend and what it is a legend OF, as a headed column.\n *\n * For legends that are several vocabularies at once — which measurement and which\n * channel — so the entries are read down a group and the groups across. Wrapped rows\n * would put the second half of one group on a line under the first half of the next.\n */\nexport function LegendGroup({ title, children }: { title: ReactNode; children: ReactNode }) {\n return (\n <div className=\"flex min-w-0 flex-col items-start gap-1\">\n <span className=\"text-[10px] font-semibold uppercase tracking-wide text-[var(--text-muted)]\">\n {title}\n </span>\n <div className=\"flex flex-col items-start gap-y-0.5\">{children}</div>\n </div>\n );\n}\n\n/** The entry's mark: a square for a measurement, a stroke for a quantity. A hidden one\n * keeps its outline — a mark that vanished would leave a line of text with nothing in\n * front of it.\n *\n * A stroke is an SVG line with the chart's own `strokeDasharray`, not a CSS gradient\n * approximating it: a gradient can say \"solid or dashed\" and nothing more.\n *\n * A hidden stroke is NOT faded here: the button around it already is (`opacity-35`),\n * and the line used to take its own 0.35 on top — 0.35 × 0.35, about 12 %, a mark\n * gone rather than dimmed, while the square beside it read at the full 35 %. */\nfunction LegendMark({ entry, off }: { entry: LegendEntry; off: boolean }) {\n if (entry.marker === \"stroke\") {\n return (\n <svg aria-hidden viewBox=\"0 0 20 2\" className=\"h-0.5 w-5 shrink-0 overflow-visible\">\n <line\n x1={0}\n y1={1}\n x2={20}\n y2={1}\n stroke={entry.color}\n strokeWidth={2}\n strokeDasharray={typeof entry.dash === \"string\" ? entry.dash : strokeDash(entry.dash ?? 0)}\n />\n </svg>\n );\n }\n return (\n <span\n aria-hidden\n className=\"h-2.5 w-2.5 shrink-0 rounded-[3px]\"\n style={{\n backgroundColor: off ? \"transparent\" : entry.color,\n boxShadow: `inset 0 0 0 1.5px ${entry.color}`,\n }}\n />\n );\n}\n"],"mappings":";AA+IU,SAaE,KAbF;AAxIV,SAAS,UAAU;AACnB,SAAS,oBAAoB;AAC7B,SAAS,mCAA2D;AAkB7D,MAAM,kBAAmD;AAAA,EAC9D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAGO,SAAS,WAAW,OAAmC;AAC5D,QAAM,IAAI,gBAAgB;AAC1B,SAAO,iBAAkB,KAAK,MAAM,KAAK,IAAI,IAAK,KAAK,CAAC;AAC1D;AAQO,MAAM,YAAY;AASlB,SAAS,aAAa,QAA6B,KAAkC;AAC1F,QAAM,OAAO,IAAI,IAAI,MAAM;AAC3B,MAAI,CAAC,KAAK,OAAO,GAAG,EAAG,MAAK,IAAI,GAAG;AACnC,SAAO;AACT;AAyDO,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA,cAAc;AAAA,EACd,aAAa;AAAA,EACb;AAAA,EACA,QAAQ;AACV,GAAsB;AACpB,QAAM,SAAS,aAAa,eAAe,6BAA6B,UAAU;AAClF,MAAI,QAAQ,UAAU,aAAa,IAAI,GAAI,QAAO;AAClD,SACE;AAAA,IAAC;AAAA;AAAA,MACC,MAAK;AAAA,MACL,cAAY,OAAO;AAAA,MACnB,WAAW;AAAA,QACT;AAAA,QACA,gBAAgB,aACZ,wCACA;AAAA,QACJ;AAAA,MACF;AAAA,MAEC,kBAAQ,IAAI,CA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AA;AAAA,EACF;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../src/components/toggle-legend.tsx"],"sourcesContent":["// A legend whose entries are SWITCHES — and the stroke table it shares with\n// `SeriesChart`. Lifted out of lenkbank's measurement plots, where ten legends over\n// thirteen charts took channels on and off the picture.\n//\n// No recharts in this module: a legend of switches is plain buttons, and it is as\n// useful under a chart the consumer drew by hand as under `SeriesChart`.\nimport type { ReactNode } from \"react\";\nimport { cn } from \"../lib/cn\";\nimport { useKitLabels } from \"../i18n/kit-labels\";\nimport { DEFAULT_SERIES_CHART_LABELS, type SeriesChartLabels } from \"./series-chart-labels\";\n\n/**\n * The strokes a reader can tell apart, in the order they are handed out.\n *\n * For the charts where the colour is already spoken for: a comparison draws each\n * measurement in its own colour, so a chart carrying several CHANNELS of each has\n * nothing left but the stroke — and \"solid versus dashed\" only gets you two.\n *\n * **Five, and the fifth is the last one.** They are the draughtsman's line types, in\n * the draughtsman's order — continuous, dashed, dotted, dash-dot, dash-dot-dot — the\n * one family of five a century of drawings has already proved legible at a hair's\n * width. A sixth is not distinguishable from one of these at two pixels wide, so a\n * chart needing one is a chart that should be split.\n *\n * Kept here, beside the legend's own mark, and read by `SeriesChart` from here — so\n * the key under a chart and the lines on it cannot disagree.\n */\nexport const STROKE_PATTERNS: readonly (string | undefined)[] = [\n undefined,\n \"5 4\",\n \"1 3\",\n \"9 3 2 3\",\n \"9 3 2 3 2 3\",\n];\n\n/** The dash array for the nth pattern, wrapping past the fifth. */\nexport function strokeDash(order: number): string | undefined {\n const n = STROKE_PATTERNS.length;\n return STROKE_PATTERNS[((Math.trunc(order) % n) + n) % n];\n}\n\n/** Which of the patterns a `step` series is drawn in.\n *\n * A whole-number channel that jumps rather than travels is drawn dashed, and it has\n * to be one of {@link STROKE_PATTERNS} rather than a dash array written out at the\n * call site: a legend entry says its pattern by index, so a step line drawn in\n * anything else would be a legend promising a solid line for a dashed one. */\nexport const STEP_DASH = 1;\n\n/**\n * One key switched, as a new hidden set.\n *\n * Every caller writes `onToggle={(key) => setHidden(toggleHidden(hidden, key))}`. A\n * new set rather than a mutated one, because the state is read during render and a\n * mutation of something a component already holds is invisible to React.\n */\nexport function toggleHidden(hidden: ReadonlySet<string>, key: string): ReadonlySet<string> {\n const next = new Set(hidden);\n if (!next.delete(key)) next.add(key);\n return next;\n}\n\nexport interface LegendEntry {\n key: string;\n label: ReactNode;\n /** Any CSS colour — `paletteFor(i)` for the kit's own ramp. */\n color: string;\n /**\n * What the entry's mark looks like. `swatch` — a filled square, the default — says\n * WHICH MEASUREMENT. `stroke` says WHICH QUANTITY, for the charts that carry both at\n * once and tell them apart by colour and by dash. `dot` is a round mark, for a\n * MARKER on the chart (a point, an event) rather than a series.\n */\n marker?: \"swatch\" | \"stroke\" | \"dot\";\n /** Which of {@link STROKE_PATTERNS}, when the marker is a stroke — the same index\n * `SeriesChartSeries.dash` takes, so a legend cannot promise a dot-dash the plot\n * draws dashed. Or the same custom `stroke-dasharray` string the series draws with\n * (keksdose's `\"4 3\"`). */\n dash?: number | string;\n /**\n * A mark of the caller's own, drawn in place of {@link marker} — for a key whose\n * mark is not a colour at all (a fading bar for \"open-ended\", a hairline for\n * \"today\"). Decorative: it is wrapped `aria-hidden`, and the label is the name.\n */\n icon?: ReactNode;\n /**\n * `\"end\"`: push this entry to the legend's inline END — the far right in LTR, the far\n * left in RTL — with everything before it kept at the start. kastlan's lease gantt\n * (feedback #49) keys its bars at the start and its \"today\" hairline at the end, over\n * the time axis whose end \"today\" is nearest, and wrote it as\n * `className=\"[&>li:last-child]:ms-auto\"` — a selector that breaks the moment the\n * entries are reordered and that reaches into the legend's markup.\n *\n * An auto inline-start margin, so it is logical (RTL mirrors it) and it takes only the\n * row's LEFTOVER space: on a narrow screen where the row wraps, the entry wraps with it\n * and sits at the end of its own line rather than overflowing. Give it to the LAST\n * entry — auto margins push everything after them too, so an end entry in the middle\n * drags the rest over with it (which is also how to end-align a GROUP: mark its first).\n * In a vertical legend it sits at the column's inline end. Honoured by both\n * {@link StaticLegend} and {@link ToggleLegend}, which share this entry type.\n */\n align?: \"start\" | \"end\";\n}\n\nexport interface ToggleLegendProps {\n entries: LegendEntry[];\n /** The keys currently off the chart. */\n hidden: ReadonlySet<string>;\n onToggle: (key: string) => void;\n /** `vertical` is for a legend standing BESIDE the charts rather than under them —\n * what a row of charts sharing one legend wants, since under two charts there is\n * no \"under\", and putting it under one says it belongs to that one. */\n orientation?: \"horizontal\" | \"vertical\";\n /**\n * Draw a legend of ONE entry rather than nothing.\n *\n * A single line's legend is usually noise. It is not where the legend is the only\n * SWITCH that line has — a series that starts hidden and has no entry to bring it\n * back is gone for good.\n */\n showSingle?: boolean;\n className?: string;\n /** Per-instance strings over `<UiKitProvider labels={{ seriesChart }}>`. */\n labels?: Partial<SeriesChartLabels>;\n}\n\n/**\n * A legend whose entries are switches.\n *\n * `ChartLegendContent` with `onItemClick`/`activeKey` is the other kind: clicking an\n * entry HIGHLIGHTS it and dims the rest, which is right when every series belongs on\n * the chart and one of them is momentarily interesting. This is for the opposite —\n * three coordinates on one axis where y runs to 800 and z barely moves, and the only\n * way to see z is to take y off the chart entirely. Any number may be off at once.\n *\n * A hidden entry keeps its mark and its place. Removing it would reflow the legend on\n * every click and lose the one thing it is for: saying what COULD be shown.\n *\n * Each entry is a real `<button>` with `aria-pressed` — pressed means \"on the chart\" —\n * so Tab reaches every switch and Space/Enter flips it.\n */\nexport function ToggleLegend({\n entries,\n hidden,\n onToggle,\n orientation = \"horizontal\",\n showSingle = false,\n className,\n labels: labelsProp,\n}: ToggleLegendProps) {\n const labels = useKitLabels(\"seriesChart\", DEFAULT_SERIES_CHART_LABELS, labelsProp);\n if (entries.length < (showSingle ? 1 : 2)) return null;\n return (\n <div\n role=\"group\"\n aria-label={labels.legend}\n className={cn(\n \"flex gap-x-3 gap-y-1\",\n orientation === \"vertical\"\n ? \"flex-col items-start justify-center\"\n : \"mt-2 flex-wrap items-center\",\n className,\n )}\n >\n {entries.map((entry) => {\n const off = hidden.has(entry.key);\n return (\n <button\n key={entry.key}\n type=\"button\"\n // Pressed rather than a checkbox: it is a control over what the chart\n // draws, and \"not pressed\" is the same sentence the dimmed mark says.\n aria-pressed={!off}\n onClick={() => onToggle(entry.key)}\n className={cn(\n \"flex items-center gap-1.5 rounded text-start text-[11px] text-[var(--text-secondary)] transition-opacity hover:opacity-80\",\n \"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--brand)]\",\n off && \"opacity-35\",\n entry.align === \"end\" && \"ms-auto\",\n )}\n >\n <LegendMark entry={entry} off={off} />\n {entry.label}\n </button>\n );\n })}\n </div>\n );\n}\n\nexport interface StaticLegendProps {\n entries: LegendEntry[];\n /** See {@link ToggleLegendProps.orientation}. */\n orientation?: \"horizontal\" | \"vertical\";\n /** The list's accessible name. Default: the `seriesChart.legend` label. */\n \"aria-label\"?: string;\n className?: string;\n /** Per-instance strings over `<UiKitProvider labels={{ seriesChart }}>`. */\n labels?: Partial<SeriesChartLabels>;\n}\n\n/**\n * A legend that is a KEY, not a control: the same entries and marks as\n * {@link ToggleLegend} — swatch, stroke (with the chart's own dash), dot, or a mark of\n * the caller's own — but nothing to press.\n *\n * A separate component rather than `ToggleLegend` without `onToggle`, because the two\n * are different things to a screen reader: a group of switches announces a pressed\n * state on every entry, a key is a LIST, read as \"list, 4 items\" and walked with the\n * list keys, and costs no tab stops. The apps drew this by hand under the charts that\n * say what a colour or a dash means without letting you switch it (kastlan's lease\n * timeline, keksdose's cash buffer).\n *\n * Unlike `ToggleLegend` it draws a single entry: a key with one line still says what\n * the one mark on the chart means.\n */\nexport function StaticLegend({\n entries,\n orientation = \"horizontal\",\n \"aria-label\": ariaLabel,\n className,\n labels: labelsProp,\n}: StaticLegendProps) {\n const labels = useKitLabels(\"seriesChart\", DEFAULT_SERIES_CHART_LABELS, labelsProp);\n if (entries.length === 0) return null;\n return (\n <ul\n aria-label={ariaLabel ?? labels.legend}\n className={cn(\n \"m-0 flex list-none gap-x-3 gap-y-1 p-0\",\n orientation === \"vertical\"\n ? \"flex-col items-start justify-center\"\n : \"mt-2 flex-wrap items-center\",\n className,\n )}\n >\n {entries.map((entry) => (\n <li\n key={entry.key}\n className={cn(\n \"flex items-center gap-1.5 text-[11px] text-[var(--text-secondary)]\",\n entry.align === \"end\" && \"ms-auto\",\n )}\n >\n <LegendMark entry={entry} off={false} />\n {entry.label}\n </li>\n ))}\n </ul>\n );\n}\n\n/**\n * The column a vertical legend stands in: beside the charts, on their horizontal\n * centre line. `h-full` + `justify-center`, so it centres in a grid cell or a flex row\n * that stretches it — and stacks whatever it is given, which is what a panel showing\n * two legends at once needs. The width is the caller's: how wide a legend column is\n * is a fact about that screen's layout.\n */\nexport function LegendColumn({ children, className }: { children: ReactNode; className?: string }) {\n return (\n <div className={cn(\"flex h-full flex-col justify-center gap-3\", className)}>{children}</div>\n );\n}\n\n/**\n * A legend and what it is a legend OF, as a headed column.\n *\n * For legends that are several vocabularies at once — which measurement and which\n * channel — so the entries are read down a group and the groups across. Wrapped rows\n * would put the second half of one group on a line under the first half of the next.\n */\nexport function LegendGroup({ title, children }: { title: ReactNode; children: ReactNode }) {\n return (\n <div className=\"flex min-w-0 flex-col items-start gap-1\">\n <span className=\"text-[10px] font-semibold uppercase tracking-wide text-[var(--text-muted)]\">\n {title}\n </span>\n <div className=\"flex flex-col items-start gap-y-0.5\">{children}</div>\n </div>\n );\n}\n\n/** The entry's mark: a square for a measurement, a stroke for a quantity. A hidden one\n * keeps its outline — a mark that vanished would leave a line of text with nothing in\n * front of it.\n *\n * A stroke is an SVG line with the chart's own `strokeDasharray`, not a CSS gradient\n * approximating it: a gradient can say \"solid or dashed\" and nothing more.\n *\n * A hidden stroke is NOT faded here: the button around it already is (`opacity-35`),\n * and the line used to take its own 0.35 on top — 0.35 × 0.35, about 12 %, a mark\n * gone rather than dimmed, while the square beside it read at the full 35 %. */\nfunction LegendMark({ entry, off }: { entry: LegendEntry; off: boolean }) {\n if (entry.icon != null) {\n return (\n <span aria-hidden className=\"inline-flex shrink-0 items-center\">\n {entry.icon}\n </span>\n );\n }\n if (entry.marker === \"dot\") {\n return (\n <span\n aria-hidden\n className=\"size-2 shrink-0 rounded-full\"\n style={{\n backgroundColor: off ? \"transparent\" : entry.color,\n boxShadow: `inset 0 0 0 1.5px ${entry.color}`,\n }}\n />\n );\n }\n if (entry.marker === \"stroke\") {\n return (\n <svg aria-hidden viewBox=\"0 0 20 2\" className=\"h-0.5 w-5 shrink-0 overflow-visible\">\n <line\n x1={0}\n y1={1}\n x2={20}\n y2={1}\n stroke={entry.color}\n strokeWidth={2}\n strokeDasharray={typeof entry.dash === \"string\" ? entry.dash : strokeDash(entry.dash ?? 0)}\n />\n </svg>\n );\n }\n return (\n <span\n aria-hidden\n className=\"h-2.5 w-2.5 shrink-0 rounded-[3px]\"\n style={{\n backgroundColor: off ? \"transparent\" : entry.color,\n boxShadow: `inset 0 0 0 1.5px ${entry.color}`,\n }}\n />\n );\n}\n"],"mappings":";AAuKU,SAcE,KAdF;AAhKV,SAAS,UAAU;AACnB,SAAS,oBAAoB;AAC7B,SAAS,mCAA2D;AAkB7D,MAAM,kBAAmD;AAAA,EAC9D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAGO,SAAS,WAAW,OAAmC;AAC5D,QAAM,IAAI,gBAAgB;AAC1B,SAAO,iBAAkB,KAAK,MAAM,KAAK,IAAI,IAAK,KAAK,CAAC;AAC1D;AAQO,MAAM,YAAY;AASlB,SAAS,aAAa,QAA6B,KAAkC;AAC1F,QAAM,OAAO,IAAI,IAAI,MAAM;AAC3B,MAAI,CAAC,KAAK,OAAO,GAAG,EAAG,MAAK,IAAI,GAAG;AACnC,SAAO;AACT;AAiFO,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA,cAAc;AAAA,EACd,aAAa;AAAA,EACb;AAAA,EACA,QAAQ;AACV,GAAsB;AACpB,QAAM,SAAS,aAAa,eAAe,6BAA6B,UAAU;AAClF,M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@@ interface TooltipProps extends ComponentPropsWithoutRef<"span"> {
31
31
  * what they were before the default existed.
32
32
  */
33
33
  portal?: boolean;
34
+ /**
35
+ * Mount the IN-PLACE bubble only while it is up (hovered or focused, not dismissed),
36
+ * instead of always. It still sits next to its trigger and is still placed by CSS
37
+ * alone; what changes is that, while closed, it is not in the DOM — so it is not in
38
+ * `getAllByRole("tooltip")`, not in an ancestor's `textContent` and not in an
39
+ * ancestor's accessible name. The trigger is described (`aria-describedby`) while
40
+ * the bubble is up, exactly as a portalled one is. See "Lazy in place" on
41
+ * {@link Tooltip} for why this exists (keksdose F6) and why it is not the default.
42
+ *
43
+ * Has no effect on a bubble that is portalled (`portal`, or auto-portalled inside a
44
+ * clipping container) — that one is already mounted only while up.
45
+ */
46
+ lazy?: boolean;
34
47
  /** Tag the bubble `data-private`, for a label that repeats the user's own data. */
35
48
  redact?: boolean;
36
49
  children: ReactNode;
@@ -109,8 +122,45 @@ interface TooltipProps extends ComponentPropsWithoutRef<"span"> {
109
122
  * Why not simply portal everything? Because the in-place bubble is the one existing
110
123
  * app tests rely on (it is in the DOM without a hover), and because it follows its
111
124
  * trigger through a scroll or an animation for free — the portalled one re-measures.
125
+ *
126
+ * ⚠️ **Lazy in place: `lazy` keeps the bubble next to its trigger but out of the DOM
127
+ * until it is up (keksdose F6).** `data-clips` cured the doubled text for tooltips
128
+ * inside a table; it did nothing for the ones outside any clipping container, where the
129
+ * always-mounted bubble is still a real `role="tooltip"` node full of text. About seven
130
+ * keksdose sites — column-header tooltips, a direction toggle, an fx-estimate row, a
131
+ * FlagBadge, a toast inside a `<button>` — still pinned `portal` for that alone: their
132
+ * tests found two tooltips with `getAllByRole("tooltip")`, read the label twice in a
133
+ * `textContent`, or got a button whose accessible name had the bubble's sentence glued
134
+ * on. `portal` fixed the test and cost the browser the measured, re-positioning bubble
135
+ * for no reason. `lazy` is the in-place bubble with the portalled one's lifetime: it is
136
+ * rendered only while hovered or focused (and not dismissed), in the same slot, with the
137
+ * same classes, so it looks and sits exactly as the default one does when it is up.
138
+ *
139
+ * Why unmount rather than hide? Hiding was the other option — keep the bubble mounted
140
+ * with `hidden` (or `aria-hidden` plus `display: none` until `:hover` / `:focus-within`)
141
+ * and let `aria-describedby` go on pointing at it, which the accname algorithm allows:
142
+ * a node referenced directly by `aria-describedby` contributes its text even while
143
+ * hidden. That would take the bubble out of the role queries and out of an ancestor's
144
+ * accessible name — but NOT out of `textContent`, which is plain DOM and counts hidden
145
+ * text too, and `textContent` is one of the three things F6 lists. Only a bubble that
146
+ * is not there solves all three. The cost is the portalled variant's: the trigger is
147
+ * described while the bubble is up rather than always. Focusing the trigger IS what
148
+ * puts it up, and React commits the `aria-describedby` in the same task as that focus
149
+ * event, so a screen reader landing on the control still hears it; what goes is the description
150
+ * of a trigger that is read in browse mode without ever being focused.
151
+ *
152
+ * Escape still dismisses it — here by unmounting it, which takes it off the screen and
153
+ * out of the accessibility tree at once — and the next hover or focus brings it back.
154
+ * There is no fade to lose: neither in-place bubble has ever had a transition, only the
155
+ * `opacity` switch, so appearing on a state change looks the same as appearing on
156
+ * `:hover`.
157
+ *
158
+ * Why opt-in rather than the new default? Because the always-mounted bubble is the one
159
+ * existing app tests find without a hover (see above): flipping it would turn every
160
+ * `getByRole("tooltip")` written against 0.12 into a failure in all three apps at once.
161
+ * Reach for `lazy` wherever a `portal` was pinned only to keep a test's DOM clean.
112
162
  */
113
- declare function Tooltip({ label, side, className, portal, redact, children, ...rest }: TooltipProps): react.JSX.Element;
163
+ declare function Tooltip({ label, side, className, portal, lazy, redact, children, ...rest }: TooltipProps): react.JSX.Element;
114
164
  interface TooltipSize {
115
165
  width: number;
116
166
  height: number;