@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
|
});
|
|
@@ -10,80 +9,71 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
10
9
|
var _Chip = _interopRequireDefault(require("../../Chip"));
|
|
11
10
|
var _utils = require("../utils");
|
|
12
11
|
var _utils2 = require("../../../utils");
|
|
13
|
-
function _getRequireWildcardCache(
|
|
14
|
-
function _interopRequireWildcard(
|
|
12
|
+
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); }
|
|
13
|
+
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; }
|
|
15
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
33
|
-
overflowCounter = _useState2[0],
|
|
34
|
-
setOverflowCounter = _useState2[1];
|
|
35
|
-
var _useState3 = (0, _react.useState)(false),
|
|
36
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
37
|
-
expanded = _useState4[0],
|
|
38
|
-
setExpanded = _useState4[1];
|
|
39
|
-
var chipWrapper = (0, _react.useRef)(null);
|
|
40
|
-
var handleChipClick = function handleChipClick(chip) {
|
|
15
|
+
const FilterPanelSection = _ref => {
|
|
16
|
+
let {
|
|
17
|
+
data,
|
|
18
|
+
searchData,
|
|
19
|
+
searchTerm = "",
|
|
20
|
+
sectionHidden,
|
|
21
|
+
toggleSelected
|
|
22
|
+
} = _ref;
|
|
23
|
+
const {
|
|
24
|
+
chips,
|
|
25
|
+
heading
|
|
26
|
+
} = data;
|
|
27
|
+
const [overflowCounter, setOverflowCounter] = (0, _react.useState)(0);
|
|
28
|
+
const [expanded, setExpanded] = (0, _react.useState)(false);
|
|
29
|
+
const chipWrapper = (0, _react.useRef)(null);
|
|
30
|
+
const handleChipClick = chip => {
|
|
41
31
|
toggleSelected(chip);
|
|
42
32
|
};
|
|
43
33
|
|
|
44
34
|
// If the offsetTop is more than double height of a single chip, consider it
|
|
45
35
|
// overflowing
|
|
46
|
-
|
|
36
|
+
const updateFlowCount = function () {
|
|
47
37
|
var _chipWrapper$current;
|
|
48
|
-
|
|
49
|
-
|
|
38
|
+
const chips = chipWrapper === null || chipWrapper === void 0 || (_chipWrapper$current = chipWrapper.current) === null || _chipWrapper$current === void 0 ? void 0 : _chipWrapper$current.querySelectorAll(".p-chip");
|
|
39
|
+
const overflowCount = (0, _utils.overflowingChipsCount)(chips, 2);
|
|
50
40
|
setOverflowCounter(overflowCount);
|
|
51
41
|
};
|
|
52
42
|
|
|
53
43
|
// Check if search term characters matches any characters in panel heading
|
|
54
|
-
|
|
44
|
+
const searchTermInHeading = (0, _utils2.highlightSubString)(heading, searchTerm).match;
|
|
55
45
|
|
|
56
46
|
// Serialise chip values into string so it can be interrogated with subString
|
|
57
|
-
|
|
58
|
-
Object.entries(chips).forEach(
|
|
47
|
+
const chipValues = [];
|
|
48
|
+
Object.entries(chips).forEach(chipValue => {
|
|
59
49
|
chipValues.push(chipValue[1].value);
|
|
60
50
|
});
|
|
61
51
|
|
|
62
52
|
// Search chips for character match with search term
|
|
63
|
-
|
|
64
|
-
|
|
53
|
+
const searchTermInChips = (0, _utils2.highlightSubString)(chipValues.toString(), searchTerm).match;
|
|
54
|
+
const panelSectionVisible = searchTermInHeading || searchTermInChips || searchTerm === "";
|
|
65
55
|
|
|
66
56
|
// Update overflow count when component is resized
|
|
67
|
-
(0, _react.useEffect)(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
57
|
+
(0, _react.useEffect)(() => {
|
|
58
|
+
const resizeObserverSupported = typeof ResizeObserver !== "undefined";
|
|
59
|
+
const wrapper = chipWrapper === null || chipWrapper === void 0 ? void 0 : chipWrapper.current;
|
|
60
|
+
let wrapperWidthObserver;
|
|
71
61
|
if (resizeObserverSupported && panelSectionVisible) {
|
|
72
|
-
wrapperWidthObserver = new ResizeObserver(
|
|
62
|
+
wrapperWidthObserver = new ResizeObserver(() => {
|
|
73
63
|
updateFlowCount();
|
|
74
64
|
});
|
|
75
65
|
wrapperWidthObserver.observe(wrapper);
|
|
76
66
|
} else {
|
|
77
67
|
updateFlowCount();
|
|
78
68
|
}
|
|
79
|
-
return
|
|
69
|
+
return () => {
|
|
80
70
|
var _wrapperWidthObserver;
|
|
81
71
|
resizeObserverSupported && ((_wrapperWidthObserver = wrapperWidthObserver) === null || _wrapperWidthObserver === void 0 ? void 0 : _wrapperWidthObserver.disconnect());
|
|
82
72
|
};
|
|
83
73
|
}, [panelSectionVisible]);
|
|
84
74
|
|
|
85
75
|
// When overflow counter is clicked, all chips are shown
|
|
86
|
-
|
|
76
|
+
const showAllChips = () => {
|
|
87
77
|
setExpanded(true);
|
|
88
78
|
};
|
|
89
79
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, panelSectionVisible && /*#__PURE__*/_react.default.createElement("div", {
|
|
@@ -97,20 +87,18 @@ var FilterPanelSection = function FilterPanelSection(_ref) {
|
|
|
97
87
|
className: "p-filter-panel-section__chips",
|
|
98
88
|
"aria-expanded": expanded,
|
|
99
89
|
ref: chipWrapper
|
|
100
|
-
}, chips === null || chips === void 0 ? void 0 : chips.map(
|
|
90
|
+
}, chips === null || chips === void 0 ? void 0 : chips.map(chip => {
|
|
101
91
|
// If search term has been added to input, only matching chips
|
|
102
92
|
// should display
|
|
103
|
-
|
|
104
|
-
|
|
93
|
+
const searchTermInChip = (0, _utils2.highlightSubString)(chip.value, searchTerm).match;
|
|
94
|
+
const chipVisible = searchTermInChip || searchTerm === "" || (0, _utils2.highlightSubString)(heading, searchTerm).match;
|
|
105
95
|
return chipVisible && !sectionHidden && /*#__PURE__*/_react.default.createElement(_Chip.default, {
|
|
106
96
|
key: "".concat(chip.lead, "+").concat(chip.value),
|
|
107
97
|
lead: chip.lead,
|
|
108
98
|
value: chip.value,
|
|
109
99
|
selected: (0, _utils.isChipInArray)(chip, searchData),
|
|
110
100
|
subString: searchTerm,
|
|
111
|
-
onClick:
|
|
112
|
-
return handleChipClick(chip);
|
|
113
|
-
}
|
|
101
|
+
onClick: () => handleChipClick(chip)
|
|
114
102
|
});
|
|
115
103
|
}), overflowCounter > 0 && !expanded && /*#__PURE__*/_react.default.createElement("span", {
|
|
116
104
|
className: "p-filter-panel-section__counter",
|
|
@@ -125,5 +113,4 @@ FilterPanelSection.propTypes = {
|
|
|
125
113
|
sectionHidden: _propTypes.default.bool,
|
|
126
114
|
toggleSelected: _propTypes.default.func.isRequired
|
|
127
115
|
};
|
|
128
|
-
var _default = FilterPanelSection;
|
|
129
|
-
exports.default = _default;
|
|
116
|
+
var _default = exports.default = FilterPanelSection;
|
|
@@ -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
|
});
|
|
@@ -11,72 +10,36 @@ var _FilterPanelSection = _interopRequireDefault(require("./FilterPanelSection")
|
|
|
11
10
|
var _Chip = _interopRequireDefault(require("../Chip"));
|
|
12
11
|
var _utils = require("./utils");
|
|
13
12
|
var _hooks = require("../../hooks");
|
|
14
|
-
|
|
15
|
-
function
|
|
16
|
-
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; }
|
|
13
|
+
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); }
|
|
14
|
+
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; }
|
|
17
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
16
|
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); }
|
|
19
|
-
|
|
20
|
-
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."); }
|
|
21
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
22
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
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 _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); }
|
|
26
|
-
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; }
|
|
27
|
-
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; } }
|
|
28
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
29
|
-
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
30
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
31
|
-
var Label = /*#__PURE__*/function (Label) {
|
|
17
|
+
let Label = exports.Label = /*#__PURE__*/function (Label) {
|
|
32
18
|
Label["AddFilter"] = "Add filter";
|
|
33
19
|
Label["Clear"] = "Clear input";
|
|
34
20
|
Label["SearchAndFilter"] = "Search and filter";
|
|
35
21
|
return Label;
|
|
36
22
|
}({});
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
_useState6 = _slicedToArray(_useState5, 2),
|
|
58
|
-
filterPanelHidden = _useState6[0],
|
|
59
|
-
setFilterPanelHidden = _useState6[1];
|
|
60
|
-
var _useState7 = (0, _react.useState)(false),
|
|
61
|
-
_useState8 = _slicedToArray(_useState7, 2),
|
|
62
|
-
searchBoxExpanded = _useState8[0],
|
|
63
|
-
setSearchBoxExpanded = _useState8[1];
|
|
64
|
-
var _useState9 = (0, _react.useState)(0),
|
|
65
|
-
_useState10 = _slicedToArray(_useState9, 2),
|
|
66
|
-
overflowSearchTermCounter = _useState10[0],
|
|
67
|
-
setOverflowSearchTermCounter = _useState10[1];
|
|
68
|
-
var _useState11 = (0, _react.useState)(false),
|
|
69
|
-
_useState12 = _slicedToArray(_useState11, 2),
|
|
70
|
-
searchContainerActive = _useState12[0],
|
|
71
|
-
setSearchContainerActive = _useState12[1];
|
|
72
|
-
var _useState13 = (0, _react.useState)(),
|
|
73
|
-
_useState14 = _slicedToArray(_useState13, 2),
|
|
74
|
-
maxHeight = _useState14[0],
|
|
75
|
-
setMaxHeight = _useState14[1];
|
|
76
|
-
var searchAndFilterRef = (0, _react.useRef)(null);
|
|
77
|
-
var searchContainerRef = (0, _react.useRef)(null);
|
|
78
|
-
var searchBoxRef = (0, _react.useRef)(null);
|
|
79
|
-
var panel = (0, _react.useRef)();
|
|
23
|
+
const SearchAndFilter = _ref => {
|
|
24
|
+
let {
|
|
25
|
+
existingSearchData = [],
|
|
26
|
+
filterPanelData,
|
|
27
|
+
returnSearchData,
|
|
28
|
+
onPanelToggle = () => {},
|
|
29
|
+
onExpandChange = () => {},
|
|
30
|
+
...props
|
|
31
|
+
} = _ref;
|
|
32
|
+
const [searchData, setSearchData] = (0, _react.useState)(existingSearchData);
|
|
33
|
+
const [searchTerm, setSearchTerm] = (0, _react.useState)("");
|
|
34
|
+
const [filterPanelHidden, setFilterPanelHidden] = (0, _react.useState)(true);
|
|
35
|
+
const [searchBoxExpanded, setSearchBoxExpanded] = (0, _react.useState)(false);
|
|
36
|
+
const [overflowSearchTermCounter, setOverflowSearchTermCounter] = (0, _react.useState)(0);
|
|
37
|
+
const [searchContainerActive, setSearchContainerActive] = (0, _react.useState)(false);
|
|
38
|
+
const [maxHeight, setMaxHeight] = (0, _react.useState)();
|
|
39
|
+
const searchAndFilterRef = (0, _react.useRef)(null);
|
|
40
|
+
const searchContainerRef = (0, _react.useRef)(null);
|
|
41
|
+
const searchBoxRef = (0, _react.useRef)(null);
|
|
42
|
+
const panel = (0, _react.useRef)();
|
|
80
43
|
|
|
81
44
|
// Call onPanelToggle when the filterPanelHidden state changes
|
|
82
45
|
(0, _react.useEffect)(onPanelToggle, [onPanelToggle, filterPanelHidden]);
|
|
@@ -85,40 +48,38 @@ var SearchAndFilter = function SearchAndFilter(_ref) {
|
|
|
85
48
|
(0, _react.useEffect)(onExpandChange, [onExpandChange, searchBoxExpanded]);
|
|
86
49
|
|
|
87
50
|
// Return searchData to parent component
|
|
88
|
-
(0, _react.useEffect)(
|
|
89
|
-
|
|
51
|
+
(0, _react.useEffect)(() => {
|
|
52
|
+
let mounted = true;
|
|
90
53
|
returnSearchData && mounted && returnSearchData(searchData);
|
|
91
|
-
return
|
|
54
|
+
return () => {
|
|
92
55
|
mounted = false;
|
|
93
56
|
};
|
|
94
57
|
}, [searchData, returnSearchData]);
|
|
95
|
-
|
|
58
|
+
const searchOnChange = searchTerm => {
|
|
96
59
|
setSearchTerm(searchTerm);
|
|
97
60
|
};
|
|
98
61
|
|
|
99
62
|
// Hide manual input form field when search container is inactive
|
|
100
|
-
(0, _react.useEffect)(
|
|
101
|
-
|
|
63
|
+
(0, _react.useEffect)(() => {
|
|
64
|
+
const searchContainerClickCheck = e => {
|
|
102
65
|
var _e$target;
|
|
103
|
-
|
|
66
|
+
const clickInContainer = ((_e$target = e.target) === null || _e$target === void 0 ? void 0 : _e$target.closest(".p-search-and-filter")) !== null;
|
|
104
67
|
setSearchContainerActive(clickInContainer);
|
|
105
68
|
};
|
|
106
69
|
document.addEventListener("click", searchContainerClickCheck);
|
|
107
|
-
return
|
|
70
|
+
return () => {
|
|
108
71
|
document.removeEventListener("click", searchContainerClickCheck);
|
|
109
72
|
};
|
|
110
73
|
}, [searchContainerActive]);
|
|
111
|
-
|
|
74
|
+
const closePanel = () => {
|
|
112
75
|
setFilterPanelHidden(true);
|
|
113
76
|
};
|
|
114
|
-
(0, _hooks.useOnEscapePressed)(
|
|
115
|
-
return closePanel();
|
|
116
|
-
});
|
|
77
|
+
(0, _hooks.useOnEscapePressed)(() => closePanel());
|
|
117
78
|
|
|
118
79
|
// This useEffect sets up listeners so the panel will close if user clicks
|
|
119
80
|
// anywhere else on the page or hits the escape key
|
|
120
|
-
(0, _react.useEffect)(
|
|
121
|
-
|
|
81
|
+
(0, _react.useEffect)(() => {
|
|
82
|
+
const mouseDown = e => {
|
|
122
83
|
var _searchAndFilterRef$c;
|
|
123
84
|
// Check if click is outside of filter panel
|
|
124
85
|
if (!(searchAndFilterRef !== null && searchAndFilterRef !== void 0 && (_searchAndFilterRef$c = searchAndFilterRef.current) !== null && _searchAndFilterRef$c !== void 0 && _searchAndFilterRef$c.contains(e.target))) {
|
|
@@ -130,20 +91,20 @@ var SearchAndFilter = function SearchAndFilter(_ref) {
|
|
|
130
91
|
// Add listener on document to capture click events
|
|
131
92
|
document.addEventListener("mousedown", mouseDown);
|
|
132
93
|
// return function to be called when unmounted
|
|
133
|
-
return
|
|
94
|
+
return () => {
|
|
134
95
|
document.removeEventListener("mousedown", mouseDown);
|
|
135
96
|
};
|
|
136
97
|
}, []);
|
|
137
98
|
|
|
138
99
|
// Add passed chip to the searchData array
|
|
139
|
-
|
|
140
|
-
|
|
100
|
+
const toggleSelected = chip => {
|
|
101
|
+
const currentSelected = [...searchData];
|
|
141
102
|
if (!(0, _utils.isChipInArray)(chip, currentSelected)) {
|
|
142
103
|
currentSelected.push(chip);
|
|
143
104
|
setSearchData(currentSelected);
|
|
144
105
|
setSearchTerm("");
|
|
145
106
|
} else {
|
|
146
|
-
|
|
107
|
+
const updatedCurrentSelected = currentSelected.filter(currentSelectedChip => {
|
|
147
108
|
return currentSelectedChip.value !== chip.value;
|
|
148
109
|
});
|
|
149
110
|
setSearchData(updatedCurrentSelected);
|
|
@@ -151,33 +112,31 @@ var SearchAndFilter = function SearchAndFilter(_ref) {
|
|
|
151
112
|
};
|
|
152
113
|
|
|
153
114
|
// Remove passed chip from the searchData array
|
|
154
|
-
|
|
115
|
+
const removeFromSelected = chip => {
|
|
155
116
|
if (searchData.includes(chip)) {
|
|
156
|
-
|
|
157
|
-
return searchDataChip !== chip;
|
|
158
|
-
});
|
|
117
|
+
const updatedSelected = searchData.filter(searchDataChip => searchDataChip !== chip);
|
|
159
118
|
setSearchData(updatedSelected);
|
|
160
119
|
}
|
|
161
120
|
};
|
|
162
121
|
|
|
163
122
|
// When overflow chips are shown, clicking anywhere outside search area
|
|
164
123
|
// or clicking on a chip should hide them again
|
|
165
|
-
(0, _react.useEffect)(
|
|
166
|
-
|
|
124
|
+
(0, _react.useEffect)(() => {
|
|
125
|
+
const hideOverflowChips = e => {
|
|
167
126
|
if (!e.target.closest(".p-search-and-filter") && e.target.className !== "p-icon--close") {
|
|
168
127
|
setSearchBoxExpanded(false);
|
|
169
128
|
}
|
|
170
129
|
};
|
|
171
|
-
document.addEventListener("click",
|
|
130
|
+
document.addEventListener("click", e => {
|
|
172
131
|
hideOverflowChips(e);
|
|
173
132
|
});
|
|
174
|
-
return
|
|
175
|
-
document.removeEventListener("click",
|
|
133
|
+
return () => {
|
|
134
|
+
document.removeEventListener("click", e => {
|
|
176
135
|
hideOverflowChips(e);
|
|
177
136
|
});
|
|
178
137
|
};
|
|
179
138
|
}, []);
|
|
180
|
-
|
|
139
|
+
const handleSubmit = () => {
|
|
181
140
|
if (searchTerm.trim() !== "") {
|
|
182
141
|
toggleSelected({
|
|
183
142
|
value: searchTerm,
|
|
@@ -189,43 +148,41 @@ var SearchAndFilter = function SearchAndFilter(_ref) {
|
|
|
189
148
|
|
|
190
149
|
// If the offsetTop is more than double height of a single chip, consider it
|
|
191
150
|
// overflowing
|
|
192
|
-
|
|
151
|
+
const updateFlowCount = function () {
|
|
193
152
|
var _searchContainerRef$c;
|
|
194
|
-
|
|
195
|
-
|
|
153
|
+
const chips = searchContainerRef === null || searchContainerRef === void 0 || (_searchContainerRef$c = searchContainerRef.current) === null || _searchContainerRef$c === void 0 ? void 0 : _searchContainerRef$c.querySelectorAll(".p-chip");
|
|
154
|
+
const overflowCount = (0, _utils.overflowingChipsCount)(chips, 1);
|
|
196
155
|
setOverflowSearchTermCounter(overflowCount);
|
|
197
156
|
};
|
|
198
157
|
|
|
199
158
|
// Watch for container resize and recalculate overflow count accordingly
|
|
200
|
-
(0, _react.useEffect)(
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
159
|
+
(0, _react.useEffect)(() => {
|
|
160
|
+
const resizeObserverSupported = typeof ResizeObserver !== "undefined";
|
|
161
|
+
const wrapper = searchContainerRef.current;
|
|
162
|
+
let wrapperWidthObserver;
|
|
204
163
|
if (resizeObserverSupported && wrapper) {
|
|
205
|
-
wrapperWidthObserver = new ResizeObserver(
|
|
164
|
+
wrapperWidthObserver = new ResizeObserver(() => {
|
|
206
165
|
updateFlowCount();
|
|
207
166
|
});
|
|
208
167
|
wrapperWidthObserver.observe(wrapper);
|
|
209
168
|
} else {
|
|
210
169
|
updateFlowCount();
|
|
211
170
|
}
|
|
212
|
-
return
|
|
171
|
+
return () => {
|
|
213
172
|
var _wrapperWidthObserver;
|
|
214
173
|
resizeObserverSupported && ((_wrapperWidthObserver = wrapperWidthObserver) === null || _wrapperWidthObserver === void 0 ? void 0 : _wrapperWidthObserver.disconnect());
|
|
215
174
|
};
|
|
216
175
|
}, [searchData]);
|
|
217
|
-
(0, _hooks.useWindowFitment)(panel.current, searchAndFilterRef.current,
|
|
218
|
-
return setMaxHeight(fitsWindow.fromBottom.spaceBelow - 16);
|
|
219
|
-
}, 0, !filterPanelHidden);
|
|
176
|
+
(0, _hooks.useWindowFitment)(panel.current, searchAndFilterRef.current, fitsWindow => setMaxHeight(fitsWindow.fromBottom.spaceBelow - 16), 0, !filterPanelHidden);
|
|
220
177
|
|
|
221
178
|
// Add search prompt value to search on Enter key
|
|
222
|
-
|
|
179
|
+
const searchPromptKeyDown = e => {
|
|
223
180
|
if (e.key === "Enter") {
|
|
224
181
|
handleSubmit();
|
|
225
182
|
}
|
|
226
183
|
};
|
|
227
|
-
|
|
228
|
-
|
|
184
|
+
const searchBox = searchBoxRef.current;
|
|
185
|
+
const searchContainer = searchContainerRef.current;
|
|
229
186
|
if (!searchBoxExpanded && searchBox && searchContainer && overflowSearchTermCounter === 0) {
|
|
230
187
|
if (searchBox.offsetTop > searchContainer.offsetHeight) {
|
|
231
188
|
setSearchBoxExpanded(true);
|
|
@@ -233,16 +190,14 @@ var SearchAndFilter = function SearchAndFilter(_ref) {
|
|
|
233
190
|
}
|
|
234
191
|
|
|
235
192
|
// If chips or input field contains values, clear 'em out
|
|
236
|
-
|
|
193
|
+
const clearAllSearchTerms = () => {
|
|
237
194
|
setSearchTerm("");
|
|
238
195
|
};
|
|
239
|
-
|
|
196
|
+
const placeholder = searchData.length ? Label.AddFilter : Label.SearchAndFilter;
|
|
240
197
|
return /*#__PURE__*/_react.default.createElement("div", _extends({
|
|
241
198
|
className: "p-search-and-filter",
|
|
242
199
|
ref: searchAndFilterRef,
|
|
243
|
-
onClick:
|
|
244
|
-
return filterPanelHidden && setFilterPanelHidden(false);
|
|
245
|
-
}
|
|
200
|
+
onClick: () => filterPanelHidden && setFilterPanelHidden(false)
|
|
246
201
|
}, props), /*#__PURE__*/_react.default.createElement("div", {
|
|
247
202
|
className: "p-search-and-filter__search-container",
|
|
248
203
|
"aria-expanded": searchBoxExpanded,
|
|
@@ -252,25 +207,21 @@ var SearchAndFilter = function SearchAndFilter(_ref) {
|
|
|
252
207
|
}, searchTerm !== "" && /*#__PURE__*/_react.default.createElement("button", {
|
|
253
208
|
"aria-label": Label.Clear,
|
|
254
209
|
className: "p-search-and-filter__clear",
|
|
255
|
-
onClick:
|
|
256
|
-
return clearAllSearchTerms();
|
|
257
|
-
}
|
|
210
|
+
onClick: () => clearAllSearchTerms()
|
|
258
211
|
}, /*#__PURE__*/_react.default.createElement("i", {
|
|
259
212
|
className: "p-icon--close"
|
|
260
|
-
})), Object.values(searchData).map(
|
|
213
|
+
})), Object.values(searchData).map(chip => {
|
|
261
214
|
return /*#__PURE__*/_react.default.createElement(_Chip.default, {
|
|
262
215
|
lead: chip.lead,
|
|
263
216
|
value: chip.value,
|
|
264
217
|
key: "search-".concat(chip.lead, "+").concat(chip.value),
|
|
265
|
-
onDismiss:
|
|
266
|
-
return removeFromSelected(chip);
|
|
267
|
-
},
|
|
218
|
+
onDismiss: () => removeFromSelected(chip),
|
|
268
219
|
selected: true,
|
|
269
220
|
quoteValue: chip.quoteValue
|
|
270
221
|
});
|
|
271
222
|
}), /*#__PURE__*/_react.default.createElement("form", {
|
|
272
223
|
className: "p-search-and-filter__box",
|
|
273
|
-
onSubmit:
|
|
224
|
+
onSubmit: e => {
|
|
274
225
|
e.preventDefault();
|
|
275
226
|
handleSubmit();
|
|
276
227
|
},
|
|
@@ -284,9 +235,7 @@ var SearchAndFilter = function SearchAndFilter(_ref) {
|
|
|
284
235
|
className: "p-search-and-filter__input",
|
|
285
236
|
id: "search-and-filter-input",
|
|
286
237
|
name: "search",
|
|
287
|
-
onChange:
|
|
288
|
-
return searchOnChange(e.target.value);
|
|
289
|
-
},
|
|
238
|
+
onChange: e => searchOnChange(e.target.value),
|
|
290
239
|
placeholder: placeholder,
|
|
291
240
|
type: "search",
|
|
292
241
|
value: searchTerm
|
|
@@ -295,12 +244,8 @@ var SearchAndFilter = function SearchAndFilter(_ref) {
|
|
|
295
244
|
type: "submit"
|
|
296
245
|
}, "Search")), overflowSearchTermCounter > 0 && /*#__PURE__*/_react.default.createElement("span", {
|
|
297
246
|
className: "p-search-and-filter__selected-count",
|
|
298
|
-
onClick:
|
|
299
|
-
|
|
300
|
-
},
|
|
301
|
-
onKeyDown: function onKeyDown() {
|
|
302
|
-
return setSearchBoxExpanded(true);
|
|
303
|
-
},
|
|
247
|
+
onClick: () => setSearchBoxExpanded(true),
|
|
248
|
+
onKeyDown: () => setSearchBoxExpanded(true),
|
|
304
249
|
role: "button",
|
|
305
250
|
tabIndex: 0
|
|
306
251
|
}, "+", overflowSearchTermCounter)), (filterPanelData.length > 0 || searchTerm.length > 0) && /*#__PURE__*/_react.default.createElement("div", {
|
|
@@ -308,23 +253,19 @@ var SearchAndFilter = function SearchAndFilter(_ref) {
|
|
|
308
253
|
"aria-hidden": filterPanelHidden,
|
|
309
254
|
ref: panel,
|
|
310
255
|
style: {
|
|
311
|
-
maxHeight
|
|
256
|
+
maxHeight,
|
|
312
257
|
minHeight: "5rem",
|
|
313
258
|
overflowX: "auto"
|
|
314
259
|
}
|
|
315
260
|
}, /*#__PURE__*/_react.default.createElement("div", null, searchTerm.length > 0 && /*#__PURE__*/_react.default.createElement("div", {
|
|
316
261
|
className: "p-search-and-filter__search-prompt",
|
|
317
|
-
onClick:
|
|
318
|
-
|
|
319
|
-
},
|
|
320
|
-
onKeyDown: function onKeyDown(e) {
|
|
321
|
-
return searchPromptKeyDown(e);
|
|
322
|
-
},
|
|
262
|
+
onClick: () => handleSubmit(),
|
|
263
|
+
onKeyDown: e => searchPromptKeyDown(e),
|
|
323
264
|
role: "button",
|
|
324
265
|
tabIndex: 0
|
|
325
266
|
}, "Search for", " ", /*#__PURE__*/_react.default.createElement("span", {
|
|
326
267
|
className: "p-search-and-filter__search-query"
|
|
327
|
-
}, searchTerm), "..."), filterPanelData.map(
|
|
268
|
+
}, searchTerm), "..."), filterPanelData.map(filterPanelSectionData => {
|
|
328
269
|
return /*#__PURE__*/_react.default.createElement(_FilterPanelSection.default, {
|
|
329
270
|
key: filterPanelSectionData.id,
|
|
330
271
|
data: filterPanelSectionData,
|
|
@@ -341,5 +282,4 @@ SearchAndFilter.propTypes = {
|
|
|
341
282
|
onPanelToggle: _propTypes.default.func,
|
|
342
283
|
onExpandChange: _propTypes.default.func
|
|
343
284
|
};
|
|
344
|
-
var _default = SearchAndFilter;
|
|
345
|
-
exports.default = _default;
|
|
285
|
+
var _default = exports.default = SearchAndFilter;
|
|
@@ -10,10 +10,10 @@ exports.overflowingChipsCount = exports.isChipInArray = void 0;
|
|
|
10
10
|
* @param {Integer} overflowRowLimit - Number of rows to show before counting
|
|
11
11
|
* overflow
|
|
12
12
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const overflowingChipsCount = (chips, overflowRowLimit) => {
|
|
14
|
+
let overflowChips = 0;
|
|
15
15
|
if (chips) {
|
|
16
|
-
chips.forEach(
|
|
16
|
+
chips.forEach(chip => {
|
|
17
17
|
if (chip.offsetTop > chip.offsetHeight * overflowRowLimit) overflowChips++;
|
|
18
18
|
});
|
|
19
19
|
}
|
|
@@ -26,9 +26,5 @@ var overflowingChipsCount = function overflowingChipsCount(chips, overflowRowLim
|
|
|
26
26
|
* @param {Array} existingArr - An array of chip objects
|
|
27
27
|
*/
|
|
28
28
|
exports.overflowingChipsCount = overflowingChipsCount;
|
|
29
|
-
|
|
30
|
-
return existingArr === null || existingArr === void 0 ? void 0 : existingArr.some(function (searchDataItem) {
|
|
31
|
-
return searchDataItem.lead === chip.lead && searchDataItem.value === chip.value;
|
|
32
|
-
});
|
|
33
|
-
};
|
|
29
|
+
const isChipInArray = (chip, existingArr) => existingArr === null || existingArr === void 0 ? void 0 : existingArr.some(searchDataItem => searchDataItem.lead === chip.lead && searchDataItem.value === chip.value);
|
|
34
30
|
exports.isChipInArray = isChipInArray;
|