@digigov/ui 0.32.2 → 0.34.0
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/CHANGELOG.md +23 -1
- package/admin/Drawer/__stories__/Default.js +3 -0
- package/admin/Dropdown/index.d.ts +1 -1
- package/admin/Dropdown/index.js +45 -27
- package/core/CaretContainer/index.d.ts +3 -0
- package/core/CaretContainer/index.js +30 -0
- package/core/Table/Table.stories.d.ts +2 -0
- package/core/Table/Table.stories.js +28 -0
- package/core/Table/Table.stories.playwright.json +16 -0
- package/core/Table/__stories__/Stacked.d.ts +2 -0
- package/core/Table/__stories__/Stacked.js +42 -0
- package/core/Table/__stories__/WithSortFilters.d.ts +2 -0
- package/core/Table/__stories__/WithSortFilters.js +121 -0
- package/core/Table/index.d.ts +14 -1
- package/core/Table/index.js +107 -10
- package/core/index.d.ts +1 -0
- package/core/index.js +13 -0
- package/es/admin/Drawer/__stories__/Default.js +3 -0
- package/es/admin/Dropdown/index.js +45 -27
- package/es/core/CaretContainer/index.js +3 -0
- package/es/core/Table/Table.stories.js +2 -0
- package/es/core/Table/Table.stories.playwright.json +16 -0
- package/es/core/Table/__stories__/Stacked.js +29 -0
- package/es/core/Table/__stories__/WithSortFilters.js +106 -0
- package/es/core/Table/index.js +86 -1
- package/es/core/index.js +1 -0
- package/es/hooks/useSort.js +54 -0
- package/es/registry.js +2 -0
- package/esm/admin/Drawer/__stories__/Default.js +3 -0
- package/esm/admin/Dropdown/index.js +45 -27
- package/esm/core/CaretContainer/index.js +3 -0
- package/esm/core/Table/Table.stories.js +2 -0
- package/esm/core/Table/Table.stories.playwright.json +16 -0
- package/esm/core/Table/__stories__/Stacked.js +29 -0
- package/esm/core/Table/__stories__/WithSortFilters.js +106 -0
- package/esm/core/Table/index.js +86 -1
- package/esm/core/index.js +1 -0
- package/esm/hooks/useSort.js +54 -0
- package/esm/index.js +1 -1
- package/esm/registry.js +2 -0
- package/hooks/useSort.d.ts +9 -0
- package/hooks/useSort.js +67 -0
- package/package.json +3 -3
- package/registry.d.ts +1 -0
- package/registry.js +3 -0
- package/src/admin/Drawer/__stories__/Default.tsx +3 -1
- package/src/admin/Dropdown/index.tsx +80 -55
- package/src/core/CaretContainer/index.tsx +3 -0
- package/src/core/Table/Table.stories.js +2 -0
- package/src/core/Table/Table.stories.playwright.json +16 -0
- package/src/core/Table/__stories__/Stacked.tsx +59 -0
- package/src/core/Table/__stories__/WithSortFilters.tsx +152 -0
- package/src/core/Table/index.tsx +112 -2
- package/src/core/index.ts +1 -0
- package/src/hooks/useSort.tsx +53 -0
- package/src/registry.js +2 -0
package/es/registry.js
CHANGED
|
@@ -71,6 +71,7 @@ import * as _digigov_ui_core_Button_Icon from '@digigov/ui/core/Button/Icon';
|
|
|
71
71
|
import * as _digigov_ui_core_Button from '@digigov/ui/core/Button';
|
|
72
72
|
import * as _digigov_ui_core_Button_ThemeToggleButton from '@digigov/ui/core/Button/ThemeToggleButton';
|
|
73
73
|
import * as _digigov_ui_core_Card from '@digigov/ui/core/Card';
|
|
74
|
+
import * as _digigov_ui_core_CaretContainer from '@digigov/ui/core/CaretContainer';
|
|
74
75
|
import * as _digigov_ui_core_Checkbox from '@digigov/ui/core/Checkbox';
|
|
75
76
|
import * as _digigov_ui_core_DateInputContainer from '@digigov/ui/core/DateInputContainer';
|
|
76
77
|
import * as _digigov_ui_core_Details from '@digigov/ui/core/Details';
|
|
@@ -283,6 +284,7 @@ export default {
|
|
|
283
284
|
'@digigov/ui/core/Button': lazyImport(_digigov_ui_core_Button),
|
|
284
285
|
'@digigov/ui/core/Button/ThemeToggleButton': lazyImport(_digigov_ui_core_Button_ThemeToggleButton),
|
|
285
286
|
'@digigov/ui/core/Card': lazyImport(_digigov_ui_core_Card),
|
|
287
|
+
'@digigov/ui/core/CaretContainer': lazyImport(_digigov_ui_core_CaretContainer),
|
|
286
288
|
'@digigov/ui/core/Checkbox': lazyImport(_digigov_ui_core_Checkbox),
|
|
287
289
|
'@digigov/ui/core/DateInputContainer': lazyImport(_digigov_ui_core_DateInputContainer),
|
|
288
290
|
'@digigov/ui/core/Details': lazyImport(_digigov_ui_core_Details),
|
|
@@ -77,7 +77,9 @@ export var Default = function Default() {
|
|
|
77
77
|
|
|
78
78
|
var layout = 'vertical';
|
|
79
79
|
var border = false;
|
|
80
|
+
var fixed = false;
|
|
80
81
|
return /*#__PURE__*/React.createElement(Drawer, {
|
|
82
|
+
upRelative: "m",
|
|
81
83
|
direction: "left",
|
|
82
84
|
open: open
|
|
83
85
|
}, /*#__PURE__*/React.createElement(DrawerHeading, {
|
|
@@ -88,6 +90,7 @@ export var Default = function Default() {
|
|
|
88
90
|
layout: layout,
|
|
89
91
|
links: links,
|
|
90
92
|
border: border,
|
|
93
|
+
fixed: fixed,
|
|
91
94
|
"aria-label": "Nav list"
|
|
92
95
|
}, links.map(function (item, key) {
|
|
93
96
|
var _item$subMenu;
|
|
@@ -9,18 +9,31 @@ export * from '@digigov/react-extensions/admin/DropdownContent';
|
|
|
9
9
|
/**
|
|
10
10
|
* Dropdown component is used for showing more options with a button.
|
|
11
11
|
*/
|
|
12
|
-
export var Dropdown = function Dropdown(_ref) {
|
|
12
|
+
export var Dropdown = /*#__PURE__*/React.forwardRef(function Dropdown(_ref, _ref2) {
|
|
13
13
|
var _ref$closeBehaviour = _ref.closeBehaviour,
|
|
14
14
|
closeBehaviour = _ref$closeBehaviour === void 0 ? 'clickOutside' : _ref$closeBehaviour,
|
|
15
15
|
_ref$float = _ref["float"],
|
|
16
16
|
_float = _ref$float === void 0 ? false : _ref$float,
|
|
17
17
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
18
18
|
|
|
19
|
-
var innerRef = useRef();
|
|
19
|
+
var innerRef = useRef(null);
|
|
20
20
|
useEffect(function () {
|
|
21
|
+
var element = innerRef.current;
|
|
22
|
+
|
|
23
|
+
if (!element) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
var keyDownHandler = function keyDownHandler(event) {
|
|
28
|
+
if (event.key === 'Escape') {
|
|
29
|
+
element.open = false;
|
|
30
|
+
event.preventDefault();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
21
34
|
var handleClickOutside = function handleClickOutside(event) {
|
|
22
|
-
if (
|
|
23
|
-
|
|
35
|
+
if (element && !element.contains(event.target)) {
|
|
36
|
+
element.open = false;
|
|
24
37
|
}
|
|
25
38
|
};
|
|
26
39
|
|
|
@@ -28,43 +41,40 @@ export var Dropdown = function Dropdown(_ref) {
|
|
|
28
41
|
document.addEventListener('click', handleClickOutside, true);
|
|
29
42
|
}
|
|
30
43
|
|
|
31
|
-
|
|
32
|
-
var _innerRef$current;
|
|
44
|
+
document.addEventListener('keydown', keyDownHandler);
|
|
33
45
|
|
|
34
|
-
|
|
35
|
-
var
|
|
36
|
-
|
|
37
|
-
if (innerRef.current.open) {
|
|
38
|
-
var _innerRef$current2;
|
|
46
|
+
var toggleFloat = function toggleFloat() {
|
|
47
|
+
var tbody = element.closest('tbody');
|
|
48
|
+
var parentElement = element === null || element === void 0 ? void 0 : element.parentElement;
|
|
39
49
|
|
|
50
|
+
if (element.open) {
|
|
40
51
|
tbody.style.position = 'static';
|
|
41
|
-
var rect =
|
|
52
|
+
var rect = element === null || element === void 0 ? void 0 : element.getBoundingClientRect();
|
|
42
53
|
var parentRect = parentElement.getBoundingClientRect();
|
|
43
|
-
|
|
54
|
+
element.style.position = 'static'; // arbitrary spacing of 12 pixels because CSS
|
|
44
55
|
|
|
45
56
|
var top = rect.top + window.pageYOffset;
|
|
46
57
|
var left = rect.left + window.pageXOffset;
|
|
47
58
|
parentElement.style.height = "".concat(parentRect.height, "px");
|
|
48
59
|
parentElement.style.width = "".concat(parentRect.width, "px");
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
60
|
+
element.style.top = "".concat(top, "px");
|
|
61
|
+
element.style.left = "".concat(left, "px");
|
|
62
|
+
element.style.position = "absolute";
|
|
63
|
+
element.style.display = "block";
|
|
64
|
+
element.style.background = 'white';
|
|
54
65
|
} else {
|
|
55
66
|
tbody.style.position = 'relative';
|
|
56
67
|
parentElement.style.height = '';
|
|
57
68
|
parentElement.style.width = '';
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
innerRef.current.style.background = 'transparent';
|
|
69
|
+
element.style.top = "0";
|
|
70
|
+
element.style.left = "0";
|
|
71
|
+
element.style.position = "relative";
|
|
72
|
+
element.style.display = "table-cell"; // element.style.background = 'transparent';
|
|
63
73
|
}
|
|
64
74
|
};
|
|
65
75
|
|
|
66
76
|
if (_float) {
|
|
67
|
-
|
|
77
|
+
element.addEventListener('toggle', toggleFloat);
|
|
68
78
|
}
|
|
69
79
|
|
|
70
80
|
return function () {
|
|
@@ -73,15 +83,23 @@ export var Dropdown = function Dropdown(_ref) {
|
|
|
73
83
|
}
|
|
74
84
|
|
|
75
85
|
if (_float) {
|
|
76
|
-
|
|
86
|
+
element.removeEventListener('toggle', toggleFloat);
|
|
77
87
|
}
|
|
88
|
+
|
|
89
|
+
document.removeEventListener('keydown', keyDownHandler);
|
|
78
90
|
};
|
|
79
91
|
}, []); // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
80
92
|
// @ts-ignore
|
|
81
93
|
|
|
82
94
|
return /*#__PURE__*/React.createElement(DropdownBase, _extends({
|
|
83
|
-
ref:
|
|
95
|
+
ref: function ref(el) {
|
|
96
|
+
innerRef.current = el;
|
|
97
|
+
|
|
98
|
+
if (typeof _ref2 === 'function') {
|
|
99
|
+
_ref2(el);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
84
102
|
}, props));
|
|
85
|
-
};
|
|
103
|
+
});
|
|
86
104
|
export { DropdownBase };
|
|
87
105
|
export default Dropdown;
|
|
@@ -14,11 +14,13 @@ export * from './__stories__/VerticalHeaders';
|
|
|
14
14
|
export * from './__stories__/ZebraProp';
|
|
15
15
|
export * from './__stories__/NumericDataType';
|
|
16
16
|
export * from './__stories__/VerticalBorders';
|
|
17
|
+
export * from './__stories__/Stacked';
|
|
17
18
|
export * from './__stories__/DarkVariant';
|
|
18
19
|
export * from './__stories__/DarkVariantWithVerticalHeaders';
|
|
19
20
|
export * from './__stories__/WithLoader';
|
|
20
21
|
export * from './__stories__/DefinedWidth';
|
|
21
22
|
export * from './__stories__/Densed';
|
|
22
23
|
export * from './__stories__/MultipleProps';
|
|
24
|
+
export * from './__stories__/WithSortFilters';
|
|
23
25
|
export * from './__stories__/WithFloatingScroll';
|
|
24
26
|
export * from './__stories__/Full';
|
|
@@ -16,6 +16,22 @@
|
|
|
16
16
|
"title": "Toggle Loading"
|
|
17
17
|
}
|
|
18
18
|
]
|
|
19
|
+
},
|
|
20
|
+
"digigov-ui-core-table--with-sort-filters": {
|
|
21
|
+
"actionSets": [
|
|
22
|
+
{
|
|
23
|
+
"actions": [
|
|
24
|
+
{
|
|
25
|
+
"name": "click",
|
|
26
|
+
"args": {
|
|
27
|
+
"selector": "html>body>div:nth-child(5)>div>div>table>thead>tr>th:nth-child(2)>details>summary"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
"id": "Gdm_Fpollj7d",
|
|
32
|
+
"title": "Table with filter action"
|
|
33
|
+
}
|
|
34
|
+
]
|
|
19
35
|
}
|
|
20
36
|
}
|
|
21
37
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { TableContainer, Table, TableCaption, TableHead, TableRow, TableBody, TableHeadCell, TableDataCell } from '@digigov/ui/core/Table';
|
|
3
|
+
|
|
4
|
+
var _ref = /*#__PURE__*/React.createElement(TableContainer, null, /*#__PURE__*/React.createElement(Table, {
|
|
5
|
+
stacked: "always"
|
|
6
|
+
}, /*#__PURE__*/React.createElement(TableCaption, null, "\u03A0\u03B5\u03C1\u03AF\u03BF\u03B4\u03BF\u03C2 \u03BA\u03B1\u03B9 \u03C0\u03BF\u03C3\u03AC"), /*#__PURE__*/React.createElement(TableHead, null, /*#__PURE__*/React.createElement(TableRow, null, /*#__PURE__*/React.createElement(TableHeadCell, null, "\u03A0\u03B5\u03C1\u03AF\u03BF\u03B4\u03BF\u03C2"), /*#__PURE__*/React.createElement(TableHeadCell, null, "\u039A\u03B1\u03BD\u03BF\u03BD\u03B9\u03BA\u03CC \u03C0\u03BF\u03C3\u03CC"), /*#__PURE__*/React.createElement(TableHeadCell, null, "\u039C\u03B5\u03B9\u03C9\u03BC\u03AD\u03BD\u03BF \u03C0\u03BF\u03C3\u03CC"))), /*#__PURE__*/React.createElement(TableBody, null, /*#__PURE__*/React.createElement(TableRow, null, /*#__PURE__*/React.createElement(TableDataCell, {
|
|
7
|
+
"data-label": "\u03A0\u03B5\u03C1\u03AF\u03BF\u03B4\u03BF\u03C2"
|
|
8
|
+
}, "\u03A0\u03C1\u03CE\u03C4\u03B5\u03C2 6 \u03B5\u03B2\u03B4\u03BF\u03BC\u03AC\u03B4\u03B5\u03C2"), /*#__PURE__*/React.createElement(TableDataCell, {
|
|
9
|
+
"data-label": "\u039A\u03B1\u03BD\u03BF\u03BD\u03B9\u03BA\u03CC \u03C0\u03BF\u03C3\u03CC"
|
|
10
|
+
}, "\u20AC109.80 / \u03B5\u03B2\u03B4\u03BF\u03BC\u03AC\u03B4\u03B1"), /*#__PURE__*/React.createElement(TableDataCell, {
|
|
11
|
+
"data-label": "\u039C\u03B5\u03B9\u03C9\u03BC\u03AD\u03BD\u03BF \u03C0\u03BF\u03C3\u03CC"
|
|
12
|
+
}, "\u20AC69.80 / \u03B5\u03B2\u03B4\u03BF\u03BC\u03AC\u03B4\u03B1")), /*#__PURE__*/React.createElement(TableRow, null, /*#__PURE__*/React.createElement(TableDataCell, {
|
|
13
|
+
"data-label": "\u03A0\u03B5\u03C1\u03AF\u03BF\u03B4\u03BF\u03C2"
|
|
14
|
+
}, "\u0395\u03C0\u03CC\u03BC\u03B5\u03BD\u03B5\u03C2 33 \u03B5\u03B2\u03B4\u03BF\u03BC\u03AC\u03B4\u03B5\u03C2"), /*#__PURE__*/React.createElement(TableDataCell, {
|
|
15
|
+
"data-label": "\u039A\u03B1\u03BD\u03BF\u03BD\u03B9\u03BA\u03CC \u03C0\u03BF\u03C3\u03CC"
|
|
16
|
+
}, "\u20AC99.80 / \u03B5\u03B2\u03B4\u03BF\u03BC\u03AC\u03B4\u03B1"), /*#__PURE__*/React.createElement(TableDataCell, {
|
|
17
|
+
"data-label": "\u039C\u03B5\u03B9\u03C9\u03BC\u03AD\u03BD\u03BF \u03C0\u03BF\u03C3\u03CC"
|
|
18
|
+
}, "\u20AC64.80 / \u03B5\u03B2\u03B4\u03BF\u03BC\u03AC\u03B4\u03B1")), /*#__PURE__*/React.createElement(TableRow, null, /*#__PURE__*/React.createElement(TableDataCell, {
|
|
19
|
+
"data-label": "\u03A0\u03B5\u03C1\u03AF\u03BF\u03B4\u03BF\u03C2"
|
|
20
|
+
}, "\u03A3\u03C5\u03BD\u03BF\u03BB\u03B9\u03BA\u03CC \u03C0\u03BF\u03C3\u03CC "), /*#__PURE__*/React.createElement(TableDataCell, {
|
|
21
|
+
"data-label": "\u039A\u03B1\u03BD\u03BF\u03BD\u03B9\u03BA\u03CC \u03C0\u03BF\u03C3\u03CC"
|
|
22
|
+
}, "\u20AC4.282,20 "), /*#__PURE__*/React.createElement(TableDataCell, {
|
|
23
|
+
"data-label": "\u039C\u03B5\u03B9\u03C9\u03BC\u03AD\u03BD\u03BF \u03C0\u03BF\u03C3\u03CC"
|
|
24
|
+
}, " \u20AC3.282,20")))));
|
|
25
|
+
|
|
26
|
+
export var Stacked = function Stacked() {
|
|
27
|
+
return _ref;
|
|
28
|
+
};
|
|
29
|
+
export default Stacked;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { TableContainer, Table, TableCaption, TableHead, TableRow, TableBody, TableHeadCell, TableDataCell, TableNoDataRow, TableSortLabel } from '@digigov/ui/core/Table';
|
|
3
|
+
import { useSort } from '@digigov/ui/hooks/useSort';
|
|
4
|
+
var headerConfig = [{
|
|
5
|
+
name: 'product',
|
|
6
|
+
label: 'Προϊόν',
|
|
7
|
+
sortLabels: {
|
|
8
|
+
asc: 'Αλφαβητική σειρά (Α -> Ω)',
|
|
9
|
+
desc: 'Αλφαβητική σειρά (Ω -> Α)'
|
|
10
|
+
}
|
|
11
|
+
}, {
|
|
12
|
+
name: 'price',
|
|
13
|
+
label: 'Τιμή',
|
|
14
|
+
sortLabels: {
|
|
15
|
+
asc: 'Αύξουσα σειρά',
|
|
16
|
+
desc: 'Φθίνουσα σειρά'
|
|
17
|
+
}
|
|
18
|
+
}, {
|
|
19
|
+
name: 'stock',
|
|
20
|
+
label: 'Στοκ',
|
|
21
|
+
sortLabels: {
|
|
22
|
+
asc: 'Αύξουσα σειρά',
|
|
23
|
+
desc: 'Φθίνουσα σειρά'
|
|
24
|
+
}
|
|
25
|
+
}, {
|
|
26
|
+
name: 'date',
|
|
27
|
+
label: 'Ημερομηνία',
|
|
28
|
+
sortLabels: {
|
|
29
|
+
asc: 'Αύξουσα σειρά',
|
|
30
|
+
desc: 'Φθίνουσα σειρά'
|
|
31
|
+
}
|
|
32
|
+
}];
|
|
33
|
+
var data = [{
|
|
34
|
+
id: 1,
|
|
35
|
+
product: 'Τυρί',
|
|
36
|
+
price: '4.9€',
|
|
37
|
+
stock: 20,
|
|
38
|
+
date: '2013-04-01'
|
|
39
|
+
}, {
|
|
40
|
+
id: 2,
|
|
41
|
+
product: 'Γάλα',
|
|
42
|
+
price: '1.9€',
|
|
43
|
+
stock: 32,
|
|
44
|
+
date: '2013-01-01'
|
|
45
|
+
}, {
|
|
46
|
+
id: 3,
|
|
47
|
+
product: 'Γιαούρτι',
|
|
48
|
+
price: '2.4€',
|
|
49
|
+
stock: 12,
|
|
50
|
+
date: '2002-04-12'
|
|
51
|
+
}, {
|
|
52
|
+
id: 4,
|
|
53
|
+
product: 'Κρέμα',
|
|
54
|
+
price: '3.9€',
|
|
55
|
+
stock: 8,
|
|
56
|
+
date: '2011-12-12'
|
|
57
|
+
}, {
|
|
58
|
+
id: 5,
|
|
59
|
+
product: 'Βούτυρο',
|
|
60
|
+
price: '0.9€',
|
|
61
|
+
stock: 99,
|
|
62
|
+
date: '2019-06-01'
|
|
63
|
+
}, {
|
|
64
|
+
id: 6,
|
|
65
|
+
product: 'Καφές',
|
|
66
|
+
price: '2.9€',
|
|
67
|
+
stock: 86,
|
|
68
|
+
date: '2023-02-11'
|
|
69
|
+
}, {
|
|
70
|
+
id: 7,
|
|
71
|
+
product: 'Ψωμί',
|
|
72
|
+
price: '99€',
|
|
73
|
+
stock: 12,
|
|
74
|
+
date: '2000-12-12'
|
|
75
|
+
}];
|
|
76
|
+
|
|
77
|
+
var _ref = /*#__PURE__*/React.createElement(TableCaption, null, "Table of products");
|
|
78
|
+
|
|
79
|
+
var _ref2 = /*#__PURE__*/React.createElement(TableNoDataRow, null, "No data");
|
|
80
|
+
|
|
81
|
+
export var WithSortFilters = function WithSortFilters() {
|
|
82
|
+
var _useSort = useSort(data),
|
|
83
|
+
sortedData = _useSort.sortedData,
|
|
84
|
+
setSortedField = _useSort.setSortedField,
|
|
85
|
+
field = _useSort.field,
|
|
86
|
+
direction = _useSort.direction;
|
|
87
|
+
|
|
88
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
89
|
+
className: "example"
|
|
90
|
+
}, /*#__PURE__*/React.createElement(TableContainer, null, /*#__PURE__*/React.createElement(Table, null, _ref, /*#__PURE__*/React.createElement(TableHead, null, /*#__PURE__*/React.createElement(TableRow, null, headerConfig.map(function (header, index) {
|
|
91
|
+
return /*#__PURE__*/React.createElement(TableHeadCell, {
|
|
92
|
+
key: index
|
|
93
|
+
}, /*#__PURE__*/React.createElement(TableSortLabel, {
|
|
94
|
+
labels: header.sortLabels,
|
|
95
|
+
onSort: function onSort(dir) {
|
|
96
|
+
return setSortedField(header.name, dir);
|
|
97
|
+
},
|
|
98
|
+
direction: header.name === field ? direction : 0
|
|
99
|
+
}, header.label));
|
|
100
|
+
}))), /*#__PURE__*/React.createElement(TableBody, null, sortedData.length > 0 ? sortedData.map(function (d, index) {
|
|
101
|
+
return /*#__PURE__*/React.createElement(TableRow, {
|
|
102
|
+
key: index
|
|
103
|
+
}, /*#__PURE__*/React.createElement(TableDataCell, null, d.product), /*#__PURE__*/React.createElement(TableDataCell, null, d.price), /*#__PURE__*/React.createElement(TableDataCell, null, d.stock), /*#__PURE__*/React.createElement(TableDataCell, null, new Date(d.date).toLocaleDateString('en-GB')));
|
|
104
|
+
}) : _ref2))));
|
|
105
|
+
};
|
|
106
|
+
export default WithSortFilters;
|
package/esm/core/Table/index.js
CHANGED
|
@@ -1,3 +1,89 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["labels", "disabled", "children", "direction", "onSort"];
|
|
4
|
+
import React, { useRef } from 'react';
|
|
5
|
+
import Table from '@digigov/react-core/Table';
|
|
6
|
+
import { Dropdown, DropdownButton, DropdownContent } from '@digigov/ui/admin/Dropdown';
|
|
7
|
+
import { NavVertical } from '@digigov/ui/core/NavList/NavVertical';
|
|
8
|
+
import { NavVerticalItem } from '@digigov/ui/core/NavList/NavVerticalItem';
|
|
9
|
+
import { CaretIcon } from '@digigov/ui/core/SvgIcon';
|
|
10
|
+
import CaretContainer from '@digigov/ui/core/CaretContainer';
|
|
11
|
+
|
|
12
|
+
var _ref2 = /*#__PURE__*/React.createElement(CaretIcon, {
|
|
13
|
+
direction: 'up',
|
|
14
|
+
marginRight: 1,
|
|
15
|
+
marginTop: 1,
|
|
16
|
+
size: "m"
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
var _ref3 = /*#__PURE__*/React.createElement(CaretIcon, {
|
|
20
|
+
direction: 'down',
|
|
21
|
+
marginRight: 1,
|
|
22
|
+
marginTop: 1,
|
|
23
|
+
size: "m"
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export var TableSortLabel = /*#__PURE__*/React.forwardRef(function TableSortLabel(_ref, _ref4) {
|
|
27
|
+
var labels = _ref.labels,
|
|
28
|
+
disabled = _ref.disabled,
|
|
29
|
+
children = _ref.children,
|
|
30
|
+
_ref$direction = _ref.direction,
|
|
31
|
+
direction = _ref$direction === void 0 ? 0 : _ref$direction,
|
|
32
|
+
onSort = _ref.onSort,
|
|
33
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
34
|
+
|
|
35
|
+
// TODO: this is a workaround for the dropdown component
|
|
36
|
+
// https://itnext.io/reusing-the-ref-from-forwardref-with-react-hooks-4ce9df693dd
|
|
37
|
+
var dropdownRef = useRef(null);
|
|
38
|
+
var active = [-1, 1].includes(direction);
|
|
39
|
+
return /*#__PURE__*/React.createElement(Dropdown, _extends({
|
|
40
|
+
ref: function ref(el) {
|
|
41
|
+
dropdownRef.current = el;
|
|
42
|
+
typeof _ref4 === 'function' && _ref4(el);
|
|
43
|
+
},
|
|
44
|
+
disabled: disabled
|
|
45
|
+
}, props), /*#__PURE__*/React.createElement(DropdownButton, {
|
|
46
|
+
variant: "link",
|
|
47
|
+
tabIndex: 0,
|
|
48
|
+
underline: active
|
|
49
|
+
}, children, /*#__PURE__*/React.createElement(CaretContainer, {
|
|
50
|
+
marginLeft: 1
|
|
51
|
+
}, /*#__PURE__*/React.createElement(CaretIcon, {
|
|
52
|
+
direction: 'up',
|
|
53
|
+
size: "m",
|
|
54
|
+
variant: direction === 1 ? 'dark' : 'gray'
|
|
55
|
+
}), /*#__PURE__*/React.createElement(CaretIcon, {
|
|
56
|
+
direction: 'down',
|
|
57
|
+
size: "m",
|
|
58
|
+
variant: direction === -1 ? 'dark' : 'gray'
|
|
59
|
+
}))), /*#__PURE__*/React.createElement(DropdownContent, null, /*#__PURE__*/React.createElement(NavVertical, null, /*#__PURE__*/React.createElement(NavVerticalItem, {
|
|
60
|
+
active: direction === 1,
|
|
61
|
+
tabIndex: 0,
|
|
62
|
+
onClick: function onClick() {
|
|
63
|
+
onSort(1);
|
|
64
|
+
dropdownRef.current && (dropdownRef.current.open = false);
|
|
65
|
+
},
|
|
66
|
+
onKeyDown: function onKeyDown(e) {
|
|
67
|
+
if (e.key === 'Enter') {
|
|
68
|
+
onSort(1);
|
|
69
|
+
dropdownRef.current && (dropdownRef.current.open = false);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}, _ref2, labels.asc), /*#__PURE__*/React.createElement(NavVerticalItem, {
|
|
73
|
+
active: direction === -1,
|
|
74
|
+
tabIndex: 0,
|
|
75
|
+
onClick: function onClick() {
|
|
76
|
+
onSort(-1);
|
|
77
|
+
dropdownRef.current && (dropdownRef.current.open = false);
|
|
78
|
+
},
|
|
79
|
+
onKeyDown: function onKeyDown(e) {
|
|
80
|
+
if (e.key === 'Enter') {
|
|
81
|
+
onSort(-1);
|
|
82
|
+
dropdownRef.current && (dropdownRef.current.open = false);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}, _ref3, labels.desc))));
|
|
86
|
+
});
|
|
1
87
|
export * from '@digigov/react-core/TableContainer';
|
|
2
88
|
export * from '@digigov/react-core/Table';
|
|
3
89
|
export * from '@digigov/react-core/TableBody';
|
|
@@ -8,5 +94,4 @@ export * from '@digigov/react-core/TableHeadCell';
|
|
|
8
94
|
export * from '@digigov/react-core/TableRow';
|
|
9
95
|
export * from '@digigov/react-core/TableNoDataRow';
|
|
10
96
|
export * from '@digigov/ui/core/Table/TableFloatingScroll';
|
|
11
|
-
import Table from '@digigov/react-core/Table';
|
|
12
97
|
export default Table;
|
package/esm/core/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export * from '@digigov/ui/core/Accordion';
|
|
|
6
6
|
export * from '@digigov/ui/core/Blockquote';
|
|
7
7
|
export * from '@digigov/ui/core/Breadcrumbs';
|
|
8
8
|
export * from '@digigov/ui/core/Card';
|
|
9
|
+
export * from '@digigov/ui/core/CaretContainer';
|
|
9
10
|
export * from '@digigov/ui/core/Checkbox';
|
|
10
11
|
export * from '@digigov/ui/core/DateInputContainer';
|
|
11
12
|
export * from '@digigov/ui/core/Details';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { useMemo } from 'react';
|
|
5
|
+
export var useSort = function useSort(data) {
|
|
6
|
+
var _useState = useState(''),
|
|
7
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
8
|
+
sortDataBy = _useState2[0],
|
|
9
|
+
setSortDataBy = _useState2[1];
|
|
10
|
+
|
|
11
|
+
var _useState3 = useState(0),
|
|
12
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
13
|
+
direction = _useState4[0],
|
|
14
|
+
setDirection = _useState4[1];
|
|
15
|
+
|
|
16
|
+
var sortedItems = useMemo(function () {
|
|
17
|
+
var sortableItems = _toConsumableArray(data);
|
|
18
|
+
|
|
19
|
+
if (sortableItems.length === 0) {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (sortDataBy) {
|
|
24
|
+
sortableItems.sort(function (a, b) {
|
|
25
|
+
if (a[sortDataBy] === null) return 1;
|
|
26
|
+
if (b[sortDataBy] === null) return -1;
|
|
27
|
+
if (a[sortDataBy] === null && b[sortDataBy] === null) return 0;
|
|
28
|
+
return a[sortDataBy].toString().localeCompare(b[sortDataBy].toString(), undefined, {
|
|
29
|
+
numeric: true
|
|
30
|
+
}) * (direction > 0 ? 1 : -1);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return sortableItems;
|
|
35
|
+
}, [data, direction, sortDataBy]);
|
|
36
|
+
|
|
37
|
+
var setSortedField = function setSortedField(item, value) {
|
|
38
|
+
if (item === sortDataBy && value === direction) {
|
|
39
|
+
setDirection(0);
|
|
40
|
+
setSortDataBy('');
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
setDirection(value);
|
|
45
|
+
setSortDataBy(item);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
sortedData: sortedItems,
|
|
50
|
+
setSortedField: setSortedField,
|
|
51
|
+
field: sortDataBy,
|
|
52
|
+
direction: direction
|
|
53
|
+
};
|
|
54
|
+
};
|
package/esm/index.js
CHANGED
package/esm/registry.js
CHANGED
|
@@ -71,6 +71,7 @@ import * as _digigov_ui_core_Button_Icon from '@digigov/ui/core/Button/Icon';
|
|
|
71
71
|
import * as _digigov_ui_core_Button from '@digigov/ui/core/Button';
|
|
72
72
|
import * as _digigov_ui_core_Button_ThemeToggleButton from '@digigov/ui/core/Button/ThemeToggleButton';
|
|
73
73
|
import * as _digigov_ui_core_Card from '@digigov/ui/core/Card';
|
|
74
|
+
import * as _digigov_ui_core_CaretContainer from '@digigov/ui/core/CaretContainer';
|
|
74
75
|
import * as _digigov_ui_core_Checkbox from '@digigov/ui/core/Checkbox';
|
|
75
76
|
import * as _digigov_ui_core_DateInputContainer from '@digigov/ui/core/DateInputContainer';
|
|
76
77
|
import * as _digigov_ui_core_Details from '@digigov/ui/core/Details';
|
|
@@ -283,6 +284,7 @@ export default {
|
|
|
283
284
|
'@digigov/ui/core/Button': lazyImport(_digigov_ui_core_Button),
|
|
284
285
|
'@digigov/ui/core/Button/ThemeToggleButton': lazyImport(_digigov_ui_core_Button_ThemeToggleButton),
|
|
285
286
|
'@digigov/ui/core/Card': lazyImport(_digigov_ui_core_Card),
|
|
287
|
+
'@digigov/ui/core/CaretContainer': lazyImport(_digigov_ui_core_CaretContainer),
|
|
286
288
|
'@digigov/ui/core/Checkbox': lazyImport(_digigov_ui_core_Checkbox),
|
|
287
289
|
'@digigov/ui/core/DateInputContainer': lazyImport(_digigov_ui_core_DateInputContainer),
|
|
288
290
|
'@digigov/ui/core/Details': lazyImport(_digigov_ui_core_Details),
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SortDirection } from '@digigov/ui/core/Table';
|
|
2
|
+
export interface UseSortResult {
|
|
3
|
+
sortedData: any[];
|
|
4
|
+
setSortedField: (item: string, value: SortDirection) => void;
|
|
5
|
+
field: string;
|
|
6
|
+
direction: SortDirection;
|
|
7
|
+
}
|
|
8
|
+
export declare type SortData = Record<string, any>[];
|
|
9
|
+
export declare const useSort: (data: SortData) => UseSortResult;
|
package/hooks/useSort.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.useSort = void 0;
|
|
9
|
+
|
|
10
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
|
+
|
|
12
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
13
|
+
|
|
14
|
+
var _react = require("react");
|
|
15
|
+
|
|
16
|
+
var useSort = function useSort(data) {
|
|
17
|
+
var _useState = (0, _react.useState)(''),
|
|
18
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
19
|
+
sortDataBy = _useState2[0],
|
|
20
|
+
setSortDataBy = _useState2[1];
|
|
21
|
+
|
|
22
|
+
var _useState3 = (0, _react.useState)(0),
|
|
23
|
+
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
|
24
|
+
direction = _useState4[0],
|
|
25
|
+
setDirection = _useState4[1];
|
|
26
|
+
|
|
27
|
+
var sortedItems = (0, _react.useMemo)(function () {
|
|
28
|
+
var sortableItems = (0, _toConsumableArray2["default"])(data);
|
|
29
|
+
|
|
30
|
+
if (sortableItems.length === 0) {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (sortDataBy) {
|
|
35
|
+
sortableItems.sort(function (a, b) {
|
|
36
|
+
if (a[sortDataBy] === null) return 1;
|
|
37
|
+
if (b[sortDataBy] === null) return -1;
|
|
38
|
+
if (a[sortDataBy] === null && b[sortDataBy] === null) return 0;
|
|
39
|
+
return a[sortDataBy].toString().localeCompare(b[sortDataBy].toString(), undefined, {
|
|
40
|
+
numeric: true
|
|
41
|
+
}) * (direction > 0 ? 1 : -1);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return sortableItems;
|
|
46
|
+
}, [data, direction, sortDataBy]);
|
|
47
|
+
|
|
48
|
+
var setSortedField = function setSortedField(item, value) {
|
|
49
|
+
if (item === sortDataBy && value === direction) {
|
|
50
|
+
setDirection(0);
|
|
51
|
+
setSortDataBy('');
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
setDirection(value);
|
|
56
|
+
setSortDataBy(item);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
sortedData: sortedItems,
|
|
61
|
+
setSortedField: setSortedField,
|
|
62
|
+
field: sortDataBy,
|
|
63
|
+
direction: direction
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
exports.useSort = useSort;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digigov/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.0",
|
|
4
4
|
"description": "@digigov reusable components toolkit",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"module": "./esm/index.js",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"clsx": "1.1.1",
|
|
21
21
|
"react": "^16.8.0 || ^17.0.0",
|
|
22
22
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
23
|
-
"@digigov/react-core": "0.
|
|
24
|
-
"@digigov/react-extensions": "0.
|
|
23
|
+
"@digigov/react-core": "0.25.0",
|
|
24
|
+
"@digigov/react-extensions": "0.22.1"
|
|
25
25
|
},
|
|
26
26
|
"gitHead": "c903a46306f77f55ad7fc4d2e274006f39a6c871",
|
|
27
27
|
"private": false,
|
package/registry.d.ts
CHANGED
|
@@ -72,6 +72,7 @@ declare var _default: {
|
|
|
72
72
|
'@digigov/ui/core/Button': {};
|
|
73
73
|
'@digigov/ui/core/Button/ThemeToggleButton': {};
|
|
74
74
|
'@digigov/ui/core/Card': {};
|
|
75
|
+
'@digigov/ui/core/CaretContainer': {};
|
|
75
76
|
'@digigov/ui/core/Checkbox': {};
|
|
76
77
|
'@digigov/ui/core/DateInputContainer': {};
|
|
77
78
|
'@digigov/ui/core/Details': {};
|
package/registry.js
CHANGED
|
@@ -153,6 +153,8 @@ var _digigov_ui_core_Button_ThemeToggleButton = _interopRequireWildcard(require(
|
|
|
153
153
|
|
|
154
154
|
var _digigov_ui_core_Card = _interopRequireWildcard(require("@digigov/ui/core/Card"));
|
|
155
155
|
|
|
156
|
+
var _digigov_ui_core_CaretContainer = _interopRequireWildcard(require("@digigov/ui/core/CaretContainer"));
|
|
157
|
+
|
|
156
158
|
var _digigov_ui_core_Checkbox = _interopRequireWildcard(require("@digigov/ui/core/Checkbox"));
|
|
157
159
|
|
|
158
160
|
var _digigov_ui_core_DateInputContainer = _interopRequireWildcard(require("@digigov/ui/core/DateInputContainer"));
|
|
@@ -597,6 +599,7 @@ var _default = {
|
|
|
597
599
|
'@digigov/ui/core/Button': lazyImport(_digigov_ui_core_Button),
|
|
598
600
|
'@digigov/ui/core/Button/ThemeToggleButton': lazyImport(_digigov_ui_core_Button_ThemeToggleButton),
|
|
599
601
|
'@digigov/ui/core/Card': lazyImport(_digigov_ui_core_Card),
|
|
602
|
+
'@digigov/ui/core/CaretContainer': lazyImport(_digigov_ui_core_CaretContainer),
|
|
600
603
|
'@digigov/ui/core/Checkbox': lazyImport(_digigov_ui_core_Checkbox),
|
|
601
604
|
'@digigov/ui/core/DateInputContainer': lazyImport(_digigov_ui_core_DateInputContainer),
|
|
602
605
|
'@digigov/ui/core/Details': lazyImport(_digigov_ui_core_Details),
|