@alepha/ui 0.36.0 → 0.37.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 (288) hide show
  1. package/dist/account/$pageAccount.d.ts +1 -1
  2. package/dist/account/$pageAccount.d.ts.map +1 -1
  3. package/dist/account/$pageAccount.js.map +1 -1
  4. package/dist/account/AccountDisplay.d.ts +13 -0
  5. package/dist/account/AccountDisplay.d.ts.map +1 -0
  6. package/dist/account/AccountDisplay.js +48 -0
  7. package/dist/account/AccountDisplay.js.map +1 -0
  8. package/dist/account/AccountProfile.d.ts.map +1 -1
  9. package/dist/account/AccountProfile.js +14 -10
  10. package/dist/account/AccountProfile.js.map +1 -1
  11. package/dist/account/AccountRouter.d.ts +6 -6
  12. package/dist/account/AccountRouter.d.ts.map +1 -1
  13. package/dist/account/index.d.ts +5 -0
  14. package/dist/account/index.d.ts.map +1 -1
  15. package/dist/account/index.js +2 -1
  16. package/dist/admin/$pageAdmin.d.ts +1 -1
  17. package/dist/admin/$pageAdmin.d.ts.map +1 -1
  18. package/dist/admin/$pageAdmin.js.map +1 -1
  19. package/dist/admin/AdminAudits.js.map +1 -1
  20. package/dist/admin/AdminJobDetail.js.map +1 -1
  21. package/dist/admin/AdminJobs.js.map +1 -1
  22. package/dist/admin/AdminNotifications.js.map +1 -1
  23. package/dist/admin/AdminRouter.d.ts +14 -14
  24. package/dist/admin/AdminRouter.d.ts.map +1 -1
  25. package/dist/admin/AdminUserDetail.js.map +1 -1
  26. package/dist/admin/AdminUsers.js.map +1 -1
  27. package/dist/admin/ParameterHistoryItem.js.map +1 -1
  28. package/dist/ai/AiChat.d.ts +26 -39
  29. package/dist/ai/AiChat.d.ts.map +1 -1
  30. package/dist/ai/AiChat.js +65 -123
  31. package/dist/ai/AiChat.js.map +1 -1
  32. package/dist/ai/AiChatDock.d.ts +23 -0
  33. package/dist/ai/AiChatDock.d.ts.map +1 -0
  34. package/dist/ai/AiChatDock.js +90 -0
  35. package/dist/ai/AiChatDock.js.map +1 -0
  36. package/dist/ai/AiChatDockSlot.d.ts +15 -0
  37. package/dist/ai/AiChatDockSlot.d.ts.map +1 -0
  38. package/dist/ai/AiChatDockSlot.js +20 -0
  39. package/dist/ai/AiChatDockSlot.js.map +1 -0
  40. package/dist/ai/AiChatLauncher.d.ts +17 -0
  41. package/dist/ai/AiChatLauncher.d.ts.map +1 -0
  42. package/dist/ai/AiChatLauncher.js +42 -0
  43. package/dist/ai/AiChatLauncher.js.map +1 -0
  44. package/dist/ai/AiChatMessage.d.ts +7 -1
  45. package/dist/ai/AiChatMessage.d.ts.map +1 -1
  46. package/dist/ai/AiChatMessage.js +27 -7
  47. package/dist/ai/AiChatMessage.js.map +1 -1
  48. package/dist/ai/AiChatPanel.d.ts +71 -0
  49. package/dist/ai/AiChatPanel.d.ts.map +1 -0
  50. package/dist/ai/AiChatPanel.js +143 -0
  51. package/dist/ai/AiChatPanel.js.map +1 -0
  52. package/dist/ai/index.d.ts +8 -4
  53. package/dist/ai/index.d.ts.map +1 -1
  54. package/dist/ai/index.js +5 -1
  55. package/dist/ai/useAiChat.d.ts +17 -0
  56. package/dist/ai/useAiChat.d.ts.map +1 -1
  57. package/dist/ai/useAiChat.js +38 -17
  58. package/dist/ai/useAiChat.js.map +1 -1
  59. package/dist/auth/AuthLogin.d.ts +9 -0
  60. package/dist/auth/AuthLogin.d.ts.map +1 -1
  61. package/dist/auth/AuthLogin.js +2 -2
  62. package/dist/auth/AuthLogin.js.map +1 -1
  63. package/dist/auth/AuthRegister.d.ts +4 -1
  64. package/dist/auth/AuthRegister.d.ts.map +1 -1
  65. package/dist/auth/AuthRegister.js +1 -1
  66. package/dist/auth/AuthRegister.js.map +1 -1
  67. package/dist/auth/AuthResetPassword.d.ts +8 -0
  68. package/dist/auth/AuthResetPassword.d.ts.map +1 -1
  69. package/dist/auth/AuthResetPassword.js +2 -2
  70. package/dist/auth/AuthResetPassword.js.map +1 -1
  71. package/dist/auth/AuthRouter.d.ts +4 -4
  72. package/dist/auth/AuthRouter.d.ts.map +1 -1
  73. package/dist/core/Badge.d.ts.map +1 -1
  74. package/dist/core/Badge.js +7 -3
  75. package/dist/core/Badge.js.map +1 -1
  76. package/dist/core/Collapsible.d.ts +50 -0
  77. package/dist/core/Collapsible.d.ts.map +1 -0
  78. package/dist/core/Collapsible.js +70 -0
  79. package/dist/core/Collapsible.js.map +1 -0
  80. package/dist/core/Combobox.d.ts +7 -1
  81. package/dist/core/Combobox.d.ts.map +1 -1
  82. package/dist/core/Combobox.js +2 -2
  83. package/dist/core/Combobox.js.map +1 -1
  84. package/dist/core/PaneRail.d.ts +24 -7
  85. package/dist/core/PaneRail.d.ts.map +1 -1
  86. package/dist/core/PaneRail.js +24 -19
  87. package/dist/core/PaneRail.js.map +1 -1
  88. package/dist/core/Stepper.d.ts +36 -0
  89. package/dist/core/Stepper.d.ts.map +1 -0
  90. package/dist/core/Stepper.js +54 -0
  91. package/dist/core/Stepper.js.map +1 -0
  92. package/dist/core/index.d.ts +2 -0
  93. package/dist/core/index.d.ts.map +1 -1
  94. package/dist/core/index.js +3 -1
  95. package/dist/core/useToast.js +13 -13
  96. package/dist/core/useToast.js.map +1 -1
  97. package/dist/form/AutoForm.d.ts.map +1 -1
  98. package/dist/form/AutoForm.js +29 -0
  99. package/dist/form/AutoForm.js.map +1 -1
  100. package/dist/form/AutoFormErrorPopover.js +13 -3
  101. package/dist/form/AutoFormErrorPopover.js.map +1 -1
  102. package/dist/form/Control.d.ts +14 -1
  103. package/dist/form/Control.d.ts.map +1 -1
  104. package/dist/form/Control.js +12 -2
  105. package/dist/form/Control.js.map +1 -1
  106. package/dist/form/ControlDate.d.ts.map +1 -1
  107. package/dist/form/ControlDate.js +3 -0
  108. package/dist/form/ControlDate.js.map +1 -1
  109. package/dist/form/ControlDateRange.d.ts +12 -1
  110. package/dist/form/ControlDateRange.d.ts.map +1 -1
  111. package/dist/form/ControlDateRange.js +11 -1
  112. package/dist/form/ControlDateRange.js.map +1 -1
  113. package/dist/form/ControlNumber.d.ts.map +1 -1
  114. package/dist/form/ControlNumber.js +2 -0
  115. package/dist/form/ControlNumber.js.map +1 -1
  116. package/dist/form/ControlObject.d.ts.map +1 -1
  117. package/dist/form/ControlObject.js +15 -1
  118. package/dist/form/ControlObject.js.map +1 -1
  119. package/dist/form/ControlPassword.d.ts +4 -0
  120. package/dist/form/ControlPassword.d.ts.map +1 -1
  121. package/dist/form/ControlPassword.js +1 -0
  122. package/dist/form/ControlPassword.js.map +1 -1
  123. package/dist/form/ControlSelect.d.ts +23 -1
  124. package/dist/form/ControlSelect.d.ts.map +1 -1
  125. package/dist/form/ControlSelect.js +5 -0
  126. package/dist/form/ControlSelect.js.map +1 -1
  127. package/dist/form/ControlSelectCombobox.d.ts +11 -1
  128. package/dist/form/ControlSelectCombobox.d.ts.map +1 -1
  129. package/dist/form/ControlSelectCombobox.js +9 -1
  130. package/dist/form/ControlSelectCombobox.js.map +1 -1
  131. package/dist/form/ControlUpload.d.ts.map +1 -1
  132. package/dist/form/ControlUpload.js +1 -0
  133. package/dist/form/ControlUpload.js.map +1 -1
  134. package/dist/form/FormField.d.ts +5 -0
  135. package/dist/form/FormField.d.ts.map +1 -1
  136. package/dist/form/FormField.js +7 -0
  137. package/dist/form/FormField.js.map +1 -1
  138. package/dist/i18n/fr/uiFr.d.ts.map +1 -1
  139. package/dist/i18n/fr/uiFr.js +15 -0
  140. package/dist/i18n/fr/uiFr.js.map +1 -1
  141. package/dist/shell/$pageNav.d.ts +2 -2
  142. package/dist/shell/$pageNav.d.ts.map +1 -1
  143. package/dist/shell/$pageNav.js.map +1 -1
  144. package/dist/shell/AppShell.d.ts +6 -0
  145. package/dist/shell/AppShell.d.ts.map +1 -1
  146. package/dist/shell/AppShell.js +31 -27
  147. package/dist/shell/AppShell.js.map +1 -1
  148. package/dist/shell/ButtonSettings.d.ts +6 -2
  149. package/dist/shell/ButtonSettings.d.ts.map +1 -1
  150. package/dist/shell/ButtonSettings.js +17 -3
  151. package/dist/shell/ButtonSettings.js.map +1 -1
  152. package/dist/shell/ButtonSettingsVisionMenuItem.d.ts +16 -0
  153. package/dist/shell/ButtonSettingsVisionMenuItem.d.ts.map +1 -0
  154. package/dist/shell/ButtonSettingsVisionMenuItem.js +24 -0
  155. package/dist/shell/ButtonSettingsVisionMenuItem.js.map +1 -0
  156. package/dist/shell/ButtonVision.d.ts +28 -0
  157. package/dist/shell/ButtonVision.d.ts.map +1 -0
  158. package/dist/shell/ButtonVision.js +46 -0
  159. package/dist/shell/ButtonVision.js.map +1 -0
  160. package/dist/shell/index.d.ts +6 -3
  161. package/dist/shell/index.d.ts.map +1 -1
  162. package/dist/shell/index.js +2 -1
  163. package/dist/styles.css +57 -0
  164. package/dist/table/DataTable.d.ts.map +1 -1
  165. package/dist/table/DataTable.js +29 -4
  166. package/dist/table/DataTable.js.map +1 -1
  167. package/dist/table/DataTableColumnPicker.d.ts.map +1 -1
  168. package/dist/table/DataTableColumnPicker.js +1 -0
  169. package/dist/table/DataTableColumnPicker.js.map +1 -1
  170. package/dist/table/DataTableFilterBar.d.ts +1 -1
  171. package/dist/table/DataTableFilterBar.d.ts.map +1 -1
  172. package/dist/table/DataTableFilterBar.js +5 -108
  173. package/dist/table/DataTableFilterBar.js.map +1 -1
  174. package/dist/table/DataTableHeaderFilter.d.ts +51 -0
  175. package/dist/table/DataTableHeaderFilter.d.ts.map +1 -0
  176. package/dist/table/DataTableHeaderFilter.js +113 -0
  177. package/dist/table/DataTableHeaderFilter.js.map +1 -0
  178. package/dist/table/DataTableHeaderRow.d.ts +7 -0
  179. package/dist/table/DataTableHeaderRow.d.ts.map +1 -1
  180. package/dist/table/DataTableHeaderRow.js +92 -74
  181. package/dist/table/DataTableHeaderRow.js.map +1 -1
  182. package/dist/table/DataTableTabs.d.ts +42 -0
  183. package/dist/table/DataTableTabs.d.ts.map +1 -0
  184. package/dist/table/DataTableTabs.js +55 -0
  185. package/dist/table/DataTableTabs.js.map +1 -0
  186. package/dist/table/dataTableBaseProps.d.ts +12 -0
  187. package/dist/table/dataTableBaseProps.d.ts.map +1 -1
  188. package/dist/table/dataTablePersistence.d.ts.map +1 -1
  189. package/dist/table/dataTablePersistence.js +4 -2
  190. package/dist/table/dataTablePersistence.js.map +1 -1
  191. package/dist/table/dataTableTypes.d.ts +18 -0
  192. package/dist/table/dataTableTypes.d.ts.map +1 -1
  193. package/dist/table/index.d.ts +5 -2
  194. package/dist/table/index.d.ts.map +1 -1
  195. package/dist/table/index.js +2 -1
  196. package/dist/table/useDataTableColumns.d.ts.map +1 -1
  197. package/dist/table/useDataTableColumns.js +1 -0
  198. package/dist/table/useDataTableColumns.js.map +1 -1
  199. package/dist/table/useDataTableFilterModel.d.ts +110 -0
  200. package/dist/table/useDataTableFilterModel.d.ts.map +1 -0
  201. package/dist/table/useDataTableFilterModel.js +154 -0
  202. package/dist/table/useDataTableFilterModel.js.map +1 -0
  203. package/docs/packages-alepha-ui-account.md +4 -0
  204. package/docs/packages-alepha-ui-ai.md +5 -5
  205. package/docs/packages-alepha-ui-shell.md +4 -3
  206. package/docs/packages-alepha-ui-table.md +4 -2
  207. package/package.json +8 -8
  208. package/src/account/$pageAccount.tsx +5 -4
  209. package/src/account/AccountDisplay.tsx +58 -0
  210. package/src/account/AccountProfile.tsx +30 -42
  211. package/src/account/__tests__/AccountProfile.browser.spec.tsx +141 -0
  212. package/src/account/__tests__/AccountRecoveryCodes.browser.spec.tsx +1 -1
  213. package/src/account/index.ts +5 -0
  214. package/src/admin/$pageAdmin.tsx +5 -4
  215. package/src/admin/AdminAudits.tsx +1 -1
  216. package/src/admin/AdminJobDetail.tsx +1 -1
  217. package/src/admin/AdminJobs.tsx +1 -1
  218. package/src/admin/AdminNotifications.tsx +1 -1
  219. package/src/admin/AdminUserDetail.tsx +1 -1
  220. package/src/admin/AdminUsers.tsx +1 -1
  221. package/src/admin/ParameterHistoryItem.tsx +1 -1
  222. package/src/admin/__tests__/AdminFilesUsageCard.browser.spec.tsx +17 -9
  223. package/src/ai/AiChat.tsx +94 -183
  224. package/src/ai/AiChatDock.tsx +129 -0
  225. package/src/ai/AiChatDockSlot.tsx +23 -0
  226. package/src/ai/AiChatLauncher.tsx +58 -0
  227. package/src/ai/AiChatMessage.tsx +48 -9
  228. package/src/ai/AiChatPanel.tsx +252 -0
  229. package/src/ai/__tests__/AiChat.browser.spec.tsx +197 -5
  230. package/src/ai/index.ts +8 -4
  231. package/src/ai/useAiChat.ts +80 -14
  232. package/src/auth/AuthLogin.tsx +19 -4
  233. package/src/auth/AuthRegister.tsx +6 -3
  234. package/src/auth/AuthResetPassword.tsx +18 -8
  235. package/src/auth/__tests__/AuthCancel.browser.spec.tsx +129 -0
  236. package/src/core/Badge.tsx +7 -3
  237. package/src/core/Collapsible.tsx +95 -0
  238. package/src/core/Combobox.tsx +11 -3
  239. package/src/core/PaneRail.tsx +36 -20
  240. package/src/core/Stepper.tsx +118 -0
  241. package/src/core/__tests__/Badge.browser.spec.tsx +5 -5
  242. package/src/core/__tests__/Collapsible.browser.spec.tsx +88 -0
  243. package/src/core/__tests__/PaneRail.browser.spec.tsx +48 -0
  244. package/src/core/__tests__/Stepper.browser.spec.tsx +39 -0
  245. package/src/core/__tests__/primitiveSlots.spec.ts +7 -0
  246. package/src/core/index.ts +15 -0
  247. package/src/form/AutoForm.tsx +32 -0
  248. package/src/form/AutoFormErrorPopover.tsx +27 -6
  249. package/src/form/Control.tsx +22 -0
  250. package/src/form/ControlDate.tsx +3 -0
  251. package/src/form/ControlDateRange.tsx +87 -58
  252. package/src/form/ControlNumber.tsx +2 -0
  253. package/src/form/ControlObject.tsx +20 -1
  254. package/src/form/ControlPassword.tsx +5 -0
  255. package/src/form/ControlSelect.tsx +32 -1
  256. package/src/form/ControlSelectCombobox.tsx +82 -56
  257. package/src/form/ControlUpload.tsx +1 -0
  258. package/src/form/FormField.tsx +23 -1
  259. package/src/form/__tests__/ControlFieldErrors.browser.spec.tsx +253 -0
  260. package/src/form/__tests__/ControlValidateMode.browser.spec.tsx +217 -0
  261. package/src/form/__tests__/ControlVariantErrors.browser.spec.tsx +133 -0
  262. package/src/i18n/fr/uiFr.ts +19 -1
  263. package/src/markdown/css.d.ts +11 -0
  264. package/src/shell/$pageNav.tsx +6 -4
  265. package/src/shell/AppShell.tsx +7 -0
  266. package/src/shell/ButtonSettings.tsx +20 -5
  267. package/src/shell/ButtonSettingsVisionMenuItem.tsx +40 -0
  268. package/src/shell/ButtonVision.tsx +73 -0
  269. package/src/shell/__tests__/ButtonSettings.browser.spec.tsx +42 -2
  270. package/src/shell/__tests__/ButtonVision.browser.spec.tsx +73 -0
  271. package/src/shell/__tests__/visionTokens.spec.ts +104 -0
  272. package/src/shell/index.ts +6 -3
  273. package/src/styles.css +57 -0
  274. package/src/table/DataTable.tsx +52 -4
  275. package/src/table/DataTableColumnPicker.tsx +3 -0
  276. package/src/table/DataTableFilterBar.tsx +18 -191
  277. package/src/table/DataTableHeaderFilter.tsx +156 -0
  278. package/src/table/DataTableHeaderRow.tsx +78 -40
  279. package/src/table/DataTableTabs.tsx +114 -0
  280. package/src/table/__tests__/DataTableHeaderFilter.browser.spec.tsx +174 -0
  281. package/src/table/__tests__/DataTableStaleColumns.browser.spec.tsx +80 -0
  282. package/src/table/__tests__/DataTableTabs.browser.spec.tsx +72 -0
  283. package/src/table/dataTableBaseProps.ts +12 -0
  284. package/src/table/dataTablePersistence.ts +11 -5
  285. package/src/table/dataTableTypes.ts +18 -0
  286. package/src/table/index.ts +9 -2
  287. package/src/table/useDataTableColumns.ts +1 -0
  288. package/src/table/useDataTableFilterModel.tsx +240 -0
@@ -14,7 +14,10 @@ import type { DataTableBaseProps } from "./dataTableBaseProps.ts";
14
14
  import { DataTableBody } from "./DataTableBody.tsx";
15
15
  import { DataTableBulkBar } from "./DataTableBulkBar.tsx";
16
16
  import { DATA_TABLE_CELL_PADDING } from "./dataTableCellPadding.ts";
17
+ import type { DataTableFilterBarField } from "./DataTableFilterBar.tsx";
18
+ import { dataTableFilterBarFields } from "./dataTableFilterFields.ts";
17
19
  import { DataTableFooter, PAGE_SIZES } from "./DataTableFooter.tsx";
20
+ import { DataTableHeaderFilter } from "./DataTableHeaderFilter.tsx";
18
21
  import { DataTableHeaderRow } from "./DataTableHeaderRow.tsx";
19
22
  import {
20
23
  persistedColumns,
@@ -24,6 +27,7 @@ import {
24
27
  } from "./dataTablePersistence.ts";
25
28
  import { DATA_TABLE_SQUARE_RIGHT } from "./dataTableSquareRight.ts";
26
29
  import { DataTableSummaryPanel } from "./DataTableSummaryPanel.tsx";
30
+ import { DataTableTabs } from "./DataTableTabs.tsx";
27
31
  import { DataTableToolbar } from "./DataTableToolbar.tsx";
28
32
  import type {
29
33
  DataTableCellContext,
@@ -130,6 +134,33 @@ export const DataTable = <
130
134
  filtersKey,
131
135
  });
132
136
 
137
+ // The filters that sit in a column's header, by column: the first field
138
+ // naming a column wins it. Only for the bar the table draws itself - a
139
+ // caller's `filters.render` owns where its filters go, and the bar's rule
140
+ // that a set filter shows on it is what makes a header filter safe.
141
+ const headerFilters: Record<string, DataTableFilterBarField> = {};
142
+ if (untyped.filters && !untyped.filters.render && filterDefinition) {
143
+ for (const field of dataTableFilterBarFields(
144
+ untyped.filters.fields,
145
+ filterDefinition,
146
+ )) {
147
+ if (!field.column || field.hidden) continue;
148
+ if (!(field.column in headerFilters)) headerFilters[field.column] = field;
149
+ }
150
+ }
151
+ const headerFilter = (columnKey: string) => {
152
+ const field = headerFilters[columnKey];
153
+ if (!field || !form) return undefined;
154
+ return (
155
+ <DataTableHeaderFilter
156
+ form={form}
157
+ field={field}
158
+ shown={filterVisibility.shown}
159
+ onShownChange={filterVisibility.setShown}
160
+ />
161
+ );
162
+ };
163
+
133
164
  const {
134
165
  page,
135
166
  setPage,
@@ -462,6 +493,10 @@ export const DataTable = <
462
493
  !unpaged &&
463
494
  ((props.pageSizes ?? PAGE_SIZES).length > 0 ||
464
495
  Boolean(meta?.totalPages && meta.totalPages > 1));
496
+ const showTabs = Boolean(props.tabs?.length);
497
+ // The classes of the band that joins under the tabs: flattened top, no top
498
+ // border, `-mt-2` against the wrapper's gap, as below the summary.
499
+ const underTabs = showTabs && "-mt-2 rounded-t-none border-t-0";
465
500
  const showColumnPicker = !props.hideColumnPicker && allColumnKeys.length > 0;
466
501
  const showActionsMenu = !props.hideActionsMenu;
467
502
 
@@ -482,6 +517,13 @@ export const DataTable = <
482
517
  the wrapper's gap. The panel's own bottom border is the line
483
518
  between them.
484
519
  */}
520
+ {showTabs && (
521
+ <DataTableTabs
522
+ tabs={props.tabs!}
523
+ className={cn(squareRight?.top, flatTop, props.chromeClassName)}
524
+ />
525
+ )}
526
+
485
527
  {showSummary && (
486
528
  <DataTableSummaryPanel
487
529
  title={
@@ -493,7 +535,11 @@ export const DataTable = <
493
535
  cards={summary.cards}
494
536
  loading={summary.loading}
495
537
  content={hasSummaryContent ? summaryContent : undefined}
496
- className={cn(squareRight?.top, flatTop, props.chromeClassName)}
538
+ className={cn(
539
+ showTabs ? underTabs : squareRight?.top,
540
+ flatTop,
541
+ props.chromeClassName,
542
+ )}
497
543
  />
498
544
  )}
499
545
 
@@ -524,7 +570,7 @@ export const DataTable = <
524
570
  isRefreshing={isRefreshing}
525
571
  handleRefreshClick={handleRefreshClick}
526
572
  className={cn(
527
- showSummary
573
+ showSummary || showTabs
528
574
  ? "-mt-2 rounded-t-none border-t-0"
529
575
  : squareRight?.top,
530
576
  flatTop,
@@ -556,12 +602,13 @@ export const DataTable = <
556
602
  <div
557
603
  className={cn(
558
604
  "flex min-h-0 flex-1 flex-col overflow-auto rounded-md border",
559
- (showToolbar || showSummary) && "-mt-2 rounded-t-none border-t-0",
605
+ (showToolbar || showSummary || showTabs) &&
606
+ "-mt-2 rounded-t-none border-t-0",
560
607
  showFooter ? "rounded-b-none border-b-0" : squareRight?.bottom,
561
608
  flatRows,
562
609
  // With no toolbar and no summary the rows open the table, so
563
610
  // their top-right corner is the one `squareRight` squares.
564
- !showToolbar && !showSummary && squareRight?.top,
611
+ !showToolbar && !showSummary && !showTabs && squareRight?.top,
565
612
  // `<Table>` wraps the table in a container div whose classes it
566
613
  // hardcodes, and only this table needs that container to grow,
567
614
  // so the one class it needs is set from out here instead.
@@ -624,6 +671,7 @@ export const DataTable = <
624
671
  setSortTo={setSortTo}
625
672
  moveColumn={moveColumn}
626
673
  toggleColumn={toggleColumn}
674
+ headerFilter={headerFilter}
627
675
  />
628
676
  </TableHeader>
629
677
  <DataTableBody<T>
@@ -114,6 +114,9 @@ export const DataTableColumnPicker = <T,>(
114
114
  />
115
115
  <DropdownMenuCheckboxItem
116
116
  checked={props.visible.has(key)}
117
+ // The last visible column stays: a table of zero columns is
118
+ // rows of empty cells, never what the reader meant.
119
+ disabled={props.visible.has(key) && props.visible.size === 1}
117
120
  closeOnClick={false}
118
121
  onCheckedChange={() => props.onToggle(key)}
119
122
  className="flex-1"
@@ -1,26 +1,17 @@
1
- import { type ZObject, type ZType, z } from "alepha";
1
+ import type { ZObject, ZType } from "alepha";
2
2
  import type { FormModel } from "alepha/react/form";
3
- import { useFormValues } from "alepha/react/form";
4
3
  import { useI18n } from "alepha/react/i18n";
5
- import { Calendar, List, Search, Type } from "lucide-react";
6
4
  import { useEffect, useLayoutEffect, useRef } from "react";
7
5
 
8
6
  import { FilterSlot } from "../core/FilterSlot.tsx";
9
7
  import { Control } from "../form/Control.tsx";
10
- import type { SelectOption } from "../form/ControlSelect.tsx";
11
- import type { DataTableFilterAddType } from "./DataTableFilterAdd.tsx";
12
8
  import { DataTableFilterAdd } from "./DataTableFilterAdd.tsx";
13
9
  import { DataTableFilterControl } from "./DataTableFilterControl.tsx";
14
- import type { DataTableFilterOperatorOption } from "./DataTableFilterOperator.tsx";
15
- import {
16
- DATA_TABLE_FILTER_OPERATORS,
17
- DataTableFilterOperator,
18
- } from "./DataTableFilterOperator.tsx";
19
10
  import type {
20
11
  DataTableFilterFieldOptions,
21
- DataTableFilterMode,
22
12
  DataTableFilterPreset,
23
13
  } from "./dataTableTypes.ts";
14
+ import { useDataTableFilterModel } from "./useDataTableFilterModel.tsx";
24
15
 
25
16
  export interface DataTableFilterBarProps {
26
17
  /**
@@ -92,10 +83,22 @@ export interface DataTableFilterBarProps {
92
83
  */
93
84
  export const DataTableFilterBar = (props: DataTableFilterBarProps) => {
94
85
  const { tr } = useI18n();
95
- const values = useFormValues(props.form) as Record<string, unknown>;
86
+ const model = useDataTableFilterModel(props.form);
87
+ const {
88
+ values,
89
+ inputs,
90
+ isSet,
91
+ holds,
92
+ isLocked,
93
+ operatorKeyOf,
94
+ operatorOf,
95
+ kindOf,
96
+ placeholderOf,
97
+ labelOf,
98
+ iconOf,
99
+ clearField,
100
+ } = model;
96
101
  const dialog = props.variant === "dialog";
97
- const modeOf = (field: DataTableFilterBarField): DataTableFilterMode =>
98
- field.mode ?? (field.preset === "search" ? "locked" : "optional");
99
102
  const shown = props.shown;
100
103
  const root = useRef<HTMLDivElement>(null);
101
104
  // The filter to open once React has put it on screen. A REF, not state: the
@@ -105,160 +108,6 @@ export const DataTableFilterBar = (props: DataTableFilterBarProps) => {
105
108
  // Which filters held a value at the last commit - see the operator effect.
106
109
  const heldValue = useRef<Record<string, boolean>>({});
107
110
 
108
- const inputs = props.form.input as unknown as Record<
109
- string,
110
- { set: (value: unknown) => void } | undefined
111
- >;
112
-
113
- const isSet = (key: string): boolean => {
114
- const value = values[key];
115
- return Array.isArray(value) ? value.length > 0 : Boolean(value);
116
- };
117
-
118
- const operatorKeyOf = (field: DataTableFilterBarField) =>
119
- field.operatorKey ?? `${field.key}Op`;
120
-
121
- // Narrowing the list, by a value or by an operator standing on its own.
122
- const holds = (field: DataTableFilterBarField): boolean =>
123
- isSet(field.key) || values[operatorKeyOf(field)] !== undefined;
124
-
125
- const isLocked = (field: DataTableFilterBarField) =>
126
- modeOf(field) === "locked";
127
-
128
- const operatorsOf = (
129
- field: DataTableFilterBarField,
130
- ): DataTableFilterOperatorOption[] | undefined => {
131
- if (!field.operators || typeof field.operators !== "string") {
132
- return field.operators as DataTableFilterOperatorOption[] | undefined;
133
- }
134
- // The values come from the one table the filter schema is built from; only
135
- // the words are this bar's. A value is labelled the same in every preset
136
- // it appears in, so one entry per value covers all three.
137
- const not = tr("dataTable.operator.prefixNot", { default: "not" });
138
- const labels: Record<
139
- string,
140
- Omit<DataTableFilterOperatorOption, "value">
141
- > = {
142
- is: { label: tr("dataTable.operator.is", { default: "is" }) },
143
- not: {
144
- label: tr("dataTable.operator.isNot", { default: "is not" }),
145
- prefix: not,
146
- },
147
- any: { label: tr("dataTable.operator.anyOf", { default: "any of" }) },
148
- all: {
149
- label: tr("dataTable.operator.allOf", { default: "all of" }),
150
- prefix: tr("dataTable.operator.prefixAll", { default: "all" }),
151
- },
152
- none: {
153
- label: tr("dataTable.operator.noneOf", { default: "none of" }),
154
- prefix: not,
155
- },
156
- };
157
- return DATA_TABLE_FILTER_OPERATORS[field.operators].map((value) => ({
158
- value,
159
- label: labels[value]?.label ?? value,
160
- prefix: labels[value]?.prefix,
161
- }));
162
- };
163
-
164
- const operatorOf = (field: DataTableFilterBarField) => {
165
- const operators = operatorsOf(field);
166
- return (
167
- operators?.find(
168
- (operator) => operator.value === values[operatorKeyOf(field)],
169
- ) ?? operators?.[0]
170
- );
171
- };
172
-
173
- /**
174
- * The schema a field is read with, stripped of `.optional()`: its own, or
175
- * `z.string()` for the search preset.
176
- */
177
- const schemaOf = (field: DataTableFilterBarField): ZType | undefined =>
178
- field.schema
179
- ? z.schema.unwrap(field.schema)
180
- : field.preset === "search"
181
- ? z.string()
182
- : undefined;
183
-
184
- /**
185
- * The values an enum schema, or an array of one, allows. Empty for any
186
- * other schema.
187
- */
188
- const enumValuesOf = (field: DataTableFilterBarField): string[] => {
189
- const schema = schemaOf(field);
190
- if (!schema) return [];
191
- if (z.schema.isEnum(schema)) return z.schema.enumOptions(schema);
192
- if (z.schema.isArray(schema)) {
193
- const element = z.schema.unwrap(z.schema.element(schema));
194
- if (z.schema.isEnum(element)) return z.schema.enumOptions(element);
195
- }
196
- return [];
197
- };
198
-
199
- // Live data first, then the enum the schema declares. A bare string falls
200
- // back to the select's own label for it.
201
- const itemsOf = (
202
- field: DataTableFilterBarField,
203
- ): SelectOption[] | undefined => {
204
- if (typeof field.items === "function") return field.items(values);
205
- if (field.items) return field.items;
206
- const options = enumValuesOf(field);
207
- if (options.length === 0) return undefined;
208
- const optionLabel = field.optionLabel;
209
- return optionLabel
210
- ? options.map((value) => ({ value, label: optionLabel(value) }))
211
- : options;
212
- };
213
-
214
- // Classified in `Control`'s own order, so the menu names the control the
215
- // filter will actually draw.
216
- const kindOf = (field: DataTableFilterBarField): DataTableFilterAddType => {
217
- const schema = schemaOf(field);
218
- // Before the list test, as `Control` orders it: a range IS an array, and
219
- // tested as one it would be offered as a list and drawn as a calendar.
220
- if (schema && z.schema.isDateRange(schema)) return "date";
221
- if (
222
- field.items ||
223
- (schema && (z.schema.isEnum(schema) || z.schema.isArray(schema)))
224
- ) {
225
- return "list";
226
- }
227
- return "text";
228
- };
229
-
230
- const placeholderOf = (field: DataTableFilterBarField) =>
231
- field.placeholder ??
232
- field.control?.placeholder ??
233
- (field.preset === "search"
234
- ? tr("dataTable.search", { default: "Search" })
235
- : undefined);
236
-
237
- const labelOf = (field: DataTableFilterBarField) =>
238
- field.label ?? placeholderOf(field) ?? field.key;
239
-
240
- // Every filter has an icon, as every `Control` does: the caller's, the
241
- // search glyph for the search preset, else its kind's (the same glyphs the
242
- // controls fall back to). Without the last step a filter the caller gave no
243
- // icon was the one bare row of the add menu ("When", beside "Resource" and
244
- // "What").
245
- const iconOf = (field: DataTableFilterBarField) => {
246
- if (field.icon) return field.icon;
247
- if (field.preset === "search") return Search;
248
- const kind = kindOf(field);
249
- if (kind === "date") return Calendar;
250
- if (kind === "list") return List;
251
- return Type;
252
- };
253
-
254
- // A filter goes back to its default operator as its value goes: an
255
- // operator standing with nothing to qualify still counts as a filter in the
256
- // table's reset button and badge, while narrowing nothing.
257
- const clearField = (field: DataTableFilterBarField) => {
258
- inputs[field.key]?.set(undefined);
259
- if (field.operators) inputs[operatorKeyOf(field)]?.set(undefined);
260
- };
261
-
262
111
  useEffect(() => {
263
112
  const key = pendingOpen.current;
264
113
  if (!key) return;
@@ -362,7 +211,6 @@ export const DataTableFilterBar = (props: DataTableFilterBarProps) => {
362
211
  // In the dialog every filter is drawn like a locked one: no
363
212
  // clear-and-remove button, the control's own cross resets it.
364
213
  const removable = !dialog && !isLocked(field);
365
- const operators = operatorsOf(field);
366
214
  const operator = operatorOf(field);
367
215
  const label = labelOf(field);
368
216
  return (
@@ -389,13 +237,7 @@ export const DataTableFilterBar = (props: DataTableFilterBarProps) => {
389
237
  }
390
238
  >
391
239
  <Control
392
- {...field.control}
393
- input={inputs[field.key] as never}
394
- label=""
395
- icon={iconOf(field)}
396
- clearable
397
- placeholder={placeholderOf(field)}
398
- items={itemsOf(field)}
240
+ {...model.controlPropsOf(field)}
399
241
  // The filter's name, as the control's accessible name:
400
242
  // an empty select says only its placeholder, and a set
401
243
  // one only its value. A name the caller gave wins.
@@ -428,21 +270,6 @@ export const DataTableFilterBar = (props: DataTableFilterBarProps) => {
428
270
  ]
429
271
  .filter(Boolean)
430
272
  .join(" ")}
431
- // Sized from its content, not the trigger: the trigger
432
- // grows as the reader picks, and a popup tied to it would
433
- // widen under the cursor.
434
- popupClassName="w-max min-w-48"
435
- popupHeader={
436
- operators && (
437
- <DataTableFilterOperator
438
- options={operators}
439
- value={operator?.value}
440
- onChange={(value) =>
441
- inputs[operatorKeyOf(field)]?.set(value)
442
- }
443
- />
444
- )
445
- }
446
273
  />
447
274
  </DataTableFilterControl>
448
275
  </div>
@@ -0,0 +1,156 @@
1
+ import type { ZObject } from "alepha";
2
+ import type { FormModel } from "alepha/react/form";
3
+ import { useI18n } from "alepha/react/i18n";
4
+ import { Funnel } from "lucide-react";
5
+ import { useEffect, useRef, useState } from "react";
6
+
7
+ import { Popover, PopoverContent, PopoverTrigger } from "../core/Popover.tsx";
8
+ import { cn } from "../core/utils.ts";
9
+ import { Control } from "../form/Control.tsx";
10
+ import type { DataTableFilterBarField } from "./DataTableFilterBar.tsx";
11
+ import { useDataTableFilterModel } from "./useDataTableFilterModel.tsx";
12
+
13
+ export interface DataTableHeaderFilterProps {
14
+ /**
15
+ * The table's filter form, the one the bar writes.
16
+ */
17
+ form: FormModel<ZObject>;
18
+ /**
19
+ * The filter this funnel opens: a field of `filters.fields` naming this
20
+ * column in its `column`.
21
+ */
22
+ field: DataTableFilterBarField;
23
+ /**
24
+ * The filters on the bar, and how to change them: see
25
+ * `DataTableFilterBarProps.shown`. Read to take a filter emptied here back
26
+ * off the bar.
27
+ */
28
+ shown: readonly string[];
29
+ onShownChange: (shown: string[], act: boolean) => void;
30
+ }
31
+
32
+ /**
33
+ * The funnel in a column's header, and the filter it opens in place.
34
+ *
35
+ * ```text
36
+ * Status ⇅ ⏷ a dim funnel: the column can be filtered
37
+ * Status ⇅ ⏷ a filled, accent funnel: it is
38
+ * ```
39
+ *
40
+ * The funnel IS the control's trigger: a list or a date range opens its own
41
+ * popup from it (`Control`'s `trigger`), so the reader meets exactly the list
42
+ * the bar would have shown them, operator switch included, one click away
43
+ * from the column it narrows. A text filter has no popup of its own, so it
44
+ * gets a popover holding its box.
45
+ *
46
+ * **The bar still shows a filter set here.** The bar's own rule puts a
47
+ * filter holding a value on it, and that rule is not bent for this: a column
48
+ * scrolled off, hidden, or simply far from where the reader is looking would
49
+ * otherwise narrow the list with nothing on screen saying why.
50
+ *
51
+ * **Emptied here, it leaves the bar again**, when it is `optional` and came
52
+ * onto the bar by holding a value: a header used to try a filter and put it
53
+ * back would otherwise leave an empty "Any status" behind every time. Decided
54
+ * when the popup closes, never while it is open, and only for a filter that
55
+ * this popup emptied or that joined the bar while it was open: a filter the
56
+ * reader put on the bar themselves and opened here without changing stays.
57
+ *
58
+ * Built in #Q3288.
59
+ */
60
+ export const DataTableHeaderFilter = (props: DataTableHeaderFilterProps) => {
61
+ const { tr } = useI18n();
62
+ const model = useDataTableFilterModel(props.form);
63
+ const { field } = props;
64
+ const label = model.labelOf(field);
65
+ const active = model.holds(field);
66
+ const kind = model.kindOf(field);
67
+ // What the filter was as the popup opened: see the docblock.
68
+ const atOpen = useRef({ held: false, shown: false });
69
+ // Counts the closes. The check runs in an effect after the render a close
70
+ // causes, never in the close handler itself: a list closes in the SAME
71
+ // event that deselects its row, before the form has the empty value, so
72
+ // the handler would still read the filter as set.
73
+ const [closes, setCloses] = useState(0);
74
+
75
+ const onPopupOpenChange = (open: boolean) => {
76
+ if (open) {
77
+ atOpen.current = {
78
+ held: model.holds(field),
79
+ shown: props.shown.includes(field.key),
80
+ };
81
+ return;
82
+ }
83
+ setCloses((count) => count + 1);
84
+ };
85
+
86
+ useEffect(() => {
87
+ if (closes === 0) return;
88
+ if (model.modeOf(field) !== "optional") return;
89
+ if (model.holds(field)) return;
90
+ if (!props.shown.includes(field.key)) return;
91
+ if (!atOpen.current.held && atOpen.current.shown) return;
92
+ props.onShownChange(
93
+ props.shown.filter((key) => key !== field.key),
94
+ true,
95
+ );
96
+ }, [closes]);
97
+
98
+ const funnel = (
99
+ <button
100
+ type="button"
101
+ // How the header row's context menu finds it: "Filter" clicks it.
102
+ data-header-filter={field.key}
103
+ data-active={active ? "" : undefined}
104
+ aria-label={tr("dataTable.filterColumn", {
105
+ default: `Filter: ${label}`,
106
+ args: [label],
107
+ })}
108
+ className={cn(
109
+ "focus-visible:ring-ring/50 inline-flex size-5 shrink-0 items-center justify-center rounded-sm outline-none focus-visible:ring-2",
110
+ "hover:bg-foreground/5 transition-[opacity,color]",
111
+ // Dimmed at rest like the sort glyph beside it, so a row of them
112
+ // does not shout; the accent and the fill say "this one is set".
113
+ active
114
+ ? "text-primary"
115
+ : "text-muted-foreground opacity-50 hover:opacity-100",
116
+ )}
117
+ >
118
+ <Funnel
119
+ className="size-3.5"
120
+ fill={active ? "currentColor" : "none"}
121
+ aria-hidden
122
+ />
123
+ </button>
124
+ );
125
+
126
+ if (kind === "text") {
127
+ return (
128
+ <Popover onOpenChange={onPopupOpenChange}>
129
+ <PopoverTrigger render={funnel}>{funnel.props.children}</PopoverTrigger>
130
+ <PopoverContent align="start" className="w-64 p-2">
131
+ <Control
132
+ {...model.controlPropsOf(field)}
133
+ inputProps={{ "aria-label": label, ...field.control?.inputProps }}
134
+ // oxlint-disable-next-line jsx-a11y/no-autofocus -- the reader just opened this popover to type into its one field
135
+ autoFocus
136
+ />
137
+ </PopoverContent>
138
+ </Popover>
139
+ );
140
+ }
141
+
142
+ return (
143
+ // `inline-flex`, so the control's own field wrapper sits on the header's
144
+ // line rather than starting a block under the label.
145
+ <div className="inline-flex align-middle">
146
+ <Control
147
+ {...model.controlPropsOf(field)}
148
+ // The funnel names itself; a caller's field name would only replace
149
+ // "Filter: Status" with "Status" on a button that opens a list.
150
+ inputProps={undefined}
151
+ trigger={funnel}
152
+ onPopupOpenChange={onPopupOpenChange}
153
+ />
154
+ </div>
155
+ );
156
+ };