@react-fabric/data 1.0.0-beta.9 → 1.0.1

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 (141) hide show
  1. package/{src/histogram/Histogram.module.css → css/_histogram.css} +16 -13
  2. package/css/styles.css +24 -0
  3. package/dist/cjs/checklist/CheckList.js +59 -33
  4. package/dist/cjs/histogram/Histogram.js +41 -26
  5. package/dist/cjs/hooks/useFilteredList.js +100 -17
  6. package/dist/cjs/hooks/usePagination.js +29 -8
  7. package/dist/cjs/hooks/useSelectableList.js +30 -5
  8. package/dist/cjs/i18n/{ar.json.js → ar/data.json.js} +8 -1
  9. package/dist/cjs/i18n/{en.json.js → en/data.json.js} +8 -1
  10. package/dist/cjs/i18n/index.js +4 -4
  11. package/dist/cjs/index.js +30 -0
  12. package/dist/cjs/json/JsonViewer.js +80 -43
  13. package/dist/cjs/pagination/Pagination.js +24 -15
  14. package/dist/cjs/table/AddColumn.js +5 -5
  15. package/dist/cjs/table/BodyCell.js +20 -13
  16. package/dist/cjs/table/BodyRow.js +41 -28
  17. package/dist/cjs/table/CheckboxCell.js +10 -9
  18. package/dist/cjs/table/ColumnFilters.js +100 -0
  19. package/dist/cjs/table/EmptyCell.js +4 -4
  20. package/dist/cjs/table/HeaderCell.js +79 -53
  21. package/dist/cjs/table/HtmlTable.js +84 -0
  22. package/dist/cjs/table/{Context.js → Provider.js} +8 -10
  23. package/dist/cjs/table/Table.js +99 -33
  24. package/dist/cjs/{tree/types.js → table/context.js} +9 -5
  25. package/dist/cjs/table/types.js +29 -0
  26. package/dist/cjs/table/useResizer.js +10 -10
  27. package/dist/cjs/table/useTableColumns.js +4 -4
  28. package/dist/cjs/table/useVirtualTable.js +129 -22
  29. package/dist/cjs/tree/TreeNode.js +66 -46
  30. package/dist/cjs/tree/TreePanel.js +60 -24
  31. package/dist/cjs/tree/useTree.js +212 -47
  32. package/dist/cjs/tree/utils.js +63 -34
  33. package/dist/cjs/utils/getColor.js +58 -0
  34. package/dist/cjs/virtual/Gallery.js +119 -61
  35. package/dist/cjs/virtual/List.js +116 -55
  36. package/dist/cjs/virtual/Scroller.js +16 -8
  37. package/dist/esm/checklist/CheckList.js +61 -35
  38. package/dist/esm/histogram/Histogram.js +43 -28
  39. package/dist/esm/hooks/useFilteredList.js +101 -18
  40. package/dist/esm/hooks/usePagination.js +29 -8
  41. package/dist/esm/hooks/useSelectableList.js +30 -5
  42. package/dist/esm/i18n/{ar.json.js → ar/data.json.js} +8 -2
  43. package/dist/esm/i18n/{en.json.js → en/data.json.js} +8 -2
  44. package/dist/esm/i18n/index.js +2 -2
  45. package/dist/esm/index.js +31 -0
  46. package/dist/esm/json/JsonViewer.js +82 -45
  47. package/dist/esm/pagination/Pagination.js +25 -16
  48. package/dist/esm/table/AddColumn.js +6 -6
  49. package/dist/esm/table/BodyCell.js +21 -14
  50. package/dist/esm/table/BodyRow.js +41 -28
  51. package/dist/esm/table/CheckboxCell.js +11 -10
  52. package/dist/esm/table/ColumnFilters.js +100 -0
  53. package/dist/esm/table/EmptyCell.js +4 -4
  54. package/dist/esm/table/HeaderCell.js +80 -54
  55. package/dist/esm/table/HtmlTable.js +84 -0
  56. package/dist/esm/table/{Context.js → Provider.js} +11 -12
  57. package/dist/esm/table/Table.js +100 -34
  58. package/dist/esm/{tree/types.js → table/context.js} +8 -4
  59. package/dist/esm/table/types.js +29 -0
  60. package/dist/esm/table/useResizer.js +10 -10
  61. package/dist/esm/table/useTableColumns.js +4 -4
  62. package/dist/esm/table/useVirtualTable.js +131 -24
  63. package/dist/esm/tree/TreeNode.js +69 -49
  64. package/dist/esm/tree/TreePanel.js +62 -26
  65. package/dist/esm/tree/useTree.js +215 -50
  66. package/dist/esm/tree/utils.js +64 -35
  67. package/dist/esm/utils/getColor.js +58 -0
  68. package/dist/esm/virtual/Gallery.js +121 -63
  69. package/dist/esm/virtual/List.js +118 -57
  70. package/dist/esm/virtual/Scroller.js +17 -9
  71. package/dist/types/checklist/CheckList.d.ts +25 -6
  72. package/dist/types/histogram/Histogram.d.ts +28 -6
  73. package/dist/types/hooks/useFilteredList.d.ts +62 -5
  74. package/dist/types/hooks/usePagination.d.ts +18 -2
  75. package/dist/types/hooks/useSelectableList.d.ts +24 -1
  76. package/dist/types/index.d.ts +27 -0
  77. package/dist/types/json/JsonViewer.d.ts +23 -3
  78. package/dist/types/pagination/Pagination.d.ts +8 -2
  79. package/dist/types/table/AddColumn.d.ts +2 -2
  80. package/dist/types/table/BodyCell.d.ts +2 -2
  81. package/dist/types/table/BodyRow.d.ts +9 -9
  82. package/dist/types/table/CheckboxCell.d.ts +3 -3
  83. package/dist/types/table/ColumnFilters.d.ts +12 -0
  84. package/dist/types/table/EmptyCell.d.ts +1 -1
  85. package/dist/types/table/HeaderCell.d.ts +1 -1
  86. package/dist/types/table/HtmlTable.d.ts +21 -0
  87. package/dist/types/table/Provider.d.ts +2 -0
  88. package/dist/types/table/Table.d.ts +10 -1
  89. package/dist/types/table/context.d.ts +7 -0
  90. package/dist/types/table/types.d.ts +52 -10
  91. package/dist/types/table/useResizer.d.ts +1 -1
  92. package/dist/types/table/useTableColumns.d.ts +1 -1
  93. package/dist/types/table/useVirtualTable.d.ts +31 -12
  94. package/dist/types/tree/TreeNode.d.ts +1 -1
  95. package/dist/types/tree/TreePanel.d.ts +36 -1
  96. package/dist/types/tree/types.d.ts +75 -28
  97. package/dist/types/tree/useTree.d.ts +8 -12
  98. package/dist/types/tree/utils.d.ts +15 -8
  99. package/dist/types/utils/getColor.d.ts +43 -0
  100. package/dist/types/virtual/Gallery.d.ts +37 -6
  101. package/dist/types/virtual/List.d.ts +38 -6
  102. package/dist/types/virtual/Scroller.d.ts +1 -1
  103. package/package.json +17 -19
  104. package/src/checklist/CheckList.tsx +68 -71
  105. package/src/histogram/Histogram.tsx +47 -48
  106. package/src/hooks/useFilteredList.tsx +111 -28
  107. package/src/hooks/usePagination.tsx +39 -39
  108. package/src/hooks/useSelectableList.ts +45 -33
  109. package/src/i18n/{ar.json → ar/data.json} +5 -0
  110. package/src/i18n/{en.json → en/data.json} +5 -0
  111. package/src/i18n/index.ts +2 -2
  112. package/src/index.ts +23 -17
  113. package/src/json/JsonViewer.tsx +89 -120
  114. package/src/pagination/Pagination.tsx +104 -105
  115. package/src/table/AddColumn.tsx +6 -15
  116. package/src/table/BodyCell.tsx +27 -36
  117. package/src/table/BodyRow.tsx +36 -59
  118. package/src/table/CheckboxCell.tsx +12 -15
  119. package/src/table/ColumnFilters.tsx +93 -0
  120. package/src/table/EmptyCell.tsx +5 -18
  121. package/src/table/HeaderCell.tsx +72 -53
  122. package/src/table/HtmlTable.tsx +106 -0
  123. package/src/table/{Context.tsx → Provider.tsx} +11 -28
  124. package/src/table/Table.tsx +98 -83
  125. package/src/table/context.ts +33 -0
  126. package/src/table/types.ts +53 -27
  127. package/src/table/useResizer.ts +5 -9
  128. package/src/table/useTableColumns.ts +4 -6
  129. package/src/table/useVirtualTable.ts +136 -37
  130. package/src/tree/TreeNode.tsx +91 -86
  131. package/src/tree/TreePanel.tsx +87 -51
  132. package/src/tree/types.ts +85 -46
  133. package/src/tree/useTree.ts +210 -65
  134. package/src/tree/utils.ts +81 -62
  135. package/src/utils/getColor.ts +55 -0
  136. package/src/virtual/Gallery.tsx +129 -120
  137. package/src/virtual/List.tsx +124 -91
  138. package/src/virtual/Scroller.tsx +25 -9
  139. package/dist/cjs/histogram/Histogram.module.css +0 -1
  140. package/dist/esm/histogram/Histogram.module.css +0 -1
  141. package/dist/types/table/Context.d.ts +0 -8
@@ -21,8 +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 { CoreIcons, Icon } from "@react-fabric/core";
25
- import classNames from "classnames";
24
+ import { Icon } from "@react-fabric/core";
25
+ import { cn } from "@react-fabric/utilities";
26
26
  import { Fragment, memo, useMemo } from "react";
27
27
 
28
28
  export interface PaginationProps {
@@ -48,110 +48,109 @@ export interface PaginationProps {
48
48
  onPageChange: (page: number) => void;
49
49
  }
50
50
 
51
- export const Pagination = memo(
52
- ({ page, ranges, totalPages, minimal, onPageChange }: PaginationProps) => {
53
- const [start, mid, last] = ranges;
51
+ const PaginationComponent = ({ page, ranges, totalPages, minimal, onPageChange }: PaginationProps) => {
52
+ const [start, mid, last] = ranges;
54
53
 
55
- const pageBody = useMemo(
56
- () => (
57
- <Fragment>
58
- {start?.map((pg) => (
59
- <button
60
- key={pg}
61
- onClick={() => onPageChange(pg)}
62
- className={classNames(
63
- "leading-none text-sm hover:bg-primary-200 w-8 h-6 rounded-full",
64
- page === pg && "bg-primary-500 text-white pointer-events-none",
65
- )}
66
- >
67
- {pg + 1}
68
- </button>
69
- ))}
70
- {mid && (
71
- <span className="leading-none inline-block w-8 text-center text-dimmed">
72
- ...
73
- </span>
74
- )}
75
- {mid?.map((pg) => (
76
- <button
77
- key={pg}
78
- onClick={() => onPageChange(pg)}
79
- className={classNames(
80
- "leading-none text-sm hover:bg-primary-200 w-8 h-6 rounded-full",
81
- page === pg && "bg-primary-500 text-white pointer-events-none",
82
- )}
83
- >
84
- {pg + 1}
85
- </button>
86
- ))}
87
- {last && (
88
- <span className="leading-none inline-block w-8 text-center text-dimmed">
89
- ...
90
- </span>
91
- )}
92
- {last?.map((pg) => (
93
- <button
94
- key={pg}
95
- onClick={() => onPageChange(pg)}
96
- className={classNames(
97
- "leading-none text-sm hover:bg-primary-200 w-8 h-6 rounded-full",
98
- page === pg && "bg-primary-500 text-white pointer-events-none",
99
- )}
100
- >
101
- {pg + 1}
102
- </button>
103
- ))}
104
- </Fragment>
105
- ),
106
- [start, mid, last, page],
107
- );
54
+ const pageBody = useMemo(
55
+ () => (
56
+ <Fragment>
57
+ {start?.map((pg) => (
58
+ <button
59
+ key={pg}
60
+ onClick={() => onPageChange(pg)}
61
+ className={cn(
62
+ "leading-none text-sm hover:bg-primary-200 w-8 h-6 rounded-full cursor-pointer",
63
+ page === pg && "bg-primary-500 text-white pointer-events-none",
64
+ )}
65
+ >
66
+ {pg + 1}
67
+ </button>
68
+ ))}
69
+ {mid && <span className="leading-none inline-block w-8 text-center text-dimmed">...</span>}
70
+ {mid?.map((pg) => (
71
+ <button
72
+ key={pg}
73
+ onClick={() => onPageChange(pg)}
74
+ className={cn(
75
+ "leading-none text-sm hover:bg-primary-200 w-8 h-6 rounded-full cursor-pointer",
76
+ page === pg && "bg-primary-500 text-white pointer-events-none",
77
+ )}
78
+ >
79
+ {pg + 1}
80
+ </button>
81
+ ))}
82
+ {last && <span className="leading-none inline-block w-8 text-center text-dimmed">...</span>}
83
+ {last?.map((pg) => (
84
+ <button
85
+ key={pg}
86
+ onClick={() => onPageChange(pg)}
87
+ className={cn(
88
+ "leading-none text-sm hover:bg-primary-200 w-8 h-6 rounded-full cursor-pointer",
89
+ page === pg && "bg-primary-500 text-white pointer-events-none",
90
+ )}
91
+ >
92
+ {pg + 1}
93
+ </button>
94
+ ))}
95
+ </Fragment>
96
+ ),
97
+ [start, mid, last, page, onPageChange],
98
+ );
108
99
 
109
- return (
110
- <div className="inline-flex items-center">
111
- <button
112
- onClick={() => onPageChange(0)}
113
- className={classNames(
114
- "leading-none text-sm hover:bg-primary-200 w-8 h-6 rounded-full",
115
- page === 0 && "pointer-events-none text-tint-300",
116
- )}
117
- >
118
- <Icon icon={CoreIcons.chevronsLeft} rtlFlip />
119
- </button>
120
- <button
121
- onClick={() => onPageChange(page - 1)}
122
- className={classNames(
123
- "leading-none text-sm hover:bg-primary-200 w-8 h-6 rounded-full",
124
- page === 0 && "pointer-events-none text-tint-300",
125
- )}
126
- >
127
- <Icon icon={CoreIcons.chevronLeft} rtlFlip />
128
- </button>
129
- {!minimal && pageBody}
130
- {minimal && (
131
- <label className="leading-none inline-block px-1 text-center text-sm select-none fixed-numbers">
132
- {page + 1}/{totalPages}
133
- </label>
100
+ return (
101
+ <div className="inline-flex items-center">
102
+ <button
103
+ onClick={() => onPageChange(0)}
104
+ className={cn(
105
+ "leading-none text-sm hover:bg-primary-200 w-8 h-6 rounded-full cursor-pointer",
106
+ page === 0 && "pointer-events-none text-tint-300",
134
107
  )}
135
- <button
136
- onClick={() => onPageChange(page + 1)}
137
- className={classNames(
138
- "leading-none text-sm hover:bg-primary-200 w-8 h-6 rounded-full",
139
- page + 1 >= totalPages && "pointer-events-none text-tint-300",
140
- )}
141
- >
142
- <Icon icon={CoreIcons.chevronRight} rtlFlip />
143
- </button>
144
- <button
145
- onClick={() => onPageChange(totalPages - 1)}
146
- className={classNames(
147
- "leading-none text-sm hover:bg-primary-200 w-8 h-6 rounded-full",
148
- page + 1 >= totalPages && "pointer-events-none text-tint-300",
149
- )}
150
- >
151
- <Icon icon={CoreIcons.chevronsRight} rtlFlip />
152
- </button>
153
- </div>
154
- );
155
- },
156
- );
108
+ >
109
+ <Icon icon="icon-[mdi--chevron-double-left]" rtlFlip />
110
+ </button>
111
+ <button
112
+ onClick={() => onPageChange(page - 1)}
113
+ className={cn(
114
+ "leading-none text-sm hover:bg-primary-200 w-8 h-6 rounded-full cursor-pointer",
115
+ page === 0 && "pointer-events-none text-tint-300",
116
+ )}
117
+ >
118
+ <Icon icon="icon-[mdi--chevron-left]" rtlFlip />
119
+ </button>
120
+ {!minimal && pageBody}
121
+ {minimal && (
122
+ <label className="leading-none inline-block px-1 text-center text-sm select-none fixed-numbers">
123
+ {page + 1}/{totalPages}
124
+ </label>
125
+ )}
126
+ <button
127
+ onClick={() => onPageChange(page + 1)}
128
+ className={cn(
129
+ "leading-none text-sm hover:bg-primary-200 w-8 h-6 rounded-full cursor-pointer",
130
+ page + 1 >= totalPages && "pointer-events-none text-tint-300",
131
+ )}
132
+ >
133
+ <Icon icon="icon-[mdi--chevron-right]" rtlFlip />
134
+ </button>
135
+ <button
136
+ onClick={() => onPageChange(totalPages - 1)}
137
+ className={cn(
138
+ "leading-none text-sm hover:bg-primary-200 w-8 h-6 rounded-full cursor-pointer",
139
+ page + 1 >= totalPages && "pointer-events-none text-tint-300",
140
+ )}
141
+ >
142
+ <Icon icon="icon-[mdi--chevron-double-right]" rtlFlip />
143
+ </button>
144
+ </div>
145
+ );
146
+ };
147
+
148
+ /**
149
+ * Pagination component to navigate through pages of data.
150
+ * It displays buttons for navigating to the first, previous, next, and last pages,
151
+ * as well as buttons for specific page numbers based on the provided ranges.
152
+ * The component supports a minimal view that shows the current page and total pages.
153
+ * It uses memoization to optimize rendering performance.
154
+ */
155
+ export const Pagination = memo(PaginationComponent);
157
156
  Pagination.displayName = "Pagination";
@@ -21,23 +21,14 @@
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 { CoreIcons, Dropdown, Icon, Menu, MenuItem } from "@react-fabric/core";
24
+ import { Dropdown, Icon, Menu, MenuItem } from "@react-fabric/core";
25
25
  import { type TableColumn } from "./types";
26
26
 
27
- export const AddColumn = ({
28
- columns,
29
- onClick,
30
- }: {
31
- columns: TableColumn[];
32
- onClick: (id: string) => void;
33
- }) => {
27
+ export function AddColumn({ columns, onClick }: { columns: TableColumn[]; onClick: (id: string) => void }) {
34
28
  return (
35
- <div className="group font-medium w-6 flex flex-nowrap text-start items-end">
29
+ <div className="group font-medium w-6 flex flex-nowrap text-start items-center">
36
30
  <Dropdown placement="bottom-end">
37
- <Icon
38
- icon={CoreIcons.insert}
39
- className="p-1 rounded-t rounded-b-none hover:outline"
40
- />
31
+ <Icon icon="icon-[mdi--plus-circle-outline]" className="p-1 rounded-t rounded-b-none hover:outline" />
41
32
  <Menu className="text-sm" onClick={onClick}>
42
33
  {columns.map((col) => (
43
34
  <MenuItem
@@ -45,11 +36,11 @@ export const AddColumn = ({
45
36
  id={String(col.id)}
46
37
  data-dropdown-dismiss="false"
47
38
  label={`${col.label ?? String(col.id)}`}
48
- icon={!col.hidden ? CoreIcons.tick : ""}
39
+ icon={!col.hidden ? "icon-[mdi--check]" : ""}
49
40
  />
50
41
  ))}
51
42
  </Menu>
52
43
  </Dropdown>
53
44
  </div>
54
45
  );
55
- };
46
+ }
@@ -22,59 +22,48 @@
22
22
  */
23
23
 
24
24
  import { DateDisplay } from "@react-fabric/date";
25
- import { Format, getByPath, isTrue } from "@react-fabric/utilities";
26
- import classNames from "classnames";
25
+ import { cn, Format, getByPath, isArray, isObject, isTrue } from "@react-fabric/utilities";
27
26
  import { useMemo } from "react";
28
- import { useTableContext } from "./Context";
29
- import {
30
- COL_DEFAULT_WIDTH,
31
- COL_MAX_WIDTH,
32
- COL_MIN_WIDTH,
33
- type TableColumn,
34
- } from "./types";
27
+ import { useTableContext } from "./context";
28
+ import { COL_DEFAULT_WIDTH, COL_MAX_WIDTH, COL_MIN_WIDTH, type TableColumn } from "./types";
35
29
 
36
- export const BodyCell = ({
37
- column,
38
- item,
39
- index,
40
- }: {
41
- column: TableColumn;
42
- item: KeyValue;
43
- index: number;
44
- }) => {
30
+ export function BodyCell({ column, item, index }: { column: TableColumn; item: KeyValue; index: number }) {
45
31
  const { widths } = useTableContext();
46
32
 
47
- const width = useMemo(
48
- () => widths.get(column.id.toString()) ?? column.width,
49
- [widths, column],
50
- );
33
+ const width = useMemo(() => widths.get(column.id.toString()) ?? column.width, [widths, column]);
51
34
 
52
- const content = useMemo(() => {
35
+ const content = useMemo<React.ReactNode>(() => {
53
36
  const value = getByPath(item, column.id.toString());
54
37
  if (column.renderer != null) {
55
- return column.renderer(item[column.id], item, index);
38
+ return column.renderer(value, item, index);
56
39
  }
57
40
  if (column.dataType === "boolean") {
58
- const map = column.valueMap ?? { true: "Yes", false: "no" };
41
+ const map = column.valueMap ?? { true: "Yes", false: "No" };
59
42
  return map[`${isTrue(value) ? "true" : "false"}`];
60
43
  }
61
44
  if (column.valueMap != null) {
62
- if (column.dataType === "string" && value in column.valueMap) {
63
- return column.valueMap[value];
45
+ if (["number", "string"].includes(column.dataType ?? "string") && (value as string) in column.valueMap) {
46
+ return column.valueMap[value as string];
64
47
  }
65
48
  }
66
- if (column.dataType === "date") {
67
- return <DateDisplay date={value} format={column.format} />;
49
+ if (["date", "time", "datetime"].includes(column.dataType ?? "")) {
50
+ return <DateDisplay date={value as string} format={column.format} />;
68
51
  }
69
52
  if (column.dataType === "number") {
70
- return Format.number(value, column.format);
53
+ return Format.number(value as string, column.format);
54
+ }
55
+ if (isObject(value)) {
56
+ return JSON.stringify(value);
57
+ }
58
+ if (isArray(value)) {
59
+ return value.join(", ");
71
60
  }
72
- return value ?? "";
73
- }, [item, column]);
61
+ return (value as string) ?? "";
62
+ }, [item, column, index]);
74
63
 
75
64
  return (
76
65
  <div
77
- className="overflow-hidden bg-inherit start-0"
66
+ className="overflow-hidden bg-inherit inset-s-0 border-e group/table-col"
78
67
  style={{
79
68
  width: width ?? COL_DEFAULT_WIDTH,
80
69
  minWidth: column.minWidth ?? COL_MIN_WIDTH,
@@ -82,8 +71,10 @@ export const BodyCell = ({
82
71
  }}
83
72
  >
84
73
  <div
85
- className={classNames(
86
- "px-2 py-1 border-e truncate",
74
+ className={cn(
75
+ "px-2 py-1",
76
+ column.className,
77
+ column.truncate && "truncate",
87
78
  column.align === "center" && "text-center",
88
79
  column.align === "end" && "text-end",
89
80
  )}
@@ -92,4 +83,4 @@ export const BodyCell = ({
92
83
  </div>
93
84
  </div>
94
85
  );
95
- };
86
+ }
@@ -21,13 +21,13 @@
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 classNames from "classnames";
24
+ import { Icon } from "@react-fabric/core";
25
+ import { cn } from "@react-fabric/utilities";
25
26
  import { BodyCell } from "./BodyCell";
26
27
  import { CheckboxCell } from "./CheckboxCell";
27
28
  import { type TableColumn } from "./types";
28
- import { CoreIcons, Icon } from "@react-fabric/core";
29
29
 
30
- export const BodyRow = ({
30
+ export function BodyRow<T extends KeyValue = KeyValue>({
31
31
  rowKey,
32
32
  index,
33
33
  data,
@@ -46,97 +46,74 @@ export const BodyRow = ({
46
46
  toggleExpand,
47
47
  expandRow,
48
48
  }: {
49
- rowKey: Key;
49
+ rowKey: keyof T;
50
50
  index: number;
51
- data: KeyValue;
52
- keyProperty?: Key;
53
- measureElement: AnyObject;
51
+ data: T;
52
+ keyProperty?: keyof T;
54
53
  state: KeyValue<TableColumn[]>;
55
54
  hideableColumns?: boolean;
56
55
  wrapperStart: string;
57
56
  wrapperEnd: string;
58
57
  checkableRows?: boolean;
59
58
  checked: 0 | 1;
60
- onRowClick?: AnyObject;
61
- canExpand?: AnyObject;
62
- expandRow?: AnyObject;
63
59
  expanded: boolean;
60
+ measureElement: (el: HTMLDivElement) => void;
61
+ expandRow?: (data: T) => React.ReactElement<unknown>;
62
+ canExpand?: (data: T) => boolean;
63
+ onRowClick?: (data: T) => void;
64
64
  toggleExpand: (key: Key) => void;
65
65
  toggleChecked: (key: Key) => void;
66
- }) => {
66
+ }) {
67
67
  return (
68
- <div
69
- ref={measureElement}
70
- data-index={index}
71
- className={index % 2 ? "bg-even" : "bg-odd"}
72
- >
68
+ <div ref={measureElement} data-index={index} className={index % 2 ? "bg-even" : "bg-odd"}>
73
69
  <div
74
70
  role="none"
75
71
  data-row={index}
76
- className={classNames(
77
- "flex flex-nowrap datatable-row data-[hilight]:outline-1 -outline-offset-1 outline-primary-500",
78
- onRowClick && "hover:bg-primary-50 active:bg-primary-100",
72
+ className={cn(
73
+ "flex flex-nowrap datatable-row data-hilight:outline-1 -outline-offset-1 outline-primary-500 group/table-row",
74
+ !!onRowClick && "hover:bg-primary-50 active:bg-primary-100",
75
+ index % 2 ? "bg-even" : "bg-odd",
79
76
  )}
80
- onClick={() =>
81
- checkableRows && keyProperty && !onRowClick
82
- ? toggleChecked(data[keyProperty])
83
- : onRowClick?.(data)
84
- }
77
+ onClick={() => {
78
+ if (checkableRows && keyProperty && !onRowClick) toggleChecked(data[keyProperty]);
79
+ else onRowClick?.(data);
80
+ }}
85
81
  >
86
82
  <div className={wrapperStart}>
87
83
  {!!canExpand && (
88
- <div
89
- className={classNames(
90
- "group font-medium w-6 flex flex-nowrap text-start items-center",
84
+ <button
85
+ type="button"
86
+ className={cn(
87
+ "group font-medium w-6 flex flex-nowrap text-start py-1",
91
88
  !canExpand(data) && "pointer-events-none opacity-35",
92
89
  )}
90
+ onClick={(e) => [keyProperty && toggleExpand(data[keyProperty]), e.stopPropagation()]}
93
91
  >
94
92
  <Icon
95
93
  className="p-1 text-tint-700 hover:text-primary-600"
96
- icon={expanded ? CoreIcons.collapse : CoreIcons.expand}
97
- onClick={(e) => [
98
- keyProperty && toggleExpand(data[keyProperty]),
99
- e.stopPropagation(),
100
- ]}
94
+ icon={expanded ? "icon-[mdi--minus-box]" : "icon-[mdi--plus-box]"}
101
95
  />
102
- </div>
103
- )}
104
- {checkableRows && keyProperty && (
105
- <CheckboxCell
106
- onClick={() => toggleChecked(data[keyProperty])}
107
- state={checked}
108
- />
96
+ </button>
109
97
  )}
98
+ {checkableRows && keyProperty && <CheckboxCell onClick={() => toggleChecked(data[keyProperty])} state={checked} />}
110
99
  {state.start?.map((col, ids) => (
111
- <BodyCell
112
- key={`${String(rowKey)}:${ids}`}
113
- column={col}
114
- item={data}
115
- index={ids}
116
- />
100
+ // eslint-disable-next-line @eslint-react/no-array-index-key
101
+ <BodyCell key={`${String(rowKey)}:${ids}`} column={col} item={data} index={ids} />
117
102
  ))}
118
103
  </div>
119
104
  {state.cols?.map((col, idc) => (
120
- <BodyCell
121
- key={`${String(rowKey)}:${idc}`}
122
- column={col}
123
- item={data}
124
- index={idc}
125
- />
105
+ // eslint-disable-next-line @eslint-react/no-array-index-key
106
+ <BodyCell key={`${String(rowKey)}:${idc}`} column={col} item={data} index={idc} />
126
107
  ))}
127
108
  <div className={wrapperEnd}>
128
109
  {state.end?.map((col, ide) => (
129
- <BodyCell
130
- key={`${String(rowKey)}:${ide}`}
131
- column={col}
132
- item={data}
133
- index={ide}
134
- />
110
+ // eslint-disable-next-line @eslint-react/no-array-index-key
111
+ <BodyCell key={`${String(rowKey)}:${ide}`} column={col} item={data} index={ide} />
135
112
  ))}
136
113
  {hideableColumns && <div className="w-6" />}
137
114
  </div>
138
115
  </div>
139
- {expanded && expandRow(data)}
116
+ {expanded && expandRow?.(data)}
140
117
  </div>
141
118
  );
142
- };
119
+ }
@@ -21,28 +21,25 @@
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 { CoreIcons, Icon } from "@react-fabric/core";
24
+ import { Icon } from "@react-fabric/core";
25
25
 
26
- export const CheckboxCell = ({
27
- state,
28
- onClick,
29
- }: {
30
- state: 0 | 1 | 2;
31
- onClick?: () => void;
32
- }) => {
26
+ export function CheckboxCell({ state, onClick }: { state: number; onClick?: () => void }) {
33
27
  return (
34
- <div className="group font-medium border-e w-6 flex flex-nowrap text-start items-center">
28
+ <button
29
+ type="button"
30
+ className="group font-medium border-e w-6 flex flex-nowrap text-start py-1"
31
+ onClick={(e) => [onClick?.(), e.stopPropagation()]}
32
+ >
35
33
  <Icon
36
34
  icon={
37
35
  state === 2
38
- ? CoreIcons.checkboxInt
36
+ ? "icon-[mdi--checkbox-intermediate]"
39
37
  : state === 1
40
- ? CoreIcons.checkboxOn
41
- : CoreIcons.checkboxOff
38
+ ? "icon-[mdi--checkbox-marked]"
39
+ : "icon-[mdi--checkbox-blank-outline]"
42
40
  }
43
41
  className="p-1 text-tint-700 hover:text-primary-600"
44
- onClick={(e) => [onClick?.(), e.stopPropagation()]}
45
42
  />
46
- </div>
43
+ </button>
47
44
  );
48
- };
45
+ }
@@ -0,0 +1,93 @@
1
+ /*
2
+ * React Fabric
3
+ * @version: 1.0.0
4
+ *
5
+ *
6
+ * The MIT License (MIT)
7
+ * Copyright (c) 2025 Adarsh Pastakia
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
11
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
13
+ * subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
16
+ * portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ import { Button, DropdownDismiss } from "@react-fabric/core";
25
+ import { Checkbox, Input, Search } from "@react-fabric/form";
26
+ import { EMPTY_ARRAY, isString, matchString } from "@react-fabric/utilities";
27
+ import { useState } from "react";
28
+ import { useFilteredList } from "../hooks/useFilteredList";
29
+ import { type TableColumn } from "./types";
30
+
31
+ interface FilterProps {
32
+ type: TableColumn["dataType"];
33
+ onFilter: (value: AnyObject) => void;
34
+ list?: Array<string | { id: string; label: string }>;
35
+ filter?: string | string[];
36
+ }
37
+
38
+ function ListFilter({ list = EMPTY_ARRAY, filter, onFilter }: Partial<FilterProps>) {
39
+ const [selected, setSelected] = useState<Set<string>>(() => new Set(filter));
40
+
41
+ const { filteredList, query, onSearch } = useFilteredList(list, (item, query) => {
42
+ return matchString(isString(item) ? item : item.id, query);
43
+ });
44
+
45
+ return (
46
+ <div className="flex flex-col">
47
+ <div>
48
+ <Search {...{ autoFocus: true }} value={query} onSearch={onSearch} searchOnChange />
49
+ </div>
50
+ <div className="flex-1 overflow-auto scroll-thin">
51
+ {filteredList.map((v, idx) => (
52
+ // eslint-disable-next-line @eslint-react/no-array-index-key
53
+ <div key={idx} className="flex gap-x-1 text-xs items-center">
54
+ <Checkbox
55
+ checked={selected.has(isString(v) ? v : v.id)}
56
+ onChange={(b) => {
57
+ const set = new Set(Array.from(selected.values()));
58
+ if (b) set.add(isString(v) ? v : v.id);
59
+ else set.delete(isString(v) ? v : v.id);
60
+ setSelected(set);
61
+ }}
62
+ label={<span className="truncate">{isString(v) ? v : v.label}</span>}
63
+ />
64
+ </div>
65
+ ))}
66
+ {filteredList.length === 0 && <span className="text-muted text-xs">No items found</span>}
67
+ </div>
68
+ <div className="flex justify-end">
69
+ <DropdownDismiss>
70
+ <Button size="xs" onClick={() => onFilter?.(Array.from(selected))}>
71
+ Apply
72
+ </Button>
73
+ </DropdownDismiss>
74
+ </div>
75
+ </div>
76
+ );
77
+ }
78
+
79
+ export function ColumnFilters({ type, list, filter, onFilter }: FilterProps) {
80
+ return (
81
+ <div className="flex flex-col min-w-[16rem]">
82
+ {list && <ListFilter list={list} filter={filter} onFilter={onFilter} />}
83
+ {!list && type === "string" && (
84
+ <Input
85
+ {...{ autoFocus: true }}
86
+ allowClear
87
+ value={filter as string}
88
+ onEnterPressed={(e) => onFilter(e.currentTarget.value ?? "")}
89
+ />
90
+ )}
91
+ </div>
92
+ );
93
+ }