@canonical/react-components 0.47.0 → 0.47.2
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/dist/__mocks__/nanoid.js +3 -3
- package/dist/components/Accordion/Accordion.js +28 -41
- package/dist/components/Accordion/AccordionSection/AccordionSection.js +18 -18
- package/dist/components/Accordion/AccordionSection/index.js +1 -1
- package/dist/components/Accordion/index.js +1 -1
- package/dist/components/ActionButton/ActionButton.js +34 -66
- package/dist/components/ActionButton/index.js +1 -1
- package/dist/components/ArticlePagination/ArticlePagination.js +10 -12
- package/dist/components/ArticlePagination/index.js +1 -1
- package/dist/components/Badge/Badge.js +24 -29
- package/dist/components/Badge/index.js +1 -1
- package/dist/components/Button/Button.js +21 -26
- package/dist/components/Button/index.js +4 -5
- package/dist/components/Card/Card.js +12 -14
- package/dist/components/Card/index.js +1 -1
- package/dist/components/CheckboxInput/CheckableInput/CheckableInput.js +15 -19
- package/dist/components/CheckboxInput/CheckableInput/index.js +1 -1
- package/dist/components/CheckboxInput/CheckboxInput.js +7 -10
- package/dist/components/CheckboxInput/index.js +1 -1
- package/dist/components/Chip/Chip.js +23 -33
- package/dist/components/Chip/index.js +1 -1
- package/dist/components/Code/Code.js +14 -17
- package/dist/components/Code/index.js +1 -1
- package/dist/components/CodeSnippet/CodeSnippet.js +9 -14
- package/dist/components/CodeSnippet/CodeSnippetBlock.js +24 -29
- package/dist/components/CodeSnippet/CodeSnippetDropdown.js +11 -11
- package/dist/components/CodeSnippet/index.js +2 -2
- package/dist/components/Col/Col.js +24 -26
- package/dist/components/Col/index.js +4 -5
- package/dist/components/ConfirmationButton/ConfirmationButton.js +18 -21
- package/dist/components/ConfirmationButton/index.js +1 -1
- package/dist/components/ConfirmationModal/ConfirmationModal.js +11 -15
- package/dist/components/ConfirmationModal/index.js +1 -1
- package/dist/components/ContextualMenu/ContextualMenu.js +89 -107
- package/dist/components/ContextualMenu/ContextualMenuDropdown/ContextualMenuDropdown.d.ts +4 -4
- package/dist/components/ContextualMenu/ContextualMenuDropdown/ContextualMenuDropdown.js +97 -107
- package/dist/components/ContextualMenu/ContextualMenuDropdown/index.js +1 -1
- package/dist/components/ContextualMenu/index.js +1 -1
- package/dist/components/EmptyState/EmptyState.js +9 -11
- package/dist/components/EmptyState/index.js +1 -1
- package/dist/components/Field/Field.js +66 -65
- package/dist/components/Field/index.js +1 -1
- package/dist/components/Form/Form.js +9 -11
- package/dist/components/Form/index.js +1 -1
- package/dist/components/Icon/Icon.js +9 -12
- package/dist/components/Icon/index.js +4 -5
- package/dist/components/Input/Input.js +38 -45
- package/dist/components/Input/index.js +1 -1
- package/dist/components/Label/Label.js +9 -11
- package/dist/components/Label/index.js +1 -1
- package/dist/components/Link/Link.js +12 -18
- package/dist/components/Link/index.js +1 -1
- package/dist/components/List/List.js +50 -54
- package/dist/components/List/index.js +1 -1
- package/dist/components/Loader/Loader.js +2 -3
- package/dist/components/Loader/index.js +1 -1
- package/dist/components/MainTable/MainTable.js +87 -104
- package/dist/components/MainTable/index.js +1 -1
- package/dist/components/Modal/Modal.js +45 -40
- package/dist/components/Modal/index.js +1 -1
- package/dist/components/ModularTable/ModularTable.js +63 -77
- package/dist/components/ModularTable/index.js +1 -1
- package/dist/components/Navigation/Navigation.js +63 -97
- package/dist/components/Navigation/NavigationLink/NavigationLink.js +32 -35
- package/dist/components/Navigation/NavigationLink/index.js +1 -1
- package/dist/components/Navigation/NavigationMenu/NavigationMenu.js +26 -45
- package/dist/components/Navigation/NavigationMenu/index.js +1 -1
- package/dist/components/Navigation/index.js +1 -1
- package/dist/components/Notification/Notification.js +49 -59
- package/dist/components/Notification/index.js +4 -5
- package/dist/components/NotificationProvider/NotificationProvider.js +47 -68
- package/dist/components/NotificationProvider/index.js +7 -7
- package/dist/components/NotificationProvider/messageBuilder.js +9 -9
- package/dist/components/NotificationProvider/types.d.ts +1 -0
- package/dist/components/Pagination/Pagination.js +55 -74
- package/dist/components/Pagination/PaginationButton/PaginationButton.js +11 -12
- package/dist/components/Pagination/PaginationButton/index.js +1 -1
- package/dist/components/Pagination/PaginationItem/PaginationItem.js +7 -7
- package/dist/components/Pagination/PaginationItem/index.js +1 -1
- package/dist/components/Pagination/index.js +1 -1
- package/dist/components/PasswordToggle/PasswordToggle.d.ts +1 -1
- package/dist/components/PasswordToggle/PasswordToggle.js +25 -40
- package/dist/components/PasswordToggle/index.js +1 -1
- package/dist/components/RadioInput/RadioInput.js +6 -8
- package/dist/components/RadioInput/index.js +1 -1
- package/dist/components/Row/Row.js +7 -9
- package/dist/components/Row/index.js +1 -1
- package/dist/components/SearchAndFilter/FilterPanelSection/FilterPanelSection.js +38 -51
- package/dist/components/SearchAndFilter/FilterPanelSection/index.js +1 -1
- package/dist/components/SearchAndFilter/SearchAndFilter.js +75 -135
- package/dist/components/SearchAndFilter/index.js +1 -1
- package/dist/components/SearchAndFilter/utils.js +4 -8
- package/dist/components/SearchBox/SearchBox.js +25 -33
- package/dist/components/SearchBox/index.js +1 -1
- package/dist/components/Select/Select.js +38 -44
- package/dist/components/Select/index.js +1 -1
- package/dist/components/Slider/Slider.js +27 -35
- package/dist/components/Slider/index.js +1 -1
- package/dist/components/Spinner/Spinner.js +10 -15
- package/dist/components/Spinner/index.js +1 -1
- package/dist/components/StatusLabel/StatusLabel.js +11 -13
- package/dist/components/StatusLabel/index.js +4 -5
- package/dist/components/Strip/Strip.js +27 -34
- package/dist/components/Strip/index.js +1 -1
- package/dist/components/SummaryButton/SummaryButton.js +9 -8
- package/dist/components/SummaryButton/index.js +1 -1
- package/dist/components/Switch/Switch.js +7 -10
- package/dist/components/Switch/index.js +1 -1
- package/dist/components/Table/Table.js +9 -13
- package/dist/components/Table/index.js +1 -1
- package/dist/components/TableCell/TableCell.js +11 -17
- package/dist/components/TableCell/index.js +1 -1
- package/dist/components/TableHeader/TableHeader.js +7 -9
- package/dist/components/TableHeader/index.js +1 -1
- package/dist/components/TablePagination/TablePagination.d.ts +37 -0
- package/dist/components/TablePagination/TablePagination.js +125 -0
- package/dist/components/TablePagination/TablePagination.scss +40 -0
- package/dist/components/TablePagination/TablePaginationControls/TablePaginationControls.d.ts +16 -0
- package/dist/components/TablePagination/TablePaginationControls/TablePaginationControls.js +66 -0
- package/dist/components/TablePagination/TablePaginationControls/index.d.ts +2 -0
- package/dist/components/TablePagination/TablePaginationControls/index.js +13 -0
- package/dist/components/TablePagination/index.d.ts +2 -0
- package/dist/components/TablePagination/index.js +13 -0
- package/dist/components/TableRow/TableRow.js +6 -8
- package/dist/components/TableRow/index.js +1 -1
- package/dist/components/Tabs/Tabs.js +17 -17
- package/dist/components/Tabs/index.js +1 -1
- package/dist/components/Textarea/Textarea.js +51 -45
- package/dist/components/Textarea/index.js +1 -1
- package/dist/components/Tooltip/Tooltip.d.ts +5 -1
- package/dist/components/Tooltip/Tooltip.js +76 -79
- package/dist/components/Tooltip/index.js +4 -5
- package/dist/enums.js +2 -3
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +16 -10
- package/dist/hooks/useId.js +1 -3
- package/dist/hooks/useListener.d.ts +2 -1
- package/dist/hooks/useListener.js +25 -24
- package/dist/hooks/useOnClickOutside.d.ts +12 -0
- package/dist/hooks/useOnClickOutside.js +45 -0
- package/dist/hooks/useOnEscapePressed.d.ts +3 -1
- package/dist/hooks/useOnEscapePressed.js +13 -6
- package/dist/hooks/usePagination.js +17 -29
- package/dist/hooks/usePrevious.js +4 -4
- package/dist/hooks/useThrottle.js +16 -25
- package/dist/hooks/useWindowFitment.js +30 -28
- package/dist/index.d.ts +3 -1
- package/dist/index.js +86 -74
- package/dist/utils.js +6 -13
- package/package.json +56 -49
- package/dist/hooks/useClickOutside.d.ts +0 -6
- package/dist/hooks/useClickOutside.js +0 -32
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
@@ -12,29 +11,12 @@ var _TableRow = _interopRequireDefault(require("../TableRow"));
|
|
|
12
11
|
var _TableHeader = _interopRequireDefault(require("../TableHeader"));
|
|
13
12
|
var _TableCell = _interopRequireDefault(require("../TableCell"));
|
|
14
13
|
var _hooks = require("../../hooks");
|
|
15
|
-
var _excluded = ["content", "sortKey"],
|
|
16
|
-
_excluded2 = ["columns", "expanded", "expandedContent", "key", "sortData"],
|
|
17
|
-
_excluded3 = ["content"],
|
|
18
|
-
_excluded4 = ["defaultSort", "defaultSortDirection", "emptyStateMsg", "expanding", "headers", "onUpdateSort", "paginate", "rows", "responsive", "sortable", "sortFunction", "hiddenCaption"];
|
|
19
|
-
var _this = void 0;
|
|
20
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
-
function _getRequireWildcardCache(
|
|
22
|
-
function _interopRequireWildcard(
|
|
23
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
24
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
25
|
-
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
26
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
27
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
28
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
29
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
30
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
31
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
32
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
15
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
16
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
33
17
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
var updateSort = function updateSort(setSortKey, setSortDirection, sortKey, sortDirection) {
|
|
37
|
-
var newDirection = null;
|
|
18
|
+
const updateSort = (setSortKey, setSortDirection, sortKey, sortDirection) => {
|
|
19
|
+
let newDirection = null;
|
|
38
20
|
if (sortDirection === "none") {
|
|
39
21
|
newDirection = "ascending";
|
|
40
22
|
} else if (sortDirection === "ascending") {
|
|
@@ -45,12 +27,14 @@ var updateSort = function updateSort(setSortKey, setSortDirection, sortKey, sort
|
|
|
45
27
|
setSortKey(sortKey);
|
|
46
28
|
setSortDirection(newDirection);
|
|
47
29
|
};
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
30
|
+
const generateHeaders = (currentSortKey, currentSortDirection, expanding, headers, sortable, setSortKey, setSortDirection) => {
|
|
31
|
+
const headerItems = headers.map((_ref, index) => {
|
|
32
|
+
let {
|
|
33
|
+
content,
|
|
34
|
+
sortKey,
|
|
35
|
+
...props
|
|
36
|
+
} = _ref;
|
|
37
|
+
let sortDirection;
|
|
54
38
|
if (sortable && sortKey) {
|
|
55
39
|
if (currentSortKey === sortKey) {
|
|
56
40
|
sortDirection = currentSortDirection;
|
|
@@ -61,7 +45,7 @@ var generateHeaders = function generateHeaders(currentSortKey, currentSortDirect
|
|
|
61
45
|
return /*#__PURE__*/_react.default.createElement(_TableHeader.default, _extends({
|
|
62
46
|
key: index,
|
|
63
47
|
sort: sortDirection,
|
|
64
|
-
onClick: sortable && sortKey ? updateSort.bind(
|
|
48
|
+
onClick: sortable && sortKey ? updateSort.bind(void 0, setSortKey, setSortDirection, sortKey, sortDirection) : undefined
|
|
65
49
|
}, props), content);
|
|
66
50
|
});
|
|
67
51
|
// When there is expanding content then provide an extra hidden header to
|
|
@@ -70,23 +54,29 @@ var generateHeaders = function generateHeaders(currentSortKey, currentSortDirect
|
|
|
70
54
|
"aria-hidden": "true"
|
|
71
55
|
})));
|
|
72
56
|
};
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
57
|
+
const generateRows = _ref2 => {
|
|
58
|
+
let {
|
|
59
|
+
rows,
|
|
60
|
+
headers,
|
|
61
|
+
responsive,
|
|
62
|
+
expanding
|
|
63
|
+
} = _ref2;
|
|
64
|
+
return rows.map((_ref3, index) => {
|
|
65
|
+
let {
|
|
66
|
+
columns,
|
|
67
|
+
expanded,
|
|
68
|
+
expandedContent,
|
|
69
|
+
key,
|
|
70
|
+
sortData,
|
|
71
|
+
...rowProps
|
|
72
|
+
} = _ref3;
|
|
73
|
+
const cellItems = columns === null || columns === void 0 ? void 0 : columns.map((_ref4, index) => {
|
|
74
|
+
let {
|
|
75
|
+
content,
|
|
76
|
+
...cellProps
|
|
77
|
+
} = _ref4;
|
|
78
|
+
const headerContent = headers && headers[index]["content"];
|
|
79
|
+
const headerReplacement = headers && headers[index]["heading"];
|
|
90
80
|
if (responsive) {
|
|
91
81
|
cellProps["data-heading"] = typeof headerContent === "string" ? headerContent : headerReplacement;
|
|
92
82
|
}
|
|
@@ -109,20 +99,22 @@ var generateRows = function generateRows(_ref2) {
|
|
|
109
99
|
}, expandedContent));
|
|
110
100
|
});
|
|
111
101
|
};
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
102
|
+
const sortRows = _ref5 => {
|
|
103
|
+
let {
|
|
104
|
+
currentSortDirection,
|
|
105
|
+
currentSortKey,
|
|
106
|
+
rows,
|
|
107
|
+
sortable,
|
|
108
|
+
sortFunction
|
|
109
|
+
} = _ref5;
|
|
118
110
|
if (!rows) {
|
|
119
111
|
return [];
|
|
120
112
|
}
|
|
121
113
|
// Clone the rows so we can restore the original order.
|
|
122
|
-
|
|
114
|
+
const sortedRows = [...rows];
|
|
123
115
|
if (sortable && currentSortKey) {
|
|
124
116
|
if (!sortFunction) {
|
|
125
|
-
sortFunction =
|
|
117
|
+
sortFunction = (a, b) => {
|
|
126
118
|
if (!a.sortData || !b.sortData) {
|
|
127
119
|
return 0;
|
|
128
120
|
}
|
|
@@ -134,65 +126,57 @@ var sortRows = function sortRows(_ref5) {
|
|
|
134
126
|
return 0;
|
|
135
127
|
};
|
|
136
128
|
}
|
|
137
|
-
sortedRows.sort(
|
|
138
|
-
return sortFunction(a, b, currentSortDirection, currentSortKey);
|
|
139
|
-
});
|
|
129
|
+
sortedRows.sort((a, b) => sortFunction(a, b, currentSortDirection, currentSortKey));
|
|
140
130
|
}
|
|
141
131
|
return sortedRows;
|
|
142
132
|
};
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
emptyStateMsg =
|
|
148
|
-
expanding
|
|
149
|
-
headers
|
|
150
|
-
onUpdateSort
|
|
151
|
-
paginate
|
|
152
|
-
rows
|
|
153
|
-
responsive
|
|
154
|
-
sortable
|
|
155
|
-
sortFunction
|
|
156
|
-
hiddenCaption
|
|
157
|
-
props
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
setSortKey = _useState2[1];
|
|
162
|
-
var _useState3 = (0, _react.useState)(defaultSortDirection),
|
|
163
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
164
|
-
currentSortDirection = _useState4[0],
|
|
165
|
-
setSortDirection = _useState4[1];
|
|
133
|
+
const MainTable = _ref6 => {
|
|
134
|
+
let {
|
|
135
|
+
defaultSort,
|
|
136
|
+
defaultSortDirection,
|
|
137
|
+
emptyStateMsg = "",
|
|
138
|
+
expanding,
|
|
139
|
+
headers,
|
|
140
|
+
onUpdateSort,
|
|
141
|
+
paginate,
|
|
142
|
+
rows,
|
|
143
|
+
responsive,
|
|
144
|
+
sortable,
|
|
145
|
+
sortFunction,
|
|
146
|
+
hiddenCaption,
|
|
147
|
+
...props
|
|
148
|
+
} = _ref6;
|
|
149
|
+
const [currentSortKey, setSortKey] = (0, _react.useState)(defaultSort);
|
|
150
|
+
const [currentSortDirection, setSortDirection] = (0, _react.useState)(defaultSortDirection);
|
|
166
151
|
|
|
167
152
|
// Update the current sort state if the prop changes.
|
|
168
|
-
(0, _react.useEffect)(
|
|
153
|
+
(0, _react.useEffect)(() => {
|
|
169
154
|
setSortKey(defaultSort);
|
|
170
155
|
}, [defaultSort]);
|
|
171
156
|
|
|
172
157
|
// Update the current sort direction state if the prop changes.
|
|
173
|
-
(0, _react.useEffect)(
|
|
158
|
+
(0, _react.useEffect)(() => {
|
|
174
159
|
setSortDirection(defaultSortDirection);
|
|
175
160
|
}, [defaultSortDirection]);
|
|
176
|
-
|
|
161
|
+
const updateSort = newSort => {
|
|
177
162
|
setSortKey(newSort);
|
|
178
163
|
onUpdateSort && onUpdateSort(newSort);
|
|
179
164
|
};
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
setCurrentPage = _usePagination.paginate;
|
|
165
|
+
const sortedRows = (0, _react.useMemo)(() => sortRows({
|
|
166
|
+
currentSortDirection,
|
|
167
|
+
currentSortKey,
|
|
168
|
+
rows,
|
|
169
|
+
sortable,
|
|
170
|
+
sortFunction
|
|
171
|
+
}), [currentSortDirection, currentSortKey, rows, sortable, sortFunction]);
|
|
172
|
+
const {
|
|
173
|
+
pageData: finalRows,
|
|
174
|
+
currentPage,
|
|
175
|
+
paginate: setCurrentPage
|
|
176
|
+
} = (0, _hooks.usePagination)(sortedRows, {
|
|
177
|
+
itemsPerPage: paginate,
|
|
178
|
+
autoResetPage: true
|
|
179
|
+
});
|
|
196
180
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_Table.default, _extends({
|
|
197
181
|
expanding: expanding,
|
|
198
182
|
responsive: responsive
|
|
@@ -210,9 +194,9 @@ var MainTable = function MainTable(_ref6) {
|
|
|
210
194
|
// If the table has no rows, return empty state message
|
|
211
195
|
Object.entries(finalRows).length === 0 && emptyStateMsg ? /*#__PURE__*/_react.default.createElement("caption", null, emptyStateMsg) : /*#__PURE__*/_react.default.createElement("tbody", null, generateRows({
|
|
212
196
|
rows: finalRows,
|
|
213
|
-
headers
|
|
214
|
-
responsive
|
|
215
|
-
expanding
|
|
197
|
+
headers,
|
|
198
|
+
responsive,
|
|
199
|
+
expanding
|
|
216
200
|
}))), paginate && rows && rows.length > 0 && /*#__PURE__*/_react.default.createElement(_Pagination.default, {
|
|
217
201
|
currentPage: currentPage,
|
|
218
202
|
itemsPerPage: paginate,
|
|
@@ -223,5 +207,4 @@ var MainTable = function MainTable(_ref6) {
|
|
|
223
207
|
totalItems: rows.length
|
|
224
208
|
}));
|
|
225
209
|
};
|
|
226
|
-
var _default = MainTable;
|
|
227
|
-
exports.default = _default;
|
|
210
|
+
var _default = exports.default = MainTable;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
@@ -8,32 +7,31 @@ exports.default = exports.Modal = void 0;
|
|
|
8
7
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
9
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
9
|
var _useId = require("../../hooks/useId");
|
|
11
|
-
|
|
12
|
-
function
|
|
13
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
10
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
11
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
14
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
13
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
14
|
+
const Modal = _ref => {
|
|
15
|
+
let {
|
|
16
|
+
buttonRow,
|
|
17
|
+
children,
|
|
18
|
+
className,
|
|
19
|
+
close,
|
|
20
|
+
title,
|
|
21
|
+
...wrapperProps
|
|
22
|
+
} = _ref;
|
|
25
23
|
// list of focusable selectors is based on this Stack Overflow answer:
|
|
26
24
|
// https://stackoverflow.com/a/30753870/3732840
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
const focusableElementSelectors = 'a[href]:not([tabindex="-1"]), button:not([disabled]), textarea:not([disabled]):not([tabindex="-1"]), input:not([disabled]):not([tabindex="-1"]), select:not([disabled]):not([tabindex="-1"]), area[href]:not([tabindex="-1"]), iframe:not([tabindex="-1"]), [tabindex]:not([tabindex="-1"]), [contentEditable=true]:not([tabindex="-1"])';
|
|
26
|
+
const descriptionId = (0, _useId.useId)();
|
|
27
|
+
const titleId = (0, _useId.useId)();
|
|
28
|
+
const shouldClose = (0, _react.useRef)(false);
|
|
29
|
+
const modalRef = (0, _react.useRef)(null);
|
|
30
|
+
const focusableModalElements = (0, _react.useRef)(null);
|
|
31
|
+
const handleTabKey = e => {
|
|
34
32
|
if (focusableModalElements.current.length > 0) {
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
const firstElement = focusableModalElements.current[0];
|
|
34
|
+
const lastElement = focusableModalElements.current[focusableModalElements.current.length - 1];
|
|
37
35
|
if (!e.shiftKey && document.activeElement === lastElement) {
|
|
38
36
|
firstElement.focus();
|
|
39
37
|
e.preventDefault();
|
|
@@ -44,46 +42,54 @@ var Modal = function Modal(_ref) {
|
|
|
44
42
|
}
|
|
45
43
|
}
|
|
46
44
|
};
|
|
47
|
-
|
|
48
|
-
e.nativeEvent.stopImmediatePropagation
|
|
45
|
+
const handleEscKey = e => {
|
|
46
|
+
if ("nativeEvent" in e && e.nativeEvent.stopImmediatePropagation) {
|
|
47
|
+
e.nativeEvent.stopImmediatePropagation();
|
|
48
|
+
} else if ("stopImmediatePropagation" in e) {
|
|
49
|
+
e.stopImmediatePropagation();
|
|
50
|
+
} else if (e.stopPropagation) {
|
|
51
|
+
e.stopPropagation();
|
|
52
|
+
}
|
|
49
53
|
close();
|
|
50
54
|
};
|
|
51
|
-
|
|
52
|
-
(0, _react.useEffect)(
|
|
55
|
+
const keyListenersMap = new Map([["Escape", handleEscKey], ["Tab", handleTabKey]]);
|
|
56
|
+
(0, _react.useEffect)(() => {
|
|
53
57
|
modalRef.current.focus();
|
|
54
58
|
}, [modalRef]);
|
|
55
|
-
(0, _react.useEffect)(
|
|
59
|
+
(0, _react.useEffect)(() => {
|
|
56
60
|
var _focusableModalElemen;
|
|
57
61
|
focusableModalElements.current = modalRef.current.querySelectorAll(focusableElementSelectors);
|
|
58
|
-
|
|
62
|
+
let focusIndex = 0;
|
|
59
63
|
// when the close button is rendered, focus on the 2nd content element and not the close btn.
|
|
60
64
|
if (close && focusableModalElements.current.length > 1) {
|
|
61
65
|
focusIndex = 1;
|
|
62
66
|
}
|
|
63
|
-
(_focusableModalElemen = focusableModalElements.current[focusIndex]) === null || _focusableModalElemen === void 0
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
(_focusableModalElemen = focusableModalElements.current[focusIndex]) === null || _focusableModalElemen === void 0 || _focusableModalElemen.focus({
|
|
68
|
+
preventScroll: true
|
|
69
|
+
});
|
|
70
|
+
}, [close]);
|
|
71
|
+
(0, _react.useEffect)(() => {
|
|
72
|
+
const keyDown = e => {
|
|
73
|
+
const listener = keyListenersMap.get(e.code);
|
|
68
74
|
return listener && listener(e);
|
|
69
75
|
};
|
|
70
76
|
document.addEventListener("keydown", keyDown);
|
|
71
|
-
return
|
|
77
|
+
return () => {
|
|
72
78
|
document.removeEventListener("keydown", keyDown);
|
|
73
79
|
};
|
|
74
80
|
});
|
|
75
|
-
|
|
81
|
+
const handleContentOnMouseDown = () => {
|
|
76
82
|
shouldClose.current = false;
|
|
77
83
|
};
|
|
78
|
-
|
|
84
|
+
const handleContentOnMouseUp = () => {
|
|
79
85
|
shouldClose.current = false;
|
|
80
86
|
};
|
|
81
|
-
|
|
87
|
+
const handleOverlayOnMouseDown = event => {
|
|
82
88
|
if (event.target === modalRef.current) {
|
|
83
89
|
shouldClose.current = true;
|
|
84
90
|
}
|
|
85
91
|
};
|
|
86
|
-
|
|
92
|
+
const handleOverlayOnClick = () => {
|
|
87
93
|
if (shouldClose.current) {
|
|
88
94
|
close();
|
|
89
95
|
}
|
|
@@ -118,5 +124,4 @@ var Modal = function Modal(_ref) {
|
|
|
118
124
|
}, buttonRow)));
|
|
119
125
|
};
|
|
120
126
|
exports.Modal = Modal;
|
|
121
|
-
var _default = Modal;
|
|
122
|
-
exports.default = _default;
|
|
127
|
+
var _default = exports.default = Modal;
|