@react-fabric/data 1.0.0-beta.61 → 1.0.0-beta.63

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 (76) hide show
  1. package/dist/cjs/checklist/CheckList.js +1 -1
  2. package/dist/cjs/histogram/Histogram.js +1 -1
  3. package/dist/cjs/i18n/index.js +4 -4
  4. package/dist/cjs/index.js +2 -0
  5. package/dist/cjs/json/JsonViewer.js +8 -8
  6. package/dist/cjs/pagination/Pagination.js +8 -8
  7. package/dist/cjs/table/BodyCell.js +2 -2
  8. package/dist/cjs/table/EmptyCell.js +2 -2
  9. package/dist/cjs/table/HeaderCell.js +6 -6
  10. package/dist/cjs/table/HtmlTable.js +78 -0
  11. package/dist/cjs/table/{Context.js → Provider.js} +2 -6
  12. package/dist/cjs/table/Table.js +4 -4
  13. package/dist/cjs/table/context.js +34 -0
  14. package/dist/cjs/table/useResizer.js +6 -4
  15. package/dist/cjs/tree/utils.js +13 -15
  16. package/dist/cjs/virtual/Gallery.js +2 -2
  17. package/dist/cjs/virtual/List.js +3 -3
  18. package/dist/esm/checklist/CheckList.js +1 -1
  19. package/dist/esm/histogram/Histogram.js +1 -1
  20. package/dist/esm/i18n/index.js +2 -2
  21. package/dist/esm/index.js +1 -0
  22. package/dist/esm/json/JsonViewer.js +8 -8
  23. package/dist/esm/pagination/Pagination.js +8 -8
  24. package/dist/esm/table/BodyCell.js +1 -1
  25. package/dist/esm/table/EmptyCell.js +1 -1
  26. package/dist/esm/table/HeaderCell.js +5 -5
  27. package/dist/esm/table/HtmlTable.js +78 -0
  28. package/dist/esm/table/{Context.js → Provider.js} +3 -6
  29. package/dist/esm/table/Table.js +3 -3
  30. package/dist/esm/table/context.js +33 -0
  31. package/dist/esm/table/useResizer.js +6 -4
  32. package/dist/esm/tree/useTree.js +12 -12
  33. package/dist/esm/tree/utils.js +11 -13
  34. package/dist/esm/virtual/Gallery.js +2 -2
  35. package/dist/esm/virtual/List.js +3 -3
  36. package/dist/types/checklist/CheckList.d.ts +1 -1
  37. package/dist/types/histogram/Histogram.d.ts +3 -3
  38. package/dist/types/index.d.ts +1 -0
  39. package/dist/types/json/JsonViewer.d.ts +2 -2
  40. package/dist/types/pagination/Pagination.d.ts +1 -1
  41. package/dist/types/table/BodyCell.d.ts +1 -1
  42. package/dist/types/table/EmptyCell.d.ts +1 -1
  43. package/dist/types/table/HtmlTable.d.ts +21 -0
  44. package/dist/types/table/{Context.d.ts → Provider.d.ts} +0 -6
  45. package/dist/types/table/Table.d.ts +1 -1
  46. package/dist/types/table/context.d.ts +7 -0
  47. package/dist/types/table/useVirtualTable.d.ts +1 -1
  48. package/dist/types/tree/TreePanel.d.ts +1 -1
  49. package/dist/types/tree/types.d.ts +6 -6
  50. package/dist/types/virtual/Gallery.d.ts +1 -1
  51. package/dist/types/virtual/List.d.ts +1 -1
  52. package/package.json +13 -14
  53. package/src/checklist/CheckList.tsx +1 -1
  54. package/src/histogram/Histogram.tsx +3 -3
  55. package/src/i18n/index.ts +2 -2
  56. package/src/index.ts +1 -0
  57. package/src/json/JsonViewer.tsx +2 -2
  58. package/src/pagination/Pagination.tsx +8 -8
  59. package/src/table/BodyCell.tsx +6 -31
  60. package/src/table/EmptyCell.tsx +4 -17
  61. package/src/table/HeaderCell.tsx +9 -41
  62. package/src/table/HtmlTable.tsx +128 -0
  63. package/src/table/{Context.tsx → Provider.tsx} +3 -20
  64. package/src/table/Table.tsx +4 -4
  65. package/src/table/context.ts +33 -0
  66. package/src/table/useResizer.ts +6 -4
  67. package/src/tree/TreePanel.tsx +1 -1
  68. package/src/tree/types.ts +6 -6
  69. package/src/virtual/Gallery.tsx +2 -2
  70. package/src/virtual/List.tsx +3 -3
  71. /package/dist/cjs/i18n/{ar.json.js → ar/data.json.js} +0 -0
  72. /package/dist/cjs/i18n/{en.json.js → en/data.json.js} +0 -0
  73. /package/dist/esm/i18n/{ar.json.js → ar/data.json.js} +0 -0
  74. /package/dist/esm/i18n/{en.json.js → en/data.json.js} +0 -0
  75. /package/src/i18n/{ar.json → ar/data.json} +0 -0
  76. /package/src/i18n/{en.json → en/data.json} +0 -0
@@ -0,0 +1,128 @@
1
+ /*
2
+ * React Fabric
3
+ * @version: 1.0.0
4
+ *
5
+ *
6
+ * The MIT License (MIT)
7
+ * Copyright (c) 2026 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 { Footer } from "@react-fabric/core";
25
+ import { getByPath } from "@react-fabric/utilities";
26
+ import classNames from "classnames";
27
+ import { useMemo } from "react";
28
+ import { usePagination } from "../hooks/usePagination";
29
+ import { Pagination } from "../pagination/Pagination";
30
+
31
+ interface Props<T = KeyValue> {
32
+ data: T[];
33
+ columns: Array<{
34
+ id: keyof T;
35
+ label?: string;
36
+ width?: number | string;
37
+ maxWidth?: number | string;
38
+ align?: "start" | "center" | "end";
39
+ className?: string;
40
+ headRenderer?: React.ReactNode;
41
+ renderer?: (value: any, row: T, index: number) => React.ReactNode;
42
+ }>;
43
+ /**
44
+ * Number of pagination buttons to show, default is 25
45
+ * If set to 0, pagination will be hidden
46
+ */
47
+ paginationSize?: number;
48
+
49
+ className?: string;
50
+ }
51
+
52
+ export const HtmlTable = <T extends KeyValue = KeyValue>({
53
+ data,
54
+ columns,
55
+ paginationSize = 25,
56
+ className,
57
+ }: Props<T>) => {
58
+ const paginator = usePagination({
59
+ totalRecords: data.length,
60
+ perPage: paginationSize,
61
+ });
62
+
63
+ const startIndex = useMemo(
64
+ () => paginator.page * paginationSize,
65
+ [paginator.page, paginationSize],
66
+ );
67
+
68
+ const dataPage = useMemo(
69
+ () =>
70
+ paginationSize > 0
71
+ ? data.slice(startIndex, startIndex + paginationSize)
72
+ : data,
73
+ [data, paginationSize, startIndex],
74
+ );
75
+
76
+ return (
77
+ <div className={className}>
78
+ <table className="table-fixed border-spacing-1 border-separate w-full text-sm">
79
+ <thead className="sticky top-0 z-1">
80
+ <tr>
81
+ {columns.map((col, idx) => (
82
+ <th
83
+ key={idx}
84
+ className="text-start truncate bg-accent-100 px-2 py-1 font-medium text-accent-800"
85
+ style={{ width: col.width, maxWidth: col.maxWidth }}
86
+ >
87
+ {col.headRenderer ?? col.label ?? " "}
88
+ </th>
89
+ ))}
90
+ </tr>
91
+ </thead>
92
+ <tbody className="bg-alternate">
93
+ {dataPage.map((row, idx) => (
94
+ <tr key={idx}>
95
+ {columns.map((col, cidx) => (
96
+ <td
97
+ key={`${idx}-${cidx}`}
98
+ className={classNames(
99
+ "px-2 py-1 truncate",
100
+ col.align === "center" && "text-center",
101
+ col.align === "end" && "text-end",
102
+ col.className,
103
+ )}
104
+ style={{ width: col.width, maxWidth: col.maxWidth }}
105
+ >
106
+ {col.renderer?.(
107
+ getByPath(row, col.id.toString()),
108
+ row,
109
+ startIndex + idx,
110
+ ) ?? getByPath(row, col.id.toString())}
111
+ </td>
112
+ ))}
113
+ </tr>
114
+ ))}
115
+ </tbody>
116
+ </table>
117
+ {paginationSize > 0 && (
118
+ <Footer
119
+ flex
120
+ justify="end"
121
+ className="px-2 py-1 sticky bottom-0 bg-tint-50"
122
+ >
123
+ <Pagination minimal {...paginator} />
124
+ </Footer>
125
+ )}
126
+ </div>
127
+ );
128
+ };
@@ -22,22 +22,10 @@
22
22
  */
23
23
 
24
24
  import { type ChildrenProp } from "@react-fabric/core/dist/types/types";
25
- import {
26
- createContext,
27
- useCallback,
28
- useContext,
29
- useRef,
30
- useState,
31
- } from "react";
25
+ import { useCallback, useRef, useState } from "react";
26
+ import { TableContext } from "./context";
32
27
  import { useResizer } from "./useResizer";
33
28
 
34
- interface Context {
35
- widths: Map<string, number>;
36
- startResize: (col: HTMLElement) => void;
37
- }
38
-
39
- const TableContext = createContext<Context>({} as Context);
40
-
41
29
  export const TableProvider = ({ children }: ChildrenProp) => {
42
30
  const ghostRef = useRef<HTMLDivElement>(null);
43
31
  const [widths, setWidths] = useState<Map<string, number>>(new Map());
@@ -57,14 +45,9 @@ export const TableProvider = ({ children }: ChildrenProp) => {
57
45
  <TableContext.Provider value={{ startResize, widths }}>
58
46
  {children}
59
47
 
60
- <div
61
- className="absolute inset-0 hidden z-20 cursor-col-resize"
62
- ref={ghostRef}
63
- >
48
+ <div className="absolute inset-0 hidden z-20 cursor-col-resize" ref={ghostRef}>
64
49
  <div className="absolute inset-y-0 bg-muted opacity-50 border-primary border-e-2" />
65
50
  </div>
66
51
  </TableContext.Provider>
67
52
  );
68
53
  };
69
-
70
- export const useTableContext = () => useContext(TableContext);
@@ -40,7 +40,7 @@ import { useTranslation } from "react-i18next";
40
40
  import { AddColumn } from "./AddColumn";
41
41
  import { BodyRow } from "./BodyRow";
42
42
  import { CheckboxCell } from "./CheckboxCell";
43
- import { TableProvider } from "./Context";
43
+ import { TableProvider } from "./Provider";
44
44
  import { EmptyCell } from "./EmptyCell";
45
45
  import { HeaderCell } from "./HeaderCell";
46
46
  import { type TableProps } from "./types";
@@ -55,7 +55,7 @@ import { useVirtualTable } from "./useVirtualTable";
55
55
  * Uses TanStack's `useVirtual` for virtualization and React's `useMemo` for performance optimization.
56
56
  *
57
57
  * @param {TableProps<T>} props - The properties for the Table component.
58
- * @returns {JSX.Element} The rendered Table component.
58
+ * @returns {React.ReactElement} The rendered Table component.
59
59
  *
60
60
  * @see {@link https://adarshpastakia.github.io/react-fabric/?path=/story/data-table--table}
61
61
  * @see {@link https://tanstack.com/table/v8/docs/api/virtual}
@@ -183,7 +183,7 @@ export const Table = <T extends KeyValue = KeyValue>({
183
183
  >
184
184
  <div
185
185
  data-ref="tableHeader"
186
- className="bg-base font-medium sticky top-0 h-8 area-head border-b select-none flex flex-nowrap z-3"
186
+ className="bg-default font-medium sticky top-0 h-8 area-head border-b select-none flex flex-nowrap z-3"
187
187
  >
188
188
  <div className={wrapperStart}>
189
189
  {canExpand && <div className="w-6" />}
@@ -251,7 +251,7 @@ export const Table = <T extends KeyValue = KeyValue>({
251
251
  ref={measureElement}
252
252
  data-index={index}
253
253
  className={classNames(
254
- "text-md bg-base border-y border-tint-100 border-t-0 cursor-pointer flex items-center justify-start gap-1 z-2",
254
+ "text-md bg-default border-y border-tint-100 border-t-0 cursor-pointer flex items-center justify-start gap-1 z-2",
255
255
  isActiveSticky(index) && "sticky top-8",
256
256
  )}
257
257
  role="none"
@@ -0,0 +1,33 @@
1
+ /*
2
+ * React Fabric
3
+ * @version: 1.0.0
4
+ *
5
+ *
6
+ * The MIT License (MIT)
7
+ * Copyright (c) 2026 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 { createContext, useContext } from "react";
25
+
26
+ interface Context {
27
+ widths: Map<string, number>;
28
+ startResize: (col: HTMLElement) => void;
29
+ }
30
+
31
+ export const TableContext = createContext<Context>({} as Context);
32
+
33
+ export const useTableContext = () => useContext(TableContext);
@@ -21,6 +21,8 @@
21
21
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  */
23
23
 
24
+ import { useCallback } from "react";
25
+
24
26
  export const useResizer = (
25
27
  colEl: HTMLElement,
26
28
  ghostEl: HTMLElement,
@@ -29,20 +31,20 @@ export const useResizer = (
29
31
  const placeholder = ghostEl.firstElementChild as HTMLElement;
30
32
  const isRtl = getComputedStyle(colEl).direction === "rtl";
31
33
 
32
- const onResize = (evt: MouseEvent) => {
34
+ const onResize = useCallback((evt: MouseEvent) => {
33
35
  /** ***************** check if reverse enabled of RTL *******************/
34
36
  const box = colEl.getBoundingClientRect();
35
37
  const x = isRtl ? box.left - evt.clientX : evt.clientX - box.right;
36
38
  placeholder.style.width = `${colEl.offsetWidth + x}px`;
37
- };
39
+ }, [colEl, isRtl, placeholder]);
38
40
 
39
41
  /** ***************** dettach handlers on mouseup *******************/
40
- const onResizeEnd = () => {
42
+ const onResizeEnd = useCallback(() => {
41
43
  callback(placeholder.offsetWidth);
42
44
  ghostEl.style.display = "none";
43
45
  document.removeEventListener("mousemove", onResize);
44
46
  document.removeEventListener("mouseup", onResizeEnd);
45
- };
47
+ }, [callback, placeholder, ghostEl]);
46
48
 
47
49
  /** ***************** attach handlers *******************/
48
50
  const box = colEl.getBoundingClientRect();
@@ -37,7 +37,7 @@ import { useTree } from "./useTree";
37
37
  * nodes and supports checkable nodes.
38
38
  *
39
39
  * @param {TreePanelProps<T>} props - The properties for the TreePanel component.
40
- * @returns {JSX.Element} The rendered TreePanel component.
40
+ * @returns {React.ReactElement} The rendered TreePanel component.
41
41
  * @template T - The type of items in the tree, extending KeyValue.
42
42
  *
43
43
  * @example
package/src/tree/types.ts CHANGED
@@ -36,7 +36,7 @@ interface TreeBaseNode<T> extends CssProp, TestProps {
36
36
  /**
37
37
  * display label
38
38
  */
39
- label: Elements<JSX.Element>;
39
+ label: Elements<React.ReactElement>;
40
40
  /**
41
41
  * icon path or props
42
42
  */
@@ -73,7 +73,7 @@ export type TreeNodeType<T extends KeyValue = KeyValue> = TreeBaseNode<T> &
73
73
 
74
74
  export interface InternalNode extends CssProp, TestProps {
75
75
  id: string;
76
- label: Elements<JSX.Element>;
76
+ label: Elements<React.ReactElement>;
77
77
  queryable?: string;
78
78
  badge?: string | number | BadgeType;
79
79
  disabled?: boolean;
@@ -101,8 +101,8 @@ export interface InternalNode extends CssProp, TestProps {
101
101
  export interface TreeNodeProps extends ChildProp {
102
102
  node: InternalNode;
103
103
  expanders: [string, string];
104
- defaultNodeIcon?: Elements<JSX.Element>;
105
- defaultLeafIcon?: Elements<JSX.Element>;
104
+ defaultNodeIcon?: Elements<React.ReactElement>;
105
+ defaultLeafIcon?: Elements<React.ReactElement>;
106
106
  noLines?: boolean;
107
107
  selectable?: true | "leafOnly";
108
108
  checkable?: true | "leafOnly";
@@ -227,8 +227,8 @@ interface BaseTreePanelProps<T extends KeyValue = KeyValue>
227
227
  matcher?: (data: T, query: string) => boolean;
228
228
 
229
229
  sorter?: false | ((a: T, b: T) => number);
230
- makeLabel?: (node: T) => Elements<JSX.Element>;
231
- makeIcon?: (node: T) => Elements<JSX.Element>;
230
+ makeLabel?: (node: T) => Elements<React.ReactElement>;
231
+ makeIcon?: (node: T) => Elements<React.ReactElement>;
232
232
 
233
233
  defaultExpanded?: string[];
234
234
  onExpandToggle?: (id: string[]) => void;
@@ -293,7 +293,7 @@ const _VirtualGallery = <T extends AnyObject>({
293
293
  <div
294
294
  ref={scrollerRef}
295
295
  onScroll={handleScroll}
296
- className={classNames("area-content bg-base overflow-auto")}
296
+ className={classNames("area-content bg-default overflow-auto")}
297
297
  {...aria}
298
298
  >
299
299
  <div
@@ -388,7 +388,7 @@ const GenericMemo: <T>(c: T) => T = memo;
388
388
  * It also provides a scroller for easy navigation through the items.
389
389
  *
390
390
  * @param {VirtualGalleryProps<T>} props - The properties for the VirtualGallery component.
391
- * @returns {JSX.Element} The rendered VirtualGallery component.
391
+ * @returns {React.ReactElement} The rendered VirtualGallery component.
392
392
  *
393
393
  * @example
394
394
  * ```jsx
@@ -270,7 +270,7 @@ const _VirtualList = <T extends AnyObject>({
270
270
  <div
271
271
  ref={scrollerRef}
272
272
  onScroll={handleScroll}
273
- className={classNames("area-content bg-base overflow-auto")}
273
+ className={classNames("area-content bg-default overflow-auto")}
274
274
  {...aria}
275
275
  >
276
276
  <div
@@ -340,7 +340,7 @@ const _VirtualList = <T extends AnyObject>({
340
340
  <div
341
341
  className={classNames(
342
342
  orientation === "vertical" && "self-end sticky bottom-2",
343
- orientation === "horizontal" && "self-end sticky end-2",
343
+ orientation === "horizontal" && "self-end sticky inset-e-2",
344
344
  )}
345
345
  >
346
346
  <Scroller
@@ -383,7 +383,7 @@ const GenericMemo: <T>(c: T) => T = memo;
383
383
  * It can be used with a ref to control scrolling and hilighting of items.
384
384
  *
385
385
  * @param {VirtualListProps<T>} props - The properties for the VirtualList component.
386
- * @returns {JSX.Element} The rendered VirtualList component.
386
+ * @returns {React.ReactElement} The rendered VirtualList component.
387
387
  * @template T - The type of items in the list, extending AnyObject.
388
388
  *
389
389
  * @example
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes