@react-fabric/data 1.0.0-beta.0 → 1.0.0-beta.11

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 (83) hide show
  1. package/dist/cjs/checklist/CheckList.js +143 -0
  2. package/dist/cjs/histogram/Histogram.js +14 -5
  3. package/dist/cjs/hooks/useSelectableList.js +54 -0
  4. package/dist/cjs/index.js +2 -0
  5. package/dist/cjs/table/AddColumn.js +56 -0
  6. package/dist/cjs/table/BodyCell.js +47 -6
  7. package/dist/cjs/table/BodyRow.js +107 -0
  8. package/dist/cjs/table/CheckboxCell.js +44 -0
  9. package/dist/cjs/table/Context.js +43 -0
  10. package/dist/cjs/table/EmptyCell.js +52 -0
  11. package/dist/cjs/table/HeaderCell.js +78 -32
  12. package/dist/cjs/table/Table.js +173 -96
  13. package/dist/cjs/table/types.js +32 -0
  14. package/dist/cjs/table/useResizer.js +65 -0
  15. package/dist/cjs/table/useTableColumns.js +45 -8
  16. package/dist/cjs/table/useVirtualTable.js +56 -25
  17. package/dist/cjs/tree/TreePanel.js +14 -2
  18. package/dist/cjs/tree/useTree.js +7 -0
  19. package/dist/cjs/virtual/Gallery.js +11 -4
  20. package/dist/cjs/virtual/List.js +11 -4
  21. package/dist/esm/checklist/CheckList.js +143 -0
  22. package/dist/esm/histogram/Histogram.js +14 -5
  23. package/dist/esm/hooks/useSelectableList.js +54 -0
  24. package/dist/esm/index.js +1 -0
  25. package/dist/esm/table/AddColumn.js +56 -0
  26. package/dist/esm/table/BodyCell.js +47 -6
  27. package/dist/esm/table/BodyRow.js +107 -0
  28. package/dist/esm/table/CheckboxCell.js +44 -0
  29. package/dist/esm/table/Context.js +42 -0
  30. package/dist/esm/table/EmptyCell.js +52 -0
  31. package/dist/esm/table/HeaderCell.js +80 -34
  32. package/dist/esm/table/Table.js +174 -97
  33. package/dist/esm/table/types.js +30 -0
  34. package/dist/esm/table/useResizer.js +65 -0
  35. package/dist/esm/table/useTableColumns.js +46 -9
  36. package/dist/esm/table/useVirtualTable.js +57 -26
  37. package/dist/esm/tree/TreePanel.js +15 -3
  38. package/dist/esm/tree/useTree.js +7 -0
  39. package/dist/esm/virtual/Gallery.js +11 -4
  40. package/dist/esm/virtual/List.js +11 -4
  41. package/dist/types/checklist/CheckList.d.ts +30 -0
  42. package/dist/types/histogram/Histogram.d.ts +3 -3
  43. package/dist/types/hooks/useSelectableList.d.ts +28 -0
  44. package/dist/types/index.d.ts +3 -0
  45. package/dist/types/table/AddColumn.d.ts +5 -0
  46. package/dist/types/table/BodyCell.d.ts +4 -3
  47. package/dist/types/table/BodyRow.d.ts +20 -0
  48. package/dist/types/table/CheckboxCell.d.ts +4 -0
  49. package/dist/types/table/Context.d.ts +8 -0
  50. package/dist/types/table/EmptyCell.d.ts +2 -0
  51. package/dist/types/table/HeaderCell.d.ts +2 -2
  52. package/dist/types/table/Table.d.ts +1 -1
  53. package/dist/types/table/types.d.ts +41 -7
  54. package/dist/types/table/useResizer.d.ts +1 -0
  55. package/dist/types/table/useTableColumns.d.ts +8 -6
  56. package/dist/types/table/useVirtualTable.d.ts +13 -1
  57. package/dist/types/tree/TreePanel.d.ts +1 -1
  58. package/dist/types/tree/types.d.ts +6 -2
  59. package/dist/types/tree/useTree.d.ts +1 -0
  60. package/dist/types/virtual/Gallery.d.ts +3 -2
  61. package/dist/types/virtual/List.d.ts +3 -2
  62. package/package.json +6 -5
  63. package/src/checklist/CheckList.tsx +222 -0
  64. package/src/histogram/Histogram.tsx +7 -2
  65. package/src/hooks/useSelectableList.ts +94 -0
  66. package/src/index.ts +3 -0
  67. package/src/table/AddColumn.tsx +55 -0
  68. package/src/table/BodyCell.tsx +47 -6
  69. package/src/table/BodyRow.tsx +142 -0
  70. package/src/table/CheckboxCell.tsx +48 -0
  71. package/src/table/Context.tsx +70 -0
  72. package/src/table/EmptyCell.tsx +57 -0
  73. package/src/table/HeaderCell.tsx +93 -25
  74. package/src/table/Table.tsx +194 -87
  75. package/src/table/types.ts +42 -6
  76. package/src/table/useResizer.ts +66 -0
  77. package/src/table/useTableColumns.ts +52 -19
  78. package/src/table/useVirtualTable.ts +61 -2
  79. package/src/tree/TreePanel.tsx +12 -1
  80. package/src/tree/types.ts +8 -1
  81. package/src/tree/useTree.ts +5 -0
  82. package/src/virtual/Gallery.tsx +4 -1
  83. package/src/virtual/List.tsx +4 -1
@@ -1,6 +1,11 @@
1
1
  'use client';
2
2
 
3
+ import { DateDisplay } from '@react-fabric/date';
4
+ import { getByPath, isTrue, Format } from '@react-fabric/utilities';
3
5
  import classNames from 'classnames';
6
+ import { useMemo } from 'react';
7
+ import { useTableContext } from './Context.js';
8
+ import { COL_DEFAULT_WIDTH, COL_MIN_WIDTH, COL_MAX_WIDTH } from './types.js';
4
9
  import { jsx } from 'react/jsx-runtime';
5
10
 
6
11
  /*
@@ -27,19 +32,55 @@ import { jsx } from 'react/jsx-runtime';
27
32
  */
28
33
 
29
34
  var BodyCell = function BodyCell(_ref) {
30
- var _column$width, _column$minWidth, _column$maxWidth, _column$renderer, _column$renderer2;
35
+ var _column$minWidth, _column$maxWidth;
31
36
  var column = _ref.column,
32
- item = _ref.item;
37
+ item = _ref.item,
38
+ index = _ref.index;
39
+ var _useTableContext = useTableContext(),
40
+ widths = _useTableContext.widths;
41
+ var width = useMemo(function () {
42
+ var _widths$get;
43
+ return (_widths$get = widths.get(column.id.toString())) !== null && _widths$get !== void 0 ? _widths$get : column.width;
44
+ }, [widths, column]);
45
+ var content = useMemo(function () {
46
+ var value = getByPath(item, column.id.toString());
47
+ if (column.renderer != null) {
48
+ return column.renderer(item[column.id], item, index);
49
+ }
50
+ if (column.dataType === "boolean") {
51
+ var _column$valueMap;
52
+ var map = (_column$valueMap = column.valueMap) !== null && _column$valueMap !== void 0 ? _column$valueMap : {
53
+ "true": "Yes",
54
+ "false": "no"
55
+ };
56
+ return map["".concat(isTrue(value) ? "true" : "false")];
57
+ }
58
+ if (column.valueMap != null) {
59
+ if (column.dataType === "string" && value in column.valueMap) {
60
+ return column.valueMap[value];
61
+ }
62
+ }
63
+ if (column.dataType === "date") {
64
+ return /*#__PURE__*/jsx(DateDisplay, {
65
+ date: value,
66
+ format: column.format
67
+ });
68
+ }
69
+ if (column.dataType === "number") {
70
+ return Format.number(value, column.format);
71
+ }
72
+ return value !== null && value !== void 0 ? value : "";
73
+ }, [item, column]);
33
74
  return /*#__PURE__*/jsx("div", {
34
75
  className: "overflow-hidden bg-inherit start-0",
35
76
  style: {
36
- width: (_column$width = column.width) !== null && _column$width !== void 0 ? _column$width : "12rem",
37
- minWidth: (_column$minWidth = column.minWidth) !== null && _column$minWidth !== void 0 ? _column$minWidth : "2rem",
38
- maxWidth: (_column$maxWidth = column.maxWidth) !== null && _column$maxWidth !== void 0 ? _column$maxWidth : "32rem"
77
+ width: width !== null && width !== void 0 ? width : COL_DEFAULT_WIDTH,
78
+ minWidth: (_column$minWidth = column.minWidth) !== null && _column$minWidth !== void 0 ? _column$minWidth : COL_MIN_WIDTH,
79
+ maxWidth: (_column$maxWidth = column.maxWidth) !== null && _column$maxWidth !== void 0 ? _column$maxWidth : COL_MAX_WIDTH
39
80
  },
40
81
  children: /*#__PURE__*/jsx("div", {
41
82
  className: classNames("px-2 py-1 border-e truncate", column.align === "center" && "text-center", column.align === "end" && "text-end"),
42
- children: (_column$renderer = (_column$renderer2 = column.renderer) === null || _column$renderer2 === void 0 ? void 0 : _column$renderer2.call(column, item[column.id], item)) !== null && _column$renderer !== void 0 ? _column$renderer : item[column.id]
83
+ children: content
43
84
  })
44
85
  });
45
86
  };
@@ -0,0 +1,107 @@
1
+ 'use client';
2
+
3
+ import classNames from 'classnames';
4
+ import { BodyCell } from './BodyCell.js';
5
+ import { CheckboxCell } from './CheckboxCell.js';
6
+ import { Icon, CoreIcons } from '@react-fabric/core';
7
+ import { jsxs, jsx } from 'react/jsx-runtime';
8
+
9
+ /*
10
+ * React Fabric
11
+ * @version: 1.0.0
12
+ *
13
+ *
14
+ * The MIT License (MIT)
15
+ * Copyright (c) 2024 Adarsh Pastakia
16
+ *
17
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
18
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
19
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
20
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
21
+ * subject to the following conditions:
22
+ *
23
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
24
+ * portions of the Software.
25
+ *
26
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
27
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
28
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
29
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
+ */
31
+
32
+ var BodyRow = function BodyRow(_ref) {
33
+ var _state$start, _state$cols, _state$end;
34
+ var rowKey = _ref.rowKey,
35
+ index = _ref.index,
36
+ data = _ref.data,
37
+ keyProperty = _ref.keyProperty,
38
+ measureElement = _ref.measureElement,
39
+ state = _ref.state,
40
+ hideableColumns = _ref.hideableColumns,
41
+ wrapperStart = _ref.wrapperStart,
42
+ wrapperEnd = _ref.wrapperEnd,
43
+ onRowClick = _ref.onRowClick,
44
+ checkableRows = _ref.checkableRows,
45
+ checked = _ref.checked,
46
+ toggleChecked = _ref.toggleChecked,
47
+ canExpand = _ref.canExpand,
48
+ expanded = _ref.expanded,
49
+ toggleExpand = _ref.toggleExpand,
50
+ expandRow = _ref.expandRow;
51
+ return /*#__PURE__*/jsxs("div", {
52
+ ref: measureElement,
53
+ "data-index": index,
54
+ className: index % 2 ? "bg-even" : "bg-odd",
55
+ children: [/*#__PURE__*/jsxs("div", {
56
+ role: "none",
57
+ "data-row": index,
58
+ className: classNames("flex flex-nowrap datatable-row data-[hilight]:outline-1 -outline-offset-1 outline-primary-500", onRowClick && "hover:bg-primary-50 active:bg-primary-100"),
59
+ onClick: function onClick() {
60
+ return checkableRows && keyProperty && !onRowClick ? toggleChecked(data[keyProperty]) : onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick(data);
61
+ },
62
+ children: [/*#__PURE__*/jsxs("div", {
63
+ className: wrapperStart,
64
+ children: [!!canExpand && /*#__PURE__*/jsx("div", {
65
+ className: classNames("group font-medium w-6 flex flex-nowrap text-start items-center", !canExpand(data) && "pointer-events-none opacity-35"),
66
+ children: /*#__PURE__*/jsx(Icon, {
67
+ className: "p-1 text-tint-700 hover:text-primary-600",
68
+ icon: expanded ? CoreIcons.collapse : CoreIcons.expand,
69
+ onClick: function onClick(e) {
70
+ return [keyProperty && toggleExpand(data[keyProperty]), e.stopPropagation()];
71
+ }
72
+ })
73
+ }), checkableRows && keyProperty && /*#__PURE__*/jsx(CheckboxCell, {
74
+ onClick: function onClick() {
75
+ return toggleChecked(data[keyProperty]);
76
+ },
77
+ state: checked
78
+ }), (_state$start = state.start) === null || _state$start === void 0 ? void 0 : _state$start.map(function (col, ids) {
79
+ return /*#__PURE__*/jsx(BodyCell, {
80
+ column: col,
81
+ item: data,
82
+ index: ids
83
+ }, "".concat(String(rowKey), ":").concat(ids));
84
+ })]
85
+ }), (_state$cols = state.cols) === null || _state$cols === void 0 ? void 0 : _state$cols.map(function (col, idc) {
86
+ return /*#__PURE__*/jsx(BodyCell, {
87
+ column: col,
88
+ item: data,
89
+ index: idc
90
+ }, "".concat(String(rowKey), ":").concat(idc));
91
+ }), /*#__PURE__*/jsxs("div", {
92
+ className: wrapperEnd,
93
+ children: [(_state$end = state.end) === null || _state$end === void 0 ? void 0 : _state$end.map(function (col, ide) {
94
+ return /*#__PURE__*/jsx(BodyCell, {
95
+ column: col,
96
+ item: data,
97
+ index: ide
98
+ }, "".concat(String(rowKey), ":").concat(ide));
99
+ }), hideableColumns && /*#__PURE__*/jsx("div", {
100
+ className: "w-6"
101
+ })]
102
+ })]
103
+ }), expanded && expandRow(data)]
104
+ });
105
+ };
106
+
107
+ export { BodyRow };
@@ -0,0 +1,44 @@
1
+ 'use client';
2
+
3
+ import { Icon, CoreIcons } from '@react-fabric/core';
4
+ import { jsx } from 'react/jsx-runtime';
5
+
6
+ /*
7
+ * React Fabric
8
+ * @version: 1.0.0
9
+ *
10
+ *
11
+ * The MIT License (MIT)
12
+ * Copyright (c) 2024 Adarsh Pastakia
13
+ *
14
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
15
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
16
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
17
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
18
+ * subject to the following conditions:
19
+ *
20
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
21
+ * portions of the Software.
22
+ *
23
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
24
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ */
28
+
29
+ var CheckboxCell = function CheckboxCell(_ref) {
30
+ var state = _ref.state,
31
+ _onClick = _ref.onClick;
32
+ return /*#__PURE__*/jsx("div", {
33
+ className: "group font-medium border-e w-6 flex flex-nowrap text-start items-center",
34
+ children: /*#__PURE__*/jsx(Icon, {
35
+ icon: state === 2 ? CoreIcons.checkboxInt : state === 1 ? CoreIcons.checkboxOn : CoreIcons.checkboxOff,
36
+ className: "p-1 text-tint-700 hover:text-primary-600",
37
+ onClick: function onClick(e) {
38
+ return [_onClick === null || _onClick === void 0 ? void 0 : _onClick(), e.stopPropagation()];
39
+ }
40
+ })
41
+ });
42
+ };
43
+
44
+ export { CheckboxCell };
@@ -0,0 +1,42 @@
1
+ 'use client';
2
+
3
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
4
+ import { useRef, useState, useCallback, createContext, useContext } from 'react';
5
+ import { useResizer } from './useResizer.js';
6
+ import { jsxs, jsx } from 'react/jsx-runtime';
7
+
8
+ var TableContext = /*#__PURE__*/createContext({});
9
+ var TableProvider = function TableProvider(_ref) {
10
+ var children = _ref.children;
11
+ var ghostRef = useRef(null);
12
+ var _useState = useState(new Map()),
13
+ _useState2 = _slicedToArray(_useState, 2),
14
+ widths = _useState2[0],
15
+ setWidths = _useState2[1];
16
+ var startResize = useCallback(function (col) {
17
+ if (col) {
18
+ ghostRef.current != null && useResizer(col, ghostRef.current, function (width) {
19
+ var _col$dataset$id;
20
+ setWidths(new Map(widths.set((_col$dataset$id = col.dataset.id) !== null && _col$dataset$id !== void 0 ? _col$dataset$id : "", width)));
21
+ });
22
+ }
23
+ }, [widths]);
24
+ return /*#__PURE__*/jsxs(TableContext.Provider, {
25
+ value: {
26
+ startResize: startResize,
27
+ widths: widths
28
+ },
29
+ children: [children, /*#__PURE__*/jsx("div", {
30
+ className: "absolute inset-0 hidden z-20 cursor-col-resize",
31
+ ref: ghostRef,
32
+ children: /*#__PURE__*/jsx("div", {
33
+ className: "absolute inset-y-0 bg-muted opacity-50 border-primary border-e-2"
34
+ })
35
+ })]
36
+ });
37
+ };
38
+ var useTableContext = function useTableContext() {
39
+ return useContext(TableContext);
40
+ };
41
+
42
+ export { TableProvider, useTableContext };
@@ -0,0 +1,52 @@
1
+ 'use client';
2
+
3
+ import { useMemo } from 'react';
4
+ import { useTableContext } from './Context.js';
5
+ import { COL_DEFAULT_WIDTH, COL_MIN_WIDTH, COL_MAX_WIDTH } from './types.js';
6
+ import { jsx } from 'react/jsx-runtime';
7
+
8
+ /*
9
+ * React Fabric
10
+ * @version: 1.0.0
11
+ *
12
+ *
13
+ * The MIT License (MIT)
14
+ * Copyright (c) 2024 Adarsh Pastakia
15
+ *
16
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
17
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
18
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
19
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
20
+ * subject to the following conditions:
21
+ *
22
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
23
+ * portions of the Software.
24
+ *
25
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
26
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
28
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
+ */
30
+
31
+ var EmptyCell = function EmptyCell(_ref) {
32
+ var id = _ref.id,
33
+ _width = _ref.width,
34
+ maxWidth = _ref.maxWidth,
35
+ minWidth = _ref.minWidth;
36
+ var _useTableContext = useTableContext(),
37
+ widths = _useTableContext.widths;
38
+ var width = useMemo(function () {
39
+ var _widths$get;
40
+ return (_widths$get = widths.get(id.toString())) !== null && _widths$get !== void 0 ? _widths$get : _width;
41
+ }, [widths, id, _width]);
42
+ return /*#__PURE__*/jsx("div", {
43
+ className: "overflow-hidden border-e",
44
+ style: {
45
+ width: width !== null && width !== void 0 ? width : COL_DEFAULT_WIDTH,
46
+ minWidth: minWidth !== null && minWidth !== void 0 ? minWidth : COL_MIN_WIDTH,
47
+ maxWidth: maxWidth !== null && maxWidth !== void 0 ? maxWidth : COL_MAX_WIDTH
48
+ }
49
+ }, "blank:".concat(id.toString()));
50
+ };
51
+
52
+ export { EmptyCell };
@@ -1,7 +1,10 @@
1
1
  'use client';
2
2
 
3
- import { Icon, Dropdown, CoreIcons, Menu, MenuItem } from '@react-fabric/core';
4
- import { jsxs, jsx } from 'react/jsx-runtime';
3
+ import { MenuItem, CoreIcons, Tooltip, Icon, DropdownTool, Menu } from '@react-fabric/core';
4
+ import { useMemo, useCallback } from 'react';
5
+ import { useTableContext } from './Context.js';
6
+ import { COL_DEFAULT_WIDTH, COL_MIN_WIDTH, COL_MAX_WIDTH } from './types.js';
7
+ import { jsx, jsxs } from 'react/jsx-runtime';
5
8
 
6
9
  /*
7
10
  * React Fabric
@@ -27,51 +30,94 @@ import { jsxs, jsx } from 'react/jsx-runtime';
27
30
  */
28
31
 
29
32
  var HeaderCell = function HeaderCell(_ref) {
30
- var label = _ref.label,
33
+ var id = _ref.id,
34
+ label = _ref.label,
31
35
  icon = _ref.icon,
32
36
  iconBg = _ref.iconBg,
33
37
  iconColor = _ref.iconColor,
34
38
  rtlFlip = _ref.rtlFlip;
35
39
  _ref.actions;
36
40
  _ref.locked;
37
- var resizable = _ref.resizable,
38
- width = _ref.width,
41
+ var tooltip = _ref.tooltip,
42
+ sortable = _ref.sortable,
43
+ resizable = _ref.resizable,
44
+ _width = _ref.width,
39
45
  maxWidth = _ref.maxWidth,
40
- minWidth = _ref.minWidth;
46
+ minWidth = _ref.minWidth,
47
+ sort = _ref.sort,
48
+ onSort = _ref.onSort;
49
+ var _useTableContext = useTableContext(),
50
+ startResize = _useTableContext.startResize,
51
+ widths = _useTableContext.widths;
52
+ var width = useMemo(function () {
53
+ var _widths$get;
54
+ return (_widths$get = widths.get(id.toString())) !== null && _widths$get !== void 0 ? _widths$get : _width;
55
+ }, [widths, _width, id]);
56
+ var handleSort = useCallback(function () {
57
+ sortable && (onSort === null || onSort === void 0 ? void 0 : onSort({
58
+ id: id.toString(),
59
+ order: (sort === null || sort === void 0 ? void 0 : sort.id) === id && sort.order === "asc" ? "desc" : "asc"
60
+ }));
61
+ }, [onSort, name, sort, sortable]);
62
+ var menus = useMemo(function () {
63
+ var ret = [];
64
+ if (sortable) {
65
+ ret.push( /*#__PURE__*/jsx(MenuItem, {
66
+ label: "Sort ascending",
67
+ icon: CoreIcons.sortAsc
68
+ }, "sort-asc"), /*#__PURE__*/jsx(MenuItem, {
69
+ label: "Sort descending",
70
+ icon: CoreIcons.sortDesc
71
+ }, "sort-desc"));
72
+ }
73
+ return ret;
74
+ }, [sortable]);
41
75
  return /*#__PURE__*/jsxs("div", {
42
- className: "group font-medium border-e flex flex-nowrap text-start items-center",
76
+ role: "none",
77
+ "data-id": id,
78
+ onClick: handleSort,
79
+ className: "group font-medium border-e flex flex-nowrap text-start items-center table-header-cell",
43
80
  style: {
44
- width: width !== null && width !== void 0 ? width : "12rem",
45
- minWidth: minWidth !== null && minWidth !== void 0 ? minWidth : "2rem",
46
- maxWidth: maxWidth !== null && maxWidth !== void 0 ? maxWidth : "32rem"
81
+ width: width !== null && width !== void 0 ? width : COL_DEFAULT_WIDTH,
82
+ minWidth: minWidth !== null && minWidth !== void 0 ? minWidth : COL_MIN_WIDTH,
83
+ maxWidth: maxWidth !== null && maxWidth !== void 0 ? maxWidth : COL_MAX_WIDTH
47
84
  },
48
- children: [/*#__PURE__*/jsxs("div", {
49
- className: "flex-1 px-2 py-1 text-sm truncate sticky start-0",
50
- children: [icon && /*#__PURE__*/jsx(Icon, {
51
- icon: icon,
52
- bg: iconBg,
53
- color: iconColor,
54
- rtlFlip: rtlFlip
55
- }), /*#__PURE__*/jsx("span", {
56
- children: label !== null && label !== void 0 ? label : " "
57
- })]
58
- }), /*#__PURE__*/jsxs(Dropdown, {
59
- placement: "bottom-start",
60
- children: [/*#__PURE__*/jsx(Icon, {
61
- icon: CoreIcons.caretDown,
62
- className: "outline bg-base me-0.5 flex-content hidden group-hover:inline-block data-[dropdown-open]:inline-block"
63
- }), /*#__PURE__*/jsxs(Menu, {
64
- className: "text-sm",
65
- children: [/*#__PURE__*/jsx(MenuItem, {
66
- label: "Sort ascending",
67
- icon: CoreIcons.sortAsc
68
- }), /*#__PURE__*/jsx(MenuItem, {
69
- label: "Sort descending",
70
- icon: CoreIcons.sortDesc
85
+ children: [/*#__PURE__*/jsx(Tooltip, {
86
+ content: tooltip !== null && tooltip !== void 0 ? tooltip : label,
87
+ disabled: !(tooltip !== null && tooltip !== void 0 ? tooltip : label),
88
+ children: /*#__PURE__*/jsxs("div", {
89
+ className: "flex-initial px-2 py-1 text-sm truncate sticky start-0",
90
+ children: [icon && /*#__PURE__*/jsx(Icon, {
91
+ icon: icon,
92
+ bg: iconBg,
93
+ color: iconColor,
94
+ rtlFlip: rtlFlip
95
+ }), /*#__PURE__*/jsx("span", {
96
+ children: label !== null && label !== void 0 ? label : " "
71
97
  })]
98
+ })
99
+ }), sortable && /*#__PURE__*/jsxs("div", {
100
+ className: "text-sm text-tint-300",
101
+ children: [(sort === null || sort === void 0 ? void 0 : sort.id) === id && (sort === null || sort === void 0 ? void 0 : sort.order) === "desc" && /*#__PURE__*/jsx("span", {
102
+ children: "\u25BC"
103
+ }), (sort === null || sort === void 0 ? void 0 : sort.id) === id && (sort === null || sort === void 0 ? void 0 : sort.order) === "asc" && /*#__PURE__*/jsx("span", {
104
+ children: "\u25B2"
72
105
  })]
106
+ }), /*#__PURE__*/jsx("div", {
107
+ className: "flex-1"
108
+ }), menus.length > 0 && /*#__PURE__*/jsx(DropdownTool, {
109
+ groupHover: true,
110
+ placement: "bottom-end",
111
+ children: /*#__PURE__*/jsx(Menu, {
112
+ className: "text-sm",
113
+ children: menus
114
+ })
73
115
  }), resizable && /*#__PURE__*/jsx("div", {
74
- className: "cursor-col-resize border-e bg-transparent border-tint-200 w-[5px] self-stretch"
116
+ role: "none",
117
+ className: "cursor-col-resize border-e bg-transparent border-tint-200 w-[5px] self-stretch",
118
+ onMouseDown: function onMouseDown(e) {
119
+ return e.currentTarget.parentElement && startResize(e.currentTarget.parentElement);
120
+ }
75
121
  })]
76
122
  });
77
123
  };