@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
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { type BadgeType, type ChildProp, type CssProp, type Elements, type IconProps, type RefProp, type TestProps } from "@react-fabric/core/dist/types/types";
|
|
3
|
-
|
|
2
|
+
import { type ElementType } from "react";
|
|
3
|
+
interface TreeBaseNode<T> extends Omit<IconProps, "icon">, CssProp, TestProps {
|
|
4
4
|
id: string;
|
|
5
5
|
/**
|
|
6
6
|
* display label
|
|
@@ -23,17 +23,18 @@ interface TreeBaseNode<T> extends IconProps, CssProp, TestProps {
|
|
|
23
23
|
*/
|
|
24
24
|
disabled?: boolean;
|
|
25
25
|
data?: T;
|
|
26
|
+
icon?: ElementType<IconProps> | string;
|
|
26
27
|
}
|
|
27
28
|
export type TreeNodeType<T extends KeyValue = KeyValue> = TreeBaseNode<T> & ({
|
|
28
29
|
leaf: true;
|
|
29
30
|
children?: never;
|
|
30
31
|
} | {
|
|
31
|
-
leaf?:
|
|
32
|
+
leaf?: boolean;
|
|
32
33
|
children?: Array<TreeNodeType<T>>;
|
|
33
34
|
open?: boolean;
|
|
34
35
|
iconOpen?: string;
|
|
35
36
|
});
|
|
36
|
-
export interface InternalNode extends IconProps, CssProp, TestProps {
|
|
37
|
+
export interface InternalNode extends Omit<IconProps, "icon">, CssProp, TestProps {
|
|
37
38
|
id: string;
|
|
38
39
|
label: Elements<JSX.Element>;
|
|
39
40
|
queryable?: string;
|
|
@@ -50,6 +51,7 @@ export interface InternalNode extends IconProps, CssProp, TestProps {
|
|
|
50
51
|
loaded: boolean;
|
|
51
52
|
parent?: string;
|
|
52
53
|
empty?: boolean;
|
|
54
|
+
icon?: ElementType<IconProps> | string;
|
|
53
55
|
errored?: string;
|
|
54
56
|
selected?: true;
|
|
55
57
|
childSelected?: true;
|
|
@@ -66,9 +68,12 @@ export interface TreeNodeProps extends ChildProp {
|
|
|
66
68
|
noLines?: boolean;
|
|
67
69
|
selectable?: true | "leafOnly";
|
|
68
70
|
checkable?: true | "leafOnly";
|
|
71
|
+
leafClassName?: string;
|
|
72
|
+
nodeClassName?: string;
|
|
69
73
|
onToggle: (id: string) => void;
|
|
70
74
|
onSelect: (id: string) => void;
|
|
71
75
|
onChecked: (id: string) => void;
|
|
76
|
+
onClick?: (id: string, node: any) => void;
|
|
72
77
|
}
|
|
73
78
|
export interface TreeRef {
|
|
74
79
|
select: (id: string) => void;
|
|
@@ -120,10 +125,18 @@ export interface TreePanelProps<T extends KeyValue = KeyValue> extends TestProps
|
|
|
120
125
|
* callback for lazy loading tree items
|
|
121
126
|
*/
|
|
122
127
|
onLoad?: (id: string) => Promise<Array<TreeNodeType<T>> | undefined> | Array<TreeNodeType<T>> | undefined;
|
|
128
|
+
/**
|
|
129
|
+
* callback to load tree using search query
|
|
130
|
+
*/
|
|
131
|
+
onQuery?: (query: string) => void;
|
|
132
|
+
/**
|
|
133
|
+
* callback on click of tree node
|
|
134
|
+
*/
|
|
135
|
+
onClick?: (id: string, data: T) => void;
|
|
123
136
|
/**
|
|
124
137
|
* callback on selection of tree node
|
|
125
138
|
*/
|
|
126
|
-
onSelect?: (id: string) => void;
|
|
139
|
+
onSelect?: (id: string, data: T) => void;
|
|
127
140
|
/**
|
|
128
141
|
* callback on change of checked list
|
|
129
142
|
*/
|
|
@@ -136,6 +149,13 @@ export interface TreePanelProps<T extends KeyValue = KeyValue> extends TestProps
|
|
|
136
149
|
* item filter matcher
|
|
137
150
|
*/
|
|
138
151
|
matcher?: (data: T, query: string) => boolean;
|
|
152
|
+
sorter?: false | ((a: T, b: T) => number);
|
|
153
|
+
makeLabel?: (node: T) => string;
|
|
154
|
+
makeIcon?: (node: T) => string;
|
|
155
|
+
defaultExpanded?: string[];
|
|
156
|
+
onExpandToggle?: (id: string[]) => void;
|
|
157
|
+
leafClassName?: string;
|
|
158
|
+
nodeClassName?: string;
|
|
139
159
|
}
|
|
140
160
|
export declare const iconExpandAll = "M12.984 9v6h3l-3.984 3.984-3.984-3.984h3v-6h-3l3.984-3.984 3.984 3.984h-3zM3.984 2.016h16.031v1.969h-16.031v-1.969zM3.984 20.016h16.031v1.969h-16.031v-1.969z";
|
|
141
161
|
export declare const iconCollapseAll = "M3.984 11.016h16.031v1.969h-16.031v-1.969zM15.984 5.016l-3.984 3.984-3.984-3.984h3v-4.031h1.969v4.031h3zM8.016 18.984l3.984-3.984 3.984 3.984h-3v4.031h-1.969v-4.031h-3z";
|
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
import { type InternalNode, type
|
|
2
|
-
export declare const useTree: <T extends KeyValue<any>>({ items, checked, selected, matcher, onSelect, onChecked, }: {
|
|
3
|
-
items?: Array<TreeNodeType<T>>;
|
|
4
|
-
selected?: string;
|
|
5
|
-
checked?: string[];
|
|
6
|
-
onSelect?: (id: string) => void;
|
|
7
|
-
onChecked?: (leafs: string[], nodes: string[]) => void;
|
|
8
|
-
matcher?: (data: T, query: string) => boolean;
|
|
9
|
-
}) => {
|
|
1
|
+
import { type InternalNode, type TreePanelProps } from "./types";
|
|
2
|
+
export declare const useTree: <T extends KeyValue<any>>({ items, checked, selected, sorter, matcher, onLoad, onQuery, onSelect, onChecked, defaultExpanded, onExpandToggle, }: Partial<TreePanelProps<T>>) => {
|
|
10
3
|
tree: InternalNode[];
|
|
11
4
|
toggleExpand: (id: string) => void;
|
|
12
5
|
expandAll: () => void;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { type InternalNode, type TreeNodeType } from "./types";
|
|
2
|
-
export declare const refactorTree: (nodes: TreeNodeType[],
|
|
2
|
+
export declare const refactorTree: (nodes: TreeNodeType[], { sorter, defaultExpanded, }: {
|
|
3
|
+
sorter?: any;
|
|
4
|
+
defaultExpanded?: string[];
|
|
5
|
+
}, options?: {
|
|
3
6
|
level: number;
|
|
4
7
|
parent?: string;
|
|
5
8
|
}) => InternalNode[];
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import { type TestProps } from "@react-fabric/core/dist/types/types";
|
|
1
2
|
import { type ReactElement, type Ref } from "react";
|
|
2
3
|
export interface VirtualGalleryRef {
|
|
3
4
|
scrollToItem: (index: number) => void;
|
|
4
5
|
hilight: (index: number) => void;
|
|
5
6
|
unhilight: () => void;
|
|
6
7
|
}
|
|
7
|
-
export interface VirtualGalleryProps<T> {
|
|
8
|
+
export interface VirtualGalleryProps<T> extends TestProps {
|
|
8
9
|
children: (props: {
|
|
9
|
-
|
|
10
|
+
item: T;
|
|
10
11
|
index: number;
|
|
11
12
|
isLast: boolean;
|
|
12
13
|
}) => ReactElement;
|
|
@@ -23,6 +24,12 @@ export interface VirtualGalleryProps<T> {
|
|
|
23
24
|
* default item width
|
|
24
25
|
*/
|
|
25
26
|
defaultWidth?: number;
|
|
27
|
+
/**
|
|
28
|
+
* full width list
|
|
29
|
+
*/
|
|
30
|
+
fullWidth?: boolean;
|
|
31
|
+
maxWidth?: string | number;
|
|
32
|
+
minWidth?: string | number;
|
|
26
33
|
/**
|
|
27
34
|
* padding
|
|
28
35
|
*/
|
|
@@ -31,6 +38,7 @@ export interface VirtualGalleryProps<T> {
|
|
|
31
38
|
* data list
|
|
32
39
|
*/
|
|
33
40
|
items: T[];
|
|
41
|
+
total?: number;
|
|
34
42
|
/**
|
|
35
43
|
* loading state
|
|
36
44
|
*/
|
|
@@ -50,6 +58,6 @@ export interface VirtualGalleryProps<T> {
|
|
|
50
58
|
onScroll?: (top: number) => void;
|
|
51
59
|
}
|
|
52
60
|
export declare const VirtualGallery: {
|
|
53
|
-
<T extends KeyValue<any>>({ items, children, columns, padding, defaultHeight: height, defaultWidth: width, hideScroller, initialScroll, loading, onLoadMore, onScroll, galleryRef, }: VirtualGalleryProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
61
|
+
<T extends KeyValue<any>>({ items, children, columns, fullWidth, maxWidth, minWidth, total, padding, defaultHeight: height, defaultWidth: width, hideScroller, initialScroll, loading, onLoadMore, onScroll, galleryRef, ...aria }: VirtualGalleryProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
54
62
|
displayName: string;
|
|
55
63
|
};
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import { type TestProps } from "@react-fabric/core/dist/types/types";
|
|
1
2
|
import { type ReactElement, type Ref } from "react";
|
|
2
3
|
export interface VirtualListRef {
|
|
3
4
|
scrollToItem: (index: number) => void;
|
|
4
5
|
hilight: (index: number) => void;
|
|
5
6
|
unhilight: () => void;
|
|
6
7
|
}
|
|
7
|
-
export interface VirtualListProps<T> {
|
|
8
|
+
export interface VirtualListProps<T> extends TestProps {
|
|
8
9
|
children: (props: {
|
|
9
|
-
|
|
10
|
+
item: T;
|
|
10
11
|
index: number;
|
|
11
12
|
isLast: boolean;
|
|
12
13
|
}) => ReactElement;
|
|
@@ -23,6 +24,8 @@ export interface VirtualListProps<T> {
|
|
|
23
24
|
* full width list
|
|
24
25
|
*/
|
|
25
26
|
fullWidth?: boolean;
|
|
27
|
+
maxWidth?: string | number;
|
|
28
|
+
minWidth?: string | number;
|
|
26
29
|
/**
|
|
27
30
|
* padding
|
|
28
31
|
*/
|
|
@@ -35,6 +38,7 @@ export interface VirtualListProps<T> {
|
|
|
35
38
|
* data list
|
|
36
39
|
*/
|
|
37
40
|
items: T[];
|
|
41
|
+
total?: number;
|
|
38
42
|
initialScroll?: number;
|
|
39
43
|
/**
|
|
40
44
|
* loading state
|
|
@@ -54,6 +58,6 @@ export interface VirtualListProps<T> {
|
|
|
54
58
|
onScroll?: (top: number) => void;
|
|
55
59
|
}
|
|
56
60
|
export declare const VirtualList: {
|
|
57
|
-
<T extends KeyValue<any>>({ items, children, fullWidth, padding, orientation, defaultHeight: height, defaultWidth: width, hideScroller, initialScroll, loading, onLoadMore, onScroll, listRef, }: VirtualListProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
61
|
+
<T extends KeyValue<any>>({ items, total, children, fullWidth, maxWidth, minWidth, padding, orientation, defaultHeight: height, defaultWidth: width, hideScroller, initialScroll, loading, onLoadMore, onScroll, listRef, ...aria }: VirtualListProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
58
62
|
displayName: string;
|
|
59
63
|
};
|
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.31",
|
|
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.31",
|
|
37
|
+
"@react-fabric/date": "^1.0.0-beta.31",
|
|
38
|
+
"@react-fabric/form": "^1.0.0-beta.31",
|
|
39
|
+
"@react-fabric/utilities": "^1.0.0-beta.31",
|
|
39
40
|
"@tanstack/react-virtual": "^3.8.6",
|
|
40
41
|
"classnames": "^2.5.1",
|
|
41
42
|
"color": "^4.2.3",
|
|
@@ -43,13 +44,13 @@
|
|
|
43
44
|
},
|
|
44
45
|
"peerDependencies": {
|
|
45
46
|
"i18next": "^23.15.1",
|
|
46
|
-
"react": "
|
|
47
|
-
"react-dom": "
|
|
47
|
+
"react": "^19.0.0",
|
|
48
|
+
"react-dom": "^19.0.0",
|
|
48
49
|
"react-i18next": "^15.0.2"
|
|
49
50
|
},
|
|
50
51
|
"engines": {
|
|
51
52
|
"node": ">=18.12.0",
|
|
52
53
|
"npm": ">=8.19.0"
|
|
53
54
|
},
|
|
54
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "de71c6875264d385666d0fa441785b9884951561"
|
|
55
56
|
}
|
|
@@ -0,0 +1,222 @@
|
|
|
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 { Badge, CoreIcons, EmptyContent, Icon } from "@react-fabric/core";
|
|
25
|
+
import {
|
|
26
|
+
type BadgeType,
|
|
27
|
+
type TestProps,
|
|
28
|
+
} from "@react-fabric/core/dist/types/types";
|
|
29
|
+
import { isString } from "@react-fabric/utilities";
|
|
30
|
+
import {
|
|
31
|
+
Fragment,
|
|
32
|
+
isValidElement,
|
|
33
|
+
useEffect,
|
|
34
|
+
useMemo,
|
|
35
|
+
useState,
|
|
36
|
+
type FC,
|
|
37
|
+
} from "react";
|
|
38
|
+
import { useTranslation } from "react-i18next";
|
|
39
|
+
import {
|
|
40
|
+
useSelectableList,
|
|
41
|
+
type SelectableProps,
|
|
42
|
+
} from "../hooks/useSelectableList";
|
|
43
|
+
|
|
44
|
+
export interface CheckListItem extends KeyValue {
|
|
45
|
+
id: string;
|
|
46
|
+
label: string;
|
|
47
|
+
icon?: string;
|
|
48
|
+
badge?: BadgeType;
|
|
49
|
+
isDisabled?: boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface CheckListProps extends SelectableProps, TestProps {
|
|
53
|
+
/**
|
|
54
|
+
* list items
|
|
55
|
+
*/
|
|
56
|
+
items: CheckListItem[];
|
|
57
|
+
/**
|
|
58
|
+
* allow negative selections
|
|
59
|
+
*/
|
|
60
|
+
allowNegative?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* max list items
|
|
63
|
+
*/
|
|
64
|
+
maxCount?: number;
|
|
65
|
+
/**
|
|
66
|
+
* message for empty list
|
|
67
|
+
*/
|
|
68
|
+
emptyMessage?: string;
|
|
69
|
+
|
|
70
|
+
sortItems?: boolean;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const CheckItem: FC<
|
|
74
|
+
Omit<CheckListItem, "selected"> & {
|
|
75
|
+
selected?: number;
|
|
76
|
+
allowNegative?: boolean;
|
|
77
|
+
}
|
|
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>
|
|
114
|
+
<Icon
|
|
115
|
+
data-type="multiple"
|
|
116
|
+
className="ax-checkList__checkbox"
|
|
117
|
+
icon={
|
|
118
|
+
selected === 1
|
|
119
|
+
? CoreIcons.expand
|
|
120
|
+
: selected === -1
|
|
121
|
+
? CoreIcons.collapse
|
|
122
|
+
: CoreIcons.checkboxOff
|
|
123
|
+
}
|
|
124
|
+
data-selected={selected}
|
|
125
|
+
/>
|
|
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
|
+
/>
|
|
133
|
+
<Icon
|
|
134
|
+
data-type="negative"
|
|
135
|
+
onClick={(e) => [(onClick(id, true), e.stopPropagation())]}
|
|
136
|
+
icon={
|
|
137
|
+
selected === -1 ? CoreIcons.collapseActive : CoreIcons.collapse
|
|
138
|
+
}
|
|
139
|
+
data-selected={selected === -1}
|
|
140
|
+
/>
|
|
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
|
+
};
|
|
151
|
+
|
|
152
|
+
export const CheckList: FC<CheckListProps> = ({
|
|
153
|
+
items = [],
|
|
154
|
+
maxCount = 0,
|
|
155
|
+
allowNegative,
|
|
156
|
+
emptyMessage,
|
|
157
|
+
sortItems = true,
|
|
158
|
+
selected,
|
|
159
|
+
nonselected,
|
|
160
|
+
onChange,
|
|
161
|
+
onClick,
|
|
162
|
+
...aria
|
|
163
|
+
}: CheckListProps) => {
|
|
164
|
+
const { t } = useTranslation("data");
|
|
165
|
+
const { selection, toggleSelection } = useSelectableList({
|
|
166
|
+
items,
|
|
167
|
+
selected,
|
|
168
|
+
nonselected,
|
|
169
|
+
onChange,
|
|
170
|
+
onClick,
|
|
171
|
+
});
|
|
172
|
+
const [showMore, setShowMore] = useState(false);
|
|
173
|
+
|
|
174
|
+
useEffect(() => {
|
|
175
|
+
setShowMore(false);
|
|
176
|
+
}, [items]);
|
|
177
|
+
|
|
178
|
+
const listItems = useMemo(() => {
|
|
179
|
+
return [...items]
|
|
180
|
+
.sort((a, b) => {
|
|
181
|
+
if (sortItems && selection[a.id] !== selection[b.id]) {
|
|
182
|
+
if (selection[a.id] === 1) return -1;
|
|
183
|
+
if (selection[b.id] === 1) return 1;
|
|
184
|
+
if (selection[a.id] === -1) return -1;
|
|
185
|
+
if (selection[b.id] === -1) return 1;
|
|
186
|
+
}
|
|
187
|
+
return 0;
|
|
188
|
+
})
|
|
189
|
+
.slice(0, !showMore && maxCount > 0 ? maxCount : undefined);
|
|
190
|
+
}, [items, selection, maxCount, showMore, sortItems]);
|
|
191
|
+
|
|
192
|
+
return (
|
|
193
|
+
<div {...aria}>
|
|
194
|
+
{listItems.map((item, index) => (
|
|
195
|
+
<CheckItem
|
|
196
|
+
{...item}
|
|
197
|
+
key={index}
|
|
198
|
+
onClick={toggleSelection}
|
|
199
|
+
allowNegative={allowNegative}
|
|
200
|
+
selected={selection[item.id]}
|
|
201
|
+
/>
|
|
202
|
+
))}
|
|
203
|
+
{maxCount > 0 && items.length > maxCount && (
|
|
204
|
+
<div className="ax-moreLink">
|
|
205
|
+
<span
|
|
206
|
+
role="none"
|
|
207
|
+
className="link"
|
|
208
|
+
onClick={() => setShowMore(!showMore)}
|
|
209
|
+
>
|
|
210
|
+
...{t(`core:action.${showMore ? "less" : "more"}`)}
|
|
211
|
+
</span>
|
|
212
|
+
</div>
|
|
213
|
+
)}
|
|
214
|
+
{listItems.length === 0 && (
|
|
215
|
+
<EmptyContent
|
|
216
|
+
className="text-sm"
|
|
217
|
+
message={emptyMessage ?? t("checkList.empty")}
|
|
218
|
+
/>
|
|
219
|
+
)}
|
|
220
|
+
</div>
|
|
221
|
+
);
|
|
222
|
+
};
|
|
@@ -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})`,
|
|
@@ -125,8 +128,10 @@ export const Histogram = ({
|
|
|
125
128
|
className={classNames(
|
|
126
129
|
"relative cursor-pointer flex flex-nowrap items-center select-none overflow-hidden min-h-6 my-px",
|
|
127
130
|
classes.histoLabel,
|
|
128
|
-
(item.count === 0 || item.disabled) &&
|
|
131
|
+
((item.total ?? item.count) === 0 || item.disabled) &&
|
|
132
|
+
"pointer-events-none",
|
|
129
133
|
)}
|
|
134
|
+
data-testid={item.id}
|
|
130
135
|
onClick={(e) => [onClick?.(item.id), e.stopPropagation()]}
|
|
131
136
|
>
|
|
132
137
|
<div
|
|
@@ -145,6 +150,7 @@ export const Histogram = ({
|
|
|
145
150
|
key="negative"
|
|
146
151
|
color="danger"
|
|
147
152
|
size="sm"
|
|
153
|
+
stopPropagation
|
|
148
154
|
icon={CoreIcons.funnelMinus}
|
|
149
155
|
aria-label="Filter Negative"
|
|
150
156
|
onClick={() => onClick?.(item.id, true)}
|
|
@@ -153,6 +159,7 @@ export const Histogram = ({
|
|
|
153
159
|
key="positive"
|
|
154
160
|
color="primary"
|
|
155
161
|
size="sm"
|
|
162
|
+
stopPropagation
|
|
156
163
|
icon={CoreIcons.funnelPlus}
|
|
157
164
|
aria-label="Filter"
|
|
158
165
|
onClick={() => onClick?.(item.id)}
|
|
@@ -111,9 +111,12 @@ export const usePagination = ({
|
|
|
111
111
|
|
|
112
112
|
/** ***************** set page *******************/
|
|
113
113
|
useEffect(() => {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
114
|
+
if (totalRecords > -1) {
|
|
115
|
+
const actual = Math.min(currentPage, totalPages - 1);
|
|
116
|
+
setPage(actual);
|
|
117
|
+
actual !== currentPage && onChange?.(actual);
|
|
118
|
+
}
|
|
119
|
+
}, [currentPage, totalRecords, totalPages]);
|
|
117
120
|
|
|
118
121
|
const headLabel = useMemo(
|
|
119
122
|
() => (
|
|
@@ -126,10 +129,13 @@ export const usePagination = ({
|
|
|
126
129
|
[page, perPage, totalRecords],
|
|
127
130
|
);
|
|
128
131
|
|
|
129
|
-
const onPageChange = useCallback(
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
132
|
+
const onPageChange = useCallback(
|
|
133
|
+
(page: number) => {
|
|
134
|
+
setPage(page);
|
|
135
|
+
startTransition(() => onChange?.(page));
|
|
136
|
+
},
|
|
137
|
+
[onChange],
|
|
138
|
+
);
|
|
133
139
|
|
|
134
140
|
return { page, totalPages, headLabel, ranges, onPageChange };
|
|
135
141
|
};
|
|
@@ -0,0 +1,94 @@
|
|
|
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 { useCallback, useEffect, useRef, useState, useTransition } from "react";
|
|
25
|
+
|
|
26
|
+
export interface SelectableProps {
|
|
27
|
+
/**
|
|
28
|
+
* list items
|
|
29
|
+
*/
|
|
30
|
+
items: Array<{ label: string } & KeyValue>;
|
|
31
|
+
/**
|
|
32
|
+
* selected item ids
|
|
33
|
+
*/
|
|
34
|
+
selected?: string[];
|
|
35
|
+
/**
|
|
36
|
+
* selected negative item ids
|
|
37
|
+
*/
|
|
38
|
+
nonselected?: string[];
|
|
39
|
+
/**
|
|
40
|
+
* change callback
|
|
41
|
+
*/
|
|
42
|
+
onChange?: (ids: string[], nonIds?: string[]) => void;
|
|
43
|
+
/**
|
|
44
|
+
* item click callback
|
|
45
|
+
*/
|
|
46
|
+
onClick?: (id: string, isNegative: boolean) => void;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const useSelectableList = ({
|
|
50
|
+
items,
|
|
51
|
+
selected,
|
|
52
|
+
nonselected,
|
|
53
|
+
onChange,
|
|
54
|
+
onClick,
|
|
55
|
+
}: SelectableProps) => {
|
|
56
|
+
const selectionRef = useRef<KeyValue<number>>({});
|
|
57
|
+
const [selection, setSelection] = useState<KeyValue<number>>({});
|
|
58
|
+
const [, startTransition] = useTransition();
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
selectionRef.current = items.reduce(
|
|
61
|
+
(ret, { id }) => ({
|
|
62
|
+
...ret,
|
|
63
|
+
[id]: selected?.includes?.(id)
|
|
64
|
+
? 1
|
|
65
|
+
: nonselected?.includes?.(id)
|
|
66
|
+
? -1
|
|
67
|
+
: 0,
|
|
68
|
+
}),
|
|
69
|
+
{},
|
|
70
|
+
);
|
|
71
|
+
setSelection({ ...selectionRef.current });
|
|
72
|
+
}, [items, selected, nonselected]);
|
|
73
|
+
|
|
74
|
+
const toggleSelection = useCallback((id: string, isNegative = false) => {
|
|
75
|
+
const check = isNegative ? -1 : 1;
|
|
76
|
+
if (selectionRef.current[id] !== check) selectionRef.current[id] = check;
|
|
77
|
+
else if (selectionRef.current[id] === check) selectionRef.current[id] = 0;
|
|
78
|
+
const change: string[][] = [[], []];
|
|
79
|
+
Object.entries(selectionRef.current).forEach(([id, select]) =>
|
|
80
|
+
select === 1
|
|
81
|
+
? change[0].push(id)
|
|
82
|
+
: select === -1
|
|
83
|
+
? change[1].push(id)
|
|
84
|
+
: undefined,
|
|
85
|
+
);
|
|
86
|
+
setSelection({ ...selectionRef.current });
|
|
87
|
+
startTransition(() => {
|
|
88
|
+
onClick?.(id, isNegative);
|
|
89
|
+
onChange?.(change[0], change[1]);
|
|
90
|
+
});
|
|
91
|
+
}, []);
|
|
92
|
+
|
|
93
|
+
return { selection, toggleSelection };
|
|
94
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -23,11 +23,12 @@
|
|
|
23
23
|
|
|
24
24
|
import "./i18n";
|
|
25
25
|
|
|
26
|
+
export { CheckList } from "./checklist/CheckList";
|
|
26
27
|
export { Histogram } from "./histogram/Histogram";
|
|
27
28
|
export { JsonViewer } from "./json/JsonViewer";
|
|
28
29
|
export { Pagination } from "./pagination/Pagination";
|
|
29
30
|
export { Table } from "./table/Table";
|
|
30
|
-
export { type TableRef } from "./table/types";
|
|
31
|
+
export { type TableColumn, type TableRef } from "./table/types";
|
|
31
32
|
export { TreePanel } from "./tree/TreePanel";
|
|
32
33
|
export { type TreeNodeType as TreeNode } from "./tree/types";
|
|
33
34
|
export { VirtualGallery, type VirtualGalleryRef } from "./virtual/Gallery";
|