@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.
Files changed (104) hide show
  1. package/{src/histogram/Histogram.module.css → css/_histogram.css} +16 -13
  2. package/{dist/esm/tree/types.js → css/styles.css} +2 -7
  3. package/dist/cjs/checklist/CheckList.js +27 -4
  4. package/dist/cjs/histogram/Histogram.js +39 -9
  5. package/dist/cjs/hooks/useFilteredList.js +88 -10
  6. package/dist/cjs/hooks/usePagination.js +27 -4
  7. package/dist/cjs/hooks/useSelectableList.js +29 -0
  8. package/dist/cjs/i18n/ar.json.js +8 -1
  9. package/dist/cjs/i18n/en.json.js +8 -1
  10. package/dist/cjs/json/JsonViewer.js +68 -28
  11. package/dist/cjs/pagination/Pagination.js +14 -4
  12. package/dist/cjs/table/AddColumn.js +3 -3
  13. package/dist/cjs/table/BodyCell.js +14 -6
  14. package/dist/cjs/table/BodyRow.js +4 -4
  15. package/dist/cjs/table/CheckboxCell.js +2 -2
  16. package/dist/cjs/table/ColumnFilters.js +97 -0
  17. package/dist/cjs/table/HeaderCell.js +71 -43
  18. package/dist/cjs/table/Table.js +62 -13
  19. package/dist/cjs/table/types.js +29 -0
  20. package/dist/cjs/table/useResizer.js +4 -4
  21. package/dist/cjs/table/useVirtualTable.js +127 -19
  22. package/dist/cjs/tree/TreeNode.js +50 -32
  23. package/dist/cjs/tree/TreePanel.js +52 -19
  24. package/dist/cjs/tree/useTree.js +199 -38
  25. package/dist/cjs/tree/utils.js +39 -12
  26. package/dist/cjs/virtual/Gallery.js +97 -45
  27. package/dist/cjs/virtual/List.js +93 -39
  28. package/dist/cjs/virtual/Scroller.js +16 -8
  29. package/dist/esm/checklist/CheckList.js +28 -5
  30. package/dist/esm/histogram/Histogram.js +41 -11
  31. package/dist/esm/hooks/useFilteredList.js +89 -11
  32. package/dist/esm/hooks/usePagination.js +27 -4
  33. package/dist/esm/hooks/useSelectableList.js +29 -0
  34. package/dist/esm/i18n/ar.json.js +8 -2
  35. package/dist/esm/i18n/en.json.js +8 -2
  36. package/dist/esm/json/JsonViewer.js +69 -29
  37. package/dist/esm/pagination/Pagination.js +15 -5
  38. package/dist/esm/table/AddColumn.js +4 -4
  39. package/dist/esm/table/BodyCell.js +15 -7
  40. package/dist/esm/table/BodyRow.js +4 -4
  41. package/dist/esm/table/CheckboxCell.js +3 -3
  42. package/dist/esm/table/ColumnFilters.js +97 -0
  43. package/dist/esm/table/HeaderCell.js +72 -44
  44. package/dist/esm/table/Table.js +63 -14
  45. package/dist/esm/table/types.js +29 -0
  46. package/dist/esm/table/useResizer.js +4 -4
  47. package/dist/esm/table/useVirtualTable.js +129 -21
  48. package/dist/esm/tree/TreeNode.js +53 -35
  49. package/dist/esm/tree/TreePanel.js +54 -21
  50. package/dist/esm/tree/useTree.js +202 -41
  51. package/dist/esm/tree/utils.js +40 -13
  52. package/dist/esm/virtual/Gallery.js +97 -45
  53. package/dist/esm/virtual/List.js +93 -39
  54. package/dist/esm/virtual/Scroller.js +17 -9
  55. package/dist/types/checklist/CheckList.d.ts +22 -0
  56. package/dist/types/histogram/Histogram.d.ts +28 -1
  57. package/dist/types/hooks/useFilteredList.d.ts +66 -5
  58. package/dist/types/hooks/usePagination.d.ts +19 -0
  59. package/dist/types/hooks/useSelectableList.d.ts +29 -0
  60. package/dist/types/json/JsonViewer.d.ts +27 -2
  61. package/dist/types/pagination/Pagination.d.ts +10 -1
  62. package/dist/types/table/ColumnFilters.d.ts +9 -0
  63. package/dist/types/table/HeaderCell.d.ts +1 -1
  64. package/dist/types/table/Table.d.ts +14 -1
  65. package/dist/types/table/types.d.ts +46 -7
  66. package/dist/types/table/useVirtualTable.d.ts +23 -9
  67. package/dist/types/tree/TreeNode.d.ts +1 -1
  68. package/dist/types/tree/TreePanel.d.ts +42 -1
  69. package/dist/types/tree/types.d.ts +65 -21
  70. package/dist/types/tree/useTree.d.ts +9 -10
  71. package/dist/types/tree/utils.d.ts +10 -3
  72. package/dist/types/virtual/Gallery.d.ts +42 -3
  73. package/dist/types/virtual/List.d.ts +42 -3
  74. package/package.json +16 -14
  75. package/src/checklist/CheckList.tsx +39 -7
  76. package/src/histogram/Histogram.tsx +43 -19
  77. package/src/hooks/useFilteredList.tsx +109 -9
  78. package/src/hooks/usePagination.tsx +32 -7
  79. package/src/hooks/useSelectableList.ts +29 -0
  80. package/src/i18n/ar.json +5 -0
  81. package/src/i18n/en.json +5 -0
  82. package/src/json/JsonViewer.tsx +76 -37
  83. package/src/pagination/Pagination.tsx +15 -5
  84. package/src/table/AddColumn.tsx +4 -4
  85. package/src/table/BodyCell.tsx +24 -7
  86. package/src/table/BodyRow.tsx +7 -4
  87. package/src/table/CheckboxCell.tsx +5 -5
  88. package/src/table/ColumnFilters.tsx +105 -0
  89. package/src/table/HeaderCell.tsx +74 -21
  90. package/src/table/Table.tsx +107 -12
  91. package/src/table/types.ts +49 -10
  92. package/src/table/useResizer.ts +5 -3
  93. package/src/table/useVirtualTable.ts +158 -27
  94. package/src/tree/TreeNode.tsx +96 -62
  95. package/src/tree/TreePanel.tsx +88 -22
  96. package/src/tree/types.ts +73 -23
  97. package/src/tree/useTree.ts +220 -44
  98. package/src/tree/utils.ts +58 -20
  99. package/src/virtual/Gallery.tsx +118 -54
  100. package/src/virtual/List.tsx +99 -39
  101. package/src/virtual/Scroller.tsx +25 -9
  102. package/dist/cjs/histogram/Histogram.module.css +0 -1
  103. package/dist/cjs/tree/types.js +0 -30
  104. 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
- data: T;
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 KeyValue<any>>({ items, children, columns, padding, defaultHeight: height, defaultWidth: width, hideScroller, initialScroll, loading, onLoadMore, onScroll, galleryRef, ...aria }: VirtualGalleryProps<T>): import("react/jsx-runtime").JSX.Element;
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
- data: T;
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?: (page?: number) => void;
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 KeyValue<any>>({ items, children, fullWidth, padding, orientation, defaultHeight: height, defaultWidth: width, hideScroller, initialScroll, loading, onLoadMore, onScroll, listRef, ...aria }: VirtualListProps<T>): import("react/jsx-runtime").JSX.Element;
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.6",
3
+ "version": "1.0.0-beta.61",
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.6",
37
- "@react-fabric/date": "^1.0.0-beta.6",
38
- "@react-fabric/form": "^1.0.0-beta.6",
39
- "@react-fabric/utilities": "^1.0.0-beta.6",
40
- "@tanstack/react-virtual": "^3.8.6",
41
- "classnames": "^2.5.1",
42
- "color": "^4.2.3",
43
- "memoize-one": "^6.0.0"
38
+ "@react-fabric/core": "^1.0.0-beta.61",
39
+ "@react-fabric/date": "^1.0.0-beta.61",
40
+ "@react-fabric/form": "^1.0.0-beta.61",
41
+ "@react-fabric/utilities": "^1.0.0-beta.61",
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": "^23.15.1",
47
- "react": ">=18.0.0 <20.0.0",
48
- "react-dom": ">=18.0.0 <20.0.0",
49
- "react-i18next": "^15.0.2"
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": "21167df13cedeae8b365e87b9bab6d7401298cb6"
57
+ "gitHead": "a0b0c571bf9c189fa3355bbc3b896ecc4b9d6a04"
56
58
  }
@@ -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 { Badge, CoreIcons, EmptyContent, Icon } from "@react-fabric/core";
24
+ import { Badge, EmptyContent, Icon } from "@react-fabric/core";
25
25
  import {
26
26
  type BadgeType,
27
27
  type TestProps,
@@ -106,7 +106,11 @@ const CheckItem: FC<
106
106
  data-type="checkbox"
107
107
  className="ax-checkList__checkbox"
108
108
  data-selected={selected === 1}
109
- icon={selected ? CoreIcons.checkboxInt : CoreIcons.checkboxOff}
109
+ icon={
110
+ selected
111
+ ? "icon-[mdi--checkbox-marked]"
112
+ : "icon-[mdi--checkbox-blank-outline]"
113
+ }
110
114
  />
111
115
  )}
112
116
  {allowNegative && (
@@ -116,10 +120,10 @@ const CheckItem: FC<
116
120
  className="ax-checkList__checkbox"
117
121
  icon={
118
122
  selected === 1
119
- ? CoreIcons.expand
123
+ ? "icon-[mdi--plus-box-outline]"
120
124
  : selected === -1
121
- ? CoreIcons.collapse
122
- : CoreIcons.checkboxOff
125
+ ? "icon-[mdi--minus-box-outline]"
126
+ : "icon-[mdi--checkbox-blank-outline]"
123
127
  }
124
128
  data-selected={selected}
125
129
  />
@@ -127,14 +131,20 @@ const CheckItem: FC<
127
131
  <Icon
128
132
  data-type="positive"
129
133
  onClick={(e) => [(onClick(id, false), e.stopPropagation())]}
130
- icon={selected === 1 ? CoreIcons.expandActive : CoreIcons.expand}
134
+ icon={
135
+ selected === 1
136
+ ? "icon-[mdi--plus-box]"
137
+ : "icon-[mdi--plus-box-outline]"
138
+ }
131
139
  data-selected={selected === 1}
132
140
  />
133
141
  <Icon
134
142
  data-type="negative"
135
143
  onClick={(e) => [(onClick(id, true), e.stopPropagation())]}
136
144
  icon={
137
- selected === -1 ? CoreIcons.collapseActive : CoreIcons.collapse
145
+ selected === -1
146
+ ? "icon-[mdi--minus-box]"
147
+ : "icon-[mdi--minus-box-outline]"
138
148
  }
139
149
  data-selected={selected === -1}
140
150
  />
@@ -149,6 +159,28 @@ const CheckItem: FC<
149
159
  );
150
160
  };
151
161
 
162
+ /**
163
+ * CheckList component to display a list of selectable items with checkboxes.
164
+ * It supports selection, deselection, and allows for negative selections.
165
+ *
166
+ * @param {CheckListProps} props - The properties for the CheckList component.
167
+ * @returns {JSX.Element} The rendered CheckList component.
168
+ *
169
+ * @example
170
+ * ```jsx
171
+ * <CheckList
172
+ * items={[
173
+ * { id: "1", label: "Item 1", icon: "icon1" },
174
+ * { id: "2", label: "Item 2", icon: "icon2", badge: { text: "New" } },
175
+ * ]}
176
+ * maxCount={5}
177
+ * allowNegative={true}
178
+ * emptyMessage="No items available"
179
+ * onChange={(selectedItems) => console.log(selectedItems)}
180
+ * onClick={(itemId, isNegative) => console.log(itemId, isNegative)}
181
+ * />
182
+ * ```
183
+ */
152
184
  export const CheckList: FC<CheckListProps> = ({
153
185
  items = [],
154
186
  maxCount = 0,
@@ -21,23 +21,16 @@
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 {
25
- ActionLabel,
26
- Button,
27
- CoreIcons,
28
- EmptyContent,
29
- Icon,
30
- } from "@react-fabric/core";
24
+ import { ActionLabel, Button, EmptyContent, Icon } from "@react-fabric/core";
31
25
  import {
32
26
  type ColorType,
33
27
  type PaletteType,
34
28
  type TestProps,
35
29
  } from "@react-fabric/core/dist/types/types";
36
- import { compareValues, Format } from "@react-fabric/utilities";
30
+ import { compareValues, Format, isColor } from "@react-fabric/utilities";
37
31
  import classNames from "classnames";
38
32
  import { useMemo } from "react";
39
33
  import { useTranslation } from "react-i18next";
40
- import classes from "./Histogram.module.css";
41
34
 
42
35
  const emptyIcon =
43
36
  "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 +74,38 @@ export interface HistogramProps extends TestProps {
81
74
  onClick?: (id: string, negative?: true) => void;
82
75
  }
83
76
 
77
+ /**
78
+ * Histogram component displays a bar chart of items with counts.
79
+ * It allows users to visualize the distribution of counts across different items.
80
+ * The component supports sorting, custom colors, and click handling for each item.
81
+ * It also provides an empty state when there are no items to display.
82
+ *
83
+ * @param {HistogramProps} props - The properties for the Histogram component.
84
+ * @returns {JSX.Element} - The rendered Histogram component.
85
+ *
86
+ * @example
87
+ * ```jsx
88
+ * <Histogram
89
+ * items={[
90
+ * { id: "1", label: "Item 1", count: 10 },
91
+ * { id: "2", label: "Item 2", count: 20 },
92
+ * { id: "3", label: "Item 3", count: 5, disabled: true },
93
+ * ]}
94
+ * total={30}
95
+ * color="primary-500"
96
+ * sortBy="count"
97
+ * emptyTitle="No Data Available"
98
+ * emptyMessage="Please check back later."
99
+ * onClick={(id, negative) => console.log(`Clicked on ${id}`, negative ? "Negative" : "Positive")}
100
+ * />
101
+ * ```
102
+ *
103
+ * @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/data-histogram--docs}
104
+ */
84
105
  export const Histogram = ({
85
106
  items = [],
86
107
  total,
87
- color = "primary",
108
+ color = "primary-500",
88
109
  sortBy = "count",
89
110
  emptyTitle,
90
111
  emptyMessage,
@@ -105,11 +126,11 @@ export const Histogram = ({
105
126
 
106
127
  return (
107
128
  <div
108
- className={classes.histogram}
129
+ className={"fabric-histogram from-0% to-100%"}
109
130
  {...aria}
110
131
  style={
111
132
  {
112
- "--color": `var(--${color})`,
133
+ "--color": isColor(color) ? color : `var(--color-${color})`,
113
134
  } as AnyObject
114
135
  }
115
136
  >
@@ -127,16 +148,17 @@ export const Histogram = ({
127
148
  data-disabled={item.count === 0 || item.disabled}
128
149
  className={classNames(
129
150
  "relative cursor-pointer flex flex-nowrap items-center select-none overflow-hidden min-h-6 my-px",
130
- classes.histoLabel,
131
- (item.count === 0 || item.disabled) && "pointer-events-none",
151
+ "fabric-histoLabel",
152
+ ((item.total ?? item.count) === 0 || item.disabled) &&
153
+ "pointer-events-none",
132
154
  )}
133
155
  data-testid={item.id}
134
156
  onClick={(e) => [onClick?.(item.id), e.stopPropagation()]}
135
157
  >
136
158
  <div
137
159
  className={classNames(
138
- "absolute z-0 inset-0 opacity-50 min-w-2 ltr:bg-gradient-to-r rtl:bg-gradient-to-l from-0% to-100%",
139
- classes.histoBar,
160
+ "absolute z-0 inset-0 opacity-50 min-w-2 ltr:bg-linear-to-r rtl:bg-linear-to-l",
161
+ "fabric-histoBar",
140
162
  )}
141
163
  style={{
142
164
  width: `${Math.min(item.count / maxTotal, 1) * 100}%`,
@@ -149,7 +171,8 @@ export const Histogram = ({
149
171
  key="negative"
150
172
  color="danger"
151
173
  size="sm"
152
- icon={CoreIcons.funnelMinus}
174
+ stopPropagation
175
+ icon="icon-[mdi--filter-minus]"
153
176
  aria-label="Filter Negative"
154
177
  onClick={() => onClick?.(item.id, true)}
155
178
  />,
@@ -157,7 +180,8 @@ export const Histogram = ({
157
180
  key="positive"
158
181
  color="primary"
159
182
  size="sm"
160
- icon={CoreIcons.funnelPlus}
183
+ stopPropagation
184
+ icon="icon-[mdi--filter-plus]"
161
185
  aria-label="Filter"
162
186
  onClick={() => onClick?.(item.id)}
163
187
  />,
@@ -168,7 +192,7 @@ export const Histogram = ({
168
192
  <span
169
193
  className={classNames(
170
194
  "z-1 rounded-full text-xs font-medium px-2 py-1 leading-none",
171
- classes.histoBadge,
195
+ "fabric-histoBadge",
172
196
  )}
173
197
  >
174
198
  {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 && isString(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
- export const useFilteredList = <
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(() => setFilteredList(filterList(items, query, matcher))),
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
- setPage(Math.min(currentPage, totalPages - 1));
115
- onChange?.(Math.min(currentPage, totalPages - 1));
116
- }, [currentPage, totalPages]);
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((page: number) => {
130
- setPage(page);
131
- startTransition(() => onChange?.(page));
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,