@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
|
});
|
|
@@ -9,42 +8,26 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
9
8
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
10
9
|
var _NavigationLink = _interopRequireDefault(require("../NavigationLink"));
|
|
11
10
|
var _hooks = require("../../../hooks");
|
|
12
|
-
var _excluded = ["alignRight", "generateLink", "items", "label"];
|
|
13
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
function _getRequireWildcardCache(
|
|
15
|
-
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; }
|
|
16
14
|
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); }
|
|
17
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
18
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
19
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
20
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
21
|
-
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); }
|
|
22
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
23
|
-
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."); }
|
|
24
|
-
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); }
|
|
25
|
-
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; }
|
|
26
|
-
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; } }
|
|
27
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
28
|
-
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; }
|
|
29
|
-
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; }
|
|
30
15
|
/**
|
|
31
16
|
* This component is used internally to display menus inside the Navigation component.
|
|
32
17
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
var menuRef = (0, _hooks.useClickOutside)(closeMenu);
|
|
47
|
-
var menuId = (0, _hooks.useId)();
|
|
18
|
+
const NavigationMenu = _ref => {
|
|
19
|
+
let {
|
|
20
|
+
alignRight,
|
|
21
|
+
generateLink,
|
|
22
|
+
items,
|
|
23
|
+
label,
|
|
24
|
+
...props
|
|
25
|
+
} = _ref;
|
|
26
|
+
const [isOpen, setIsOpen] = (0, _react.useState)(false);
|
|
27
|
+
const closeMenu = (0, _react.useCallback)(() => setIsOpen(false), [setIsOpen]);
|
|
28
|
+
const menuRef = (0, _react.useRef)(null);
|
|
29
|
+
(0, _hooks.useOnClickOutside)(menuRef, closeMenu);
|
|
30
|
+
const menuId = (0, _hooks.useId)();
|
|
48
31
|
return /*#__PURE__*/_react.default.createElement("li", _extends({}, props, {
|
|
49
32
|
className: (0, _classnames.default)(props.className, "p-navigation__item--dropdown-toggle", {
|
|
50
33
|
"is-active": isOpen
|
|
@@ -53,7 +36,7 @@ var NavigationMenu = function NavigationMenu(_ref) {
|
|
|
53
36
|
}), /*#__PURE__*/_react.default.createElement("button", {
|
|
54
37
|
"aria-controls": menuId,
|
|
55
38
|
className: "p-navigation__link u-no-margin--right",
|
|
56
|
-
onClick:
|
|
39
|
+
onClick: evt => {
|
|
57
40
|
evt.preventDefault();
|
|
58
41
|
setIsOpen(!isOpen);
|
|
59
42
|
}
|
|
@@ -63,16 +46,14 @@ var NavigationMenu = function NavigationMenu(_ref) {
|
|
|
63
46
|
"p-navigation__dropdown--right": alignRight
|
|
64
47
|
}),
|
|
65
48
|
id: menuId
|
|
66
|
-
}, items.map(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
})));
|
|
49
|
+
}, items.map((item, i) => /*#__PURE__*/_react.default.createElement("li", {
|
|
50
|
+
key: i
|
|
51
|
+
}, /*#__PURE__*/_react.default.createElement(_NavigationLink.default, {
|
|
52
|
+
generateLink: generateLink,
|
|
53
|
+
link: {
|
|
54
|
+
...item,
|
|
55
|
+
className: (0, _classnames.default)("p-navigation__dropdown-item", item.className)
|
|
56
|
+
}
|
|
57
|
+
})))));
|
|
76
58
|
};
|
|
77
|
-
var _default = NavigationMenu;
|
|
78
|
-
exports.default = _default;
|
|
59
|
+
var _default = exports.default = NavigationMenu;
|
|
@@ -8,75 +8,68 @@ var _classnames = _interopRequireDefault(require("classnames"));
|
|
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
var _Button = _interopRequireWildcard(require("../Button"));
|
|
10
10
|
var _utils = require("../../utils");
|
|
11
|
-
|
|
12
|
-
var
|
|
13
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
14
|
-
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; }
|
|
11
|
+
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); }
|
|
12
|
+
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
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
-
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); }
|
|
17
14
|
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); }
|
|
18
|
-
|
|
19
|
-
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; }
|
|
20
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
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
|
-
var Label = /*#__PURE__*/function (Label) {
|
|
15
|
+
let Label = exports.Label = /*#__PURE__*/function (Label) {
|
|
24
16
|
Label["Close"] = "Close notification";
|
|
25
17
|
return Label;
|
|
26
18
|
}({});
|
|
27
|
-
exports.
|
|
28
|
-
var NotificationSeverity = {
|
|
19
|
+
const NotificationSeverity = exports.NotificationSeverity = {
|
|
29
20
|
CAUTION: "caution",
|
|
30
21
|
INFORMATION: "information",
|
|
31
22
|
NEGATIVE: "negative",
|
|
32
23
|
POSITIVE: "positive"
|
|
33
24
|
};
|
|
34
|
-
exports.
|
|
35
|
-
|
|
25
|
+
const DefaultTitles = exports.DefaultTitles = {
|
|
26
|
+
[NotificationSeverity.CAUTION]: "Warning",
|
|
27
|
+
[NotificationSeverity.INFORMATION]: "Info",
|
|
28
|
+
[NotificationSeverity.NEGATIVE]: "Error",
|
|
29
|
+
[NotificationSeverity.POSITIVE]: "Success"
|
|
30
|
+
};
|
|
36
31
|
|
|
37
32
|
/**
|
|
38
33
|
* The props for the Notification component.
|
|
39
34
|
*/
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
var hasActions = (actions === null || actions === void 0 ? void 0 : actions.length) > 0;
|
|
64
|
-
var showMeta = !!timestamp || hasActions;
|
|
65
|
-
(0, _react.useEffect)(function () {
|
|
35
|
+
|
|
36
|
+
const Notification = _ref => {
|
|
37
|
+
let {
|
|
38
|
+
actions,
|
|
39
|
+
borderless = false,
|
|
40
|
+
children,
|
|
41
|
+
className,
|
|
42
|
+
close,
|
|
43
|
+
inline = false,
|
|
44
|
+
onDismiss,
|
|
45
|
+
severity = NotificationSeverity.INFORMATION,
|
|
46
|
+
status,
|
|
47
|
+
timeout,
|
|
48
|
+
timestamp,
|
|
49
|
+
title,
|
|
50
|
+
titleElement: TitleComponent = "h5",
|
|
51
|
+
type,
|
|
52
|
+
...props
|
|
53
|
+
} = _ref;
|
|
54
|
+
const timeoutId = (0, _react.useRef)(null);
|
|
55
|
+
const hasActions = (actions === null || actions === void 0 ? void 0 : actions.length) > 0;
|
|
56
|
+
const showMeta = !!timestamp || hasActions;
|
|
57
|
+
(0, _react.useEffect)(() => {
|
|
66
58
|
if (timeout && onDismiss) {
|
|
67
|
-
timeoutId.current = setTimeout(
|
|
68
|
-
return onDismiss();
|
|
69
|
-
}, timeout);
|
|
59
|
+
timeoutId.current = setTimeout(() => onDismiss(), timeout);
|
|
70
60
|
}
|
|
71
|
-
return
|
|
72
|
-
return clearTimeout(timeoutId.current);
|
|
73
|
-
};
|
|
61
|
+
return () => clearTimeout(timeoutId.current);
|
|
74
62
|
}, [onDismiss, timeout]);
|
|
75
63
|
if (_utils.IS_DEV && (close || status || type)) {
|
|
76
64
|
console.warn("The Notification component is using deprecated props. Refer to the deprecated list for details: https://canonical.github.io/react-components/?path=/docs/notification--information#deprecated");
|
|
77
65
|
}
|
|
78
66
|
return /*#__PURE__*/_react.default.createElement("div", _extends({
|
|
79
|
-
className: (0, _classnames.default)(className,
|
|
67
|
+
className: (0, _classnames.default)(className, {
|
|
68
|
+
["p-notification--".concat(severity)]: !!severity,
|
|
69
|
+
"p-notification": !severity,
|
|
70
|
+
"is-borderless": borderless,
|
|
71
|
+
"is-inline": inline
|
|
72
|
+
})
|
|
80
73
|
}, props), /*#__PURE__*/_react.default.createElement("div", {
|
|
81
74
|
className: "p-notification__content"
|
|
82
75
|
}, title && /*#__PURE__*/_react.default.createElement(TitleComponent, {
|
|
@@ -96,15 +89,12 @@ var Notification = function Notification(_ref) {
|
|
|
96
89
|
"data-testid": "notification-timestamp"
|
|
97
90
|
}, timestamp), hasActions ? /*#__PURE__*/_react.default.createElement("div", {
|
|
98
91
|
className: "p-notification__actions"
|
|
99
|
-
}, actions.map(
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}, action.label);
|
|
107
|
-
})) : null));
|
|
92
|
+
}, actions.map((action, i) => /*#__PURE__*/_react.default.createElement(_Button.default, {
|
|
93
|
+
appearance: _Button.ButtonAppearance.LINK,
|
|
94
|
+
className: "p-notification__action",
|
|
95
|
+
"data-testid": "notification-action",
|
|
96
|
+
key: "".concat(action.label, "-").concat(i),
|
|
97
|
+
onClick: action.onClick
|
|
98
|
+
}, action.label))) : null));
|
|
108
99
|
};
|
|
109
|
-
var _default = Notification;
|
|
110
|
-
exports.default = _default;
|
|
100
|
+
var _default = exports.default = Notification;
|
|
@@ -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, "NotificationSeverity", {
|
|
8
7
|
enumerable: true,
|
|
9
|
-
get: function
|
|
8
|
+
get: function () {
|
|
10
9
|
return _Notification.NotificationSeverity;
|
|
11
10
|
}
|
|
12
11
|
});
|
|
13
12
|
Object.defineProperty(exports, "default", {
|
|
14
13
|
enumerable: true,
|
|
15
|
-
get: function
|
|
14
|
+
get: function () {
|
|
16
15
|
return _Notification.default;
|
|
17
16
|
}
|
|
18
17
|
});
|
|
19
18
|
var _Notification = _interopRequireWildcard(require("./Notification"));
|
|
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; }
|
|
@@ -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,71 +11,37 @@ var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
|
|
|
12
11
|
var _messageBuilder = require("./messageBuilder");
|
|
13
12
|
var _Notification = _interopRequireWildcard(require("../Notification/Notification"));
|
|
14
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
function _getRequireWildcardCache(
|
|
16
|
-
function _interopRequireWildcard(
|
|
17
|
-
|
|
18
|
-
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."); }
|
|
19
|
-
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); }
|
|
20
|
-
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; }
|
|
21
|
-
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; } }
|
|
22
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
23
|
-
var NotifyContext = /*#__PURE__*/(0, _react.createContext)({
|
|
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; }
|
|
16
|
+
const NotifyContext = /*#__PURE__*/(0, _react.createContext)({
|
|
24
17
|
notification: null,
|
|
25
|
-
clear:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
success: function success() {
|
|
32
|
-
return undefined;
|
|
33
|
-
},
|
|
34
|
-
info: function info() {
|
|
35
|
-
return undefined;
|
|
36
|
-
},
|
|
37
|
-
queue: function queue() {
|
|
38
|
-
return undefined;
|
|
39
|
-
}
|
|
18
|
+
clear: () => undefined,
|
|
19
|
+
failure: () => undefined,
|
|
20
|
+
success: () => undefined,
|
|
21
|
+
info: () => undefined,
|
|
22
|
+
queue: () => undefined,
|
|
23
|
+
setDeduplicated: () => undefined
|
|
40
24
|
});
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
state = _ref2.state,
|
|
49
|
-
pathname = _ref2.pathname;
|
|
50
|
-
var clear = function clear() {
|
|
51
|
-
return notification !== null && setNotification(null);
|
|
52
|
-
};
|
|
53
|
-
var setDeduplicated = function setDeduplicated(value) {
|
|
25
|
+
const NotificationProvider = _ref => {
|
|
26
|
+
let {
|
|
27
|
+
children
|
|
28
|
+
} = _ref;
|
|
29
|
+
const [notification, setNotification] = (0, _react.useState)(null);
|
|
30
|
+
const clear = () => notification !== null && setNotification(null);
|
|
31
|
+
const setDeduplicated = value => {
|
|
54
32
|
if (!(0, _isEqual.default)(value, notification)) {
|
|
55
33
|
setNotification(value);
|
|
56
34
|
}
|
|
57
35
|
return value;
|
|
58
36
|
};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
window.history.replaceState({}, "");
|
|
63
|
-
} else {
|
|
64
|
-
clear();
|
|
65
|
-
}
|
|
66
|
-
}, [state, pathname]);
|
|
67
|
-
var helper = {
|
|
68
|
-
notification: notification,
|
|
69
|
-
clear: clear,
|
|
37
|
+
const helper = {
|
|
38
|
+
notification,
|
|
39
|
+
clear,
|
|
70
40
|
queue: _messageBuilder.queue,
|
|
71
|
-
failure:
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return setDeduplicated((0, _messageBuilder.info)(message, title));
|
|
76
|
-
},
|
|
77
|
-
success: function success(message) {
|
|
78
|
-
return setDeduplicated((0, _messageBuilder.success)(message));
|
|
79
|
-
}
|
|
41
|
+
failure: (title, error, message, actions) => setDeduplicated((0, _messageBuilder.failure)(title, error, message, actions)),
|
|
42
|
+
info: (message, title) => setDeduplicated((0, _messageBuilder.info)(message, title)),
|
|
43
|
+
success: message => setDeduplicated((0, _messageBuilder.success)(message)),
|
|
44
|
+
setDeduplicated
|
|
80
45
|
};
|
|
81
46
|
return /*#__PURE__*/_react.default.createElement(NotifyContext.Provider, {
|
|
82
47
|
value: helper
|
|
@@ -84,12 +49,25 @@ var NotificationProvider = function NotificationProvider(_ref) {
|
|
|
84
49
|
};
|
|
85
50
|
exports.NotificationProvider = NotificationProvider;
|
|
86
51
|
function useNotify() {
|
|
87
|
-
|
|
52
|
+
const ctx = (0, _react.useContext)(NotifyContext);
|
|
53
|
+
const {
|
|
54
|
+
state,
|
|
55
|
+
pathname
|
|
56
|
+
} = (0, _reactRouterDom.useLocation)();
|
|
57
|
+
(0, _react.useEffect)(() => {
|
|
58
|
+
if (state !== null && state !== void 0 && state.queuedNotification) {
|
|
59
|
+
ctx.setDeduplicated(state.queuedNotification);
|
|
60
|
+
window.history.replaceState({}, "");
|
|
61
|
+
} else {
|
|
62
|
+
ctx.clear();
|
|
63
|
+
}
|
|
64
|
+
}, [state, pathname]);
|
|
65
|
+
return ctx;
|
|
88
66
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
(0, _react.useEffect)(
|
|
67
|
+
const NotificationConsumer = () => {
|
|
68
|
+
const notify = useNotify();
|
|
69
|
+
const ref = (0, _react.useRef)(null);
|
|
70
|
+
(0, _react.useEffect)(() => {
|
|
93
71
|
var _ref$current;
|
|
94
72
|
if ((_ref$current = ref.current) !== null && _ref$current !== void 0 && _ref$current.hasAttribute("scrollIntoView")) {
|
|
95
73
|
ref.current.scrollIntoView({
|
|
@@ -102,11 +80,12 @@ var NotificationConsumer = function NotificationConsumer() {
|
|
|
102
80
|
if (!notify.notification) {
|
|
103
81
|
return null;
|
|
104
82
|
}
|
|
105
|
-
|
|
106
|
-
actions
|
|
107
|
-
title
|
|
108
|
-
type
|
|
109
|
-
message
|
|
83
|
+
const {
|
|
84
|
+
actions,
|
|
85
|
+
title,
|
|
86
|
+
type,
|
|
87
|
+
message
|
|
88
|
+
} = notify.notification;
|
|
110
89
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
111
90
|
ref: ref
|
|
112
91
|
}, /*#__PURE__*/_react.default.createElement(_Notification.default, {
|
|
@@ -5,43 +5,43 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
Object.defineProperty(exports, "NotificationConsumer", {
|
|
7
7
|
enumerable: true,
|
|
8
|
-
get: function
|
|
8
|
+
get: function () {
|
|
9
9
|
return _NotificationProvider.NotificationConsumer;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "NotificationProvider", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function
|
|
14
|
+
get: function () {
|
|
15
15
|
return _NotificationProvider.NotificationProvider;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
Object.defineProperty(exports, "failure", {
|
|
19
19
|
enumerable: true,
|
|
20
|
-
get: function
|
|
20
|
+
get: function () {
|
|
21
21
|
return _messageBuilder.failure;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
24
|
Object.defineProperty(exports, "info", {
|
|
25
25
|
enumerable: true,
|
|
26
|
-
get: function
|
|
26
|
+
get: function () {
|
|
27
27
|
return _messageBuilder.info;
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
30
|
Object.defineProperty(exports, "queue", {
|
|
31
31
|
enumerable: true,
|
|
32
|
-
get: function
|
|
32
|
+
get: function () {
|
|
33
33
|
return _messageBuilder.queue;
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
Object.defineProperty(exports, "success", {
|
|
37
37
|
enumerable: true,
|
|
38
|
-
get: function
|
|
38
|
+
get: function () {
|
|
39
39
|
return _messageBuilder.success;
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
42
|
Object.defineProperty(exports, "useNotify", {
|
|
43
43
|
enumerable: true,
|
|
44
|
-
get: function
|
|
44
|
+
get: function () {
|
|
45
45
|
return _NotificationProvider.useNotify;
|
|
46
46
|
}
|
|
47
47
|
});
|
|
@@ -7,7 +7,7 @@ exports.success = exports.queue = exports.info = exports.failure = void 0;
|
|
|
7
7
|
var _react = _interopRequireDefault(require("react"));
|
|
8
8
|
var _Notification = require("../Notification");
|
|
9
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
|
|
10
|
+
const queue = notification => {
|
|
11
11
|
return {
|
|
12
12
|
state: {
|
|
13
13
|
queuedNotification: notification
|
|
@@ -15,26 +15,26 @@ var queue = function queue(notification) {
|
|
|
15
15
|
};
|
|
16
16
|
};
|
|
17
17
|
exports.queue = queue;
|
|
18
|
-
|
|
18
|
+
const info = (message, title) => {
|
|
19
19
|
return {
|
|
20
|
-
message
|
|
21
|
-
title
|
|
20
|
+
message,
|
|
21
|
+
title,
|
|
22
22
|
type: _Notification.NotificationSeverity.INFORMATION
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
25
|
exports.info = info;
|
|
26
|
-
|
|
26
|
+
const success = message => {
|
|
27
27
|
return {
|
|
28
|
-
message
|
|
28
|
+
message,
|
|
29
29
|
type: _Notification.NotificationSeverity.POSITIVE
|
|
30
30
|
};
|
|
31
31
|
};
|
|
32
32
|
exports.success = success;
|
|
33
|
-
|
|
33
|
+
const failure = (title, error, message, actions) => {
|
|
34
34
|
return {
|
|
35
|
-
actions
|
|
35
|
+
actions,
|
|
36
36
|
message: error && error instanceof Error ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, message, " ", error.message) : message,
|
|
37
|
-
title
|
|
37
|
+
title,
|
|
38
38
|
type: _Notification.NotificationSeverity.NEGATIVE
|
|
39
39
|
};
|
|
40
40
|
};
|
|
@@ -27,4 +27,5 @@ export interface NotificationHelper {
|
|
|
27
27
|
info: (message: ReactNode, title?: string) => NotificationType;
|
|
28
28
|
success: (message: ReactNode) => NotificationType;
|
|
29
29
|
queue: (notification: NotificationType) => QueuedNotification;
|
|
30
|
+
setDeduplicated: (value: NotificationType) => NotificationType;
|
|
30
31
|
}
|