@react-fabric/data 1.0.0-beta.3 → 1.0.0-beta.31
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.
- package/dist/cjs/checklist/CheckList.js +143 -0
- package/dist/cjs/histogram/Histogram.js +16 -5
- package/dist/cjs/hooks/usePagination.js +7 -4
- package/dist/cjs/hooks/useSelectableList.js +54 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/json/JsonViewer.js +30 -23
- package/dist/cjs/table/BodyCell.js +38 -5
- package/dist/cjs/table/BodyRow.js +107 -0
- package/dist/cjs/table/CheckboxCell.js +1 -1
- package/dist/cjs/table/HeaderCell.js +29 -36
- package/dist/cjs/table/Table.js +104 -66
- package/dist/cjs/table/useResizer.js +4 -4
- package/dist/cjs/table/useVirtualTable.js +118 -17
- package/dist/cjs/tree/TreeNode.js +44 -24
- package/dist/cjs/tree/TreePanel.js +28 -10
- package/dist/cjs/tree/useTree.js +96 -14
- package/dist/cjs/tree/utils.js +20 -5
- package/dist/cjs/virtual/Gallery.js +43 -29
- package/dist/cjs/virtual/List.js +43 -31
- package/dist/esm/checklist/CheckList.js +143 -0
- package/dist/esm/histogram/Histogram.js +16 -5
- package/dist/esm/hooks/usePagination.js +7 -4
- package/dist/esm/hooks/useSelectableList.js +54 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/json/JsonViewer.js +31 -24
- package/dist/esm/table/BodyCell.js +38 -5
- package/dist/esm/table/BodyRow.js +107 -0
- package/dist/esm/table/CheckboxCell.js +1 -1
- package/dist/esm/table/HeaderCell.js +30 -37
- package/dist/esm/table/Table.js +106 -68
- package/dist/esm/table/useResizer.js +4 -4
- package/dist/esm/table/useVirtualTable.js +120 -19
- package/dist/esm/tree/TreeNode.js +46 -26
- package/dist/esm/tree/TreePanel.js +28 -10
- package/dist/esm/tree/useTree.js +98 -16
- package/dist/esm/tree/utils.js +20 -5
- package/dist/esm/virtual/Gallery.js +43 -29
- package/dist/esm/virtual/List.js +43 -31
- package/dist/types/checklist/CheckList.d.ts +30 -0
- package/dist/types/histogram/Histogram.d.ts +3 -3
- package/dist/types/hooks/useSelectableList.d.ts +28 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/table/AddColumn.d.ts +2 -2
- package/dist/types/table/BodyCell.d.ts +4 -3
- package/dist/types/table/BodyRow.d.ts +20 -0
- package/dist/types/table/EmptyCell.d.ts +2 -2
- package/dist/types/table/HeaderCell.d.ts +2 -2
- package/dist/types/table/Table.d.ts +1 -1
- package/dist/types/table/types.d.ts +19 -8
- package/dist/types/table/useTableColumns.d.ts +6 -6
- package/dist/types/table/useVirtualTable.d.ts +20 -5
- package/dist/types/tree/TreeNode.d.ts +1 -1
- package/dist/types/tree/TreePanel.d.ts +1 -1
- package/dist/types/tree/types.d.ts +25 -5
- package/dist/types/tree/useTree.d.ts +2 -9
- package/dist/types/tree/utils.d.ts +4 -1
- package/dist/types/virtual/Gallery.d.ts +11 -3
- package/dist/types/virtual/List.d.ts +7 -3
- package/package.json +8 -7
- package/src/checklist/CheckList.tsx +222 -0
- package/src/histogram/Histogram.tsx +9 -2
- package/src/hooks/usePagination.tsx +13 -7
- package/src/hooks/useSelectableList.ts +94 -0
- package/src/index.ts +2 -1
- package/src/json/JsonViewer.tsx +31 -31
- package/src/table/AddColumn.tsx +2 -2
- package/src/table/BodyCell.tsx +34 -5
- package/src/table/BodyRow.tsx +143 -0
- package/src/table/CheckboxCell.tsx +1 -1
- package/src/table/EmptyCell.tsx +2 -2
- package/src/table/HeaderCell.tsx +27 -13
- package/src/table/Table.tsx +141 -73
- package/src/table/types.ts +22 -7
- package/src/table/useResizer.ts +5 -3
- package/src/table/useTableColumns.ts +7 -7
- package/src/table/useVirtualTable.ts +142 -27
- package/src/tree/TreeNode.tsx +90 -56
- package/src/tree/TreePanel.tsx +23 -3
- package/src/tree/types.ts +32 -4
- package/src/tree/useTree.ts +102 -23
- package/src/tree/utils.ts +23 -8
- package/src/virtual/Gallery.tsx +45 -34
- package/src/virtual/List.tsx +40 -27
package/src/json/JsonViewer.tsx
CHANGED
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
import {
|
|
25
|
-
ActionLabel,
|
|
26
25
|
Button,
|
|
27
26
|
Copy,
|
|
28
27
|
CoreIcons,
|
|
@@ -181,6 +180,8 @@ const JsonEntry = ({
|
|
|
181
180
|
ret = actualValue ? t("json.true") : t("json.false");
|
|
182
181
|
if (ret?.length > 128) {
|
|
183
182
|
ret = <Text clamp={3}>{ret}</Text>;
|
|
183
|
+
} else {
|
|
184
|
+
ret = <div className="break-words">{ret}</div>;
|
|
184
185
|
}
|
|
185
186
|
|
|
186
187
|
return (
|
|
@@ -216,37 +217,36 @@ const JsonEntry = ({
|
|
|
216
217
|
|
|
217
218
|
const labelDisplay = useMemo(
|
|
218
219
|
() => (
|
|
219
|
-
<
|
|
220
|
-
className=
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
<Button
|
|
225
|
-
key="negative"
|
|
226
|
-
color="danger"
|
|
227
|
-
size="sm"
|
|
228
|
-
variant="link"
|
|
229
|
-
icon={CoreIcons.funnelMinus}
|
|
230
|
-
aria-label="Filter Negative"
|
|
231
|
-
onClick={() =>
|
|
232
|
-
onFilter?.(pathWithoutOrdinal, actualValue, true)
|
|
233
|
-
}
|
|
234
|
-
/>,
|
|
235
|
-
<Button
|
|
236
|
-
key="positive"
|
|
237
|
-
color="primary"
|
|
238
|
-
size="sm"
|
|
239
|
-
variant="link"
|
|
240
|
-
icon={CoreIcons.funnelPlus}
|
|
241
|
-
aria-label="Filter"
|
|
242
|
-
onClick={() => onFilter?.(pathWithoutOrdinal, actualValue)}
|
|
243
|
-
/>,
|
|
244
|
-
]
|
|
245
|
-
: []
|
|
246
|
-
}
|
|
220
|
+
<div
|
|
221
|
+
className={classNames(
|
|
222
|
+
"text-dimmed text-sm px-2 flex-1 group",
|
|
223
|
+
inline ? "truncate" : "break-words",
|
|
224
|
+
)}
|
|
247
225
|
>
|
|
226
|
+
{!canExpand && canFilter && (
|
|
227
|
+
<div className="hidden pe-1 group-hover:inline-block">
|
|
228
|
+
<Button
|
|
229
|
+
key="negative"
|
|
230
|
+
color="danger"
|
|
231
|
+
size="xs"
|
|
232
|
+
variant="link"
|
|
233
|
+
icon={CoreIcons.funnelMinus}
|
|
234
|
+
aria-label="Filter Negative"
|
|
235
|
+
onClick={() => onFilter?.(pathWithoutOrdinal, actualValue, true)}
|
|
236
|
+
/>
|
|
237
|
+
<Button
|
|
238
|
+
key="positive"
|
|
239
|
+
color="primary"
|
|
240
|
+
size="xs"
|
|
241
|
+
variant="link"
|
|
242
|
+
icon={CoreIcons.funnelPlus}
|
|
243
|
+
aria-label="Filter"
|
|
244
|
+
onClick={() => onFilter?.(pathWithoutOrdinal, actualValue)}
|
|
245
|
+
/>
|
|
246
|
+
</div>
|
|
247
|
+
)}
|
|
248
248
|
{labeler?.(path) ?? field}
|
|
249
|
-
</
|
|
249
|
+
</div>
|
|
250
250
|
),
|
|
251
251
|
[field, labeler, pathWithoutOrdinal, actualValue, canExpand, canFilter],
|
|
252
252
|
);
|
|
@@ -356,7 +356,7 @@ export const JsonViewer = <T extends KeyValue = KeyValue>({
|
|
|
356
356
|
const list = useMemo(() => reduceObject(json), [json]);
|
|
357
357
|
|
|
358
358
|
return (
|
|
359
|
-
<div {...rest} className={classNames(className, "
|
|
359
|
+
<div {...rest} className={classNames(className, "bg-alternate")}>
|
|
360
360
|
{!isEmpty(json) ? (
|
|
361
361
|
list.map((item) => (
|
|
362
362
|
<JsonEntry
|
package/src/table/AddColumn.tsx
CHANGED
|
@@ -22,13 +22,13 @@
|
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
import { CoreIcons, Dropdown, Icon, Menu, MenuItem } from "@react-fabric/core";
|
|
25
|
-
import { type
|
|
25
|
+
import { type TableColumn } from "./types";
|
|
26
26
|
|
|
27
27
|
export const AddColumn = ({
|
|
28
28
|
columns,
|
|
29
29
|
onClick,
|
|
30
30
|
}: {
|
|
31
|
-
columns:
|
|
31
|
+
columns: TableColumn[];
|
|
32
32
|
onClick: (id: string) => void;
|
|
33
33
|
}) => {
|
|
34
34
|
return (
|
package/src/table/BodyCell.tsx
CHANGED
|
@@ -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
|
|
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:
|
|
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
|
|
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
|
-
{
|
|
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
|
|
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
|
package/src/table/EmptyCell.tsx
CHANGED
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
COL_DEFAULT_WIDTH,
|
|
28
28
|
COL_MAX_WIDTH,
|
|
29
29
|
COL_MIN_WIDTH,
|
|
30
|
-
type
|
|
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
|
-
}:
|
|
38
|
+
}: TableColumn) => {
|
|
39
39
|
const { widths } = useTableContext();
|
|
40
40
|
|
|
41
41
|
const width = useMemo(
|
package/src/table/HeaderCell.tsx
CHANGED
|
@@ -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
|
|
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
|
-
}:
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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} />
|