@react-fabric/data 1.0.0-beta.5 → 1.0.0-beta.52
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/{src/histogram/Histogram.module.css → css/_histogram.css} +16 -13
- package/css/styles.css +24 -0
- package/dist/cjs/checklist/CheckList.js +48 -16
- package/dist/cjs/histogram/Histogram.js +48 -10
- package/dist/cjs/hooks/useFilteredList.js +20 -0
- package/dist/cjs/hooks/usePagination.js +27 -4
- package/dist/cjs/hooks/useSelectableList.js +29 -0
- package/dist/cjs/i18n/ar.json.js +8 -1
- package/dist/cjs/i18n/en.json.js +8 -1
- package/dist/cjs/json/JsonViewer.js +67 -27
- package/dist/cjs/pagination/Pagination.js +10 -0
- package/dist/cjs/table/AddColumn.js +1 -1
- 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/ColumnFilters.js +97 -0
- package/dist/cjs/table/HeaderCell.js +70 -37
- package/dist/cjs/table/Table.js +113 -71
- package/dist/cjs/table/types.js +29 -0
- package/dist/cjs/table/useResizer.js +4 -4
- package/dist/cjs/table/useVirtualTable.js +122 -18
- package/dist/cjs/tree/TreeNode.js +45 -25
- package/dist/cjs/tree/TreePanel.js +28 -10
- package/dist/cjs/tree/useTree.js +97 -15
- package/dist/cjs/tree/utils.js +20 -5
- package/dist/cjs/virtual/Gallery.js +84 -35
- package/dist/cjs/virtual/List.js +82 -32
- package/dist/esm/checklist/CheckList.js +50 -18
- package/dist/esm/histogram/Histogram.js +49 -11
- package/dist/esm/hooks/useFilteredList.js +20 -0
- package/dist/esm/hooks/usePagination.js +27 -4
- package/dist/esm/hooks/useSelectableList.js +29 -0
- package/dist/esm/i18n/ar.json.js +8 -2
- package/dist/esm/i18n/en.json.js +8 -2
- package/dist/esm/json/JsonViewer.js +68 -28
- package/dist/esm/pagination/Pagination.js +10 -0
- package/dist/esm/table/AddColumn.js +1 -1
- 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/ColumnFilters.js +97 -0
- package/dist/esm/table/HeaderCell.js +71 -38
- package/dist/esm/table/Table.js +115 -73
- package/dist/esm/table/types.js +29 -0
- package/dist/esm/table/useResizer.js +4 -4
- package/dist/esm/table/useVirtualTable.js +124 -20
- package/dist/esm/tree/TreeNode.js +47 -27
- package/dist/esm/tree/TreePanel.js +28 -10
- package/dist/esm/tree/useTree.js +99 -17
- package/dist/esm/tree/utils.js +20 -5
- package/dist/esm/virtual/Gallery.js +84 -35
- package/dist/esm/virtual/List.js +82 -32
- package/dist/types/checklist/CheckList.d.ts +24 -2
- package/dist/types/histogram/Histogram.d.ts +31 -4
- package/dist/types/hooks/useFilteredList.d.ts +20 -2
- package/dist/types/hooks/usePagination.d.ts +19 -0
- package/dist/types/hooks/useSelectableList.d.ts +29 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/json/JsonViewer.d.ts +27 -2
- package/dist/types/pagination/Pagination.d.ts +10 -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/ColumnFilters.d.ts +9 -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 +14 -1
- package/dist/types/table/types.d.ts +48 -7
- package/dist/types/table/useTableColumns.d.ts +6 -6
- package/dist/types/table/useVirtualTable.d.ts +23 -8
- package/dist/types/tree/TreeNode.d.ts +1 -1
- package/dist/types/tree/TreePanel.d.ts +42 -1
- package/dist/types/tree/types.d.ts +25 -5
- package/dist/types/tree/useTree.d.ts +3 -10
- package/dist/types/tree/utils.d.ts +4 -1
- package/dist/types/virtual/Gallery.d.ts +44 -4
- package/dist/types/virtual/List.d.ts +44 -4
- package/package.json +13 -10
- package/src/checklist/CheckList.tsx +103 -77
- package/src/histogram/Histogram.tsx +45 -11
- package/src/hooks/useFilteredList.tsx +19 -0
- package/src/hooks/usePagination.tsx +32 -7
- package/src/hooks/useSelectableList.ts +29 -0
- package/src/i18n/ar.json +5 -0
- package/src/i18n/en.json +5 -0
- package/src/index.ts +1 -1
- package/src/json/JsonViewer.tsx +71 -35
- package/src/pagination/Pagination.tsx +10 -0
- package/src/table/AddColumn.tsx +3 -3
- package/src/table/BodyCell.tsx +34 -5
- package/src/table/BodyRow.tsx +143 -0
- package/src/table/CheckboxCell.tsx +1 -1
- package/src/table/ColumnFilters.tsx +105 -0
- package/src/table/EmptyCell.tsx +2 -2
- package/src/table/HeaderCell.tsx +72 -14
- package/src/table/Table.tsx +177 -77
- package/src/table/types.ts +52 -6
- package/src/table/useResizer.ts +5 -3
- package/src/table/useTableColumns.ts +7 -7
- package/src/table/useVirtualTable.ts +146 -24
- package/src/tree/TreeNode.tsx +98 -56
- package/src/tree/TreePanel.tsx +64 -3
- package/src/tree/types.ts +32 -4
- package/src/tree/useTree.ts +109 -26
- package/src/tree/utils.ts +23 -8
- package/src/virtual/Gallery.tsx +96 -42
- package/src/virtual/List.tsx +82 -33
- package/dist/cjs/histogram/Histogram.module.css +0 -1
- package/dist/esm/histogram/Histogram.module.css +0 -1
|
@@ -48,6 +48,16 @@ export interface PaginationProps {
|
|
|
48
48
|
onPageChange: (page: number) => void;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Pagination component to navigate through pages of data.
|
|
53
|
+
* It displays buttons for navigating to the first, previous, next, and last pages,
|
|
54
|
+
* as well as buttons for specific page numbers based on the provided ranges.
|
|
55
|
+
* The component supports a minimal view that shows the current page and total pages.
|
|
56
|
+
* It uses memoization to optimize rendering performance.
|
|
57
|
+
*
|
|
58
|
+
* @param {PaginationProps} props - The properties for the Pagination component.
|
|
59
|
+
* @returns {JSX.Element} The rendered Pagination component.
|
|
60
|
+
*/
|
|
51
61
|
export const Pagination = memo(
|
|
52
62
|
({ page, ranges, totalPages, minimal, onPageChange }: PaginationProps) => {
|
|
53
63
|
const [start, mid, last] = ranges;
|
package/src/table/AddColumn.tsx
CHANGED
|
@@ -22,17 +22,17 @@
|
|
|
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 (
|
|
35
|
-
<div className="group font-medium w-6 flex flex-nowrap text-start items-
|
|
35
|
+
<div className="group font-medium w-6 flex flex-nowrap text-start items-center">
|
|
36
36
|
<Dropdown placement="bottom-end">
|
|
37
37
|
<Icon
|
|
38
38
|
icon={CoreIcons.insert}
|
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(value, 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 group/table-col"
|
|
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 group/table-row",
|
|
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
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* React Fabric
|
|
3
|
+
* @version: 1.0.0
|
|
4
|
+
*
|
|
5
|
+
*
|
|
6
|
+
* The MIT License (MIT)
|
|
7
|
+
* Copyright (c) 2025 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 { Button, DropdownDismiss } from "@react-fabric/core";
|
|
25
|
+
import { Checkbox, Input, Search } from "@react-fabric/form";
|
|
26
|
+
import { EMPTY_ARRAY, matchString } from "@react-fabric/utilities";
|
|
27
|
+
import { useState } from "react";
|
|
28
|
+
import { useFilteredList } from "../hooks/useFilteredList";
|
|
29
|
+
import { type TableColumn } from "./types";
|
|
30
|
+
|
|
31
|
+
interface FilterProps {
|
|
32
|
+
type: TableColumn["dataType"];
|
|
33
|
+
onFilter: (value: AnyObject) => void;
|
|
34
|
+
list?: AnyObject[];
|
|
35
|
+
filter: AnyObject;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const ListFilter = ({
|
|
39
|
+
list = EMPTY_ARRAY,
|
|
40
|
+
filter,
|
|
41
|
+
onFilter,
|
|
42
|
+
}: Partial<FilterProps>) => {
|
|
43
|
+
const [selected, setSelected] = useState<Set<string>>(new Set(filter));
|
|
44
|
+
|
|
45
|
+
const { filteredList, query, onSearch } = useFilteredList(
|
|
46
|
+
list,
|
|
47
|
+
(item, query) => {
|
|
48
|
+
return matchString(item.id ?? item, query);
|
|
49
|
+
},
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<div className="flex flex-col">
|
|
54
|
+
<div>
|
|
55
|
+
<Search autoFocus value={query} onSearch={onSearch} searchOnChange />
|
|
56
|
+
</div>
|
|
57
|
+
<div className="flex-1 overflow-auto scroll-thin">
|
|
58
|
+
{filteredList.map((v, idx) => (
|
|
59
|
+
<div key={idx} className="flex gap-x-1 text-xs items-center">
|
|
60
|
+
<Checkbox
|
|
61
|
+
checked={selected.has(v.id ?? v)}
|
|
62
|
+
onChange={(b) => {
|
|
63
|
+
const set = new Set(Array.from(selected.values()));
|
|
64
|
+
b ? set.add(v.id ?? v) : set.delete(v.id ?? v);
|
|
65
|
+
setSelected(set);
|
|
66
|
+
}}
|
|
67
|
+
label={<span className="truncate">{v.label ?? v}</span>}
|
|
68
|
+
/>
|
|
69
|
+
</div>
|
|
70
|
+
))}
|
|
71
|
+
{filteredList.length === 0 && (
|
|
72
|
+
<span className="text-muted text-xs">No items found</span>
|
|
73
|
+
)}
|
|
74
|
+
</div>
|
|
75
|
+
<div className="flex justify-end">
|
|
76
|
+
<DropdownDismiss>
|
|
77
|
+
<Button size="xs" onClick={() => onFilter?.(Array.from(selected))}>
|
|
78
|
+
Apply
|
|
79
|
+
</Button>
|
|
80
|
+
</DropdownDismiss>
|
|
81
|
+
</div>
|
|
82
|
+
</div>
|
|
83
|
+
);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export const ColumnFilters = ({
|
|
87
|
+
type,
|
|
88
|
+
list,
|
|
89
|
+
filter,
|
|
90
|
+
onFilter,
|
|
91
|
+
}: FilterProps) => {
|
|
92
|
+
return (
|
|
93
|
+
<div className="flex flex-col min-w-[16rem]">
|
|
94
|
+
{list && <ListFilter list={list} filter={filter} onFilter={onFilter} />}
|
|
95
|
+
{!list && type === "string" && (
|
|
96
|
+
<Input
|
|
97
|
+
autoFocus
|
|
98
|
+
allowClear
|
|
99
|
+
value={filter}
|
|
100
|
+
onEnterPressed={(e: AnyObject) => onFilter(e.target.value ?? "")}
|
|
101
|
+
/>
|
|
102
|
+
)}
|
|
103
|
+
</div>
|
|
104
|
+
);
|
|
105
|
+
};
|
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
|
@@ -22,25 +22,30 @@
|
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
import {
|
|
25
|
+
Button,
|
|
25
26
|
CoreIcons,
|
|
27
|
+
Divider,
|
|
26
28
|
DropdownTool,
|
|
27
29
|
Icon,
|
|
28
30
|
Menu,
|
|
29
31
|
MenuItem,
|
|
30
32
|
Tooltip,
|
|
31
33
|
} from "@react-fabric/core";
|
|
34
|
+
import { isEmpty } from "@react-fabric/utilities";
|
|
32
35
|
import { useCallback, useMemo } from "react";
|
|
36
|
+
import { ColumnFilters } from "./ColumnFilters";
|
|
33
37
|
import { useTableContext } from "./Context";
|
|
34
38
|
import {
|
|
35
39
|
COL_DEFAULT_WIDTH,
|
|
36
40
|
COL_MAX_WIDTH,
|
|
37
41
|
COL_MIN_WIDTH,
|
|
38
|
-
type
|
|
42
|
+
type TableColumn,
|
|
39
43
|
type TableProps,
|
|
40
44
|
} from "./types";
|
|
41
45
|
|
|
42
46
|
export const HeaderCell = ({
|
|
43
47
|
id,
|
|
48
|
+
dataType,
|
|
44
49
|
label,
|
|
45
50
|
icon,
|
|
46
51
|
iconBg,
|
|
@@ -48,6 +53,10 @@ export const HeaderCell = ({
|
|
|
48
53
|
rtlFlip,
|
|
49
54
|
actions,
|
|
50
55
|
locked,
|
|
56
|
+
filter,
|
|
57
|
+
filterable,
|
|
58
|
+
filterOptions,
|
|
59
|
+
tooltip,
|
|
51
60
|
sortable,
|
|
52
61
|
resizable,
|
|
53
62
|
width: _width,
|
|
@@ -55,7 +64,8 @@ export const HeaderCell = ({
|
|
|
55
64
|
minWidth,
|
|
56
65
|
sort,
|
|
57
66
|
onSort,
|
|
58
|
-
|
|
67
|
+
onFilter,
|
|
68
|
+
}: TableColumn & Pick<TableProps, "sort" | "onSort" | "onFilter">) => {
|
|
59
69
|
const { startResize, widths } = useTableContext();
|
|
60
70
|
|
|
61
71
|
const width = useMemo(
|
|
@@ -63,46 +73,84 @@ export const HeaderCell = ({
|
|
|
63
73
|
[widths, _width, id],
|
|
64
74
|
);
|
|
65
75
|
|
|
66
|
-
const handleSort = useCallback(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
76
|
+
const handleSort = useCallback(
|
|
77
|
+
(order?: "asc" | "desc") => {
|
|
78
|
+
sortable &&
|
|
79
|
+
onSort?.({
|
|
80
|
+
id: id.toString(),
|
|
81
|
+
order:
|
|
82
|
+
order ?? (sort?.id === id && sort.order === "asc" ? "desc" : "asc"),
|
|
83
|
+
});
|
|
84
|
+
},
|
|
85
|
+
[onSort, sort, sortable],
|
|
86
|
+
);
|
|
73
87
|
|
|
74
88
|
const menus = useMemo(() => {
|
|
75
|
-
|
|
89
|
+
let ret = [];
|
|
90
|
+
if (filterable && (dataType ?? filterOptions)) {
|
|
91
|
+
ret.push(
|
|
92
|
+
<Menu
|
|
93
|
+
key="filters"
|
|
94
|
+
label="Filter"
|
|
95
|
+
icon={filter ? CoreIcons.tick : ""}
|
|
96
|
+
trigger="click"
|
|
97
|
+
>
|
|
98
|
+
<ColumnFilters
|
|
99
|
+
type={dataType}
|
|
100
|
+
list={filterOptions}
|
|
101
|
+
filter={filter}
|
|
102
|
+
onFilter={(value) => onFilter?.(id, value)}
|
|
103
|
+
/>
|
|
104
|
+
</Menu>,
|
|
105
|
+
);
|
|
106
|
+
}
|
|
76
107
|
if (sortable) {
|
|
77
108
|
ret.push(
|
|
78
109
|
<MenuItem
|
|
79
110
|
key="sort-asc"
|
|
80
111
|
label="Sort ascending"
|
|
81
112
|
icon={CoreIcons.sortAsc}
|
|
113
|
+
onClick={() => handleSort("asc")}
|
|
82
114
|
/>,
|
|
83
115
|
<MenuItem
|
|
84
116
|
key="sort-desc"
|
|
85
117
|
label="Sort descending"
|
|
86
118
|
icon={CoreIcons.sortDesc}
|
|
119
|
+
onClick={() => handleSort("desc")}
|
|
87
120
|
/>,
|
|
88
121
|
);
|
|
89
122
|
}
|
|
123
|
+
if (actions) {
|
|
124
|
+
ret.push(<Divider key="div" />);
|
|
125
|
+
ret.push(...actions);
|
|
126
|
+
}
|
|
127
|
+
if (ret.length === 1) {
|
|
128
|
+
ret = [
|
|
129
|
+
<ColumnFilters
|
|
130
|
+
key="filters"
|
|
131
|
+
type={dataType}
|
|
132
|
+
list={filterOptions}
|
|
133
|
+
filter={filter}
|
|
134
|
+
onFilter={(value) => onFilter?.(id, value)}
|
|
135
|
+
/>,
|
|
136
|
+
];
|
|
137
|
+
}
|
|
90
138
|
return ret;
|
|
91
|
-
}, [sortable]);
|
|
139
|
+
}, [sortable, actions, onFilter, handleSort]);
|
|
92
140
|
|
|
93
141
|
return (
|
|
94
142
|
<div
|
|
95
143
|
role="none"
|
|
96
144
|
data-id={id}
|
|
97
|
-
onClick={handleSort}
|
|
98
|
-
className="group font-medium border-e flex flex-nowrap text-start items-center table-header-cell"
|
|
145
|
+
onClick={() => handleSort()}
|
|
146
|
+
className="group/tool font-medium border-e flex flex-nowrap text-start items-center table-header-cell"
|
|
99
147
|
style={{
|
|
100
148
|
width: width ?? COL_DEFAULT_WIDTH,
|
|
101
149
|
minWidth: minWidth ?? COL_MIN_WIDTH,
|
|
102
150
|
maxWidth: maxWidth ?? COL_MAX_WIDTH,
|
|
103
151
|
}}
|
|
104
152
|
>
|
|
105
|
-
<Tooltip content={label} disabled={!label}>
|
|
153
|
+
<Tooltip content={tooltip ?? label} disabled={!(tooltip ?? label)}>
|
|
106
154
|
<div className="flex-initial px-2 py-1 text-sm truncate sticky start-0">
|
|
107
155
|
{icon && (
|
|
108
156
|
<Icon icon={icon} bg={iconBg} color={iconColor} rtlFlip={rtlFlip} />
|
|
@@ -122,6 +170,16 @@ export const HeaderCell = ({
|
|
|
122
170
|
<Menu className="text-sm">{menus}</Menu>
|
|
123
171
|
</DropdownTool>
|
|
124
172
|
)}
|
|
173
|
+
{filterable && !isEmpty(filter) && (
|
|
174
|
+
<Button
|
|
175
|
+
size="sm"
|
|
176
|
+
variant="link"
|
|
177
|
+
aria-label="clear filter"
|
|
178
|
+
stopPropagation
|
|
179
|
+
icon={CoreIcons.funnelRemove}
|
|
180
|
+
onClick={() => onFilter?.(id)}
|
|
181
|
+
/>
|
|
182
|
+
)}
|
|
125
183
|
{resizable && (
|
|
126
184
|
<div
|
|
127
185
|
role="none"
|