@react-fabric/data 1.0.0-beta.6 → 1.0.0-beta.61
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/{dist/esm/tree/types.js → css/styles.css} +2 -7
- package/dist/cjs/checklist/CheckList.js +27 -4
- package/dist/cjs/histogram/Histogram.js +39 -9
- package/dist/cjs/hooks/useFilteredList.js +88 -10
- 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 +68 -28
- package/dist/cjs/pagination/Pagination.js +14 -4
- package/dist/cjs/table/AddColumn.js +3 -3
- package/dist/cjs/table/BodyCell.js +14 -6
- package/dist/cjs/table/BodyRow.js +4 -4
- package/dist/cjs/table/CheckboxCell.js +2 -2
- package/dist/cjs/table/ColumnFilters.js +97 -0
- package/dist/cjs/table/HeaderCell.js +71 -43
- package/dist/cjs/table/Table.js +62 -13
- package/dist/cjs/table/types.js +29 -0
- package/dist/cjs/table/useResizer.js +4 -4
- package/dist/cjs/table/useVirtualTable.js +127 -19
- package/dist/cjs/tree/TreeNode.js +50 -32
- package/dist/cjs/tree/TreePanel.js +52 -19
- package/dist/cjs/tree/useTree.js +199 -38
- package/dist/cjs/tree/utils.js +39 -12
- package/dist/cjs/virtual/Gallery.js +97 -45
- package/dist/cjs/virtual/List.js +93 -39
- package/dist/cjs/virtual/Scroller.js +16 -8
- package/dist/esm/checklist/CheckList.js +28 -5
- package/dist/esm/histogram/Histogram.js +41 -11
- package/dist/esm/hooks/useFilteredList.js +89 -11
- 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 +69 -29
- package/dist/esm/pagination/Pagination.js +15 -5
- package/dist/esm/table/AddColumn.js +4 -4
- package/dist/esm/table/BodyCell.js +15 -7
- package/dist/esm/table/BodyRow.js +4 -4
- package/dist/esm/table/CheckboxCell.js +3 -3
- package/dist/esm/table/ColumnFilters.js +97 -0
- package/dist/esm/table/HeaderCell.js +72 -44
- package/dist/esm/table/Table.js +63 -14
- package/dist/esm/table/types.js +29 -0
- package/dist/esm/table/useResizer.js +4 -4
- package/dist/esm/table/useVirtualTable.js +129 -21
- package/dist/esm/tree/TreeNode.js +53 -35
- package/dist/esm/tree/TreePanel.js +54 -21
- package/dist/esm/tree/useTree.js +202 -41
- package/dist/esm/tree/utils.js +40 -13
- package/dist/esm/virtual/Gallery.js +97 -45
- package/dist/esm/virtual/List.js +93 -39
- package/dist/esm/virtual/Scroller.js +17 -9
- package/dist/types/checklist/CheckList.d.ts +22 -0
- package/dist/types/histogram/Histogram.d.ts +28 -1
- package/dist/types/hooks/useFilteredList.d.ts +66 -5
- package/dist/types/hooks/usePagination.d.ts +19 -0
- package/dist/types/hooks/useSelectableList.d.ts +29 -0
- package/dist/types/json/JsonViewer.d.ts +27 -2
- package/dist/types/pagination/Pagination.d.ts +10 -1
- package/dist/types/table/ColumnFilters.d.ts +9 -0
- package/dist/types/table/HeaderCell.d.ts +1 -1
- package/dist/types/table/Table.d.ts +14 -1
- package/dist/types/table/types.d.ts +46 -7
- package/dist/types/table/useVirtualTable.d.ts +23 -9
- 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 +65 -21
- package/dist/types/tree/useTree.d.ts +9 -10
- package/dist/types/tree/utils.d.ts +10 -3
- package/dist/types/virtual/Gallery.d.ts +42 -3
- package/dist/types/virtual/List.d.ts +42 -3
- package/package.json +16 -14
- package/src/checklist/CheckList.tsx +39 -7
- package/src/histogram/Histogram.tsx +43 -19
- package/src/hooks/useFilteredList.tsx +109 -9
- 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/json/JsonViewer.tsx +76 -37
- package/src/pagination/Pagination.tsx +15 -5
- package/src/table/AddColumn.tsx +4 -4
- package/src/table/BodyCell.tsx +24 -7
- package/src/table/BodyRow.tsx +7 -4
- package/src/table/CheckboxCell.tsx +5 -5
- package/src/table/ColumnFilters.tsx +105 -0
- package/src/table/HeaderCell.tsx +74 -21
- package/src/table/Table.tsx +107 -12
- package/src/table/types.ts +49 -10
- package/src/table/useResizer.ts +5 -3
- package/src/table/useVirtualTable.ts +158 -27
- package/src/tree/TreeNode.tsx +96 -62
- package/src/tree/TreePanel.tsx +88 -22
- package/src/tree/types.ts +73 -23
- package/src/tree/useTree.ts +220 -44
- package/src/tree/utils.ts +58 -20
- package/src/virtual/Gallery.tsx +118 -54
- package/src/virtual/List.tsx +99 -39
- package/src/virtual/Scroller.tsx +25 -9
- package/dist/cjs/histogram/Histogram.module.css +0 -1
- package/dist/cjs/tree/types.js +0 -30
- package/dist/esm/histogram/Histogram.module.css +0 -1
package/src/i18n/ar.json
CHANGED
package/src/i18n/en.json
CHANGED
package/src/json/JsonViewer.tsx
CHANGED
|
@@ -22,10 +22,8 @@
|
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
import {
|
|
25
|
-
ActionLabel,
|
|
26
25
|
Button,
|
|
27
26
|
Copy,
|
|
28
|
-
CoreIcons,
|
|
29
27
|
EmptyContent,
|
|
30
28
|
Icon,
|
|
31
29
|
Meter,
|
|
@@ -181,6 +179,8 @@ const JsonEntry = ({
|
|
|
181
179
|
ret = actualValue ? t("json.true") : t("json.false");
|
|
182
180
|
if (ret?.length > 128) {
|
|
183
181
|
ret = <Text clamp={3}>{ret}</Text>;
|
|
182
|
+
} else {
|
|
183
|
+
ret = <div className="break-words">{ret}</div>;
|
|
184
184
|
}
|
|
185
185
|
|
|
186
186
|
return (
|
|
@@ -216,37 +216,36 @@ const JsonEntry = ({
|
|
|
216
216
|
|
|
217
217
|
const labelDisplay = useMemo(
|
|
218
218
|
() => (
|
|
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
|
-
}
|
|
219
|
+
<div
|
|
220
|
+
className={classNames(
|
|
221
|
+
"text-dimmed text-sm px-2 flex-1 group",
|
|
222
|
+
inline ? "truncate" : "break-words",
|
|
223
|
+
)}
|
|
247
224
|
>
|
|
225
|
+
{!canExpand && canFilter && (
|
|
226
|
+
<div className="hidden pe-1 group-hover:inline-block">
|
|
227
|
+
<Button
|
|
228
|
+
key="negative"
|
|
229
|
+
color="danger"
|
|
230
|
+
size="xs"
|
|
231
|
+
variant="link"
|
|
232
|
+
icon="icon-[mdi--filter-minus]"
|
|
233
|
+
aria-label="Filter Negative"
|
|
234
|
+
onClick={() => onFilter?.(pathWithoutOrdinal, actualValue, true)}
|
|
235
|
+
/>
|
|
236
|
+
<Button
|
|
237
|
+
key="positive"
|
|
238
|
+
color="primary"
|
|
239
|
+
size="xs"
|
|
240
|
+
variant="link"
|
|
241
|
+
icon="icon-[mdi--filter-plus]"
|
|
242
|
+
aria-label="Filter"
|
|
243
|
+
onClick={() => onFilter?.(pathWithoutOrdinal, actualValue)}
|
|
244
|
+
/>
|
|
245
|
+
</div>
|
|
246
|
+
)}
|
|
248
247
|
{labeler?.(path) ?? field}
|
|
249
|
-
</
|
|
248
|
+
</div>
|
|
250
249
|
),
|
|
251
250
|
[field, labeler, pathWithoutOrdinal, actualValue, canExpand, canFilter],
|
|
252
251
|
);
|
|
@@ -277,15 +276,24 @@ const JsonEntry = ({
|
|
|
277
276
|
{canExpand && (
|
|
278
277
|
<Icon
|
|
279
278
|
rtlFlip
|
|
280
|
-
icon={
|
|
279
|
+
icon={
|
|
280
|
+
expanded
|
|
281
|
+
? "icon-[mdi--chevron-down]"
|
|
282
|
+
: "icon-[mdi--chevron-right]"
|
|
283
|
+
}
|
|
281
284
|
/>
|
|
282
285
|
)}
|
|
283
286
|
{labelDisplay}
|
|
284
287
|
</div>
|
|
285
288
|
{display && (
|
|
286
|
-
<div
|
|
289
|
+
<div
|
|
290
|
+
className={classNames(
|
|
291
|
+
"px-2 flex flex-nowrap overflow-hidden",
|
|
292
|
+
inline && "flex-1",
|
|
293
|
+
)}
|
|
294
|
+
>
|
|
287
295
|
{canCopy && <Copy size="xs" text={actualValue} />}
|
|
288
|
-
{display}
|
|
296
|
+
<div className="flex-1">{display}</div>
|
|
289
297
|
</div>
|
|
290
298
|
)}
|
|
291
299
|
</div>
|
|
@@ -309,9 +317,14 @@ const JsonEntry = ({
|
|
|
309
317
|
>
|
|
310
318
|
{labelDisplay}
|
|
311
319
|
</div>
|
|
312
|
-
<div
|
|
320
|
+
<div
|
|
321
|
+
className={classNames(
|
|
322
|
+
"px-2 flex flex-nowrap overflow-hidden",
|
|
323
|
+
inline && "flex-1",
|
|
324
|
+
)}
|
|
325
|
+
>
|
|
313
326
|
{canCopy && <Copy size="xs" text={value} />}
|
|
314
|
-
{display}
|
|
327
|
+
<div className="flex-1">{display}</div>
|
|
315
328
|
</div>
|
|
316
329
|
</div>
|
|
317
330
|
)}
|
|
@@ -336,6 +349,32 @@ const JsonEntry = ({
|
|
|
336
349
|
);
|
|
337
350
|
};
|
|
338
351
|
|
|
352
|
+
/**
|
|
353
|
+
* JsonViewer component to display JSON data in a structured format.
|
|
354
|
+
* It supports inline display, property filtering, and custom formatting.
|
|
355
|
+
* The component can handle nested objects and arrays, displaying them in a tree-like structure.
|
|
356
|
+
* It also provides options for copying values and filtering properties.
|
|
357
|
+
*
|
|
358
|
+
* @param {JsonViewProps<T>} props - The properties for the JsonViewer component.
|
|
359
|
+
* @returns {JSX.Element} The rendered JsonViewer component.
|
|
360
|
+
*
|
|
361
|
+
* @example
|
|
362
|
+
* ```jsx
|
|
363
|
+
* <JsonViewer
|
|
364
|
+
* json={{ name: "John", age: 30, address: { city: "New York", zip: "10001" } }}
|
|
365
|
+
* copy={true}
|
|
366
|
+
* filters={true}
|
|
367
|
+
* propertyScheme={{ date: ["createdAt"], phone: ["contact"] }}
|
|
368
|
+
* inline={true}
|
|
369
|
+
* labelWidth="25%"
|
|
370
|
+
* formatter={(path, value) => (path === "age" ? `${value} years` : value)}
|
|
371
|
+
* labeler={(path) => path.replace(/_/g, " ").toUpperCase()}
|
|
372
|
+
* onFilter={(path, value, negate) => console.log(`Filter ${negate ? "negate" : ""} on ${path}:`, value)}
|
|
373
|
+
* />
|
|
374
|
+
* ```
|
|
375
|
+
*
|
|
376
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/data-jsonviewer--docs}
|
|
377
|
+
*/
|
|
339
378
|
export const JsonViewer = <T extends KeyValue = KeyValue>({
|
|
340
379
|
className,
|
|
341
380
|
json,
|
|
@@ -356,7 +395,7 @@ export const JsonViewer = <T extends KeyValue = KeyValue>({
|
|
|
356
395
|
const list = useMemo(() => reduceObject(json), [json]);
|
|
357
396
|
|
|
358
397
|
return (
|
|
359
|
-
<div {...rest} className={classNames(className, "
|
|
398
|
+
<div {...rest} className={classNames(className, "bg-alternate")}>
|
|
360
399
|
{!isEmpty(json) ? (
|
|
361
400
|
list.map((item) => (
|
|
362
401
|
<JsonEntry
|
|
@@ -21,7 +21,7 @@
|
|
|
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 {
|
|
24
|
+
import { Icon } from "@react-fabric/core";
|
|
25
25
|
import classNames from "classnames";
|
|
26
26
|
import { Fragment, memo, useMemo } from "react";
|
|
27
27
|
|
|
@@ -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;
|
|
@@ -115,7 +125,7 @@ export const Pagination = memo(
|
|
|
115
125
|
page === 0 && "pointer-events-none text-tint-300",
|
|
116
126
|
)}
|
|
117
127
|
>
|
|
118
|
-
<Icon icon=
|
|
128
|
+
<Icon icon="icon-[mdi--chevron-double-left]" rtlFlip />
|
|
119
129
|
</button>
|
|
120
130
|
<button
|
|
121
131
|
onClick={() => onPageChange(page - 1)}
|
|
@@ -124,7 +134,7 @@ export const Pagination = memo(
|
|
|
124
134
|
page === 0 && "pointer-events-none text-tint-300",
|
|
125
135
|
)}
|
|
126
136
|
>
|
|
127
|
-
<Icon icon=
|
|
137
|
+
<Icon icon="icon-[mdi--chevron-left]" rtlFlip />
|
|
128
138
|
</button>
|
|
129
139
|
{!minimal && pageBody}
|
|
130
140
|
{minimal && (
|
|
@@ -139,7 +149,7 @@ export const Pagination = memo(
|
|
|
139
149
|
page + 1 >= totalPages && "pointer-events-none text-tint-300",
|
|
140
150
|
)}
|
|
141
151
|
>
|
|
142
|
-
<Icon icon=
|
|
152
|
+
<Icon icon="icon-[mdi--chevron-right]" rtlFlip />
|
|
143
153
|
</button>
|
|
144
154
|
<button
|
|
145
155
|
onClick={() => onPageChange(totalPages - 1)}
|
|
@@ -148,7 +158,7 @@ export const Pagination = memo(
|
|
|
148
158
|
page + 1 >= totalPages && "pointer-events-none text-tint-300",
|
|
149
159
|
)}
|
|
150
160
|
>
|
|
151
|
-
<Icon icon=
|
|
161
|
+
<Icon icon="icon-[mdi--chevron-double-right]" rtlFlip />
|
|
152
162
|
</button>
|
|
153
163
|
</div>
|
|
154
164
|
);
|
package/src/table/AddColumn.tsx
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
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 {
|
|
24
|
+
import { Dropdown, Icon, Menu, MenuItem } from "@react-fabric/core";
|
|
25
25
|
import { type TableColumn } from "./types";
|
|
26
26
|
|
|
27
27
|
export const AddColumn = ({
|
|
@@ -32,10 +32,10 @@ export const AddColumn = ({
|
|
|
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
|
-
icon=
|
|
38
|
+
icon="icon-[mdi--plus-circle-outline]"
|
|
39
39
|
className="p-1 rounded-t rounded-b-none hover:outline"
|
|
40
40
|
/>
|
|
41
41
|
<Menu className="text-sm" onClick={onClick}>
|
|
@@ -45,7 +45,7 @@ export const AddColumn = ({
|
|
|
45
45
|
id={String(col.id)}
|
|
46
46
|
data-dropdown-dismiss="false"
|
|
47
47
|
label={`${col.label ?? String(col.id)}`}
|
|
48
|
-
icon={!col.hidden ?
|
|
48
|
+
icon={!col.hidden ? "icon-[mdi--check]" : ""}
|
|
49
49
|
/>
|
|
50
50
|
))}
|
|
51
51
|
</Menu>
|
package/src/table/BodyCell.tsx
CHANGED
|
@@ -22,7 +22,13 @@
|
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
import { DateDisplay } from "@react-fabric/date";
|
|
25
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
Format,
|
|
27
|
+
getByPath,
|
|
28
|
+
isArray,
|
|
29
|
+
isObject,
|
|
30
|
+
isTrue,
|
|
31
|
+
} from "@react-fabric/utilities";
|
|
26
32
|
import classNames from "classnames";
|
|
27
33
|
import { useMemo } from "react";
|
|
28
34
|
import { useTableContext } from "./Context";
|
|
@@ -52,29 +58,38 @@ export const BodyCell = ({
|
|
|
52
58
|
const content = useMemo(() => {
|
|
53
59
|
const value = getByPath(item, column.id.toString());
|
|
54
60
|
if (column.renderer != null) {
|
|
55
|
-
return column.renderer(
|
|
61
|
+
return column.renderer(value, item, index);
|
|
56
62
|
}
|
|
57
63
|
if (column.dataType === "boolean") {
|
|
58
|
-
const map = column.valueMap ?? { true: "Yes", false: "
|
|
64
|
+
const map = column.valueMap ?? { true: "Yes", false: "No" };
|
|
59
65
|
return map[`${isTrue(value) ? "true" : "false"}`];
|
|
60
66
|
}
|
|
61
67
|
if (column.valueMap != null) {
|
|
62
|
-
if (
|
|
68
|
+
if (
|
|
69
|
+
["number", "string"].includes(column.dataType ?? "string") &&
|
|
70
|
+
value in column.valueMap
|
|
71
|
+
) {
|
|
63
72
|
return column.valueMap[value];
|
|
64
73
|
}
|
|
65
74
|
}
|
|
66
|
-
if (column.dataType
|
|
75
|
+
if (["date", "time", "datetime"].includes(column.dataType ?? "")) {
|
|
67
76
|
return <DateDisplay date={value} format={column.format} />;
|
|
68
77
|
}
|
|
69
78
|
if (column.dataType === "number") {
|
|
70
79
|
return Format.number(value, column.format);
|
|
71
80
|
}
|
|
81
|
+
if (isObject(value)) {
|
|
82
|
+
return JSON.stringify(value);
|
|
83
|
+
}
|
|
84
|
+
if (isArray(value)) {
|
|
85
|
+
return value.join(", ");
|
|
86
|
+
}
|
|
72
87
|
return value ?? "";
|
|
73
88
|
}, [item, column]);
|
|
74
89
|
|
|
75
90
|
return (
|
|
76
91
|
<div
|
|
77
|
-
className="overflow-hidden bg-inherit start-0"
|
|
92
|
+
className="overflow-hidden bg-inherit start-0 border-e group/table-col"
|
|
78
93
|
style={{
|
|
79
94
|
width: width ?? COL_DEFAULT_WIDTH,
|
|
80
95
|
minWidth: column.minWidth ?? COL_MIN_WIDTH,
|
|
@@ -83,7 +98,9 @@ export const BodyCell = ({
|
|
|
83
98
|
>
|
|
84
99
|
<div
|
|
85
100
|
className={classNames(
|
|
86
|
-
"px-2 py-1
|
|
101
|
+
"px-2 py-1",
|
|
102
|
+
column.className,
|
|
103
|
+
column.truncate && "truncate",
|
|
87
104
|
column.align === "center" && "text-center",
|
|
88
105
|
column.align === "end" && "text-end",
|
|
89
106
|
)}
|
package/src/table/BodyRow.tsx
CHANGED
|
@@ -21,11 +21,11 @@
|
|
|
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 { Icon } from "@react-fabric/core";
|
|
24
25
|
import classNames from "classnames";
|
|
25
26
|
import { BodyCell } from "./BodyCell";
|
|
26
27
|
import { CheckboxCell } from "./CheckboxCell";
|
|
27
28
|
import { type TableColumn } from "./types";
|
|
28
|
-
import { CoreIcons, Icon } from "@react-fabric/core";
|
|
29
29
|
|
|
30
30
|
export const BodyRow = ({
|
|
31
31
|
rowKey,
|
|
@@ -74,8 +74,9 @@ export const BodyRow = ({
|
|
|
74
74
|
role="none"
|
|
75
75
|
data-row={index}
|
|
76
76
|
className={classNames(
|
|
77
|
-
"flex flex-nowrap datatable-row data-
|
|
77
|
+
"flex flex-nowrap datatable-row data-hilight:outline-1 -outline-offset-1 outline-primary-500 group/table-row",
|
|
78
78
|
onRowClick && "hover:bg-primary-50 active:bg-primary-100",
|
|
79
|
+
index % 2 ? "bg-even" : "bg-odd",
|
|
79
80
|
)}
|
|
80
81
|
onClick={() =>
|
|
81
82
|
checkableRows && keyProperty && !onRowClick
|
|
@@ -87,13 +88,15 @@ export const BodyRow = ({
|
|
|
87
88
|
{!!canExpand && (
|
|
88
89
|
<div
|
|
89
90
|
className={classNames(
|
|
90
|
-
"group font-medium w-6 flex flex-nowrap text-start
|
|
91
|
+
"group font-medium w-6 flex flex-nowrap text-start py-1",
|
|
91
92
|
!canExpand(data) && "pointer-events-none opacity-35",
|
|
92
93
|
)}
|
|
93
94
|
>
|
|
94
95
|
<Icon
|
|
95
96
|
className="p-1 text-tint-700 hover:text-primary-600"
|
|
96
|
-
icon={
|
|
97
|
+
icon={
|
|
98
|
+
expanded ? "icon-[mdi--minus-box]" : "icon-[mdi--plus-box]"
|
|
99
|
+
}
|
|
97
100
|
onClick={(e) => [
|
|
98
101
|
keyProperty && toggleExpand(data[keyProperty]),
|
|
99
102
|
e.stopPropagation(),
|
|
@@ -21,7 +21,7 @@
|
|
|
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 {
|
|
24
|
+
import { Icon } from "@react-fabric/core";
|
|
25
25
|
|
|
26
26
|
export const CheckboxCell = ({
|
|
27
27
|
state,
|
|
@@ -31,14 +31,14 @@ 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
|
|
38
|
-
?
|
|
38
|
+
? "icon-[mdi--checkbox-intermediate]"
|
|
39
39
|
: state === 1
|
|
40
|
-
?
|
|
41
|
-
:
|
|
40
|
+
? "icon-[mdi--checkbox-marked]"
|
|
41
|
+
: "icon-[mdi--checkbox-blank-outline]"
|
|
42
42
|
}
|
|
43
43
|
className="p-1 text-tint-700 hover:text-primary-600"
|
|
44
44
|
onClick={(e) => [onClick?.(), e.stopPropagation()]}
|
|
@@ -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
|
+
};
|