@react-fabric/data 1.0.0-beta.5 → 1.0.0-beta.7
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 +25 -16
- package/dist/cjs/histogram/Histogram.js +12 -4
- package/dist/cjs/table/BodyCell.js +35 -3
- package/dist/cjs/table/BodyRow.js +107 -0
- package/dist/cjs/table/HeaderCell.js +4 -3
- package/dist/cjs/table/Table.js +71 -69
- package/dist/cjs/table/useVirtualTable.js +15 -1
- package/dist/cjs/virtual/Gallery.js +11 -4
- package/dist/cjs/virtual/List.js +11 -4
- package/dist/esm/checklist/CheckList.js +27 -18
- package/dist/esm/histogram/Histogram.js +12 -4
- package/dist/esm/table/BodyCell.js +35 -3
- package/dist/esm/table/BodyRow.js +107 -0
- package/dist/esm/table/HeaderCell.js +4 -3
- package/dist/esm/table/Table.js +72 -70
- package/dist/esm/table/useVirtualTable.js +15 -1
- package/dist/esm/virtual/Gallery.js +11 -4
- package/dist/esm/virtual/List.js +11 -4
- package/dist/types/checklist/CheckList.d.ts +2 -2
- package/dist/types/histogram/Histogram.d.ts +3 -3
- package/dist/types/index.d.ts +1 -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 +11 -4
- package/dist/types/table/useTableColumns.d.ts +6 -6
- package/dist/types/table/useVirtualTable.d.ts +4 -0
- package/dist/types/virtual/Gallery.d.ts +3 -2
- package/dist/types/virtual/List.d.ts +3 -2
- package/package.json +6 -5
- package/src/checklist/CheckList.tsx +81 -77
- package/src/histogram/Histogram.tsx +5 -1
- package/src/index.ts +1 -1
- package/src/table/AddColumn.tsx +2 -2
- package/src/table/BodyCell.tsx +30 -3
- package/src/table/BodyRow.tsx +142 -0
- package/src/table/EmptyCell.tsx +2 -2
- package/src/table/HeaderCell.tsx +4 -3
- package/src/table/Table.tsx +90 -73
- package/src/table/types.ts +13 -3
- package/src/table/useTableColumns.ts +7 -7
- package/src/table/useVirtualTable.ts +16 -2
- package/src/virtual/Gallery.tsx +4 -1
- package/src/virtual/List.tsx +4 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-fabric/data",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.7",
|
|
4
4
|
"description": "RUF: Data package",
|
|
5
5
|
"author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,9 +33,10 @@
|
|
|
33
33
|
"watch": "npm-run-all -p watch:rollup watch:dts"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@react-fabric/core": "^1.0.0-beta.
|
|
37
|
-
"@react-fabric/
|
|
38
|
-
"@react-fabric/
|
|
36
|
+
"@react-fabric/core": "^1.0.0-beta.7",
|
|
37
|
+
"@react-fabric/date": "^1.0.0-beta.7",
|
|
38
|
+
"@react-fabric/form": "^1.0.0-beta.7",
|
|
39
|
+
"@react-fabric/utilities": "^1.0.0-beta.7",
|
|
39
40
|
"@tanstack/react-virtual": "^3.8.6",
|
|
40
41
|
"classnames": "^2.5.1",
|
|
41
42
|
"color": "^4.2.3",
|
|
@@ -51,5 +52,5 @@
|
|
|
51
52
|
"node": ">=18.12.0",
|
|
52
53
|
"npm": ">=8.19.0"
|
|
53
54
|
},
|
|
54
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "8e6efedbbb02660c0b64140aff00e633b891bb85"
|
|
55
56
|
}
|
|
@@ -22,12 +22,14 @@
|
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
import { Badge, CoreIcons, EmptyContent, Icon } from "@react-fabric/core";
|
|
25
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
type BadgeType,
|
|
27
|
+
type TestProps,
|
|
28
|
+
} from "@react-fabric/core/dist/types/types";
|
|
26
29
|
import { isString } from "@react-fabric/utilities";
|
|
27
30
|
import {
|
|
28
31
|
Fragment,
|
|
29
32
|
isValidElement,
|
|
30
|
-
memo,
|
|
31
33
|
useEffect,
|
|
32
34
|
useMemo,
|
|
33
35
|
useState,
|
|
@@ -47,7 +49,7 @@ export interface CheckListItem extends KeyValue {
|
|
|
47
49
|
isDisabled?: boolean;
|
|
48
50
|
}
|
|
49
51
|
|
|
50
|
-
export interface CheckListProps extends SelectableProps {
|
|
52
|
+
export interface CheckListProps extends SelectableProps, TestProps {
|
|
51
53
|
/**
|
|
52
54
|
* list items
|
|
53
55
|
*/
|
|
@@ -73,84 +75,79 @@ const CheckItem: FC<
|
|
|
73
75
|
selected?: number;
|
|
74
76
|
allowNegative?: boolean;
|
|
75
77
|
}
|
|
76
|
-
> =
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
78
|
+
> = ({
|
|
79
|
+
id,
|
|
80
|
+
allowNegative,
|
|
81
|
+
selected,
|
|
82
|
+
icon,
|
|
83
|
+
label,
|
|
84
|
+
isDisabled,
|
|
85
|
+
onClick,
|
|
86
|
+
badge,
|
|
87
|
+
...aria
|
|
88
|
+
}: Omit<CheckListItem, "selected"> & {
|
|
89
|
+
selected?: number;
|
|
90
|
+
allowNegative?: boolean;
|
|
91
|
+
}) => {
|
|
92
|
+
return (
|
|
93
|
+
<div
|
|
94
|
+
role="none"
|
|
95
|
+
className="ax-checkList__item"
|
|
96
|
+
data-disabled={isDisabled}
|
|
97
|
+
onClick={() => onClick(id, false)}
|
|
98
|
+
onContextMenu={(e) => [
|
|
99
|
+
allowNegative && onClick(id, true),
|
|
100
|
+
e.preventDefault(),
|
|
101
|
+
]}
|
|
102
|
+
{...aria}
|
|
103
|
+
>
|
|
104
|
+
{!allowNegative && (
|
|
105
|
+
<Icon
|
|
106
|
+
data-type="checkbox"
|
|
107
|
+
className="ax-checkList__checkbox"
|
|
108
|
+
data-selected={selected === 1}
|
|
109
|
+
icon={selected ? CoreIcons.checkboxInt : CoreIcons.checkboxOff}
|
|
110
|
+
/>
|
|
111
|
+
)}
|
|
112
|
+
{allowNegative && (
|
|
113
|
+
<Fragment>
|
|
102
114
|
<Icon
|
|
103
|
-
data-type="
|
|
115
|
+
data-type="multiple"
|
|
104
116
|
className="ax-checkList__checkbox"
|
|
105
|
-
|
|
106
|
-
|
|
117
|
+
icon={
|
|
118
|
+
selected === 1
|
|
119
|
+
? CoreIcons.expand
|
|
120
|
+
: selected === -1
|
|
121
|
+
? CoreIcons.collapse
|
|
122
|
+
: CoreIcons.checkboxOff
|
|
123
|
+
}
|
|
124
|
+
data-selected={selected}
|
|
107
125
|
/>
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
126
|
+
<div className="ax-checkList__checkbox">
|
|
127
|
+
<Icon
|
|
128
|
+
data-type="positive"
|
|
129
|
+
onClick={(e) => [(onClick(id, false), e.stopPropagation())]}
|
|
130
|
+
icon={selected === 1 ? CoreIcons.expandActive : CoreIcons.expand}
|
|
131
|
+
data-selected={selected === 1}
|
|
132
|
+
/>
|
|
111
133
|
<Icon
|
|
112
|
-
data-type="
|
|
113
|
-
|
|
134
|
+
data-type="negative"
|
|
135
|
+
onClick={(e) => [(onClick(id, true), e.stopPropagation())]}
|
|
114
136
|
icon={
|
|
115
|
-
selected === 1
|
|
116
|
-
? CoreIcons.expand
|
|
117
|
-
: selected === -1
|
|
118
|
-
? CoreIcons.collapse
|
|
119
|
-
: CoreIcons.checkboxOff
|
|
137
|
+
selected === -1 ? CoreIcons.collapseActive : CoreIcons.collapse
|
|
120
138
|
}
|
|
121
|
-
data-selected={selected}
|
|
139
|
+
data-selected={selected === -1}
|
|
122
140
|
/>
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
data-type="negative"
|
|
134
|
-
onClick={(e) => [(onClick(id, true), e.stopPropagation())]}
|
|
135
|
-
icon={
|
|
136
|
-
selected === -1
|
|
137
|
-
? CoreIcons.collapseActive
|
|
138
|
-
: CoreIcons.collapse
|
|
139
|
-
}
|
|
140
|
-
data-selected={selected === -1}
|
|
141
|
-
/>
|
|
142
|
-
</div>
|
|
143
|
-
</Fragment>
|
|
144
|
-
)}
|
|
145
|
-
{isValidElement(icon) && icon}
|
|
146
|
-
{isString(icon) && <Icon icon={icon} />}
|
|
147
|
-
<label>{label}</label>
|
|
148
|
-
<Badge {...badge} />
|
|
149
|
-
</div>
|
|
150
|
-
);
|
|
151
|
-
},
|
|
152
|
-
);
|
|
153
|
-
CheckItem.displayName = "CheckItem";
|
|
141
|
+
</div>
|
|
142
|
+
</Fragment>
|
|
143
|
+
)}
|
|
144
|
+
{isValidElement(icon) && icon}
|
|
145
|
+
{isString(icon) && <Icon icon={icon} />}
|
|
146
|
+
<label>{label}</label>
|
|
147
|
+
<Badge {...badge} />
|
|
148
|
+
</div>
|
|
149
|
+
);
|
|
150
|
+
};
|
|
154
151
|
|
|
155
152
|
export const CheckList: FC<CheckListProps> = ({
|
|
156
153
|
items = [],
|
|
@@ -158,12 +155,19 @@ export const CheckList: FC<CheckListProps> = ({
|
|
|
158
155
|
allowNegative,
|
|
159
156
|
emptyMessage,
|
|
160
157
|
sortItems = true,
|
|
161
|
-
|
|
158
|
+
selected,
|
|
159
|
+
nonselected,
|
|
160
|
+
onChange,
|
|
161
|
+
onClick,
|
|
162
|
+
...aria
|
|
162
163
|
}: CheckListProps) => {
|
|
163
164
|
const { t } = useTranslation("data");
|
|
164
165
|
const { selection, toggleSelection } = useSelectableList({
|
|
165
166
|
items,
|
|
166
|
-
|
|
167
|
+
selected,
|
|
168
|
+
nonselected,
|
|
169
|
+
onChange,
|
|
170
|
+
onClick,
|
|
167
171
|
});
|
|
168
172
|
const [showMore, setShowMore] = useState(false);
|
|
169
173
|
|
|
@@ -186,7 +190,7 @@ export const CheckList: FC<CheckListProps> = ({
|
|
|
186
190
|
}, [items, selection, maxCount, showMore, sortItems]);
|
|
187
191
|
|
|
188
192
|
return (
|
|
189
|
-
<div
|
|
193
|
+
<div {...aria}>
|
|
190
194
|
{listItems.map((item, index) => (
|
|
191
195
|
<CheckItem
|
|
192
196
|
{...item}
|
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
import {
|
|
32
32
|
type ColorType,
|
|
33
33
|
type PaletteType,
|
|
34
|
+
type TestProps,
|
|
34
35
|
} from "@react-fabric/core/dist/types/types";
|
|
35
36
|
import { compareValues, Format } from "@react-fabric/utilities";
|
|
36
37
|
import classNames from "classnames";
|
|
@@ -49,7 +50,7 @@ interface HistogramItem {
|
|
|
49
50
|
disabled?: boolean;
|
|
50
51
|
}
|
|
51
52
|
|
|
52
|
-
export interface HistogramProps {
|
|
53
|
+
export interface HistogramProps extends TestProps {
|
|
53
54
|
/**
|
|
54
55
|
* histogram items list
|
|
55
56
|
*/
|
|
@@ -88,6 +89,7 @@ export const Histogram = ({
|
|
|
88
89
|
emptyTitle,
|
|
89
90
|
emptyMessage,
|
|
90
91
|
onClick,
|
|
92
|
+
...aria
|
|
91
93
|
}: HistogramProps) => {
|
|
92
94
|
const { t } = useTranslation("data");
|
|
93
95
|
const maxTotal = useMemo(() => {
|
|
@@ -104,6 +106,7 @@ export const Histogram = ({
|
|
|
104
106
|
return (
|
|
105
107
|
<div
|
|
106
108
|
className={classes.histogram}
|
|
109
|
+
{...aria}
|
|
107
110
|
style={
|
|
108
111
|
{
|
|
109
112
|
"--color": `var(--${color})`,
|
|
@@ -127,6 +130,7 @@ export const Histogram = ({
|
|
|
127
130
|
classes.histoLabel,
|
|
128
131
|
(item.count === 0 || item.disabled) && "pointer-events-none",
|
|
129
132
|
)}
|
|
133
|
+
data-testid={item.id}
|
|
130
134
|
onClick={(e) => [onClick?.(item.id), e.stopPropagation()]}
|
|
131
135
|
>
|
|
132
136
|
<div
|
package/src/index.ts
CHANGED
|
@@ -28,7 +28,7 @@ export { Histogram } from "./histogram/Histogram";
|
|
|
28
28
|
export { JsonViewer } from "./json/JsonViewer";
|
|
29
29
|
export { Pagination } from "./pagination/Pagination";
|
|
30
30
|
export { Table } from "./table/Table";
|
|
31
|
-
export { type TableRef } from "./table/types";
|
|
31
|
+
export { type TableColumn, type TableRef } from "./table/types";
|
|
32
32
|
export { TreePanel } from "./tree/TreePanel";
|
|
33
33
|
export { type TreeNodeType as TreeNode } from "./tree/types";
|
|
34
34
|
export { VirtualGallery, type VirtualGalleryRef } from "./virtual/Gallery";
|
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,6 +49,29 @@ 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 (column.dataType === "date") {
|
|
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
77
|
className="overflow-hidden bg-inherit start-0"
|
|
@@ -61,7 +88,7 @@ export const BodyCell = ({
|
|
|
61
88
|
column.align === "end" && "text-end",
|
|
62
89
|
)}
|
|
63
90
|
>
|
|
64
|
-
{
|
|
91
|
+
{content}
|
|
65
92
|
</div>
|
|
66
93
|
</div>
|
|
67
94
|
);
|
|
@@ -0,0 +1,142 @@
|
|
|
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
|
+
)}
|
|
80
|
+
onClick={() =>
|
|
81
|
+
checkableRows && keyProperty && !onRowClick
|
|
82
|
+
? toggleChecked(data[keyProperty])
|
|
83
|
+
: onRowClick?.(data)
|
|
84
|
+
}
|
|
85
|
+
>
|
|
86
|
+
<div className={wrapperStart}>
|
|
87
|
+
{!!canExpand && (
|
|
88
|
+
<div
|
|
89
|
+
className={classNames(
|
|
90
|
+
"group font-medium w-6 flex flex-nowrap text-start items-center",
|
|
91
|
+
!canExpand(data) && "pointer-events-none opacity-35",
|
|
92
|
+
)}
|
|
93
|
+
>
|
|
94
|
+
<Icon
|
|
95
|
+
className="p-1 text-tint-700 hover:text-primary-600"
|
|
96
|
+
icon={expanded ? CoreIcons.collapse : CoreIcons.expand}
|
|
97
|
+
onClick={(e) => [
|
|
98
|
+
keyProperty && toggleExpand(data[keyProperty]),
|
|
99
|
+
e.stopPropagation(),
|
|
100
|
+
]}
|
|
101
|
+
/>
|
|
102
|
+
</div>
|
|
103
|
+
)}
|
|
104
|
+
{checkableRows && keyProperty && (
|
|
105
|
+
<CheckboxCell
|
|
106
|
+
onClick={() => toggleChecked(data[keyProperty])}
|
|
107
|
+
state={checked}
|
|
108
|
+
/>
|
|
109
|
+
)}
|
|
110
|
+
{state.start?.map((col, ids) => (
|
|
111
|
+
<BodyCell
|
|
112
|
+
key={`${String(rowKey)}:${ids}`}
|
|
113
|
+
column={col}
|
|
114
|
+
item={data}
|
|
115
|
+
index={ids}
|
|
116
|
+
/>
|
|
117
|
+
))}
|
|
118
|
+
</div>
|
|
119
|
+
{state.cols?.map((col, idc) => (
|
|
120
|
+
<BodyCell
|
|
121
|
+
key={`${String(rowKey)}:${idc}`}
|
|
122
|
+
column={col}
|
|
123
|
+
item={data}
|
|
124
|
+
index={idc}
|
|
125
|
+
/>
|
|
126
|
+
))}
|
|
127
|
+
<div className={wrapperEnd}>
|
|
128
|
+
{state.end?.map((col, ide) => (
|
|
129
|
+
<BodyCell
|
|
130
|
+
key={`${String(rowKey)}:${ide}`}
|
|
131
|
+
column={col}
|
|
132
|
+
item={data}
|
|
133
|
+
index={ide}
|
|
134
|
+
/>
|
|
135
|
+
))}
|
|
136
|
+
{hideableColumns && <div className="w-6" />}
|
|
137
|
+
</div>
|
|
138
|
+
</div>
|
|
139
|
+
{expanded && expandRow(data)}
|
|
140
|
+
</div>
|
|
141
|
+
);
|
|
142
|
+
};
|
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
|
@@ -35,7 +35,7 @@ import {
|
|
|
35
35
|
COL_DEFAULT_WIDTH,
|
|
36
36
|
COL_MAX_WIDTH,
|
|
37
37
|
COL_MIN_WIDTH,
|
|
38
|
-
type
|
|
38
|
+
type TableColumn,
|
|
39
39
|
type TableProps,
|
|
40
40
|
} from "./types";
|
|
41
41
|
|
|
@@ -48,6 +48,7 @@ export const HeaderCell = ({
|
|
|
48
48
|
rtlFlip,
|
|
49
49
|
actions,
|
|
50
50
|
locked,
|
|
51
|
+
tooltip,
|
|
51
52
|
sortable,
|
|
52
53
|
resizable,
|
|
53
54
|
width: _width,
|
|
@@ -55,7 +56,7 @@ export const HeaderCell = ({
|
|
|
55
56
|
minWidth,
|
|
56
57
|
sort,
|
|
57
58
|
onSort,
|
|
58
|
-
}:
|
|
59
|
+
}: TableColumn & Pick<TableProps, "sort" | "onSort">) => {
|
|
59
60
|
const { startResize, widths } = useTableContext();
|
|
60
61
|
|
|
61
62
|
const width = useMemo(
|
|
@@ -102,7 +103,7 @@ export const HeaderCell = ({
|
|
|
102
103
|
maxWidth: maxWidth ?? COL_MAX_WIDTH,
|
|
103
104
|
}}
|
|
104
105
|
>
|
|
105
|
-
<Tooltip content={label} disabled={!label}>
|
|
106
|
+
<Tooltip content={tooltip ?? label} disabled={!(tooltip ?? label)}>
|
|
106
107
|
<div className="flex-initial px-2 py-1 text-sm truncate sticky start-0">
|
|
107
108
|
{icon && (
|
|
108
109
|
<Icon icon={icon} bg={iconBg} color={iconColor} rtlFlip={rtlFlip} />
|