@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.
Files changed (103) 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 +23 -0
  4. package/dist/cjs/histogram/Histogram.js +37 -7
  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 +67 -27
  11. package/dist/cjs/pagination/Pagination.js +10 -0
  12. package/dist/cjs/table/AddColumn.js +1 -1
  13. package/dist/cjs/table/BodyCell.js +5 -4
  14. package/dist/cjs/table/BodyRow.js +2 -2
  15. package/dist/cjs/table/CheckboxCell.js +1 -1
  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 +58 -12
  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 +48 -30
  23. package/dist/cjs/tree/TreePanel.js +45 -11
  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 +23 -0
  30. package/dist/esm/histogram/Histogram.js +38 -8
  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 +68 -28
  37. package/dist/esm/pagination/Pagination.js +10 -0
  38. package/dist/esm/table/AddColumn.js +1 -1
  39. package/dist/esm/table/BodyCell.js +5 -4
  40. package/dist/esm/table/BodyRow.js +2 -2
  41. package/dist/esm/table/CheckboxCell.js +1 -1
  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 +59 -13
  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 +51 -33
  49. package/dist/esm/tree/TreePanel.js +46 -12
  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 +16 -8
  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 +44 -5
  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 -19
  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 +22 -0
  76. package/src/histogram/Histogram.tsx +40 -10
  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 +71 -35
  83. package/src/pagination/Pagination.tsx +10 -0
  84. package/src/table/AddColumn.tsx +1 -1
  85. package/src/table/BodyCell.tsx +6 -4
  86. package/src/table/BodyRow.tsx +3 -2
  87. package/src/table/CheckboxCell.tsx +1 -1
  88. package/src/table/ColumnFilters.tsx +105 -0
  89. package/src/table/HeaderCell.tsx +72 -18
  90. package/src/table/Table.tsx +99 -11
  91. package/src/table/types.ts +46 -8
  92. package/src/table/useResizer.ts +5 -3
  93. package/src/table/useVirtualTable.ts +158 -27
  94. package/src/tree/TreeNode.tsx +98 -58
  95. package/src/tree/TreePanel.tsx +77 -6
  96. package/src/tree/types.ts +73 -18
  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 +16 -8
  102. package/dist/cjs/histogram/Histogram.module.css +0 -1
  103. package/dist/esm/histogram/Histogram.module.css +0 -1
@@ -22,7 +22,6 @@
22
22
  */
23
23
 
24
24
  import {
25
- ActionLabel,
26
25
  Button,
27
26
  Copy,
28
27
  CoreIcons,
@@ -181,6 +180,8 @@ const JsonEntry = ({
181
180
  ret = actualValue ? t("json.true") : t("json.false");
182
181
  if (ret?.length > 128) {
183
182
  ret = <Text clamp={3}>{ret}</Text>;
183
+ } else {
184
+ ret = <div className="break-words">{ret}</div>;
184
185
  }
185
186
 
186
187
  return (
@@ -216,37 +217,36 @@ const JsonEntry = ({
216
217
 
217
218
  const labelDisplay = useMemo(
218
219
  () => (
219
- <ActionLabel
220
- className="text-dimmed text-sm px-2 flex-1 truncate"
221
- actions={
222
- !canExpand && canFilter
223
- ? [
224
- <Button
225
- key="negative"
226
- color="danger"
227
- size="sm"
228
- variant="link"
229
- icon={CoreIcons.funnelMinus}
230
- aria-label="Filter Negative"
231
- onClick={() =>
232
- onFilter?.(pathWithoutOrdinal, actualValue, true)
233
- }
234
- />,
235
- <Button
236
- key="positive"
237
- color="primary"
238
- size="sm"
239
- variant="link"
240
- icon={CoreIcons.funnelPlus}
241
- aria-label="Filter"
242
- onClick={() => onFilter?.(pathWithoutOrdinal, actualValue)}
243
- />,
244
- ]
245
- : []
246
- }
220
+ <div
221
+ className={classNames(
222
+ "text-dimmed text-sm px-2 flex-1 group",
223
+ inline ? "truncate" : "break-words",
224
+ )}
247
225
  >
226
+ {!canExpand && canFilter && (
227
+ <div className="hidden pe-1 group-hover:inline-block">
228
+ <Button
229
+ key="negative"
230
+ color="danger"
231
+ size="xs"
232
+ variant="link"
233
+ icon={CoreIcons.funnelMinus}
234
+ aria-label="Filter Negative"
235
+ onClick={() => onFilter?.(pathWithoutOrdinal, actualValue, true)}
236
+ />
237
+ <Button
238
+ key="positive"
239
+ color="primary"
240
+ size="xs"
241
+ variant="link"
242
+ icon={CoreIcons.funnelPlus}
243
+ aria-label="Filter"
244
+ onClick={() => onFilter?.(pathWithoutOrdinal, actualValue)}
245
+ />
246
+ </div>
247
+ )}
248
248
  {labeler?.(path) ?? field}
249
- </ActionLabel>
249
+ </div>
250
250
  ),
251
251
  [field, labeler, pathWithoutOrdinal, actualValue, canExpand, canFilter],
252
252
  );
@@ -283,9 +283,14 @@ const JsonEntry = ({
283
283
  {labelDisplay}
284
284
  </div>
285
285
  {display && (
286
- <div className={classNames("px-2", inline && "flex-1")}>
286
+ <div
287
+ className={classNames(
288
+ "px-2 flex flex-nowrap overflow-hidden",
289
+ inline && "flex-1",
290
+ )}
291
+ >
287
292
  {canCopy && <Copy size="xs" text={actualValue} />}
288
- {display}
293
+ <div className="flex-1">{display}</div>
289
294
  </div>
290
295
  )}
291
296
  </div>
@@ -309,9 +314,14 @@ const JsonEntry = ({
309
314
  >
310
315
  {labelDisplay}
311
316
  </div>
312
- <div className={classNames("px-2", inline && "flex-1")}>
317
+ <div
318
+ className={classNames(
319
+ "px-2 flex flex-nowrap overflow-hidden",
320
+ inline && "flex-1",
321
+ )}
322
+ >
313
323
  {canCopy && <Copy size="xs" text={value} />}
314
- {display}
324
+ <div className="flex-1">{display}</div>
315
325
  </div>
316
326
  </div>
317
327
  )}
@@ -336,6 +346,32 @@ const JsonEntry = ({
336
346
  );
337
347
  };
338
348
 
349
+ /**
350
+ * JsonViewer component to display JSON data in a structured format.
351
+ * It supports inline display, property filtering, and custom formatting.
352
+ * The component can handle nested objects and arrays, displaying them in a tree-like structure.
353
+ * It also provides options for copying values and filtering properties.
354
+ *
355
+ * @param {JsonViewProps<T>} props - The properties for the JsonViewer component.
356
+ * @returns {JSX.Element} The rendered JsonViewer component.
357
+ *
358
+ * @example
359
+ * ```jsx
360
+ * <JsonViewer
361
+ * json={{ name: "John", age: 30, address: { city: "New York", zip: "10001" } }}
362
+ * copy={true}
363
+ * filters={true}
364
+ * propertyScheme={{ date: ["createdAt"], phone: ["contact"] }}
365
+ * inline={true}
366
+ * labelWidth="25%"
367
+ * formatter={(path, value) => (path === "age" ? `${value} years` : value)}
368
+ * labeler={(path) => path.replace(/_/g, " ").toUpperCase()}
369
+ * onFilter={(path, value, negate) => console.log(`Filter ${negate ? "negate" : ""} on ${path}:`, value)}
370
+ * />
371
+ * ```
372
+ *
373
+ * @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/data-jsonviewer--docs}
374
+ */
339
375
  export const JsonViewer = <T extends KeyValue = KeyValue>({
340
376
  className,
341
377
  json,
@@ -356,7 +392,7 @@ export const JsonViewer = <T extends KeyValue = KeyValue>({
356
392
  const list = useMemo(() => reduceObject(json), [json]);
357
393
 
358
394
  return (
359
- <div {...rest} className={classNames(className, "p-4 bg-alternate")}>
395
+ <div {...rest} className={classNames(className, "bg-alternate")}>
360
396
  {!isEmpty(json) ? (
361
397
  list.map((item) => (
362
398
  <JsonEntry
@@ -48,6 +48,16 @@ export interface PaginationProps {
48
48
  onPageChange: (page: number) => void;
49
49
  }
50
50
 
51
+ /**
52
+ * Pagination component to navigate through pages of data.
53
+ * It displays buttons for navigating to the first, previous, next, and last pages,
54
+ * as well as buttons for specific page numbers based on the provided ranges.
55
+ * The component supports a minimal view that shows the current page and total pages.
56
+ * It uses memoization to optimize rendering performance.
57
+ *
58
+ * @param {PaginationProps} props - The properties for the Pagination component.
59
+ * @returns {JSX.Element} The rendered Pagination component.
60
+ */
51
61
  export const Pagination = memo(
52
62
  ({ page, ranges, totalPages, minimal, onPageChange }: PaginationProps) => {
53
63
  const [start, mid, last] = ranges;
@@ -32,7 +32,7 @@ export const AddColumn = ({
32
32
  onClick: (id: string) => void;
33
33
  }) => {
34
34
  return (
35
- <div className="group font-medium w-6 flex flex-nowrap text-start items-end">
35
+ <div className="group font-medium w-6 flex flex-nowrap text-start items-center">
36
36
  <Dropdown placement="bottom-end">
37
37
  <Icon
38
38
  icon={CoreIcons.insert}
@@ -52,7 +52,7 @@ export const BodyCell = ({
52
52
  const content = useMemo(() => {
53
53
  const value = getByPath(item, column.id.toString());
54
54
  if (column.renderer != null) {
55
- return column.renderer(item[column.id], item, index);
55
+ return column.renderer(value, item, index);
56
56
  }
57
57
  if (column.dataType === "boolean") {
58
58
  const map = column.valueMap ?? { true: "Yes", false: "no" };
@@ -63,7 +63,7 @@ export const BodyCell = ({
63
63
  return column.valueMap[value];
64
64
  }
65
65
  }
66
- if (column.dataType === "date") {
66
+ if (["date", "time", "datetime"].includes(column.dataType ?? "")) {
67
67
  return <DateDisplay date={value} format={column.format} />;
68
68
  }
69
69
  if (column.dataType === "number") {
@@ -74,7 +74,7 @@ export const BodyCell = ({
74
74
 
75
75
  return (
76
76
  <div
77
- className="overflow-hidden bg-inherit start-0"
77
+ className="overflow-hidden bg-inherit start-0 border-e group/table-col"
78
78
  style={{
79
79
  width: width ?? COL_DEFAULT_WIDTH,
80
80
  minWidth: column.minWidth ?? COL_MIN_WIDTH,
@@ -83,7 +83,9 @@ export const BodyCell = ({
83
83
  >
84
84
  <div
85
85
  className={classNames(
86
- "px-2 py-1 border-e truncate",
86
+ "px-2 py-1",
87
+ column.className,
88
+ column.truncate && "truncate",
87
89
  column.align === "center" && "text-center",
88
90
  column.align === "end" && "text-end",
89
91
  )}
@@ -74,8 +74,9 @@ export const BodyRow = ({
74
74
  role="none"
75
75
  data-row={index}
76
76
  className={classNames(
77
- "flex flex-nowrap datatable-row data-[hilight]:outline-1 -outline-offset-1 outline-primary-500",
77
+ "flex flex-nowrap datatable-row data-hilight:outline-1 -outline-offset-1 outline-primary-500 group/table-row",
78
78
  onRowClick && "hover:bg-primary-50 active:bg-primary-100",
79
+ index % 2 ? "bg-even" : "bg-odd",
79
80
  )}
80
81
  onClick={() =>
81
82
  checkableRows && keyProperty && !onRowClick
@@ -87,7 +88,7 @@ export const BodyRow = ({
87
88
  {!!canExpand && (
88
89
  <div
89
90
  className={classNames(
90
- "group font-medium w-6 flex flex-nowrap text-start items-center",
91
+ "group font-medium w-6 flex flex-nowrap text-start py-1",
91
92
  !canExpand(data) && "pointer-events-none opacity-35",
92
93
  )}
93
94
  >
@@ -31,7 +31,7 @@ export const CheckboxCell = ({
31
31
  onClick?: () => void;
32
32
  }) => {
33
33
  return (
34
- <div className="group font-medium border-e w-6 flex flex-nowrap text-start items-center">
34
+ <div className="group font-medium border-e w-6 flex flex-nowrap text-start py-1">
35
35
  <Icon
36
36
  icon={
37
37
  state === 2
@@ -0,0 +1,105 @@
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, 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?: AnyObject[];
35
+ filter: AnyObject;
36
+ }
37
+
38
+ const ListFilter = ({
39
+ list = EMPTY_ARRAY,
40
+ filter,
41
+ onFilter,
42
+ }: Partial<FilterProps>) => {
43
+ const [selected, setSelected] = useState<Set<string>>(new Set(filter));
44
+
45
+ const { filteredList, query, onSearch } = useFilteredList(
46
+ list,
47
+ (item, query) => {
48
+ return matchString(item.id ?? item, query);
49
+ },
50
+ );
51
+
52
+ return (
53
+ <div className="flex flex-col">
54
+ <div>
55
+ <Search autoFocus value={query} onSearch={onSearch} searchOnChange />
56
+ </div>
57
+ <div className="flex-1 overflow-auto scroll-thin">
58
+ {filteredList.map((v, idx) => (
59
+ <div key={idx} className="flex gap-x-1 text-xs items-center">
60
+ <Checkbox
61
+ checked={selected.has(v.id ?? v)}
62
+ onChange={(b) => {
63
+ const set = new Set(Array.from(selected.values()));
64
+ b ? set.add(v.id ?? v) : set.delete(v.id ?? v);
65
+ setSelected(set);
66
+ }}
67
+ label={<span className="truncate">{v.label ?? v}</span>}
68
+ />
69
+ </div>
70
+ ))}
71
+ {filteredList.length === 0 && (
72
+ <span className="text-muted text-xs">No items found</span>
73
+ )}
74
+ </div>
75
+ <div className="flex justify-end">
76
+ <DropdownDismiss>
77
+ <Button size="xs" onClick={() => onFilter?.(Array.from(selected))}>
78
+ Apply
79
+ </Button>
80
+ </DropdownDismiss>
81
+ </div>
82
+ </div>
83
+ );
84
+ };
85
+
86
+ export const ColumnFilters = ({
87
+ type,
88
+ list,
89
+ filter,
90
+ onFilter,
91
+ }: FilterProps) => {
92
+ return (
93
+ <div className="flex flex-col min-w-[16rem]">
94
+ {list && <ListFilter list={list} filter={filter} onFilter={onFilter} />}
95
+ {!list && type === "string" && (
96
+ <Input
97
+ autoFocus
98
+ allowClear
99
+ value={filter}
100
+ onEnterPressed={(e: AnyObject) => onFilter(e.target.value ?? "")}
101
+ />
102
+ )}
103
+ </div>
104
+ );
105
+ };
@@ -22,14 +22,19 @@
22
22
  */
23
23
 
24
24
  import {
25
+ Button,
25
26
  CoreIcons,
27
+ Divider,
26
28
  DropdownTool,
29
+ getIconProps,
27
30
  Icon,
28
31
  Menu,
29
32
  MenuItem,
30
33
  Tooltip,
31
34
  } from "@react-fabric/core";
35
+ import { isEmpty } from "@react-fabric/utilities";
32
36
  import { useCallback, useMemo } from "react";
37
+ import { ColumnFilters } from "./ColumnFilters";
33
38
  import { useTableContext } from "./Context";
34
39
  import {
35
40
  COL_DEFAULT_WIDTH,
@@ -41,13 +46,15 @@ import {
41
46
 
42
47
  export const HeaderCell = ({
43
48
  id,
49
+ field,
50
+ dataType,
44
51
  label,
45
52
  icon,
46
- iconBg,
47
- iconColor,
48
- rtlFlip,
49
53
  actions,
50
54
  locked,
55
+ filter,
56
+ filterable,
57
+ filterOptions,
51
58
  tooltip,
52
59
  sortable,
53
60
  resizable,
@@ -56,7 +63,8 @@ export const HeaderCell = ({
56
63
  minWidth,
57
64
  sort,
58
65
  onSort,
59
- }: TableColumn & Pick<TableProps, "sort" | "onSort">) => {
66
+ onFilter,
67
+ }: TableColumn & Pick<TableProps, "sort" | "onSort" | "onFilter">) => {
60
68
  const { startResize, widths } = useTableContext();
61
69
 
62
70
  const width = useMemo(
@@ -64,39 +72,77 @@ export const HeaderCell = ({
64
72
  [widths, _width, id],
65
73
  );
66
74
 
67
- const handleSort = useCallback(() => {
68
- sortable &&
69
- onSort?.({
70
- id: id.toString(),
71
- order: sort?.id === id && sort.order === "asc" ? "desc" : "asc",
72
- });
73
- }, [onSort, name, sort, sortable]);
75
+ const handleSort = useCallback(
76
+ (order?: "asc" | "desc") => {
77
+ sortable &&
78
+ onSort?.({
79
+ id: id.toString(),
80
+ order:
81
+ order ?? (sort?.id === id && sort.order === "asc" ? "desc" : "asc"),
82
+ });
83
+ },
84
+ [onSort, sort, sortable],
85
+ );
74
86
 
75
87
  const menus = useMemo(() => {
76
- const ret = [];
88
+ let ret = [];
89
+ if (filterable && (dataType ?? filterOptions)) {
90
+ ret.push(
91
+ <Menu
92
+ key="filters"
93
+ label="Filter"
94
+ icon={filter ? CoreIcons.tick : ""}
95
+ trigger="click"
96
+ >
97
+ <ColumnFilters
98
+ type={dataType}
99
+ list={filterOptions}
100
+ filter={filter}
101
+ onFilter={(value) => onFilter?.(field ?? id, value)}
102
+ />
103
+ </Menu>,
104
+ );
105
+ }
77
106
  if (sortable) {
78
107
  ret.push(
79
108
  <MenuItem
80
109
  key="sort-asc"
81
110
  label="Sort ascending"
82
111
  icon={CoreIcons.sortAsc}
112
+ onClick={() => handleSort("asc")}
83
113
  />,
84
114
  <MenuItem
85
115
  key="sort-desc"
86
116
  label="Sort descending"
87
117
  icon={CoreIcons.sortDesc}
118
+ onClick={() => handleSort("desc")}
88
119
  />,
89
120
  );
90
121
  }
122
+ if (actions) {
123
+ ret.push(<Divider key="div" />);
124
+ ret.push(...actions);
125
+ }
126
+ if (ret.length === 1) {
127
+ ret = [
128
+ <ColumnFilters
129
+ key="filters"
130
+ type={dataType}
131
+ list={filterOptions}
132
+ filter={filter}
133
+ onFilter={(value) => onFilter?.(field ?? id, value)}
134
+ />,
135
+ ];
136
+ }
91
137
  return ret;
92
- }, [sortable]);
138
+ }, [sortable, actions, onFilter, handleSort]);
93
139
 
94
140
  return (
95
141
  <div
96
142
  role="none"
97
143
  data-id={id}
98
- onClick={handleSort}
99
- className="group font-medium border-e flex flex-nowrap text-start items-center table-header-cell"
144
+ onClick={() => handleSort()}
145
+ className="group/tool font-medium border-e flex flex-nowrap text-start items-center table-header-cell"
100
146
  style={{
101
147
  width: width ?? COL_DEFAULT_WIDTH,
102
148
  minWidth: minWidth ?? COL_MIN_WIDTH,
@@ -105,9 +151,7 @@ export const HeaderCell = ({
105
151
  >
106
152
  <Tooltip content={tooltip ?? label} disabled={!(tooltip ?? label)}>
107
153
  <div className="flex-initial px-2 py-1 text-sm truncate sticky start-0">
108
- {icon && (
109
- <Icon icon={icon} bg={iconBg} color={iconColor} rtlFlip={rtlFlip} />
110
- )}
154
+ {icon && <Icon {...getIconProps(icon)} />}
111
155
  <span>{label ?? " "}</span>
112
156
  </div>
113
157
  </Tooltip>
@@ -123,6 +167,16 @@ export const HeaderCell = ({
123
167
  <Menu className="text-sm">{menus}</Menu>
124
168
  </DropdownTool>
125
169
  )}
170
+ {filterable && !isEmpty(filter) && (
171
+ <Button
172
+ size="sm"
173
+ variant="link"
174
+ aria-label="clear filter"
175
+ stopPropagation
176
+ icon={CoreIcons.funnelRemove}
177
+ onClick={() => onFilter?.(id)}
178
+ />
179
+ )}
126
180
  {resizable && (
127
181
  <div
128
182
  role="none"