@42-central/ui-react 0.26.0 → 0.27.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 (138) hide show
  1. package/dist/{chunk-YZJUPYPO.js → chunk-2W7H43WL.js} +3 -3
  2. package/dist/{chunk-YZJUPYPO.js.map → chunk-2W7H43WL.js.map} +1 -1
  3. package/dist/{chunk-NLSJ6T7V.js → chunk-4D2V4JE4.js} +3 -3
  4. package/dist/{chunk-NLSJ6T7V.js.map → chunk-4D2V4JE4.js.map} +1 -1
  5. package/dist/{chunk-7B44J3CF.js → chunk-5H5YOPCF.js} +3 -3
  6. package/dist/{chunk-7B44J3CF.js.map → chunk-5H5YOPCF.js.map} +1 -1
  7. package/dist/{chunk-JFB6O7IY.js → chunk-7KFUFAVP.js} +4 -4
  8. package/dist/{chunk-JFB6O7IY.js.map → chunk-7KFUFAVP.js.map} +1 -1
  9. package/dist/{chunk-PT22KEVD.js → chunk-BGDVUC3B.js} +5 -5
  10. package/dist/{chunk-PT22KEVD.js.map → chunk-BGDVUC3B.js.map} +1 -1
  11. package/dist/{chunk-7247WBTV.js → chunk-DJ72KP32.js} +3 -3
  12. package/dist/{chunk-7247WBTV.js.map → chunk-DJ72KP32.js.map} +1 -1
  13. package/dist/{chunk-JDPVD2YE.js → chunk-HCHGERDB.js} +3 -3
  14. package/dist/{chunk-JDPVD2YE.js.map → chunk-HCHGERDB.js.map} +1 -1
  15. package/dist/{chunk-H7WOMZXO.js → chunk-HWBFRDX7.js} +16 -8
  16. package/dist/chunk-HWBFRDX7.js.map +1 -0
  17. package/dist/{chunk-LYGOFMXJ.js → chunk-I4IJOLNA.js} +4 -4
  18. package/dist/{chunk-LYGOFMXJ.js.map → chunk-I4IJOLNA.js.map} +1 -1
  19. package/dist/{chunk-DSZF2TW6.js → chunk-IA6DCC3N.js} +6 -6
  20. package/dist/{chunk-DSZF2TW6.js.map → chunk-IA6DCC3N.js.map} +1 -1
  21. package/dist/{chunk-QEAF57ZQ.js → chunk-ISX3AM32.js} +3 -3
  22. package/dist/{chunk-QEAF57ZQ.js.map → chunk-ISX3AM32.js.map} +1 -1
  23. package/dist/{chunk-YMVUQ2L7.js → chunk-L24N5EON.js} +6 -6
  24. package/dist/chunk-L24N5EON.js.map +1 -0
  25. package/dist/{chunk-J2NW7JID.js → chunk-L5GH7LLD.js} +3 -3
  26. package/dist/{chunk-J2NW7JID.js.map → chunk-L5GH7LLD.js.map} +1 -1
  27. package/dist/{chunk-N42EFOML.js → chunk-MCRTAUSZ.js} +6 -6
  28. package/dist/chunk-MCRTAUSZ.js.map +1 -0
  29. package/dist/{chunk-276RL7FX.js → chunk-MNYY7UU2.js} +6 -6
  30. package/dist/{chunk-276RL7FX.js.map → chunk-MNYY7UU2.js.map} +1 -1
  31. package/dist/{chunk-THGJLR5S.js → chunk-NNPSBC7O.js} +5 -5
  32. package/dist/{chunk-THGJLR5S.js.map → chunk-NNPSBC7O.js.map} +1 -1
  33. package/dist/{chunk-2CL3FKEY.js → chunk-QEMXXQQO.js} +3 -3
  34. package/dist/{chunk-2CL3FKEY.js.map → chunk-QEMXXQQO.js.map} +1 -1
  35. package/dist/{chunk-2NTCQIRP.js → chunk-QRNQQIQM.js} +5 -5
  36. package/dist/{chunk-2NTCQIRP.js.map → chunk-QRNQQIQM.js.map} +1 -1
  37. package/dist/{chunk-E3XLWMEB.js → chunk-RKCUXOU2.js} +4 -4
  38. package/dist/{chunk-E3XLWMEB.js.map → chunk-RKCUXOU2.js.map} +1 -1
  39. package/dist/{chunk-DMI4KS32.js → chunk-SBZJGFZ6.js} +3 -3
  40. package/dist/{chunk-DMI4KS32.js.map → chunk-SBZJGFZ6.js.map} +1 -1
  41. package/dist/{chunk-7P32XCEU.js → chunk-SLUOF7XW.js} +2 -2
  42. package/dist/chunk-SLUOF7XW.js.map +1 -0
  43. package/dist/{chunk-2TZU4LSX.js → chunk-ULF5LOBS.js} +3 -3
  44. package/dist/{chunk-2TZU4LSX.js.map → chunk-ULF5LOBS.js.map} +1 -1
  45. package/dist/components/app-shell/index.js +4 -4
  46. package/dist/components/autocomplete/index.js +4 -4
  47. package/dist/components/calendar-heatmap/index.js +2 -2
  48. package/dist/components/camera/index.js +6 -6
  49. package/dist/components/code-block/chrome.js +5 -5
  50. package/dist/components/code-block/index.js +6 -6
  51. package/dist/components/combobox/index.js +4 -4
  52. package/dist/components/combobox-list/index.js +6 -6
  53. package/dist/components/data-table/data-table-features.d.ts +8 -0
  54. package/dist/components/data-table/data-table-features.d.ts.map +1 -1
  55. package/dist/components/data-table/data-table-group.d.ts +128 -0
  56. package/dist/components/data-table/data-table-group.d.ts.map +1 -0
  57. package/dist/components/data-table/data-table-grouping.d.ts +72 -0
  58. package/dist/components/data-table/data-table-grouping.d.ts.map +1 -0
  59. package/dist/components/data-table/data-table-icons.d.ts +4 -2
  60. package/dist/components/data-table/data-table-icons.d.ts.map +1 -1
  61. package/dist/components/data-table/data-table-meta.d.ts +9 -0
  62. package/dist/components/data-table/data-table-meta.d.ts.map +1 -1
  63. package/dist/components/data-table/data-table-pagination.d.ts +4 -1
  64. package/dist/components/data-table/data-table-pagination.d.ts.map +1 -1
  65. package/dist/components/data-table/data-table-schema.d.ts +4 -0
  66. package/dist/components/data-table/data-table-schema.d.ts.map +1 -1
  67. package/dist/components/data-table/data-table-stack.d.ts +16 -3
  68. package/dist/components/data-table/data-table-stack.d.ts.map +1 -1
  69. package/dist/components/data-table/data-table-toolbar.d.ts +33 -2
  70. package/dist/components/data-table/data-table-toolbar.d.ts.map +1 -1
  71. package/dist/components/data-table/data-table-translations.d.ts +35 -0
  72. package/dist/components/data-table/data-table-translations.d.ts.map +1 -1
  73. package/dist/components/data-table/data-table.d.ts +55 -3
  74. package/dist/components/data-table/data-table.d.ts.map +1 -1
  75. package/dist/components/data-table/index.d.ts +3 -1
  76. package/dist/components/data-table/index.d.ts.map +1 -1
  77. package/dist/components/data-table/index.js +877 -229
  78. package/dist/components/data-table/index.js.map +1 -1
  79. package/dist/components/date-picker/index.js +7 -7
  80. package/dist/components/drawer/index.js +4 -4
  81. package/dist/components/hover-card/index.js +3 -3
  82. package/dist/components/kbd/index.js +3 -3
  83. package/dist/components/lightbox/index.js +4 -4
  84. package/dist/components/menu/index.js +4 -4
  85. package/dist/components/modal/index.js +4 -4
  86. package/dist/components/multi-combobox-list/index.js +6 -6
  87. package/dist/components/multi-select/index.js +4 -4
  88. package/dist/components/nav-link/index.js +3 -3
  89. package/dist/components/nav-link/tanstack.js +3 -3
  90. package/dist/components/notification/create-notifier.d.ts.map +1 -1
  91. package/dist/components/notification/index.js +15 -3
  92. package/dist/components/notification/index.js.map +1 -1
  93. package/dist/components/notification/types.d.ts +5 -0
  94. package/dist/components/notification/types.d.ts.map +1 -1
  95. package/dist/components/number-input/index.js +4 -4
  96. package/dist/components/overlays/index.js +5 -5
  97. package/dist/components/photo-capture/index.js +6 -6
  98. package/dist/components/popover/index.js +3 -3
  99. package/dist/components/schedule/index.js +3 -3
  100. package/dist/components/select/index.js +5 -5
  101. package/dist/components/spotlight/index.js +8 -8
  102. package/dist/components/tags-input/index.js +3 -3
  103. package/dist/components/time-input/index.js +5 -5
  104. package/dist/components/tooltip/index.js +2 -2
  105. package/dist/components/tree-multi-select/index.js +4 -4
  106. package/dist/components/tree-select/index.js +4 -4
  107. package/dist/index.js +2 -2
  108. package/dist/lib/overlay-container.d.ts.map +1 -1
  109. package/dist/lib/overlay-layer.d.ts +10 -3
  110. package/dist/lib/overlay-layer.d.ts.map +1 -1
  111. package/dist/theme.css +14 -6
  112. package/package.json +1 -1
  113. package/src/components/data-table/data-table-features.ts +11 -0
  114. package/src/components/data-table/data-table-group.test.tsx +1007 -0
  115. package/src/components/data-table/data-table-group.tsx +474 -0
  116. package/src/components/data-table/data-table-grouping.ts +160 -0
  117. package/src/components/data-table/data-table-icons.tsx +8 -1
  118. package/src/components/data-table/data-table-meta.ts +9 -0
  119. package/src/components/data-table/data-table-pagination.tsx +5 -1
  120. package/src/components/data-table/data-table-stack.tsx +165 -43
  121. package/src/components/data-table/data-table-toolbar.tsx +110 -2
  122. package/src/components/data-table/data-table-translations.ts +44 -0
  123. package/src/components/data-table/data-table.tsx +420 -150
  124. package/src/components/data-table/index.ts +4 -0
  125. package/src/components/drawer/drawer.tsx +1 -1
  126. package/src/components/modal/modal.tsx +1 -1
  127. package/src/components/notification/create-notifier.tsx +18 -2
  128. package/src/components/notification/notify-in-modal.test.tsx +128 -0
  129. package/src/components/notification/types.ts +5 -0
  130. package/src/lib/overlay-container.tsx +2 -1
  131. package/src/lib/overlay-layer.test.tsx +63 -1
  132. package/src/lib/overlay-layer.tsx +29 -6
  133. package/src/theme.css +14 -6
  134. package/src/theme.test.ts +14 -10
  135. package/dist/chunk-7P32XCEU.js.map +0 -1
  136. package/dist/chunk-H7WOMZXO.js.map +0 -1
  137. package/dist/chunk-N42EFOML.js.map +0 -1
  138. package/dist/chunk-YMVUQ2L7.js.map +0 -1
@@ -5,47 +5,48 @@ import { Table } from '../../chunk-PEHFWGTT.js';
5
5
  import { Text } from '../../chunk-XKDL4QS6.js';
6
6
  import '../../chunk-R5GMMWAY.js';
7
7
  import '../../chunk-BJZLQTAZ.js';
8
- import { Root, Trigger, Content, CheckboxItem } from '../../chunk-PT22KEVD.js';
9
- import { MultiComboboxList } from '../../chunk-JFB6O7IY.js';
8
+ import { Root, Trigger, Content, RadioGroup, ItemGroupLabel, RadioItem, Divider, CheckboxItem } from '../../chunk-BGDVUC3B.js';
9
+ import { MultiComboboxList } from '../../chunk-7KFUFAVP.js';
10
10
  import { Pill } from '../../chunk-6M6YZ3PQ.js';
11
11
  import { Flex } from '../../chunk-UXPINIDN.js';
12
12
  import '../../chunk-XFEPUGUZ.js';
13
13
  import '../../chunk-FMMKEYHB.js';
14
- import { ComboboxList } from '../../chunk-THGJLR5S.js';
15
- import '../../chunk-QEAF57ZQ.js';
16
- import { serializeDateValue, DatePicker } from '../../chunk-276RL7FX.js';
17
- import { resolveHourCycle } from '../../chunk-2TZU4LSX.js';
14
+ import { ComboboxList } from '../../chunk-NNPSBC7O.js';
15
+ import '../../chunk-ISX3AM32.js';
16
+ import { serializeDateValue, DatePicker } from '../../chunk-MNYY7UU2.js';
17
+ import { resolveHourCycle } from '../../chunk-ULF5LOBS.js';
18
18
  import '../../chunk-NF2PBGD3.js';
19
- import { NUMBER_INPUT_DEFAULT_TRANSLATIONS, NumberInput } from '../../chunk-DMI4KS32.js';
19
+ import { NUMBER_INPUT_DEFAULT_TRANSLATIONS, NumberInput } from '../../chunk-SBZJGFZ6.js';
20
20
  import { Checkbox } from '../../chunk-7E7JNWOC.js';
21
21
  import '../../chunk-NLOBBJAA.js';
22
22
  import { resolveCalendarTranslations } from '../../chunk-E52Z2FKU.js';
23
23
  import '../../chunk-ZB5VMGKB.js';
24
24
  import '../../chunk-ZP6EBROY.js';
25
- import { Select } from '../../chunk-DSZF2TW6.js';
25
+ import { Select } from '../../chunk-IA6DCC3N.js';
26
26
  import { Skeleton } from '../../chunk-TWNIAF7K.js';
27
27
  import { Card } from '../../chunk-KKLCHLCZ.js';
28
- import { Drawer } from '../../chunk-YMVUQ2L7.js';
29
- import '../../chunk-NLSJ6T7V.js';
30
- import '../../chunk-7TDHT3QD.js';
31
- import { COMBOBOX_DEFAULT_TRANSLATIONS } from '../../chunk-2NTCQIRP.js';
28
+ import { Drawer } from '../../chunk-L24N5EON.js';
29
+ import '../../chunk-4D2V4JE4.js';
30
+ import { normalizeSelectData } from '../../chunk-7TDHT3QD.js';
31
+ import { COMBOBOX_DEFAULT_TRANSLATIONS } from '../../chunk-QRNQQIQM.js';
32
32
  import '../../chunk-5FDOOG4J.js';
33
33
  import { Input } from '../../chunk-I4B3N3UX.js';
34
34
  import '../../chunk-X6DESK37.js';
35
35
  import '../../chunk-DHM4IG2O.js';
36
+ import { Badge } from '../../chunk-ZVECQBGG.js';
36
37
  import '../../chunk-SKPM2FRX.js';
37
38
  import '../../chunk-ORTCK34Y.js';
38
39
  import { Button } from '../../chunk-SCXXJDKQ.js';
39
40
  import { useDebouncedCallback } from '../../chunk-ZYX564HO.js';
40
41
  import '../../chunk-HBWV5EPU.js';
41
42
  import { useLocale, useTimeZone } from '../../chunk-IUK7OJXZ.js';
42
- import { Popover } from '../../chunk-E3XLWMEB.js';
43
- import '../../chunk-H7WOMZXO.js';
44
- import { Tooltip } from '../../chunk-YZJUPYPO.js';
43
+ import { Popover } from '../../chunk-RKCUXOU2.js';
44
+ import '../../chunk-HWBFRDX7.js';
45
+ import { Tooltip } from '../../chunk-2W7H43WL.js';
45
46
  import '../../chunk-V6PY7C6S.js';
46
- import '../../chunk-7P32XCEU.js';
47
+ import '../../chunk-SLUOF7XW.js';
47
48
  import { ActionIcon } from '../../chunk-BMEJBY6H.js';
48
- import '../../chunk-LIZWCWED.js';
49
+ import { devWarnOnce } from '../../chunk-LIZWCWED.js';
49
50
  import { useUncontrolled } from '../../chunk-PMUCGFY5.js';
50
51
  import '../../chunk-BUIHQJGE.js';
51
52
  import '../../chunk-6YNLRQ25.js';
@@ -57,10 +58,10 @@ import { focusStyles } from '../../chunk-C6NVU4F7.js';
57
58
  import { TEXT_COLOR_CLASSES } from '../../chunk-GIPQUKCN.js';
58
59
  import { cn } from '../../chunk-4ASNIDV7.js';
59
60
  import { useLocaleContext } from '@ark-ui/react/locale';
60
- import { tableFeatures, filterFn_weakEquals, filterFn_inDateRange, filterFn_arrIncludes, filterFn_equals, filterFn_inNumberRange, filterFn_includesString, sortFn_basic, sortFn_datetime, sortFn_text, sortFn_alphanumeric, columnResizingFeature, columnSizingFeature, columnVisibilityFeature, rowSelectionFeature, rowPaginationFeature, rowSortingFeature, globalFilteringFeature, columnFilteringFeature, createPaginatedRowModel, createSortedRowModel, createFilteredRowModel, useTable, flexRender, createColumnHelper as createColumnHelper$1 } from '@tanstack/react-table';
61
- import { useRef, useMemo, useId, useState, useEffect } from 'react';
61
+ import { tableFeatures, filterFn_weakEquals, filterFn_inDateRange, filterFn_arrIncludes, filterFn_equals, filterFn_inNumberRange, filterFn_includesString, sortFn_basic, sortFn_datetime, sortFn_text, sortFn_alphanumeric, rowExpandingFeature, columnGroupingFeature, columnResizingFeature, columnSizingFeature, columnVisibilityFeature, rowSelectionFeature, rowPaginationFeature, rowSortingFeature, globalFilteringFeature, columnFilteringFeature, createPaginatedRowModel, createExpandedRowModel, createSortedRowModel, createGroupedRowModel, createFilteredRowModel, useTable, flexRender, createColumnHelper as createColumnHelper$1 } from '@tanstack/react-table';
62
+ import { useRef, useMemo, useId, useState, Fragment as Fragment$1, useEffect } from 'react';
62
63
  import { match, P } from 'ts-pattern';
63
- import { ChevronRight, ChevronLeft, Search, ArrowUpToLineIcon, ArrowDownToLineIcon, RotateCwIcon, EraserIcon, ServerCrashIcon, SearchAlertIcon, Columns3CogIcon, ListFilterIcon, ChevronsUpDownIcon, ChevronDownIcon, ChevronUpIcon } from 'lucide-react';
64
+ import { ChevronRight, ChevronLeft, Search, GroupIcon, ArrowUpToLineIcon, ArrowDownToLineIcon, RotateCwIcon, EraserIcon, ServerCrashIcon, SearchAlertIcon, Columns3CogIcon, ListFilterIcon, ChevronsUpDownIcon, ChevronDownIcon, ChevronUpIcon } from 'lucide-react';
64
65
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
65
66
  import { parseDateTime, parseDate } from '@internationalized/date';
66
67
  import { cva } from 'class-variance-authority';
@@ -74,10 +75,17 @@ var dataTableFeatures = tableFeatures({
74
75
  columnVisibilityFeature,
75
76
  columnSizingFeature,
76
77
  columnResizingFeature,
78
+ // Row grouping (`grouping`) and its fold state (`expanded`). No
79
+ // `rowAggregationFeature`: a group row draws a header, never cells, so there
80
+ // is nothing to aggregate.
81
+ columnGroupingFeature,
82
+ rowExpandingFeature,
77
83
  // v8's `get*RowModel` options moved into these slots. The core row model is
78
84
  // automatic in v9 and must not be passed.
79
85
  filteredRowModel: createFilteredRowModel(),
86
+ groupedRowModel: createGroupedRowModel(),
80
87
  sortedRowModel: createSortedRowModel(),
88
+ expandedRowModel: createExpandedRowModel(),
81
89
  paginatedRowModel: createPaginatedRowModel(),
82
90
  /* These two registries are load-bearing, and their failure mode is silent.
83
91
  *
@@ -121,7 +129,9 @@ var DEFAULT_ICONS = {
121
129
  clear: /* @__PURE__ */ jsx(EraserIcon, { className: iconStroke }),
122
130
  retry: /* @__PURE__ */ jsx(RotateCwIcon, { className: iconStroke }),
123
131
  min: /* @__PURE__ */ jsx(ArrowDownToLineIcon, { className: iconStroke }),
124
- max: /* @__PURE__ */ jsx(ArrowUpToLineIcon, { className: iconStroke })
132
+ max: /* @__PURE__ */ jsx(ArrowUpToLineIcon, { className: iconStroke }),
133
+ group: /* @__PURE__ */ jsx(GroupIcon, { className: iconStroke }),
134
+ fold: /* @__PURE__ */ jsx(ChevronRight, { "aria-hidden": "true", className: iconStroke })
125
135
  };
126
136
  var resolveDataTableIcons = (icons) => icons ? mergeIcons(DEFAULT_ICONS, icons) : DEFAULT_ICONS;
127
137
  var sortIcon = (sorted) => sorted || "unsorted";
@@ -148,6 +158,17 @@ var DATA_TABLE_DEFAULT_TRANSLATIONS = {
148
158
  fromTime: "From time",
149
159
  toTime: "To time",
150
160
  clearDates: "Clear",
161
+ group: "Group rows",
162
+ groupBy: "Group by",
163
+ groupThenBy: "Then by",
164
+ groupNone: "None",
165
+ hideEmptyGroups: "Hide empty groups",
166
+ groupToggle: (label) => label,
167
+ groupCount: (count, formatted) => count === 1 ? `${formatted} row` : `${formatted} rows`,
168
+ groupNoValue: "No value",
169
+ selectGroup: (label) => `Select group ${label}`,
170
+ showMore: (_count, formatted) => `Show ${formatted} more`,
171
+ groupSummary: ({ rows, groups, formatted }) => `${formatted.rows} ${rows === 1 ? "row" : "rows"} in ${formatted.groups} ${groups === 1 ? "group" : "groups"}`,
151
172
  clearTriggerLabel: COMBOBOX_DEFAULT_TRANSLATIONS.clearTriggerLabel,
152
173
  incrementLabel: NUMBER_INPUT_DEFAULT_TRANSLATIONS.incrementLabel,
153
174
  decrementLabel: NUMBER_INPUT_DEFAULT_TRANSLATIONS.decrementLabel
@@ -595,6 +616,345 @@ var DataTableFilterControl = ({
595
616
  }
596
617
  )).exhaustive();
597
618
  };
619
+
620
+ // src/components/data-table/data-table-grouping.ts
621
+ var MAX_GROUPING_DEPTH = 2;
622
+ var NO_OPTIONS = [];
623
+ var optionsCache = /* @__PURE__ */ new WeakMap();
624
+ var groupOptions = (column) => {
625
+ const filter = column?.columnDef.meta?.filter;
626
+ if (filter?.type !== "select" || !Array.isArray(filter.options)) return NO_OPTIONS;
627
+ const cached = optionsCache.get(filter.options);
628
+ if (cached) return cached;
629
+ const items = normalizeSelectData(filter.options).items;
630
+ optionsCache.set(filter.options, items);
631
+ return items;
632
+ };
633
+ var isGroupExpanded = (expanded, id) => expanded === true || expanded[id] !== false;
634
+ var toggleGroupExpanded = (expanded, id) => {
635
+ const { [id]: current, ...rest } = expanded === true ? {} : expanded;
636
+ return current === false ? rest : { ...rest, [id]: false };
637
+ };
638
+ var groupLeafRows = (node) => node.groups.length > 0 ? node.groups.flatMap(groupLeafRows) : node.rows;
639
+ var ascending = (a, b) => a.localeCompare(b, void 0, { numeric: true });
640
+ function buildGroupTree({
641
+ table,
642
+ rows,
643
+ grouping,
644
+ hideEmptyGroups,
645
+ manualGroups
646
+ }) {
647
+ const level = (levelRows, depth, parentId) => {
648
+ const columnId = grouping[depth];
649
+ if (columnId == null) return [];
650
+ const column = table.getColumn(columnId);
651
+ const manual = depth === 0 ? manualGroups : void 0;
652
+ const order = manual?.map((group) => group.value) ?? groupOptions(column).map((option) => option.value);
653
+ const declared = depth === 0 ? order : [];
654
+ const rank = new Map(order.map((value, index) => [value, index]));
655
+ const counts = new Map(manual?.map((group) => [group.value, group.count]));
656
+ const compare = column?.columnDef.meta?.groupOrder ?? ((a, b) => (rank.get(a) ?? Number.POSITIVE_INFINITY) - (rank.get(b) ?? Number.POSITIVE_INFINITY) || ascending(a, b));
657
+ const present = levelRows.filter((row) => row.getIsGrouped()).map((row) => {
658
+ const nested = depth + 1 < grouping.length;
659
+ const groups = nested ? level(row.subRows, depth + 1, row.id) : [];
660
+ const leaves = nested ? [] : row.subRows;
661
+ const loaded = nested ? groups.reduce((sum, group) => sum + group.loaded, 0) : leaves.length;
662
+ return {
663
+ id: row.id,
664
+ columnId,
665
+ value: String(row.groupingValue),
666
+ depth,
667
+ count: loaded,
668
+ loaded,
669
+ row,
670
+ groups,
671
+ rows: leaves
672
+ };
673
+ });
674
+ const known = new Set(present.map((node) => node.value));
675
+ const empty = declared.filter((value) => !known.has(value)).map(
676
+ (value) => ({
677
+ id: parentId ? `${parentId}>${columnId}:${value}` : `${columnId}:${value}`,
678
+ columnId,
679
+ value,
680
+ depth,
681
+ count: 0,
682
+ loaded: 0,
683
+ groups: [],
684
+ rows: []
685
+ })
686
+ );
687
+ return [...present, ...empty].map((node) => ({ ...node, count: counts.get(node.value) ?? node.count })).filter((node) => !hideEmptyGroups || node.count > 0).sort((a, b) => compare(a.value, b.value));
688
+ };
689
+ return level(rows, 0);
690
+ }
691
+ var NO_VALUE = /* @__PURE__ */ new Set(["", "null", "undefined"]);
692
+ function useDataTableGrouping({
693
+ table,
694
+ grouping,
695
+ expanded,
696
+ onExpandedChange,
697
+ hideEmptyGroups,
698
+ paginate,
699
+ groupPageSize,
700
+ manualGrouping,
701
+ manualGroups,
702
+ onGroupShowMore,
703
+ renderGroupHeader,
704
+ translations,
705
+ resetKey
706
+ }) {
707
+ const [limitState, setLimitState] = useState({
708
+ key: resetKey,
709
+ limits: {}
710
+ });
711
+ const [opened, setOpened] = useState(() => /* @__PURE__ */ new Set());
712
+ if (grouping.length === 0) return null;
713
+ const limits = limitState.key === resetKey ? limitState.limits : {};
714
+ const groups = buildGroupTree({
715
+ table,
716
+ rows: table.getSortedRowModel().rows,
717
+ grouping,
718
+ hideEmptyGroups,
719
+ manualGroups: manualGrouping ? manualGroups : void 0
720
+ });
721
+ const limitOf = (node) => paginate && !manualGrouping ? limits[node.id] ?? groupPageSize : Number.POSITIVE_INFINITY;
722
+ const isExpanded = (node) => isGroupExpanded(expanded, node.id);
723
+ const toggle = (node) => {
724
+ if (!isExpanded(node)) setOpened((previous) => new Set(previous).add(node.id));
725
+ onExpandedChange((old) => toggleGroupExpanded(old, node.id));
726
+ };
727
+ const label = (node) => groupOptions(table.getColumn(node.columnId)).find((option) => option.value === node.value)?.label ?? (NO_VALUE.has(node.value) ? translations.groupNoValue : node.value);
728
+ const renderValue = (node) => {
729
+ const column = table.getColumn(node.columnId);
730
+ if (!column) return label(node);
731
+ const leaves = groupLeafRows(node);
732
+ if (renderGroupHeader) {
733
+ return renderGroupHeader({
734
+ column,
735
+ value: node.value,
736
+ label: label(node),
737
+ rows: leaves,
738
+ count: node.count,
739
+ expanded: isExpanded(node),
740
+ toggle: () => toggle(node)
741
+ });
742
+ }
743
+ const cell = column.columnDef.getGroupingValue == null && !NO_VALUE.has(node.value) ? leaves[0]?.getAllCells().find((candidate) => candidate.column.id === node.columnId) : void 0;
744
+ if (cell) return flexRender(column.columnDef.cell, cell.getContext());
745
+ const option = groupOptions(column).find((candidate) => candidate.value === node.value);
746
+ return option?.color ? /* @__PURE__ */ jsx(Badge, { size: "sm", color: option.color, children: option.label }) : label(node);
747
+ };
748
+ return {
749
+ groups,
750
+ rowCount: groups.reduce((sum, node) => sum + node.count, 0),
751
+ label,
752
+ renderValue,
753
+ isExpanded,
754
+ toggle,
755
+ visibleRows: (node) => node.rows.slice(0, limitOf(node)),
756
+ nextCount: (node) => {
757
+ if (node.groups.length > 0) return 0;
758
+ const rest = manualGrouping ? node.count - node.loaded : node.rows.length - limitOf(node);
759
+ return Math.max(0, Math.min(groupPageSize, rest));
760
+ },
761
+ showMore: (node) => {
762
+ if (manualGrouping) {
763
+ onGroupShowMore?.({ columnId: node.columnId, value: node.value, loaded: node.loaded });
764
+ return;
765
+ }
766
+ setLimitState({
767
+ key: resetKey,
768
+ limits: { ...limits, [node.id]: limitOf(node) + groupPageSize }
769
+ });
770
+ },
771
+ opened
772
+ };
773
+ }
774
+ function DataTableGroupToggle({
775
+ node,
776
+ grouping,
777
+ controls,
778
+ translations,
779
+ icons,
780
+ className
781
+ }) {
782
+ const format = new Intl.NumberFormat(useLocale()).format;
783
+ const expanded = grouping.isExpanded(node);
784
+ const foldable = node.count > 0;
785
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
786
+ /* @__PURE__ */ jsxs(
787
+ "button",
788
+ {
789
+ type: "button",
790
+ "aria-expanded": foldable ? expanded : void 0,
791
+ "aria-controls": foldable && expanded ? controls : void 0,
792
+ "aria-label": translations.groupToggle(grouping.label(node)),
793
+ disabled: !foldable,
794
+ onClick: () => grouping.toggle(node),
795
+ className: cn(
796
+ "inline-flex min-w-0 items-center gap-1.5 rounded-xxs font-medium select-none",
797
+ "enabled:cursor-pointer",
798
+ focusStyles({ offset: false }),
799
+ // The chevron is sized and coloured from here, so one passed through
800
+ // `icons` lands the same. It turns down while the group is open; when
801
+ // closed it follows the reading direction.
802
+ "[&>svg]:size-3.5 [&>svg]:shrink-0 [&>svg]:text-brand-900/40 dark:[&>svg]:text-white/35",
803
+ "enabled:hover:[&>svg]:text-brand-950 dark:enabled:hover:[&>svg]:text-white",
804
+ "motion-safe:[&>svg]:transition-transform motion-safe:[&>svg]:duration-(--duration-fast)",
805
+ foldable && expanded ? "[&>svg]:rotate-90" : "rtl:[&>svg]:rotate-180",
806
+ !foldable && "[&>svg]:opacity-40",
807
+ className
808
+ ),
809
+ children: [
810
+ icons.fold,
811
+ /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "pointer-events-none inline-flex min-w-0 items-center", children: grouping.renderValue(node) })
812
+ ]
813
+ }
814
+ ),
815
+ /* @__PURE__ */ jsxs(Text, { span: true, size: "xs", c: "muted", className: "tabular-nums", children: [
816
+ /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: format(node.count) }),
817
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: translations.groupCount(node.count, format(node.count)) })
818
+ ] })
819
+ ] });
820
+ }
821
+ function DataTableGroupShowMore({
822
+ node,
823
+ grouping,
824
+ translations
825
+ }) {
826
+ const format = new Intl.NumberFormat(useLocale()).format;
827
+ const next = grouping.nextCount(node);
828
+ return /* @__PURE__ */ jsx(Button, { variant: "subtle", color: "neutral", size: "xs", onClick: () => grouping.showMore(node), children: translations.showMore(next, format(next)) });
829
+ }
830
+ var groupHeaderCell = cn(
831
+ "bg-black/3 dark:bg-white/4",
832
+ "border-brand-900/20 dark:border-white/8",
833
+ // A hairline under the header unless it closes its `<tbody>` (a folded or empty
834
+ // last group): the next group's header, or the footer, draws that one.
835
+ "[tr:not(:last-child)>&]:border-b"
836
+ );
837
+ function DataTableGroupedBody({
838
+ grouping,
839
+ table,
840
+ colSpan,
841
+ renderRow,
842
+ selectable,
843
+ size,
844
+ translations,
845
+ icons,
846
+ className
847
+ }) {
848
+ const baseId = useId();
849
+ const header = (node, controls) => {
850
+ const selectableRows = groupLeafRows(node).filter((row) => row.getCanSelect());
851
+ const selectableIds = new Set(selectableRows.map((row) => row.id));
852
+ const selected = selectableRows.filter((row) => row.getIsSelected()).length;
853
+ const allLoadedSelected = selected === selectableRows.length;
854
+ const partlyLoaded = node.loaded < node.count;
855
+ return /* @__PURE__ */ jsx(
856
+ Table.Row,
857
+ {
858
+ testId: `group-${node.id}`,
859
+ "data-placeholder": true,
860
+ "data-group": true,
861
+ "data-depth": node.depth,
862
+ ...props({ "data-expanded": grouping.isExpanded(node) }),
863
+ children: /* @__PURE__ */ jsx(
864
+ Table.HeaderCell,
865
+ {
866
+ scope: node.depth === 0 ? "rowgroup" : "row",
867
+ colSpan,
868
+ className: cn(
869
+ groupHeaderCell,
870
+ node.depth === 0 && "[tbody:not(:first-of-type)_&]:border-t"
871
+ ),
872
+ children: /* @__PURE__ */ jsxs("div", { className: "sticky start-3 flex w-max max-w-full items-center gap-2", children: [
873
+ selectable && selectableRows.length > 0 && /* @__PURE__ */ jsx(
874
+ Checkbox,
875
+ {
876
+ size,
877
+ checked: selected === 0 ? false : allLoadedSelected && !partlyLoaded ? true : "indeterminate",
878
+ onCheckedChange: () => (
879
+ // Written to the leaf rows directly: the group row itself is never
880
+ // selectable, so `rowSelection` only ever holds real row ids. Decided
881
+ // from the rows, not from the checkbox: a partly loaded group reads
882
+ // indeterminate with every loaded row selected, and must still clear.
883
+ table.setRowSelection((old) => ({
884
+ ...Object.fromEntries(
885
+ Object.entries(old).filter(([id]) => !selectableIds.has(id))
886
+ ),
887
+ ...allLoadedSelected ? {} : Object.fromEntries(selectableRows.map((row) => [row.id, true]))
888
+ }))
889
+ ),
890
+ label: translations.selectGroup(grouping.label(node)),
891
+ classNames: { label: "sr-only" }
892
+ }
893
+ ),
894
+ /* @__PURE__ */ jsx(
895
+ DataTableGroupToggle,
896
+ {
897
+ node,
898
+ grouping,
899
+ controls,
900
+ translations,
901
+ icons,
902
+ className: node.depth > 0 ? "ms-6" : void 0
903
+ }
904
+ )
905
+ ] })
906
+ }
907
+ )
908
+ },
909
+ node.id
910
+ );
911
+ };
912
+ const leaves = (node) => [
913
+ ...grouping.visibleRows(node).map(
914
+ (row) => renderRow(row, {
915
+ className: grouping.opened.has(node.id) ? "motion-safe:animate-fade-in" : void 0,
916
+ // Rows under a sub-group step in with it, so they read as its children.
917
+ indent: node.depth > 0
918
+ })
919
+ ),
920
+ grouping.nextCount(node) > 0 && /* @__PURE__ */ jsx(Table.Row, { testId: `group-${node.id}-more`, "data-placeholder": true, children: /* @__PURE__ */ jsx(Table.Cell, { colSpan, children: /* @__PURE__ */ jsx("div", { className: cn("sticky start-3 w-max", node.depth > 0 && "ps-6"), children: /* @__PURE__ */ jsx(DataTableGroupShowMore, { node, grouping, translations }) }) }) }, `${node.id}-more`)
921
+ ];
922
+ return grouping.groups.map((node, index) => {
923
+ const bodyId = `${baseId}-group-${index}`;
924
+ return /* @__PURE__ */ jsxs(Table.Body, { id: bodyId, className, children: [
925
+ header(node, bodyId),
926
+ grouping.isExpanded(node) && (node.groups.length > 0 ? node.groups.flatMap((sub) => [
927
+ header(sub),
928
+ ...grouping.isExpanded(sub) ? leaves(sub) : []
929
+ ]) : leaves(node))
930
+ ] }, node.id);
931
+ });
932
+ }
933
+ function DataTableGroupSummary({
934
+ grouping,
935
+ translations,
936
+ className
937
+ }) {
938
+ const format = new Intl.NumberFormat(useLocale()).format;
939
+ const rows = grouping.rowCount;
940
+ const groups = grouping.groups.length;
941
+ return /* @__PURE__ */ jsx(
942
+ "div",
943
+ {
944
+ className: cn(
945
+ // The pagination band's own fill, hairline and padding.
946
+ "bg-brand-50/90 dark:bg-transparent",
947
+ "flex shrink-0 items-center border-t border-brand-900/20 px-4 py-3 dark:border-white/8",
948
+ className
949
+ ),
950
+ children: /* @__PURE__ */ jsx(Text, { span: true, size: "sm", c: "muted", role: "status", children: translations.groupSummary({
951
+ rows,
952
+ groups,
953
+ formatted: { rows: format(rows), groups: format(groups) }
954
+ }) })
955
+ }
956
+ );
957
+ }
598
958
  var RESIZE_STEP = 5;
599
959
  var columnLabel = (column) => {
600
960
  if (column.columnDef.meta?.label) return column.columnDef.meta.label;
@@ -810,6 +1170,7 @@ var DEFAULT_TRANSLATIONS = {
810
1170
  function DataTablePagination({
811
1171
  table,
812
1172
  pageSizeOptions = [10, 20, 50],
1173
+ rowsOnPage: rowsOnPageProp,
813
1174
  hasNextPage,
814
1175
  className,
815
1176
  translations: translationsProp,
@@ -819,7 +1180,7 @@ function DataTablePagination({
819
1180
  const { pageIndex, pageSize } = table.atoms.pagination.get();
820
1181
  const pageCount = table.getPageCount();
821
1182
  const totalKnown = pageCount >= 0;
822
- const rowsOnPage = table.getRowModel().rows.length;
1183
+ const rowsOnPage = rowsOnPageProp ?? table.getRowModel().rows.length;
823
1184
  const canPrevious = table.getCanPreviousPage();
824
1185
  const canNext = totalKnown ? table.getCanNextPage() : hasNextPage ?? rowsOnPage >= pageSize;
825
1186
  const translations = { ...DEFAULT_TRANSLATIONS, ...translationsProp };
@@ -938,8 +1299,122 @@ function RenderPlaceholder({
938
1299
  }
939
1300
  );
940
1301
  }
1302
+ function DataTableGlobalFilter({
1303
+ value,
1304
+ onChange,
1305
+ placeholder = "Search\u2026",
1306
+ debounce = 300,
1307
+ icon = DEFAULT_ICONS.search
1308
+ }) {
1309
+ const [local, setLocal] = useDebouncedCommit(value, debounce, onChange);
1310
+ return /* @__PURE__ */ jsx(
1311
+ Input,
1312
+ {
1313
+ size: "sm",
1314
+ placeholder,
1315
+ startSlot: icon,
1316
+ value: local,
1317
+ onChange: (e) => setLocal(e.target.value),
1318
+ className: "max-w-64"
1319
+ }
1320
+ );
1321
+ }
1322
+ function DataTableColumnVisibilityMenu({
1323
+ table,
1324
+ label,
1325
+ icon = DEFAULT_ICONS.columns,
1326
+ className
1327
+ }) {
1328
+ const columns = table.getAllLeafColumns().filter((column) => !column.columnDef.meta?.hideFromMenu);
1329
+ return /* @__PURE__ */ jsxs(Root, { closeOnSelect: false, position: "bottom-end", children: [
1330
+ /* @__PURE__ */ jsx(Trigger, { asChild: true, children: /* @__PURE__ */ jsx(
1331
+ ActionIcon,
1332
+ {
1333
+ variant: "subtle",
1334
+ color: "neutral",
1335
+ size: "sm",
1336
+ "aria-label": label,
1337
+ className,
1338
+ children: icon
1339
+ }
1340
+ ) }),
1341
+ /* @__PURE__ */ jsx(Content, { children: columns.map((column) => /* @__PURE__ */ jsx(
1342
+ CheckboxItem,
1343
+ {
1344
+ value: column.id,
1345
+ checked: column.getIsVisible(),
1346
+ disabled: !column.getCanHide(),
1347
+ onCheckedChange: () => column.toggleVisibility(),
1348
+ children: columnLabel(column)
1349
+ },
1350
+ column.id
1351
+ )) })
1352
+ ] });
1353
+ }
1354
+ var NO_GROUP = "__none__";
1355
+ var pickGrouping = (grouping, level, value) => value === NO_GROUP ? grouping.slice(0, level) : [
1356
+ ...grouping.slice(0, level),
1357
+ value,
1358
+ ...grouping.slice(level + 1).filter((id) => id !== value)
1359
+ ];
1360
+ var groupingChoices = (table, grouping, level) => [
1361
+ { value: NO_GROUP, label: void 0 },
1362
+ ...table.getAllLeafColumns().filter((column) => column.getCanGroup() && !grouping.slice(0, level).includes(column.id)).map((column) => ({ value: column.id, label: columnLabel(column) }))
1363
+ ];
1364
+ var groupingLevels = (grouping, maxDepth) => Array.from({ length: Math.min(grouping.length + 1, maxDepth) }, (_, level) => level);
1365
+ function DataTableGroupMenu({
1366
+ table,
1367
+ grouping,
1368
+ onGroupingChange,
1369
+ maxDepth,
1370
+ hideEmptyGroups,
1371
+ onHideEmptyGroupsChange,
1372
+ translations,
1373
+ icon = DEFAULT_ICONS.group,
1374
+ className
1375
+ }) {
1376
+ return /* @__PURE__ */ jsxs(Root, { closeOnSelect: false, position: "bottom-end", children: [
1377
+ /* @__PURE__ */ jsx(Trigger, { asChild: true, children: /* @__PURE__ */ jsx(
1378
+ ActionIcon,
1379
+ {
1380
+ variant: "subtle",
1381
+ color: "neutral",
1382
+ size: "sm",
1383
+ "aria-label": translations.group,
1384
+ className,
1385
+ children: icon
1386
+ }
1387
+ ) }),
1388
+ /* @__PURE__ */ jsxs(Content, { children: [
1389
+ groupingLevels(grouping, maxDepth).map((level) => /* @__PURE__ */ jsxs(Fragment$1, { children: [
1390
+ /* @__PURE__ */ jsxs(
1391
+ RadioGroup,
1392
+ {
1393
+ value: `${level}:${grouping[level] ?? NO_GROUP}`,
1394
+ onChange: (value) => onGroupingChange(pickGrouping(grouping, level, value.slice(`${level}:`.length))),
1395
+ children: [
1396
+ /* @__PURE__ */ jsx(ItemGroupLabel, { children: level === 0 ? translations.groupBy : translations.groupThenBy }),
1397
+ groupingChoices(table, grouping, level).map((choice) => /* @__PURE__ */ jsx(RadioItem, { value: `${level}:${choice.value}`, children: choice.label ?? translations.groupNone }, choice.value))
1398
+ ]
1399
+ }
1400
+ ),
1401
+ /* @__PURE__ */ jsx(Divider, {})
1402
+ ] }, level)),
1403
+ /* @__PURE__ */ jsx(
1404
+ CheckboxItem,
1405
+ {
1406
+ value: "hide-empty-groups",
1407
+ checked: hideEmptyGroups,
1408
+ onCheckedChange: (checked) => onHideEmptyGroupsChange(checked === true),
1409
+ children: translations.hideEmptyGroups
1410
+ }
1411
+ )
1412
+ ] })
1413
+ ] });
1414
+ }
941
1415
  function DataTableStackedRows({
942
1416
  rows,
1417
+ grouping,
943
1418
  view,
944
1419
  error,
945
1420
  refetching,
@@ -953,6 +1428,7 @@ function DataTableStackedRows({
953
1428
  translations,
954
1429
  icons
955
1430
  }) {
1431
+ const stackId = useId();
956
1432
  return /* @__PURE__ */ jsx("div", { className: cn("flex flex-1 min-h-0 flex-col gap-2 overflow-y-auto p-3", className), children: match(view).with("error", () => /* @__PURE__ */ jsxs(
957
1433
  "div",
958
1434
  {
@@ -1008,6 +1484,76 @@ function DataTableStackedRows({
1008
1484
  const headersByColumnId = new Map(
1009
1485
  table.getFlatHeaders().map((header) => [header.column.id, header])
1010
1486
  );
1487
+ const renderCard = (row, cardClassName) => /* @__PURE__ */ jsx(
1488
+ Card,
1489
+ {
1490
+ padding: "sm",
1491
+ className: cn(
1492
+ "transition-colors",
1493
+ cardClassName,
1494
+ // Same black/white wash convention as Table's row hover/
1495
+ // DataTable's row selection, instead of a fixed per-theme gray.
1496
+ "hover:bg-black/5 dark:hover:bg-white/8",
1497
+ "data-[selected=true]:bg-black/8 dark:data-[selected=true]:bg-white/16",
1498
+ onRowClick && "cursor-pointer"
1499
+ ),
1500
+ ...props({ "data-selected": row.getIsSelected() }),
1501
+ onClick: onRowClick ? (event) => {
1502
+ if (!isRowClickIgnored2(event.target, event.currentTarget)) {
1503
+ onRowClick(row.original);
1504
+ }
1505
+ } : void 0,
1506
+ children: /* @__PURE__ */ jsx(Flex, { direction: "col", gap: "xs", children: row.getVisibleCells().map((cell) => {
1507
+ const header = headersByColumnId.get(cell.column.id);
1508
+ return /* @__PURE__ */ jsxs(Flex, { justify: "between", gap: "sm", children: [
1509
+ /* @__PURE__ */ jsx(Text, { size: "xs", c: "muted", children: header ? renderColumnHeader(header, "stack") : columnLabel(cell.column) }),
1510
+ /* @__PURE__ */ jsx("div", { children: flexRender(cell.column.columnDef.cell, cell.getContext()) })
1511
+ ] }, cell.id);
1512
+ }) })
1513
+ },
1514
+ row.id
1515
+ );
1516
+ const section = (node, path) => {
1517
+ if (!grouping) return null;
1518
+ const headingId = `${stackId}-group-${path}`;
1519
+ return /* @__PURE__ */ jsxs(
1520
+ "section",
1521
+ {
1522
+ "aria-labelledby": headingId,
1523
+ "data-group": true,
1524
+ "data-depth": node.depth,
1525
+ className: cn("flex flex-col gap-2", node.depth > 0 && "ps-3"),
1526
+ children: [
1527
+ /* @__PURE__ */ jsx("div", { id: headingId, className: "flex items-center gap-2 pt-1 text-sm", children: /* @__PURE__ */ jsx(
1528
+ DataTableGroupToggle,
1529
+ {
1530
+ node,
1531
+ grouping,
1532
+ translations,
1533
+ icons
1534
+ }
1535
+ ) }),
1536
+ grouping.isExpanded(node) && (node.groups.length > 0 ? node.groups.map((sub, index) => section(sub, `${path}-${index}`)) : /* @__PURE__ */ jsxs(Fragment, { children: [
1537
+ grouping.visibleRows(node).map(
1538
+ (row) => renderCard(
1539
+ row,
1540
+ grouping.opened.has(node.id) ? "motion-safe:animate-fade-in" : void 0
1541
+ )
1542
+ ),
1543
+ grouping.nextCount(node) > 0 && /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
1544
+ DataTableGroupShowMore,
1545
+ {
1546
+ node,
1547
+ grouping,
1548
+ translations
1549
+ }
1550
+ ) })
1551
+ ] }))
1552
+ ]
1553
+ },
1554
+ node.id
1555
+ );
1556
+ };
1011
1557
  return /* @__PURE__ */ jsx(
1012
1558
  "div",
1013
1559
  {
@@ -1015,34 +1561,7 @@ function DataTableStackedRows({
1015
1561
  "flex flex-col gap-2",
1016
1562
  refetching && "pointer-events-none opacity-60 transition-opacity"
1017
1563
  ),
1018
- children: rows.map((row) => /* @__PURE__ */ jsx(
1019
- Card,
1020
- {
1021
- padding: "sm",
1022
- className: cn(
1023
- "transition-colors",
1024
- // Same black/white wash convention as Table's row hover/
1025
- // DataTable's row selection, instead of a fixed per-theme gray.
1026
- "hover:bg-black/5 dark:hover:bg-white/8",
1027
- "data-[selected=true]:bg-black/8 dark:data-[selected=true]:bg-white/16",
1028
- onRowClick && "cursor-pointer"
1029
- ),
1030
- ...props({ "data-selected": row.getIsSelected() }),
1031
- onClick: onRowClick ? (event) => {
1032
- if (!isRowClickIgnored2(event.target, event.currentTarget)) {
1033
- onRowClick(row.original);
1034
- }
1035
- } : void 0,
1036
- children: /* @__PURE__ */ jsx(Flex, { direction: "col", gap: "xs", children: row.getVisibleCells().map((cell) => {
1037
- const header = headersByColumnId.get(cell.column.id);
1038
- return /* @__PURE__ */ jsxs(Flex, { justify: "between", gap: "sm", children: [
1039
- /* @__PURE__ */ jsx(Text, { size: "xs", c: "muted", children: header ? renderColumnHeader(header, "stack") : columnLabel(cell.column) }),
1040
- /* @__PURE__ */ jsx("div", { children: flexRender(cell.column.columnDef.cell, cell.getContext()) })
1041
- ] }, cell.id);
1042
- }) })
1043
- },
1044
- row.id
1045
- ))
1564
+ children: grouping ? grouping.groups.map((node, index) => section(node, String(index))) : rows.map((row) => renderCard(row))
1046
1565
  }
1047
1566
  );
1048
1567
  }).exhaustive() });
@@ -1050,6 +1569,7 @@ function DataTableStackedRows({
1050
1569
  function DataTableStackOptions({
1051
1570
  table,
1052
1571
  enableColumnVisibility,
1572
+ grouping,
1053
1573
  translations,
1054
1574
  icons,
1055
1575
  className
@@ -1058,7 +1578,7 @@ function DataTableStackOptions({
1058
1578
  const visibleColumns = table.getVisibleLeafColumns();
1059
1579
  const sortableColumns = visibleColumns.filter((column) => column.getCanSort());
1060
1580
  const filterableColumns = visibleColumns.filter((column) => column.columnDef.meta?.filter != null);
1061
- if (sortableColumns.length === 0 && filterableColumns.length === 0 && !enableColumnVisibility) {
1581
+ if (sortableColumns.length === 0 && filterableColumns.length === 0 && !enableColumnVisibility && !grouping) {
1062
1582
  return null;
1063
1583
  }
1064
1584
  const activeFilterCount = filterableColumns.filter(
@@ -1093,6 +1613,34 @@ function DataTableStackOptions({
1093
1613
  open,
1094
1614
  onOpenChange: setOpen,
1095
1615
  children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
1616
+ grouping && /* @__PURE__ */ jsxs(Fragment, { children: [
1617
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
1618
+ groupingLevels(grouping.value, grouping.maxDepth).map((level) => /* @__PURE__ */ jsx(
1619
+ Select,
1620
+ {
1621
+ size: "sm",
1622
+ label: level === 0 ? translations.groupBy : translations.groupThenBy,
1623
+ data: groupingChoices(table, grouping.value, level).map((choice) => ({
1624
+ value: choice.value,
1625
+ label: choice.label ?? translations.groupNone
1626
+ })),
1627
+ value: grouping.value[level] ?? groupingChoices(table, grouping.value, level)[0]?.value,
1628
+ onChange: (value) => value && grouping.onChange(pickGrouping(grouping.value, level, value))
1629
+ },
1630
+ level
1631
+ )),
1632
+ /* @__PURE__ */ jsx(
1633
+ Checkbox,
1634
+ {
1635
+ size: "sm",
1636
+ checked: grouping.hideEmptyGroups,
1637
+ onCheckedChange: (checked) => grouping.onHideEmptyGroupsChange(checked === true),
1638
+ label: translations.hideEmptyGroups
1639
+ }
1640
+ )
1641
+ ] }),
1642
+ (enableColumnVisibility || sortableColumns.length > 0 || filterableColumns.length > 0) && /* @__PURE__ */ jsx("hr", { className: "mt-6 mb-2 border-0 border-t border-brand-900/20 dark:border-white/8" })
1643
+ ] }),
1096
1644
  enableColumnVisibility && /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
1097
1645
  /* @__PURE__ */ jsxs(Text, { size: "xs", c: "muted", className: "uppercase tracking-wide", children: [
1098
1646
  /* @__PURE__ */ jsx("span", { "aria-hidden": true, children: "// " }),
@@ -1192,58 +1740,6 @@ function DataTableStackOptions({
1192
1740
  )
1193
1741
  ] });
1194
1742
  }
1195
- function DataTableGlobalFilter({
1196
- value,
1197
- onChange,
1198
- placeholder = "Search\u2026",
1199
- debounce = 300,
1200
- icon = DEFAULT_ICONS.search
1201
- }) {
1202
- const [local, setLocal] = useDebouncedCommit(value, debounce, onChange);
1203
- return /* @__PURE__ */ jsx(
1204
- Input,
1205
- {
1206
- size: "sm",
1207
- placeholder,
1208
- startSlot: icon,
1209
- value: local,
1210
- onChange: (e) => setLocal(e.target.value),
1211
- className: "max-w-64"
1212
- }
1213
- );
1214
- }
1215
- function DataTableColumnVisibilityMenu({
1216
- table,
1217
- label,
1218
- icon = DEFAULT_ICONS.columns,
1219
- className
1220
- }) {
1221
- const columns = table.getAllLeafColumns().filter((column) => !column.columnDef.meta?.hideFromMenu);
1222
- return /* @__PURE__ */ jsxs(Root, { closeOnSelect: false, position: "bottom-end", children: [
1223
- /* @__PURE__ */ jsx(Trigger, { asChild: true, children: /* @__PURE__ */ jsx(
1224
- ActionIcon,
1225
- {
1226
- variant: "subtle",
1227
- color: "neutral",
1228
- size: "sm",
1229
- "aria-label": label,
1230
- className,
1231
- children: icon
1232
- }
1233
- ) }),
1234
- /* @__PURE__ */ jsx(Content, { children: columns.map((column) => /* @__PURE__ */ jsx(
1235
- CheckboxItem,
1236
- {
1237
- value: column.id,
1238
- checked: column.getIsVisible(),
1239
- disabled: !column.getCanHide(),
1240
- onCheckedChange: () => column.toggleVisibility(),
1241
- children: columnLabel(column)
1242
- },
1243
- column.id
1244
- )) })
1245
- ] });
1246
- }
1247
1743
  var INTERACTIVE_SELECTOR = [
1248
1744
  "a[href]",
1249
1745
  "button",
@@ -1322,16 +1818,22 @@ function createSelectColumn(size, labels) {
1322
1818
  meta: {
1323
1819
  hideFromMenu: true
1324
1820
  },
1325
- header: ({ table, mode }) => mode === "table" ? /* @__PURE__ */ jsx(
1326
- Checkbox,
1327
- {
1328
- size,
1329
- checked: table.getIsAllPageRowsSelected() ? true : table.getIsSomePageRowsSelected() ? "indeterminate" : false,
1330
- onCheckedChange: (checked) => table.toggleAllPageRowsSelected(checked === true),
1331
- label: labels.current.selectAllRows,
1332
- classNames: { label: "sr-only" }
1333
- }
1334
- ) : null,
1821
+ header: ({ table, mode }) => {
1822
+ if (mode !== "table") return null;
1823
+ const grouped = table.atoms.grouping.get().length > 0;
1824
+ const all = grouped ? table.getIsAllRowsSelected() : table.getIsAllPageRowsSelected();
1825
+ const some = grouped ? table.getIsSomeRowsSelected() : table.getIsSomePageRowsSelected();
1826
+ return /* @__PURE__ */ jsx(
1827
+ Checkbox,
1828
+ {
1829
+ size,
1830
+ checked: all ? true : some ? "indeterminate" : false,
1831
+ onCheckedChange: (checked) => grouped ? table.toggleAllRowsSelected(checked === true) : table.toggleAllPageRowsSelected(checked === true),
1832
+ label: labels.current.selectAllRows,
1833
+ classNames: { label: "sr-only" }
1834
+ }
1835
+ );
1836
+ },
1335
1837
  cell: ({ row }) => /* @__PURE__ */ jsx("span", { className: "flex flex-row justify-center items-center", children: /* @__PURE__ */ jsx(
1336
1838
  Checkbox,
1337
1839
  {
@@ -1366,10 +1868,19 @@ function DataTableComponent({
1366
1868
  onColumnVisibilityChange,
1367
1869
  columnSizing: columnSizingProp,
1368
1870
  onColumnSizingChange,
1871
+ grouping: groupingProp,
1872
+ onGroupingChange,
1873
+ expanded: expandedProp,
1874
+ onExpandedChange,
1875
+ hideEmptyGroups: hideEmptyGroupsProp,
1876
+ onHideEmptyGroupsChange,
1369
1877
  initialState,
1370
1878
  manualSorting,
1371
1879
  manualFiltering,
1372
1880
  manualPagination,
1881
+ manualGrouping = false,
1882
+ groups: manualGroups,
1883
+ onGroupShowMore,
1373
1884
  enableMultiSort,
1374
1885
  rowCount,
1375
1886
  pageCount,
@@ -1390,6 +1901,10 @@ function DataTableComponent({
1390
1901
  globalFilterPlaceholder,
1391
1902
  globalFilterDebounce,
1392
1903
  enableColumnVisibility: _enableColumnVisibility,
1904
+ enableGrouping,
1905
+ hideGroupedColumns = true,
1906
+ groupPageSize = 25,
1907
+ renderGroupHeader,
1393
1908
  enableColumnResizing,
1394
1909
  enablePagination = true,
1395
1910
  sizing = "fixed",
@@ -1447,13 +1962,35 @@ function DataTableComponent({
1447
1962
  onChange: onColumnSizingChange,
1448
1963
  defaultValue: initialState?.columnSizing ?? {}
1449
1964
  });
1965
+ const [grouping, handleGroupingChange] = useUncontrolled({
1966
+ value: groupingProp,
1967
+ onChange: (value) => {
1968
+ resetPagignation();
1969
+ onGroupingChange?.(value);
1970
+ },
1971
+ defaultValue: initialState?.grouping ?? []
1972
+ });
1973
+ const [expanded, handleExpandedChange] = useUncontrolled({
1974
+ value: expandedProp,
1975
+ onChange: onExpandedChange,
1976
+ defaultValue: initialState?.expanded ?? true
1977
+ });
1978
+ const [hideEmptyGroups, handleHideEmptyGroupsChange] = useUncontrolled({
1979
+ value: hideEmptyGroupsProp,
1980
+ onChange: onHideEmptyGroupsChange,
1981
+ defaultValue: initialState?.hideEmptyGroups ?? true
1982
+ });
1450
1983
  const resolvedTranslations = resolveDataTableTranslations(translations);
1451
1984
  const selectLabels = { ...resolvedTranslations, rowLabel: getRowLabel };
1452
1985
  const selectLabelsRef = useRef(selectLabels);
1453
1986
  const icons = resolveDataTableIcons(iconsProp);
1454
1987
  selectLabelsRef.current = selectLabels;
1455
1988
  const tableColumns = useMemo(() => {
1456
- const withFilterFns = columns.map((col) => {
1989
+ const withFilterFns = columns.map((column) => {
1990
+ const col = {
1991
+ ...column,
1992
+ enableGrouping: column.enableGrouping ?? column.meta?.groupable === true
1993
+ };
1457
1994
  const filter = col.meta?.filter;
1458
1995
  if (!filter || col.filterFn != null) return col;
1459
1996
  return { ...col, filterFn: resolveFilterFn(filter) };
@@ -1462,6 +1999,35 @@ function DataTableComponent({
1462
1999
  const selectColumn = createSelectColumn(size ?? "md", selectLabelsRef);
1463
2000
  return [selectColumn, ...withFilterFns];
1464
2001
  }, [columns, enableRowSelection, size]);
2002
+ const maxGroupingDepth = manualGrouping ? 1 : MAX_GROUPING_DEPTH;
2003
+ const { activeGrouping, groupingVisibility } = useMemo(() => {
2004
+ const idOf = (col) => "accessorKey" in col && col.id == null ? String(col.accessorKey).replaceAll(".", "_") : col.id;
2005
+ const groupable = new Set(
2006
+ tableColumns.filter(
2007
+ (col) => col.enableGrouping && ("accessorKey" in col || "accessorFn" in col || col.getGroupingValue != null)
2008
+ ).map(idOf)
2009
+ );
2010
+ const pinnedVisible = new Set(
2011
+ tableColumns.filter((col) => col.enableHiding === false).map(idOf)
2012
+ );
2013
+ const active = grouping.filter((id) => groupable.has(id)).slice(0, maxGroupingDepth);
2014
+ return {
2015
+ activeGrouping: active,
2016
+ // A grouped column is hidden by default: every row of a group would repeat
2017
+ // what its header already says. Only a default, laid under `columnVisibility`
2018
+ // below, so an explicit entry (the column menu's toggle, or the app's own
2019
+ // state) shows it again. A column that can't be hidden is left alone, since
2020
+ // nothing could bring it back.
2021
+ groupingVisibility: Object.fromEntries(
2022
+ active.filter((id) => hideGroupedColumns && !pinnedVisible.has(id)).map((id) => [id, false])
2023
+ )
2024
+ };
2025
+ }, [tableColumns, grouping, maxGroupingDepth, hideGroupedColumns]);
2026
+ if (activeGrouping.length < grouping.length) {
2027
+ devWarnOnce(
2028
+ `[DataTable] \`grouping\` is ${JSON.stringify(grouping)}, but only ${JSON.stringify(activeGrouping)} applies: a column must opt in with \`meta.groupable\` and the table groups ${maxGroupingDepth === 1 ? "one level deep under `manualGrouping`" : `at most ${maxGroupingDepth} levels deep`}.`
2029
+ );
2030
+ }
1465
2031
  const { dir } = useLocaleContext();
1466
2032
  const table = useTable({
1467
2033
  // v9 makes features opt-in; `dataTableFeatures` is the kit's registry and
@@ -1479,8 +2045,12 @@ function DataTableComponent({
1479
2045
  globalFilter,
1480
2046
  pagination,
1481
2047
  rowSelection,
1482
- columnVisibility,
1483
- columnSizing
2048
+ // `onColumnVisibilityChange` still resolves against `columnVisibility` alone,
2049
+ // so the grouping default never leaks into the app's state.
2050
+ columnVisibility: { ...groupingVisibility, ...columnVisibility },
2051
+ columnSizing,
2052
+ grouping: activeGrouping,
2053
+ expanded
1484
2054
  },
1485
2055
  onSortingChange: handleSortingChange,
1486
2056
  onColumnFiltersChange: handleColumnFiltersChange,
@@ -1489,11 +2059,22 @@ function DataTableComponent({
1489
2059
  onRowSelectionChange: handleRowSelectionChange,
1490
2060
  onColumnVisibilityChange: handleColumnVisibilityChange,
1491
2061
  onColumnSizingChange: handleColumnSizingChange,
2062
+ onGroupingChange: handleGroupingChange,
2063
+ onExpandedChange: handleExpandedChange,
2064
+ // The grouped column stays where the app put it, after the select column.
2065
+ groupedColumnMode: false,
2066
+ // A refetch or a filter change must not reopen what the user folded.
2067
+ autoResetExpanded: false,
2068
+ // Groups are open unless folded, see `isGroupExpanded`; any other row keeps
2069
+ // react-table's reading of `expanded`.
2070
+ getIsRowExpanded: (row) => row.getIsGrouped() ? isGroupExpanded(expanded, row.id) : expanded === true || expanded[row.id] === true,
1492
2071
  manualSorting,
1493
2072
  manualFiltering,
1494
2073
  manualPagination,
1495
2074
  enableMultiSort,
1496
- enableRowSelection,
2075
+ // A group row is never selectable itself: its checkbox selects its rows, and
2076
+ // `rowSelection` only ever holds real row ids.
2077
+ enableRowSelection: (row) => !row.getIsGrouped() && (typeof enableRowSelection === "function" ? enableRowSelection(row) : enableRowSelection ?? true),
1497
2078
  // No fixed width for a drag to adjust in "auto" mode — see the `sizing` prop doc.
1498
2079
  enableColumnResizing: Boolean(enableColumnResizing) && sizing === "fixed",
1499
2080
  columnResizeMode: "onChange",
@@ -1501,22 +2082,91 @@ function DataTableComponent({
1501
2082
  rowCount,
1502
2083
  pageCount
1503
2084
  });
1504
- const rows = table.getRowModel().rows;
2085
+ const groupsOnePage = Boolean(manualPagination) && !manualGrouping;
2086
+ if (groupsOnePage && activeGrouping.length > 0) {
2087
+ devWarnOnce(
2088
+ "[DataTable] `grouping` with `manualPagination` only groups the rows of the current page, so a group's count is its count on this page. Pass `manualGrouping` with `groups` and `onGroupShowMore` to let the server own the groups."
2089
+ );
2090
+ }
2091
+ const groupingView = useDataTableGrouping({
2092
+ table,
2093
+ grouping: activeGrouping,
2094
+ expanded,
2095
+ onExpandedChange: handleExpandedChange,
2096
+ hideEmptyGroups,
2097
+ paginate: enablePagination && !groupsOnePage,
2098
+ groupPageSize,
2099
+ manualGrouping,
2100
+ manualGroups,
2101
+ onGroupShowMore,
2102
+ renderGroupHeader,
2103
+ translations: resolvedTranslations,
2104
+ resetKey: JSON.stringify([activeGrouping, sorting, columnFilters, globalFilter])
2105
+ });
2106
+ const rows = groupingView ? [] : table.getRowModel().rows;
2107
+ const loadedCount = groupingView ? groupingView.groups.reduce((sum, group) => sum + group.loaded, 0) : rows.length;
2108
+ const itemCount = groupingView ? groupingView.groups.length : rows.length;
1505
2109
  const visibleColumnCount = table.getVisibleLeafColumns().length;
1506
- const showSkeleton = loading && rows.length === 0;
1507
- const isRefetching = loading && rows.length > 0;
2110
+ const showSkeleton = loading && loadedCount === 0;
2111
+ const isRefetching = loading && loadedCount > 0;
1508
2112
  const skeletonRowCount = Math.min(Math.max(pagination.pageSize, 1), 100);
1509
2113
  const handleRowClick = (row) => (event) => {
1510
2114
  if (!onRowClick || isRowClickIgnored(event.target, event.currentTarget)) return;
1511
2115
  onRowClick(row);
1512
2116
  };
1513
2117
  const enableColumnVisibility = _enableColumnVisibility && table.getAllLeafColumns().some((column) => !column.columnDef.meta?.hideFromMenu);
1514
- const showToolbar = title != null || toolbarActions != null || enableGlobalFilter || enableColumnVisibility;
2118
+ const showGroupMenu = enableGrouping && table.getAllLeafColumns().some((column) => column.getCanGroup());
2119
+ const showToolbar = title != null || toolbarActions != null || enableGlobalFilter || enableColumnVisibility || showGroupMenu;
1515
2120
  const titleId = useId();
1516
2121
  const isStacked = responsive === "stack";
1517
2122
  const isFixedSizing = sizing === "fixed";
1518
2123
  const isFillLast = isFixedSizing && fillLastColumn;
1519
- const view = match({ error, showSkeleton, items: rows.length }).with({ error: P.nonNullable }, () => "error").with({ showSkeleton: true }, () => "loading").with({ items: P.number.lte(0) }, () => "empty").otherwise(() => "items");
2124
+ const view = match({ error, showSkeleton, items: itemCount }).with({ error: P.nonNullable }, () => "error").with({ showSkeleton: true }, () => "loading").with({ items: P.number.lte(0) }, () => "empty").otherwise(() => "items");
2125
+ const bodyClassName = cn(
2126
+ classNames?.body,
2127
+ isRefetching && "pointer-events-none opacity-60 transition-opacity"
2128
+ );
2129
+ const leafIndent = `${SELECT_CELL_PADDING_PX[size ?? "md"] + (enableRowSelection ? 28 : 44)}px`;
2130
+ const renderRow = (row, { className: rowClassName, indent = false } = {}) => {
2131
+ const rowTestId = getRowTestId ? getRowTestId(row.original, row.id) : defaultRowTestId(row.id);
2132
+ const indentedColumnId = indent ? row.getVisibleCells().find((cell) => cell.column.id !== "__select__")?.column.id : void 0;
2133
+ return /* @__PURE__ */ jsx(
2134
+ Table.Row,
2135
+ {
2136
+ testId: rowTestId,
2137
+ onClick: onRowClick ? handleRowClick(row.original) : void 0,
2138
+ className: cn(onRowClick && "cursor-pointer", rowClassName, classNames?.row),
2139
+ ...props({ "data-selected": row.getIsSelected() }),
2140
+ children: row.getVisibleCells().map((cell, index, cells) => {
2141
+ const fillsRemaining = isFillLast && index === cells.length - 1;
2142
+ const indented = cell.column.id === indentedColumnId;
2143
+ return /* @__PURE__ */ jsx(
2144
+ Table.Cell,
2145
+ {
2146
+ testId: `${rowTestId}-cell-${cell.column.id}`,
2147
+ style: {
2148
+ width: isFixedSizing && !fillsRemaining ? cell.column.getSize() : void 0,
2149
+ "--data-table-leaf-indent": indented ? leafIndent : void 0
2150
+ },
2151
+ className: cn(
2152
+ tableCell({
2153
+ align: cell.column.columnDef.meta?.align
2154
+ }),
2155
+ isFixedSizing && cell.column.id !== "__select__" && "truncate",
2156
+ // Through a custom property, with `!`: the cell padding comes from a
2157
+ // descendant rule on the table root, which a plain utility loses to.
2158
+ indented && "ps-(--data-table-leaf-indent)!",
2159
+ classNames?.cell
2160
+ ),
2161
+ children: flexRender(cell.column.columnDef.cell, cell.getContext())
2162
+ },
2163
+ cell.id
2164
+ );
2165
+ })
2166
+ },
2167
+ row.id
2168
+ );
2169
+ };
1520
2170
  return /* @__PURE__ */ jsxs(
1521
2171
  Table,
1522
2172
  {
@@ -1552,6 +2202,20 @@ function DataTableComponent({
1552
2202
  }
1553
2203
  ),
1554
2204
  toolbarActions,
2205
+ showGroupMenu && /* @__PURE__ */ jsx(
2206
+ DataTableGroupMenu,
2207
+ {
2208
+ table,
2209
+ grouping: activeGrouping,
2210
+ onGroupingChange: handleGroupingChange,
2211
+ maxDepth: maxGroupingDepth,
2212
+ hideEmptyGroups,
2213
+ onHideEmptyGroupsChange: handleHideEmptyGroupsChange,
2214
+ translations: resolvedTranslations,
2215
+ icon: icons.group,
2216
+ className: isStacked ? "hidden @lg:flex" : void 0
2217
+ }
2218
+ ),
1555
2219
  enableColumnVisibility && /* @__PURE__ */ jsx(
1556
2220
  DataTableColumnVisibilityMenu,
1557
2221
  {
@@ -1619,130 +2283,98 @@ function DataTableComponent({
1619
2283
  header.id
1620
2284
  );
1621
2285
  }) }, headerGroup.id)) }),
1622
- /* @__PURE__ */ jsx(
1623
- Table.Body,
2286
+ view === "items" && groupingView ? /* @__PURE__ */ jsx(
2287
+ DataTableGroupedBody,
1624
2288
  {
1625
- className: cn(
1626
- classNames?.body,
1627
- isRefetching && "pointer-events-none opacity-60 transition-opacity"
1628
- ),
1629
- children: match(view).with("error", () => /* @__PURE__ */ jsx(Table.Row, { "data-placeholder": true, children: /* @__PURE__ */ jsx(
1630
- Table.Cell,
1631
- {
1632
- colSpan: visibleColumnCount,
1633
- className: cn("py-6 text-center", classNames?.error),
1634
- children: /* @__PURE__ */ jsxs(
1635
- "div",
1636
- {
1637
- role: "alert",
1638
- className: "flex flex-col gap-3 items-center justify-center min-h-48.5",
1639
- children: [
1640
- icons.error != null && /* @__PURE__ */ jsx(ThemeIcon, { children: icons.error }),
1641
- /* @__PURE__ */ jsx(
1642
- RenderPlaceholder,
1643
- {
1644
- node: error,
1645
- defaultActions: onRetry && /* @__PURE__ */ jsx(
1646
- Button,
1647
- {
1648
- variant: "light",
1649
- color: "neutral",
1650
- size: "sm",
1651
- startSlot: icons.retry,
1652
- onClick: onRetry,
1653
- children: resolvedTranslations.retry
1654
- }
1655
- )
1656
- }
1657
- )
1658
- ]
1659
- }
1660
- )
1661
- }
1662
- ) })).with("empty", () => /* @__PURE__ */ jsx(Table.Row, { "data-placeholder": true, children: /* @__PURE__ */ jsx(
1663
- Table.Cell,
2289
+ grouping: groupingView,
2290
+ table,
2291
+ colSpan: visibleColumnCount,
2292
+ renderRow,
2293
+ selectable: Boolean(enableRowSelection),
2294
+ size: size ?? "md",
2295
+ translations: resolvedTranslations,
2296
+ icons,
2297
+ className: bodyClassName
2298
+ }
2299
+ ) : /* @__PURE__ */ jsx(Table.Body, { className: bodyClassName, children: match(view).with("error", () => /* @__PURE__ */ jsx(Table.Row, { "data-placeholder": true, children: /* @__PURE__ */ jsx(
2300
+ Table.Cell,
2301
+ {
2302
+ colSpan: visibleColumnCount,
2303
+ className: cn("py-6 text-center", classNames?.error),
2304
+ children: /* @__PURE__ */ jsxs(
2305
+ "div",
1664
2306
  {
1665
- colSpan: visibleColumnCount,
1666
- className: cn("py-6 text-center", classNames?.empty),
1667
- children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3 items-center justify-center min-h-48.5", children: [
1668
- icons.empty != null && /* @__PURE__ */ jsx(ThemeIcon, { children: icons.empty }),
2307
+ role: "alert",
2308
+ className: "flex flex-col gap-3 items-center justify-center min-h-48.5",
2309
+ children: [
2310
+ icons.error != null && /* @__PURE__ */ jsx(ThemeIcon, { children: icons.error }),
1669
2311
  /* @__PURE__ */ jsx(
1670
2312
  RenderPlaceholder,
1671
2313
  {
1672
- node: empty,
1673
- defaultActions: /* @__PURE__ */ jsx(
2314
+ node: error,
2315
+ defaultActions: onRetry && /* @__PURE__ */ jsx(
1674
2316
  Button,
1675
2317
  {
1676
2318
  variant: "light",
1677
2319
  color: "neutral",
1678
2320
  size: "sm",
1679
- startSlot: icons.clear,
1680
- onClick: () => table.resetColumnFilters(),
1681
- children: resolvedTranslations.clearFilters
2321
+ startSlot: icons.retry,
2322
+ onClick: onRetry,
2323
+ children: resolvedTranslations.retry
1682
2324
  }
1683
2325
  )
1684
2326
  }
1685
2327
  )
1686
- ] })
2328
+ ]
1687
2329
  }
1688
- ) })).with(
1689
- "loading",
1690
- () => Array.from({ length: skeletonRowCount }).map((_, rowIndex) => /* @__PURE__ */ jsx(
1691
- Table.Row,
2330
+ )
2331
+ }
2332
+ ) })).with("empty", () => /* @__PURE__ */ jsx(Table.Row, { "data-placeholder": true, children: /* @__PURE__ */ jsx(
2333
+ Table.Cell,
2334
+ {
2335
+ colSpan: visibleColumnCount,
2336
+ className: cn("py-6 text-center", classNames?.empty),
2337
+ children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3 items-center justify-center min-h-48.5", children: [
2338
+ icons.empty != null && /* @__PURE__ */ jsx(ThemeIcon, { children: icons.empty }),
2339
+ /* @__PURE__ */ jsx(
2340
+ RenderPlaceholder,
1692
2341
  {
1693
- testId: `skeleton-row-${rowIndex}`,
1694
- "aria-hidden": "true",
1695
- "data-placeholder": true,
1696
- children: table.getVisibleLeafColumns().map((column) => /* @__PURE__ */ jsx(
1697
- Table.Cell,
2342
+ node: empty,
2343
+ defaultActions: /* @__PURE__ */ jsx(
2344
+ Button,
1698
2345
  {
1699
- testId: `skeleton-row-${rowIndex}-cell-${column.id}`,
1700
- children: column.columnDef.meta?.skeleton ?? /* @__PURE__ */ jsx(Skeleton, { shape: "rectangular", size, className: "w-full" })
1701
- },
1702
- column.id
1703
- ))
2346
+ variant: "light",
2347
+ color: "neutral",
2348
+ size: "sm",
2349
+ startSlot: icons.clear,
2350
+ onClick: () => table.resetColumnFilters(),
2351
+ children: resolvedTranslations.clearFilters
2352
+ }
2353
+ )
2354
+ }
2355
+ )
2356
+ ] })
2357
+ }
2358
+ ) })).with(
2359
+ "loading",
2360
+ () => Array.from({ length: skeletonRowCount }).map((_, rowIndex) => /* @__PURE__ */ jsx(
2361
+ Table.Row,
2362
+ {
2363
+ testId: `skeleton-row-${rowIndex}`,
2364
+ "aria-hidden": "true",
2365
+ "data-placeholder": true,
2366
+ children: table.getVisibleLeafColumns().map((column) => /* @__PURE__ */ jsx(
2367
+ Table.Cell,
2368
+ {
2369
+ testId: `skeleton-row-${rowIndex}-cell-${column.id}`,
2370
+ children: column.columnDef.meta?.skeleton ?? /* @__PURE__ */ jsx(Skeleton, { shape: "rectangular", size, className: "w-full" })
1704
2371
  },
1705
- `skeleton-${rowIndex}`
2372
+ column.id
1706
2373
  ))
1707
- ).with(
1708
- "items",
1709
- () => rows.map((row) => {
1710
- const rowTestId = getRowTestId ? getRowTestId(row.original, row.id) : defaultRowTestId(row.id);
1711
- return /* @__PURE__ */ jsx(
1712
- Table.Row,
1713
- {
1714
- testId: rowTestId,
1715
- onClick: onRowClick ? handleRowClick(row.original) : void 0,
1716
- className: cn(onRowClick && "cursor-pointer", classNames?.row),
1717
- ...props({ "data-selected": row.getIsSelected() }),
1718
- children: row.getVisibleCells().map((cell, index, cells) => {
1719
- const fillsRemaining = isFillLast && index === cells.length - 1;
1720
- return /* @__PURE__ */ jsx(
1721
- Table.Cell,
1722
- {
1723
- testId: `${rowTestId}-cell-${cell.column.id}`,
1724
- style: {
1725
- width: isFixedSizing && !fillsRemaining ? cell.column.getSize() : void 0
1726
- },
1727
- className: cn(
1728
- tableCell({
1729
- align: cell.column.columnDef.meta?.align
1730
- }),
1731
- isFixedSizing && cell.column.id !== "__select__" && "truncate",
1732
- classNames?.cell
1733
- ),
1734
- children: flexRender(cell.column.columnDef.cell, cell.getContext())
1735
- },
1736
- cell.id
1737
- );
1738
- })
1739
- },
1740
- row.id
1741
- );
1742
- })
1743
- ).exhaustive()
1744
- }
1745
- )
2374
+ },
2375
+ `skeleton-${rowIndex}`
2376
+ ))
2377
+ ).with("items", () => rows.map((row) => renderRow(row))).exhaustive() })
1746
2378
  ]
1747
2379
  }
1748
2380
  ),
@@ -1752,6 +2384,13 @@ function DataTableComponent({
1752
2384
  {
1753
2385
  table,
1754
2386
  enableColumnVisibility,
2387
+ grouping: showGroupMenu ? {
2388
+ value: activeGrouping,
2389
+ onChange: handleGroupingChange,
2390
+ maxDepth: maxGroupingDepth,
2391
+ hideEmptyGroups,
2392
+ onHideEmptyGroupsChange: handleHideEmptyGroupsChange
2393
+ } : void 0,
1755
2394
  translations: resolvedTranslations,
1756
2395
  icons,
1757
2396
  className: "@lg:hidden"
@@ -1761,6 +2400,7 @@ function DataTableComponent({
1761
2400
  DataTableStackedRows,
1762
2401
  {
1763
2402
  rows,
2403
+ grouping: groupingView,
1764
2404
  view,
1765
2405
  error,
1766
2406
  refetching: isRefetching,
@@ -1776,10 +2416,18 @@ function DataTableComponent({
1776
2416
  }
1777
2417
  )
1778
2418
  ] }),
1779
- enablePagination && /* @__PURE__ */ jsx(
2419
+ enablePagination && (groupingView && !groupsOnePage ? /* @__PURE__ */ jsx(
2420
+ DataTableGroupSummary,
2421
+ {
2422
+ grouping: groupingView,
2423
+ translations: resolvedTranslations,
2424
+ className: classNames?.pagination
2425
+ }
2426
+ ) : /* @__PURE__ */ jsx(
1780
2427
  DataTablePagination,
1781
2428
  {
1782
2429
  table,
2430
+ rowsOnPage: groupingView ? loadedCount : void 0,
1783
2431
  pageSizeOptions,
1784
2432
  hasNextPage,
1785
2433
  translations,
@@ -1787,7 +2435,7 @@ function DataTableComponent({
1787
2435
  icons,
1788
2436
  className: classNames?.pagination
1789
2437
  }
1790
- )
2438
+ ))
1791
2439
  ]
1792
2440
  }
1793
2441
  );