@react-fabric/data 1.0.0-beta.6 → 1.0.0-beta.60
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 +23 -0
- package/dist/cjs/histogram/Histogram.js +37 -7
- 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 +67 -27
- package/dist/cjs/pagination/Pagination.js +10 -0
- package/dist/cjs/table/AddColumn.js +1 -1
- package/dist/cjs/table/BodyCell.js +5 -4
- package/dist/cjs/table/BodyRow.js +2 -2
- package/dist/cjs/table/CheckboxCell.js +1 -1
- package/dist/cjs/table/ColumnFilters.js +97 -0
- package/dist/cjs/table/HeaderCell.js +71 -43
- package/dist/cjs/table/Table.js +58 -12
- 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 +48 -30
- package/dist/cjs/tree/TreePanel.js +45 -11
- 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 +23 -0
- package/dist/esm/histogram/Histogram.js +38 -8
- 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 +68 -28
- package/dist/esm/pagination/Pagination.js +10 -0
- package/dist/esm/table/AddColumn.js +1 -1
- package/dist/esm/table/BodyCell.js +5 -4
- package/dist/esm/table/BodyRow.js +2 -2
- package/dist/esm/table/CheckboxCell.js +1 -1
- package/dist/esm/table/ColumnFilters.js +97 -0
- package/dist/esm/table/HeaderCell.js +72 -44
- package/dist/esm/table/Table.js +59 -13
- 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 +51 -33
- package/dist/esm/tree/TreePanel.js +46 -12
- 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 +16 -8
- 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 +44 -5
- 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 -19
- 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 +22 -0
- package/src/histogram/Histogram.tsx +40 -10
- 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 +71 -35
- package/src/pagination/Pagination.tsx +10 -0
- package/src/table/AddColumn.tsx +1 -1
- package/src/table/BodyCell.tsx +6 -4
- package/src/table/BodyRow.tsx +3 -2
- package/src/table/CheckboxCell.tsx +1 -1
- package/src/table/ColumnFilters.tsx +105 -0
- package/src/table/HeaderCell.tsx +72 -18
- package/src/table/Table.tsx +99 -11
- package/src/table/types.ts +46 -8
- package/src/table/useResizer.ts +5 -3
- package/src/table/useVirtualTable.ts +158 -27
- package/src/tree/TreeNode.tsx +98 -58
- package/src/tree/TreePanel.tsx +77 -6
- package/src/tree/types.ts +73 -18
- 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 +16 -8
- package/dist/cjs/histogram/Histogram.module.css +0 -1
- package/dist/esm/histogram/Histogram.module.css +0 -1
|
@@ -7,7 +7,7 @@ export interface VirtualGalleryRef {
|
|
|
7
7
|
}
|
|
8
8
|
export interface VirtualGalleryProps<T> extends TestProps {
|
|
9
9
|
children: (props: {
|
|
10
|
-
|
|
10
|
+
item: T;
|
|
11
11
|
index: number;
|
|
12
12
|
isLast: boolean;
|
|
13
13
|
}) => ReactElement;
|
|
@@ -24,6 +24,12 @@ export interface VirtualGalleryProps<T> extends TestProps {
|
|
|
24
24
|
* default item width
|
|
25
25
|
*/
|
|
26
26
|
defaultWidth?: number;
|
|
27
|
+
/**
|
|
28
|
+
* full width list
|
|
29
|
+
*/
|
|
30
|
+
fullWidth?: boolean;
|
|
31
|
+
maxWidth?: string | number;
|
|
32
|
+
minWidth?: string | number;
|
|
27
33
|
/**
|
|
28
34
|
* padding
|
|
29
35
|
*/
|
|
@@ -32,6 +38,7 @@ export interface VirtualGalleryProps<T> extends TestProps {
|
|
|
32
38
|
* data list
|
|
33
39
|
*/
|
|
34
40
|
items: T[];
|
|
41
|
+
total?: number;
|
|
35
42
|
/**
|
|
36
43
|
* loading state
|
|
37
44
|
*/
|
|
@@ -44,13 +51,45 @@ export interface VirtualGalleryProps<T> extends TestProps {
|
|
|
44
51
|
/**
|
|
45
52
|
* load more callback
|
|
46
53
|
*/
|
|
47
|
-
onLoadMore?: () => void;
|
|
54
|
+
onLoadMore?: (lastIndex?: number) => void;
|
|
48
55
|
/**
|
|
49
56
|
* scroll handler
|
|
50
57
|
*/
|
|
51
58
|
onScroll?: (top: number) => void;
|
|
52
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* VirtualGallery component provides a virtualized gallery view for displaying a large list of items efficiently.
|
|
62
|
+
* It supports features like fixed columns, loading states, and customizable item rendering.
|
|
63
|
+
* The component uses virtualization to render only the visible items, improving performance for large datasets.
|
|
64
|
+
* It also provides a scroller for easy navigation through the items.
|
|
65
|
+
*
|
|
66
|
+
* @param {VirtualGalleryProps<T>} props - The properties for the VirtualGallery component.
|
|
67
|
+
* @returns {JSX.Element} The rendered VirtualGallery component.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```jsx
|
|
71
|
+
* <VirtualGallery
|
|
72
|
+
* items={items}
|
|
73
|
+
* columns={3}
|
|
74
|
+
* defaultHeight={100}
|
|
75
|
+
* defaultWidth={100}
|
|
76
|
+
* fullWidth={true}
|
|
77
|
+
* onLoadMore={(lastIndex) => console.log("Load more items from index:", lastIndex)}
|
|
78
|
+
* onScroll={(top) => console.log("Scrolled to top:", top)}
|
|
79
|
+
* >
|
|
80
|
+
* {({ item, index, isLast }) => (
|
|
81
|
+
* <div className="gallery-item" key={item.id}>
|
|
82
|
+
* <img src={item.image} alt={item.label} />
|
|
83
|
+
* <p>{item.label}</p>
|
|
84
|
+
* </div>
|
|
85
|
+
* )}
|
|
86
|
+
* </VirtualGallery>
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/data-virtualgallery--docs}
|
|
90
|
+
* @see {@link https://tanstack.com/docs/react-virtual/latest/overview}
|
|
91
|
+
*/
|
|
53
92
|
export declare const VirtualGallery: {
|
|
54
|
-
<T extends
|
|
93
|
+
<T extends unknown>({ 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;
|
|
55
94
|
displayName: string;
|
|
56
95
|
};
|
|
@@ -7,7 +7,7 @@ export interface VirtualListRef {
|
|
|
7
7
|
}
|
|
8
8
|
export interface VirtualListProps<T> extends TestProps {
|
|
9
9
|
children: (props: {
|
|
10
|
-
|
|
10
|
+
item: T;
|
|
11
11
|
index: number;
|
|
12
12
|
isLast: boolean;
|
|
13
13
|
}) => ReactElement;
|
|
@@ -24,6 +24,8 @@ export interface VirtualListProps<T> extends TestProps {
|
|
|
24
24
|
* full width list
|
|
25
25
|
*/
|
|
26
26
|
fullWidth?: boolean;
|
|
27
|
+
maxWidth?: string | number;
|
|
28
|
+
minWidth?: string | number;
|
|
27
29
|
/**
|
|
28
30
|
* padding
|
|
29
31
|
*/
|
|
@@ -36,6 +38,7 @@ export interface VirtualListProps<T> extends TestProps {
|
|
|
36
38
|
* data list
|
|
37
39
|
*/
|
|
38
40
|
items: T[];
|
|
41
|
+
total?: number;
|
|
39
42
|
initialScroll?: number;
|
|
40
43
|
/**
|
|
41
44
|
* loading state
|
|
@@ -48,13 +51,49 @@ export interface VirtualListProps<T> extends TestProps {
|
|
|
48
51
|
/**
|
|
49
52
|
* load more callback
|
|
50
53
|
*/
|
|
51
|
-
onLoadMore?: (
|
|
54
|
+
onLoadMore?: (lastIndex?: number) => void;
|
|
52
55
|
/**
|
|
53
56
|
* scroll handler
|
|
54
57
|
*/
|
|
55
58
|
onScroll?: (top: number) => void;
|
|
56
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* VirtualList component for rendering large lists efficiently using virtualization.
|
|
62
|
+
* It supports horizontal and vertical orientations, custom item heights and widths,
|
|
63
|
+
* and provides a scroller for navigating through the list.
|
|
64
|
+
* It also supports loading more items on scroll and provides a way to hilight items.
|
|
65
|
+
* It can be used with a ref to control scrolling and hilighting of items.
|
|
66
|
+
*
|
|
67
|
+
* @param {VirtualListProps<T>} props - The properties for the VirtualList component.
|
|
68
|
+
* @returns {JSX.Element} The rendered VirtualList component.
|
|
69
|
+
* @template T - The type of items in the list, extending AnyObject.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```jsx
|
|
73
|
+
* <VirtualList
|
|
74
|
+
* items={items}
|
|
75
|
+
* children={({ item, index, isLast }) => (
|
|
76
|
+
* <div key={index} className="item">
|
|
77
|
+
* {item.label}
|
|
78
|
+
* </div>
|
|
79
|
+
* )}
|
|
80
|
+
* fullWidth={true}
|
|
81
|
+
* orientation="vertical"
|
|
82
|
+
* defaultHeight={50}
|
|
83
|
+
* onLoadMore={(lastIndex) => console.log("Load more items from index:", lastIndex)}
|
|
84
|
+
* onScroll={(top) => console.log("Scrolled to top:", top)}
|
|
85
|
+
* listRef={virtualListRef}
|
|
86
|
+
* >
|
|
87
|
+
* {({ item, index, isLast }) => (
|
|
88
|
+
* <div className="gallery-item" key={item.id}>
|
|
89
|
+
* <img src={item.image} alt={item.label} />
|
|
90
|
+
* <p>{item.label}</p>
|
|
91
|
+
* </div>
|
|
92
|
+
* )}
|
|
93
|
+
* </VirtualList>
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
57
96
|
export declare const VirtualList: {
|
|
58
|
-
<T extends
|
|
97
|
+
<T extends unknown>({ 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;
|
|
59
98
|
displayName: string;
|
|
60
99
|
};
|
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.60",
|
|
4
4
|
"description": "RUF: Data package",
|
|
5
5
|
"author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -11,9 +11,11 @@
|
|
|
11
11
|
"types": "dist/types/index.d.ts",
|
|
12
12
|
"directories": {
|
|
13
13
|
"src": "src",
|
|
14
|
+
"styles": "css",
|
|
14
15
|
"test": "tests"
|
|
15
16
|
},
|
|
16
17
|
"files": [
|
|
18
|
+
"css",
|
|
17
19
|
"src",
|
|
18
20
|
"dist"
|
|
19
21
|
],
|
|
@@ -33,24 +35,24 @@
|
|
|
33
35
|
"watch": "npm-run-all -p watch:rollup watch:dts"
|
|
34
36
|
},
|
|
35
37
|
"dependencies": {
|
|
36
|
-
"@react-fabric/core": "^1.0.0-beta.
|
|
37
|
-
"@react-fabric/date": "^1.0.0-beta.
|
|
38
|
-
"@react-fabric/form": "^1.0.0-beta.
|
|
39
|
-
"@react-fabric/utilities": "^1.0.0-beta.
|
|
40
|
-
"@tanstack/react-virtual": "
|
|
41
|
-
"classnames": "
|
|
42
|
-
"color": "
|
|
43
|
-
"memoize-one": "
|
|
38
|
+
"@react-fabric/core": "^1.0.0-beta.60",
|
|
39
|
+
"@react-fabric/date": "^1.0.0-beta.60",
|
|
40
|
+
"@react-fabric/form": "^1.0.0-beta.60",
|
|
41
|
+
"@react-fabric/utilities": "^1.0.0-beta.60",
|
|
42
|
+
"@tanstack/react-virtual": "~3.13.12",
|
|
43
|
+
"classnames": "~2.5.1",
|
|
44
|
+
"color": "~5.0.2",
|
|
45
|
+
"memoize-one": "~6.0.0"
|
|
44
46
|
},
|
|
45
47
|
"peerDependencies": {
|
|
46
|
-
"i18next": "
|
|
47
|
-
"react": "
|
|
48
|
-
"react-dom": "
|
|
49
|
-
"react-i18next": "
|
|
48
|
+
"i18next": "~25.6.0",
|
|
49
|
+
"react": "~19.2.0",
|
|
50
|
+
"react-dom": "~19.2.0",
|
|
51
|
+
"react-i18next": "~16.2.1"
|
|
50
52
|
},
|
|
51
53
|
"engines": {
|
|
52
54
|
"node": ">=18.12.0",
|
|
53
55
|
"npm": ">=8.19.0"
|
|
54
56
|
},
|
|
55
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "a79f053ee7e13422c06d7d9c35d4f0c2610cdf5d"
|
|
56
58
|
}
|
|
@@ -149,6 +149,28 @@ const CheckItem: FC<
|
|
|
149
149
|
);
|
|
150
150
|
};
|
|
151
151
|
|
|
152
|
+
/**
|
|
153
|
+
* CheckList component to display a list of selectable items with checkboxes.
|
|
154
|
+
* It supports selection, deselection, and allows for negative selections.
|
|
155
|
+
*
|
|
156
|
+
* @param {CheckListProps} props - The properties for the CheckList component.
|
|
157
|
+
* @returns {JSX.Element} The rendered CheckList component.
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```jsx
|
|
161
|
+
* <CheckList
|
|
162
|
+
* items={[
|
|
163
|
+
* { id: "1", label: "Item 1", icon: "icon1" },
|
|
164
|
+
* { id: "2", label: "Item 2", icon: "icon2", badge: { text: "New" } },
|
|
165
|
+
* ]}
|
|
166
|
+
* maxCount={5}
|
|
167
|
+
* allowNegative={true}
|
|
168
|
+
* emptyMessage="No items available"
|
|
169
|
+
* onChange={(selectedItems) => console.log(selectedItems)}
|
|
170
|
+
* onClick={(itemId, isNegative) => console.log(itemId, isNegative)}
|
|
171
|
+
* />
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
152
174
|
export const CheckList: FC<CheckListProps> = ({
|
|
153
175
|
items = [],
|
|
154
176
|
maxCount = 0,
|
|
@@ -33,11 +33,10 @@ import {
|
|
|
33
33
|
type PaletteType,
|
|
34
34
|
type TestProps,
|
|
35
35
|
} from "@react-fabric/core/dist/types/types";
|
|
36
|
-
import { compareValues, Format } from "@react-fabric/utilities";
|
|
36
|
+
import { compareValues, Format, isColor } from "@react-fabric/utilities";
|
|
37
37
|
import classNames from "classnames";
|
|
38
38
|
import { useMemo } from "react";
|
|
39
39
|
import { useTranslation } from "react-i18next";
|
|
40
|
-
import classes from "./Histogram.module.css";
|
|
41
40
|
|
|
42
41
|
const emptyIcon =
|
|
43
42
|
"M20.84 22.73L11.11 13H3V11H9.11L6.11 8H3V6H4.11L1.11 3L2.39 1.73L22.11 21.46L20.84 22.73M15 11H14.2L15 11.8V11M21 8V6H9.2L11.2 8H21M3 18H9V16H3V18Z";
|
|
@@ -81,10 +80,38 @@ export interface HistogramProps extends TestProps {
|
|
|
81
80
|
onClick?: (id: string, negative?: true) => void;
|
|
82
81
|
}
|
|
83
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Histogram component displays a bar chart of items with counts.
|
|
85
|
+
* It allows users to visualize the distribution of counts across different items.
|
|
86
|
+
* The component supports sorting, custom colors, and click handling for each item.
|
|
87
|
+
* It also provides an empty state when there are no items to display.
|
|
88
|
+
*
|
|
89
|
+
* @param {HistogramProps} props - The properties for the Histogram component.
|
|
90
|
+
* @returns {JSX.Element} - The rendered Histogram component.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```jsx
|
|
94
|
+
* <Histogram
|
|
95
|
+
* items={[
|
|
96
|
+
* { id: "1", label: "Item 1", count: 10 },
|
|
97
|
+
* { id: "2", label: "Item 2", count: 20 },
|
|
98
|
+
* { id: "3", label: "Item 3", count: 5, disabled: true },
|
|
99
|
+
* ]}
|
|
100
|
+
* total={30}
|
|
101
|
+
* color="primary-500"
|
|
102
|
+
* sortBy="count"
|
|
103
|
+
* emptyTitle="No Data Available"
|
|
104
|
+
* emptyMessage="Please check back later."
|
|
105
|
+
* onClick={(id, negative) => console.log(`Clicked on ${id}`, negative ? "Negative" : "Positive")}
|
|
106
|
+
* />
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/data-histogram--docs}
|
|
110
|
+
*/
|
|
84
111
|
export const Histogram = ({
|
|
85
112
|
items = [],
|
|
86
113
|
total,
|
|
87
|
-
color = "primary",
|
|
114
|
+
color = "primary-500",
|
|
88
115
|
sortBy = "count",
|
|
89
116
|
emptyTitle,
|
|
90
117
|
emptyMessage,
|
|
@@ -105,11 +132,11 @@ export const Histogram = ({
|
|
|
105
132
|
|
|
106
133
|
return (
|
|
107
134
|
<div
|
|
108
|
-
className={
|
|
135
|
+
className={"fabric-histogram from-0% to-100%"}
|
|
109
136
|
{...aria}
|
|
110
137
|
style={
|
|
111
138
|
{
|
|
112
|
-
"--color": `var(
|
|
139
|
+
"--color": isColor(color) ? color : `var(--color-${color})`,
|
|
113
140
|
} as AnyObject
|
|
114
141
|
}
|
|
115
142
|
>
|
|
@@ -127,16 +154,17 @@ export const Histogram = ({
|
|
|
127
154
|
data-disabled={item.count === 0 || item.disabled}
|
|
128
155
|
className={classNames(
|
|
129
156
|
"relative cursor-pointer flex flex-nowrap items-center select-none overflow-hidden min-h-6 my-px",
|
|
130
|
-
|
|
131
|
-
(item.count === 0 || item.disabled) &&
|
|
157
|
+
"fabric-histoLabel",
|
|
158
|
+
((item.total ?? item.count) === 0 || item.disabled) &&
|
|
159
|
+
"pointer-events-none",
|
|
132
160
|
)}
|
|
133
161
|
data-testid={item.id}
|
|
134
162
|
onClick={(e) => [onClick?.(item.id), e.stopPropagation()]}
|
|
135
163
|
>
|
|
136
164
|
<div
|
|
137
165
|
className={classNames(
|
|
138
|
-
"absolute z-0 inset-0 opacity-50 min-w-2 ltr:bg-
|
|
139
|
-
|
|
166
|
+
"absolute z-0 inset-0 opacity-50 min-w-2 ltr:bg-linear-to-r rtl:bg-linear-to-l",
|
|
167
|
+
"fabric-histoBar",
|
|
140
168
|
)}
|
|
141
169
|
style={{
|
|
142
170
|
width: `${Math.min(item.count / maxTotal, 1) * 100}%`,
|
|
@@ -149,6 +177,7 @@ export const Histogram = ({
|
|
|
149
177
|
key="negative"
|
|
150
178
|
color="danger"
|
|
151
179
|
size="sm"
|
|
180
|
+
stopPropagation
|
|
152
181
|
icon={CoreIcons.funnelMinus}
|
|
153
182
|
aria-label="Filter Negative"
|
|
154
183
|
onClick={() => onClick?.(item.id, true)}
|
|
@@ -157,6 +186,7 @@ export const Histogram = ({
|
|
|
157
186
|
key="positive"
|
|
158
187
|
color="primary"
|
|
159
188
|
size="sm"
|
|
189
|
+
stopPropagation
|
|
160
190
|
icon={CoreIcons.funnelPlus}
|
|
161
191
|
aria-label="Filter"
|
|
162
192
|
onClick={() => onClick?.(item.id)}
|
|
@@ -168,7 +198,7 @@ export const Histogram = ({
|
|
|
168
198
|
<span
|
|
169
199
|
className={classNames(
|
|
170
200
|
"z-1 rounded-full text-xs font-medium px-2 py-1 leading-none",
|
|
171
|
-
|
|
201
|
+
"fabric-histoBadge",
|
|
172
202
|
)}
|
|
173
203
|
>
|
|
174
204
|
{Format.number(item.count)}
|
|
@@ -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 { isString, matchString } from "@react-fabric/utilities";
|
|
24
|
+
import { isArray, isString, matchString } from "@react-fabric/utilities";
|
|
25
25
|
import {
|
|
26
26
|
useCallback,
|
|
27
27
|
useDeferredValue,
|
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
const filterList = (
|
|
34
34
|
items: AnyObject[],
|
|
35
35
|
query: AnyObject = "",
|
|
36
|
+
matchAll: boolean = true,
|
|
36
37
|
matcher?: AnyObject,
|
|
37
38
|
) => {
|
|
38
39
|
const newList: AnyObject[] = [];
|
|
@@ -40,7 +41,20 @@ const filterList = (
|
|
|
40
41
|
if (matcher) {
|
|
41
42
|
return matcher?.(item, query) && newList.push(item);
|
|
42
43
|
}
|
|
43
|
-
if (query &&
|
|
44
|
+
if (query && isArray(query) && query.length > 0) {
|
|
45
|
+
if (
|
|
46
|
+
matchAll &&
|
|
47
|
+
query.every((q) => matchString(item.label ?? item.toString(), q))
|
|
48
|
+
) {
|
|
49
|
+
return newList.push(item);
|
|
50
|
+
}
|
|
51
|
+
if (
|
|
52
|
+
!matchAll &&
|
|
53
|
+
query.some((q) => matchString(item.label ?? item.toString(), q))
|
|
54
|
+
) {
|
|
55
|
+
return newList.push(item);
|
|
56
|
+
}
|
|
57
|
+
} else if (query && isString(query)) {
|
|
44
58
|
if (matchString(item.label ?? item.toString(), query)) {
|
|
45
59
|
return newList.push(item);
|
|
46
60
|
}
|
|
@@ -51,28 +65,114 @@ const filterList = (
|
|
|
51
65
|
return newList;
|
|
52
66
|
};
|
|
53
67
|
|
|
54
|
-
|
|
68
|
+
interface RetType<T, Q> {
|
|
69
|
+
onSearch: (query?: Q) => void;
|
|
70
|
+
query: Q;
|
|
71
|
+
filteredList: T[];
|
|
72
|
+
isSearching: boolean;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Custom hook to filter a list of items based on a query.
|
|
77
|
+
* It provides a way to search through the items and returns the filtered list.
|
|
78
|
+
* The hook uses a deferred value to optimize performance during transitions.
|
|
79
|
+
* It also allows for a custom matcher function to define how items should be matched against the query.
|
|
80
|
+
*
|
|
81
|
+
* @param items - The list of items to filter.
|
|
82
|
+
* @param matchAll - Match all phrases in the query list against the items.
|
|
83
|
+
* @returns An object containing the search function, current query, filtered list, and a boolean indicating if a search is in progress.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```jsx
|
|
87
|
+
* useFilteredList(items, (item, query) => {
|
|
88
|
+
* return item.name.includes(query);
|
|
89
|
+
* });
|
|
90
|
+
* ```
|
|
91
|
+
*
|
|
92
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/data-usefilteredlist--docs}
|
|
93
|
+
*/
|
|
94
|
+
export function useFilteredList<
|
|
95
|
+
T extends AnyObject = KeyValue,
|
|
96
|
+
Q extends AnyObject = string,
|
|
97
|
+
>(items: T[], matchAll?: boolean): RetType<T, Q>;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Custom hook to filter a list of items based on a query.
|
|
101
|
+
* It provides a way to search through the items and returns the filtered list.
|
|
102
|
+
* The hook uses a deferred value to optimize performance during transitions.
|
|
103
|
+
* It also allows for a custom matcher function to define how items should be matched against the query.
|
|
104
|
+
*
|
|
105
|
+
* @param items - The list of items to filter.
|
|
106
|
+
* @param matcher - An optional function to match items against the query.
|
|
107
|
+
* @returns An object containing the search function, current query, filtered list, and a boolean indicating if a search is in progress.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```jsx
|
|
111
|
+
* useFilteredList(items, (item, query) => {
|
|
112
|
+
* return item.name.includes(query);
|
|
113
|
+
* });
|
|
114
|
+
* ```
|
|
115
|
+
*
|
|
116
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/data-usefilteredlist--docs}
|
|
117
|
+
*/
|
|
118
|
+
export function useFilteredList<
|
|
119
|
+
T extends AnyObject = KeyValue,
|
|
120
|
+
Q extends AnyObject = string,
|
|
121
|
+
>(items: T[], matcher?: (item: T, query: Q) => boolean): RetType<T, Q>;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Custom hook to filter a list of items based on a query.
|
|
125
|
+
* It provides a way to search through the items and returns the filtered list.
|
|
126
|
+
* The hook uses a deferred value to optimize performance during transitions.
|
|
127
|
+
* It also allows for a custom matcher function to define how items should be matched against the query.
|
|
128
|
+
*
|
|
129
|
+
* @param items - The list of items to filter.
|
|
130
|
+
* @param matchAll - Match all phrases in the query list against the items.
|
|
131
|
+
* @param matcher - An optional function to match items against the query.
|
|
132
|
+
* @returns An object containing the search function, current query, filtered list, and a boolean indicating if a search is in progress.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```jsx
|
|
136
|
+
* useFilteredList(items, (item, query) => {
|
|
137
|
+
* return item.name.includes(query);
|
|
138
|
+
* });
|
|
139
|
+
* ```
|
|
140
|
+
*
|
|
141
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/data-usefilteredlist--docs}
|
|
142
|
+
*/
|
|
143
|
+
export function useFilteredList<
|
|
55
144
|
T extends AnyObject = KeyValue,
|
|
56
145
|
Q extends AnyObject = string,
|
|
57
146
|
>(
|
|
58
147
|
items: T[],
|
|
148
|
+
matchAll?: boolean,
|
|
59
149
|
matcher?: (item: T, query: Q) => boolean,
|
|
60
|
-
)
|
|
150
|
+
): RetType<T, Q>;
|
|
151
|
+
|
|
152
|
+
export function useFilteredList<
|
|
153
|
+
T extends AnyObject = KeyValue,
|
|
154
|
+
Q extends AnyObject = string,
|
|
155
|
+
>(items: T[], matchAll?: AnyObject, matcher?: (item: T, query: Q) => boolean) {
|
|
61
156
|
const [query, setQuery] = useState<Q>();
|
|
62
157
|
const _items = useDeferredValue(items ?? []);
|
|
63
158
|
const [filteredList, setFilteredList] = useState<T[]>([]);
|
|
64
159
|
const [isSearching, startTransition] = useTransition();
|
|
65
160
|
|
|
161
|
+
const matchingAll = typeof matchAll === "boolean" ? matchAll : true;
|
|
162
|
+
const matcherFn = typeof matchAll === "function" ? matchAll : matcher;
|
|
163
|
+
|
|
66
164
|
const filterItems = useCallback(
|
|
67
|
-
(items: T[], query?: Q) =>
|
|
68
|
-
startTransition(() =>
|
|
165
|
+
(items: T[], query?: Q, matchingAll?: boolean) =>
|
|
166
|
+
startTransition(() =>
|
|
167
|
+
setFilteredList(filterList(items, query, matchingAll, matcherFn)),
|
|
168
|
+
),
|
|
69
169
|
[],
|
|
70
170
|
);
|
|
71
171
|
|
|
72
172
|
useEffect(() => {
|
|
73
|
-
if (query) filterItems(_items, query);
|
|
173
|
+
if (query) filterItems(_items, query, matchingAll);
|
|
74
174
|
else setFilteredList(items);
|
|
75
|
-
}, [query, _items]);
|
|
175
|
+
}, [query, matchingAll, _items]);
|
|
76
176
|
|
|
77
177
|
return { onSearch: setQuery, query, filteredList, isSearching };
|
|
78
|
-
}
|
|
178
|
+
}
|
|
@@ -57,6 +57,25 @@ const makeRange = (start: number, end: number) => {
|
|
|
57
57
|
return Array.from({ length }, (_: AnyObject, idx: number) => idx + start);
|
|
58
58
|
};
|
|
59
59
|
|
|
60
|
+
/**
|
|
61
|
+
* Custom hook to manage pagination state and logic.
|
|
62
|
+
* It calculates the total number of pages, generates page ranges,
|
|
63
|
+
* and provides a way to change the current page.
|
|
64
|
+
* It also handles the transition of page changes to optimize performance.
|
|
65
|
+
*
|
|
66
|
+
* @param options - The pagination options including total records, current page, records per page, and change handler.
|
|
67
|
+
* @returns An object containing the current page, total pages, head label, ranges for pagination pills, and a function to change the page.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```jsx
|
|
71
|
+
* const { page, totalPages, headLabel, ranges, onPageChange } = usePagination({
|
|
72
|
+
* totalRecords: 100,
|
|
73
|
+
* currentPage: 0,
|
|
74
|
+
* perPage: 10,
|
|
75
|
+
* onChange: (newPage) => console.log("Page changed to:", newPage),
|
|
76
|
+
* });
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
60
79
|
export const usePagination = ({
|
|
61
80
|
totalRecords,
|
|
62
81
|
currentPage = 0,
|
|
@@ -111,9 +130,12 @@ export const usePagination = ({
|
|
|
111
130
|
|
|
112
131
|
/** ***************** set page *******************/
|
|
113
132
|
useEffect(() => {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
133
|
+
if (totalRecords > -1) {
|
|
134
|
+
const actual = Math.min(currentPage, totalPages - 1);
|
|
135
|
+
setPage(actual);
|
|
136
|
+
actual !== currentPage && onChange?.(actual);
|
|
137
|
+
}
|
|
138
|
+
}, [currentPage, totalRecords, totalPages]);
|
|
117
139
|
|
|
118
140
|
const headLabel = useMemo(
|
|
119
141
|
() => (
|
|
@@ -126,10 +148,13 @@ export const usePagination = ({
|
|
|
126
148
|
[page, perPage, totalRecords],
|
|
127
149
|
);
|
|
128
150
|
|
|
129
|
-
const onPageChange = useCallback(
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
151
|
+
const onPageChange = useCallback(
|
|
152
|
+
(page: number) => {
|
|
153
|
+
setPage(page);
|
|
154
|
+
startTransition(() => onChange?.(page));
|
|
155
|
+
},
|
|
156
|
+
[onChange],
|
|
157
|
+
);
|
|
133
158
|
|
|
134
159
|
return { page, totalPages, headLabel, ranges, onPageChange };
|
|
135
160
|
};
|
|
@@ -46,6 +46,35 @@ export interface SelectableProps {
|
|
|
46
46
|
onClick?: (id: string, isNegative: boolean) => void;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Custom hook to manage selection of items in a list.
|
|
51
|
+
* It allows toggling selection state of items, handling both selected and non-selected states.
|
|
52
|
+
* The hook maintains a selection state and provides a function to toggle the selection of items.
|
|
53
|
+
* It also supports callbacks for when the selection changes or when an item is clicked.
|
|
54
|
+
*
|
|
55
|
+
* @param items - The list of items to manage selection for.
|
|
56
|
+
* @param selected - An array of item IDs that are currently selected.
|
|
57
|
+
* @param nonselected - An array of item IDs that are currently non-selected.
|
|
58
|
+
* @param onChange - Callback function that is called when the selection changes.
|
|
59
|
+
* @param onClick - Callback function that is called when an item is clicked.
|
|
60
|
+
* @returns An object containing the current selection state and a function to toggle selection of items.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```jsx
|
|
64
|
+
* const { selection, toggleSelection } = useSelectableList({
|
|
65
|
+
* items: [{ id: '1', label: 'Item 1' }, { id: '2', label: 'Item 2' }],
|
|
66
|
+
* selected: ['1'],
|
|
67
|
+
* nonselected: ['2'],
|
|
68
|
+
* onChange: (selectedIds, nonSelectedIds) => {
|
|
69
|
+
* console.log('Selected:', selectedIds);
|
|
70
|
+
* console.log('Non-selected:', nonSelectedIds);
|
|
71
|
+
* },
|
|
72
|
+
* onClick: (id, isNegative) => {
|
|
73
|
+
* console.log(`Item ${id} clicked, isNegative: ${isNegative}`);
|
|
74
|
+
* },
|
|
75
|
+
* });
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
49
78
|
export const useSelectableList = ({
|
|
50
79
|
items,
|
|
51
80
|
selected,
|
package/src/i18n/ar.json
CHANGED