@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.
- package/{src/histogram/Histogram.module.css → css/_histogram.css} +16 -13
- package/css/styles.css +24 -0
- package/dist/cjs/checklist/CheckList.js +59 -33
- package/dist/cjs/histogram/Histogram.js +41 -26
- package/dist/cjs/hooks/useFilteredList.js +100 -17
- package/dist/cjs/hooks/usePagination.js +29 -8
- package/dist/cjs/hooks/useSelectableList.js +30 -5
- package/dist/cjs/i18n/{ar.json.js → ar/data.json.js} +8 -1
- package/dist/cjs/i18n/{en.json.js → en/data.json.js} +8 -1
- package/dist/cjs/i18n/index.js +4 -4
- package/dist/cjs/index.js +30 -0
- package/dist/cjs/json/JsonViewer.js +80 -43
- package/dist/cjs/pagination/Pagination.js +24 -15
- package/dist/cjs/table/AddColumn.js +5 -5
- package/dist/cjs/table/BodyCell.js +20 -13
- package/dist/cjs/table/BodyRow.js +41 -28
- package/dist/cjs/table/CheckboxCell.js +10 -9
- package/dist/cjs/table/ColumnFilters.js +100 -0
- package/dist/cjs/table/EmptyCell.js +4 -4
- package/dist/cjs/table/HeaderCell.js +79 -53
- package/dist/cjs/table/HtmlTable.js +84 -0
- package/dist/cjs/table/{Context.js → Provider.js} +8 -10
- package/dist/cjs/table/Table.js +99 -33
- package/dist/cjs/{tree/types.js → table/context.js} +9 -5
- package/dist/cjs/table/types.js +29 -0
- package/dist/cjs/table/useResizer.js +10 -10
- package/dist/cjs/table/useTableColumns.js +4 -4
- package/dist/cjs/table/useVirtualTable.js +129 -22
- package/dist/cjs/tree/TreeNode.js +66 -46
- package/dist/cjs/tree/TreePanel.js +60 -24
- package/dist/cjs/tree/useTree.js +212 -47
- package/dist/cjs/tree/utils.js +63 -34
- package/dist/cjs/utils/getColor.js +58 -0
- package/dist/cjs/virtual/Gallery.js +119 -61
- package/dist/cjs/virtual/List.js +116 -55
- package/dist/cjs/virtual/Scroller.js +16 -8
- package/dist/esm/checklist/CheckList.js +61 -35
- package/dist/esm/histogram/Histogram.js +43 -28
- package/dist/esm/hooks/useFilteredList.js +101 -18
- package/dist/esm/hooks/usePagination.js +29 -8
- package/dist/esm/hooks/useSelectableList.js +30 -5
- package/dist/esm/i18n/{ar.json.js → ar/data.json.js} +8 -2
- package/dist/esm/i18n/{en.json.js → en/data.json.js} +8 -2
- package/dist/esm/i18n/index.js +2 -2
- package/dist/esm/index.js +31 -0
- package/dist/esm/json/JsonViewer.js +82 -45
- package/dist/esm/pagination/Pagination.js +25 -16
- package/dist/esm/table/AddColumn.js +6 -6
- package/dist/esm/table/BodyCell.js +21 -14
- package/dist/esm/table/BodyRow.js +41 -28
- package/dist/esm/table/CheckboxCell.js +11 -10
- package/dist/esm/table/ColumnFilters.js +100 -0
- package/dist/esm/table/EmptyCell.js +4 -4
- package/dist/esm/table/HeaderCell.js +80 -54
- package/dist/esm/table/HtmlTable.js +84 -0
- package/dist/esm/table/{Context.js → Provider.js} +11 -12
- package/dist/esm/table/Table.js +100 -34
- package/dist/esm/{tree/types.js → table/context.js} +8 -4
- package/dist/esm/table/types.js +29 -0
- package/dist/esm/table/useResizer.js +10 -10
- package/dist/esm/table/useTableColumns.js +4 -4
- package/dist/esm/table/useVirtualTable.js +131 -24
- package/dist/esm/tree/TreeNode.js +69 -49
- package/dist/esm/tree/TreePanel.js +62 -26
- package/dist/esm/tree/useTree.js +215 -50
- package/dist/esm/tree/utils.js +64 -35
- package/dist/esm/utils/getColor.js +58 -0
- package/dist/esm/virtual/Gallery.js +121 -63
- package/dist/esm/virtual/List.js +118 -57
- package/dist/esm/virtual/Scroller.js +17 -9
- package/dist/types/checklist/CheckList.d.ts +25 -6
- package/dist/types/histogram/Histogram.d.ts +28 -6
- package/dist/types/hooks/useFilteredList.d.ts +62 -5
- package/dist/types/hooks/usePagination.d.ts +18 -2
- package/dist/types/hooks/useSelectableList.d.ts +24 -1
- package/dist/types/index.d.ts +27 -0
- package/dist/types/json/JsonViewer.d.ts +23 -3
- package/dist/types/pagination/Pagination.d.ts +8 -2
- package/dist/types/table/AddColumn.d.ts +2 -2
- package/dist/types/table/BodyCell.d.ts +2 -2
- package/dist/types/table/BodyRow.d.ts +9 -9
- package/dist/types/table/CheckboxCell.d.ts +3 -3
- package/dist/types/table/ColumnFilters.d.ts +12 -0
- package/dist/types/table/EmptyCell.d.ts +1 -1
- package/dist/types/table/HeaderCell.d.ts +1 -1
- package/dist/types/table/HtmlTable.d.ts +21 -0
- package/dist/types/table/Provider.d.ts +2 -0
- package/dist/types/table/Table.d.ts +10 -1
- package/dist/types/table/context.d.ts +7 -0
- package/dist/types/table/types.d.ts +52 -10
- package/dist/types/table/useResizer.d.ts +1 -1
- package/dist/types/table/useTableColumns.d.ts +1 -1
- package/dist/types/table/useVirtualTable.d.ts +31 -12
- package/dist/types/tree/TreeNode.d.ts +1 -1
- package/dist/types/tree/TreePanel.d.ts +36 -1
- package/dist/types/tree/types.d.ts +75 -28
- package/dist/types/tree/useTree.d.ts +8 -12
- package/dist/types/tree/utils.d.ts +15 -8
- package/dist/types/utils/getColor.d.ts +43 -0
- package/dist/types/virtual/Gallery.d.ts +37 -6
- package/dist/types/virtual/List.d.ts +38 -6
- package/dist/types/virtual/Scroller.d.ts +1 -1
- package/package.json +17 -19
- package/src/checklist/CheckList.tsx +68 -71
- package/src/histogram/Histogram.tsx +47 -48
- package/src/hooks/useFilteredList.tsx +111 -28
- package/src/hooks/usePagination.tsx +39 -39
- package/src/hooks/useSelectableList.ts +45 -33
- package/src/i18n/{ar.json → ar/data.json} +5 -0
- package/src/i18n/{en.json → en/data.json} +5 -0
- package/src/i18n/index.ts +2 -2
- package/src/index.ts +23 -17
- package/src/json/JsonViewer.tsx +89 -120
- package/src/pagination/Pagination.tsx +104 -105
- package/src/table/AddColumn.tsx +6 -15
- package/src/table/BodyCell.tsx +27 -36
- package/src/table/BodyRow.tsx +36 -59
- package/src/table/CheckboxCell.tsx +12 -15
- package/src/table/ColumnFilters.tsx +93 -0
- package/src/table/EmptyCell.tsx +5 -18
- package/src/table/HeaderCell.tsx +72 -53
- package/src/table/HtmlTable.tsx +106 -0
- package/src/table/{Context.tsx → Provider.tsx} +11 -28
- package/src/table/Table.tsx +98 -83
- package/src/table/context.ts +33 -0
- package/src/table/types.ts +53 -27
- package/src/table/useResizer.ts +5 -9
- package/src/table/useTableColumns.ts +4 -6
- package/src/table/useVirtualTable.ts +136 -37
- package/src/tree/TreeNode.tsx +91 -86
- package/src/tree/TreePanel.tsx +87 -51
- package/src/tree/types.ts +85 -46
- package/src/tree/useTree.ts +210 -65
- package/src/tree/utils.ts +81 -62
- package/src/utils/getColor.ts +55 -0
- package/src/virtual/Gallery.tsx +129 -120
- package/src/virtual/List.tsx +124 -91
- package/src/virtual/Scroller.tsx +25 -9
- package/dist/cjs/histogram/Histogram.module.css +0 -1
- package/dist/esm/histogram/Histogram.module.css +0 -1
- package/dist/types/table/Context.d.ts +0 -8
|
@@ -2,77 +2,101 @@
|
|
|
2
2
|
|
|
3
3
|
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
4
4
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
5
|
-
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
6
5
|
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import { useState, useEffect, useMemo,
|
|
6
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
7
|
+
import { EmptyContent, Icon, Badge } from '@react-fabric/core';
|
|
8
|
+
import { useState, useEffect, useMemo, Fragment } from 'react';
|
|
10
9
|
import { useTranslation } from 'react-i18next';
|
|
11
10
|
import { useSelectableList } from '../hooks/useSelectableList.js';
|
|
12
11
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
13
12
|
|
|
14
|
-
var _excluded = ["
|
|
15
|
-
_excluded2 = ["items", "maxCount", "allowNegative", "emptyMessage", "sortItems", "selected", "nonselected", "onChange", "onClick"];
|
|
13
|
+
var _excluded = ["items", "maxCount", "allowNegative", "emptyMessage", "sortItems", "selected", "nonselected", "onChange", "onClick"];
|
|
16
14
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
17
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t),
|
|
18
|
-
|
|
15
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
16
|
+
function CheckItem(_ref) {
|
|
19
17
|
var id = _ref.id,
|
|
20
18
|
allowNegative = _ref.allowNegative,
|
|
21
19
|
selected = _ref.selected,
|
|
22
20
|
icon = _ref.icon,
|
|
23
21
|
label = _ref.label,
|
|
24
|
-
|
|
22
|
+
disabled = _ref.disabled,
|
|
25
23
|
_onClick = _ref.onClick,
|
|
26
|
-
badge = _ref.badge
|
|
27
|
-
|
|
28
|
-
return /*#__PURE__*/jsxs("div", _objectSpread(_objectSpread({
|
|
24
|
+
badge = _ref.badge;
|
|
25
|
+
return /*#__PURE__*/jsxs("div", {
|
|
29
26
|
role: "none",
|
|
30
27
|
className: "ax-checkList__item",
|
|
31
|
-
"data-disabled":
|
|
28
|
+
"data-disabled": disabled,
|
|
32
29
|
onClick: function onClick() {
|
|
33
30
|
return _onClick(id, false);
|
|
34
31
|
},
|
|
35
32
|
onContextMenu: function onContextMenu(e) {
|
|
36
33
|
return [allowNegative && _onClick(id, true), e.preventDefault()];
|
|
37
|
-
}
|
|
38
|
-
}, aria), {}, {
|
|
34
|
+
},
|
|
39
35
|
children: [!allowNegative && /*#__PURE__*/jsx(Icon, {
|
|
40
36
|
"data-type": "checkbox",
|
|
41
37
|
className: "ax-checkList__checkbox",
|
|
42
38
|
"data-selected": selected === 1,
|
|
43
|
-
icon: selected ?
|
|
39
|
+
icon: selected ? "icon-[mdi--checkbox-marked]" : "icon-[mdi--checkbox-blank-outline]"
|
|
44
40
|
}), allowNegative && /*#__PURE__*/jsxs(Fragment, {
|
|
45
41
|
children: [/*#__PURE__*/jsx(Icon, {
|
|
46
42
|
"data-type": "multiple",
|
|
47
43
|
className: "ax-checkList__checkbox",
|
|
48
|
-
icon: selected === 1 ?
|
|
44
|
+
icon: selected === 1 ? "icon-[mdi--plus-box-outline]" : selected === -1 ? "icon-[mdi--minus-box-outline]" : "icon-[mdi--checkbox-blank-outline]",
|
|
49
45
|
"data-selected": selected
|
|
50
46
|
}), /*#__PURE__*/jsxs("div", {
|
|
51
47
|
className: "ax-checkList__checkbox",
|
|
52
|
-
children: [/*#__PURE__*/jsx(
|
|
53
|
-
|
|
48
|
+
children: [/*#__PURE__*/jsx("button", {
|
|
49
|
+
type: "button",
|
|
50
|
+
className: "size-fit leading-0 cursor-pointer",
|
|
54
51
|
onClick: function onClick(e) {
|
|
55
52
|
return [(_onClick(id, false), e.stopPropagation())];
|
|
56
53
|
},
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
54
|
+
children: /*#__PURE__*/jsx(Icon, {
|
|
55
|
+
"data-type": "positive",
|
|
56
|
+
icon: selected === 1 ? "icon-[mdi--plus-box]" : "icon-[mdi--plus-box-outline]",
|
|
57
|
+
"data-selected": selected === 1
|
|
58
|
+
})
|
|
59
|
+
}), /*#__PURE__*/jsx("button", {
|
|
60
|
+
type: "button",
|
|
61
|
+
className: "size-fit leading-0 cursor-pointer",
|
|
61
62
|
onClick: function onClick(e) {
|
|
62
63
|
return [(_onClick(id, true), e.stopPropagation())];
|
|
63
64
|
},
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
children: /*#__PURE__*/jsx(Icon, {
|
|
66
|
+
"data-type": "negative",
|
|
67
|
+
icon: selected === -1 ? "icon-[mdi--minus-box]" : "icon-[mdi--minus-box-outline]",
|
|
68
|
+
"data-selected": selected === -1
|
|
69
|
+
})
|
|
66
70
|
})]
|
|
67
71
|
})]
|
|
68
|
-
}),
|
|
72
|
+
}), icon && /*#__PURE__*/jsx(Icon, {
|
|
69
73
|
icon: icon
|
|
70
74
|
}), /*#__PURE__*/jsx("label", {
|
|
71
75
|
children: label
|
|
72
|
-
}), /*#__PURE__*/jsx(Badge, _objectSpread({}, badge))]
|
|
73
|
-
})
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
+
}), badge && /*#__PURE__*/jsx(Badge, _objectSpread({}, badge))]
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* CheckList component to display a list of selectable items with checkboxes.
|
|
82
|
+
* It supports selection, deselection, and allows for negative selections.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```jsx
|
|
86
|
+
* <CheckList
|
|
87
|
+
* items={[
|
|
88
|
+
* { id: "1", label: "Item 1", icon: "icon1" },
|
|
89
|
+
* { id: "2", label: "Item 2", icon: "icon2", badge: { text: "New" } },
|
|
90
|
+
* ]}
|
|
91
|
+
* maxCount={5}
|
|
92
|
+
* allowNegative={true}
|
|
93
|
+
* emptyMessage="No items available"
|
|
94
|
+
* onChange={(selectedItems) => console.log(selectedItems)}
|
|
95
|
+
* onClick={(itemId, isNegative) => console.log(itemId, isNegative)}
|
|
96
|
+
* />
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
function CheckList(_ref2) {
|
|
76
100
|
var _ref2$items = _ref2.items,
|
|
77
101
|
items = _ref2$items === void 0 ? [] : _ref2$items,
|
|
78
102
|
_ref2$maxCount = _ref2.maxCount,
|
|
@@ -85,7 +109,7 @@ var CheckList = function CheckList(_ref2) {
|
|
|
85
109
|
nonselected = _ref2.nonselected,
|
|
86
110
|
onChange = _ref2.onChange,
|
|
87
111
|
onClick = _ref2.onClick,
|
|
88
|
-
aria = _objectWithoutProperties(_ref2,
|
|
112
|
+
aria = _objectWithoutProperties(_ref2, _excluded);
|
|
89
113
|
var _useTranslation = useTranslation("data"),
|
|
90
114
|
t = _useTranslation.t;
|
|
91
115
|
var _useSelectableList = useSelectableList({
|
|
@@ -102,6 +126,7 @@ var CheckList = function CheckList(_ref2) {
|
|
|
102
126
|
showMore = _useState2[0],
|
|
103
127
|
setShowMore = _useState2[1];
|
|
104
128
|
useEffect(function () {
|
|
129
|
+
// eslint-disable-next-line @eslint-react/set-state-in-effect
|
|
105
130
|
setShowMore(false);
|
|
106
131
|
}, [items]);
|
|
107
132
|
var listItems = useMemo(function () {
|
|
@@ -117,12 +142,13 @@ var CheckList = function CheckList(_ref2) {
|
|
|
117
142
|
}, [items, selection, maxCount, showMore, sortItems]);
|
|
118
143
|
return /*#__PURE__*/jsxs("div", _objectSpread(_objectSpread({}, aria), {}, {
|
|
119
144
|
children: [listItems.map(function (item, index) {
|
|
120
|
-
return /*#__PURE__*/
|
|
121
|
-
|
|
145
|
+
return /*#__PURE__*/jsx(CheckItem
|
|
146
|
+
// eslint-disable-next-line @eslint-react/no-array-index-key
|
|
147
|
+
, _objectSpread(_objectSpread({}, item), {}, {
|
|
122
148
|
onClick: toggleSelection,
|
|
123
149
|
allowNegative: allowNegative,
|
|
124
150
|
selected: selection[item.id]
|
|
125
|
-
}));
|
|
151
|
+
}), index);
|
|
126
152
|
}), maxCount > 0 && items.length > maxCount && /*#__PURE__*/jsx("div", {
|
|
127
153
|
className: "ax-moreLink",
|
|
128
154
|
children: /*#__PURE__*/jsxs("span", {
|
|
@@ -138,6 +164,6 @@ var CheckList = function CheckList(_ref2) {
|
|
|
138
164
|
message: emptyMessage !== null && emptyMessage !== void 0 ? emptyMessage : t("checkList.empty")
|
|
139
165
|
})]
|
|
140
166
|
}));
|
|
141
|
-
}
|
|
167
|
+
}
|
|
142
168
|
|
|
143
169
|
export { CheckList };
|
|
@@ -1,32 +1,48 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
4
3
|
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import { compareValues, Format } from '@react-fabric/utilities';
|
|
8
|
-
import classNames from 'classnames';
|
|
4
|
+
import { EmptyContent, Icon, ActionLabel, Button } from '@react-fabric/core';
|
|
5
|
+
import { compareValues, cn, Format } from '@react-fabric/utilities';
|
|
9
6
|
import { useMemo } from 'react';
|
|
10
7
|
import { useTranslation } from 'react-i18next';
|
|
11
|
-
import
|
|
8
|
+
import { getColor } from '../utils/getColor.js';
|
|
12
9
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
13
10
|
|
|
14
|
-
var _excluded = ["items", "total", "color", "sortBy", "emptyTitle", "emptyMessage", "onClick"];
|
|
15
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
16
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
17
11
|
var emptyIcon = "M20.84 22.73L11.11 13H3V11H9.11L6.11 8H3V6H4.11L1.11 3L2.39 1.73L22.11 21.46L20.84 22.73M15 11H14.2L15 11.8V11M21 8V6H9.2L11.2 8H21M3 18H9V16H3V18Z";
|
|
18
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Histogram component displays a bar chart of items with counts.
|
|
14
|
+
* It allows users to visualize the distribution of counts across different items.
|
|
15
|
+
* The component supports sorting, custom colors, and click handling for each item.
|
|
16
|
+
* It also provides an empty state when there are no items to display.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```jsx
|
|
20
|
+
* <Histogram
|
|
21
|
+
* items={[
|
|
22
|
+
* { id: "1", label: "Item 1", count: 10 },
|
|
23
|
+
* { id: "2", label: "Item 2", count: 20 },
|
|
24
|
+
* { id: "3", label: "Item 3", count: 5, disabled: true },
|
|
25
|
+
* ]}
|
|
26
|
+
* total={30}
|
|
27
|
+
* color="primary-500"
|
|
28
|
+
* sortBy="count"
|
|
29
|
+
* emptyTitle="No Data Available"
|
|
30
|
+
* emptyMessage="Please check back later."
|
|
31
|
+
* onClick={(id, negative) => console.log(`Clicked on ${id}`, negative ? "Negative" : "Positive")}
|
|
32
|
+
* />
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
function Histogram(_ref) {
|
|
19
36
|
var _ref$items = _ref.items,
|
|
20
37
|
items = _ref$items === void 0 ? [] : _ref$items,
|
|
21
38
|
total = _ref.total,
|
|
22
39
|
_ref$color = _ref.color,
|
|
23
|
-
color = _ref$color === void 0 ? "primary" : _ref$color,
|
|
40
|
+
color = _ref$color === void 0 ? "primary-500" : _ref$color,
|
|
24
41
|
_ref$sortBy = _ref.sortBy,
|
|
25
42
|
sortBy = _ref$sortBy === void 0 ? "count" : _ref$sortBy,
|
|
26
43
|
emptyTitle = _ref.emptyTitle,
|
|
27
44
|
emptyMessage = _ref.emptyMessage,
|
|
28
|
-
_onClick = _ref.onClick
|
|
29
|
-
aria = _objectWithoutProperties(_ref, _excluded);
|
|
45
|
+
_onClick = _ref.onClick;
|
|
30
46
|
var _useTranslation = useTranslation("data"),
|
|
31
47
|
t = _useTranslation.t;
|
|
32
48
|
var maxTotal = useMemo(function () {
|
|
@@ -38,11 +54,10 @@ var Histogram = function Histogram(_ref) {
|
|
|
38
54
|
var sorted = useMemo(function () {
|
|
39
55
|
return items.sort(compareValues(sortBy === "label" ? "asc" : "desc", sortBy));
|
|
40
56
|
}, [items, sortBy]);
|
|
41
|
-
return /*#__PURE__*/jsxs("div",
|
|
42
|
-
className:
|
|
43
|
-
}, aria), {}, {
|
|
57
|
+
return /*#__PURE__*/jsxs("div", {
|
|
58
|
+
className: "fabric-histogram from-0% to-100%",
|
|
44
59
|
style: {
|
|
45
|
-
"--color":
|
|
60
|
+
"--color": getColor(color)
|
|
46
61
|
},
|
|
47
62
|
children: [sorted.length === 0 && /*#__PURE__*/jsx(EmptyContent, {
|
|
48
63
|
icon: /*#__PURE__*/jsx(Icon, {
|
|
@@ -56,13 +71,13 @@ var Histogram = function Histogram(_ref) {
|
|
|
56
71
|
return /*#__PURE__*/jsxs("div", {
|
|
57
72
|
role: "none",
|
|
58
73
|
"data-disabled": item.count === 0 || item.disabled,
|
|
59
|
-
className:
|
|
74
|
+
className: cn("relative cursor-pointer flex flex-nowrap items-center select-none overflow-hidden min-h-6 my-px", "fabric-histoLabel", (((_item$total = item.total) !== null && _item$total !== void 0 ? _item$total : item.count) === 0 || item.disabled) && "pointer-events-none"),
|
|
60
75
|
"data-testid": item.id,
|
|
61
76
|
onClick: function onClick(e) {
|
|
62
77
|
return [_onClick === null || _onClick === void 0 ? void 0 : _onClick(item.id), e.stopPropagation()];
|
|
63
78
|
},
|
|
64
79
|
children: [/*#__PURE__*/jsx("div", {
|
|
65
|
-
className:
|
|
80
|
+
className: cn("absolute z-0 inset-0 opacity-50 min-w-2 ltr:bg-linear-to-r rtl:bg-linear-to-l", "fabric-histoBar"),
|
|
66
81
|
style: {
|
|
67
82
|
width: "".concat(Math.min(item.count / maxTotal, 1) * 100, "%")
|
|
68
83
|
}
|
|
@@ -71,28 +86,28 @@ var Histogram = function Histogram(_ref) {
|
|
|
71
86
|
actions: [/*#__PURE__*/jsx(Button, {
|
|
72
87
|
color: "danger",
|
|
73
88
|
size: "sm",
|
|
74
|
-
icon:
|
|
89
|
+
icon: "icon-[mdi--filter-minus]",
|
|
75
90
|
"aria-label": "Filter Negative",
|
|
76
|
-
onClick: function onClick() {
|
|
77
|
-
return _onClick === null || _onClick === void 0 ? void 0 : _onClick(item.id, true);
|
|
91
|
+
onClick: function onClick(e) {
|
|
92
|
+
return e !== null && e !== void 0 && e.stopPropagation(), _onClick === null || _onClick === void 0 ? void 0 : _onClick(item.id, true);
|
|
78
93
|
}
|
|
79
94
|
}, "negative"), /*#__PURE__*/jsx(Button, {
|
|
80
95
|
color: "primary",
|
|
81
96
|
size: "sm",
|
|
82
|
-
icon:
|
|
97
|
+
icon: "icon-[mdi--filter-plus]",
|
|
83
98
|
"aria-label": "Filter",
|
|
84
|
-
onClick: function onClick() {
|
|
85
|
-
return _onClick === null || _onClick === void 0 ? void 0 : _onClick(item.id);
|
|
99
|
+
onClick: function onClick(e) {
|
|
100
|
+
return e !== null && e !== void 0 && e.stopPropagation(), _onClick === null || _onClick === void 0 ? void 0 : _onClick(item.id);
|
|
86
101
|
}
|
|
87
102
|
}, "positive")],
|
|
88
103
|
children: item.label
|
|
89
104
|
}), /*#__PURE__*/jsx("span", {
|
|
90
|
-
className:
|
|
105
|
+
className: cn("z-1 rounded-full text-xs font-medium px-2 py-1 leading-none", "fabric-histoBadge"),
|
|
91
106
|
children: Format.number(item.count)
|
|
92
107
|
})]
|
|
93
108
|
}, item.id);
|
|
94
109
|
})]
|
|
95
|
-
})
|
|
96
|
-
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
97
112
|
|
|
98
113
|
export { Histogram };
|
|
@@ -1,20 +1,34 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
4
|
-
import {
|
|
4
|
+
import { isArray, matchString, isString } from '@react-fabric/utilities';
|
|
5
5
|
import { useState, useDeferredValue, useTransition, useCallback, useEffect } from 'react';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
function filterList(items) {
|
|
8
8
|
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
|
|
9
|
-
var
|
|
9
|
+
var matchAll = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
10
|
+
var matcher = arguments.length > 3 ? arguments[3] : undefined;
|
|
10
11
|
var newList = [];
|
|
11
12
|
items.forEach(function (item) {
|
|
12
13
|
if (matcher) {
|
|
13
|
-
|
|
14
|
+
if (matcher !== null && matcher !== void 0 && matcher(item, query)) return newList.push(item);
|
|
14
15
|
}
|
|
15
|
-
if (query &&
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
if (query && isArray(query) && query.length > 0) {
|
|
17
|
+
if (matchAll && query.every(function (q) {
|
|
18
|
+
var _item$label;
|
|
19
|
+
return matchString((_item$label = item.label) !== null && _item$label !== void 0 ? _item$label : item.toString(), q);
|
|
20
|
+
})) {
|
|
21
|
+
return newList.push(item);
|
|
22
|
+
}
|
|
23
|
+
if (!matchAll && query.some(function (q) {
|
|
24
|
+
var _item$label2;
|
|
25
|
+
return matchString((_item$label2 = item.label) !== null && _item$label2 !== void 0 ? _item$label2 : item.toString(), q);
|
|
26
|
+
})) {
|
|
27
|
+
return newList.push(item);
|
|
28
|
+
}
|
|
29
|
+
} else if (query && isString(query)) {
|
|
30
|
+
var _item$label3;
|
|
31
|
+
if (matchString((_item$label3 = item.label) !== null && _item$label3 !== void 0 ? _item$label3 : item.toString(), query)) {
|
|
18
32
|
return newList.push(item);
|
|
19
33
|
}
|
|
20
34
|
} else {
|
|
@@ -22,14 +36,74 @@ var filterList = function filterList(items) {
|
|
|
22
36
|
}
|
|
23
37
|
});
|
|
24
38
|
return newList;
|
|
25
|
-
}
|
|
26
|
-
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Custom hook to filter a list of items based on a query.
|
|
43
|
+
* It provides a way to search through the items and returns the filtered list.
|
|
44
|
+
* The hook uses a deferred value to optimize performance during transitions.
|
|
45
|
+
* It also allows for a custom matcher function to define how items should be matched against the query.
|
|
46
|
+
*
|
|
47
|
+
* @param items - The list of items to filter.
|
|
48
|
+
* @param matchAll - Match all phrases in the query list against the items.
|
|
49
|
+
* @returns An object containing the search function, current query, filtered list, and a boolean indicating if a search is in progress.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```jsx
|
|
53
|
+
* useFilteredList(items, (item, query) => {
|
|
54
|
+
* return item.name.includes(query);
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/data-usefilteredlist--docs}
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Custom hook to filter a list of items based on a query.
|
|
63
|
+
* It provides a way to search through the items and returns the filtered list.
|
|
64
|
+
* The hook uses a deferred value to optimize performance during transitions.
|
|
65
|
+
* It also allows for a custom matcher function to define how items should be matched against the query.
|
|
66
|
+
*
|
|
67
|
+
* @param items - The list of items to filter.
|
|
68
|
+
* @param matcher - An optional function to match items against the query.
|
|
69
|
+
* @returns An object containing the search function, current query, filtered list, and a boolean indicating if a search is in progress.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```jsx
|
|
73
|
+
* useFilteredList(items, (item, query) => {
|
|
74
|
+
* return item.name.includes(query);
|
|
75
|
+
* });
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Custom hook to filter a list of items based on a query.
|
|
81
|
+
* It provides a way to search through the items and returns the filtered list.
|
|
82
|
+
* The hook uses a deferred value to optimize performance during transitions.
|
|
83
|
+
* It also allows for a custom matcher function to define how items should be matched against the query.
|
|
84
|
+
*
|
|
85
|
+
* @param items - The list of items to filter.
|
|
86
|
+
* @param matchAll - Match all phrases in the query list against the items.
|
|
87
|
+
* @param matcher - An optional function to match items against the query.
|
|
88
|
+
* @returns An object containing the search function, current query, filtered list, and a boolean indicating if a search is in progress.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```jsx
|
|
92
|
+
* useFilteredList(items, (item, query) => {
|
|
93
|
+
* return item.name.includes(query);
|
|
94
|
+
* });
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
function useFilteredList(items, matchAll, matcher) {
|
|
27
99
|
var _useState = useState(),
|
|
28
100
|
_useState2 = _slicedToArray(_useState, 2),
|
|
29
101
|
query = _useState2[0],
|
|
30
102
|
setQuery = _useState2[1];
|
|
31
103
|
var _items = useDeferredValue(items !== null && items !== void 0 ? items : []);
|
|
32
|
-
var _useState3 = useState(
|
|
104
|
+
var _useState3 = useState(function () {
|
|
105
|
+
return [];
|
|
106
|
+
}),
|
|
33
107
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
34
108
|
filteredList = _useState4[0],
|
|
35
109
|
setFilteredList = _useState4[1];
|
|
@@ -37,20 +111,29 @@ var useFilteredList = function useFilteredList(items, matcher) {
|
|
|
37
111
|
_useTransition2 = _slicedToArray(_useTransition, 2),
|
|
38
112
|
isSearching = _useTransition2[0],
|
|
39
113
|
startTransition = _useTransition2[1];
|
|
40
|
-
var
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
114
|
+
var matchingAll = typeof matchAll === "boolean" ? matchAll : true;
|
|
115
|
+
var matcherFn = typeof matchAll === "function" ? matchAll : matcher;
|
|
116
|
+
var filterItems = useCallback(function (items, query, matchingAll) {
|
|
117
|
+
return (
|
|
118
|
+
// eslint-disable-next-line @eslint-react/set-state-in-effect
|
|
119
|
+
startTransition(function () {
|
|
120
|
+
return setFilteredList(filterList(items, query, matchingAll, matcherFn));
|
|
121
|
+
})
|
|
122
|
+
);
|
|
123
|
+
},
|
|
124
|
+
// eslint-disable-next-line @eslint-react/exhaustive-deps
|
|
125
|
+
[]);
|
|
45
126
|
useEffect(function () {
|
|
46
|
-
if (query) filterItems(_items, query
|
|
47
|
-
|
|
127
|
+
if (query) filterItems(_items, query, matchingAll);
|
|
128
|
+
// eslint-disable-next-line @eslint-react/set-state-in-effect
|
|
129
|
+
else setFilteredList(items);
|
|
130
|
+
}, [query, matchingAll, _items, filterItems, items]);
|
|
48
131
|
return {
|
|
49
132
|
onSearch: setQuery,
|
|
50
133
|
query: query,
|
|
51
134
|
filteredList: filteredList,
|
|
52
135
|
isSearching: isSearching
|
|
53
136
|
};
|
|
54
|
-
}
|
|
137
|
+
}
|
|
55
138
|
|
|
56
139
|
export { useFilteredList };
|
|
@@ -7,15 +7,32 @@ import { jsxs } from 'react/jsx-runtime';
|
|
|
7
7
|
var TOTAL_PILLS = 12;
|
|
8
8
|
var TOTAL_SIBLINGS = 2;
|
|
9
9
|
var TOTAL_MID_SIBLINGS = 3;
|
|
10
|
-
|
|
10
|
+
function makeRange(start, end) {
|
|
11
11
|
var length = end - start;
|
|
12
12
|
return Array.from({
|
|
13
13
|
length: length
|
|
14
14
|
}, function (_, idx) {
|
|
15
15
|
return idx + start;
|
|
16
16
|
});
|
|
17
|
-
}
|
|
18
|
-
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Custom hook to manage pagination state and logic.
|
|
21
|
+
* It calculates the total number of pages, generates page ranges,
|
|
22
|
+
* and provides a way to change the current page.
|
|
23
|
+
* It also handles the transition of page changes to optimize performance.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```jsx
|
|
27
|
+
* const { page, totalPages, headLabel, ranges, onPageChange } = usePagination({
|
|
28
|
+
* totalRecords: 100,
|
|
29
|
+
* currentPage: 0,
|
|
30
|
+
* perPage: 10,
|
|
31
|
+
* onChange: (newPage) => console.log("Page changed to:", newPage),
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
function usePagination(_ref) {
|
|
19
36
|
var totalRecords = _ref.totalRecords,
|
|
20
37
|
_ref$currentPage = _ref.currentPage,
|
|
21
38
|
currentPage = _ref$currentPage === void 0 ? 0 : _ref$currentPage,
|
|
@@ -58,9 +75,13 @@ var usePagination = function usePagination(_ref) {
|
|
|
58
75
|
|
|
59
76
|
/** ***************** set page *******************/
|
|
60
77
|
useEffect(function () {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
78
|
+
if (totalRecords > -1) {
|
|
79
|
+
var actual = Math.min(currentPage, totalPages - 1);
|
|
80
|
+
// eslint-disable-next-line @eslint-react/set-state-in-effect
|
|
81
|
+
setPage(actual);
|
|
82
|
+
if (actual !== currentPage) onChange === null || onChange === void 0 || onChange(actual);
|
|
83
|
+
}
|
|
84
|
+
}, [currentPage, totalRecords, totalPages, onChange]);
|
|
64
85
|
var headLabel = useMemo(function () {
|
|
65
86
|
return /*#__PURE__*/jsxs("span", {
|
|
66
87
|
className: "text-muted",
|
|
@@ -72,7 +93,7 @@ var usePagination = function usePagination(_ref) {
|
|
|
72
93
|
startTransition(function () {
|
|
73
94
|
return onChange === null || onChange === void 0 ? void 0 : onChange(page);
|
|
74
95
|
});
|
|
75
|
-
}, []);
|
|
96
|
+
}, [onChange]);
|
|
76
97
|
return {
|
|
77
98
|
page: page,
|
|
78
99
|
totalPages: totalPages,
|
|
@@ -80,6 +101,6 @@ var usePagination = function usePagination(_ref) {
|
|
|
80
101
|
ranges: ranges,
|
|
81
102
|
onPageChange: onPageChange
|
|
82
103
|
};
|
|
83
|
-
}
|
|
104
|
+
}
|
|
84
105
|
|
|
85
106
|
export { usePagination };
|
|
@@ -5,15 +5,39 @@ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
|
5
5
|
import { useRef, useState, useTransition, useEffect, useCallback } from 'react';
|
|
6
6
|
|
|
7
7
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
8
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t),
|
|
9
|
-
|
|
8
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
9
|
+
/**
|
|
10
|
+
* Custom hook to manage selection of items in a list.
|
|
11
|
+
* It allows toggling selection state of items, handling both selected and non-selected states.
|
|
12
|
+
* The hook maintains a selection state and provides a function to toggle the selection of items.
|
|
13
|
+
* It also supports callbacks for when the selection changes or when an item is clicked.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```jsx
|
|
17
|
+
* const { selection, toggleSelection } = useSelectableList({
|
|
18
|
+
* items: [{ id: '1', label: 'Item 1' }, { id: '2', label: 'Item 2' }],
|
|
19
|
+
* selected: ['1'],
|
|
20
|
+
* nonselected: ['2'],
|
|
21
|
+
* onChange: (selectedIds, nonSelectedIds) => {
|
|
22
|
+
* console.log('Selected:', selectedIds);
|
|
23
|
+
* console.log('Non-selected:', nonSelectedIds);
|
|
24
|
+
* },
|
|
25
|
+
* onClick: (id, isNegative) => {
|
|
26
|
+
* console.log(`Item ${id} clicked, isNegative: ${isNegative}`);
|
|
27
|
+
* },
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
function useSelectableList(_ref) {
|
|
10
32
|
var items = _ref.items,
|
|
11
33
|
selected = _ref.selected,
|
|
12
34
|
nonselected = _ref.nonselected,
|
|
13
35
|
onChange = _ref.onChange,
|
|
14
36
|
onClick = _ref.onClick;
|
|
15
37
|
var selectionRef = useRef({});
|
|
16
|
-
var _useState = useState({
|
|
38
|
+
var _useState = useState(function () {
|
|
39
|
+
return {};
|
|
40
|
+
}),
|
|
17
41
|
_useState2 = _slicedToArray(_useState, 2),
|
|
18
42
|
selection = _useState2[0],
|
|
19
43
|
setSelection = _useState2[1];
|
|
@@ -26,6 +50,7 @@ var useSelectableList = function useSelectableList(_ref) {
|
|
|
26
50
|
var id = _ref2.id;
|
|
27
51
|
return _objectSpread(_objectSpread({}, ret), {}, _defineProperty({}, id, selected !== null && selected !== void 0 && (_selected$includes = selected.includes) !== null && _selected$includes !== void 0 && _selected$includes.call(selected, id) ? 1 : nonselected !== null && nonselected !== void 0 && (_nonselected$includes = nonselected.includes) !== null && _nonselected$includes !== void 0 && _nonselected$includes.call(nonselected, id) ? -1 : 0));
|
|
28
52
|
}, {});
|
|
53
|
+
// eslint-disable-next-line @eslint-react/set-state-in-effect
|
|
29
54
|
setSelection(_objectSpread({}, selectionRef.current));
|
|
30
55
|
}, [items, selected, nonselected]);
|
|
31
56
|
var toggleSelection = useCallback(function (id) {
|
|
@@ -44,11 +69,11 @@ var useSelectableList = function useSelectableList(_ref) {
|
|
|
44
69
|
onClick === null || onClick === void 0 || onClick(id, isNegative);
|
|
45
70
|
onChange === null || onChange === void 0 || onChange(change[0], change[1]);
|
|
46
71
|
});
|
|
47
|
-
}, []);
|
|
72
|
+
}, [onChange, onClick]);
|
|
48
73
|
return {
|
|
49
74
|
selection: selection,
|
|
50
75
|
toggleSelection: toggleSelection
|
|
51
76
|
};
|
|
52
|
-
}
|
|
77
|
+
}
|
|
53
78
|
|
|
54
79
|
export { useSelectableList };
|
|
@@ -34,6 +34,11 @@ var action = {
|
|
|
34
34
|
addFilter: "أضف عامل تصفية",
|
|
35
35
|
addFilterNot: "إضافة لا تصفية"
|
|
36
36
|
};
|
|
37
|
+
var data = {
|
|
38
|
+
tree: {
|
|
39
|
+
noItems: "لا توجد عناصر شجرة متوفرة"
|
|
40
|
+
}
|
|
41
|
+
};
|
|
37
42
|
var ar = {
|
|
38
43
|
label: label,
|
|
39
44
|
tree: tree,
|
|
@@ -41,7 +46,8 @@ var ar = {
|
|
|
41
46
|
json: json,
|
|
42
47
|
checkList: checkList,
|
|
43
48
|
histogram: histogram,
|
|
44
|
-
action: action
|
|
49
|
+
action: action,
|
|
50
|
+
data: data
|
|
45
51
|
};
|
|
46
52
|
|
|
47
|
-
export { action, checkList, datagrid, ar as default, histogram, json, label, tree };
|
|
53
|
+
export { action, checkList, data, datagrid, ar as default, histogram, json, label, tree };
|
|
@@ -34,6 +34,11 @@ var action = {
|
|
|
34
34
|
addFilter: "Add Filter",
|
|
35
35
|
addFilterNot: "Add not Filter"
|
|
36
36
|
};
|
|
37
|
+
var data = {
|
|
38
|
+
tree: {
|
|
39
|
+
noItems: "No tree items available"
|
|
40
|
+
}
|
|
41
|
+
};
|
|
37
42
|
var en = {
|
|
38
43
|
label: label,
|
|
39
44
|
tree: tree,
|
|
@@ -41,7 +46,8 @@ var en = {
|
|
|
41
46
|
json: json,
|
|
42
47
|
checkList: checkList,
|
|
43
48
|
histogram: histogram,
|
|
44
|
-
action: action
|
|
49
|
+
action: action,
|
|
50
|
+
data: data
|
|
45
51
|
};
|
|
46
52
|
|
|
47
|
-
export { action, checkList, datagrid, en as default, histogram, json, label, tree };
|
|
53
|
+
export { action, checkList, data, datagrid, en as default, histogram, json, label, tree };
|
package/dist/esm/i18n/index.js
CHANGED