@canonical/react-components 0.47.1 → 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 +37 -38
- 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 +50 -69
- 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 +42 -35
- package/dist/hooks/useClickOutside.d.ts +0 -6
- package/dist/hooks/useClickOutside.js +0 -32
|
@@ -1,21 +1,20 @@
|
|
|
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
|
});
|
|
7
6
|
Object.defineProperty(exports, "colSizes", {
|
|
8
7
|
enumerable: true,
|
|
9
|
-
get: function
|
|
8
|
+
get: function () {
|
|
10
9
|
return _Col.colSizes;
|
|
11
10
|
}
|
|
12
11
|
});
|
|
13
12
|
Object.defineProperty(exports, "default", {
|
|
14
13
|
enumerable: true,
|
|
15
|
-
get: function
|
|
14
|
+
get: function () {
|
|
16
15
|
return _Col.default;
|
|
17
16
|
}
|
|
18
17
|
});
|
|
19
18
|
var _Col = _interopRequireWildcard(require("./Col"));
|
|
20
|
-
function _getRequireWildcardCache(
|
|
21
|
-
function _interopRequireWildcard(
|
|
19
|
+
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); }
|
|
20
|
+
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; }
|
|
@@ -8,35 +8,33 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
8
8
|
var _ActionButton = _interopRequireDefault(require("../ActionButton"));
|
|
9
9
|
var _ConfirmationModal = _interopRequireDefault(require("../ConfirmationModal"));
|
|
10
10
|
var _reactUseportal = _interopRequireDefault(require("react-useportal"));
|
|
11
|
-
var _excluded = ["confirmationModalProps", "onHoverText", "shiftClickEnabled", "showShiftClickHint"];
|
|
12
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
12
|
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); }
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
var handleCancelModal = function handleCancelModal() {
|
|
13
|
+
const ConfirmationButton = _ref => {
|
|
14
|
+
let {
|
|
15
|
+
confirmationModalProps,
|
|
16
|
+
onHoverText,
|
|
17
|
+
shiftClickEnabled = false,
|
|
18
|
+
showShiftClickHint = false,
|
|
19
|
+
...actionButtonProps
|
|
20
|
+
} = _ref;
|
|
21
|
+
const {
|
|
22
|
+
openPortal,
|
|
23
|
+
closePortal,
|
|
24
|
+
isOpen,
|
|
25
|
+
Portal
|
|
26
|
+
} = (0, _reactUseportal.default)();
|
|
27
|
+
const handleCancelModal = () => {
|
|
30
28
|
closePortal();
|
|
31
29
|
if (confirmationModalProps.close) {
|
|
32
30
|
confirmationModalProps.close();
|
|
33
31
|
}
|
|
34
32
|
};
|
|
35
|
-
|
|
33
|
+
const handleConfirmModal = e => {
|
|
36
34
|
closePortal();
|
|
37
35
|
confirmationModalProps.onConfirm(e);
|
|
38
36
|
};
|
|
39
|
-
|
|
37
|
+
const handleShiftClick = e => {
|
|
40
38
|
if (e.shiftKey) {
|
|
41
39
|
confirmationModalProps.onConfirm(e);
|
|
42
40
|
} else {
|
|
@@ -55,5 +53,4 @@ var ConfirmationButton = function ConfirmationButton(_ref) {
|
|
|
55
53
|
}), actionButtonProps.children));
|
|
56
54
|
};
|
|
57
55
|
exports.ConfirmationButton = ConfirmationButton;
|
|
58
|
-
var _default = ConfirmationButton;
|
|
59
|
-
exports.default = _default;
|
|
56
|
+
var _default = exports.default = ConfirmationButton;
|
|
@@ -7,21 +7,18 @@ exports.default = exports.ConfirmationModal = void 0;
|
|
|
7
7
|
var _react = _interopRequireDefault(require("react"));
|
|
8
8
|
var _Button = _interopRequireDefault(require("../Button"));
|
|
9
9
|
var _Modal = _interopRequireDefault(require("../Modal"));
|
|
10
|
-
var _excluded = ["cancelButtonLabel", "children", "confirmButtonAppearance", "confirmButtonLabel", "confirmExtra", "onConfirm"];
|
|
11
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
11
|
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); }
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
onConfirm = _ref.onConfirm,
|
|
24
|
-
props = _objectWithoutProperties(_ref, _excluded);
|
|
12
|
+
const ConfirmationModal = _ref => {
|
|
13
|
+
let {
|
|
14
|
+
cancelButtonLabel = "Cancel",
|
|
15
|
+
children,
|
|
16
|
+
confirmButtonAppearance = "negative",
|
|
17
|
+
confirmButtonLabel,
|
|
18
|
+
confirmExtra,
|
|
19
|
+
onConfirm,
|
|
20
|
+
...props
|
|
21
|
+
} = _ref;
|
|
25
22
|
return /*#__PURE__*/_react.default.createElement(_Modal.default, _extends({
|
|
26
23
|
buttonRow: /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, confirmExtra, /*#__PURE__*/_react.default.createElement(_Button.default, {
|
|
27
24
|
className: "u-no-margin--bottom",
|
|
@@ -34,5 +31,4 @@ var ConfirmationModal = function ConfirmationModal(_ref) {
|
|
|
34
31
|
}, props), children);
|
|
35
32
|
};
|
|
36
33
|
exports.ConfirmationModal = ConfirmationModal;
|
|
37
|
-
var _default = ConfirmationModal;
|
|
38
|
-
exports.default = _default;
|
|
34
|
+
var _default = exports.default = ConfirmationModal;
|
|
@@ -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,23 +11,11 @@ var _hooks = require("../../hooks");
|
|
|
12
11
|
var _Button = _interopRequireDefault(require("../Button"));
|
|
13
12
|
var _ContextualMenuDropdown = _interopRequireDefault(require("./ContextualMenuDropdown"));
|
|
14
13
|
var _useId = require("../../hooks/useId");
|
|
15
|
-
|
|
16
|
-
function
|
|
17
|
-
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; }
|
|
14
|
+
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); }
|
|
15
|
+
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; }
|
|
18
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
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); }
|
|
20
|
-
|
|
21
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
22
|
-
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
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) {
|
|
18
|
+
let Label = exports.Label = /*#__PURE__*/function (Label) {
|
|
32
19
|
Label["Toggle"] = "Toggle menu";
|
|
33
20
|
return Label;
|
|
34
21
|
}({});
|
|
@@ -36,19 +23,18 @@ var Label = /*#__PURE__*/function (Label) {
|
|
|
36
23
|
* The props for the ContextualMenu component.
|
|
37
24
|
* @template L - The type of the link props.
|
|
38
25
|
*/
|
|
39
|
-
exports.Label = Label;
|
|
40
26
|
/**
|
|
41
27
|
* Get the node to use for positioning the menu.
|
|
42
28
|
* @param wrapper - The component's wrapping element.
|
|
43
29
|
* @param positionNode - A positioning node, if supplied.
|
|
44
30
|
* @return A node or null.
|
|
45
31
|
*/
|
|
46
|
-
|
|
32
|
+
const getPositionNode = (wrapper, positionNode) => {
|
|
47
33
|
if (positionNode) {
|
|
48
34
|
return positionNode;
|
|
49
35
|
} else if (wrapper) {
|
|
50
36
|
// We want to position the menu in relation to the toggle, if it exists.
|
|
51
|
-
|
|
37
|
+
const toggle = wrapper.querySelector(".p-contextual-menu__toggle");
|
|
52
38
|
return toggle || wrapper;
|
|
53
39
|
}
|
|
54
40
|
return null;
|
|
@@ -59,7 +45,7 @@ var getPositionNode = function getPositionNode(wrapper, positionNode) {
|
|
|
59
45
|
* @param positionNode - The node that is used to position the menu.
|
|
60
46
|
* @return Whether the positioning node is visible.
|
|
61
47
|
*/
|
|
62
|
-
|
|
48
|
+
const getPositionNodeVisible = positionNode => {
|
|
63
49
|
return !positionNode || positionNode.offsetParent !== null;
|
|
64
50
|
};
|
|
65
51
|
|
|
@@ -85,83 +71,78 @@ var getPositionNodeVisible = function getPositionNodeVisible(positionNode) {
|
|
|
85
71
|
* @param [toggleLabelFirst=true] - Whether the toggle lable or icon should appear first.
|
|
86
72
|
* @param [visible=false] - Whether the menu should be visible.
|
|
87
73
|
*/
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
autoAdjust =
|
|
91
|
-
children
|
|
92
|
-
className
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
positionCoords = _useState2[0],
|
|
122
|
-
setPositionCoords = _useState2[1];
|
|
123
|
-
var _useState3 = (0, _react.useState)(position),
|
|
124
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
125
|
-
adjustedPosition = _useState4[0],
|
|
126
|
-
setAdjustedPosition = _useState4[1];
|
|
127
|
-
var hasToggle = hasToggleIcon || toggleLabel;
|
|
74
|
+
const ContextualMenu = _ref => {
|
|
75
|
+
let {
|
|
76
|
+
autoAdjust = true,
|
|
77
|
+
children,
|
|
78
|
+
className,
|
|
79
|
+
closeOnEsc = true,
|
|
80
|
+
closeOnOutsideClick = true,
|
|
81
|
+
constrainPanelWidth,
|
|
82
|
+
dropdownClassName,
|
|
83
|
+
dropdownProps,
|
|
84
|
+
hasToggleIcon,
|
|
85
|
+
links,
|
|
86
|
+
onToggleMenu,
|
|
87
|
+
position = "right",
|
|
88
|
+
positionNode,
|
|
89
|
+
scrollOverflow,
|
|
90
|
+
toggleAppearance,
|
|
91
|
+
toggleClassName,
|
|
92
|
+
toggleDisabled,
|
|
93
|
+
toggleLabel,
|
|
94
|
+
toggleLabelFirst = true,
|
|
95
|
+
toggleProps,
|
|
96
|
+
visible = false,
|
|
97
|
+
...wrapperProps
|
|
98
|
+
} = _ref;
|
|
99
|
+
const id = (0, _useId.useId)();
|
|
100
|
+
const wrapper = (0, _react.useRef)(null);
|
|
101
|
+
const [positionCoords, setPositionCoords] = (0, _react.useState)();
|
|
102
|
+
const [adjustedPosition, setAdjustedPosition] = (0, _react.useState)(position);
|
|
103
|
+
const hasToggle = hasToggleIcon || toggleLabel;
|
|
104
|
+
(0, _react.useEffect)(() => {
|
|
105
|
+
setAdjustedPosition(position);
|
|
106
|
+
}, [position, autoAdjust]);
|
|
128
107
|
|
|
129
108
|
// Update the coordinates of the position node.
|
|
130
|
-
|
|
131
|
-
|
|
109
|
+
const updatePositionCoords = (0, _react.useCallback)(() => {
|
|
110
|
+
const parent = getPositionNode(wrapper.current, positionNode);
|
|
132
111
|
if (!parent) {
|
|
133
112
|
return null;
|
|
134
113
|
}
|
|
135
114
|
setPositionCoords(parent.getBoundingClientRect());
|
|
136
115
|
}, [wrapper, positionNode]);
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
116
|
+
const {
|
|
117
|
+
openPortal,
|
|
118
|
+
closePortal,
|
|
119
|
+
isOpen,
|
|
120
|
+
Portal
|
|
121
|
+
} = (0, _reactUseportal.default)({
|
|
122
|
+
closeOnEsc,
|
|
123
|
+
closeOnOutsideClick,
|
|
124
|
+
isOpen: visible,
|
|
125
|
+
onOpen: () => {
|
|
126
|
+
// Call the toggle callback, if supplied.
|
|
127
|
+
onToggleMenu && onToggleMenu(true);
|
|
128
|
+
// When the menu opens then update the coordinates of the parent.
|
|
129
|
+
updatePositionCoords();
|
|
130
|
+
},
|
|
131
|
+
onClose: () => {
|
|
132
|
+
// Call the toggle callback, if supplied.
|
|
133
|
+
onToggleMenu && onToggleMenu(false);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
const previousVisible = (0, _hooks.usePrevious)(visible);
|
|
137
|
+
const labelNode = toggleLabel && typeof toggleLabel === "string" ? /*#__PURE__*/_react.default.createElement("span", null, toggleLabel) : /*#__PURE__*/_react.default.isValidElement(toggleLabel) ? toggleLabel : null;
|
|
138
|
+
const contextualMenuClassName = (0, _classnames.default)(className, "p-contextual-menu", {
|
|
139
|
+
["p-contextual-menu--".concat(adjustedPosition)]: adjustedPosition !== "right"
|
|
140
|
+
});
|
|
160
141
|
|
|
161
142
|
// Update the coordinates of the wrapper once it mounts to the dom. This uses
|
|
162
143
|
// The callback ref pattern:
|
|
163
144
|
// https://reactjs.org/docs/hooks-faq.html#how-can-i-measure-a-dom-node
|
|
164
|
-
|
|
145
|
+
const wrapperRef = (0, _react.useCallback)(node => {
|
|
165
146
|
wrapper.current = node;
|
|
166
147
|
if (node !== null) {
|
|
167
148
|
updatePositionCoords();
|
|
@@ -170,7 +151,7 @@ var ContextualMenu = function ContextualMenu(_ref) {
|
|
|
170
151
|
|
|
171
152
|
// Handle controlling updates to the menu visibility from outside
|
|
172
153
|
// the component.
|
|
173
|
-
(0, _react.useEffect)(
|
|
154
|
+
(0, _react.useEffect)(() => {
|
|
174
155
|
if (visible !== previousVisible) {
|
|
175
156
|
if (visible && !isOpen) {
|
|
176
157
|
openPortal();
|
|
@@ -179,8 +160,8 @@ var ContextualMenu = function ContextualMenu(_ref) {
|
|
|
179
160
|
}
|
|
180
161
|
}
|
|
181
162
|
}, [closePortal, openPortal, visible, isOpen, previousVisible]);
|
|
182
|
-
|
|
183
|
-
|
|
163
|
+
const onResize = (0, _react.useCallback)(evt => {
|
|
164
|
+
const parent = getPositionNode(wrapper.current, positionNode);
|
|
184
165
|
if (parent && !getPositionNodeVisible(parent)) {
|
|
185
166
|
// Hide the menu if the item has become hidden. This might happen in
|
|
186
167
|
// a responsive table when columns become hidden as the page
|
|
@@ -192,13 +173,20 @@ var ContextualMenu = function ContextualMenu(_ref) {
|
|
|
192
173
|
updatePositionCoords();
|
|
193
174
|
}
|
|
194
175
|
}, [closePortal, positionNode, updatePositionCoords]);
|
|
176
|
+
const onScroll = (0, _react.useCallback)(e => {
|
|
177
|
+
const parent = getPositionNode(wrapper.current, positionNode);
|
|
178
|
+
// update position if the scroll event is triggered by the parent of the menu
|
|
179
|
+
if (parent && e.target.contains(parent)) {
|
|
180
|
+
// Update the coordinates so that the menu stays relative to the
|
|
181
|
+
// toggle button.
|
|
182
|
+
updatePositionCoords();
|
|
183
|
+
}
|
|
184
|
+
}, [positionNode, updatePositionCoords]);
|
|
195
185
|
(0, _hooks.useListener)(window, onResize, "resize", true, isOpen);
|
|
186
|
+
(0, _hooks.useListener)(window, onScroll, "scroll", false, isOpen, true);
|
|
196
187
|
return /*#__PURE__*/_react.default.createElement("span", _extends({
|
|
197
|
-
className:
|
|
198
|
-
ref: wrapperRef
|
|
199
|
-
style: positionNode ? null : {
|
|
200
|
-
position: "relative"
|
|
201
|
-
}
|
|
188
|
+
className: contextualMenuClassName,
|
|
189
|
+
ref: wrapperRef
|
|
202
190
|
}, wrapperProps), hasToggle ? /*#__PURE__*/_react.default.createElement(_Button.default, _extends({
|
|
203
191
|
appearance: toggleAppearance,
|
|
204
192
|
"aria-controls": id,
|
|
@@ -209,7 +197,7 @@ var ContextualMenu = function ContextualMenu(_ref) {
|
|
|
209
197
|
className: (0, _classnames.default)("p-contextual-menu__toggle", toggleClassName),
|
|
210
198
|
disabled: toggleDisabled,
|
|
211
199
|
hasIcon: hasToggleIcon,
|
|
212
|
-
onClick:
|
|
200
|
+
onClick: evt => {
|
|
213
201
|
if (!isOpen) {
|
|
214
202
|
openPortal(evt);
|
|
215
203
|
} else {
|
|
@@ -221,15 +209,10 @@ var ContextualMenu = function ContextualMenu(_ref) {
|
|
|
221
209
|
className: (0, _classnames.default)("p-icon--chevron-down p-contextual-menu__indicator", {
|
|
222
210
|
"is-light": ["negative", "positive"].includes(toggleAppearance)
|
|
223
211
|
})
|
|
224
|
-
}) : null, toggleLabelFirst ? null : labelNode) : /*#__PURE__*/_react.default.createElement(
|
|
225
|
-
style: {
|
|
226
|
-
display: "none"
|
|
227
|
-
},
|
|
228
|
-
ref: ref
|
|
229
|
-
})), isOpen && /*#__PURE__*/_react.default.createElement(Portal, null, /*#__PURE__*/_react.default.createElement(_ContextualMenuDropdown.default, _extends({
|
|
212
|
+
}) : null, toggleLabelFirst ? null : labelNode) : null, isOpen && /*#__PURE__*/_react.default.createElement(Portal, null, /*#__PURE__*/_react.default.createElement(_ContextualMenuDropdown.default, _extends({
|
|
230
213
|
adjustedPosition: adjustedPosition,
|
|
231
214
|
autoAdjust: autoAdjust,
|
|
232
|
-
|
|
215
|
+
handleClose: closePortal,
|
|
233
216
|
constrainPanelWidth: constrainPanelWidth,
|
|
234
217
|
dropdownClassName: dropdownClassName,
|
|
235
218
|
dropdownContent: children,
|
|
@@ -238,11 +221,10 @@ var ContextualMenu = function ContextualMenu(_ref) {
|
|
|
238
221
|
links: links,
|
|
239
222
|
position: position,
|
|
240
223
|
positionCoords: positionCoords,
|
|
241
|
-
|
|
224
|
+
contextualMenuClassName: contextualMenuClassName,
|
|
225
|
+
positionNode: getPositionNode(wrapper.current),
|
|
242
226
|
scrollOverflow: scrollOverflow,
|
|
243
|
-
setAdjustedPosition: setAdjustedPosition
|
|
244
|
-
wrapperClass: wrapperClass
|
|
227
|
+
setAdjustedPosition: setAdjustedPosition
|
|
245
228
|
}, dropdownProps))));
|
|
246
229
|
};
|
|
247
|
-
var _default = ContextualMenu;
|
|
248
|
-
exports.default = _default;
|
|
230
|
+
var _default = exports.default = ContextualMenu;
|
|
@@ -18,7 +18,7 @@ export type Position = "left" | "center" | "right";
|
|
|
18
18
|
export type Props<L = null> = {
|
|
19
19
|
adjustedPosition?: Position;
|
|
20
20
|
autoAdjust?: boolean;
|
|
21
|
-
|
|
21
|
+
handleClose?: (evt?: MouseEvent) => void;
|
|
22
22
|
constrainPanelWidth?: boolean;
|
|
23
23
|
dropdownClassName?: string;
|
|
24
24
|
dropdownContent?: ReactNode | ((close: () => void) => ReactElement);
|
|
@@ -26,11 +26,11 @@ export type Props<L = null> = {
|
|
|
26
26
|
isOpen?: boolean;
|
|
27
27
|
links?: MenuLink<L>[];
|
|
28
28
|
position?: Position;
|
|
29
|
-
positionCoords?:
|
|
29
|
+
positionCoords?: DOMRect;
|
|
30
30
|
positionNode?: HTMLElement;
|
|
31
31
|
scrollOverflow?: boolean;
|
|
32
32
|
setAdjustedPosition?: (position: Position) => void;
|
|
33
|
-
|
|
33
|
+
contextualMenuClassName?: string;
|
|
34
34
|
} & HTMLProps<HTMLSpanElement>;
|
|
35
35
|
/**
|
|
36
36
|
* Calculate the adjusted position in relation to the window.
|
|
@@ -39,5 +39,5 @@ export type Props<L = null> = {
|
|
|
39
39
|
* @return The new position.
|
|
40
40
|
*/
|
|
41
41
|
export declare const adjustForWindow: (position: Position, fitsWindow: WindowFitment) => Position;
|
|
42
|
-
declare const ContextualMenuDropdown: <L>({ adjustedPosition, autoAdjust,
|
|
42
|
+
declare const ContextualMenuDropdown: <L>({ adjustedPosition, autoAdjust, handleClose, constrainPanelWidth, dropdownClassName, dropdownContent, id, isOpen, links, position, positionCoords, positionNode, scrollOverflow, setAdjustedPosition, contextualMenuClassName, ...props }: Props<L>) => JSX.Element;
|
|
43
43
|
export default ContextualMenuDropdown;
|