@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.
Files changed (152) hide show
  1. package/dist/__mocks__/nanoid.js +3 -3
  2. package/dist/components/Accordion/Accordion.js +28 -41
  3. package/dist/components/Accordion/AccordionSection/AccordionSection.js +18 -18
  4. package/dist/components/Accordion/AccordionSection/index.js +1 -1
  5. package/dist/components/Accordion/index.js +1 -1
  6. package/dist/components/ActionButton/ActionButton.js +34 -66
  7. package/dist/components/ActionButton/index.js +1 -1
  8. package/dist/components/ArticlePagination/ArticlePagination.js +10 -12
  9. package/dist/components/ArticlePagination/index.js +1 -1
  10. package/dist/components/Badge/Badge.js +24 -29
  11. package/dist/components/Badge/index.js +1 -1
  12. package/dist/components/Button/Button.js +21 -26
  13. package/dist/components/Button/index.js +4 -5
  14. package/dist/components/Card/Card.js +12 -14
  15. package/dist/components/Card/index.js +1 -1
  16. package/dist/components/CheckboxInput/CheckableInput/CheckableInput.js +15 -19
  17. package/dist/components/CheckboxInput/CheckableInput/index.js +1 -1
  18. package/dist/components/CheckboxInput/CheckboxInput.js +7 -10
  19. package/dist/components/CheckboxInput/index.js +1 -1
  20. package/dist/components/Chip/Chip.js +23 -33
  21. package/dist/components/Chip/index.js +1 -1
  22. package/dist/components/Code/Code.js +14 -17
  23. package/dist/components/Code/index.js +1 -1
  24. package/dist/components/CodeSnippet/CodeSnippet.js +9 -14
  25. package/dist/components/CodeSnippet/CodeSnippetBlock.js +24 -29
  26. package/dist/components/CodeSnippet/CodeSnippetDropdown.js +11 -11
  27. package/dist/components/CodeSnippet/index.js +2 -2
  28. package/dist/components/Col/Col.js +24 -26
  29. package/dist/components/Col/index.js +4 -5
  30. package/dist/components/ConfirmationButton/ConfirmationButton.js +18 -21
  31. package/dist/components/ConfirmationButton/index.js +1 -1
  32. package/dist/components/ConfirmationModal/ConfirmationModal.js +11 -15
  33. package/dist/components/ConfirmationModal/index.js +1 -1
  34. package/dist/components/ContextualMenu/ContextualMenu.js +89 -107
  35. package/dist/components/ContextualMenu/ContextualMenuDropdown/ContextualMenuDropdown.d.ts +4 -4
  36. package/dist/components/ContextualMenu/ContextualMenuDropdown/ContextualMenuDropdown.js +97 -107
  37. package/dist/components/ContextualMenu/ContextualMenuDropdown/index.js +1 -1
  38. package/dist/components/ContextualMenu/index.js +1 -1
  39. package/dist/components/EmptyState/EmptyState.js +9 -11
  40. package/dist/components/EmptyState/index.js +1 -1
  41. package/dist/components/Field/Field.js +66 -65
  42. package/dist/components/Field/index.js +1 -1
  43. package/dist/components/Form/Form.js +9 -11
  44. package/dist/components/Form/index.js +1 -1
  45. package/dist/components/Icon/Icon.js +9 -12
  46. package/dist/components/Icon/index.js +4 -5
  47. package/dist/components/Input/Input.js +38 -45
  48. package/dist/components/Input/index.js +1 -1
  49. package/dist/components/Label/Label.js +9 -11
  50. package/dist/components/Label/index.js +1 -1
  51. package/dist/components/Link/Link.js +12 -18
  52. package/dist/components/Link/index.js +1 -1
  53. package/dist/components/List/List.js +50 -54
  54. package/dist/components/List/index.js +1 -1
  55. package/dist/components/Loader/Loader.js +2 -3
  56. package/dist/components/Loader/index.js +1 -1
  57. package/dist/components/MainTable/MainTable.js +87 -104
  58. package/dist/components/MainTable/index.js +1 -1
  59. package/dist/components/Modal/Modal.js +37 -38
  60. package/dist/components/Modal/index.js +1 -1
  61. package/dist/components/ModularTable/ModularTable.js +63 -77
  62. package/dist/components/ModularTable/index.js +1 -1
  63. package/dist/components/Navigation/Navigation.js +63 -97
  64. package/dist/components/Navigation/NavigationLink/NavigationLink.js +32 -35
  65. package/dist/components/Navigation/NavigationLink/index.js +1 -1
  66. package/dist/components/Navigation/NavigationMenu/NavigationMenu.js +26 -45
  67. package/dist/components/Navigation/NavigationMenu/index.js +1 -1
  68. package/dist/components/Navigation/index.js +1 -1
  69. package/dist/components/Notification/Notification.js +49 -59
  70. package/dist/components/Notification/index.js +4 -5
  71. package/dist/components/NotificationProvider/NotificationProvider.js +47 -68
  72. package/dist/components/NotificationProvider/index.js +7 -7
  73. package/dist/components/NotificationProvider/messageBuilder.js +9 -9
  74. package/dist/components/NotificationProvider/types.d.ts +1 -0
  75. package/dist/components/Pagination/Pagination.js +50 -69
  76. package/dist/components/Pagination/PaginationButton/PaginationButton.js +11 -12
  77. package/dist/components/Pagination/PaginationButton/index.js +1 -1
  78. package/dist/components/Pagination/PaginationItem/PaginationItem.js +7 -7
  79. package/dist/components/Pagination/PaginationItem/index.js +1 -1
  80. package/dist/components/Pagination/index.js +1 -1
  81. package/dist/components/PasswordToggle/PasswordToggle.d.ts +1 -1
  82. package/dist/components/PasswordToggle/PasswordToggle.js +25 -40
  83. package/dist/components/PasswordToggle/index.js +1 -1
  84. package/dist/components/RadioInput/RadioInput.js +6 -8
  85. package/dist/components/RadioInput/index.js +1 -1
  86. package/dist/components/Row/Row.js +7 -9
  87. package/dist/components/Row/index.js +1 -1
  88. package/dist/components/SearchAndFilter/FilterPanelSection/FilterPanelSection.js +38 -51
  89. package/dist/components/SearchAndFilter/FilterPanelSection/index.js +1 -1
  90. package/dist/components/SearchAndFilter/SearchAndFilter.js +75 -135
  91. package/dist/components/SearchAndFilter/index.js +1 -1
  92. package/dist/components/SearchAndFilter/utils.js +4 -8
  93. package/dist/components/SearchBox/SearchBox.js +25 -33
  94. package/dist/components/SearchBox/index.js +1 -1
  95. package/dist/components/Select/Select.js +38 -44
  96. package/dist/components/Select/index.js +1 -1
  97. package/dist/components/Slider/Slider.js +27 -35
  98. package/dist/components/Slider/index.js +1 -1
  99. package/dist/components/Spinner/Spinner.js +10 -15
  100. package/dist/components/Spinner/index.js +1 -1
  101. package/dist/components/StatusLabel/StatusLabel.js +11 -13
  102. package/dist/components/StatusLabel/index.js +4 -5
  103. package/dist/components/Strip/Strip.js +27 -34
  104. package/dist/components/Strip/index.js +1 -1
  105. package/dist/components/SummaryButton/SummaryButton.js +9 -8
  106. package/dist/components/SummaryButton/index.js +1 -1
  107. package/dist/components/Switch/Switch.js +7 -10
  108. package/dist/components/Switch/index.js +1 -1
  109. package/dist/components/Table/Table.js +9 -13
  110. package/dist/components/Table/index.js +1 -1
  111. package/dist/components/TableCell/TableCell.js +11 -17
  112. package/dist/components/TableCell/index.js +1 -1
  113. package/dist/components/TableHeader/TableHeader.js +7 -9
  114. package/dist/components/TableHeader/index.js +1 -1
  115. package/dist/components/TablePagination/TablePagination.d.ts +37 -0
  116. package/dist/components/TablePagination/TablePagination.js +125 -0
  117. package/dist/components/TablePagination/TablePagination.scss +40 -0
  118. package/dist/components/TablePagination/TablePaginationControls/TablePaginationControls.d.ts +16 -0
  119. package/dist/components/TablePagination/TablePaginationControls/TablePaginationControls.js +66 -0
  120. package/dist/components/TablePagination/TablePaginationControls/index.d.ts +2 -0
  121. package/dist/components/TablePagination/TablePaginationControls/index.js +13 -0
  122. package/dist/components/TablePagination/index.d.ts +2 -0
  123. package/dist/components/TablePagination/index.js +13 -0
  124. package/dist/components/TableRow/TableRow.js +6 -8
  125. package/dist/components/TableRow/index.js +1 -1
  126. package/dist/components/Tabs/Tabs.js +17 -17
  127. package/dist/components/Tabs/index.js +1 -1
  128. package/dist/components/Textarea/Textarea.js +51 -45
  129. package/dist/components/Textarea/index.js +1 -1
  130. package/dist/components/Tooltip/Tooltip.d.ts +5 -1
  131. package/dist/components/Tooltip/Tooltip.js +76 -79
  132. package/dist/components/Tooltip/index.js +4 -5
  133. package/dist/enums.js +2 -3
  134. package/dist/hooks/index.d.ts +1 -1
  135. package/dist/hooks/index.js +16 -10
  136. package/dist/hooks/useId.js +1 -3
  137. package/dist/hooks/useListener.d.ts +2 -1
  138. package/dist/hooks/useListener.js +25 -24
  139. package/dist/hooks/useOnClickOutside.d.ts +12 -0
  140. package/dist/hooks/useOnClickOutside.js +45 -0
  141. package/dist/hooks/useOnEscapePressed.d.ts +3 -1
  142. package/dist/hooks/useOnEscapePressed.js +13 -6
  143. package/dist/hooks/usePagination.js +17 -29
  144. package/dist/hooks/usePrevious.js +4 -4
  145. package/dist/hooks/useThrottle.js +16 -25
  146. package/dist/hooks/useWindowFitment.js +30 -28
  147. package/dist/index.d.ts +3 -1
  148. package/dist/index.js +86 -74
  149. package/dist/utils.js +6 -13
  150. package/package.json +42 -35
  151. package/dist/hooks/useClickOutside.d.ts +0 -6
  152. package/dist/hooks/useClickOutside.js +0 -32
@@ -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
- var _excluded = ["actions", "borderless", "children", "className", "close", "inline", "onDismiss", "severity", "status", "timeout", "timestamp", "title", "titleElement", "type"];
12
- var _DefaultTitles;
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
- 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; }
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.Label = Label;
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.NotificationSeverity = NotificationSeverity;
35
- var DefaultTitles = (_DefaultTitles = {}, _defineProperty(_DefaultTitles, NotificationSeverity.CAUTION, "Warning"), _defineProperty(_DefaultTitles, NotificationSeverity.INFORMATION, "Info"), _defineProperty(_DefaultTitles, NotificationSeverity.NEGATIVE, "Error"), _defineProperty(_DefaultTitles, NotificationSeverity.POSITIVE, "Success"), _DefaultTitles);
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
- exports.DefaultTitles = DefaultTitles;
41
- var Notification = function Notification(_ref) {
42
- var _classNames;
43
- var actions = _ref.actions,
44
- _ref$borderless = _ref.borderless,
45
- borderless = _ref$borderless === void 0 ? false : _ref$borderless,
46
- children = _ref.children,
47
- className = _ref.className,
48
- close = _ref.close,
49
- _ref$inline = _ref.inline,
50
- inline = _ref$inline === void 0 ? false : _ref$inline,
51
- onDismiss = _ref.onDismiss,
52
- _ref$severity = _ref.severity,
53
- severity = _ref$severity === void 0 ? NotificationSeverity.INFORMATION : _ref$severity,
54
- status = _ref.status,
55
- timeout = _ref.timeout,
56
- timestamp = _ref.timestamp,
57
- title = _ref.title,
58
- _ref$titleElement = _ref.titleElement,
59
- TitleComponent = _ref$titleElement === void 0 ? "h5" : _ref$titleElement,
60
- type = _ref.type,
61
- props = _objectWithoutProperties(_ref, _excluded);
62
- var timeoutId = (0, _react.useRef)(null);
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(function () {
68
- return onDismiss();
69
- }, timeout);
59
+ timeoutId.current = setTimeout(() => onDismiss(), timeout);
70
60
  }
71
- return function () {
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, (_classNames = {}, _defineProperty(_classNames, "p-notification--".concat(severity), !!severity), _defineProperty(_classNames, "p-notification", !severity), _defineProperty(_classNames, "is-borderless", borderless), _defineProperty(_classNames, "is-inline", inline), _classNames))
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(function (action, i) {
100
- return /*#__PURE__*/_react.default.createElement(_Button.default, {
101
- appearance: _Button.ButtonAppearance.LINK,
102
- className: "p-notification__action",
103
- "data-testid": "notification-action",
104
- key: "".concat(action.label, "-").concat(i),
105
- onClick: action.onClick
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 get() {
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 get() {
14
+ get: function () {
16
15
  return _Notification.default;
17
16
  }
18
17
  });
19
18
  var _Notification = _interopRequireWildcard(require("./Notification"));
20
- 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); }
21
- 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; }
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(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); }
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; }
17
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
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: function clear() {
26
- return undefined;
27
- },
28
- failure: function failure() {
29
- return undefined;
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
- var NotificationProvider = function NotificationProvider(_ref) {
42
- var children = _ref.children;
43
- var _useState = (0, _react.useState)(null),
44
- _useState2 = _slicedToArray(_useState, 2),
45
- notification = _useState2[0],
46
- setNotification = _useState2[1];
47
- var _ref2 = (0, _reactRouterDom.useLocation)(),
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
- (0, _react.useEffect)(function () {
60
- if (state !== null && state !== void 0 && state.queuedNotification) {
61
- setDeduplicated(state.queuedNotification);
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: function failure(title, error, message, actions) {
72
- return setDeduplicated((0, _messageBuilder.failure)(title, error, message, actions));
73
- },
74
- info: function info(message, title) {
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
- return (0, _react.useContext)(NotifyContext);
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
- var NotificationConsumer = function NotificationConsumer() {
90
- var notify = useNotify();
91
- var ref = (0, _react.useRef)(null);
92
- (0, _react.useEffect)(function () {
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
- var _notify$notification = notify.notification,
106
- actions = _notify$notification.actions,
107
- title = _notify$notification.title,
108
- type = _notify$notification.type,
109
- message = _notify$notification.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 get() {
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 get() {
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 get() {
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 get() {
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 get() {
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 get() {
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 get() {
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
- var queue = function queue(notification) {
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
- var info = function info(message, title) {
18
+ const info = (message, title) => {
19
19
  return {
20
- message: message,
21
- title: title,
20
+ message,
21
+ title,
22
22
  type: _Notification.NotificationSeverity.INFORMATION
23
23
  };
24
24
  };
25
25
  exports.info = info;
26
- var success = function success(message) {
26
+ const success = message => {
27
27
  return {
28
- message: message,
28
+ message,
29
29
  type: _Notification.NotificationSeverity.POSITIVE
30
30
  };
31
31
  };
32
32
  exports.success = success;
33
- var failure = function failure(title, error, message, actions) {
33
+ const failure = (title, error, message, actions) => {
34
34
  return {
35
- actions: actions,
35
+ actions,
36
36
  message: error && error instanceof Error ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, message, " ", error.message) : message,
37
- title: 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
  }
@@ -8,22 +8,17 @@ var _classnames = _interopRequireDefault(require("classnames"));
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
  var _PaginationButton = _interopRequireDefault(require("./PaginationButton"));
10
10
  var _PaginationItem = _interopRequireDefault(require("./PaginationItem"));
11
- var _excluded = ["itemsPerPage", "totalItems", "paginate", "currentPage", "scrollToTop", "truncateThreshold", "centered", "showLabels", "hideNumbers", "onForward", "onBack", "forwardDisabled", "backDisabled", "forwardLabel", "backLabel"];
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
- 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; }
15
- 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; }
16
- var scrollTop = function scrollTop() {
17
- return window.scrollTo(0, 0);
18
- };
19
- var generatePaginationItems = function generatePaginationItems(pageNumbers, currentPage, truncateThreshold, changePage) {
20
- var lastPage = pageNumbers.length;
21
- var truncated = lastPage > truncateThreshold;
22
- var visiblePages;
13
+ const scrollTop = () => window.scrollTo(0, 0);
14
+ const generatePaginationItems = (pageNumbers, currentPage, truncateThreshold, changePage) => {
15
+ const lastPage = pageNumbers.length;
16
+ const truncated = lastPage > truncateThreshold;
17
+ let visiblePages;
23
18
  if (truncated) {
24
19
  // the default range for pages outside the start and end threshold
25
- var start = currentPage - 2;
26
- var end = currentPage + 1;
20
+ let start = currentPage - 2;
21
+ let end = currentPage + 1;
27
22
  // on page 1, also show pages 2, 3 and 4
28
23
  if (currentPage === 1) {
29
24
  start = 1;
@@ -43,16 +38,14 @@ var generatePaginationItems = function generatePaginationItems(pageNumbers, curr
43
38
  } else {
44
39
  visiblePages = pageNumbers;
45
40
  }
46
- var items = [];
41
+ const items = [];
47
42
  if (truncated) {
48
43
  // render first in sequence
49
44
  items.push( /*#__PURE__*/_react.default.createElement(_PaginationItem.default, {
50
45
  key: 1,
51
46
  number: 1,
52
47
  isActive: currentPage === 1,
53
- onClick: function onClick() {
54
- return changePage(1);
55
- }
48
+ onClick: () => changePage(1)
56
49
  }));
57
50
  if (!visiblePages.includes(2)) {
58
51
  items.push( /*#__PURE__*/_react.default.createElement(PaginationItemSeparator, {
@@ -60,16 +53,12 @@ var generatePaginationItems = function generatePaginationItems(pageNumbers, curr
60
53
  }));
61
54
  }
62
55
  }
63
- items.push(visiblePages.map(function (number) {
64
- return /*#__PURE__*/_react.default.createElement(_PaginationItem.default, {
65
- key: number,
66
- number: number,
67
- isActive: number === currentPage,
68
- onClick: function onClick() {
69
- return changePage(number);
70
- }
71
- });
72
- }));
56
+ items.push(visiblePages.map(number => /*#__PURE__*/_react.default.createElement(_PaginationItem.default, {
57
+ key: number,
58
+ number: number,
59
+ isActive: number === currentPage,
60
+ onClick: () => changePage(number)
61
+ })));
73
62
  if (truncated) {
74
63
  // render last in sequence
75
64
  if (!visiblePages.includes(lastPage - 1)) {
@@ -81,18 +70,14 @@ var generatePaginationItems = function generatePaginationItems(pageNumbers, curr
81
70
  key: lastPage,
82
71
  number: lastPage,
83
72
  isActive: currentPage === lastPage,
84
- onClick: function onClick() {
85
- return changePage(lastPage);
86
- }
73
+ onClick: () => changePage(lastPage)
87
74
  }));
88
75
  }
89
76
  return items;
90
77
  };
91
- var PaginationItemSeparator = function PaginationItemSeparator() {
92
- return /*#__PURE__*/_react.default.createElement("li", {
93
- className: "p-pagination__item p-pagination__item--truncation"
94
- }, "\u2026");
95
- };
78
+ const PaginationItemSeparator = () => /*#__PURE__*/_react.default.createElement("li", {
79
+ className: "p-pagination__item p-pagination__item--truncation"
80
+ }, "\u2026");
96
81
 
97
82
  // Props that are used in both types of paginations.
98
83
 
@@ -103,51 +88,52 @@ var PaginationItemSeparator = function PaginationItemSeparator() {
103
88
  // Used when number of items per page, number of total items,
104
89
  // current page and paginate function are undefined.
105
90
  // Pagination is handled by onForward and onBack function.
106
- var Pagination = function Pagination(_ref) {
107
- var itemsPerPage = _ref.itemsPerPage,
108
- totalItems = _ref.totalItems,
109
- paginate = _ref.paginate,
110
- currentPage = _ref.currentPage,
111
- scrollToTop = _ref.scrollToTop,
112
- _ref$truncateThreshol = _ref.truncateThreshold,
113
- truncateThreshold = _ref$truncateThreshol === void 0 ? 10 : _ref$truncateThreshol,
114
- centered = _ref.centered,
115
- showLabels = _ref.showLabels,
116
- hideNumbers = _ref.hideNumbers,
117
- onForward = _ref.onForward,
118
- onBack = _ref.onBack,
119
- forwardDisabled = _ref.forwardDisabled,
120
- backDisabled = _ref.backDisabled,
121
- forwardLabel = _ref.forwardLabel,
122
- backLabel = _ref.backLabel,
123
- navProps = _objectWithoutProperties(_ref, _excluded);
124
- var isNumberedPagination = !!itemsPerPage && !!totalItems && !!currentPage && !!paginate;
125
- var pageNumbers = [];
91
+ const Pagination = _ref => {
92
+ let {
93
+ itemsPerPage,
94
+ totalItems,
95
+ paginate,
96
+ currentPage,
97
+ scrollToTop,
98
+ truncateThreshold = 10,
99
+ centered,
100
+ showLabels,
101
+ hideNumbers,
102
+ onForward,
103
+ onBack,
104
+ forwardDisabled,
105
+ backDisabled,
106
+ forwardLabel,
107
+ backLabel,
108
+ ...navProps
109
+ } = _ref;
110
+ const isNumberedPagination = !!itemsPerPage && !!totalItems && !!currentPage && !!paginate;
111
+ const pageNumbers = [];
126
112
  if (isNumberedPagination) {
127
113
  // return early if no pagination is required
128
114
  if (totalItems <= itemsPerPage) {
129
115
  return null;
130
116
  }
131
- for (var i = 1; i <= Math.ceil(totalItems / itemsPerPage); i++) {
117
+ for (let i = 1; i <= Math.ceil(totalItems / itemsPerPage); i++) {
132
118
  pageNumbers.push(i);
133
119
  }
134
120
  }
135
- var changeNumberedPage = function changeNumberedPage(page) {
121
+ const changeNumberedPage = page => {
136
122
  paginate(page);
137
123
  if (page > currentPage) {
138
- onForward === null || onForward === void 0 ? void 0 : onForward(page);
124
+ onForward === null || onForward === void 0 || onForward(page);
139
125
  }
140
126
  if (page < currentPage) {
141
- onBack === null || onBack === void 0 ? void 0 : onBack(page);
127
+ onBack === null || onBack === void 0 || onBack(page);
142
128
  }
143
129
  scrollToTop && scrollTop();
144
130
  };
145
- var changeButtonsOnlyPage = function changeButtonsOnlyPage(direction) {
131
+ const changeButtonsOnlyPage = direction => {
146
132
  if (direction === "forward") {
147
- onForward === null || onForward === void 0 ? void 0 : onForward(undefined);
133
+ onForward === null || onForward === void 0 || onForward(undefined);
148
134
  }
149
135
  if (direction === "back") {
150
- onBack === null || onBack === void 0 ? void 0 : onBack(undefined);
136
+ onBack === null || onBack === void 0 || onBack(undefined);
151
137
  }
152
138
  scrollToTop && scrollTop();
153
139
  };
@@ -162,21 +148,16 @@ var Pagination = function Pagination(_ref) {
162
148
  key: "back",
163
149
  direction: "back",
164
150
  disabled: backDisabled || currentPage === 1,
165
- onClick: function onClick() {
166
- return isNumberedPagination ? changeNumberedPage(currentPage - 1) : changeButtonsOnlyPage("back");
167
- },
151
+ onClick: () => isNumberedPagination ? changeNumberedPage(currentPage - 1) : changeButtonsOnlyPage("back"),
168
152
  showLabel: showLabels,
169
153
  label: backLabel
170
154
  }), isNumberedPagination && !hideNumbers ? generatePaginationItems(pageNumbers, currentPage, truncateThreshold, changeNumberedPage) : null, /*#__PURE__*/_react.default.createElement(_PaginationButton.default, {
171
155
  key: "forward",
172
156
  direction: "forward",
173
157
  disabled: forwardDisabled || currentPage === pageNumbers.length,
174
- onClick: function onClick() {
175
- return isNumberedPagination ? changeNumberedPage(currentPage + 1) : changeButtonsOnlyPage("forward");
176
- },
158
+ onClick: () => isNumberedPagination ? changeNumberedPage(currentPage + 1) : changeButtonsOnlyPage("forward"),
177
159
  showLabel: showLabels,
178
160
  label: forwardLabel
179
161
  })));
180
162
  };
181
- var _default = Pagination;
182
- exports.default = _default;
163
+ var _default = exports.default = Pagination;