@dashforge/tw 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (390) hide show
  1. package/CHANGELOG.md +21 -1
  2. package/dist/index.esm.js +1 -1
  3. package/dist/src/index.d.ts +1 -1
  4. package/package.json +8 -3
  5. package/.swcrc +0 -29
  6. package/A11Y.md +0 -130
  7. package/CONSUMER-VALIDATION.md +0 -130
  8. package/COVERAGE.md +0 -63
  9. package/PARITY.md +0 -481
  10. package/PERFORMANCE.md +0 -227
  11. package/REFINEMENT-NOTES.md +0 -50
  12. package/THEME-AUDIT.md +0 -174
  13. package/dashforge-tw-1.0.0.tgz +0 -0
  14. package/eslint.config.mjs +0 -62
  15. package/project.json +0 -15
  16. package/rollup.config.cjs +0 -16
  17. package/src/components/Accordion/Accordion.test.tsx +0 -95
  18. package/src/components/Accordion/Accordion.tsx +0 -97
  19. package/src/components/Accordion/accordion.types.ts +0 -66
  20. package/src/components/Accordion/accordion.variants.ts +0 -32
  21. package/src/components/Alert/Alert.test.tsx +0 -302
  22. package/src/components/Alert/Alert.tsx +0 -186
  23. package/src/components/Alert/alert.types.ts +0 -144
  24. package/src/components/Alert/alert.variants.ts +0 -71
  25. package/src/components/AppShell/AppShell.test.tsx +0 -223
  26. package/src/components/AppShell/AppShell.tsx +0 -239
  27. package/src/components/AppShell/appShell.types.ts +0 -49
  28. package/src/components/AppShell/appShell.variants.ts +0 -54
  29. package/src/components/AspectRatio/AspectRatio.test.tsx +0 -173
  30. package/src/components/AspectRatio/AspectRatio.tsx +0 -73
  31. package/src/components/AspectRatio/aspectRatio.types.ts +0 -54
  32. package/src/components/Autocomplete/Autocomplete.perf.test.tsx +0 -225
  33. package/src/components/Autocomplete/Autocomplete.test.tsx +0 -556
  34. package/src/components/Autocomplete/Autocomplete.tsx +0 -1069
  35. package/src/components/Autocomplete/autocomplete.types.ts +0 -198
  36. package/src/components/Autocomplete/autocomplete.variants.ts +0 -141
  37. package/src/components/Avatar/Avatar.test.tsx +0 -287
  38. package/src/components/Avatar/Avatar.tsx +0 -304
  39. package/src/components/Avatar/avatar.types.ts +0 -205
  40. package/src/components/Avatar/avatar.variants.ts +0 -194
  41. package/src/components/Badge/Badge.test.tsx +0 -385
  42. package/src/components/Badge/Badge.tsx +0 -174
  43. package/src/components/Badge/badge.types.ts +0 -154
  44. package/src/components/Badge/badge.variants.ts +0 -161
  45. package/src/components/Box/Box.test.tsx +0 -391
  46. package/src/components/Box/Box.tsx +0 -112
  47. package/src/components/Box/box.types.ts +0 -116
  48. package/src/components/Box/box.variants.ts +0 -230
  49. package/src/components/Breadcrumbs/Breadcrumbs.perf.test.tsx +0 -128
  50. package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +0 -231
  51. package/src/components/Breadcrumbs/Breadcrumbs.tsx +0 -203
  52. package/src/components/Breadcrumbs/breadcrumbs.types.ts +0 -87
  53. package/src/components/Breadcrumbs/breadcrumbs.variants.ts +0 -54
  54. package/src/components/Button/Button.test.tsx +0 -204
  55. package/src/components/Button/Button.tsx +0 -151
  56. package/src/components/Button/button.types.ts +0 -110
  57. package/src/components/Button/button.variants.ts +0 -159
  58. package/src/components/Calendar/Calendar.test.tsx +0 -75
  59. package/src/components/Calendar/Calendar.tsx +0 -264
  60. package/src/components/Calendar/calendar.types.ts +0 -65
  61. package/src/components/Calendar/calendar.variants.ts +0 -64
  62. package/src/components/Card/Card.test.tsx +0 -291
  63. package/src/components/Card/Card.tsx +0 -241
  64. package/src/components/Card/card.types.ts +0 -132
  65. package/src/components/Checkbox/Checkbox.test.tsx +0 -146
  66. package/src/components/Checkbox/Checkbox.tsx +0 -286
  67. package/src/components/Checkbox/checkbox.types.ts +0 -88
  68. package/src/components/Checkbox/checkbox.variants.ts +0 -68
  69. package/src/components/Chip/Chip.test.tsx +0 -316
  70. package/src/components/Chip/Chip.tsx +0 -224
  71. package/src/components/Chip/chip.types.ts +0 -128
  72. package/src/components/Chip/chip.variants.ts +0 -173
  73. package/src/components/ConfirmDialog/ConfirmDialog.perf.test.tsx +0 -172
  74. package/src/components/ConfirmDialog/ConfirmDialog.test.tsx +0 -311
  75. package/src/components/ConfirmDialog/ConfirmDialog.tsx +0 -252
  76. package/src/components/ConfirmDialog/confirmDialog.types.ts +0 -70
  77. package/src/components/ConfirmDialog/confirmDialog.variants.ts +0 -76
  78. package/src/components/Container/Container.test.tsx +0 -209
  79. package/src/components/Container/Container.tsx +0 -74
  80. package/src/components/Container/container.types.ts +0 -45
  81. package/src/components/Container/container.variants.ts +0 -81
  82. package/src/components/DataGrid/DataGrid.perf.test.tsx +0 -114
  83. package/src/components/DataGrid/DataGrid.test.tsx +0 -1153
  84. package/src/components/DataGrid/DataGrid.tsx +0 -1282
  85. package/src/components/DataGrid/dataGrid.types.ts +0 -238
  86. package/src/components/DataGrid/dataGrid.variants.ts +0 -152
  87. package/src/components/DataGrid/filters/ColumnFilters.test.tsx +0 -330
  88. package/src/components/DataGrid/filters/ColumnFilters.tsx +0 -456
  89. package/src/components/DataGrid/reorder/useColumnReorder.test.ts +0 -130
  90. package/src/components/DataGrid/reorder/useColumnReorder.ts +0 -144
  91. package/src/components/DataGrid/resize/useColumnResize.test.ts +0 -144
  92. package/src/components/DataGrid/resize/useColumnResize.ts +0 -135
  93. package/src/components/DataGrid/visibility/ColumnVisibilityMenu.tsx +0 -186
  94. package/src/components/DatePicker/DatePicker.test.tsx +0 -76
  95. package/src/components/DatePicker/DatePicker.tsx +0 -305
  96. package/src/components/DatePicker/datePicker.types.ts +0 -77
  97. package/src/components/DatePicker/datePicker.variants.ts +0 -50
  98. package/src/components/DateRangePicker/DateRangePicker.test.tsx +0 -92
  99. package/src/components/DateRangePicker/DateRangePicker.tsx +0 -510
  100. package/src/components/DateRangePicker/dateRangePicker.types.ts +0 -74
  101. package/src/components/DateRangePicker/dateRangePicker.variants.ts +0 -101
  102. package/src/components/DateTimePicker/DateTimePicker.test.tsx +0 -78
  103. package/src/components/DateTimePicker/DateTimePicker.tsx +0 -347
  104. package/src/components/DateTimePicker/dateTimePicker.types.ts +0 -79
  105. package/src/components/DateTimePicker/dateTimePicker.variants.ts +0 -55
  106. package/src/components/Dialog/Dialog.test.tsx +0 -96
  107. package/src/components/Dialog/Dialog.tsx +0 -102
  108. package/src/components/Dialog/dialog.types.ts +0 -62
  109. package/src/components/Dialog/dialog.variants.ts +0 -66
  110. package/src/components/Divider/Divider.test.tsx +0 -243
  111. package/src/components/Divider/Divider.tsx +0 -140
  112. package/src/components/Divider/divider.types.ts +0 -52
  113. package/src/components/Divider/divider.variants.ts +0 -116
  114. package/src/components/Grid/Grid.test.tsx +0 -321
  115. package/src/components/Grid/Grid.tsx +0 -148
  116. package/src/components/Grid/grid.types.ts +0 -112
  117. package/src/components/Grid/grid.variants.ts +0 -133
  118. package/src/components/IconButton/IconButton.test.tsx +0 -367
  119. package/src/components/IconButton/IconButton.tsx +0 -159
  120. package/src/components/IconButton/iconButton.types.ts +0 -106
  121. package/src/components/IconButton/iconButton.variants.ts +0 -31
  122. package/src/components/LeftNav/LeftNav.perf.test.tsx +0 -172
  123. package/src/components/LeftNav/LeftNav.test.tsx +0 -302
  124. package/src/components/LeftNav/LeftNav.tsx +0 -330
  125. package/src/components/LeftNav/leftNav.types.ts +0 -120
  126. package/src/components/LeftNav/leftNav.variants.ts +0 -107
  127. package/src/components/Menu/Menu.test.tsx +0 -408
  128. package/src/components/Menu/Menu.tsx +0 -335
  129. package/src/components/Menu/menu.types.ts +0 -221
  130. package/src/components/Menu/menu.variants.ts +0 -132
  131. package/src/components/NumberField/NumberField.test.tsx +0 -83
  132. package/src/components/NumberField/NumberField.tsx +0 -321
  133. package/src/components/NumberField/numberField.types.ts +0 -72
  134. package/src/components/NumberField/numberField.variants.ts +0 -94
  135. package/src/components/OTPField/OTPField.test.tsx +0 -121
  136. package/src/components/OTPField/OTPField.tsx +0 -250
  137. package/src/components/OTPField/otpField.types.ts +0 -58
  138. package/src/components/OTPField/otpField.variants.ts +0 -72
  139. package/src/components/Pagination/Pagination.test.tsx +0 -314
  140. package/src/components/Pagination/Pagination.tsx +0 -277
  141. package/src/components/Pagination/pagination.helpers.ts +0 -102
  142. package/src/components/Pagination/pagination.types.ts +0 -117
  143. package/src/components/Pagination/pagination.variants.ts +0 -117
  144. package/src/components/Popover/Popover.test.tsx +0 -72
  145. package/src/components/Popover/Popover.tsx +0 -55
  146. package/src/components/Popover/popover.types.ts +0 -42
  147. package/src/components/Popover/popover.variants.ts +0 -24
  148. package/src/components/RadioGroup/RadioGroup.test.tsx +0 -140
  149. package/src/components/RadioGroup/RadioGroup.tsx +0 -283
  150. package/src/components/RadioGroup/radioGroup.types.ts +0 -85
  151. package/src/components/RadioGroup/radioGroup.variants.ts +0 -87
  152. package/src/components/Skeleton/Skeleton.test.tsx +0 -127
  153. package/src/components/Skeleton/Skeleton.tsx +0 -49
  154. package/src/components/Skeleton/skeleton.types.ts +0 -59
  155. package/src/components/Skeleton/skeleton.variants.ts +0 -87
  156. package/src/components/Snackbar/Snackbar.perf.test.tsx +0 -144
  157. package/src/components/Snackbar/Snackbar.test.tsx +0 -327
  158. package/src/components/Snackbar/Snackbar.tsx +0 -316
  159. package/src/components/Snackbar/snackbar.types.ts +0 -127
  160. package/src/components/Snackbar/snackbar.variants.ts +0 -81
  161. package/src/components/Spinner/Spinner.test.tsx +0 -199
  162. package/src/components/Spinner/Spinner.tsx +0 -158
  163. package/src/components/Spinner/spinner.types.ts +0 -113
  164. package/src/components/Spinner/spinner.variants.ts +0 -83
  165. package/src/components/Stack/Stack.test.tsx +0 -309
  166. package/src/components/Stack/Stack.tsx +0 -115
  167. package/src/components/Stack/stack.types.ts +0 -68
  168. package/src/components/Stack/stack.variants.ts +0 -80
  169. package/src/components/Switch/Switch.test.tsx +0 -131
  170. package/src/components/Switch/Switch.tsx +0 -158
  171. package/src/components/Switch/switch.types.ts +0 -36
  172. package/src/components/Switch/switch.variants.ts +0 -70
  173. package/src/components/Table/Table.perf.test.tsx +0 -81
  174. package/src/components/Table/Table.test.tsx +0 -674
  175. package/src/components/Table/Table.tsx +0 -863
  176. package/src/components/Table/cells/RenderButton.tsx +0 -23
  177. package/src/components/Table/cells/RenderChip.tsx +0 -37
  178. package/src/components/Table/cells/RenderText.tsx +0 -37
  179. package/src/components/Table/cells/RenderTwoLine.tsx +0 -34
  180. package/src/components/Table/cells/RowActionsMenu.tsx +0 -147
  181. package/src/components/Table/cells/cells.test.tsx +0 -247
  182. package/src/components/Table/cells/index.ts +0 -14
  183. package/src/components/Table/table.types.ts +0 -438
  184. package/src/components/Table/table.variants.ts +0 -207
  185. package/src/components/Tabs/Tabs.test.tsx +0 -145
  186. package/src/components/Tabs/Tabs.tsx +0 -77
  187. package/src/components/Tabs/tabs.types.ts +0 -55
  188. package/src/components/Tabs/tabs.variants.ts +0 -69
  189. package/src/components/Tabs/useTabs.ts +0 -167
  190. package/src/components/TextField/TextField.test.tsx +0 -198
  191. package/src/components/TextField/TextField.tsx +0 -245
  192. package/src/components/TextField/textField.types.ts +0 -90
  193. package/src/components/TextField/textField.variants.ts +0 -105
  194. package/src/components/Textarea/Textarea.test.tsx +0 -75
  195. package/src/components/Textarea/Textarea.tsx +0 -190
  196. package/src/components/Textarea/textarea.types.ts +0 -60
  197. package/src/components/Textarea/textarea.variants.ts +0 -85
  198. package/src/components/TimePicker/TimePicker.test.tsx +0 -65
  199. package/src/components/TimePicker/TimePicker.tsx +0 -274
  200. package/src/components/TimePicker/timePicker.types.ts +0 -69
  201. package/src/components/TimePicker/timePicker.variants.ts +0 -53
  202. package/src/components/Tooltip/Tooltip.test.tsx +0 -73
  203. package/src/components/Tooltip/Tooltip.tsx +0 -70
  204. package/src/components/Tooltip/tooltip.types.ts +0 -44
  205. package/src/components/Tooltip/tooltip.variants.ts +0 -28
  206. package/src/components/TopBar/TopBar.test.tsx +0 -129
  207. package/src/components/TopBar/TopBar.tsx +0 -66
  208. package/src/components/TopBar/topBar.types.ts +0 -42
  209. package/src/components/TopBar/topBar.variants.ts +0 -38
  210. package/src/components/Typography/Typography.test.tsx +0 -247
  211. package/src/components/Typography/Typography.tsx +0 -112
  212. package/src/components/Typography/typography.types.ts +0 -65
  213. package/src/components/Typography/typography.variants.ts +0 -130
  214. package/src/components/VisuallyHidden/VisuallyHidden.test.tsx +0 -86
  215. package/src/components/VisuallyHidden/VisuallyHidden.tsx +0 -59
  216. package/src/components/VisuallyHidden/visuallyHidden.types.ts +0 -45
  217. package/src/components/_shared/data/getNestedValue.test.ts +0 -50
  218. package/src/components/_shared/data/getNestedValue.ts +0 -32
  219. package/src/components/_shared/data/useColumnAutoDetect.test.ts +0 -123
  220. package/src/components/_shared/data/useColumnAutoDetect.ts +0 -100
  221. package/src/components/_shared/data/useControllableState.ts +0 -48
  222. package/src/components/_shared/data/useDebouncedValue.ts +0 -24
  223. package/src/components/_shared/data/useTableFilter.test.ts +0 -166
  224. package/src/components/_shared/data/useTableFilter.ts +0 -118
  225. package/src/components/_shared/data/useTableSearch.test.ts +0 -115
  226. package/src/components/_shared/data/useTableSearch.ts +0 -66
  227. package/src/components/_shared/data/useTableSelection.test.ts +0 -100
  228. package/src/components/_shared/data/useTableSelection.ts +0 -100
  229. package/src/components/_shared/data/useTableSort.test.ts +0 -150
  230. package/src/components/_shared/data/useTableSort.ts +0 -141
  231. package/src/components/_shared/data/useVirtualizer.test.ts +0 -158
  232. package/src/components/_shared/data/useVirtualizer.ts +0 -199
  233. package/src/components/_shared/resolveValidationState.ts +0 -60
  234. package/src/components/_shared/severity/index.ts +0 -33
  235. package/src/components/_shared/severity/severity.types.ts +0 -50
  236. package/src/components/_shared/severity/severityIcons.tsx +0 -104
  237. package/src/components/_shared/severity/severityVariants.test.ts +0 -136
  238. package/src/components/_shared/severity/severityVariants.ts +0 -115
  239. package/src/components/_shared/themeIdentity.test.ts +0 -113
  240. package/src/hooks/useAccessState.spec.tsx +0 -161
  241. package/src/hooks/useAccessState.ts +0 -81
  242. package/src/index.ts +0 -550
  243. package/src/utils/cn.spec.ts +0 -16
  244. package/src/utils/cn.ts +0 -29
  245. package/test-output/vitest/coverage/base.css +0 -224
  246. package/test-output/vitest/coverage/block-navigation.js +0 -87
  247. package/test-output/vitest/coverage/clover.xml +0 -2418
  248. package/test-output/vitest/coverage/coverage-final.json +0 -89
  249. package/test-output/vitest/coverage/favicon.png +0 -0
  250. package/test-output/vitest/coverage/index.html +0 -746
  251. package/test-output/vitest/coverage/prettify.css +0 -1
  252. package/test-output/vitest/coverage/prettify.js +0 -2
  253. package/test-output/vitest/coverage/sort-arrow-sprite.png +0 -0
  254. package/test-output/vitest/coverage/sorter.js +0 -210
  255. package/test-output/vitest/coverage/src/components/Accordion/Accordion.tsx.html +0 -376
  256. package/test-output/vitest/coverage/src/components/Accordion/accordion.variants.ts.html +0 -181
  257. package/test-output/vitest/coverage/src/components/Accordion/index.html +0 -131
  258. package/test-output/vitest/coverage/src/components/AppShell/AppShell.tsx.html +0 -802
  259. package/test-output/vitest/coverage/src/components/AppShell/appShell.variants.ts.html +0 -247
  260. package/test-output/vitest/coverage/src/components/AppShell/index.html +0 -131
  261. package/test-output/vitest/coverage/src/components/AspectRatio/AspectRatio.tsx.html +0 -304
  262. package/test-output/vitest/coverage/src/components/AspectRatio/index.html +0 -116
  263. package/test-output/vitest/coverage/src/components/Autocomplete/Autocomplete.tsx.html +0 -3292
  264. package/test-output/vitest/coverage/src/components/Autocomplete/autocomplete.variants.ts.html +0 -508
  265. package/test-output/vitest/coverage/src/components/Autocomplete/index.html +0 -131
  266. package/test-output/vitest/coverage/src/components/Box/Box.tsx.html +0 -334
  267. package/test-output/vitest/coverage/src/components/Box/box.variants.ts.html +0 -775
  268. package/test-output/vitest/coverage/src/components/Box/index.html +0 -131
  269. package/test-output/vitest/coverage/src/components/Breadcrumbs/Breadcrumbs.tsx.html +0 -694
  270. package/test-output/vitest/coverage/src/components/Breadcrumbs/breadcrumbs.variants.ts.html +0 -247
  271. package/test-output/vitest/coverage/src/components/Breadcrumbs/index.html +0 -131
  272. package/test-output/vitest/coverage/src/components/Button/Button.tsx.html +0 -535
  273. package/test-output/vitest/coverage/src/components/Button/button.variants.ts.html +0 -562
  274. package/test-output/vitest/coverage/src/components/Button/index.html +0 -131
  275. package/test-output/vitest/coverage/src/components/Checkbox/Checkbox.tsx.html +0 -943
  276. package/test-output/vitest/coverage/src/components/Checkbox/checkbox.variants.ts.html +0 -289
  277. package/test-output/vitest/coverage/src/components/Checkbox/index.html +0 -131
  278. package/test-output/vitest/coverage/src/components/ConfirmDialog/ConfirmDialog.tsx.html +0 -841
  279. package/test-output/vitest/coverage/src/components/ConfirmDialog/confirmDialog.variants.ts.html +0 -313
  280. package/test-output/vitest/coverage/src/components/ConfirmDialog/index.html +0 -131
  281. package/test-output/vitest/coverage/src/components/Container/Container.tsx.html +0 -307
  282. package/test-output/vitest/coverage/src/components/Container/container.variants.ts.html +0 -328
  283. package/test-output/vitest/coverage/src/components/Container/index.html +0 -131
  284. package/test-output/vitest/coverage/src/components/DataGrid/DataGrid.tsx.html +0 -3937
  285. package/test-output/vitest/coverage/src/components/DataGrid/dataGrid.variants.ts.html +0 -541
  286. package/test-output/vitest/coverage/src/components/DataGrid/filters/ColumnFilters.tsx.html +0 -1453
  287. package/test-output/vitest/coverage/src/components/DataGrid/filters/index.html +0 -116
  288. package/test-output/vitest/coverage/src/components/DataGrid/index.html +0 -131
  289. package/test-output/vitest/coverage/src/components/DataGrid/reorder/index.html +0 -116
  290. package/test-output/vitest/coverage/src/components/DataGrid/reorder/useColumnReorder.ts.html +0 -517
  291. package/test-output/vitest/coverage/src/components/DataGrid/resize/index.html +0 -116
  292. package/test-output/vitest/coverage/src/components/DataGrid/resize/useColumnResize.ts.html +0 -490
  293. package/test-output/vitest/coverage/src/components/DataGrid/visibility/ColumnVisibilityMenu.tsx.html +0 -592
  294. package/test-output/vitest/coverage/src/components/DataGrid/visibility/index.html +0 -116
  295. package/test-output/vitest/coverage/src/components/DateTimePicker/DateTimePicker.tsx.html +0 -1042
  296. package/test-output/vitest/coverage/src/components/DateTimePicker/dateTimePicker.variants.ts.html +0 -337
  297. package/test-output/vitest/coverage/src/components/DateTimePicker/index.html +0 -131
  298. package/test-output/vitest/coverage/src/components/Dialog/Dialog.tsx.html +0 -391
  299. package/test-output/vitest/coverage/src/components/Dialog/dialog.variants.ts.html +0 -283
  300. package/test-output/vitest/coverage/src/components/Dialog/index.html +0 -131
  301. package/test-output/vitest/coverage/src/components/Divider/Divider.tsx.html +0 -505
  302. package/test-output/vitest/coverage/src/components/Divider/divider.variants.ts.html +0 -433
  303. package/test-output/vitest/coverage/src/components/Divider/index.html +0 -131
  304. package/test-output/vitest/coverage/src/components/Grid/Grid.tsx.html +0 -529
  305. package/test-output/vitest/coverage/src/components/Grid/grid.variants.ts.html +0 -484
  306. package/test-output/vitest/coverage/src/components/Grid/index.html +0 -131
  307. package/test-output/vitest/coverage/src/components/LeftNav/LeftNav.tsx.html +0 -1075
  308. package/test-output/vitest/coverage/src/components/LeftNav/index.html +0 -131
  309. package/test-output/vitest/coverage/src/components/LeftNav/leftNav.variants.ts.html +0 -406
  310. package/test-output/vitest/coverage/src/components/NumberField/NumberField.tsx.html +0 -1048
  311. package/test-output/vitest/coverage/src/components/NumberField/index.html +0 -131
  312. package/test-output/vitest/coverage/src/components/NumberField/numberField.variants.ts.html +0 -367
  313. package/test-output/vitest/coverage/src/components/OTPField/OTPField.tsx.html +0 -835
  314. package/test-output/vitest/coverage/src/components/OTPField/index.html +0 -131
  315. package/test-output/vitest/coverage/src/components/OTPField/otpField.variants.ts.html +0 -301
  316. package/test-output/vitest/coverage/src/components/Pagination/Pagination.tsx.html +0 -916
  317. package/test-output/vitest/coverage/src/components/Pagination/index.html +0 -146
  318. package/test-output/vitest/coverage/src/components/Pagination/pagination.helpers.ts.html +0 -391
  319. package/test-output/vitest/coverage/src/components/Pagination/pagination.variants.ts.html +0 -436
  320. package/test-output/vitest/coverage/src/components/Popover/Popover.tsx.html +0 -250
  321. package/test-output/vitest/coverage/src/components/Popover/index.html +0 -131
  322. package/test-output/vitest/coverage/src/components/Popover/popover.variants.ts.html +0 -157
  323. package/test-output/vitest/coverage/src/components/RadioGroup/RadioGroup.tsx.html +0 -934
  324. package/test-output/vitest/coverage/src/components/RadioGroup/index.html +0 -131
  325. package/test-output/vitest/coverage/src/components/RadioGroup/radioGroup.variants.ts.html +0 -346
  326. package/test-output/vitest/coverage/src/components/Skeleton/Skeleton.tsx.html +0 -232
  327. package/test-output/vitest/coverage/src/components/Skeleton/index.html +0 -131
  328. package/test-output/vitest/coverage/src/components/Skeleton/skeleton.variants.ts.html +0 -346
  329. package/test-output/vitest/coverage/src/components/Snackbar/Snackbar.tsx.html +0 -979
  330. package/test-output/vitest/coverage/src/components/Snackbar/index.html +0 -131
  331. package/test-output/vitest/coverage/src/components/Snackbar/snackbar.variants.ts.html +0 -307
  332. package/test-output/vitest/coverage/src/components/Stack/Stack.tsx.html +0 -430
  333. package/test-output/vitest/coverage/src/components/Stack/index.html +0 -131
  334. package/test-output/vitest/coverage/src/components/Stack/stack.variants.ts.html +0 -325
  335. package/test-output/vitest/coverage/src/components/Switch/Switch.tsx.html +0 -559
  336. package/test-output/vitest/coverage/src/components/Switch/index.html +0 -131
  337. package/test-output/vitest/coverage/src/components/Switch/switch.variants.ts.html +0 -295
  338. package/test-output/vitest/coverage/src/components/Table/Table.tsx.html +0 -2677
  339. package/test-output/vitest/coverage/src/components/Table/cells/RenderButton.tsx.html +0 -154
  340. package/test-output/vitest/coverage/src/components/Table/cells/RenderChip.tsx.html +0 -385
  341. package/test-output/vitest/coverage/src/components/Table/cells/RenderText.tsx.html +0 -196
  342. package/test-output/vitest/coverage/src/components/Table/cells/RenderTwoLine.tsx.html +0 -187
  343. package/test-output/vitest/coverage/src/components/Table/cells/RowActionsMenu.tsx.html +0 -526
  344. package/test-output/vitest/coverage/src/components/Table/cells/index.html +0 -191
  345. package/test-output/vitest/coverage/src/components/Table/cells/index.ts.html +0 -127
  346. package/test-output/vitest/coverage/src/components/Table/index.html +0 -131
  347. package/test-output/vitest/coverage/src/components/Table/table.variants.ts.html +0 -706
  348. package/test-output/vitest/coverage/src/components/Tabs/Tabs.tsx.html +0 -283
  349. package/test-output/vitest/coverage/src/components/Tabs/index.html +0 -131
  350. package/test-output/vitest/coverage/src/components/Tabs/tabs.variants.ts.html +0 -292
  351. package/test-output/vitest/coverage/src/components/TextField/TextField.tsx.html +0 -820
  352. package/test-output/vitest/coverage/src/components/TextField/index.html +0 -131
  353. package/test-output/vitest/coverage/src/components/TextField/textField.variants.ts.html +0 -400
  354. package/test-output/vitest/coverage/src/components/Textarea/Textarea.tsx.html +0 -655
  355. package/test-output/vitest/coverage/src/components/Textarea/index.html +0 -131
  356. package/test-output/vitest/coverage/src/components/Textarea/textarea.variants.ts.html +0 -340
  357. package/test-output/vitest/coverage/src/components/Tooltip/Tooltip.tsx.html +0 -295
  358. package/test-output/vitest/coverage/src/components/Tooltip/index.html +0 -131
  359. package/test-output/vitest/coverage/src/components/Tooltip/tooltip.variants.ts.html +0 -169
  360. package/test-output/vitest/coverage/src/components/TopBar/TopBar.tsx.html +0 -283
  361. package/test-output/vitest/coverage/src/components/TopBar/index.html +0 -131
  362. package/test-output/vitest/coverage/src/components/TopBar/topBar.variants.ts.html +0 -199
  363. package/test-output/vitest/coverage/src/components/Typography/Typography.tsx.html +0 -421
  364. package/test-output/vitest/coverage/src/components/Typography/index.html +0 -131
  365. package/test-output/vitest/coverage/src/components/Typography/typography.variants.ts.html +0 -436
  366. package/test-output/vitest/coverage/src/components/VisuallyHidden/VisuallyHidden.tsx.html +0 -262
  367. package/test-output/vitest/coverage/src/components/VisuallyHidden/index.html +0 -116
  368. package/test-output/vitest/coverage/src/components/_shared/data/getNestedValue.ts.html +0 -181
  369. package/test-output/vitest/coverage/src/components/_shared/data/index.html +0 -236
  370. package/test-output/vitest/coverage/src/components/_shared/data/useColumnAutoDetect.ts.html +0 -385
  371. package/test-output/vitest/coverage/src/components/_shared/data/useControllableState.ts.html +0 -229
  372. package/test-output/vitest/coverage/src/components/_shared/data/useDebouncedValue.ts.html +0 -157
  373. package/test-output/vitest/coverage/src/components/_shared/data/useTableFilter.ts.html +0 -439
  374. package/test-output/vitest/coverage/src/components/_shared/data/useTableSearch.ts.html +0 -283
  375. package/test-output/vitest/coverage/src/components/_shared/data/useTableSelection.ts.html +0 -385
  376. package/test-output/vitest/coverage/src/components/_shared/data/useTableSort.ts.html +0 -508
  377. package/test-output/vitest/coverage/src/components/_shared/data/useVirtualizer.ts.html +0 -682
  378. package/test-output/vitest/coverage/src/components/_shared/index.html +0 -116
  379. package/test-output/vitest/coverage/src/components/_shared/resolveValidationState.ts.html +0 -265
  380. package/test-output/vitest/coverage/src/hooks/index.html +0 -116
  381. package/test-output/vitest/coverage/src/hooks/useAccessState.ts.html +0 -328
  382. package/test-output/vitest/coverage/src/index.html +0 -116
  383. package/test-output/vitest/coverage/src/index.ts.html +0 -1153
  384. package/test-output/vitest/coverage/src/utils/cn.ts.html +0 -172
  385. package/test-output/vitest/coverage/src/utils/index.html +0 -116
  386. package/tsconfig.json +0 -13
  387. package/tsconfig.lib.json +0 -58
  388. package/tsconfig.spec.json +0 -34
  389. package/vite.config.ts +0 -33
  390. package/vitest.config.mts +0 -29
@@ -1,1282 +0,0 @@
1
- import {
2
- useMemo,
3
- useState,
4
- useEffect,
5
- type ReactNode,
6
- type MouseEvent,
7
- type PointerEvent as RPointerEvent,
8
- } from 'react';
9
- import { cn } from '../../utils/cn.js';
10
- import { useAccessState } from '../../hooks/useAccessState.js';
11
- import { Skeleton } from '../Skeleton/Skeleton.js';
12
- import { Pagination } from '../Pagination/Pagination.js';
13
- import { dataGridVariants } from './dataGrid.variants.js';
14
- import { useControllableState } from '../_shared/data/useControllableState.js';
15
- import { useDebouncedValue } from '../_shared/data/useDebouncedValue.js';
16
- import { useTableSearch } from '../_shared/data/useTableSearch.js';
17
- import { useTableFilter } from '../_shared/data/useTableFilter.js';
18
- import { useTableSort, cycleSortFor } from '../_shared/data/useTableSort.js';
19
- import { useTableSelection } from '../_shared/data/useTableSelection.js';
20
- import { getNestedValue } from '../_shared/data/getNestedValue.js';
21
- import { useVirtualizer } from '../_shared/data/useVirtualizer.js';
22
- import {
23
- useColumnAutoDetect,
24
- resolveAlign,
25
- resolveMonospace,
26
- resolveTabularNums,
27
- } from '../_shared/data/useColumnAutoDetect.js';
28
- import type {
29
- TableColumn,
30
- TableColumnInferredType,
31
- TableFilterType,
32
- TableSortModel,
33
- TableFilterModel,
34
- TableLabels,
35
- } from '../Table/table.types.js';
36
- import type { DataGridProps } from './dataGrid.types.js';
37
- import { ColumnFilterTrigger } from './filters/ColumnFilters.js';
38
- import { ColumnVisibilityTrigger } from './visibility/ColumnVisibilityMenu.js';
39
- import { useColumnResize } from './resize/useColumnResize.js';
40
- import {
41
- useColumnReorder,
42
- type ColumnReorderHandlers,
43
- } from './reorder/useColumnReorder.js';
44
-
45
- const DEFAULT_LABELS: Required<TableLabels> = {
46
- searchPlaceholder: 'Search...',
47
- noData: 'No data',
48
- noResults: 'No matching results',
49
- loading: 'Loading…',
50
- ariaSortNone: 'Not sorted. Click to sort ascending.',
51
- ariaSortAscending: 'Sorted ascending. Click to sort descending.',
52
- ariaSortDescending: 'Sorted descending. Click to clear sort.',
53
- ariaSelectRow: 'Select row',
54
- ariaSelectAllRows: 'Select all rows',
55
- ariaExpandRow: 'Expand row',
56
- ariaCollapseRow: 'Collapse row',
57
- selectedCount: '{count} selected',
58
- clearSelection: 'Clear selection',
59
- filterColumn: 'Filter',
60
- filterApply: 'Apply',
61
- filterClear: 'Clear',
62
- filterMin: 'Min',
63
- filterMax: 'Max',
64
- filterFrom: 'From',
65
- filterTo: 'To',
66
- filterAll: 'All',
67
- filterTrue: 'True',
68
- filterFalse: 'False',
69
- density: 'Density',
70
- densityCompact: 'Compact',
71
- densityComfortable: 'Comfortable',
72
- densitySpacious: 'Spacious',
73
- columnsButton: 'Columns',
74
- columnsTitle: 'Toggle columns',
75
- columnsToggleAll: 'Toggle all columns',
76
- };
77
-
78
- /**
79
- * Dashforge TW `<DataGrid>` — virtualized data table.
80
- *
81
- * Companion to `<Table>` for large data sets (~500+ rows up to
82
- * millions via virtualization). Same column model, sort/search/
83
- * filter/selection logic (shared via `_shared/data/` helpers) —
84
- * differs in render path: only the visible window of rows is mounted
85
- * in DOM, with spacer `<tr>` above and below to preserve scrollbar
86
- * size.
87
- *
88
- * Virtualization: hand-rolled (`useVirtualizer`) using
89
- * `IntersectionObserver` + scroll-event + `requestAnimationFrame`
90
- * debounce + `ResizeObserver`. Zero new runtime deps.
91
- *
92
- * Server-side mode (4 independent opt-in flags):
93
- * - `serverSideSort` — emits `onSortChange` but does NOT sort locally
94
- * - `serverSideFilter` — emits `onFilterChange` but does NOT filter
95
- * - `serverSideSearch` — emits `onSearchQueryChange` (debounced)
96
- * - `serverSidePagination` — `totalCount` prop sizes the virtual
97
- * scrollbar; `rows` is the page slice from the server
98
- *
99
- * Selection at scale: `selectAllScope`:
100
- * - `'allLoaded'` (default) — header checkbox toggles all rows in
101
- * `rows` prop
102
- * - `'visible'` — toggles only the current viewport window
103
- */
104
- export function DataGrid<T extends object>(props: DataGridProps<T>) {
105
- const {
106
- rows,
107
- cols,
108
- getRowId,
109
- totalCount: totalCountProp,
110
-
111
- rowHeight,
112
- overscan = 5,
113
- height,
114
-
115
- sortModel: sortModelProp,
116
- onSortChange,
117
- defaultSortModel,
118
- serverSideSort = false,
119
-
120
- enableSearch = false,
121
- searchQuery: searchQueryProp,
122
- onSearchQueryChange,
123
- searchPlaceholder,
124
- searchDebounceMs = 200,
125
- serverSideSearch = false,
126
-
127
- filterModel: filterModelProp,
128
- onFilterChange,
129
- serverSideFilter = false,
130
-
131
- hiddenColumns: hiddenColumnsProp,
132
- onHiddenColumnsChange,
133
- enableColumnVisibility = true,
134
-
135
- columnWidths: columnWidthsProp,
136
- onColumnWidthsChange,
137
- enableColumnResize = true,
138
-
139
- columnOrder: columnOrderProp,
140
- onColumnOrderChange,
141
- enableColumnReorder = true,
142
-
143
- rowSelection = 'none',
144
- selectedRowIds: selectedRowIdsProp,
145
- onSelectionChange,
146
- bulkActions,
147
- selectAllScope = 'allLoaded',
148
-
149
- pagination,
150
- serverSidePagination = false,
151
-
152
- rowActions,
153
-
154
- loading = false,
155
- loadingRowCount = 8,
156
- emptyState,
157
-
158
- stickyHeader = true,
159
- caption,
160
- showCaption = false,
161
-
162
- access: gridAccess,
163
-
164
- labels: labelsProp,
165
-
166
- variant,
167
- size,
168
- density,
169
-
170
- sx,
171
- slotProps,
172
- } = props;
173
-
174
- const labels = { ...DEFAULT_LABELS, ...labelsProp };
175
- const gridAccessState = useAccessState(gridAccess);
176
-
177
- // ───── Controllable state ─────
178
-
179
- const [sortModel, setSortModel] = useControllableState<TableSortModel>({
180
- controlledValue: sortModelProp,
181
- defaultValue: defaultSortModel ?? [],
182
- onChange: onSortChange,
183
- });
184
- const [searchQuery, setSearchQuery] = useControllableState<string>({
185
- controlledValue: searchQueryProp,
186
- defaultValue: '',
187
- onChange: onSearchQueryChange,
188
- });
189
- // filterModel: in v1-bis the per-column header UI commits filter
190
- // items to this controllable state. Consumer can lift it via
191
- // filterModelProp + onFilterChange to drive server-side filtering.
192
- const [filterModel, setFilterModel] = useControllableState<TableFilterModel>({
193
- controlledValue: filterModelProp,
194
- defaultValue: [],
195
- onChange: onFilterChange,
196
- });
197
- const [selectedRowIds, setSelectedRowIds] = useControllableState<string[]>({
198
- controlledValue: selectedRowIdsProp,
199
- defaultValue: [],
200
- onChange: onSelectionChange,
201
- });
202
-
203
- // ───── Column visibility ─────
204
- // Seed default hidden set from `defaultHidden` flag on columns.
205
- // Memoized to avoid the seed shifting on every render — the
206
- // controllable state keeps internal state stable thereafter.
207
- const defaultHiddenColumns = useMemo(
208
- () =>
209
- cols
210
- .filter((c) => c.defaultHidden === true)
211
- .map((c) => c.field as string),
212
- [cols],
213
- );
214
- const [hiddenColumns, setHiddenColumns] = useControllableState<string[]>({
215
- controlledValue: hiddenColumnsProp,
216
- defaultValue: defaultHiddenColumns,
217
- onChange: onHiddenColumnsChange,
218
- });
219
-
220
- // ───── Column widths (resize state) ─────
221
- // Seed from any `col.width` declared statically. Internal state is
222
- // applied only when the user actually starts dragging; until then
223
- // we fall back to the static width from the column def.
224
- const defaultColumnWidths = useMemo(() => {
225
- const map: Record<string, number> = {};
226
- for (const c of cols) {
227
- if (typeof c.width === 'number') {
228
- map[c.field as string] = c.width;
229
- }
230
- }
231
- return map;
232
- }, [cols]);
233
- const [columnWidths, setColumnWidths] = useControllableState<
234
- Record<string, number>
235
- >({
236
- controlledValue: columnWidthsProp,
237
- defaultValue: defaultColumnWidths,
238
- onChange: onColumnWidthsChange,
239
- });
240
- const { startResize, nudge: nudgeColumnWidth } = useColumnResize({
241
- widths: columnWidths,
242
- onChange: setColumnWidths,
243
- });
244
-
245
- // ───── Column order (reorder state) ─────
246
- const defaultColumnOrder = useMemo(
247
- () => cols.map((c) => c.field as string),
248
- [cols],
249
- );
250
- const [columnOrder, setColumnOrder] = useControllableState<string[]>({
251
- controlledValue: columnOrderProp,
252
- defaultValue: defaultColumnOrder,
253
- onChange: onColumnOrderChange,
254
- });
255
- const reorderHandlers = useColumnReorder({
256
- order: columnOrder,
257
- onChange: setColumnOrder,
258
- });
259
-
260
- // Column reorder rides on native HTML5 drag-and-drop, whose
261
- // `dragstart` / `drop` events DO NOT fire for touch input. On a
262
- // coarse-pointer device the drag would be a dead affordance — so
263
- // we detect the primary pointer and gate reorder off there. Mouse
264
- // / trackpad / pen (fine pointer) keep the feature. A pointer-event
265
- // based reorder that also covers touch is tracked as a follow-up
266
- // in REFINEMENT-NOTES.md.
267
- const [coarsePointer, setCoarsePointer] = useState(false);
268
- useEffect(() => {
269
- if (typeof window === 'undefined' || !window.matchMedia) return;
270
- const mq = window.matchMedia('(pointer: coarse)');
271
- setCoarsePointer(mq.matches);
272
- const onChange = (e: MediaQueryListEvent) => setCoarsePointer(e.matches);
273
- mq.addEventListener('change', onChange);
274
- return () => mq.removeEventListener('change', onChange);
275
- }, []);
276
-
277
- // Apply the active order to the columns list. Cols not in the
278
- // order array (e.g. newly-added columns at runtime) are appended
279
- // in their original position from `cols`.
280
- const orderedCols = useMemo(() => {
281
- if (!columnOrder || columnOrder.length === 0) return cols;
282
- const byField = new Map(
283
- cols.map((c) => [c.field as string, c] as const),
284
- );
285
- const seen = new Set<string>();
286
- const result: typeof cols = [];
287
- for (const field of columnOrder) {
288
- const c = byField.get(field);
289
- if (c) {
290
- result.push(c);
291
- seen.add(field);
292
- }
293
- }
294
- for (const c of cols) {
295
- if (!seen.has(c.field as string)) result.push(c);
296
- }
297
- return result;
298
- }, [cols, columnOrder]);
299
-
300
- // ───── RBAC + visibility + reorder: derive final column list ─────
301
- // - `access.onUnauthorized === 'hide'` removes a column entirely.
302
- // - `hiddenColumns` is the user-toggled hidden set from the
303
- // column-visibility dialog.
304
- // - `orderedCols` is the user-reordered version of `cols`.
305
- // NOTE: filtering happens on `orderedCols` so the active order is
306
- // preserved through visibility changes.
307
- const visibleCols = useMemo(
308
- () =>
309
- orderedCols.filter((col) => {
310
- if (col.access && col.access.onUnauthorized === 'hide') return false;
311
- if (hiddenColumns.includes(col.field as string)) return false;
312
- return true;
313
- }),
314
- [orderedCols, hiddenColumns],
315
- );
316
-
317
- // ───── Smart-default column types ─────
318
- const columnTypes = useColumnAutoDetect(rows, visibleCols);
319
-
320
- // ───── Pipeline: search → filter → sort (skip when server-side) ─────
321
- //
322
- // Each pipeline hook is ALWAYS called (React hooks rules). The
323
- // server-side flags decide whether to use the local-computed result
324
- // or pass the upstream rows through unchanged. The hooks are
325
- // `useMemo`-based internally so they're cheap when their inputs
326
- // are unchanged.
327
-
328
- const debouncedSearchQuery = useDebouncedValue(searchQuery, searchDebounceMs);
329
- const localSearched = useTableSearch(rows, visibleCols, debouncedSearchQuery);
330
- const searchedRows = serverSideSearch ? rows : localSearched;
331
-
332
- const localFiltered = useTableFilter(searchedRows, filterModel);
333
- const filteredRows = serverSideFilter ? searchedRows : localFiltered;
334
-
335
- const localSorted = useTableSort(filteredRows, visibleCols, sortModel);
336
- const sortedRows = serverSideSort ? filteredRows : localSorted;
337
-
338
- // ───── Virtualization ─────
339
-
340
- // Effective row count for the virtual scrollbar:
341
- // - Client-side: actual sorted rows count
342
- // - Server-side pagination: caller-provided totalCount
343
- const effectiveTotalCount = serverSidePagination
344
- ? totalCountProp ?? sortedRows.length
345
- : sortedRows.length;
346
-
347
- const initialViewportHeight = height ? parseInt(height, 10) || 400 : 400;
348
- const { scrollRef, window: vWindow } = useVirtualizer({
349
- totalCount: effectiveTotalCount,
350
- rowHeight,
351
- overscan,
352
- initialViewportHeight,
353
- });
354
-
355
- // The rows actually mounted in DOM.
356
- const renderedRows = useMemo(() => {
357
- if (serverSidePagination) {
358
- // In server-side pagination, `rows` IS the page slice; we
359
- // render all of it (virtualization within the page is still
360
- // useful for very large page sizes).
361
- return rows.slice(vWindow.startIndex, vWindow.endIndex + 1);
362
- }
363
- return sortedRows.slice(vWindow.startIndex, vWindow.endIndex + 1);
364
- }, [serverSidePagination, rows, sortedRows, vWindow.startIndex, vWindow.endIndex]);
365
-
366
- // ───── Selection helpers ─────
367
-
368
- // For `selectAllScope='visible'`, the select-all scope is the
369
- // current window. For `'allLoaded'`, it's the whole sorted set.
370
- const selectAllPool = useMemo(() => {
371
- if (selectAllScope === 'visible') {
372
- return renderedRows.map((row, idx) =>
373
- getRowId(row, vWindow.startIndex + idx),
374
- );
375
- }
376
- return sortedRows.map((row, idx) => getRowId(row, idx));
377
- }, [selectAllScope, renderedRows, sortedRows, getRowId, vWindow.startIndex]);
378
-
379
- const selection = useTableSelection(rowSelection, selectedRowIds, setSelectedRowIds);
380
-
381
- const selectedRows = useMemo(
382
- () => sortedRows.filter((row, idx) => selection.isSelected(getRowId(row, idx))),
383
- [sortedRows, selection, getRowId],
384
- );
385
-
386
- // ───── Variant recipe ─────
387
- const v = dataGridVariants({ variant, size, density });
388
-
389
- // ───── Render ─────
390
-
391
- if (!gridAccessState.visible) return null;
392
-
393
- const isInteractive = !gridAccessState.disabled;
394
- const showSelectionColumn = rowSelection !== 'none';
395
- const showRowActionsColumn = rowActions != null;
396
-
397
- const totalColumnCount =
398
- visibleCols.length +
399
- (showSelectionColumn ? 1 : 0) +
400
- (showRowActionsColumn ? 1 : 0);
401
-
402
- return (
403
- <div
404
- className={cn(v.root(), sx, slotProps?.root?.className)}
405
- data-disabled={!isInteractive ? 'true' : undefined}
406
- >
407
- {/* ───── Toolbar ───── */}
408
- {(enableSearch || enableColumnVisibility) && (
409
- <div className={cn(v.toolbar(), slotProps?.toolbar?.className)}>
410
- {enableSearch && (
411
- <label className={cn(v.search(), slotProps?.search?.className)}>
412
- <span className="sr-only">{labels.searchPlaceholder}</span>
413
- <SearchIcon className="ml-2 shrink-0 text-neutral-500" />
414
- <input
415
- type="text"
416
- value={searchQuery}
417
- onChange={(e) => setSearchQuery(e.target.value)}
418
- placeholder={searchPlaceholder ?? labels.searchPlaceholder}
419
- disabled={!isInteractive}
420
- className={cn(
421
- 'flex-1 bg-transparent border-0 outline-none',
422
- 'px-2 py-1.5',
423
- 'placeholder:text-neutral-400',
424
- 'disabled:opacity-50 disabled:cursor-not-allowed',
425
- )}
426
- />
427
- </label>
428
- )}
429
- {enableColumnVisibility && (
430
- <ColumnVisibilityTrigger
431
- cols={cols.filter(
432
- (c) =>
433
- // RBAC-hidden columns are never offered in the menu.
434
- !c.access || c.access.onUnauthorized !== 'hide',
435
- )}
436
- hiddenColumns={hiddenColumns}
437
- onChange={setHiddenColumns}
438
- disabled={!isInteractive}
439
- labels={{
440
- columnsButton: labels.columnsButton,
441
- columnsTitle: labels.columnsTitle,
442
- columnsToggleAll: labels.columnsToggleAll,
443
- }}
444
- />
445
- )}
446
- </div>
447
- )}
448
-
449
- {/* ───── Scroll wrapper (bounded height — required for virt) ───── */}
450
- <div
451
- ref={scrollRef}
452
- className={cn(v.scroll(), slotProps?.scroll?.className)}
453
- style={height ? { height, maxHeight: height } : undefined}
454
- >
455
- {/*
456
- `aria-rowcount` announces the TRUE total to assistive tech —
457
- the virtualized DOM only holds the ~visible window, so without
458
- it a screen reader reports "row N of <window size>" instead of
459
- "row N of <dataset size>". `+ 1` accounts for the header row.
460
- Each `<tr>` carries a 1-based `aria-rowindex` (header = 1,
461
- data rows = absoluteIndex + 2). `-1` when the effective count
462
- is unknown/zero keeps it a valid (ignored) value.
463
- */}
464
- <table
465
- className={cn(v.table(), slotProps?.table?.className)}
466
- aria-rowcount={effectiveTotalCount > 0 ? effectiveTotalCount + 1 : -1}
467
- >
468
- {caption != null && (
469
- <caption className={cn(!showCaption && 'sr-only', 'py-2 text-sm text-neutral-500')}>
470
- {caption}
471
- </caption>
472
- )}
473
-
474
- <thead
475
- className={cn(
476
- stickyHeader ? v.thead() : 'bg-neutral-50',
477
- slotProps?.thead?.className,
478
- )}
479
- >
480
- <tr
481
- aria-rowindex={1}
482
- className={cn(v.headerRow(), slotProps?.headerRow?.className)}
483
- >
484
- {showSelectionColumn && (
485
- <th
486
- scope="col"
487
- className={cn(
488
- v.headerCell(),
489
- v.selectionCell(),
490
- v.stickyLeftHeaderCell(),
491
- slotProps?.headerCell?.className,
492
- slotProps?.selectionCell?.className,
493
- )}
494
- >
495
- {rowSelection === 'multiple' && (
496
- <input
497
- type="checkbox"
498
- aria-label={labels.ariaSelectAllRows}
499
- checked={selection.isAllSelected(selectAllPool)}
500
- ref={(el) => {
501
- if (el)
502
- el.indeterminate = selection.isIndeterminate(selectAllPool);
503
- }}
504
- onChange={() => selection.toggleAll(selectAllPool)}
505
- disabled={!isInteractive}
506
- className="cursor-pointer"
507
- />
508
- )}
509
- </th>
510
- )}
511
-
512
- {visibleCols.map((col) => (
513
- <HeaderCell
514
- key={col.field as string}
515
- col={col}
516
- sortModel={sortModel}
517
- onSortClick={(e) =>
518
- handleSortClick(col, e, sortModel, setSortModel)
519
- }
520
- inferredType={columnTypes.get(col.field as string)}
521
- filterModel={filterModel}
522
- onFilterChange={setFilterModel}
523
- effectiveWidth={resolveColumnWidth(col, columnWidths)}
524
- resizable={
525
- enableColumnResize && col.resizable !== false
526
- }
527
- startResize={startResize}
528
- nudgeColumnWidth={nudgeColumnWidth}
529
- reorderable={
530
- enableColumnReorder &&
531
- col.reorderable !== false &&
532
- !coarsePointer
533
- }
534
- reorderHandlers={reorderHandlers}
535
- labels={labels}
536
- className={cn(
537
- v.headerCell(),
538
- col.sticky === 'left' && v.stickyLeftHeaderCell(),
539
- col.sticky === 'right' && v.stickyRightHeaderCell(),
540
- slotProps?.headerCell?.className,
541
- )}
542
- buttonClassName={v.headerCellButton()}
543
- disabled={!isInteractive}
544
- />
545
- ))}
546
-
547
- {showRowActionsColumn && (
548
- <th
549
- scope="col"
550
- aria-hidden="true"
551
- className={cn(
552
- v.headerCell(),
553
- 'w-12',
554
- slotProps?.headerCell?.className,
555
- )}
556
- />
557
- )}
558
- </tr>
559
- </thead>
560
-
561
- <tbody className={cn(v.tbody(), slotProps?.tbody?.className)}>
562
- {loading
563
- ? renderLoadingRows({
564
- count: loadingRowCount,
565
- visibleCols,
566
- showSelectionColumn,
567
- showRowActionsColumn,
568
- rowHeight,
569
- rowClass: cn(v.row(), slotProps?.row?.className),
570
- cellClass: cn(v.cell(), slotProps?.cell?.className),
571
- })
572
- : sortedRows.length === 0
573
- ? renderEmptyState({
574
- totalColumnCount,
575
- emptyState,
576
- // Distinguish a genuinely empty dataset from one
577
- // emptied by an active search / filter (works for
578
- // server-side mode too — a query that returns 0
579
- // rows still reads as "no matching results").
580
- fallback:
581
- rows.length > 0 &&
582
- (debouncedSearchQuery.trim().length > 0 ||
583
- filterModel.length > 0)
584
- ? labels.noResults
585
- : labels.noData,
586
- cellClass: cn(
587
- v.cell(),
588
- v.emptyState(),
589
- slotProps?.emptyState?.className,
590
- ),
591
- })
592
- : renderVirtualizedBody({
593
- vWindow,
594
- rowHeight,
595
- renderedRows,
596
- visibleCols,
597
- columnTypes,
598
- columnWidths,
599
- selection,
600
- rowSelection,
601
- showSelectionColumn,
602
- showRowActionsColumn,
603
- rowActions,
604
- getRowId,
605
- isInteractive,
606
- labels,
607
- serverSidePagination,
608
- classes: {
609
- row: cn(v.row(), slotProps?.row?.className),
610
- cell: cn(v.cell(), slotProps?.cell?.className),
611
- selectionCell: cn(
612
- v.cell(),
613
- v.selectionCell(),
614
- v.stickyLeftCell(),
615
- slotProps?.cell?.className,
616
- slotProps?.selectionCell?.className,
617
- ),
618
- stickyLeftCell: v.stickyLeftCell(),
619
- stickyRightCell: v.stickyRightCell(),
620
- rowActionsCell: cn(
621
- v.cell(),
622
- v.rowActionsCell(),
623
- slotProps?.cell?.className,
624
- slotProps?.rowActionsCell?.className,
625
- ),
626
- },
627
- })}
628
- </tbody>
629
- </table>
630
- </div>
631
-
632
- {/* ───── Bulk action footer ───── */}
633
- {bulkActions && selectedRows.length > 0 && (
634
- <div
635
- className={cn(v.bulkActionFooter(), slotProps?.bulkActionFooter?.className)}
636
- role="region"
637
- aria-label={labels.selectedCount.replace(
638
- '{count}',
639
- String(selectedRows.length),
640
- )}
641
- >
642
- <span className="text-sm text-neutral-700">
643
- {labels.selectedCount.replace('{count}', String(selectedRows.length))}
644
- </span>
645
- <div className="flex items-center gap-2">
646
- {bulkActions(selectedRows)}
647
- <button
648
- type="button"
649
- onClick={selection.clearSelection}
650
- className={cn(
651
- 'text-sm text-neutral-500 hover:text-neutral-900',
652
- 'underline-offset-2 hover:underline',
653
- 'focus:outline-none focus-visible:underline',
654
- )}
655
- >
656
- {labels.clearSelection}
657
- </button>
658
- </div>
659
- </div>
660
- )}
661
-
662
- {/* ───── Optional pagination footer ───── */}
663
- {pagination && (
664
- <div className={cn(v.paginationFooter(), slotProps?.pagination?.className)}>
665
- <Pagination
666
- page={pagination.page}
667
- pageSize={pagination.pageSize}
668
- totalCount={totalCountProp ?? sortedRows.length}
669
- onPageChange={pagination.onPageChange}
670
- onPageSizeChange={pagination.onPageSizeChange}
671
- pageSizeOptions={pagination.pageSizeOptions}
672
- />
673
- </div>
674
- )}
675
- </div>
676
- );
677
- }
678
-
679
- // ───── Header cell ─────
680
-
681
- function HeaderCell<T extends object>(props: {
682
- col: TableColumn<T>;
683
- sortModel: TableSortModel;
684
- onSortClick: (e: MouseEvent<HTMLButtonElement>) => void;
685
- inferredType: string | undefined;
686
- filterModel: TableFilterModel;
687
- onFilterChange: (model: TableFilterModel) => void;
688
- effectiveWidth: number | undefined;
689
- resizable: boolean;
690
- startResize: (
691
- field: string,
692
- startWidth: number,
693
- clampMin: number,
694
- clampMax: number,
695
- ) => (e: RPointerEvent<HTMLElement>) => void;
696
- nudgeColumnWidth: (
697
- field: string,
698
- currentWidth: number,
699
- delta: number,
700
- clampMin: number,
701
- clampMax: number,
702
- ) => void;
703
- reorderable: boolean;
704
- reorderHandlers: ColumnReorderHandlers;
705
- labels: Required<TableLabels>;
706
- className: string;
707
- buttonClassName: string;
708
- disabled: boolean;
709
- }) {
710
- const {
711
- col,
712
- sortModel,
713
- onSortClick,
714
- inferredType,
715
- filterModel,
716
- onFilterChange,
717
- effectiveWidth,
718
- resizable,
719
- startResize,
720
- nudgeColumnWidth,
721
- reorderable,
722
- reorderHandlers,
723
- labels,
724
- className,
725
- buttonClassName,
726
- disabled,
727
- } = props;
728
-
729
- const align = resolveAlign(col, inferredType as never);
730
- const alignClass =
731
- align === 'right' ? 'text-right' : align === 'center' ? 'text-center' : 'text-left';
732
-
733
- const sortEntry = sortModel.find((s) => s.field === col.field);
734
- const ariaSort: 'ascending' | 'descending' | 'none' =
735
- sortEntry?.direction === 'asc'
736
- ? 'ascending'
737
- : sortEntry?.direction === 'desc'
738
- ? 'descending'
739
- : 'none';
740
-
741
- const headerContent =
742
- typeof col.header === 'function' ? col.header() : col.header;
743
-
744
- const cellStyle = {
745
- width: effectiveWidth != null ? `${effectiveWidth}px` : undefined,
746
- minWidth: col.minWidth != null ? `${col.minWidth}px` : undefined,
747
- flex: effectiveWidth != null ? undefined : col.flex,
748
- position: resizable || reorderable ? ('relative' as const) : undefined,
749
- };
750
-
751
- // Drop indicator for reorder: a 2px vertical bar at the LEFT or
752
- // RIGHT edge of this th when it's the active drop target.
753
- const dropTarget = reorderHandlers.dropTarget;
754
- const dropIndicatorClass =
755
- dropTarget != null && dropTarget.field === (col.field as string)
756
- ? dropTarget.side === 'left'
757
- ? 'before:absolute before:top-0 before:bottom-0 before:left-0 before:w-0.5 before:bg-primary-500'
758
- : 'after:absolute after:top-0 after:bottom-0 after:right-0 after:w-0.5 after:bg-primary-500'
759
- : '';
760
-
761
- const isDragging = reorderHandlers.draggingField === (col.field as string);
762
-
763
- // Drag attributes only attach when reorderable; we DO NOT make the
764
- // entire th `draggable` if it isn't — keeps the keyboard focus
765
- // behavior unchanged.
766
- const dragAttrs = reorderable
767
- ? {
768
- draggable: true,
769
- onDragStart: reorderHandlers.dragStart(col.field as string),
770
- onDragOver: reorderHandlers.dragOver(col.field as string),
771
- onDrop: reorderHandlers.drop(col.field as string),
772
- onDragEnd: reorderHandlers.dragEnd,
773
- }
774
- : {};
775
-
776
- // Resize bounds — shared by the pointer-drag and keyboard paths.
777
- const resizeMin = col.minWidth ?? 40;
778
- const resizeMax = col.maxWidth ?? 1200;
779
- // Keyboard nudge step: 16px, or 64px with Shift held (coarse).
780
- const measureWidth = (handle: HTMLElement): number =>
781
- effectiveWidth ??
782
- (handle.parentElement as HTMLElement | null)?.getBoundingClientRect()
783
- .width ??
784
- 120;
785
-
786
- const resizeHandle = resizable ? (
787
- <span
788
- role="separator"
789
- aria-orientation="vertical"
790
- aria-label={`Resize ${typeof col.header === 'string' ? col.header : col.field}`}
791
- // Width bounds announced to assistive tech on the separator.
792
- aria-valuemin={resizeMin}
793
- aria-valuemax={resizeMax}
794
- aria-valuenow={effectiveWidth ?? undefined}
795
- // Keyboard-operable: focusable + ArrowLeft/Right resize. WCAG 2.1
796
- // keyboard operability — the drag is no longer the only path.
797
- tabIndex={disabled ? -1 : 0}
798
- // D6 guard: the parent `<th>` is `draggable` when reorderable;
799
- // marking the handle non-draggable means grabbing the handle
800
- // starts a RESIZE, never a column-reorder drag.
801
- draggable={false}
802
- onPointerDown={(e) => {
803
- const startWidth = measureWidth(e.currentTarget);
804
- startResize(col.field as string, startWidth, resizeMin, resizeMax)(e);
805
- }}
806
- onKeyDown={(e) => {
807
- if (disabled) return;
808
- if (e.key !== 'ArrowLeft' && e.key !== 'ArrowRight') return;
809
- e.preventDefault();
810
- const step = (e.shiftKey ? 64 : 16) * (e.key === 'ArrowLeft' ? -1 : 1);
811
- const current = measureWidth(e.currentTarget);
812
- nudgeColumnWidth(
813
- col.field as string,
814
- current,
815
- step,
816
- resizeMin,
817
- resizeMax,
818
- );
819
- }}
820
- className={cn(
821
- 'absolute top-0 bottom-0 right-0 w-1.5',
822
- 'cursor-col-resize select-none touch-none',
823
- 'hover:bg-primary-300 active:bg-primary-400',
824
- 'focus:outline-none focus-visible:bg-primary-400',
825
- 'transition-colors motion-reduce:transition-none',
826
- )}
827
- />
828
- ) : null;
829
-
830
- const filterType = col.filterable
831
- ? resolveFilterType(col, inferredType as TableColumnInferredType | undefined)
832
- : null;
833
-
834
- const filterTrigger =
835
- col.filterable && filterType ? (
836
- <ColumnFilterTrigger
837
- field={col.field as string}
838
- filterType={filterType}
839
- filterModel={filterModel}
840
- onFilterChange={onFilterChange}
841
- disabled={disabled}
842
- labels={{
843
- filterColumn: labels.filterColumn,
844
- filterApply: labels.filterApply,
845
- filterClear: labels.filterClear,
846
- filterMin: labels.filterMin,
847
- filterMax: labels.filterMax,
848
- filterFrom: labels.filterFrom,
849
- filterTo: labels.filterTo,
850
- filterAll: labels.filterAll,
851
- filterTrue: labels.filterTrue,
852
- filterFalse: labels.filterFalse,
853
- }}
854
- />
855
- ) : null;
856
-
857
- // Layout strategy:
858
- // - sortable only → sort button is the cell content
859
- // - filterable only → header text + filter trigger in a flex row
860
- // - both → sort button + filter trigger in a flex row
861
- // - neither → plain header text
862
- const wrapperJustify =
863
- align === 'right'
864
- ? 'justify-end'
865
- : align === 'center'
866
- ? 'justify-center'
867
- : 'justify-start';
868
-
869
- if (col.sortable) {
870
- const sortButton = (
871
- <button
872
- type="button"
873
- onClick={onSortClick}
874
- disabled={disabled}
875
- aria-label={
876
- ariaSort === 'ascending'
877
- ? labels.ariaSortAscending
878
- : ariaSort === 'descending'
879
- ? labels.ariaSortDescending
880
- : labels.ariaSortNone
881
- }
882
- className={cn(
883
- buttonClassName,
884
- align === 'right' && 'flex-row-reverse',
885
- 'disabled:cursor-not-allowed disabled:opacity-50',
886
- )}
887
- >
888
- <span>{headerContent}</span>
889
- <SortIcon direction={sortEntry?.direction} />
890
- </button>
891
- );
892
- return (
893
- <th
894
- scope="col"
895
- aria-sort={ariaSort}
896
- className={cn(
897
- className,
898
- alignClass,
899
- dropIndicatorClass,
900
- isDragging && 'opacity-50',
901
- )}
902
- style={cellStyle}
903
- {...dragAttrs}
904
- >
905
- {filterTrigger ? (
906
- <div className={cn('flex items-center gap-1', wrapperJustify)}>
907
- {sortButton}
908
- {filterTrigger}
909
- </div>
910
- ) : (
911
- sortButton
912
- )}
913
- {resizeHandle}
914
- </th>
915
- );
916
- }
917
-
918
- return (
919
- <th
920
- scope="col"
921
- className={cn(
922
- className,
923
- alignClass,
924
- dropIndicatorClass,
925
- isDragging && 'opacity-50',
926
- )}
927
- style={cellStyle}
928
- {...dragAttrs}
929
- >
930
- {filterTrigger ? (
931
- <div className={cn('flex items-center gap-1', wrapperJustify)}>
932
- <span>{headerContent}</span>
933
- {filterTrigger}
934
- </div>
935
- ) : (
936
- headerContent
937
- )}
938
- {resizeHandle}
939
- </th>
940
- );
941
- }
942
-
943
- /**
944
- * Resolve the effective width (px) for a column. User-driven resize
945
- * (`columnWidths[field]`) wins over the static `col.width`. Returns
946
- * `undefined` if neither source has a width set — the consumer falls
947
- * back to the column's `flex` value or browser auto-layout.
948
- */
949
- function resolveColumnWidth<T extends object>(
950
- col: TableColumn<T>,
951
- columnWidths: Record<string, number>,
952
- ): number | undefined {
953
- const resized = columnWidths[col.field as string];
954
- if (resized != null) return resized;
955
- return col.width;
956
- }
957
-
958
- /**
959
- * Resolve the filter UI type for a column. Explicit `col.filterType`
960
- * wins; otherwise we map the auto-detected primitive type:
961
- * - `number` → number range
962
- * - `boolean` → true/false/all select
963
- * - `date` → date range
964
- * - anything else (string / unknown) → text contains
965
- */
966
- function resolveFilterType<T extends object>(
967
- col: TableColumn<T>,
968
- inferred: TableColumnInferredType | undefined,
969
- ): TableFilterType {
970
- if (col.filterType) return col.filterType;
971
- switch (inferred) {
972
- case 'number':
973
- return 'number';
974
- case 'boolean':
975
- return 'boolean';
976
- case 'date':
977
- return 'date';
978
- default:
979
- return 'text';
980
- }
981
- }
982
-
983
- // ───── Virtualized body ─────
984
-
985
- function renderVirtualizedBody<T extends object>(args: {
986
- vWindow: { startIndex: number; endIndex: number; paddingTop: number; paddingBottom: number };
987
- rowHeight: number;
988
- renderedRows: T[];
989
- visibleCols: TableColumn<T>[];
990
- columnTypes: Map<string, string>;
991
- columnWidths: Record<string, number>;
992
- selection: ReturnType<typeof useTableSelection>;
993
- rowSelection: 'none' | 'single' | 'multiple';
994
- showSelectionColumn: boolean;
995
- showRowActionsColumn: boolean;
996
- rowActions: ((row: T) => ReactNode) | undefined;
997
- getRowId: (row: T, index: number) => string;
998
- isInteractive: boolean;
999
- labels: Required<TableLabels>;
1000
- serverSidePagination: boolean;
1001
- classes: {
1002
- row: string;
1003
- cell: string;
1004
- selectionCell: string;
1005
- stickyLeftCell: string;
1006
- stickyRightCell: string;
1007
- rowActionsCell: string;
1008
- };
1009
- }): ReactNode {
1010
- const {
1011
- vWindow,
1012
- renderedRows,
1013
- visibleCols,
1014
- columnTypes,
1015
- columnWidths,
1016
- selection,
1017
- rowSelection,
1018
- showSelectionColumn,
1019
- showRowActionsColumn,
1020
- rowActions,
1021
- getRowId,
1022
- isInteractive,
1023
- labels,
1024
- classes,
1025
- } = args;
1026
-
1027
- return (
1028
- <>
1029
- {vWindow.paddingTop > 0 && (
1030
- <tr aria-hidden="true" style={{ height: vWindow.paddingTop }} />
1031
- )}
1032
- {renderedRows.map((row, localIdx) => {
1033
- const absoluteIdx = vWindow.startIndex + localIdx;
1034
- const rowId = getRowId(row, absoluteIdx);
1035
- const isSelected = selection.isSelected(rowId);
1036
- return (
1037
- <tr
1038
- key={rowId}
1039
- // 1-based row index in the FULL dataset (header row is 1,
1040
- // so data rows start at 2). Lets a screen reader announce
1041
- // the true position despite virtualization windowing.
1042
- aria-rowindex={absoluteIdx + 2}
1043
- data-selected={isSelected ? 'true' : 'false'}
1044
- aria-selected={rowSelection !== 'none' ? isSelected : undefined}
1045
- className={classes.row}
1046
- >
1047
- {showSelectionColumn && (
1048
- <td className={classes.selectionCell}>
1049
- <input
1050
- type="checkbox"
1051
- aria-label={labels.ariaSelectRow}
1052
- checked={isSelected}
1053
- onChange={() => selection.toggleRow(rowId)}
1054
- disabled={!isInteractive}
1055
- className="cursor-pointer"
1056
- />
1057
- </td>
1058
- )}
1059
- {visibleCols.map((col) => (
1060
- <DataCell
1061
- key={col.field as string}
1062
- col={col}
1063
- row={row}
1064
- rowIndex={absoluteIdx}
1065
- isSelected={isSelected}
1066
- inferredType={columnTypes.get(col.field as string)}
1067
- effectiveWidth={resolveColumnWidth(col, columnWidths)}
1068
- cellClass={classes.cell}
1069
- stickyLeftClass={classes.stickyLeftCell}
1070
- stickyRightClass={classes.stickyRightCell}
1071
- />
1072
- ))}
1073
- {showRowActionsColumn && rowActions && (
1074
- <td className={classes.rowActionsCell}>{rowActions(row)}</td>
1075
- )}
1076
- </tr>
1077
- );
1078
- })}
1079
- {vWindow.paddingBottom > 0 && (
1080
- <tr aria-hidden="true" style={{ height: vWindow.paddingBottom }} />
1081
- )}
1082
- </>
1083
- );
1084
- }
1085
-
1086
- // ───── Data cell ─────
1087
-
1088
- function DataCell<T extends object>(props: {
1089
- col: TableColumn<T>;
1090
- row: T;
1091
- rowIndex: number;
1092
- isSelected: boolean;
1093
- inferredType: string | undefined;
1094
- effectiveWidth: number | undefined;
1095
- cellClass: string;
1096
- stickyLeftClass: string;
1097
- stickyRightClass: string;
1098
- }) {
1099
- const {
1100
- col,
1101
- row,
1102
- rowIndex,
1103
- isSelected,
1104
- inferredType,
1105
- effectiveWidth,
1106
- cellClass,
1107
- stickyLeftClass,
1108
- stickyRightClass,
1109
- } = props;
1110
- const value = getNestedValue(row, col.field as string);
1111
- const align = resolveAlign(col, inferredType as never);
1112
- const tabularNums = resolveTabularNums(col, inferredType as never);
1113
- const monospace = resolveMonospace(col);
1114
- const alignClass =
1115
- align === 'right' ? 'text-right' : align === 'center' ? 'text-center' : 'text-left';
1116
-
1117
- const columnAccessState = col.access
1118
- ? {
1119
- hidden: col.access.onUnauthorized === 'hide',
1120
- disabled: col.access.onUnauthorized === 'disable',
1121
- readonly: col.access.onUnauthorized === 'readonly',
1122
- }
1123
- : null;
1124
-
1125
- const content = col.cellRenderer
1126
- ? col.cellRenderer({
1127
- row,
1128
- value,
1129
- rowIndex,
1130
- isSelected,
1131
- isExpanded: false, // DataGrid v1 doesn't support expansion (defer)
1132
- access: columnAccessState,
1133
- })
1134
- : renderDefaultCell(value);
1135
-
1136
- return (
1137
- <td
1138
- className={cn(
1139
- cellClass,
1140
- alignClass,
1141
- tabularNums && 'tabular-nums',
1142
- monospace && 'font-mono',
1143
- col.sticky === 'left' && stickyLeftClass,
1144
- col.sticky === 'right' && stickyRightClass,
1145
- )}
1146
- style={{
1147
- width: effectiveWidth != null ? `${effectiveWidth}px` : undefined,
1148
- minWidth: col.minWidth != null ? `${col.minWidth}px` : undefined,
1149
- }}
1150
- >
1151
- {content}
1152
- </td>
1153
- );
1154
- }
1155
-
1156
- // ───── Helpers ─────
1157
-
1158
- function renderDefaultCell(value: unknown): ReactNode {
1159
- if (value == null) return null;
1160
- if (typeof value === 'boolean') return value ? '✓' : '✗';
1161
- if (value instanceof Date) return value.toISOString().slice(0, 10);
1162
- if (typeof value === 'object') return JSON.stringify(value);
1163
- return value as ReactNode;
1164
- }
1165
-
1166
- function handleSortClick<T extends object>(
1167
- col: TableColumn<T>,
1168
- event: MouseEvent<HTMLButtonElement>,
1169
- current: TableSortModel,
1170
- setSortModel: (
1171
- next: TableSortModel | ((prev: TableSortModel) => TableSortModel),
1172
- ) => void,
1173
- ) {
1174
- if (!col.sortable) return;
1175
- const multi = event.shiftKey;
1176
- setSortModel((prev) => cycleSortFor(prev, col.field as string, multi));
1177
- }
1178
-
1179
- function renderLoadingRows<T extends object>(args: {
1180
- count: number;
1181
- visibleCols: TableColumn<T>[];
1182
- showSelectionColumn: boolean;
1183
- showRowActionsColumn: boolean;
1184
- rowHeight: number;
1185
- rowClass: string;
1186
- cellClass: string;
1187
- }): ReactNode {
1188
- const {
1189
- count,
1190
- visibleCols,
1191
- showSelectionColumn,
1192
- showRowActionsColumn,
1193
- rowHeight,
1194
- rowClass,
1195
- cellClass,
1196
- } = args;
1197
- return Array.from({ length: count }).map((_, i) => (
1198
- <tr
1199
- key={`loading-${i}`}
1200
- className={rowClass}
1201
- aria-busy="true"
1202
- style={{ height: rowHeight }}
1203
- >
1204
- {showSelectionColumn && (
1205
- <td className={cellClass}>
1206
- <Skeleton variant="rectangle" width="16px" height="16px" />
1207
- </td>
1208
- )}
1209
- {visibleCols.map((col) => (
1210
- <td key={col.field as string} className={cellClass}>
1211
- <Skeleton variant="text" width="80%" />
1212
- </td>
1213
- ))}
1214
- {showRowActionsColumn && (
1215
- <td className={cellClass}>
1216
- <Skeleton variant="rectangle" width="24px" height="24px" />
1217
- </td>
1218
- )}
1219
- </tr>
1220
- ));
1221
- }
1222
-
1223
- function renderEmptyState(args: {
1224
- totalColumnCount: number;
1225
- emptyState: ReactNode;
1226
- fallback: string;
1227
- cellClass: string;
1228
- }): ReactNode {
1229
- return (
1230
- <tr>
1231
- <td colSpan={args.totalColumnCount} className={args.cellClass}>
1232
- {args.emptyState ?? args.fallback}
1233
- </td>
1234
- </tr>
1235
- );
1236
- }
1237
-
1238
- // ───── Icons ─────
1239
-
1240
- function SortIcon(props: { direction?: 'asc' | 'desc' }) {
1241
- return (
1242
- <svg
1243
- width="0.75em"
1244
- height="0.75em"
1245
- viewBox="0 0 16 16"
1246
- fill="currentColor"
1247
- aria-hidden="true"
1248
- className="shrink-0 opacity-60 group-hover:opacity-100"
1249
- >
1250
- {props.direction === 'asc' ? (
1251
- <path d="M8 4l4 6H4z" />
1252
- ) : props.direction === 'desc' ? (
1253
- <path d="M8 12L4 6h8z" />
1254
- ) : (
1255
- <>
1256
- <path d="M8 3l3 4H5z" opacity="0.5" />
1257
- <path d="M8 13l-3-4h6z" opacity="0.5" />
1258
- </>
1259
- )}
1260
- </svg>
1261
- );
1262
- }
1263
-
1264
- function SearchIcon(props: { className?: string }) {
1265
- return (
1266
- <svg
1267
- width="0.875em"
1268
- height="0.875em"
1269
- viewBox="0 0 16 16"
1270
- fill="none"
1271
- stroke="currentColor"
1272
- strokeWidth="1.5"
1273
- strokeLinecap="round"
1274
- strokeLinejoin="round"
1275
- aria-hidden="true"
1276
- className={props.className}
1277
- >
1278
- <circle cx="7" cy="7" r="4.5" />
1279
- <path d="M11 11l3 3" />
1280
- </svg>
1281
- );
1282
- }