@noix-dev/brix-vue 0.0.0-stage → 0.2.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 (255) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +74 -2
  3. package/package.json +117 -3
  4. package/src/components/address-field/AddressField.vue +337 -0
  5. package/src/components/address-field/index.ts +1 -0
  6. package/src/components/appearance-picker/AppearancePicker.vue +502 -0
  7. package/src/components/appearance-picker/AppearanceSegment.vue +175 -0
  8. package/src/components/appearance-picker/index.ts +44 -0
  9. package/src/components/autofill/AutoFillDialog.vue +264 -0
  10. package/src/components/autofill/index.ts +1 -0
  11. package/src/components/badge/Badge.vue +23 -0
  12. package/src/components/badge/index.ts +106 -0
  13. package/src/components/build-stamp/BuildStamp.vue +62 -0
  14. package/src/components/build-stamp/index.ts +1 -0
  15. package/src/components/button/Button.vue +31 -0
  16. package/src/components/button/index.ts +122 -0
  17. package/src/components/card/Card.vue +29 -0
  18. package/src/components/card/CardAction.vue +17 -0
  19. package/src/components/card/CardContent.vue +14 -0
  20. package/src/components/card/CardDescription.vue +14 -0
  21. package/src/components/card/CardFooter.vue +22 -0
  22. package/src/components/card/CardHeader.vue +22 -0
  23. package/src/components/card/CardTitle.vue +29 -0
  24. package/src/components/card/index.ts +47 -0
  25. package/src/components/chart/BarChart.vue +123 -0
  26. package/src/components/chart/StackedBarChart.vue +149 -0
  27. package/src/components/chart/appearanceRevision.ts +22 -0
  28. package/src/components/chart/chartColor.ts +59 -0
  29. package/src/components/chart/index.ts +6 -0
  30. package/src/components/checkbox/Checkbox.vue +61 -0
  31. package/src/components/checkbox/index.ts +1 -0
  32. package/src/components/code-editor/CodeEditor.vue +352 -0
  33. package/src/components/code-editor/index.ts +9 -0
  34. package/src/components/code-editor/syntaxTheme.ts +110 -0
  35. package/src/components/colour-picker/ColourPicker.vue +421 -0
  36. package/src/components/colour-picker/index.ts +1 -0
  37. package/src/components/combobox/Combobox.vue +337 -0
  38. package/src/components/combobox/index.ts +1 -0
  39. package/src/components/comments/CommentComposer.vue +302 -0
  40. package/src/components/comments/CommentMessage.vue +259 -0
  41. package/src/components/comments/CommentThread.vue +250 -0
  42. package/src/components/comments/commentBody.ts +185 -0
  43. package/src/components/comments/commentLevels.ts +139 -0
  44. package/src/components/comments/commentNode.ts +35 -0
  45. package/src/components/comments/composer.ts +20 -0
  46. package/src/components/comments/index.ts +29 -0
  47. package/src/components/confirm-dialog/ConfirmDialog.vue +153 -0
  48. package/src/components/confirm-dialog/index.ts +1 -0
  49. package/src/components/containers/Box.vue +42 -0
  50. package/src/components/containers/Section.vue +88 -0
  51. package/src/components/containers/SectionAction.vue +17 -0
  52. package/src/components/containers/SectionContent.vue +14 -0
  53. package/src/components/containers/SectionDescription.vue +14 -0
  54. package/src/components/containers/SectionHeader.vue +22 -0
  55. package/src/components/containers/SectionTitle.vue +17 -0
  56. package/src/components/containers/index.ts +9 -0
  57. package/src/components/data-table/ColumnMenu.vue +241 -0
  58. package/src/components/data-table/DataTable.vue +447 -0
  59. package/src/components/data-table/ExpandCaret.vue +34 -0
  60. package/src/components/data-table/SortableHead.vue +184 -0
  61. package/src/components/data-table/TableLoadingRow.vue +13 -0
  62. package/src/components/data-table/TableProgressRow.vue +26 -0
  63. package/src/components/data-table/columns.ts +13 -0
  64. package/src/components/data-table/index.ts +3 -0
  65. package/src/components/data-table/pinned.ts +19 -0
  66. package/src/components/data-table/rowActivation.ts +14 -0
  67. package/src/components/data-table/sort.ts +13 -0
  68. package/src/components/data-table/types.ts +23 -0
  69. package/src/components/date-picker/CalendarPanel.vue +432 -0
  70. package/src/components/date-picker/DateField.vue +293 -0
  71. package/src/components/date-picker/DatePicker.vue +147 -0
  72. package/src/components/date-picker/UntilDatePicker.vue +96 -0
  73. package/src/components/date-picker/dateFieldGuard.ts +87 -0
  74. package/src/components/date-picker/index.ts +4 -0
  75. package/src/components/date-picker/useDateField.ts +37 -0
  76. package/src/components/date-range-picker/DateRangePicker.vue +247 -0
  77. package/src/components/date-range-picker/index.ts +1 -0
  78. package/src/components/date-time-picker/DateTimePicker.vue +291 -0
  79. package/src/components/date-time-picker/index.ts +1 -0
  80. package/src/components/dialog/Dialog.vue +250 -0
  81. package/src/components/dialog/DialogSurface.vue +214 -0
  82. package/src/components/dialog/dialogEdges.ts +65 -0
  83. package/src/components/dialog/dialogSizes.ts +35 -0
  84. package/src/components/dialog/index.ts +12 -0
  85. package/src/components/dialog/toastHost.ts +18 -0
  86. package/src/components/dropdown/Dropdown.vue +101 -0
  87. package/src/components/dropdown/DropdownItems.vue +154 -0
  88. package/src/components/dropdown/dropdown.ts +64 -0
  89. package/src/components/dropdown/index.ts +2 -0
  90. package/src/components/file-preview/FilePreview.vue +78 -0
  91. package/src/components/file-preview/index.ts +1 -0
  92. package/src/components/file-upload/FileUpload.vue +234 -0
  93. package/src/components/file-upload/index.ts +1 -0
  94. package/src/components/filter-check-menu/FilterCheckMenu.vue +562 -0
  95. package/src/components/filter-check-menu/filterCheckOption.ts +10 -0
  96. package/src/components/filter-check-menu/index.ts +2 -0
  97. package/src/components/form-field/FormField.vue +74 -0
  98. package/src/components/form-field/index.ts +2 -0
  99. package/src/components/form-field/types.ts +5 -0
  100. package/src/components/frames/FrameCentred.vue +137 -0
  101. package/src/components/frames/FrameSidebar.vue +113 -0
  102. package/src/components/frames/FrameSplit.vue +109 -0
  103. package/src/components/frames/index.ts +3 -0
  104. package/src/components/icon/BellIcon.vue +27 -0
  105. package/src/components/icon/BoldIcon.vue +31 -0
  106. package/src/components/icon/CalendarDaysIcon.vue +33 -0
  107. package/src/components/icon/CheckIcon.vue +31 -0
  108. package/src/components/icon/ChevronDownIcon.vue +30 -0
  109. package/src/components/icon/ChevronLeftIcon.vue +31 -0
  110. package/src/components/icon/ChevronRightIcon.vue +31 -0
  111. package/src/components/icon/ChevronUpIcon.vue +30 -0
  112. package/src/components/icon/CircleAlertIcon.vue +29 -0
  113. package/src/components/icon/ClockIcon.vue +31 -0
  114. package/src/components/icon/Columns3Icon.vue +32 -0
  115. package/src/components/icon/FlipHorizontalIcon.vue +29 -0
  116. package/src/components/icon/ItalicIcon.vue +28 -0
  117. package/src/components/icon/LinkIcon.vue +27 -0
  118. package/src/components/icon/ListIcon.vue +29 -0
  119. package/src/components/icon/ListOrderedIcon.vue +28 -0
  120. package/src/components/icon/PenLineIcon.vue +31 -0
  121. package/src/components/icon/PlusIcon.vue +28 -0
  122. package/src/components/icon/RotateCcwIcon.vue +28 -0
  123. package/src/components/icon/RotateCwIcon.vue +28 -0
  124. package/src/components/icon/SearchIcon.vue +31 -0
  125. package/src/components/icon/StarIcon.vue +29 -0
  126. package/src/components/icon/TriangleAlertIcon.vue +29 -0
  127. package/src/components/icon/UnderlineIcon.vue +27 -0
  128. package/src/components/icon/Undo2Icon.vue +28 -0
  129. package/src/components/icon/XIcon.vue +31 -0
  130. package/src/components/icon/ZoomInIcon.vue +30 -0
  131. package/src/components/icon/ZoomOutIcon.vue +29 -0
  132. package/src/components/icon/index.ts +37 -0
  133. package/src/components/icon-picker/IconPicker.vue +560 -0
  134. package/src/components/icon-picker/index.ts +1 -0
  135. package/src/components/image-crop-dialog/CropRatioRow.vue +132 -0
  136. package/src/components/image-crop-dialog/CropVariantStrip.vue +277 -0
  137. package/src/components/image-crop-dialog/ImageCropDialog.vue +1541 -0
  138. package/src/components/image-crop-dialog/index.ts +16 -0
  139. package/src/components/image-upload/ImageUpload.vue +345 -0
  140. package/src/components/image-upload/index.ts +2 -0
  141. package/src/components/input/Input.vue +48 -0
  142. package/src/components/input/index.ts +1 -0
  143. package/src/components/keycap/Keycap.vue +49 -0
  144. package/src/components/keycap/index.ts +1 -0
  145. package/src/components/label/Label.vue +26 -0
  146. package/src/components/label/index.ts +1 -0
  147. package/src/components/menu/MenuCheckboxItem.vue +63 -0
  148. package/src/components/menu/MenuContent.vue +45 -0
  149. package/src/components/menu/MenuGroup.vue +22 -0
  150. package/src/components/menu/MenuItem.vue +34 -0
  151. package/src/components/menu/MenuLabel.vue +22 -0
  152. package/src/components/menu/MenuRadioGroup.vue +22 -0
  153. package/src/components/menu/MenuRadioItem.vue +50 -0
  154. package/src/components/menu/MenuRoot.vue +25 -0
  155. package/src/components/menu/MenuSeparator.vue +27 -0
  156. package/src/components/menu/MenuSub.vue +29 -0
  157. package/src/components/menu/MenuSubContent.vue +48 -0
  158. package/src/components/menu/MenuSubTrigger.vue +49 -0
  159. package/src/components/menu/MenuTrigger.vue +22 -0
  160. package/src/components/menu/index.ts +20 -0
  161. package/src/components/menu/menuClasses.ts +74 -0
  162. package/src/components/morph-select/MorphSelect.vue +150 -0
  163. package/src/components/morph-select/index.ts +1 -0
  164. package/src/components/nav/NavFlyout.vue +343 -0
  165. package/src/components/nav/NavGroup.vue +306 -0
  166. package/src/components/nav/NavItem.vue +243 -0
  167. package/src/components/nav/NavNodes.ts +66 -0
  168. package/src/components/nav/NavSection.vue +105 -0
  169. package/src/components/nav/NavSidebar.vue +137 -0
  170. package/src/components/nav/index.ts +5 -0
  171. package/src/components/nav/navChain.ts +112 -0
  172. package/src/components/nav/navClasses.ts +229 -0
  173. package/src/components/nav/navNode.ts +10 -0
  174. package/src/components/nav/navRegistry.ts +24 -0
  175. package/src/components/notification-list/NotificationList.vue +314 -0
  176. package/src/components/notification-list/index.ts +2 -0
  177. package/src/components/notification-list/notifications.ts +21 -0
  178. package/src/components/pagination/Pagination.vue +296 -0
  179. package/src/components/pagination/index.ts +1 -0
  180. package/src/components/pin-field/PinField.vue +332 -0
  181. package/src/components/pin-field/index.ts +1 -0
  182. package/src/components/popover-panel/PopoverPanel.vue +115 -0
  183. package/src/components/popover-panel/index.ts +5 -0
  184. package/src/components/rating/Rating.vue +201 -0
  185. package/src/components/rating/index.ts +1 -0
  186. package/src/components/record-avatar/RecordAvatar.vue +76 -0
  187. package/src/components/record-avatar/index.ts +1 -0
  188. package/src/components/result-window/ResultWindow.vue +399 -0
  189. package/src/components/result-window/index.ts +2 -0
  190. package/src/components/result-window/results.ts +75 -0
  191. package/src/components/rich-editor/RichEditor.vue +370 -0
  192. package/src/components/rich-editor/RichEditorLinkDialog.vue +133 -0
  193. package/src/components/rich-editor/index.ts +8 -0
  194. package/src/components/row-actions/RowActions.vue +262 -0
  195. package/src/components/row-actions/index.ts +2 -0
  196. package/src/components/row-actions/rowActions.ts +44 -0
  197. package/src/components/search-select/SearchSelect.vue +599 -0
  198. package/src/components/search-select/index.ts +2 -0
  199. package/src/components/search-select/types.ts +14 -0
  200. package/src/components/segmented-choice/SegmentedChoice.vue +136 -0
  201. package/src/components/segmented-choice/index.ts +2 -0
  202. package/src/components/segmented-choice/segmentedOption.ts +6 -0
  203. package/src/components/select/Select.vue +18 -0
  204. package/src/components/select/SelectContent.vue +73 -0
  205. package/src/components/select/SelectGroup.vue +21 -0
  206. package/src/components/select/SelectItem.vue +47 -0
  207. package/src/components/select/SelectItemText.vue +12 -0
  208. package/src/components/select/SelectLabel.vue +17 -0
  209. package/src/components/select/SelectScrollDownButton.vue +36 -0
  210. package/src/components/select/SelectScrollUpButton.vue +36 -0
  211. package/src/components/select/SelectSeparator.vue +19 -0
  212. package/src/components/select/SelectTrigger.vue +52 -0
  213. package/src/components/select/SelectValue.vue +12 -0
  214. package/src/components/select/index.ts +11 -0
  215. package/src/components/session/IdleTimer.vue +71 -0
  216. package/src/components/session/SessionDialogs.vue +177 -0
  217. package/src/components/session/index.ts +2 -0
  218. package/src/components/split-button/SplitButton.vue +122 -0
  219. package/src/components/split-button/index.ts +2 -0
  220. package/src/components/split-button/splitButtonItem.ts +7 -0
  221. package/src/components/switch/Switch.vue +60 -0
  222. package/src/components/switch/index.ts +1 -0
  223. package/src/components/table/Table.vue +51 -0
  224. package/src/components/table/TableBody.vue +14 -0
  225. package/src/components/table/TableCaption.vue +17 -0
  226. package/src/components/table/TableCell.vue +22 -0
  227. package/src/components/table/TableEmpty.vue +72 -0
  228. package/src/components/table/TableFooter.vue +17 -0
  229. package/src/components/table/TableHead.vue +22 -0
  230. package/src/components/table/TableHeader.vue +14 -0
  231. package/src/components/table/TableRow.vue +22 -0
  232. package/src/components/table/index.ts +9 -0
  233. package/src/components/tabs/Tabs.vue +173 -0
  234. package/src/components/tabs/index.ts +2 -0
  235. package/src/components/tabs/tabItem.ts +12 -0
  236. package/src/components/textarea/LimitedTextarea.vue +81 -0
  237. package/src/components/textarea/TextLimitCounter.vue +107 -0
  238. package/src/components/textarea/Textarea.vue +42 -0
  239. package/src/components/textarea/index.ts +4 -0
  240. package/src/components/textarea/textLimit.ts +43 -0
  241. package/src/components/time-picker/TimePicker.vue +522 -0
  242. package/src/components/time-picker/index.ts +1 -0
  243. package/src/components/toast/ToastHost.vue +276 -0
  244. package/src/components/toast/index.ts +1 -0
  245. package/src/components/update-notice/UpdateNotice.vue +103 -0
  246. package/src/components/update-notice/index.ts +1 -0
  247. package/src/components/user-menu/UserMenu.vue +154 -0
  248. package/src/components/user-menu/index.ts +1 -0
  249. package/src/index.ts +182 -0
  250. package/src/lib/cn.ts +21 -0
  251. package/src/lib/panelFocus.ts +65 -0
  252. package/src/lib/sessionMonitor.ts +390 -0
  253. package/src/lib/slotContent.ts +17 -0
  254. package/src/lib/updateCheck.ts +133 -0
  255. package/src/styles.css +82 -0
@@ -0,0 +1,447 @@
1
+ <script setup lang="ts" generic="T">
2
+ import { useUiLabels } from '@noix-dev/brix-core';
3
+ import { computed, type FunctionalComponent, h } from 'vue';
4
+ import { cn } from '../../lib/cn';
5
+ import {
6
+ Table,
7
+ TableBody,
8
+ TableCell,
9
+ TableEmpty,
10
+ TableHead,
11
+ TableHeader,
12
+ TableRow,
13
+ } from '../table';
14
+ import ColumnMenu from './ColumnMenu.vue';
15
+ import ExpandCaret from './ExpandCaret.vue';
16
+ import { defaultVisibleKeys } from './columns';
17
+ import { PINNED, PINNED_HOVER_WASH, PINNED_WASH } from './pinned';
18
+ import { isRowActivationTarget } from './rowActivation';
19
+ import { nextSort } from './sort';
20
+ import SortableHead from './SortableHead.vue';
21
+ import TableLoadingRow from './TableLoadingRow.vue';
22
+ import TableProgressRow from './TableProgressRow.vue';
23
+ import type { DataTableColumn, TableSort } from './types';
24
+
25
+ /**
26
+ * A table that sorts, hides and shows columns, activates rows, opens a panel under a row,
27
+ * folds rows under group headers, and pins a trailing actions cell against the right edge
28
+ * while wide columns scroll. It composes the `table` primitives and draws nothing they
29
+ * already draw: the empty and the first-load state are `TableEmpty`, and `aria-busy` is the
30
+ * `Table`'s own.
31
+ *
32
+ * WHAT THE CALLER OWNS. Everything that changes is the caller's: `visibleKeys`, `sort`,
33
+ * `expandedKeys` and `collapsedGroups` come in as props and go out as `update:*` events; the
34
+ * table asks for a change and draws what it is given back.
35
+ *
36
+ * EVERY COLUMN HIDDEN. `visibleKeys` is the caller's, so it can name nothing that exists (a
37
+ * stored preference outliving a column). The column menu never offers that state, but the
38
+ * prop can still be there, and rows with no cells would collapse the table to nothing with no
39
+ * way to say why. Instead the table keeps its head, its toolbar and its column menu, and
40
+ * draws the empty state across what is left — so the way back is still on screen.
41
+ *
42
+ * WORDING comes from the label contract (`tableEmpty`, `tableLoading`, `tableExpandRow`,
43
+ * `tableCollapseRow`, `tableExpandGroup`, `tableCollapseGroup`, `tableActions`, and the column
44
+ * menu's and the sort menu's). `emptyText` and `loadingText` beat it for one call site.
45
+ *
46
+ * THE GLYPHS are slots (ADR 0013): `expand-icon` for every row caret and group caret, and
47
+ * `columns-icon`, `chevron-icon` and `search-icon` for the column menu.
48
+ */
49
+ const props = withDefaults(
50
+ defineProps<{
51
+ columns: DataTableColumn[];
52
+ rows: T[];
53
+ rowKey: (row: T) => string | number;
54
+ visibleKeys: string[];
55
+ sort: TableSort;
56
+ loading?: boolean;
57
+ // Announced while loading, on the first-load spinner and as the reload bar's label.
58
+ // Defaults to the contract's `tableLoading`.
59
+ loadingText?: string;
60
+ // Said when there is nothing to show. Defaults to the contract's `tableEmpty`.
61
+ emptyText?: string;
62
+ // When true, a click on a row's data cells emits `rowActivate` and rows show a
63
+ // pointer cursor; what that means — opening the record, expanding the row — is the
64
+ // caller's to decide. Clicks on genuine controls (links, the kebab + its menu, form
65
+ // fields), on the trailing actions cell and inside an expanded panel keep their own
66
+ // behaviour.
67
+ rowActivatable?: boolean;
68
+ // Row keys whose `expanded` slot is rendered. Owned by the caller, like
69
+ // `visibleKeys`: the table asks for a change and renders what it is given back.
70
+ // A key for a row that is not on this page is kept as it is, so paging away and
71
+ // back does not quietly discard it.
72
+ expandedKeys?: (string | number)[];
73
+ // The table runs to its container's edges: the toolbar keeps the container's gutter,
74
+ // while the rows and the pinned actions cell reach the edge, under a line, and the
75
+ // actions cell stays pinned to the right edge while wide columns scroll sideways.
76
+ flush?: boolean;
77
+ // Folds each run of rows with the same key under one header row (the `group` slot).
78
+ // The caller orders the rows so a group is one run; the table draws what it gets.
79
+ groupKey?: (row: T) => string | number;
80
+ // Group keys whose rows are hidden under their header. Owned by the caller, like
81
+ // `expandedKeys`.
82
+ collapsedGroups?: (string | number)[];
83
+ }>(),
84
+ {
85
+ loading: false,
86
+ loadingText: undefined,
87
+ emptyText: undefined,
88
+ rowActivatable: false,
89
+ expandedKeys: () => [],
90
+ flush: false,
91
+ groupKey: undefined,
92
+ collapsedGroups: () => [],
93
+ },
94
+ );
95
+
96
+ const emit = defineEmits<{
97
+ (e: 'update:visibleKeys', keys: string[]): void;
98
+ (e: 'update:sort', sort: TableSort): void;
99
+ (e: 'rowActivate', row: T): void;
100
+ (e: 'update:expandedKeys', keys: (string | number)[]): void;
101
+ (e: 'update:collapsedGroups', keys: (string | number)[]): void;
102
+ }>();
103
+
104
+ // One `cell:<key>` slot per column renders that column's cell body; `actions` renders the
105
+ // trailing per-row actions cell (not a DataTableColumn, so the ColumnMenu never lists it).
106
+ // `toolbar` lets the caller own the toolbar row (its filters etc.) and place the table's
107
+ // column menu in it via the `columnMenu` component; unused, the control renders alone,
108
+ // right-aligned.
109
+ // `expanded` renders a full-width panel under its row; providing it is what turns the
110
+ // whole feature on, including the leading caret column.
111
+ const slots = defineSlots<
112
+ {
113
+ actions?(props: { row: T }): unknown;
114
+ toolbar?(props: { columnMenu: FunctionalComponent }): unknown;
115
+ expanded?(props: { row: T }): unknown;
116
+ /**
117
+ * The header row of one group. A LINK, A FIELD OR A LABEL IN HERE KEEPS ITS OWN CLICK;
118
+ * A BUTTON DOES NOT. The whole header toggles the group, and `onGroupClick` excludes
119
+ * `a, input, select, textarea, label` from that — deliberately not `button`, because
120
+ * the group's own caret is a button with no click of its own and folds the group by
121
+ * bubbling into this handler. So a consumer's action button placed here fires its own
122
+ * handler AND folds the group. Put such an action in the row's `actions` cell, or in a
123
+ * link, or accept the fold.
124
+ */
125
+ group?(props: { groupKey: string | number; rows: T[]; collapsed: boolean }): unknown;
126
+ /** The glyph of every row caret and group caret. Defaults to a chevron. */
127
+ 'expand-icon'?(): unknown;
128
+ /** The column menu trigger's leading glyph. */
129
+ 'columns-icon'?(): unknown;
130
+ /** The column menu trigger's trailing glyph. */
131
+ 'chevron-icon'?(): unknown;
132
+ /** The column menu's search glyph. */
133
+ 'search-icon'?(): unknown;
134
+ } & {
135
+ [K in `cell:${string}`]?: (props: { row: T }) => unknown;
136
+ }
137
+ >();
138
+
139
+ const labels = useUiLabels();
140
+ const loadingLabel = computed(() => props.loadingText ?? labels.value.tableLoading);
141
+ const emptyLabel = computed(() => props.emptyText ?? labels.value.tableEmpty);
142
+
143
+ const hasActions = computed(() => slots.actions !== undefined);
144
+ const hasExpansion = computed(() => slots.expanded !== undefined);
145
+
146
+ const expanded = computed(() => new Set(props.expandedKeys));
147
+
148
+ function isExpanded(row: T): boolean {
149
+ return expanded.value.has(props.rowKey(row));
150
+ }
151
+
152
+ // Stable per row, so the caret can point at the panel it opens.
153
+ function panelId(row: T): string {
154
+ return `data-table-panel-${String(props.rowKey(row))}`;
155
+ }
156
+
157
+ function toggleRow(row: T): void {
158
+ const key = props.rowKey(row);
159
+ emit(
160
+ 'update:expandedKeys',
161
+ isExpanded(row)
162
+ ? props.expandedKeys.filter((k) => k !== key)
163
+ : [...props.expandedKeys, key],
164
+ );
165
+ }
166
+
167
+ // The rows as the body draws them: one section per group, or a single headless section
168
+ // holding every row when the table does not group.
169
+ const sections = computed<{ key: string | number | null; rows: T[] }[]>(() => {
170
+ const groupKey = props.groupKey;
171
+ if (groupKey === undefined) {
172
+ return [{ key: null, rows: props.rows }];
173
+ }
174
+ const out: { key: string | number; rows: T[] }[] = [];
175
+ for (const row of props.rows) {
176
+ const key = groupKey(row);
177
+ const last = out.at(-1);
178
+ if (last !== undefined && last.key === key) {
179
+ last.rows.push(row);
180
+ } else {
181
+ out.push({ key, rows: [row] });
182
+ }
183
+ }
184
+ return out;
185
+ });
186
+
187
+ const collapsed = computed(() => new Set(props.collapsedGroups));
188
+
189
+ function toggleGroup(key: string | number): void {
190
+ emit(
191
+ 'update:collapsedGroups',
192
+ collapsed.value.has(key)
193
+ ? props.collapsedGroups.filter((k) => k !== key)
194
+ : [...props.collapsedGroups, key],
195
+ );
196
+ }
197
+
198
+ // The whole header toggles its group, except the controls inside it (a link to the
199
+ // group's record keeps its own click).
200
+ function onGroupClick(event: MouseEvent, key: string | number): void {
201
+ const target = event.target;
202
+ if (target instanceof Element && target.closest('a, input, select, textarea, label')) {
203
+ return;
204
+ }
205
+ toggleGroup(key);
206
+ }
207
+
208
+ // Escape closes what is open, from anywhere in the table — including from inside a panel,
209
+ // which is where focus usually is by then. Silent when nothing is open, so the key stays
210
+ // available to whatever encloses the table — and, on the path where it is NOT silent, it stops
211
+ // there: a table inside a Dialog otherwise collapsed its rows and closed the dialog on one
212
+ // key. The two halves are the same rule, which is that one Escape does one thing.
213
+ function onEscape(event: KeyboardEvent): void {
214
+ if (!hasExpansion.value || props.expandedKeys.length === 0) {
215
+ return;
216
+ }
217
+ emit('update:expandedKeys', []);
218
+ event.stopPropagation();
219
+ }
220
+
221
+ // Visibility is presentational only: hidden columns are simply not rendered.
222
+ const visibleColumns = computed(() => {
223
+ const visible = new Set(props.visibleKeys);
224
+ return props.columns.filter((c) => c.alwaysVisible === true || visible.has(c.key));
225
+ });
226
+
227
+ // A `colspan` of 0 is read as 1 by the browser; say 1, so the number the table states is the
228
+ // number it means when no column is left.
229
+ const colspan = computed(() =>
230
+ Math.max(
231
+ 1,
232
+ visibleColumns.value.length + (hasActions.value ? 1 : 0) + (hasExpansion.value ? 1 : 0),
233
+ ),
234
+ );
235
+
236
+ // No column to draw means no row to draw: a row of no cells is nothing, not a record.
237
+ const showsRows = computed(() => props.rows.length > 0 && visibleColumns.value.length > 0);
238
+
239
+ function cycleSort(key: string): void {
240
+ emit('update:sort', nextSort(props.sort, key));
241
+ }
242
+
243
+ // Reset restores the default-visible set; always-visible columns stay in it.
244
+ function resetColumns(): void {
245
+ emit('update:visibleKeys', defaultVisibleKeys(props.columns));
246
+ }
247
+
248
+ // A click on a row's data cells opens the record. Genuine controls (links, the kebab
249
+ // button + its menu items, form fields) and the trailing actions cell keep their own
250
+ // click, so only a click on the plain cells activates the row.
251
+ function onRowClick(event: MouseEvent, row: T): void {
252
+ if (props.rowActivatable && isRowActivationTarget(event)) {
253
+ emit('rowActivate', row);
254
+ }
255
+ }
256
+
257
+ // The ColumnMenu bound to this table. Created once so its identity is stable across
258
+ // re-renders: a fresh component per render would remount the menu and close its panel. The
259
+ // glyph slots are read when it renders, not when it is made, so a caller's glyph follows.
260
+ const BoundColumnMenu: FunctionalComponent = () =>
261
+ h(
262
+ ColumnMenu,
263
+ {
264
+ columns: props.columns,
265
+ visibleKeys: props.visibleKeys,
266
+ 'onUpdate:visibleKeys': (keys: string[]) => emit('update:visibleKeys', keys),
267
+ onReset: resetColumns,
268
+ },
269
+ {
270
+ 'columns-icon': slots['columns-icon'],
271
+ 'chevron-icon': slots['chevron-icon'],
272
+ 'search-icon': slots['search-icon'],
273
+ },
274
+ );
275
+ </script>
276
+
277
+ <template>
278
+ <div
279
+ data-testid="data-table"
280
+ :class="cn('flex flex-col', flush ? 'gap-0' : 'gap-3')"
281
+ @keydown.escape="onEscape"
282
+ >
283
+ <div
284
+ data-testid="data-table-toolbar"
285
+ :class="
286
+ cn(
287
+ 'flex flex-wrap items-center gap-2',
288
+ !$slots.toolbar && 'justify-end',
289
+ flush && 'px-4 pb-3',
290
+ )
291
+ "
292
+ >
293
+ <slot name="toolbar" :column-menu="BoundColumnMenu">
294
+ <BoundColumnMenu />
295
+ </slot>
296
+ </div>
297
+
298
+ <Table
299
+ :loading="loading"
300
+ :container-class="flush ? 'border-t border-border' : undefined"
301
+ :class="
302
+ flush
303
+ ? '[&_td:first-child]:pl-4 [&_td:last-child]:pr-4 [&_th:first-child]:pl-4 [&_th:last-child]:pr-4'
304
+ : undefined
305
+ "
306
+ >
307
+ <TableHeader>
308
+ <TableRow :class="cn(flush && 'bg-muted/50 hover:bg-muted/50')">
309
+ <TableHead v-if="hasExpansion" class="w-px">
310
+ <span class="sr-only">{{ labels.tableExpandRow }}</span>
311
+ </TableHead>
312
+ <SortableHead
313
+ v-for="column in visibleColumns"
314
+ :key="column.key"
315
+ :column="column"
316
+ :sort="sort"
317
+ @cycle="cycleSort"
318
+ @choose="(next) => emit('update:sort', next)"
319
+ />
320
+ <TableHead
321
+ v-if="hasActions"
322
+ data-testid="data-table-actions-head"
323
+ :class="cn('w-px', flush && [PINNED, PINNED_WASH])"
324
+ >
325
+ <span class="sr-only">{{ labels.tableActions }}</span>
326
+ </TableHead>
327
+ </TableRow>
328
+ <!-- Reload: stale rows stay (dimmed) and a 2px bar runs right under the header. -->
329
+ <TableProgressRow
330
+ v-if="loading && rows.length > 0"
331
+ :colspan="colspan"
332
+ :label="loadingLabel"
333
+ />
334
+ </TableHeader>
335
+ <TableBody :class="cn(loading && 'opacity-60 transition-opacity')">
336
+ <TableLoadingRow
337
+ v-if="loading && rows.length === 0"
338
+ :colspan="colspan"
339
+ :label="loadingLabel"
340
+ />
341
+ <TableEmpty
342
+ v-else-if="!showsRows"
343
+ data-testid="data-table-empty"
344
+ :colspan="colspan"
345
+ >
346
+ <span class="text-muted-foreground">{{ emptyLabel }}</span>
347
+ </TableEmpty>
348
+ <template v-if="showsRows">
349
+ <template v-for="section in sections" :key="section.key ?? '__all__'">
350
+ <TableRow
351
+ v-if="section.key !== null"
352
+ data-testid="data-table-group"
353
+ :data-group-key="section.key"
354
+ class="bg-primary/5 hover:bg-primary/10 cursor-pointer"
355
+ @click="onGroupClick($event, section.key)"
356
+ >
357
+ <TableCell :colspan="colspan" class="py-2">
358
+ <div class="flex items-center gap-2">
359
+ <ExpandCaret
360
+ :expanded="!collapsed.has(section.key)"
361
+ :aria-label="
362
+ collapsed.has(section.key)
363
+ ? labels.tableExpandGroup
364
+ : labels.tableCollapseGroup
365
+ "
366
+ >
367
+ <template v-if="$slots['expand-icon']" #icon>
368
+ <slot name="expand-icon" />
369
+ </template>
370
+ </ExpandCaret>
371
+ <slot
372
+ name="group"
373
+ :group-key="section.key"
374
+ :rows="section.rows"
375
+ :collapsed="collapsed.has(section.key)"
376
+ />
377
+ </div>
378
+ </TableCell>
379
+ </TableRow>
380
+ <template v-if="section.key === null || !collapsed.has(section.key)">
381
+ <template v-for="row in section.rows" :key="rowKey(row)">
382
+ <TableRow
383
+ data-testid="data-table-row"
384
+ :data-row-key="rowKey(row)"
385
+ :class="
386
+ cn(
387
+ rowActivatable && 'cursor-pointer',
388
+ hasExpansion && isExpanded(row) && 'border-b-0',
389
+ )
390
+ "
391
+ @click="onRowClick($event, row)"
392
+ >
393
+ <TableCell v-if="hasExpansion" class="w-px pr-0">
394
+ <ExpandCaret
395
+ :data-testid="`data-table-expand-${rowKey(row)}`"
396
+ :expanded="isExpanded(row)"
397
+ :aria-controls="
398
+ isExpanded(row) ? panelId(row) : undefined
399
+ "
400
+ :aria-label="
401
+ isExpanded(row)
402
+ ? labels.tableCollapseRow
403
+ : labels.tableExpandRow
404
+ "
405
+ @click="toggleRow(row)"
406
+ >
407
+ <template v-if="$slots['expand-icon']" #icon>
408
+ <slot name="expand-icon" />
409
+ </template>
410
+ </ExpandCaret>
411
+ </TableCell>
412
+ <TableCell
413
+ v-for="column in visibleColumns"
414
+ :key="column.key"
415
+ :class="cn(column.align === 'right' && 'text-right')"
416
+ >
417
+ <slot :name="`cell:${column.key}`" :row="row" />
418
+ </TableCell>
419
+ <TableCell
420
+ v-if="hasActions"
421
+ :class="
422
+ cn('text-right', flush && [PINNED, PINNED_HOVER_WASH])
423
+ "
424
+ data-actions-cell
425
+ >
426
+ <slot name="actions" :row="row" />
427
+ </TableCell>
428
+ </TableRow>
429
+ <TableRow
430
+ v-if="hasExpansion && isExpanded(row)"
431
+ :id="panelId(row)"
432
+ data-testid="data-table-expanded"
433
+ :data-row-key="rowKey(row)"
434
+ class="hover:bg-transparent"
435
+ >
436
+ <TableCell :colspan="colspan" class="bg-muted/40 p-0 pb-3">
437
+ <slot name="expanded" :row="row" />
438
+ </TableCell>
439
+ </TableRow>
440
+ </template>
441
+ </template>
442
+ </template>
443
+ </template>
444
+ </TableBody>
445
+ </Table>
446
+ </div>
447
+ </template>
@@ -0,0 +1,34 @@
1
+ <script setup lang="ts">
2
+ import { cn } from '../../lib/cn';
3
+ import { ChevronRightIcon } from '../icon';
4
+
5
+ /**
6
+ * The caret that folds a group or opens a row's panel: a chevron pointing right when closed,
7
+ * down when open. `aria-expanded` follows `expanded`; the caller names it (`aria-label`) and
8
+ * wires the click.
9
+ *
10
+ * The glyph is the `icon` slot (ADR 0013). The turn belongs to the wrapper around it and not
11
+ * to the chevron, so a glyph of the caller's turns with the state too.
12
+ */
13
+ defineProps<{ expanded: boolean }>();
14
+
15
+ defineSlots<{
16
+ /** The glyph. Defaults to a chevron pointing right, which turns down when open. */
17
+ icon?: () => unknown;
18
+ }>();
19
+ </script>
20
+
21
+ <template>
22
+ <button
23
+ type="button"
24
+ :aria-expanded="expanded"
25
+ class="text-muted-foreground hover:text-foreground focus-visible:ring-ring focus-visible:ring-offset-background inline-flex size-5 shrink-0 items-center justify-center rounded outline-none focus-visible:ring-2 focus-visible:ring-offset-2"
26
+ >
27
+ <span
28
+ data-testid="expand-caret-glyph"
29
+ :class="cn('inline-flex transition-transform', expanded && 'rotate-90')"
30
+ >
31
+ <slot name="icon"><ChevronRightIcon class="size-3.5" /></slot>
32
+ </span>
33
+ </button>
34
+ </template>
@@ -0,0 +1,184 @@
1
+ <script setup lang="ts">
2
+ import { useUiLabels } from '@noix-dev/brix-core';
3
+ import { computed } from 'vue';
4
+ import { cn } from '../../lib/cn';
5
+ import {
6
+ MenuContent,
7
+ MenuGroup,
8
+ MenuItem,
9
+ MenuLabel,
10
+ MenuRoot,
11
+ MenuSeparator,
12
+ MenuTrigger,
13
+ menuLabelClass,
14
+ } from '../menu';
15
+ import { TableHead } from '../table';
16
+ import type { DataTableColumn, TableSort } from './types';
17
+
18
+ /**
19
+ * One column head. A plain column is a label; a sortable one is a button that fills the whole
20
+ * cell (full width, the row's height and the cell's own padding), so the entire head is the
21
+ * sort target and not just the text; a column with `sortChoices` opens a menu instead.
22
+ *
23
+ * The parent owns the sort state and decides the next step; this only signals intent. A column
24
+ * with `sortChoices` names the exact sort instead, since one click cannot say which field and
25
+ * which way.
26
+ *
27
+ * The direction marks (▲ ▼ ↕ in the head, ↑ ↓ in the menu) are characters, `aria-hidden`: the
28
+ * state they show is carried by `aria-sort` on the head. They are not glyph slots, for the
29
+ * reason `RowActions` gives its kebab: the package has no drawing of its own for them and a
30
+ * character is faithful. The menu's wording comes from the label contract (`tableSortBy`,
31
+ * `tableSortAscending`, `tableSortDescending`, `tableSortClear`).
32
+ *
33
+ * Focus is an inset ring, which deviates from the recipe's gap, and the number is 4px on one
34
+ * axis. An outset ring is `ring-2` outside `ring-offset-2`, so it asks for 4px on every side.
35
+ * The button fills its whole cell, and the table's own box is `overflow-x-auto`
36
+ * (`table/Table.vue`), which clips that 4px on the inline axis at the first and last column.
37
+ * The vertical axis is already paid for — the same box carries `py-1 -my-1` — so an outset ring
38
+ * here would be drawn on two sides out of four, which is not an indicator. The fourth kind of
39
+ * `ring-inset` site in CLAUDE.md's control-state recipe.
40
+ */
41
+ const props = defineProps<{
42
+ column: DataTableColumn;
43
+ sort: TableSort;
44
+ }>();
45
+
46
+ const emit = defineEmits<{
47
+ (e: 'cycle', key: string): void;
48
+ (e: 'choose', sort: TableSort): void;
49
+ }>();
50
+
51
+ const labels = useUiLabels();
52
+
53
+ const choices = computed(() => props.column.sortChoices ?? []);
54
+ const hasMenu = computed(() => choices.value.length > 0);
55
+
56
+ // Which of the choices is the active sort, for the menu column; the plain column's own key
57
+ // otherwise.
58
+ const activeChoice = computed(() =>
59
+ hasMenu.value ? choices.value.find((c) => c.column === props.sort?.column) : undefined,
60
+ );
61
+
62
+ const direction = computed<'asc' | 'desc' | 'none'>(() => {
63
+ if (!props.sort) {
64
+ return 'none';
65
+ }
66
+ const mine = hasMenu.value
67
+ ? activeChoice.value !== undefined
68
+ : props.sort.column === props.column.key;
69
+ return mine ? props.sort.direction : 'none';
70
+ });
71
+
72
+ const ariaSort = computed(() =>
73
+ direction.value === 'asc' ? 'ascending' : direction.value === 'desc' ? 'descending' : 'none',
74
+ );
75
+
76
+ const indicator = computed(() =>
77
+ direction.value === 'asc' ? '▲' : direction.value === 'desc' ? '▼' : '↕',
78
+ );
79
+
80
+ const isSortable = computed(() => props.column.sortable === true || hasMenu.value);
81
+
82
+ function isActive(column: string, dir: 'asc' | 'desc'): boolean {
83
+ return props.sort?.column === column && props.sort.direction === dir;
84
+ }
85
+
86
+ const BUTTON =
87
+ 'hover:bg-muted/50 hover:text-foreground focus-visible:ring-ring flex h-8 w-full items-center gap-1 rounded-sm px-2.5 uppercase transition-colors outline-none focus-visible:ring-2 focus-visible:ring-inset';
88
+ </script>
89
+
90
+ <template>
91
+ <TableHead
92
+ :class="cn(column.align === 'right' && 'text-right', isSortable && 'px-0')"
93
+ :aria-sort="isSortable ? ariaSort : undefined"
94
+ >
95
+ <MenuRoot v-if="hasMenu">
96
+ <MenuTrigger as-child>
97
+ <button
98
+ type="button"
99
+ data-testid="sortable-head-button"
100
+ :class="
101
+ cn(
102
+ BUTTON,
103
+ column.align === 'right' ? 'justify-end' : 'justify-start',
104
+ direction !== 'none' && 'text-foreground',
105
+ )
106
+ "
107
+ >
108
+ <span>{{ column.label }}</span>
109
+ <span
110
+ v-if="activeChoice"
111
+ data-testid="sortable-head-choice"
112
+ class="font-semibold normal-case"
113
+ >· {{ activeChoice.label }}</span
114
+ >
115
+ <span
116
+ data-testid="sortable-head-indicator"
117
+ :data-direction="direction"
118
+ aria-hidden="true"
119
+ :class="cn('text-[8px] leading-none', direction === 'none' && 'opacity-40')"
120
+ >{{ indicator }}</span
121
+ >
122
+ </button>
123
+ </MenuTrigger>
124
+ <MenuContent align="start" class="min-w-52" data-testid="sortable-head-menu">
125
+ <MenuGroup>
126
+ <MenuLabel :class="menuLabelClass">{{ labels.tableSortBy }}</MenuLabel>
127
+ <template v-for="choice in choices" :key="choice.column">
128
+ <MenuItem
129
+ v-for="dir in ['asc', 'desc'] as const"
130
+ :key="dir"
131
+ :data-testid="`sortable-head-choice-${choice.column}-${dir}`"
132
+ :data-active="isActive(choice.column, dir) || undefined"
133
+ :class="
134
+ isActive(choice.column, dir) && 'text-primary-on-wash font-bold'
135
+ "
136
+ @select="emit('choose', { column: choice.column, direction: dir })"
137
+ >
138
+ <span
139
+ >{{ choice.label }}
140
+ {{
141
+ dir === 'asc'
142
+ ? labels.tableSortAscending
143
+ : labels.tableSortDescending
144
+ }}</span
145
+ >
146
+ <span aria-hidden="true">{{ dir === 'asc' ? '↑' : '↓' }}</span>
147
+ </MenuItem>
148
+ </template>
149
+ </MenuGroup>
150
+ <MenuSeparator />
151
+ <MenuItem
152
+ data-testid="sortable-head-choice-none"
153
+ :disabled="!activeChoice"
154
+ @select="emit('choose', null)"
155
+ >
156
+ {{ labels.tableSortClear }}
157
+ </MenuItem>
158
+ </MenuContent>
159
+ </MenuRoot>
160
+ <button
161
+ v-else-if="column.sortable"
162
+ type="button"
163
+ data-testid="sortable-head-button"
164
+ :class="
165
+ cn(
166
+ BUTTON,
167
+ column.align === 'right' ? 'justify-end' : 'justify-start',
168
+ direction !== 'none' && 'text-foreground',
169
+ )
170
+ "
171
+ @click="emit('cycle', column.key)"
172
+ >
173
+ <span>{{ column.label }}</span>
174
+ <span
175
+ data-testid="sortable-head-indicator"
176
+ :data-direction="direction"
177
+ aria-hidden="true"
178
+ :class="cn('text-[8px] leading-none', direction === 'none' && 'opacity-40')"
179
+ >{{ indicator }}</span
180
+ >
181
+ </button>
182
+ <template v-else>{{ column.label }}</template>
183
+ </TableHead>
184
+ </template>
@@ -0,0 +1,13 @@
1
+ <script setup lang="ts">
2
+ import { TableEmpty } from '../table';
3
+
4
+ // The first load of a table that has no rows yet: the table primitive's own loading state, in
5
+ // place of the empty text, so an empty result never flashes before the data arrives. The
6
+ // primitive draws the spinner and says what the contract says; `label` is the one call site's
7
+ // own wording, and left out it is the contract's.
8
+ defineProps<{ colspan: number; label?: string }>();
9
+ </script>
10
+
11
+ <template>
12
+ <TableEmpty data-testid="data-table-loading" loading :colspan="colspan" :loading-text="label" />
13
+ </template>