@jcsoftdev/ui 0.5.0 → 0.6.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 (373) hide show
  1. package/CHANGELOG.md +337 -0
  2. package/README.md +25 -3
  3. package/bin/ui-theme.mjs +40 -6
  4. package/dist/ai/code-block/code-block.js +1 -1
  5. package/dist/atoms/big-date/big-date.js +2 -2
  6. package/dist/atoms/button/button.d.ts +6 -1
  7. package/dist/atoms/button/button.js +2 -2
  8. package/dist/atoms/chip/chip.d.ts +5 -0
  9. package/dist/atoms/chip/chip.js +3 -3
  10. package/dist/atoms/icon-button/icon-button.js +1 -1
  11. package/dist/atoms/internal/hit-area.d.ts +5 -4
  12. package/dist/atoms/internal/hit-area.js +1 -1
  13. package/dist/atoms/progress/index.d.ts +1 -1
  14. package/dist/atoms/progress/index.js +4 -1
  15. package/dist/atoms/progress/progress.d.ts +6 -1
  16. package/dist/atoms/progress/progress.js +19 -1
  17. package/dist/atoms/radio-group/radio-group.js +1 -1
  18. package/dist/atoms/status-pill/status-pill.d.ts +16 -5
  19. package/dist/atoms/status-pill/status-pill.js +43 -18
  20. package/dist/brand/logo-forge.js +1 -1
  21. package/dist/charts/candlestick-chart/candlestick-chart.js +2 -2
  22. package/dist/charts/chart-grid/chart-grid.js +2 -2
  23. package/dist/charts/chord-chart/chord-chart.js +1 -1
  24. package/dist/charts/core/axes.js +2 -2
  25. package/dist/charts/core/cartesian/annotations.js +2 -2
  26. package/dist/charts/core/cartesian/marks.js +1 -1
  27. package/dist/charts/core/distribution/marks.js +1 -1
  28. package/dist/charts/core/distribution/xy-points.js +1 -1
  29. package/dist/charts/core/export-menu.js +1 -1
  30. package/dist/charts/funnel-chart/funnel-chart.js +1 -1
  31. package/dist/charts/gantt-chart/gantt-chart.js +4 -4
  32. package/dist/charts/gantt-chart/gantt-marks.js +3 -3
  33. package/dist/charts/index.d.ts +2 -0
  34. package/dist/charts/index.js +2 -0
  35. package/dist/charts/maps/geo/map-data-table.js +1 -1
  36. package/dist/charts/polar-area-chart/polar-area-chart.js +1 -1
  37. package/dist/charts/radar-chart/radar-chart.js +1 -1
  38. package/dist/charts/stock-chart/stock-chart.js +1 -1
  39. package/dist/charts/stock-chart/stock-drawing-layer.js +3 -3
  40. package/dist/charts/stock-chart/stock-plot.js +2 -2
  41. package/dist/containers/chat-thread/chat-thread.d.ts +98 -0
  42. package/dist/containers/chat-thread/chat-thread.js +219 -0
  43. package/dist/containers/chat-thread/format.d.ts +20 -0
  44. package/dist/containers/chat-thread/format.js +50 -0
  45. package/dist/containers/chat-thread/index.d.ts +1 -0
  46. package/dist/containers/chat-thread/index.js +8 -0
  47. package/dist/containers/cols/cols.d.ts +1 -1
  48. package/dist/containers/cols/cols.js +7 -0
  49. package/dist/containers/comment/comment.js +1 -1
  50. package/dist/containers/context-rail/context-rail.d.ts +62 -0
  51. package/dist/containers/context-rail/context-rail.js +175 -0
  52. package/dist/containers/context-rail/index.d.ts +1 -0
  53. package/dist/containers/context-rail/index.js +6 -0
  54. package/dist/containers/dashboard/dashboard.d.ts +40 -0
  55. package/dist/containers/dashboard/dashboard.js +84 -0
  56. package/dist/containers/dashboard/index.d.ts +1 -0
  57. package/dist/containers/dashboard/index.js +14 -0
  58. package/dist/containers/data-grid/data-grid.demos.js +4 -4
  59. package/dist/containers/data-grid/data-grid.js +6 -6
  60. package/dist/containers/data-grid/filter-builder-editor.js +2 -2
  61. package/dist/containers/data-grid/grid-toolbar.js +1 -1
  62. package/dist/containers/data-grid/spreadsheet.demos.d.ts +1 -1
  63. package/dist/containers/data-grid/spreadsheet.demos.js +1 -1
  64. package/dist/containers/detail-header/detail-header.d.ts +24 -0
  65. package/dist/containers/detail-header/detail-header.js +32 -0
  66. package/dist/containers/detail-header/index.d.ts +1 -0
  67. package/dist/containers/detail-header/index.js +6 -0
  68. package/dist/containers/facts/facts.js +1 -1
  69. package/dist/containers/filter-bar/filter-bar.d.ts +58 -0
  70. package/dist/containers/filter-bar/filter-bar.js +123 -0
  71. package/dist/containers/filter-bar/index.d.ts +1 -0
  72. package/dist/containers/filter-bar/index.js +6 -0
  73. package/dist/containers/hbars/hbars.js +2 -2
  74. package/dist/containers/index.d.ts +9 -0
  75. package/dist/containers/index.js +9 -0
  76. package/dist/containers/kanban/kanban.d.ts +23 -2
  77. package/dist/containers/kanban/kanban.js +101 -21
  78. package/dist/containers/kanban/model.d.ts +12 -0
  79. package/dist/containers/kanban/model.js +8 -0
  80. package/dist/containers/kpi/kpi.js +1 -1
  81. package/dist/containers/kpi-group/kpi-group.d.ts +6 -1
  82. package/dist/containers/kpi-group/kpi-group.js +6 -2
  83. package/dist/containers/list-detail/index.d.ts +1 -1
  84. package/dist/containers/list-detail/index.js +4 -0
  85. package/dist/containers/list-detail/list-detail.d.ts +51 -3
  86. package/dist/containers/list-detail/list-detail.js +109 -15
  87. package/dist/containers/page/page.d.ts +17 -4
  88. package/dist/containers/page/page.js +33 -4
  89. package/dist/containers/page-header/back.d.ts +10 -0
  90. package/dist/containers/page-header/back.js +28 -0
  91. package/dist/containers/page-header/index.d.ts +1 -0
  92. package/dist/containers/page-header/index.js +1 -0
  93. package/dist/containers/page-header/page-header.d.ts +19 -2
  94. package/dist/containers/page-header/page-header.js +26 -2
  95. package/dist/containers/pagination/cursor-pagination.d.ts +28 -0
  96. package/dist/containers/pagination/cursor-pagination.js +48 -0
  97. package/dist/containers/pagination/index.d.ts +3 -0
  98. package/dist/containers/pagination/index.js +10 -0
  99. package/dist/containers/pagination/pagination.d.ts +52 -0
  100. package/dist/containers/pagination/pagination.js +216 -0
  101. package/dist/containers/pagination/range.d.ts +29 -0
  102. package/dist/containers/pagination/range.js +42 -0
  103. package/dist/containers/pagination/use-pagination.d.ts +18 -0
  104. package/dist/containers/pagination/use-pagination.js +22 -0
  105. package/dist/containers/responsive-list/responsive-list.d.ts +28 -2
  106. package/dist/containers/responsive-list/responsive-list.js +134 -25
  107. package/dist/containers/row-actions/index.d.ts +1 -0
  108. package/dist/containers/row-actions/index.js +4 -0
  109. package/dist/containers/row-actions/row-actions.d.ts +26 -0
  110. package/dist/containers/row-actions/row-actions.js +78 -0
  111. package/dist/containers/selectable-card/index.d.ts +1 -0
  112. package/dist/containers/selectable-card/index.js +6 -0
  113. package/dist/containers/selectable-card/selectable-card.d.ts +26 -0
  114. package/dist/containers/selectable-card/selectable-card.js +57 -0
  115. package/dist/containers/settings-layout/settings-layout.d.ts +24 -7
  116. package/dist/containers/settings-layout/settings-layout.js +63 -8
  117. package/dist/containers/shortcuts/shortcuts.js +1 -1
  118. package/dist/containers/table/cell-padding.d.ts +2 -0
  119. package/dist/containers/table/cell-padding.js +4 -0
  120. package/dist/containers/table/index.d.ts +1 -0
  121. package/dist/containers/table/index.js +8 -0
  122. package/dist/containers/table/sort.d.ts +14 -0
  123. package/dist/containers/table/sort.js +11 -0
  124. package/dist/containers/table/table-parts.d.ts +24 -0
  125. package/dist/containers/table/table-parts.js +52 -0
  126. package/dist/containers/table/table.d.ts +37 -3
  127. package/dist/containers/table/table.js +120 -19
  128. package/dist/containers/table-columns-menu/index.d.ts +1 -0
  129. package/dist/containers/table-columns-menu/index.js +6 -0
  130. package/dist/containers/table-columns-menu/table-columns-menu.d.ts +14 -0
  131. package/dist/containers/table-columns-menu/table-columns-menu.js +46 -0
  132. package/dist/dashboards/layout.d.ts +1 -27
  133. package/dist/dashboards/layout.js +8 -40
  134. package/dist/forms/chip-group/chip-group.d.ts +5 -0
  135. package/dist/forms/chip-group/chip-group.js +3 -1
  136. package/dist/forms/combobox/combobox.js +1 -1
  137. package/dist/forms/copy-field/copy-field.js +1 -1
  138. package/dist/forms/date-picker/date-picker.d.ts +3 -1
  139. package/dist/forms/date-picker/date-picker.js +4 -2
  140. package/dist/forms/date-picker/date-time-picker.d.ts +8 -2
  141. package/dist/forms/date-picker/date-time-picker.js +13 -2
  142. package/dist/forms/field/field.d.ts +9 -2
  143. package/dist/forms/field/field.js +18 -4
  144. package/dist/forms/fieldset/fieldset.d.ts +11 -0
  145. package/dist/forms/fieldset/fieldset.js +12 -0
  146. package/dist/forms/fieldset/index.d.ts +1 -0
  147. package/dist/forms/fieldset/index.js +4 -0
  148. package/dist/forms/form-footer/form-footer.d.ts +26 -0
  149. package/dist/forms/form-footer/form-footer.js +44 -0
  150. package/dist/forms/form-footer/index.d.ts +1 -0
  151. package/dist/forms/form-footer/index.js +4 -0
  152. package/dist/forms/form-grid/form-grid.d.ts +21 -4
  153. package/dist/forms/form-grid/form-grid.js +20 -3
  154. package/dist/forms/form-grid/index.d.ts +1 -1
  155. package/dist/forms/form-grid/index.js +6 -2
  156. package/dist/forms/form-section/form-section.d.ts +12 -0
  157. package/dist/forms/form-section/form-section.js +30 -0
  158. package/dist/forms/form-section/index.d.ts +1 -0
  159. package/dist/forms/form-section/index.js +4 -0
  160. package/dist/forms/index.d.ts +3 -0
  161. package/dist/forms/index.js +3 -0
  162. package/dist/forms/input/input.d.ts +6 -2
  163. package/dist/forms/input/input.js +4 -1
  164. package/dist/forms/internal/listbox-items.d.ts +1 -1
  165. package/dist/forms/internal/listbox-items.js +3 -2
  166. package/dist/forms/native-select/native-select.js +1 -1
  167. package/dist/forms/select/index.d.ts +1 -1
  168. package/dist/forms/select/select.d.ts +5 -2
  169. package/dist/forms/select/select.js +7 -2
  170. package/dist/forms/select-menu/select-menu.js +1 -1
  171. package/dist/forms/time-input/time-input.d.ts +4 -2
  172. package/dist/forms/time-input/time-input.js +3 -1
  173. package/dist/i18n/strings.d.ts +86 -0
  174. package/dist/i18n/strings.js +46 -0
  175. package/dist/motion/count-up.d.ts +20 -0
  176. package/dist/motion/count-up.js +59 -0
  177. package/dist/motion/cross-fade.d.ts +21 -0
  178. package/dist/motion/cross-fade.js +86 -0
  179. package/dist/motion/index.d.ts +5 -0
  180. package/dist/motion/index.js +14 -0
  181. package/dist/motion/model.d.ts +15 -0
  182. package/dist/motion/model.js +68 -0
  183. package/dist/motion/motion-styles.d.ts +1 -0
  184. package/dist/motion/motion-styles.js +35 -0
  185. package/dist/motion/reveal.d.ts +37 -0
  186. package/dist/motion/reveal.js +69 -0
  187. package/dist/motion/use-enter-phase.d.ts +11 -0
  188. package/dist/motion/use-enter-phase.js +40 -0
  189. package/dist/motion/use-highlight-row.d.ts +22 -0
  190. package/dist/motion/use-highlight-row.js +38 -0
  191. package/dist/navigation/tabs/tabs.js +1 -1
  192. package/dist/navigation/wizard/wizard.d.ts +4 -1
  193. package/dist/navigation/wizard/wizard.js +3 -0
  194. package/dist/overlays/alert-dialog/alert-dialog.js +8 -1
  195. package/dist/overlays/context-menu/context-menu.js +3 -1
  196. package/dist/overlays/dialog/dialog.js +10 -2
  197. package/dist/overlays/drawer/drawer.d.ts +18 -4
  198. package/dist/overlays/drawer/drawer.js +53 -4
  199. package/dist/overlays/drawer/index.d.ts +1 -1
  200. package/dist/overlays/dropdown-menu/dropdown-menu.d.ts +1 -1
  201. package/dist/overlays/dropdown-menu/dropdown-menu.js +5 -4
  202. package/dist/overlays/hover-card/hover-card.js +2 -0
  203. package/dist/overlays/popover/popover.js +2 -0
  204. package/dist/overlays/toaster/index.d.ts +1 -1
  205. package/dist/overlays/toaster/toaster.d.ts +28 -2
  206. package/dist/overlays/toaster/toaster.js +73 -29
  207. package/dist/overlays/tooltip/tooltip.js +2 -0
  208. package/dist/primitives/use-presence.js +9 -0
  209. package/dist/shell/app-shell/app-shell.d.ts +8 -1
  210. package/dist/shell/app-shell/app-shell.js +50 -3
  211. package/dist/shell/index.d.ts +1 -0
  212. package/dist/shell/index.js +1 -0
  213. package/dist/shell/sidebar/sidebar.d.ts +17 -1
  214. package/dist/shell/sidebar/sidebar.js +126 -76
  215. package/dist/shell/topbar/topbar.d.ts +4 -2
  216. package/dist/shell/topbar/topbar.js +2 -0
  217. package/dist/showcase/operations-bento.js +2 -2
  218. package/dist/states/empty-state/empty-state.d.ts +10 -3
  219. package/dist/states/empty-state/empty-state.js +46 -5
  220. package/dist/states/error-state/error-state.js +1 -1
  221. package/dist/states/skeleton/skeleton.js +1 -1
  222. package/dist/utils/class-tokens.generated.js +4 -6
  223. package/dist/utils/list-navigation.d.ts +14 -0
  224. package/dist/utils/list-navigation.js +44 -0
  225. package/dist/utils/overlay-motion.d.ts +12 -0
  226. package/dist/utils/overlay-motion.js +14 -0
  227. package/dist/utils/use-container-width.d.ts +6 -0
  228. package/dist/utils/use-container-width.js +19 -0
  229. package/package.json +2 -2
  230. package/scripts/build-theme.mjs +46 -5
  231. package/src/ai/code-block/code-block.tsx +1 -1
  232. package/src/atoms/big-date/big-date.tsx +2 -2
  233. package/src/atoms/button/button.tsx +8 -3
  234. package/src/atoms/chip/chip.tsx +8 -3
  235. package/src/atoms/icon-button/icon-button.tsx +1 -1
  236. package/src/atoms/internal/hit-area.ts +5 -4
  237. package/src/atoms/progress/index.ts +8 -1
  238. package/src/atoms/progress/progress.tsx +30 -1
  239. package/src/atoms/radio-group/radio-group.tsx +1 -1
  240. package/src/atoms/status-pill/status-pill.tsx +59 -18
  241. package/src/brand/logo-forge.tsx +1 -1
  242. package/src/charts/candlestick-chart/candlestick-chart.tsx +2 -2
  243. package/src/charts/chart-grid/chart-grid.tsx +2 -2
  244. package/src/charts/chord-chart/chord-chart.tsx +1 -1
  245. package/src/charts/core/axes.tsx +2 -2
  246. package/src/charts/core/cartesian/annotations.tsx +2 -2
  247. package/src/charts/core/cartesian/marks.tsx +1 -1
  248. package/src/charts/core/distribution/marks.tsx +1 -1
  249. package/src/charts/core/distribution/xy-points.tsx +1 -1
  250. package/src/charts/core/export-menu.tsx +1 -1
  251. package/src/charts/funnel-chart/funnel-chart.tsx +1 -1
  252. package/src/charts/gantt-chart/gantt-chart.tsx +4 -4
  253. package/src/charts/gantt-chart/gantt-marks.tsx +3 -3
  254. package/src/charts/index.ts +2 -0
  255. package/src/charts/maps/geo/map-data-table.tsx +1 -1
  256. package/src/charts/polar-area-chart/polar-area-chart.tsx +1 -1
  257. package/src/charts/radar-chart/radar-chart.tsx +1 -1
  258. package/src/charts/stock-chart/stock-chart.tsx +1 -1
  259. package/src/charts/stock-chart/stock-drawing-layer.tsx +3 -3
  260. package/src/charts/stock-chart/stock-plot.tsx +2 -2
  261. package/src/containers/chat-thread/chat-thread.tsx +331 -0
  262. package/src/containers/chat-thread/format.ts +67 -0
  263. package/src/containers/chat-thread/index.ts +12 -0
  264. package/src/containers/cols/cols.tsx +13 -1
  265. package/src/containers/comment/comment.tsx +1 -1
  266. package/src/containers/context-rail/context-rail.tsx +229 -0
  267. package/src/containers/context-rail/index.ts +7 -0
  268. package/src/containers/dashboard/dashboard.tsx +142 -0
  269. package/src/containers/dashboard/index.ts +12 -0
  270. package/src/containers/data-grid/data-grid.demos.tsx +4 -4
  271. package/src/containers/data-grid/data-grid.tsx +6 -6
  272. package/src/containers/data-grid/filter-builder-editor.tsx +2 -2
  273. package/src/containers/data-grid/grid-toolbar.tsx +1 -1
  274. package/src/containers/data-grid/spreadsheet.demos.tsx +1 -1
  275. package/src/containers/detail-header/detail-header.tsx +64 -0
  276. package/src/containers/detail-header/index.ts +5 -0
  277. package/src/containers/facts/facts.tsx +1 -1
  278. package/src/containers/filter-bar/filter-bar.tsx +201 -0
  279. package/src/containers/filter-bar/index.ts +7 -0
  280. package/src/containers/hbars/hbars.tsx +2 -2
  281. package/src/containers/index.ts +9 -0
  282. package/src/containers/kanban/kanban.tsx +146 -39
  283. package/src/containers/kanban/model.ts +20 -0
  284. package/src/containers/kpi/kpi.tsx +1 -1
  285. package/src/containers/kpi-group/kpi-group.tsx +17 -2
  286. package/src/containers/list-detail/index.ts +5 -0
  287. package/src/containers/list-detail/list-detail.tsx +157 -9
  288. package/src/containers/page/page.tsx +61 -7
  289. package/src/containers/page-header/back.tsx +42 -0
  290. package/src/containers/page-header/index.ts +1 -0
  291. package/src/containers/page-header/page-header.tsx +49 -3
  292. package/src/containers/pagination/cursor-pagination.tsx +79 -0
  293. package/src/containers/pagination/index.ts +7 -0
  294. package/src/containers/pagination/pagination.tsx +266 -0
  295. package/src/containers/pagination/range.ts +68 -0
  296. package/src/containers/pagination/use-pagination.ts +44 -0
  297. package/src/containers/responsive-list/responsive-list.tsx +183 -46
  298. package/src/containers/row-actions/index.ts +1 -0
  299. package/src/containers/row-actions/row-actions.tsx +114 -0
  300. package/src/containers/selectable-card/index.ts +5 -0
  301. package/src/containers/selectable-card/selectable-card.tsx +84 -0
  302. package/src/containers/settings-layout/settings-layout.tsx +104 -13
  303. package/src/containers/shortcuts/shortcuts.tsx +1 -1
  304. package/src/containers/table/cell-padding.ts +2 -0
  305. package/src/containers/table/index.ts +6 -0
  306. package/src/containers/table/sort.ts +23 -0
  307. package/src/containers/table/table-parts.tsx +81 -0
  308. package/src/containers/table/table.tsx +212 -45
  309. package/src/containers/table-columns-menu/index.ts +5 -0
  310. package/src/containers/table-columns-menu/table-columns-menu.tsx +68 -0
  311. package/src/dashboards/layout.tsx +8 -75
  312. package/src/forms/chip-group/chip-group.tsx +8 -1
  313. package/src/forms/combobox/combobox.tsx +1 -1
  314. package/src/forms/copy-field/copy-field.tsx +1 -1
  315. package/src/forms/date-picker/date-picker.tsx +7 -2
  316. package/src/forms/date-picker/date-time-picker.tsx +28 -2
  317. package/src/forms/field/field.tsx +30 -3
  318. package/src/forms/fieldset/fieldset.tsx +22 -0
  319. package/src/forms/fieldset/index.ts +1 -0
  320. package/src/forms/form-footer/form-footer.tsx +74 -0
  321. package/src/forms/form-footer/index.ts +1 -0
  322. package/src/forms/form-grid/form-grid.tsx +42 -5
  323. package/src/forms/form-grid/index.ts +8 -1
  324. package/src/forms/form-section/form-section.tsx +41 -0
  325. package/src/forms/form-section/index.ts +1 -0
  326. package/src/forms/index.ts +3 -0
  327. package/src/forms/input/input.tsx +10 -3
  328. package/src/forms/internal/listbox-items.tsx +3 -4
  329. package/src/forms/native-select/native-select.tsx +1 -1
  330. package/src/forms/select/index.ts +1 -1
  331. package/src/forms/select/select.tsx +14 -3
  332. package/src/forms/select-menu/select-menu.tsx +1 -1
  333. package/src/forms/time-input/time-input.tsx +6 -2
  334. package/src/i18n/strings.ts +86 -0
  335. package/src/motion/count-up.tsx +83 -0
  336. package/src/motion/cross-fade.tsx +139 -0
  337. package/src/motion/index.ts +5 -0
  338. package/src/motion/model.ts +86 -0
  339. package/src/motion/motion-styles.tsx +47 -0
  340. package/src/motion/reveal.tsx +115 -0
  341. package/src/motion/use-enter-phase.ts +50 -0
  342. package/src/motion/use-highlight-row.ts +63 -0
  343. package/src/navigation/tabs/tabs.tsx +1 -1
  344. package/src/navigation/wizard/wizard.tsx +6 -1
  345. package/src/overlays/alert-dialog/alert-dialog.tsx +5 -1
  346. package/src/overlays/context-menu/context-menu.tsx +3 -2
  347. package/src/overlays/dialog/dialog.tsx +7 -2
  348. package/src/overlays/drawer/drawer.tsx +68 -6
  349. package/src/overlays/drawer/index.ts +1 -0
  350. package/src/overlays/dropdown-menu/dropdown-menu.tsx +5 -4
  351. package/src/overlays/hover-card/hover-card.tsx +2 -0
  352. package/src/overlays/popover/popover.tsx +2 -0
  353. package/src/overlays/toaster/index.ts +2 -0
  354. package/src/overlays/toaster/toaster.tsx +113 -17
  355. package/src/overlays/tooltip/tooltip.tsx +2 -0
  356. package/src/primitives/use-presence.ts +13 -0
  357. package/src/shell/app-shell/app-shell.tsx +54 -2
  358. package/src/shell/index.ts +1 -0
  359. package/src/shell/sidebar/sidebar.tsx +154 -75
  360. package/src/shell/topbar/topbar.tsx +8 -0
  361. package/src/showcase/operations-bento.tsx +2 -2
  362. package/src/states/empty-state/empty-state.tsx +52 -9
  363. package/src/states/error-state/error-state.tsx +1 -1
  364. package/src/states/skeleton/skeleton.tsx +1 -1
  365. package/src/utils/class-tokens.generated.ts +4 -6
  366. package/src/utils/list-navigation.ts +63 -0
  367. package/src/utils/overlay-motion.ts +33 -0
  368. package/src/utils/use-container-width.ts +24 -0
  369. package/styles/Theme.kt +15 -18
  370. package/styles/tailwind.css +29 -28
  371. package/styles/theme.css +29 -28
  372. package/styles/tokens.css +46 -0
  373. package/tokens/default.json +51 -29
@@ -0,0 +1,2 @@
1
+ /** Vertical padding of body cells: the table density's value, or the former 11px outside a `Table`. */
2
+ export const CELL_PY = "py-[var(--table-cell-py,--spacing(2.75))]";
@@ -1 +1,7 @@
1
1
  export * from "./table.js";
2
+ export {
3
+ TableEmpty,
4
+ type TableEmptyProps,
5
+ TableLoading,
6
+ type TableLoadingProps,
7
+ } from "./table-parts.js";
@@ -0,0 +1,23 @@
1
+ export type TableSortDirection = "ascending" | "descending";
2
+
3
+ /** The sorted column and its direction. `null` stands for "not sorted". */
4
+ export interface TableSort {
5
+ columnId: string;
6
+ direction: TableSortDirection;
7
+ }
8
+
9
+ export type AriaSort = "ascending" | "descending" | "none";
10
+
11
+ /**
12
+ * Next sort when a header is activated: unsorted -> ascending -> descending -> unsorted. Activating
13
+ * another column starts it at ascending.
14
+ */
15
+ export function nextTableSort(current: TableSort | null, columnId: string): TableSort | null {
16
+ if (!current || current.columnId !== columnId) return { columnId, direction: "ascending" };
17
+ return current.direction === "ascending" ? { columnId, direction: "descending" } : null;
18
+ }
19
+
20
+ /** `aria-sort` value of a sortable header: only the sorted column reports a direction. */
21
+ export function ariaSortFor(current: TableSort | null, columnId: string): AriaSort {
22
+ return current?.columnId === columnId ? current.direction : "none";
23
+ }
@@ -0,0 +1,81 @@
1
+ "use client";
2
+
3
+ import type { ReactNode } from "react";
4
+ import { useUiStrings } from "../../i18n/index.js";
5
+ import { EmptyState } from "../../states/empty-state/empty-state.js";
6
+ import { cn } from "../../utils/cn.js";
7
+ import { CELL_PY } from "./cell-padding.js";
8
+
9
+ export interface TableEmptyProps {
10
+ /** Number of columns to span: the count of header cells. */
11
+ colSpan: number;
12
+ /** Defaults to the localized "No rows to show". */
13
+ title?: ReactNode;
14
+ description?: ReactNode;
15
+ icon?: ReactNode;
16
+ /** Call to action, e.g. a button that clears the filters. */
17
+ action?: ReactNode;
18
+ className?: string;
19
+ }
20
+
21
+ /** Single row that holds an `EmptyState` across every column. Put it in `TableBody` when there are no rows. */
22
+ export function TableEmpty({
23
+ colSpan,
24
+ title,
25
+ description,
26
+ icon,
27
+ action,
28
+ className,
29
+ }: TableEmptyProps) {
30
+ const strings = useUiStrings();
31
+ return (
32
+ <tr>
33
+ <td colSpan={colSpan} className={cn("p-0", className)}>
34
+ <EmptyState
35
+ title={title ?? strings.tableEmpty}
36
+ description={description}
37
+ icon={icon}
38
+ action={action}
39
+ />
40
+ </td>
41
+ </tr>
42
+ );
43
+ }
44
+
45
+ export interface TableLoadingProps {
46
+ /** Number of columns of the table. */
47
+ columns: number;
48
+ /** Placeholder rows. Default 5. */
49
+ rows?: number;
50
+ /** Text announced to screen readers. Defaults to the localized "Loading". */
51
+ label?: string;
52
+ }
53
+
54
+ const WIDTHS = ["w-3/4", "w-1/2", "w-2/3", "w-5/6"] as const;
55
+
56
+ /** Placeholder rows for the first load. The rows are decorative; one status region announces the load. */
57
+ export function TableLoading({ columns, rows = 5, label }: TableLoadingProps) {
58
+ const strings = useUiStrings();
59
+ return Array.from({ length: Math.max(0, rows) }, (_, row) => (
60
+ // biome-ignore lint/suspicious/noArrayIndexKey: placeholder rows have no identity
61
+ <tr key={row} aria-hidden={row === 0 ? undefined : "true"} className="border-b-divider">
62
+ {Array.from({ length: Math.max(1, columns) }, (_, column) => (
63
+ // biome-ignore lint/suspicious/noArrayIndexKey: placeholder cells have no identity
64
+ <td key={column} className={cn("px-4 align-middle @max-sm/table:px-2.5", CELL_PY)}>
65
+ {row === 0 && column === 0 ? (
66
+ <span role="status" className="sr-only">
67
+ {label ?? strings.loading}
68
+ </span>
69
+ ) : null}
70
+ <span
71
+ aria-hidden="true"
72
+ className={cn(
73
+ "block h-3 animate-pulse rounded-xs bg-surface-2",
74
+ WIDTHS[(row + column) % WIDTHS.length],
75
+ )}
76
+ />
77
+ </td>
78
+ ))}
79
+ </tr>
80
+ ));
81
+ }
@@ -9,14 +9,23 @@ import {
9
9
  useContext,
10
10
  useEffect,
11
11
  useLayoutEffect,
12
+ useMemo,
12
13
  useRef,
13
14
  useState,
14
15
  } from "react";
15
16
  import { Checkbox } from "../../atoms/checkbox/checkbox.js";
16
17
  import { useUiStrings } from "../../i18n/index.js";
17
- import { ArrowLeftToLine, ArrowRightToLine, PinOff } from "../../icons/index.js";
18
+ import {
19
+ ArrowDown,
20
+ ArrowLeftToLine,
21
+ ArrowRightToLine,
22
+ ArrowUp,
23
+ ChevronsUpDown,
24
+ PinOff,
25
+ } from "../../icons/index.js";
18
26
  import { cn } from "../../utils/cn.js";
19
27
  import { useControllableState } from "../../utils/use-controllable-state.js";
28
+ import { CELL_PY } from "./cell-padding.js";
20
29
  import {
21
30
  computePinOffsets,
22
31
  type PinnedColumns,
@@ -26,10 +35,17 @@ import {
26
35
  sanitizePinned,
27
36
  setColumnPin,
28
37
  } from "./pin.js";
29
-
30
38
  import { formatSelectRow, selectAllState, setKeys, toggleKey } from "./selection.js";
39
+ import { ariaSortFor, nextTableSort, type TableSort } from "./sort.js";
31
40
 
32
41
  export type { PinnedColumns, PinSide } from "./pin.js";
42
+ export {
43
+ type AriaSort,
44
+ ariaSortFor,
45
+ nextTableSort,
46
+ type TableSort,
47
+ type TableSortDirection,
48
+ } from "./sort.js";
33
49
 
34
50
  export interface TableLabels {
35
51
  pinLeft: string;
@@ -69,8 +85,48 @@ interface SelectionContextValue {
69
85
  /** `null` while the table has no selection props, so rows stay plain. */
70
86
  const SelectionContext = createContext<SelectionContextValue | null>(null);
71
87
 
88
+ interface SortContextValue {
89
+ sort: TableSort | null;
90
+ toggle: (columnId: string) => void;
91
+ }
92
+
93
+ /** `null` while the table has no sort props, so `sortable` headers stay plain. */
94
+ const SortContext = createContext<SortContextValue | null>(null);
95
+
96
+ /** Ids of the columns the table hides; empty by default. */
97
+ const HiddenContext = createContext<ReadonlySet<string>>(new Set());
98
+
72
99
  const FLUSH_START = "[&_:is(th,td):first-child]:pl-0 [&_td:first-child>a]:pl-0";
73
100
  const FLUSH_END = "[&_:is(th,td):last-child]:pr-0 [&_td:last-child>a]:pr-0";
101
+ /**
102
+ * Row density. Each sets `--row-min-h` (the least a body row measures, whatever it holds) and
103
+ * `--table-cell-py` (the vertical cell padding), so a row of text and a row holding a 30px control
104
+ * come out the same height. Override either variable with `className` or `style` to tune it.
105
+ */
106
+ export type TableDensity = "comfortable" | "compact";
107
+
108
+ const DENSITY: Readonly<Record<TableDensity, string>> = {
109
+ comfortable: "[--row-min-h:48px] [--table-cell-py:--spacing(2)]",
110
+ compact: "[--row-min-h:40px] [--table-cell-py:--spacing(1)]",
111
+ };
112
+ // A table row's `height` works as a minimum: content taller than it still grows the row.
113
+ const ROW_MIN_HEIGHT = "[&>tbody>tr]:h-(--row-min-h)";
114
+
115
+ // The last column (the actions one) sticks to the right edge from 24rem of the wrapper's width, so
116
+ // it stays reachable while the other columns scroll under it; a narrower table scrolls it along,
117
+ // since a pinned column would take most of a phone screen. Sticky cells in a collapsed-border table
118
+ // lose their bottom border, so an inset shadow redraws it, and the edge shadow shows only while
119
+ // columns are hidden underneath.
120
+ // Written out in full (no interpolation) so Tailwind finds every class in the source.
121
+ const STICKY_ACTIONS = cn(
122
+ "@sm/table:[&_:is(th,td):last-child]:sticky @sm/table:[&_:is(th,td):last-child]:right-0 @sm/table:[&_:is(th,td):last-child]:bg-surface",
123
+ "@sm/table:[&_td:last-child]:z-1 @sm/table:[&_th:last-child]:z-2 @sm/table:[&_td:last-child]:transition-colors @sm/table:[&_td:last-child]:duration-(--motion-duration)",
124
+ "@sm/table:[&_tr:hover>td:last-child]:bg-surface-2 @sm/table:[&_tr[data-selected]>td:last-child]:bg-accent-soft",
125
+ "@sm/table:[&_:is(th,td):last-child]:[box-shadow:var(--sticky-divider,0_0_transparent),var(--sticky-edge,0_0_transparent)]",
126
+ "[&_th:last-child]:[--sticky-divider:inset_0_-1px_0_var(--border-color-divider)] [&_tbody>tr:not(:last-child)>td:last-child]:[--sticky-divider:inset_0_-1px_0_var(--border-color-divider)]",
127
+ );
128
+ const STICKY_EDGE = "[&_:is(th,td):last-child]:[--sticky-edge:var(--shadow-pinned-end)]";
129
+
74
130
  const STICKY_HEADER =
75
131
  "[&_thead_th]:sticky [&_thead_th]:top-0 [&_thead_th]:z-2 [&_thead_th]:bg-surface [&_thead_th]:shadow-[inset_0_-1px_0_var(--border-color-divider)]";
76
132
 
@@ -105,6 +161,27 @@ export interface TableProps extends ComponentPropsWithoutRef<"table"> {
105
161
  defaultSelectedKeys?: readonly string[];
106
162
  /** Called with the next keys. Setting it turns selection on. */
107
163
  onSelectedKeysChange?: (keys: string[]) => void;
164
+ /**
165
+ * Controlled sort state. Setting it, `defaultSort` or `onSortChange` turns sorting on for the
166
+ * headers marked `sortable`. The table only reports the state: sort your rows yourself.
167
+ */
168
+ sort?: TableSort | null;
169
+ /** Initial sort when uncontrolled. */
170
+ defaultSort?: TableSort | null;
171
+ /** Called with the next sort (`null` when the sort is cleared). */
172
+ onSortChange?: (sort: TableSort | null) => void;
173
+ /** Ids (`columnId`) of the columns to hide. Headers and cells with that id render nothing. */
174
+ hiddenColumns?: readonly string[];
175
+ /**
176
+ * Row density: `comfortable` (default) gives every body row at least 48px, `compact` 40px, with
177
+ * the cells centred vertically. Rows never depend on what a cell holds for their height.
178
+ */
179
+ density?: TableDensity;
180
+ /**
181
+ * Keeps the last column (the row actions) stuck to the right edge while the table scrolls
182
+ * sideways, from 24rem of the table's own width up. Leave the last column unpinned when using it.
183
+ */
184
+ stickyActions?: boolean;
108
185
  }
109
186
 
110
187
  function readStorage(key: string): string | null {
@@ -148,6 +225,12 @@ export function Table({
148
225
  selectedKeys,
149
226
  defaultSelectedKeys,
150
227
  onSelectedKeysChange,
228
+ sort,
229
+ defaultSort,
230
+ onSortChange,
231
+ hiddenColumns,
232
+ density = "comfortable",
233
+ stickyActions,
151
234
  ...props
152
235
  }: TableProps) {
153
236
  const strings = useUiStrings();
@@ -160,6 +243,18 @@ export function Table({
160
243
  defaultProp: defaultSelectedKeys ?? [],
161
244
  onChange: onSelectedKeysChange ? (keys) => onSelectedKeysChange([...keys]) : undefined,
162
245
  });
246
+ const sortOn = sort !== undefined || defaultSort !== undefined || onSortChange !== undefined;
247
+ const [currentSort, setSort] = useControllableState<TableSort | null>({
248
+ prop: sort,
249
+ defaultProp: defaultSort ?? null,
250
+ onChange: onSortChange,
251
+ });
252
+ const sortContext: SortContextValue | null = sortOn
253
+ ? { sort: currentSort, toggle: (columnId) => setSort(nextTableSort(currentSort, columnId)) }
254
+ : null;
255
+ const hiddenKey = (hiddenColumns ?? []).join("\u0000");
256
+ // biome-ignore lint/correctness/useExhaustiveDependencies: hiddenKey is the content of hiddenColumns
257
+ const hidden = useMemo(() => new Set(hiddenColumns ?? []), [hiddenKey]);
163
258
  const wrapperRef = useRef<HTMLDivElement>(null);
164
259
  const tableRef = useRef<HTMLTableElement>(null);
165
260
  const controlled = pinnedColumns !== undefined;
@@ -266,29 +361,38 @@ export function Table({
266
361
  return (
267
362
  <PinContext.Provider value={context}>
268
363
  <SelectionContext.Provider value={selection}>
269
- <div
270
- ref={wrapperRef}
271
- onScroll={measure}
272
- style={maxHeight !== undefined ? { maxHeight } : undefined}
273
- tabIndex={maxHeight !== undefined ? 0 : undefined}
274
- className={cn(
275
- "@container/table max-w-full overflow-x-auto",
276
- maxHeight !== undefined && "overflow-y-auto focus-visible:focus-ring",
277
- wrapperClassName,
278
- )}
279
- >
280
- <table
281
- ref={tableRef}
282
- className={cn(
283
- "w-full border-collapse text-fs-130",
284
- (flush === true || flush === "start") && FLUSH_START,
285
- (flush === true || flush === "end") && FLUSH_END,
286
- stickyHeader && STICKY_HEADER,
287
- className,
288
- )}
289
- {...props}
290
- />
291
- </div>
364
+ <SortContext.Provider value={sortContext}>
365
+ <HiddenContext.Provider value={hidden}>
366
+ <div
367
+ ref={wrapperRef}
368
+ onScroll={measure}
369
+ style={maxHeight !== undefined ? { maxHeight } : undefined}
370
+ tabIndex={maxHeight !== undefined ? 0 : undefined}
371
+ className={cn(
372
+ "@container/table max-w-full overflow-x-auto",
373
+ maxHeight !== undefined && "overflow-y-auto focus-visible:focus-ring",
374
+ wrapperClassName,
375
+ )}
376
+ >
377
+ <table
378
+ ref={tableRef}
379
+ data-table-density={density}
380
+ className={cn(
381
+ "w-full border-collapse text-fs-130",
382
+ DENSITY[density],
383
+ ROW_MIN_HEIGHT,
384
+ stickyActions && STICKY_ACTIONS,
385
+ stickyActions && scrolled.end && STICKY_EDGE,
386
+ (flush === true || flush === "start") && FLUSH_START,
387
+ (flush === true || flush === "end") && FLUSH_END,
388
+ stickyHeader && STICKY_HEADER,
389
+ className,
390
+ )}
391
+ {...props}
392
+ />
393
+ </div>
394
+ </HiddenContext.Provider>
395
+ </SortContext.Provider>
292
396
  </SelectionContext.Provider>
293
397
  </PinContext.Provider>
294
398
  );
@@ -321,7 +425,7 @@ function usePinnedCell(columnId: string | undefined, header: boolean) {
321
425
  const shadowed =
322
426
  position.edge && (position.side === "left" ? context.scrolledStart : context.scrolledEnd);
323
427
  const className = cn(
324
- "sticky bg-surface",
428
+ "sticky bg-surface transition-colors duration-(--motion-duration) motion-reduce:transition-none",
325
429
  header
326
430
  ? "z-2"
327
431
  : "z-1 group-hover/row:bg-surface-2 group-aria-selected/row:bg-accent-soft group-data-[selected=true]/row:bg-accent-soft",
@@ -377,19 +481,70 @@ function PinButtons({ columnId }: { columnId: string }) {
377
481
  );
378
482
  }
379
483
 
484
+ function SortButton({
485
+ columnId,
486
+ context,
487
+ children,
488
+ }: {
489
+ columnId: string;
490
+ context: SortContextValue;
491
+ children: ReactNode;
492
+ }) {
493
+ const direction = ariaSortFor(context.sort, columnId);
494
+ const Icon =
495
+ direction === "ascending" ? ArrowUp : direction === "descending" ? ArrowDown : ChevronsUpDown;
496
+ return (
497
+ <button
498
+ type="button"
499
+ onClick={() => context.toggle(columnId)}
500
+ className={cn(
501
+ "-mx-1 inline-flex items-center gap-1 rounded-xs px-1 font-[inherit] text-[length:inherit] uppercase tracking-[inherit] hover:text-ink focus-visible:focus-ring",
502
+ direction !== "none" ? "text-ink" : "text-inherit",
503
+ )}
504
+ >
505
+ {children}
506
+ <Icon
507
+ aria-hidden="true"
508
+ className={cn("size-3.5 shrink-0", direction === "none" && "opacity-50")}
509
+ />
510
+ </button>
511
+ );
512
+ }
513
+
380
514
  export function TableHeaderCell({
381
515
  className,
382
516
  alignRight,
383
517
  columnId,
384
518
  pinnable,
519
+ sortable,
385
520
  children,
386
521
  style,
387
522
  ...props
388
- }: ComponentPropsWithoutRef<"th"> & AlignProps & { pinnable?: boolean }): ReactNode {
523
+ }: ComponentPropsWithoutRef<"th"> &
524
+ AlignProps & {
525
+ pinnable?: boolean;
526
+ /**
527
+ * Makes the header a button that cycles the sort (ascending, descending, off) and reports it
528
+ * as `aria-sort`. Needs a `columnId` and a `Table` with `sort`, `defaultSort` or `onSortChange`.
529
+ */
530
+ sortable?: boolean;
531
+ }): ReactNode {
389
532
  const pinned = usePinnedCell(columnId, true);
533
+ const hiddenIds = useContext(HiddenContext);
534
+ const sortContext = useContext(SortContext);
535
+ if (columnId && hiddenIds.has(columnId)) return null;
536
+ const sorting = sortable && columnId && sortContext ? { columnId, context: sortContext } : null;
537
+ const content = sorting ? (
538
+ <SortButton columnId={sorting.columnId} context={sorting.context}>
539
+ {children}
540
+ </SortButton>
541
+ ) : (
542
+ children
543
+ );
390
544
  const showPin = pinnable && columnId && pinned.context;
391
545
  return (
392
546
  <th
547
+ aria-sort={sorting ? ariaSortFor(sorting.context.sort, sorting.columnId) : undefined}
393
548
  className={cn(
394
549
  "whitespace-nowrap border-b-divider px-4 py-2.5 text-left font-[650] text-fs-110 text-ink-3 uppercase tracking-[.07em] @max-sm/table:px-2.5",
395
550
  alignRight && "text-right",
@@ -402,11 +557,11 @@ export function TableHeaderCell({
402
557
  >
403
558
  {showPin ? (
404
559
  <span className={cn("inline-flex items-center gap-1", alignRight && "flex-row-reverse")}>
405
- {children}
560
+ {content}
406
561
  <PinButtons columnId={columnId} />
407
562
  </span>
408
563
  ) : (
409
- children
564
+ content
410
565
  )}
411
566
  </th>
412
567
  );
@@ -429,7 +584,7 @@ export function TableRow({ className, rowKey, ...props }: TableRowProps) {
429
584
  aria-selected={isSelected}
430
585
  data-selected={isSelected || undefined}
431
586
  className={cn(
432
- "group/row border-b-divider last:border-b-0 hover:bg-surface-2",
587
+ "group/row border-b-divider transition-colors duration-(--motion-duration) ease-(--motion-ease) last:border-b-0 hover:bg-surface-2 motion-reduce:transition-none",
433
588
  isSelected && "bg-accent-soft hover:bg-accent-soft",
434
589
  className,
435
590
  )}
@@ -451,7 +606,10 @@ export function TableSelectCell({ rowKey, label, className, ...props }: TableSel
451
606
  if (!selection)
452
607
  throw new Error("TableSelectCell needs a Table with selectedKeys or onSelectedKeysChange");
453
608
  return (
454
- <td className={cn("w-px px-4 py-2.75 align-middle @max-sm/table:px-2.5", className)} {...props}>
609
+ <td
610
+ className={cn("w-px px-4 align-middle @max-sm/table:px-2.5", CELL_PY, className)}
611
+ {...props}
612
+ >
455
613
  <Checkbox
456
614
  checked={selection.selected.includes(rowKey)}
457
615
  onCheckedChange={() => selection.toggle(rowKey)}
@@ -507,7 +665,7 @@ export interface TableActionsCellProps extends ComponentPropsWithoutRef<"td"> {
507
665
  export function TableActionsCell({ menu, className, children, ...props }: TableActionsCellProps) {
508
666
  return (
509
667
  <td
510
- className={cn("w-px px-4 py-2.75 text-right align-middle @max-sm/table:px-2.5", className)}
668
+ className={cn("w-px px-4 text-right align-middle @max-sm/table:px-2.5", CELL_PY, className)}
511
669
  {...props}
512
670
  >
513
671
  <div
@@ -533,10 +691,13 @@ export function TableCell({
533
691
  ...props
534
692
  }: ComponentPropsWithoutRef<"td"> & AlignProps) {
535
693
  const pinned = usePinnedCell(columnId, false);
694
+ const hiddenIds = useContext(HiddenContext);
695
+ if (columnId && hiddenIds.has(columnId)) return null;
536
696
  return (
537
697
  <td
538
698
  className={cn(
539
- "px-4 py-2.75 align-middle @max-sm/table:px-2.5",
699
+ "px-4 align-middle @max-sm/table:px-2.5",
700
+ CELL_PY,
540
701
  alignRight && "text-right",
541
702
  pinned.className,
542
703
  className,
@@ -576,6 +737,7 @@ export function TableLinkRow({
576
737
  ...props
577
738
  }: TableLinkRowProps) {
578
739
  const pinned = usePinnedCell(primaryColumnId, false);
740
+ const hiddenIds = useContext(HiddenContext);
579
741
  const selection = useContext(SelectionContext);
580
742
  const isSelected =
581
743
  selection && rowKey !== undefined ? selection.selected.includes(rowKey) : undefined;
@@ -584,24 +746,29 @@ export function TableLinkRow({
584
746
  aria-selected={isSelected}
585
747
  data-selected={isSelected || undefined}
586
748
  className={cn(
587
- "group/row relative border-b-divider last:border-b-0 hover:bg-surface-2",
749
+ "group/row relative border-b-divider transition-colors duration-(--motion-duration) ease-(--motion-ease) last:border-b-0 hover:bg-surface-2 motion-reduce:transition-none",
588
750
  isSelected && "bg-accent-soft hover:bg-accent-soft",
589
751
  className,
590
752
  )}
591
753
  {...props}
592
754
  >
593
- <td
594
- className={cn("p-0 align-middle", pinned.className)}
595
- style={pinned.style}
596
- {...pinned.attrs}
597
- >
598
- <a
599
- href={href}
600
- className="block px-4 py-2.75 font-[650] text-ink no-underline before:absolute before:inset-0 before:content-[''] @max-sm/table:px-2.5"
755
+ {primaryColumnId && hiddenIds.has(primaryColumnId) ? null : (
756
+ <td
757
+ className={cn("p-0 align-middle", pinned.className)}
758
+ style={pinned.style}
759
+ {...pinned.attrs}
601
760
  >
602
- {primary}
603
- </a>
604
- </td>
761
+ <a
762
+ href={href}
763
+ className={cn(
764
+ "block px-4 font-[650] text-ink no-underline before:absolute before:inset-0 before:content-[''] @max-sm/table:px-2.5",
765
+ CELL_PY,
766
+ )}
767
+ >
768
+ {primary}
769
+ </a>
770
+ </td>
771
+ )}
605
772
  {children}
606
773
  </tr>
607
774
  );
@@ -0,0 +1,5 @@
1
+ export {
2
+ type TableColumnOption,
3
+ TableColumnsMenu,
4
+ type TableColumnsMenuProps,
5
+ } from "./table-columns-menu.js";
@@ -0,0 +1,68 @@
1
+ "use client";
2
+
3
+ import { Checkbox } from "../../atoms/checkbox/checkbox.js";
4
+ import { useUiStrings } from "../../i18n/index.js";
5
+ import { Columns3 } from "../../icons/index.js";
6
+ import { Popover, PopoverContent, PopoverTrigger } from "../../overlays/popover/popover.js";
7
+
8
+ export interface TableColumnOption {
9
+ id: string;
10
+ label: string;
11
+ }
12
+
13
+ export interface TableColumnsMenuProps {
14
+ columns: readonly TableColumnOption[];
15
+ /** Ids of the hidden columns; pass the same list to `Table` as `hiddenColumns`. */
16
+ hiddenColumns: readonly string[];
17
+ onHiddenColumnsChange: (hidden: string[]) => void;
18
+ /** Trigger text. Defaults to the localized "Columns". */
19
+ label?: string;
20
+ }
21
+
22
+ /** Popover with a checkbox per column. The last visible column cannot be hidden. */
23
+ export function TableColumnsMenu({
24
+ columns,
25
+ hiddenColumns,
26
+ onHiddenColumnsChange,
27
+ label,
28
+ }: TableColumnsMenuProps) {
29
+ const strings = useUiStrings();
30
+ const name = label ?? strings.columns;
31
+ const visible = columns.filter((column) => !hiddenColumns.includes(column.id));
32
+ return (
33
+ <Popover>
34
+ <PopoverTrigger asChild>
35
+ <button
36
+ type="button"
37
+ className="inline-flex h-control-sm items-center gap-1.5 rounded-control bg-surface-control px-2.5 text-fs-120 text-ink shadow-control hover:bg-surface-2 focus-visible:focus-ring [&_svg]:size-4"
38
+ >
39
+ <Columns3 aria-hidden="true" />
40
+ {name}
41
+ </button>
42
+ </PopoverTrigger>
43
+ <PopoverContent align="end" aria-label={name}>
44
+ <ul className="m-0 grid list-none gap-1 p-0">
45
+ {columns.map((column) => {
46
+ const shown = !hiddenColumns.includes(column.id);
47
+ return (
48
+ <li key={column.id} className="px-1.5 py-1">
49
+ <Checkbox
50
+ label={column.label}
51
+ checked={shown}
52
+ disabled={shown && visible.length === 1}
53
+ onCheckedChange={() =>
54
+ onHiddenColumnsChange(
55
+ shown
56
+ ? [...hiddenColumns, column.id]
57
+ : hiddenColumns.filter((id) => id !== column.id),
58
+ )
59
+ }
60
+ />
61
+ </li>
62
+ );
63
+ })}
64
+ </ul>
65
+ </PopoverContent>
66
+ </Popover>
67
+ );
68
+ }
@@ -1,80 +1,13 @@
1
1
  import type { Decorator } from "@storybook/react-vite";
2
- import type { ReactNode } from "react";
3
- import { Card, CardBody, CardHeader } from "../containers/card/index.js";
4
- import { cn } from "../utils/cn.js";
5
2
 
6
- /** Vertical rhythm of a dashboard page. */
7
- export function DashboardPage({ children }: { children: ReactNode }) {
8
- return <div className="flex min-w-0 flex-col gap-4">{children}</div>;
9
- }
10
-
11
- /** Joined KPI tiles: two per row when narrow, four from 720 px of page width. */
12
- export function KpiRow({ children }: { children: ReactNode }) {
13
- return (
14
- <div className="grid grid-cols-2 gap-px overflow-hidden rounded-card bg-line border-card shadow-card @min-[720px]/page:grid-cols-4">
15
- {children}
16
- </div>
17
- );
18
- }
19
-
20
- const gridClasses = {
21
- 2: "grid-cols-1 @min-[720px]/page:grid-cols-2",
22
- 3: "grid-cols-1 @min-[720px]/page:grid-cols-2 @min-[1180px]/page:grid-cols-3",
23
- } as const;
24
-
25
- /** Equal cards that stack under 720 px of page width. */
26
- export function CardGrid({ columns = 2, children }: { columns?: 2 | 3; children: ReactNode }) {
27
- return <div className={cn("grid items-start gap-4", gridClasses[columns])}>{children}</div>;
28
- }
29
-
30
- export interface ChartCardProps {
31
- title: string;
32
- subtitle?: string;
33
- /** Slot at the end of the header (a chip, a button). */
34
- aside?: ReactNode;
35
- /** Fixed height of the body in px; the chart inside uses `height="fill"`. */
36
- height?: number;
37
- children: ReactNode;
38
- }
39
-
40
- function CardTitle({ title, subtitle }: { title: string; subtitle?: string }) {
41
- return (
42
- <div className="min-w-0 flex-1">
43
- <h2 className="m-0 break-words font-semibold text-fs-140 text-ink">{title}</h2>
44
- {subtitle ? <p className="m-0 break-words text-fs-120 text-ink-3">{subtitle}</p> : null}
45
- </div>
46
- );
47
- }
48
-
49
- /** Card with a fixed-height body so `height="fill"` charts take exactly the space left. */
50
- export function ChartCard({ title, subtitle, aside, height = 300, children }: ChartCardProps) {
51
- return (
52
- <Card>
53
- <CardHeader>
54
- <CardTitle title={title} subtitle={subtitle} />
55
- {aside}
56
- </CardHeader>
57
- <CardBody>
58
- <div className="min-w-0" style={{ height }}>
59
- {children}
60
- </div>
61
- </CardBody>
62
- </Card>
63
- );
64
- }
65
-
66
- /** Card whose body is a table or grid that scrolls inside its own wrapper. */
67
- export function TableCard({ title, subtitle, aside, children }: Omit<ChartCardProps, "height">) {
68
- return (
69
- <Card>
70
- <CardHeader>
71
- <CardTitle title={title} subtitle={subtitle} />
72
- {aside}
73
- </CardHeader>
74
- <div className="min-w-0">{children}</div>
75
- </Card>
76
- );
77
- }
3
+ export {
4
+ CardGrid,
5
+ ChartCard,
6
+ type ChartCardProps,
7
+ DashboardPage,
8
+ KpiRow,
9
+ TableCard,
10
+ } from "../containers/dashboard/index.js";
78
11
 
79
12
  /** Container-width frames for the `Narrow` (320) and `Tablet` (768) variants. */
80
13
  export const narrowFrame: Decorator = (Story) => (