@react-fabric/data 1.0.0-beta.4 → 1.0.0-beta.40

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 (81) hide show
  1. package/{src/histogram/Histogram.module.css → css/_histogram.css} +16 -13
  2. package/css/styles.css +24 -0
  3. package/dist/cjs/checklist/CheckList.js +25 -16
  4. package/dist/cjs/histogram/Histogram.js +20 -10
  5. package/dist/cjs/hooks/usePagination.js +7 -4
  6. package/dist/cjs/json/JsonViewer.js +40 -27
  7. package/dist/cjs/table/BodyCell.js +38 -5
  8. package/dist/cjs/table/BodyRow.js +107 -0
  9. package/dist/cjs/table/CheckboxCell.js +1 -1
  10. package/dist/cjs/table/HeaderCell.js +29 -36
  11. package/dist/cjs/table/Table.js +105 -67
  12. package/dist/cjs/table/useResizer.js +4 -4
  13. package/dist/cjs/table/useVirtualTable.js +118 -17
  14. package/dist/cjs/tree/TreeNode.js +44 -24
  15. package/dist/cjs/tree/TreePanel.js +28 -10
  16. package/dist/cjs/tree/useTree.js +96 -14
  17. package/dist/cjs/tree/utils.js +20 -5
  18. package/dist/cjs/virtual/Gallery.js +43 -29
  19. package/dist/cjs/virtual/List.js +43 -31
  20. package/dist/esm/checklist/CheckList.js +27 -18
  21. package/dist/esm/histogram/Histogram.js +21 -11
  22. package/dist/esm/hooks/usePagination.js +7 -4
  23. package/dist/esm/json/JsonViewer.js +41 -28
  24. package/dist/esm/table/BodyCell.js +38 -5
  25. package/dist/esm/table/BodyRow.js +107 -0
  26. package/dist/esm/table/CheckboxCell.js +1 -1
  27. package/dist/esm/table/HeaderCell.js +30 -37
  28. package/dist/esm/table/Table.js +107 -69
  29. package/dist/esm/table/useResizer.js +4 -4
  30. package/dist/esm/table/useVirtualTable.js +120 -19
  31. package/dist/esm/tree/TreeNode.js +46 -26
  32. package/dist/esm/tree/TreePanel.js +28 -10
  33. package/dist/esm/tree/useTree.js +98 -16
  34. package/dist/esm/tree/utils.js +20 -5
  35. package/dist/esm/virtual/Gallery.js +43 -29
  36. package/dist/esm/virtual/List.js +43 -31
  37. package/dist/types/checklist/CheckList.d.ts +2 -2
  38. package/dist/types/histogram/Histogram.d.ts +3 -3
  39. package/dist/types/index.d.ts +1 -1
  40. package/dist/types/table/AddColumn.d.ts +2 -2
  41. package/dist/types/table/BodyCell.d.ts +4 -3
  42. package/dist/types/table/BodyRow.d.ts +20 -0
  43. package/dist/types/table/EmptyCell.d.ts +2 -2
  44. package/dist/types/table/HeaderCell.d.ts +2 -2
  45. package/dist/types/table/Table.d.ts +1 -1
  46. package/dist/types/table/types.d.ts +17 -6
  47. package/dist/types/table/useTableColumns.d.ts +6 -6
  48. package/dist/types/table/useVirtualTable.d.ts +20 -5
  49. package/dist/types/tree/TreeNode.d.ts +1 -1
  50. package/dist/types/tree/TreePanel.d.ts +1 -1
  51. package/dist/types/tree/types.d.ts +25 -5
  52. package/dist/types/tree/useTree.d.ts +2 -9
  53. package/dist/types/tree/utils.d.ts +4 -1
  54. package/dist/types/virtual/Gallery.d.ts +12 -4
  55. package/dist/types/virtual/List.d.ts +7 -3
  56. package/package.json +10 -7
  57. package/src/checklist/CheckList.tsx +81 -77
  58. package/src/histogram/Histogram.tsx +17 -11
  59. package/src/hooks/usePagination.tsx +13 -7
  60. package/src/index.ts +1 -1
  61. package/src/json/JsonViewer.tsx +45 -35
  62. package/src/table/AddColumn.tsx +2 -2
  63. package/src/table/BodyCell.tsx +34 -5
  64. package/src/table/BodyRow.tsx +143 -0
  65. package/src/table/CheckboxCell.tsx +1 -1
  66. package/src/table/EmptyCell.tsx +2 -2
  67. package/src/table/HeaderCell.tsx +27 -13
  68. package/src/table/Table.tsx +141 -73
  69. package/src/table/types.ts +20 -5
  70. package/src/table/useResizer.ts +5 -3
  71. package/src/table/useTableColumns.ts +7 -7
  72. package/src/table/useVirtualTable.ts +143 -28
  73. package/src/tree/TreeNode.tsx +90 -56
  74. package/src/tree/TreePanel.tsx +23 -3
  75. package/src/tree/types.ts +32 -4
  76. package/src/tree/useTree.ts +102 -23
  77. package/src/tree/utils.ts +23 -8
  78. package/src/virtual/Gallery.tsx +46 -35
  79. package/src/virtual/List.tsx +40 -27
  80. package/dist/cjs/histogram/Histogram.module.css +0 -1
  81. package/dist/esm/histogram/Histogram.module.css +0 -1
@@ -21,6 +21,8 @@
21
21
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  */
23
23
 
24
+ import { DateDisplay } from "@react-fabric/date";
25
+ import { Format, getByPath, isTrue } from "@react-fabric/utilities";
24
26
  import classNames from "classnames";
25
27
  import { useMemo } from "react";
26
28
  import { useTableContext } from "./Context";
@@ -28,15 +30,17 @@ import {
28
30
  COL_DEFAULT_WIDTH,
29
31
  COL_MAX_WIDTH,
30
32
  COL_MIN_WIDTH,
31
- type ColumnType,
33
+ type TableColumn,
32
34
  } from "./types";
33
35
 
34
36
  export const BodyCell = ({
35
37
  column,
36
38
  item,
39
+ index,
37
40
  }: {
38
- column: ColumnType;
41
+ column: TableColumn;
39
42
  item: KeyValue;
43
+ index: number;
40
44
  }) => {
41
45
  const { widths } = useTableContext();
42
46
 
@@ -45,9 +49,32 @@ export const BodyCell = ({
45
49
  [widths, column],
46
50
  );
47
51
 
52
+ const content = useMemo(() => {
53
+ const value = getByPath(item, column.id.toString());
54
+ if (column.renderer != null) {
55
+ return column.renderer(item[column.id], item, index);
56
+ }
57
+ if (column.dataType === "boolean") {
58
+ const map = column.valueMap ?? { true: "Yes", false: "no" };
59
+ return map[`${isTrue(value) ? "true" : "false"}`];
60
+ }
61
+ if (column.valueMap != null) {
62
+ if (column.dataType === "string" && value in column.valueMap) {
63
+ return column.valueMap[value];
64
+ }
65
+ }
66
+ if (["date", "time", "datetime"].includes(column.dataType ?? "")) {
67
+ return <DateDisplay date={value} format={column.format} />;
68
+ }
69
+ if (column.dataType === "number") {
70
+ return Format.number(value, column.format);
71
+ }
72
+ return value ?? "";
73
+ }, [item, column]);
74
+
48
75
  return (
49
76
  <div
50
- className="overflow-hidden bg-inherit start-0"
77
+ className="overflow-hidden bg-inherit start-0 border-e"
51
78
  style={{
52
79
  width: width ?? COL_DEFAULT_WIDTH,
53
80
  minWidth: column.minWidth ?? COL_MIN_WIDTH,
@@ -56,12 +83,14 @@ export const BodyCell = ({
56
83
  >
57
84
  <div
58
85
  className={classNames(
59
- "px-2 py-1 border-e truncate",
86
+ "px-2 py-1",
87
+ column.className,
88
+ column.truncate && "truncate",
60
89
  column.align === "center" && "text-center",
61
90
  column.align === "end" && "text-end",
62
91
  )}
63
92
  >
64
- {column.renderer?.(item[column.id], item) ?? item[column.id]}
93
+ {content}
65
94
  </div>
66
95
  </div>
67
96
  );
@@ -0,0 +1,143 @@
1
+ /*
2
+ * React Fabric
3
+ * @version: 1.0.0
4
+ *
5
+ *
6
+ * The MIT License (MIT)
7
+ * Copyright (c) 2024 Adarsh Pastakia
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
11
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
13
+ * subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
16
+ * portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ import classNames from "classnames";
25
+ import { BodyCell } from "./BodyCell";
26
+ import { CheckboxCell } from "./CheckboxCell";
27
+ import { type TableColumn } from "./types";
28
+ import { CoreIcons, Icon } from "@react-fabric/core";
29
+
30
+ export const BodyRow = ({
31
+ rowKey,
32
+ index,
33
+ data,
34
+ keyProperty,
35
+ measureElement,
36
+ state,
37
+ hideableColumns,
38
+ wrapperStart,
39
+ wrapperEnd,
40
+ onRowClick,
41
+ checkableRows,
42
+ checked,
43
+ toggleChecked,
44
+ canExpand,
45
+ expanded,
46
+ toggleExpand,
47
+ expandRow,
48
+ }: {
49
+ rowKey: Key;
50
+ index: number;
51
+ data: KeyValue;
52
+ keyProperty?: Key;
53
+ measureElement: AnyObject;
54
+ state: KeyValue<TableColumn[]>;
55
+ hideableColumns?: boolean;
56
+ wrapperStart: string;
57
+ wrapperEnd: string;
58
+ checkableRows?: boolean;
59
+ checked: 0 | 1;
60
+ onRowClick?: AnyObject;
61
+ canExpand?: AnyObject;
62
+ expandRow?: AnyObject;
63
+ expanded: boolean;
64
+ toggleExpand: (key: Key) => void;
65
+ toggleChecked: (key: Key) => void;
66
+ }) => {
67
+ return (
68
+ <div
69
+ ref={measureElement}
70
+ data-index={index}
71
+ className={index % 2 ? "bg-even" : "bg-odd"}
72
+ >
73
+ <div
74
+ role="none"
75
+ data-row={index}
76
+ className={classNames(
77
+ "flex flex-nowrap datatable-row data-[hilight]:outline-1 -outline-offset-1 outline-primary-500",
78
+ onRowClick && "hover:bg-primary-50 active:bg-primary-100",
79
+ index % 2 ? "bg-even" : "bg-odd",
80
+ )}
81
+ onClick={() =>
82
+ checkableRows && keyProperty && !onRowClick
83
+ ? toggleChecked(data[keyProperty])
84
+ : onRowClick?.(data)
85
+ }
86
+ >
87
+ <div className={wrapperStart}>
88
+ {!!canExpand && (
89
+ <div
90
+ className={classNames(
91
+ "group font-medium w-6 flex flex-nowrap text-start py-1",
92
+ !canExpand(data) && "pointer-events-none opacity-35",
93
+ )}
94
+ >
95
+ <Icon
96
+ className="p-1 text-tint-700 hover:text-primary-600"
97
+ icon={expanded ? CoreIcons.collapse : CoreIcons.expand}
98
+ onClick={(e) => [
99
+ keyProperty && toggleExpand(data[keyProperty]),
100
+ e.stopPropagation(),
101
+ ]}
102
+ />
103
+ </div>
104
+ )}
105
+ {checkableRows && keyProperty && (
106
+ <CheckboxCell
107
+ onClick={() => toggleChecked(data[keyProperty])}
108
+ state={checked}
109
+ />
110
+ )}
111
+ {state.start?.map((col, ids) => (
112
+ <BodyCell
113
+ key={`${String(rowKey)}:${ids}`}
114
+ column={col}
115
+ item={data}
116
+ index={ids}
117
+ />
118
+ ))}
119
+ </div>
120
+ {state.cols?.map((col, idc) => (
121
+ <BodyCell
122
+ key={`${String(rowKey)}:${idc}`}
123
+ column={col}
124
+ item={data}
125
+ index={idc}
126
+ />
127
+ ))}
128
+ <div className={wrapperEnd}>
129
+ {state.end?.map((col, ide) => (
130
+ <BodyCell
131
+ key={`${String(rowKey)}:${ide}`}
132
+ column={col}
133
+ item={data}
134
+ index={ide}
135
+ />
136
+ ))}
137
+ {hideableColumns && <div className="w-6" />}
138
+ </div>
139
+ </div>
140
+ {expanded && expandRow(data)}
141
+ </div>
142
+ );
143
+ };
@@ -31,7 +31,7 @@ export const CheckboxCell = ({
31
31
  onClick?: () => void;
32
32
  }) => {
33
33
  return (
34
- <div className="group font-medium border-e w-6 flex flex-nowrap text-start items-center">
34
+ <div className="group font-medium border-e w-6 flex flex-nowrap text-start py-1">
35
35
  <Icon
36
36
  icon={
37
37
  state === 2
@@ -27,7 +27,7 @@ import {
27
27
  COL_DEFAULT_WIDTH,
28
28
  COL_MAX_WIDTH,
29
29
  COL_MIN_WIDTH,
30
- type ColumnType,
30
+ type TableColumn,
31
31
  } from "./types";
32
32
 
33
33
  export const EmptyCell = ({
@@ -35,7 +35,7 @@ export const EmptyCell = ({
35
35
  width: _width,
36
36
  maxWidth,
37
37
  minWidth,
38
- }: ColumnType) => {
38
+ }: TableColumn) => {
39
39
  const { widths } = useTableContext();
40
40
 
41
41
  const width = useMemo(
@@ -23,6 +23,7 @@
23
23
 
24
24
  import {
25
25
  CoreIcons,
26
+ Divider,
26
27
  DropdownTool,
27
28
  Icon,
28
29
  Menu,
@@ -35,7 +36,7 @@ import {
35
36
  COL_DEFAULT_WIDTH,
36
37
  COL_MAX_WIDTH,
37
38
  COL_MIN_WIDTH,
38
- type ColumnType,
39
+ type TableColumn,
39
40
  type TableProps,
40
41
  } from "./types";
41
42
 
@@ -48,6 +49,7 @@ export const HeaderCell = ({
48
49
  rtlFlip,
49
50
  actions,
50
51
  locked,
52
+ tooltip,
51
53
  sortable,
52
54
  resizable,
53
55
  width: _width,
@@ -55,7 +57,7 @@ export const HeaderCell = ({
55
57
  minWidth,
56
58
  sort,
57
59
  onSort,
58
- }: ColumnType & Pick<TableProps, "sort" | "onSort">) => {
60
+ }: TableColumn & Pick<TableProps, "sort" | "onSort">) => {
59
61
  const { startResize, widths } = useTableContext();
60
62
 
61
63
  const width = useMemo(
@@ -63,13 +65,17 @@ export const HeaderCell = ({
63
65
  [widths, _width, id],
64
66
  );
65
67
 
66
- const handleSort = useCallback(() => {
67
- sortable &&
68
- onSort?.({
69
- id: id.toString(),
70
- order: sort?.id === id && sort.order === "asc" ? "desc" : "asc",
71
- });
72
- }, [onSort, name, sort, sortable]);
68
+ const handleSort = useCallback(
69
+ (order?: "asc" | "desc") => {
70
+ sortable &&
71
+ onSort?.({
72
+ id: id.toString(),
73
+ order:
74
+ order ?? (sort?.id === id && sort.order === "asc" ? "desc" : "asc"),
75
+ });
76
+ },
77
+ [onSort, sort, sortable],
78
+ );
73
79
 
74
80
  const menus = useMemo(() => {
75
81
  const ret = [];
@@ -79,30 +85,38 @@ export const HeaderCell = ({
79
85
  key="sort-asc"
80
86
  label="Sort ascending"
81
87
  icon={CoreIcons.sortAsc}
88
+ onClick={() => handleSort("asc")}
82
89
  />,
83
90
  <MenuItem
84
91
  key="sort-desc"
85
92
  label="Sort descending"
86
93
  icon={CoreIcons.sortDesc}
94
+ onClick={() => handleSort("desc")}
87
95
  />,
88
96
  );
89
97
  }
98
+ if (sortable && actions) {
99
+ ret.push(<Divider />);
100
+ }
101
+ if (actions) {
102
+ ret.push(...actions);
103
+ }
90
104
  return ret;
91
- }, [sortable]);
105
+ }, [sortable, actions]);
92
106
 
93
107
  return (
94
108
  <div
95
109
  role="none"
96
110
  data-id={id}
97
- onClick={handleSort}
98
- className="group font-medium border-e flex flex-nowrap text-start items-center table-header-cell"
111
+ onClick={() => handleSort()}
112
+ className="group/tool font-medium border-e flex flex-nowrap text-start items-center table-header-cell"
99
113
  style={{
100
114
  width: width ?? COL_DEFAULT_WIDTH,
101
115
  minWidth: minWidth ?? COL_MIN_WIDTH,
102
116
  maxWidth: maxWidth ?? COL_MAX_WIDTH,
103
117
  }}
104
118
  >
105
- <Tooltip content={label} disabled={!label}>
119
+ <Tooltip content={tooltip ?? label} disabled={!(tooltip ?? label)}>
106
120
  <div className="flex-initial px-2 py-1 text-sm truncate sticky start-0">
107
121
  {icon && (
108
122
  <Icon icon={icon} bg={iconBg} color={iconColor} rtlFlip={rtlFlip} />
@@ -21,12 +21,25 @@
21
21
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  */
23
23
 
24
- import { EmptyContent, Loading, useDebounce } from "@react-fabric/core";
24
+ import {
25
+ CoreIcons,
26
+ EmptyContent,
27
+ Icon,
28
+ Loading,
29
+ useDebounce,
30
+ } from "@react-fabric/core";
31
+ import { debounce } from "@react-fabric/utilities";
25
32
  import classNames from "classnames";
26
- import { useImperativeHandle, useMemo, useRef } from "react";
33
+ import {
34
+ useEffect,
35
+ useImperativeHandle,
36
+ useLayoutEffect,
37
+ useMemo,
38
+ useRef,
39
+ } from "react";
27
40
  import { useTranslation } from "react-i18next";
28
41
  import { AddColumn } from "./AddColumn";
29
- import { BodyCell } from "./BodyCell";
42
+ import { BodyRow } from "./BodyRow";
30
43
  import { CheckboxCell } from "./CheckboxCell";
31
44
  import { TableProvider } from "./Context";
32
45
  import { EmptyCell } from "./EmptyCell";
@@ -39,12 +52,20 @@ export const Table = <T extends KeyValue = KeyValue>({
39
52
  ref,
40
53
  data,
41
54
  columns,
42
- keyProperty,
55
+ keyProperty = "id",
56
+ groupProperty,
43
57
  checkableRows,
58
+ initialScroll,
44
59
  hideableColumns,
45
60
  sort,
46
61
  loading,
62
+ checked,
63
+ emptyDisplay,
64
+ groupRenderer,
65
+ canExpand,
66
+ children,
47
67
  onSort,
68
+ onScroll,
48
69
  onRowClick,
49
70
  onCheckedChanged,
50
71
  }: TableProps<T>) => {
@@ -58,13 +79,24 @@ export const Table = <T extends KeyValue = KeyValue>({
58
79
  const {
59
80
  scrollerRef,
60
81
  items,
82
+ top,
61
83
  checkState,
84
+ virtualizer,
85
+ hasActiveSticky,
86
+ toggleExpand,
62
87
  toggleChecked,
63
88
  toggleAllChecked,
89
+ toggleGroupExpand,
64
90
  getData,
65
91
  totalSize,
92
+ isActiveSticky,
66
93
  measureElement,
67
- } = useVirtualTable(data, keyProperty, fireCheckChanged);
94
+ } = useVirtualTable(data, {
95
+ checked,
96
+ keyProperty,
97
+ groupProperty,
98
+ onCheckChanged: fireCheckChanged,
99
+ });
68
100
  const refBody = useRef<HTMLDivElement>(null);
69
101
 
70
102
  const wrapperStart = useMemo(
@@ -76,32 +108,51 @@ export const Table = <T extends KeyValue = KeyValue>({
76
108
  [],
77
109
  );
78
110
 
111
+ useLayoutEffect(() => {
112
+ setTimeout(() => {
113
+ initialScroll &&
114
+ virtualizer.scrollToIndex(initialScroll, { align: "start" });
115
+ }, 100);
116
+ }, []);
117
+
79
118
  useImperativeHandle(
80
119
  ref,
81
120
  () => ({
82
- hilight: (row: number) => {
83
- refBody.current
84
- ?.querySelectorAll<HTMLElement>(`.datatable-row[data-hilight="true"]`)
85
- .forEach((el) => el && (el.dataset.hilight = undefined));
86
- const el = refBody.current?.querySelector<HTMLElement>(
87
- `[data-row="${row}"]`,
88
- );
89
- el?.scrollIntoView({ behavior: "smooth", block: "center" });
90
- el && (el.dataset.hilight = "true");
121
+ scrollTo: (row: number) => {
122
+ virtualizer.scrollToIndex(row, { align: "start" });
91
123
  },
92
- unhilight: () => {
93
- refBody.current
94
- ?.querySelectorAll<HTMLElement>(`.datatable-row[data-hilight="true"]`)
95
- .forEach((el) => el && (el.dataset.hilight = undefined));
124
+ hilight(row) {
125
+ scrollerRef.current
126
+ ?.querySelector(".hilight")
127
+ ?.classList.remove("hilight", "ring-1");
128
+ virtualizer.scrollToIndex(Math.floor(row), {
129
+ align: "start",
130
+ });
131
+ setTimeout(() => {
132
+ scrollerRef.current
133
+ ?.querySelector(`[data-index="${row}"]`)
134
+ ?.classList.add("hilight", "ring-1");
135
+ }, 100);
96
136
  },
97
- scrollTo: (row: number) => {
98
- const el = refBody.current?.querySelector(`[data-row="${row}"]`);
99
- el?.scrollIntoView({ behavior: "smooth" });
137
+ unhilight() {
138
+ scrollerRef.current
139
+ ?.querySelector(".hilight")
140
+ ?.classList.remove("hilight", "ring-1");
100
141
  },
101
142
  }),
102
143
  [],
103
144
  );
104
145
 
146
+ useEffect(() => {
147
+ const handle = debounce((top: number) => {
148
+ onScroll?.(top ?? 0);
149
+ });
150
+ handle(top);
151
+ return () => {
152
+ handle.cancel();
153
+ };
154
+ }, [top]);
155
+
105
156
  return (
106
157
  <TableProvider>
107
158
  <div
@@ -109,10 +160,15 @@ export const Table = <T extends KeyValue = KeyValue>({
109
160
  style={{
110
161
  gridTemplate: `"head" auto "loader" auto "content" 1fr "foot" auto/1fr`,
111
162
  }}
163
+ data-ref="tableScroller"
112
164
  ref={scrollerRef}
113
165
  >
114
- <div className="bg-base font-medium sticky top-0 area-head border-b select-none flex flex-nowrap z-2">
166
+ <div
167
+ data-ref="tableHeader"
168
+ className="bg-base font-medium sticky top-0 h-8 area-head border-b select-none flex flex-nowrap z-5"
169
+ >
115
170
  <div className={wrapperStart}>
171
+ {canExpand && <div className="w-6" />}
116
172
  {checkableRows && (
117
173
  <CheckboxCell
118
174
  state={checkState.allChecked}
@@ -146,62 +202,72 @@ export const Table = <T extends KeyValue = KeyValue>({
146
202
  style={{ height: totalSize() }}
147
203
  ref={refBody}
148
204
  >
149
- <div style={{ height: items[0]?.start }} />
205
+ <div
206
+ style={{
207
+ height: items[hasActiveSticky ? 1 : 0]?.start,
208
+ }}
209
+ />
150
210
  {items.map(({ index, key }) => {
151
211
  const data = getData(index);
152
- return (
212
+ return "__GROUP__" in data ? (
153
213
  <div
154
214
  key={key}
155
- role="none"
156
- data-row={index}
215
+ ref={measureElement}
216
+ data-index={index}
157
217
  className={classNames(
158
- "flex flex-nowrap datatable-row data-[hilight]:outline-1 -outline-offset-1 outline-primary-500",
159
- index % 2 ? "bg-even" : "bg-odd",
160
- onRowClick && "hover:bg-primary-50 active:bg-primary-100",
218
+ "px-2 py-1 text-md bg-base border-y border-tint-100 cursor-pointer flex items-center gap-1 z-3",
219
+ isActiveSticky(index) && "sticky top-8",
161
220
  )}
162
- onClick={() =>
163
- checkableRows && keyProperty && !onRowClick
164
- ? toggleChecked(data[keyProperty])
165
- : onRowClick?.(data)
166
- }
167
- data-index={index}
168
- ref={measureElement}
221
+ role="none"
222
+ onClick={() => toggleGroupExpand(data.key)}
169
223
  >
170
- <div className={wrapperStart}>
171
- {checkableRows && keyProperty && (
172
- <CheckboxCell
173
- onClick={() => toggleChecked(data[keyProperty])}
174
- state={
175
- checkState.checked.includes(data[keyProperty]) ? 1 : 0
176
- }
177
- />
178
- )}
179
- {state.start?.map((col, ids) => (
180
- <BodyCell
181
- key={`${key}:${ids}`}
182
- column={col}
183
- item={data}
184
- />
185
- ))}
186
- </div>
187
- {state.cols?.map((col, idc) => (
188
- <BodyCell key={`${key}:${idc}`} column={col} item={data} />
189
- ))}
190
- <div className={wrapperEnd}>
191
- {state.end?.map((col, ide) => (
192
- <BodyCell
193
- key={`${key}:${ide}`}
194
- column={col}
195
- item={data}
196
- />
197
- ))}
198
- {hideableColumns && <div className="w-6" />}
199
- </div>
224
+ <Icon
225
+ rtlFlip
226
+ icon={
227
+ data.open ? CoreIcons.chevronDown : CoreIcons.chevronRight
228
+ }
229
+ />
230
+ {groupRenderer?.(data) ?? (
231
+ <div className="flex gap-1 items-center">
232
+ <span>{data.key}</span>
233
+ <span className="text-sm">({data.itemCount})</span>
234
+ </div>
235
+ )}
200
236
  </div>
237
+ ) : (
238
+ <BodyRow
239
+ rowKey={key}
240
+ index={index}
241
+ checkableRows={checkableRows}
242
+ checked={
243
+ keyProperty &&
244
+ checkState.checked.includes(data[keyProperty])
245
+ ? 1
246
+ : 0
247
+ }
248
+ expanded={
249
+ !!keyProperty &&
250
+ checkState.expanded.includes(data[keyProperty])
251
+ }
252
+ data={data}
253
+ hideableColumns={hideableColumns}
254
+ keyProperty={keyProperty}
255
+ measureElement={measureElement}
256
+ onRowClick={onRowClick}
257
+ state={state}
258
+ canExpand={canExpand}
259
+ toggleExpand={toggleExpand}
260
+ expandRow={children}
261
+ toggleChecked={toggleChecked}
262
+ wrapperEnd={wrapperEnd}
263
+ wrapperStart={wrapperStart}
264
+ key={key}
265
+ />
201
266
  );
202
267
  })}
203
268
  <div className="flex-1 flex flex-nowrap">
204
269
  <div className={wrapperStart}>
270
+ {canExpand && <div className="w-6" />}
205
271
  {checkableRows && <div className="w-6" />}
206
272
  {state.start?.map((col) => (
207
273
  <EmptyCell key={String(col.id)} {...col} />
@@ -220,13 +286,15 @@ export const Table = <T extends KeyValue = KeyValue>({
220
286
  </div>
221
287
  </div>
222
288
  )}
223
- {!loading && data.length === 0 && (
224
- <EmptyContent
225
- size="sm"
226
- className="bg-dimmed"
227
- message={t("datagrid.empty")}
228
- />
229
- )}
289
+ {!loading &&
290
+ data.length === 0 &&
291
+ (emptyDisplay ?? (
292
+ <EmptyContent
293
+ size="sm"
294
+ className="bg-dimmed"
295
+ message={t("datagrid.empty")}
296
+ />
297
+ ))}
230
298
  </div>
231
299
  </TableProvider>
232
300
  );