@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
@@ -8,7 +8,9 @@ import {
8
8
  ChevronRight,
9
9
  ChevronsUpDown,
10
10
  EyeOff,
11
+ Funnel,
11
12
  } from "lucide-react";
13
+ import { type ReactNode, useRef } from "react";
12
14
 
13
15
  import { Checkbox } from "../core/Checkbox.tsx";
14
16
  import {
@@ -46,6 +48,12 @@ export interface DataTableHeaderRowProps<T> {
46
48
  ) => void;
47
49
  moveColumn: (key: string, delta: -1 | 1) => void;
48
50
  toggleColumn: (id: string) => void;
51
+ /**
52
+ * The funnel a column's header carries, for a column some filter names in
53
+ * its `column`; `undefined` for every other column. See
54
+ * `DataTableHeaderFilter`.
55
+ */
56
+ headerFilter?: (columnKey: string) => ReactNode;
49
57
  }
50
58
 
51
59
  /**
@@ -67,9 +75,22 @@ export const DataTableHeaderRow = <T,>(props: DataTableHeaderRowProps<T>) => {
67
75
  toggleColumn,
68
76
  } = props;
69
77
  const { tr } = useI18n();
78
+ const row = useRef<HTMLTableRowElement>(null);
79
+
80
+ // The menu's "Filter" opens the funnel, so the filter is reachable from the
81
+ // keyboard menu too (Shift+F10). Clicked on the next frame: the menu is
82
+ // still closing on this one, and hands focus back to the header as it goes,
83
+ // which would close a popup opened under it.
84
+ const openFilter = (key: string) => {
85
+ requestAnimationFrame(() => {
86
+ row.current
87
+ ?.querySelector<HTMLElement>(`[data-header-filter="${key}"]`)
88
+ ?.click();
89
+ });
90
+ };
70
91
 
71
92
  return (
72
- <TableRow>
93
+ <TableRow ref={row}>
73
94
  {hasCheckbox && (
74
95
  <TableHead className={cn(props.headClassName, "w-10")}>
75
96
  <Checkbox
@@ -84,6 +105,7 @@ export const DataTableHeaderRow = <T,>(props: DataTableHeaderRowProps<T>) => {
84
105
  )}
85
106
  {visibleCols.map(([key, def], index) => {
86
107
  const sorted = def.sortable && sort?.field === (def.sortKey ?? key);
108
+ const filter = props.headerFilter?.(key);
87
109
  return (
88
110
  // ⚠️ The menu is on the HEADER and never on a body cell.
89
111
  // Overriding the browser's own menu is acceptable on
@@ -117,23 +139,28 @@ export const DataTableHeaderRow = <T,>(props: DataTableHeaderRowProps<T>) => {
117
139
  />
118
140
  }
119
141
  >
120
- {def.sortable ? (
121
- // A real button so keyboard and assistive-tech
122
- // users can sort — a th onClick is mouse-only.
123
- <button
124
- type="button"
125
- onClick={() => toggleSort(key, def)}
126
- className="group/sort hover:text-foreground inline-flex items-center gap-1 select-none"
127
- >
128
- <span
129
- className={cn(
130
- def.hint &&
131
- "decoration-muted-foreground/60 underline decoration-dotted underline-offset-4",
132
- )}
142
+ {/* One line: the label (or the sort button), then the funnel.
143
+ The funnel sits OUTSIDE the sort button, never in it - a
144
+ button nested in a button is invalid, and a click on it
145
+ would also sort. */}
146
+ <span className="inline-flex items-center gap-1">
147
+ {def.sortable ? (
148
+ // A real button so keyboard and assistive-tech
149
+ // users can sort — a th onClick is mouse-only.
150
+ <button
151
+ type="button"
152
+ onClick={() => toggleSort(key, def)}
153
+ className="group/sort hover:text-foreground inline-flex items-center gap-1 select-none"
133
154
  >
134
- {def.label}
135
- </span>
136
- {/* A sortable column says so at rest. The arrow
155
+ <span
156
+ className={cn(
157
+ def.hint &&
158
+ "decoration-muted-foreground/60 underline decoration-dotted underline-offset-4",
159
+ )}
160
+ >
161
+ {def.label}
162
+ </span>
163
+ {/* A sortable column says so at rest. The arrow
137
164
  used to appear only once a column WAS sorted,
138
165
  so an unsorted sortable header and a dead one
139
166
  were indistinguishable until you happened to
@@ -148,30 +175,32 @@ export const DataTableHeaderRow = <T,>(props: DataTableHeaderRowProps<T>) => {
148
175
 
149
176
  `aria-hidden` throughout: `aria-sort` on the
150
177
  `th` already states this to assistive tech. */}
151
- {sorted ? (
152
- sort?.direction === "asc" ? (
153
- <ArrowUp className="size-3.5" aria-hidden />
178
+ {sorted ? (
179
+ sort?.direction === "asc" ? (
180
+ <ArrowUp className="size-3.5" aria-hidden />
181
+ ) : (
182
+ <ArrowDown className="size-3.5" aria-hidden />
183
+ )
154
184
  ) : (
155
- <ArrowDown className="size-3.5" aria-hidden />
156
- )
157
- ) : (
158
- <ChevronsUpDown
159
- className="size-3.5 opacity-40 transition-opacity group-hover/sort:opacity-100"
160
- aria-hidden
161
- />
162
- )}
163
- </button>
164
- ) : (
165
- <span
166
- className={cn(
167
- "inline-flex items-center gap-1",
168
- def.hint &&
169
- "decoration-muted-foreground/60 underline decoration-dotted underline-offset-4",
170
- )}
171
- >
172
- {def.label}
173
- </span>
174
- )}
185
+ <ChevronsUpDown
186
+ className="size-3.5 opacity-40 transition-opacity group-hover/sort:opacity-100"
187
+ aria-hidden
188
+ />
189
+ )}
190
+ </button>
191
+ ) : (
192
+ <span
193
+ className={cn(
194
+ "inline-flex items-center gap-1",
195
+ def.hint &&
196
+ "decoration-muted-foreground/60 underline decoration-dotted underline-offset-4",
197
+ )}
198
+ >
199
+ {def.label}
200
+ </span>
201
+ )}
202
+ {filter}
203
+ </span>
175
204
  </ContextMenuTrigger>
176
205
  <ContextMenuContent>
177
206
  {/* Explicit directions rather than the header's
@@ -206,6 +235,15 @@ export const DataTableHeaderRow = <T,>(props: DataTableHeaderRowProps<T>) => {
206
235
  <ContextMenuSeparator />
207
236
  </>
208
237
  )}
238
+ {filter && (
239
+ <>
240
+ <ContextMenuItem onClick={() => openFilter(key)}>
241
+ <Funnel className="size-4" />
242
+ {tr("dataTable.filterColumnMenu", { default: "Filter" })}
243
+ </ContextMenuItem>
244
+ <ContextMenuSeparator />
245
+ </>
246
+ )}
209
247
  {/* Disabled at the ends rather than hidden: the pair
210
248
  is a fixed landmark, and an entry that appears
211
249
  and disappears as you move a column is harder to
@@ -0,0 +1,114 @@
1
+ import { Link } from "alepha/react/router";
2
+ import type { ComponentType, ReactNode } from "react";
3
+
4
+ import { cn } from "../core/utils.ts";
5
+
6
+ /**
7
+ * One tab of a table's tab band: a view of the same page, such as the users
8
+ * and the profiles of a team, or the open and the closed tickets.
9
+ */
10
+ export interface DataTableTab {
11
+ /** Unique among the tabs. */
12
+ key: string;
13
+ label: ReactNode;
14
+ icon?: ComponentType<{ className?: string }>;
15
+ /** Drawn as a pill after the label. Omitted, or `null`, draws none. */
16
+ count?: number | null;
17
+ /** Whether this is the tab on screen. The caller decides it. */
18
+ active?: boolean;
19
+ /** A route: the tab is a link, for tabs that are pages of their own. */
20
+ href?: string;
21
+ /** Called on a click, for tabs that switch state inside one page. */
22
+ onSelect?: () => void;
23
+ }
24
+
25
+ export interface DataTableTabsProps {
26
+ tabs: DataTableTab[];
27
+ className?: string;
28
+ }
29
+
30
+ /**
31
+ * The band of tabs that opens a table's frame, drawn like a browser's tabs:
32
+ * the active tab is a tile of the bar below it, flaring into the band at its
33
+ * two bottom corners, so the tab and the bar read as one surface. A resting
34
+ * tab is plain text, lit as a tile on hover, with a short divider between two
35
+ * resting neighbours.
36
+ *
37
+ * The band scrolls sideways when its tabs outrun it, and never vertically:
38
+ * `overflow-x-auto` alone computes `overflow-y` as `auto` too, so anything
39
+ * reaching past the band's bottom edge drew a vertical scrollbar wherever
40
+ * scrollbars are always shown. Its bottom line is therefore an inset shadow,
41
+ * not a border a tab would have to overlap: the tabs paint over it, so the
42
+ * active tile covers it and joins the bar, and everywhere else it stays the
43
+ * line between the band and what follows.
44
+ */
45
+ export const DataTableTabs = (props: DataTableTabsProps) => (
46
+ <div
47
+ role="tablist"
48
+ data-slot="data-table-tabs"
49
+ className={cn(
50
+ "bg-background flex items-end overflow-x-auto overflow-y-hidden rounded-md rounded-b-none border border-b-0 px-3 pt-1.5 shadow-[inset_0_-1px_0_0_var(--border)]",
51
+ props.className,
52
+ )}
53
+ >
54
+ {props.tabs.map((tab, index) => {
55
+ const Icon = tab.icon;
56
+ // A divider on the start edge of a resting tab that follows another
57
+ // resting tab, hidden while either of the two is hovered.
58
+ const divided =
59
+ !tab.active && index > 0 && !props.tabs[index - 1]!.active;
60
+ const className = cn(
61
+ "relative flex h-9 shrink-0 items-center gap-2 rounded-t-[0.625rem] px-4 text-sm font-medium transition-colors duration-150",
62
+ tab.active
63
+ ? // The ears: two squares outside the tile's bottom corners, each
64
+ // filled but for a quarter circle, so the tile's sides curve out
65
+ // into the band. Swapped under rtl, where the start is the right.
66
+ "bg-muted text-foreground before:absolute before:start-[-0.625rem] before:bottom-0 before:size-[0.625rem] before:bg-[image:radial-gradient(circle_at_0_0,transparent_0.625rem,var(--muted)_calc(0.625rem_+_0.5px))] before:content-[''] after:absolute after:end-[-0.625rem] after:bottom-0 after:size-[0.625rem] after:bg-[image:radial-gradient(circle_at_100%_0,transparent_0.625rem,var(--muted)_calc(0.625rem_+_0.5px))] after:content-[''] rtl:before:bg-[image:radial-gradient(circle_at_100%_0,transparent_0.625rem,var(--muted)_calc(0.625rem_+_0.5px))] rtl:after:bg-[image:radial-gradient(circle_at_0_0,transparent_0.625rem,var(--muted)_calc(0.625rem_+_0.5px))]"
67
+ : "text-muted-foreground hover:text-foreground hover:bg-[color-mix(in_oklab,var(--muted),transparent_40%)]",
68
+ divided &&
69
+ "before:bg-border before:absolute before:start-0 before:top-[30%] before:h-[40%] before:w-px before:content-[''] hover:before:opacity-0 [[role=tab]:hover+&]:before:opacity-0",
70
+ );
71
+ const content = (
72
+ <>
73
+ {Icon && <Icon className="size-4" />}
74
+ {tab.label}
75
+ {tab.count != null && (
76
+ <span
77
+ className={cn(
78
+ "rounded-full px-1.5 text-xs tabular-nums",
79
+ tab.active
80
+ ? "bg-primary/10 text-primary"
81
+ : "bg-muted text-muted-foreground",
82
+ )}
83
+ >
84
+ {tab.count}
85
+ </span>
86
+ )}
87
+ </>
88
+ );
89
+ return tab.href ? (
90
+ <Link
91
+ key={tab.key}
92
+ href={tab.href}
93
+ role="tab"
94
+ aria-selected={Boolean(tab.active)}
95
+ className={className}
96
+ onClick={tab.onSelect}
97
+ >
98
+ {content}
99
+ </Link>
100
+ ) : (
101
+ <button
102
+ key={tab.key}
103
+ type="button"
104
+ role="tab"
105
+ aria-selected={Boolean(tab.active)}
106
+ className={className}
107
+ onClick={tab.onSelect}
108
+ >
109
+ {content}
110
+ </button>
111
+ );
112
+ })}
113
+ </div>
114
+ );
@@ -0,0 +1,174 @@
1
+ import { fireEvent, render, screen, waitFor } from "@testing-library/react";
2
+ import { Alepha, z } from "alepha";
3
+ import { AlephaContext } from "alepha/react";
4
+ import { AlephaReactI18n } from "alepha/react/i18n";
5
+ import { AlephaReactRouter } from "alepha/react/router";
6
+ import { setupJsdomMocks } from "alepha/testing/react";
7
+ import { afterEach, beforeAll, describe, expect, it } from "vitest";
8
+
9
+ import { DataTable } from "../DataTable.tsx";
10
+ import type {
11
+ DataTableFilterFields,
12
+ DataTableFilterValues,
13
+ } from "../dataTableTypes.ts";
14
+
15
+ interface Row {
16
+ id: number;
17
+ title: string;
18
+ status: string;
19
+ owner: string;
20
+ }
21
+
22
+ const columns = {
23
+ title: { label: "Title", cell: (r: Row) => r.title },
24
+ status: { label: "Status", cell: (r: Row) => r.status },
25
+ owner: { label: "Owner", cell: (r: Row) => r.owner },
26
+ };
27
+
28
+ const filterFields = {
29
+ search: { preset: "search" },
30
+ status: {
31
+ schema: z.enum(["open", "closed"]),
32
+ label: "Status",
33
+ column: "status",
34
+ operators: "is",
35
+ items: [
36
+ { value: "open", label: "Open" },
37
+ { value: "closed", label: "Closed" },
38
+ ],
39
+ },
40
+ owner: { schema: z.string(), label: "Owner", column: "owner" },
41
+ } satisfies DataTableFilterFields;
42
+
43
+ type Filters = DataTableFilterValues<typeof filterFields>;
44
+
45
+ /**
46
+ * The funnel a filter's `column` puts in that column's header: it opens the
47
+ * filter in place, a set filter still shows on the bar, and a filter emptied
48
+ * from its header leaves the bar again.
49
+ */
50
+ describe("DataTableHeaderFilter", () => {
51
+ let alepha: Alepha | undefined;
52
+
53
+ beforeAll(() => {
54
+ setupJsdomMocks();
55
+ });
56
+
57
+ afterEach(async () => {
58
+ await alepha?.stop();
59
+ alepha = undefined;
60
+ window.localStorage.clear();
61
+ });
62
+
63
+ const mount = async () => {
64
+ alepha = Alepha.create().with(AlephaReactRouter).with(AlephaReactI18n);
65
+ await alepha.start();
66
+ const seen: Array<Filters | undefined> = [];
67
+ render(
68
+ <AlephaContext.Provider value={alepha}>
69
+ <DataTable<Row, typeof filterFields>
70
+ columns={columns}
71
+ filters={{ fields: filterFields }}
72
+ fetch={async ({ filters }) => {
73
+ seen.push({ ...filters });
74
+ return {
75
+ content: [
76
+ { id: 1, title: "Alpha", status: "open", owner: "Ada" },
77
+ ],
78
+ page: {
79
+ number: 0,
80
+ size: 20,
81
+ offset: 0,
82
+ numberOfElements: 1,
83
+ totalElements: 1,
84
+ totalPages: 1,
85
+ isEmpty: false,
86
+ isFirst: true,
87
+ isLast: true,
88
+ },
89
+ };
90
+ }}
91
+ />
92
+ </AlephaContext.Provider>,
93
+ );
94
+ await waitFor(() => expect(screen.getByText("Alpha")).toBeTruthy());
95
+ return { last: () => seen.at(-1) };
96
+ };
97
+
98
+ const funnel = (key: string) =>
99
+ document.querySelector<HTMLElement>(`[data-header-filter="${key}"]`);
100
+ const slot = (key: string) =>
101
+ document.querySelector(`[data-filter="${key}"]`);
102
+
103
+ /**
104
+ * Opens the Status funnel's list and picks `name`.
105
+ */
106
+ const pick = async (name: string) => {
107
+ fireEvent.keyDown(funnel("status")!, { key: "ArrowDown" });
108
+ fireEvent.click(await screen.findByRole("option", { name }));
109
+ };
110
+
111
+ it("draws a dim funnel on the columns a filter names, and on no other", async () => {
112
+ await mount();
113
+
114
+ expect(funnel("status")).toBeTruthy();
115
+ expect(funnel("owner")).toBeTruthy();
116
+ expect(funnel("title")).toBeNull();
117
+ expect(funnel("status")!.hasAttribute("data-active")).toBe(false);
118
+ // A combobox, not a button: the funnel IS the list's trigger.
119
+ expect(
120
+ screen.getByRole("combobox", { name: "Filter: Status" }),
121
+ ).toBeTruthy();
122
+ });
123
+
124
+ it("filters from the header, lights the funnel, and still shows the filter on the bar", async () => {
125
+ const table = await mount();
126
+ expect(slot("status")).toBeNull();
127
+
128
+ await pick("Open");
129
+
130
+ await waitFor(() => expect(table.last()?.status).toBe("open"));
131
+ expect(funnel("status")!.hasAttribute("data-active")).toBe(true);
132
+ await waitFor(() => expect(slot("status")).toBeTruthy());
133
+ });
134
+
135
+ it("takes a filter emptied from its header back off the bar", async () => {
136
+ const table = await mount();
137
+ await pick("Open");
138
+ await waitFor(() => expect(slot("status")).toBeTruthy());
139
+
140
+ // Pressing the selected row again deselects it, and the list closes.
141
+ await pick("Open");
142
+
143
+ await waitFor(() => expect(table.last()?.status).toBeUndefined());
144
+ await waitFor(() => expect(slot("status")).toBeNull());
145
+ expect(funnel("status")!.hasAttribute("data-active")).toBe(false);
146
+ });
147
+
148
+ it("opens a text filter's box in a popover", async () => {
149
+ const table = await mount();
150
+
151
+ fireEvent.click(funnel("owner")!);
152
+ const box = await screen.findByRole("textbox", { name: "Owner" });
153
+ fireEvent.change(box, { target: { value: "Ada" } });
154
+
155
+ await waitFor(() => expect(table.last()?.owner).toBe("Ada"));
156
+ expect(funnel("owner")!.hasAttribute("data-active")).toBe(true);
157
+ });
158
+
159
+ it("offers Filter in the column's context menu, and only there", async () => {
160
+ await mount();
161
+
162
+ fireEvent.contextMenu(screen.getByRole("columnheader", { name: /Title/ }));
163
+ await screen.findByRole("menuitem", { name: /Hide column/ });
164
+ expect(screen.queryByRole("menuitem", { name: "Filter" })).toBeNull();
165
+ fireEvent.keyDown(document.activeElement ?? document.body, {
166
+ key: "Escape",
167
+ });
168
+
169
+ fireEvent.contextMenu(screen.getByRole("columnheader", { name: /Status/ }));
170
+ fireEvent.click(await screen.findByRole("menuitem", { name: "Filter" }));
171
+
172
+ expect(await screen.findByRole("option", { name: "Open" })).toBeTruthy();
173
+ });
174
+ });
@@ -0,0 +1,80 @@
1
+ import { render, screen } from "@testing-library/react";
2
+ import { Alepha } from "alepha";
3
+ import { AlephaContext } from "alepha/react";
4
+ import { AlephaReactI18n } from "alepha/react/i18n";
5
+ import { AlephaReactRouter } from "alepha/react/router";
6
+ import { setupJsdomMocks } from "alepha/testing/react";
7
+ import { afterEach, beforeAll, describe, expect, it } from "vitest";
8
+
9
+ import { DataTable } from "../DataTable.tsx";
10
+
11
+ interface Row {
12
+ id: number;
13
+ title: string;
14
+ owner: string;
15
+ }
16
+
17
+ const rows: Row[] = [{ id: 1, title: "Alpha", owner: "ada" }];
18
+
19
+ /**
20
+ * A stored column set written by an older layout of the same table.
21
+ *
22
+ * The visible set is persisted as a list of column keys. When a table's
23
+ * columns are all renamed, the list a reader stored before names none of them,
24
+ * and it used to win: the table rendered its rows with zero columns, a row of
25
+ * empty cells and no header labels, for every reader who had once toggled a
26
+ * column. A set that keeps nothing now falls back to the declaration.
27
+ */
28
+ describe("DataTable (stale persisted columns)", () => {
29
+ let alepha: Alepha | undefined;
30
+
31
+ beforeAll(() => {
32
+ setupJsdomMocks();
33
+ });
34
+
35
+ afterEach(async () => {
36
+ await alepha?.stop();
37
+ alepha = undefined;
38
+ window.localStorage.clear();
39
+ });
40
+
41
+ const mount = async () => {
42
+ alepha = Alepha.create().with(AlephaReactRouter).with(AlephaReactI18n);
43
+ await alepha.start();
44
+ return render(
45
+ <AlephaContext.Provider value={alepha}>
46
+ <DataTable<Row>
47
+ persistenceKey="probe"
48
+ rowKey={(r) => String(r.id)}
49
+ data={rows}
50
+ columns={{
51
+ title: { label: "Title", cell: (r: Row) => r.title },
52
+ owner: { label: "Owner", cell: (r: Row) => r.owner },
53
+ }}
54
+ />
55
+ </AlephaContext.Provider>,
56
+ );
57
+ };
58
+
59
+ it("shows the declared columns when the stored set names none of them", async () => {
60
+ window.localStorage.setItem(
61
+ "probe.columns",
62
+ JSON.stringify(["name", "email"]),
63
+ );
64
+ await mount();
65
+ expect(await screen.findByText("Alpha")).toBeTruthy();
66
+ expect(screen.getByText("ada")).toBeTruthy();
67
+ expect(screen.getByText("Title")).toBeTruthy();
68
+ expect(screen.getByText("Owner")).toBeTruthy();
69
+ });
70
+
71
+ it("keeps a stored choice that still names a column", async () => {
72
+ window.localStorage.setItem(
73
+ "probe.columns",
74
+ JSON.stringify(["title", "email"]),
75
+ );
76
+ await mount();
77
+ expect(await screen.findByText("Alpha")).toBeTruthy();
78
+ expect(screen.queryByText("ada")).toBeNull();
79
+ });
80
+ });
@@ -0,0 +1,72 @@
1
+ import { fireEvent, render, screen } from "@testing-library/react";
2
+ import { Alepha } from "alepha";
3
+ import { AlephaContext } from "alepha/react";
4
+ import { AlephaReactI18n } from "alepha/react/i18n";
5
+ import { AlephaReactRouter } from "alepha/react/router";
6
+ import { setupJsdomMocks } from "alepha/testing/react";
7
+ import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";
8
+
9
+ import { DataTable } from "../DataTable.tsx";
10
+ import type { DataTableTab } from "../DataTableTabs.tsx";
11
+
12
+ interface Row {
13
+ id: number;
14
+ title: string;
15
+ }
16
+
17
+ const rows: Row[] = [{ id: 1, title: "Alpha" }];
18
+
19
+ describe("DataTable (tabs)", () => {
20
+ let alepha: Alepha | undefined;
21
+
22
+ beforeAll(() => {
23
+ setupJsdomMocks();
24
+ });
25
+
26
+ afterEach(async () => {
27
+ await alepha?.stop();
28
+ alepha = undefined;
29
+ });
30
+
31
+ const mount = async (tabs?: DataTableTab[]) => {
32
+ alepha = Alepha.create().with(AlephaReactRouter).with(AlephaReactI18n);
33
+ await alepha.start();
34
+ return render(
35
+ <AlephaContext.Provider value={alepha}>
36
+ <DataTable<Row>
37
+ rowKey={(r) => String(r.id)}
38
+ data={rows}
39
+ tabs={tabs}
40
+ columns={{ title: { label: "Title", cell: (r: Row) => r.title } }}
41
+ />
42
+ </AlephaContext.Provider>,
43
+ );
44
+ };
45
+
46
+ it("draws its tabs with their counts, the active one selected", async () => {
47
+ const onSelect = vi.fn();
48
+ await mount([
49
+ { key: "users", label: "Users", count: 2, active: true },
50
+ { key: "profiles", label: "Profiles", count: 4, onSelect },
51
+ ]);
52
+ const tabs = await screen.findAllByRole("tab");
53
+ expect(tabs.map((t) => t.textContent)).toEqual(["Users2", "Profiles4"]);
54
+ expect(tabs[0]!.getAttribute("aria-selected")).toBe("true");
55
+ expect(tabs[1]!.getAttribute("aria-selected")).toBe("false");
56
+ fireEvent.click(tabs[1]!);
57
+ expect(onSelect).toHaveBeenCalledOnce();
58
+ });
59
+
60
+ it("renders a link tab as an anchor", async () => {
61
+ await mount([{ key: "a", label: "A", href: "/a", active: true }]);
62
+ const tab = await screen.findByRole("tab");
63
+ expect(tab.tagName).toBe("A");
64
+ expect(tab.getAttribute("href")).toBe("/a");
65
+ });
66
+
67
+ it("draws no band without tabs", async () => {
68
+ await mount([]);
69
+ expect(await screen.findByText("Alpha")).toBeTruthy();
70
+ expect(screen.queryByRole("tablist")).toBeNull();
71
+ });
72
+ });
@@ -2,6 +2,7 @@ import type { ReactNode } from "react";
2
2
 
3
3
  import type { DataTableCellPadding } from "./dataTableCellPadding.ts";
4
4
  import type { DataTableSquareRight } from "./dataTableSquareRight.ts";
5
+ import type { DataTableTab } from "./DataTableTabs.tsx";
5
6
  import type {
6
7
  DataTableEmptyState,
7
8
  DataTableFilterFields,
@@ -404,6 +405,17 @@ export interface DataTableBaseProps<
404
405
  * is stated here rather than made uncompilable.
405
406
  */
406
407
  empty?: ReactNode;
408
+ /**
409
+ * Tabs that open the table's frame, above the summary and the toolbar:
410
+ * views of the same page, such as a team's users and its profiles, each
411
+ * with an optional count. Part of the table's chrome, so they read as the
412
+ * card's own header rather than a strip floating above it.
413
+ *
414
+ * A tab with `href` is a link (each tab its own route), one with
415
+ * `onSelect` a button; `active` marks the tab on screen. An empty list
416
+ * draws no band.
417
+ */
418
+ tabs?: DataTableTab[];
407
419
  /**
408
420
  * Free-form content rendered above the toolbar (e.g. a page title).
409
421
  *
@@ -138,13 +138,19 @@ export const persistedColumns = <T>(
138
138
  key: string | undefined,
139
139
  columns: Record<string, ColumnDef<T>>,
140
140
  ): Set<string> => {
141
- const stored = key ? readPersisted<string[]>(key, "columns") : undefined;
142
- if (stored) {
143
- return new Set(stored.filter((k) => k in columns));
144
- }
145
- return new Set(
141
+ const declared = new Set(
146
142
  Object.keys(columns).filter((k) => !columns[k]!.defaultHidden),
147
143
  );
144
+ const stored = key ? readPersisted<string[]>(key, "columns") : undefined;
145
+ if (!Array.isArray(stored)) return declared;
146
+ const kept = new Set(stored.filter((k) => k in columns));
147
+ // A stored set that names none of today's columns is a snapshot of an
148
+ // older layout, not a reader's choice: a table showing zero columns is not
149
+ // something anyone picks (the picker keeps the last one). It
150
+ // used to win anyway, so a table whose columns were all renamed opened as
151
+ // rows of empty cells, headers included, for everyone who had once toggled
152
+ // a column. The declaration wins instead.
153
+ return kept.size > 0 ? kept : declared;
148
154
  };
149
155
 
150
156
  /**