@canonical/react-components 0.34.2 → 0.37.0

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 (78) hide show
  1. package/dist/components/Accordion/Accordion.js +1 -1
  2. package/dist/components/ActionButton/ActionButton.js +1 -1
  3. package/dist/components/ArticlePagination/ArticlePagination.js +1 -1
  4. package/dist/components/Button/Button.d.ts +1 -0
  5. package/dist/components/Button/Button.js +2 -1
  6. package/dist/components/Card/Card.js +1 -1
  7. package/dist/components/CheckableInput/CheckableInput.js +1 -1
  8. package/dist/components/CheckboxInput/CheckboxInput.js +1 -1
  9. package/dist/components/Chip/Chip.js +1 -1
  10. package/dist/components/Code/Code.js +1 -1
  11. package/dist/components/CodeSnippet/CodeSnippet.js +1 -1
  12. package/dist/components/CodeSnippet/CodeSnippetBlock.js +1 -1
  13. package/dist/components/CodeSnippet/CodeSnippetDropdown.js +1 -1
  14. package/dist/components/Col/Col.js +1 -1
  15. package/dist/components/ContextualMenu/ContextualMenu.js +1 -2
  16. package/dist/components/ContextualMenu/ContextualMenuDropdown/ContextualMenuDropdown.js +1 -1
  17. package/dist/components/Field/Field.d.ts +5 -1
  18. package/dist/components/Field/Field.js +6 -1
  19. package/dist/components/Form/Form.js +1 -1
  20. package/dist/components/Icon/Icon.js +1 -1
  21. package/dist/components/Input/Input.d.ts +5 -1
  22. package/dist/components/Input/Input.js +4 -2
  23. package/dist/components/Label/Label.js +1 -1
  24. package/dist/components/Link/Link.js +1 -1
  25. package/dist/components/List/List.js +28 -17
  26. package/dist/components/MainTable/MainTable.js +98 -79
  27. package/dist/components/Modal/Modal.js +1 -1
  28. package/dist/components/ModularTable/ModularTable.js +1 -1
  29. package/dist/components/Navigation/Navigation.d.ts +57 -0
  30. package/dist/components/Navigation/Navigation.js +266 -0
  31. package/dist/components/Navigation/NavigationLink/NavigationLink.d.ts +11 -0
  32. package/dist/components/Navigation/NavigationLink/NavigationLink.js +57 -0
  33. package/dist/components/Navigation/NavigationLink/index.d.ts +1 -0
  34. package/dist/components/Navigation/NavigationLink/index.js +15 -0
  35. package/dist/components/Navigation/NavigationMenu/NavigationMenu.d.ts +11 -0
  36. package/dist/components/Navigation/NavigationMenu/NavigationMenu.js +97 -0
  37. package/dist/components/Navigation/NavigationMenu/index.d.ts +1 -0
  38. package/dist/components/Navigation/NavigationMenu/index.js +15 -0
  39. package/dist/components/Navigation/index.d.ts +3 -0
  40. package/dist/components/Navigation/index.js +15 -0
  41. package/dist/components/Navigation/types.d.ts +57 -0
  42. package/dist/components/Navigation/types.js +5 -0
  43. package/dist/components/Notification/Notification.js +1 -1
  44. package/dist/components/PasswordToggle/PasswordToggle.js +1 -1
  45. package/dist/components/RadioInput/RadioInput.js +1 -1
  46. package/dist/components/Row/Row.js +1 -1
  47. package/dist/components/SearchAndFilter/SearchAndFilter.js +12 -16
  48. package/dist/components/SearchBox/SearchBox.d.ts +6 -5
  49. package/dist/components/SearchBox/SearchBox.js +22 -8
  50. package/dist/components/Select/Select.js +1 -1
  51. package/dist/components/Slider/Slider.js +1 -1
  52. package/dist/components/Spinner/Spinner.js +1 -1
  53. package/dist/components/StatusLabel/StatusLabel.d.ts +31 -0
  54. package/dist/components/StatusLabel/StatusLabel.js +51 -0
  55. package/dist/components/StatusLabel/index.d.ts +2 -0
  56. package/dist/components/StatusLabel/index.js +25 -0
  57. package/dist/components/Strip/Strip.js +1 -1
  58. package/dist/components/Switch/Switch.js +1 -1
  59. package/dist/components/Table/Table.js +1 -1
  60. package/dist/components/TableCell/TableCell.js +1 -1
  61. package/dist/components/TableHeader/TableHeader.js +1 -1
  62. package/dist/components/TableRow/TableRow.js +1 -1
  63. package/dist/components/Tabs/Tabs.js +1 -1
  64. package/dist/components/Textarea/Textarea.js +1 -1
  65. package/dist/components/Tooltip/Tooltip.js +30 -1
  66. package/dist/hooks/index.d.ts +5 -2
  67. package/dist/hooks/index.js +26 -2
  68. package/dist/hooks/useClickOutside.d.ts +7 -0
  69. package/dist/hooks/useClickOutside.js +41 -0
  70. package/dist/hooks/useOnEscapePressed.d.ts +4 -0
  71. package/dist/hooks/useOnEscapePressed.js +27 -0
  72. package/dist/hooks/usePagination.d.ts +19 -0
  73. package/dist/hooks/usePagination.js +74 -0
  74. package/dist/index.d.ts +6 -2
  75. package/dist/index.js +34 -0
  76. package/dist/types/index.d.ts +13 -0
  77. package/dist/types/index.js +49 -1
  78. package/package.json +44 -42
@@ -13,7 +13,7 @@ var _excluded = ["children", "className", "expanding", "responsive"];
13
13
 
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
15
 
16
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
16
+ 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
17
 
18
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
19
 
@@ -13,7 +13,7 @@ var _excluded = ["children", "className", "hasOverflow", "expanding", "hidden",
13
13
 
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
15
 
16
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
16
+ 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
17
 
18
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
19
 
@@ -11,7 +11,7 @@ var _excluded = ["children", "sort"];
11
11
 
12
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
13
 
14
- function _extends() { _extends = Object.assign || 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 _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); }
15
15
 
16
16
  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; }
17
17
 
@@ -11,7 +11,7 @@ var _excluded = ["children"];
11
11
 
12
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
13
 
14
- function _extends() { _extends = Object.assign || 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 _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); }
15
15
 
16
16
  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; }
17
17
 
@@ -13,7 +13,7 @@ var _excluded = ["active", "className", "component", "label", "listItemClassName
13
13
 
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
15
 
16
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
16
+ 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
17
 
18
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
19
 
@@ -23,7 +23,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
23
23
 
24
24
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
25
 
26
- function _extends() { _extends = Object.assign || 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); }
26
+ 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); }
27
27
 
28
28
  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; }
29
29
 
@@ -223,18 +223,47 @@ var Tooltip = function Tooltip(_ref) {
223
223
  (0, _hooks.useListener)(wrapperRef.current, mouseHandler, "mousemove", true, followMouse && isOpen); // Handle adjusting the position of the tooltip so that it remains on screen.
224
224
 
225
225
  (0, _hooks.useWindowFitment)(messageRef.current, wrapperRef.current, onUpdateWindowFitment, 20, isOpen, autoAdjust && followMouse);
226
+ var handleKeyPress = (0, _react.useCallback)(function (event) {
227
+ if (event.key === "Escape") {
228
+ closePortal();
229
+ }
230
+ }, [closePortal]);
231
+ (0, _react.useEffect)(function () {
232
+ window.addEventListener("keypress", handleKeyPress);
233
+ return function () {
234
+ window.removeEventListener("keypress", handleKeyPress);
235
+ };
236
+ }, [handleKeyPress]);
226
237
 
227
238
  var handleBlur = function handleBlur(e) {
228
- var _messageRef$current;
239
+ var _wrapperRef$current, _messageRef$current;
240
+
241
+ // do not close if the focus is within the tooltip wrapper
242
+ if (wrapperRef !== null && wrapperRef !== void 0 && (_wrapperRef$current = wrapperRef.current) !== null && _wrapperRef$current !== void 0 && _wrapperRef$current.contains(document.activeElement)) {
243
+ return;
244
+ }
229
245
 
230
246
  if (e.relatedTarget ? !((_messageRef$current = messageRef.current) !== null && _messageRef$current !== void 0 && _messageRef$current.contains(e.relatedTarget)) : e.target !== messageRef.current) {
231
247
  closePortal();
232
248
  }
233
249
  };
234
250
 
251
+ var handleClick = function handleClick(e) {
252
+ var _messageRef$current2;
253
+
254
+ // ignore clicks within the tooltip message
255
+ if ((_messageRef$current2 = messageRef.current) !== null && _messageRef$current2 !== void 0 && _messageRef$current2.contains(e.target)) {
256
+ return;
257
+ }
258
+
259
+ e.target.focus();
260
+ openPortal();
261
+ };
262
+
235
263
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, message ? /*#__PURE__*/_react.default.createElement("span", {
236
264
  className: className,
237
265
  onBlur: handleBlur,
266
+ onClick: handleClick,
238
267
  onFocus: openPortal,
239
268
  onMouseOut: handleBlur,
240
269
  onMouseOver: openPortal
@@ -1,6 +1,9 @@
1
- export { useWindowFitment } from "./useWindowFitment";
1
+ export { useClickOutside } from "./useClickOutside";
2
+ export { useId } from "./useId";
2
3
  export { useListener } from "./useListener";
4
+ export { useOnEscapePressed } from "./useOnEscapePressed";
3
5
  export { usePrevious } from "./usePrevious";
4
6
  export { useThrottle } from "./useThrottle";
5
- export { useId } from "./useId";
7
+ export { usePagination } from "./usePagination";
8
+ export { useWindowFitment } from "./useWindowFitment";
6
9
  export type { WindowFitment } from "./useWindowFitment";
@@ -3,6 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ Object.defineProperty(exports, "useClickOutside", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _useClickOutside.useClickOutside;
10
+ }
11
+ });
6
12
  Object.defineProperty(exports, "useId", {
7
13
  enumerable: true,
8
14
  get: function get() {
@@ -15,6 +21,18 @@ Object.defineProperty(exports, "useListener", {
15
21
  return _useListener.useListener;
16
22
  }
17
23
  });
24
+ Object.defineProperty(exports, "useOnEscapePressed", {
25
+ enumerable: true,
26
+ get: function get() {
27
+ return _useOnEscapePressed.useOnEscapePressed;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "usePagination", {
31
+ enumerable: true,
32
+ get: function get() {
33
+ return _usePagination.usePagination;
34
+ }
35
+ });
18
36
  Object.defineProperty(exports, "usePrevious", {
19
37
  enumerable: true,
20
38
  get: function get() {
@@ -34,12 +52,18 @@ Object.defineProperty(exports, "useWindowFitment", {
34
52
  }
35
53
  });
36
54
 
37
- var _useWindowFitment = require("./useWindowFitment");
55
+ var _useClickOutside = require("./useClickOutside");
56
+
57
+ var _useId = require("./useId");
38
58
 
39
59
  var _useListener = require("./useListener");
40
60
 
61
+ var _useOnEscapePressed = require("./useOnEscapePressed");
62
+
41
63
  var _usePrevious = require("./usePrevious");
42
64
 
43
65
  var _useThrottle = require("./useThrottle");
44
66
 
45
- var _useId = require("./useId");
67
+ var _usePagination = require("./usePagination");
68
+
69
+ var _useWindowFitment = require("./useWindowFitment");
@@ -0,0 +1,7 @@
1
+ import { MutableRefObject } from "react";
2
+ /**
3
+ * Handle clicks outside an element.
4
+ * @returns An id and ref to pass to the element to handle clicks
5
+ * outside of.
6
+ */
7
+ export declare const useClickOutside: <E extends HTMLElement>(onClickOutside: () => void) => [MutableRefObject<E>, string];
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useClickOutside = void 0;
7
+
8
+ var _react = require("react");
9
+
10
+ var _useId = require("./useId");
11
+
12
+ /**
13
+ * Handle clicks outside an element.
14
+ * @returns An id and ref to pass to the element to handle clicks
15
+ * outside of.
16
+ */
17
+ var useClickOutside = function useClickOutside(onClickOutside) {
18
+ var wrapperRef = (0, _react.useRef)(null);
19
+ var id = (0, _useId.useId)();
20
+ var handleClickOutside = (0, _react.useCallback)(function (evt) {
21
+ var _evt$target, _wrapperRef$current;
22
+
23
+ var target = evt.target; // The target might be something like an SVG node which doesn't provide
24
+ // the class name as a string.
25
+
26
+ var isValidTarget = typeof (evt === null || evt === void 0 ? void 0 : (_evt$target = evt.target) === null || _evt$target === void 0 ? void 0 : _evt$target.className) === "string";
27
+
28
+ if (!isValidTarget || wrapperRef.current && !((_wrapperRef$current = wrapperRef.current) !== null && _wrapperRef$current !== void 0 && _wrapperRef$current.contains(target)) && target.id !== id) {
29
+ onClickOutside();
30
+ }
31
+ }, [id, onClickOutside]);
32
+ (0, _react.useEffect)(function () {
33
+ document.addEventListener("click", handleClickOutside, false);
34
+ return function () {
35
+ return document.removeEventListener("click", handleClickOutside, false);
36
+ };
37
+ }, [handleClickOutside]);
38
+ return [wrapperRef, id];
39
+ };
40
+
41
+ exports.useClickOutside = useClickOutside;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Handle the escape key pressed.
3
+ */
4
+ export declare const useOnEscapePressed: (onEscape: () => void) => void;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useOnEscapePressed = void 0;
7
+
8
+ var _react = require("react");
9
+
10
+ /**
11
+ * Handle the escape key pressed.
12
+ */
13
+ var useOnEscapePressed = function useOnEscapePressed(onEscape) {
14
+ var keyDown = (0, _react.useCallback)(function (evt) {
15
+ if (evt.code === "Escape") {
16
+ onEscape();
17
+ }
18
+ }, [onEscape]);
19
+ (0, _react.useEffect)(function () {
20
+ document.addEventListener("keydown", keyDown);
21
+ return function () {
22
+ document.removeEventListener("keydown", keyDown);
23
+ };
24
+ }, [keyDown]);
25
+ };
26
+
27
+ exports.useOnEscapePressed = useOnEscapePressed;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * A hook that handles pagination.
3
+ * @param data - The data array to paginate.
4
+ * @param {Object} options
5
+ * @param {number} [options.itemsPerPage] - Number of items per page. Returns all items if no value has been provided.
6
+ * @param {number} [options.initialPage=1] - Initial page number. Defaults to 1.
7
+ * @param {boolean} [options.autoResetPage=false] - Whether to reset the page number to 1 when the data changes.
8
+ */
9
+ export declare function usePagination<D, I = number | null>(data: Array<D>, options?: {
10
+ itemsPerPage: I;
11
+ initialPage?: number;
12
+ autoResetPage?: boolean;
13
+ }): {
14
+ pageData: Array<D>;
15
+ currentPage: number;
16
+ paginate: (pageNumber: number) => void;
17
+ itemsPerPage: I;
18
+ totalItems: number;
19
+ };
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.usePagination = usePagination;
7
+
8
+ var _react = require("react");
9
+
10
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
11
+
12
+ 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."); }
13
+
14
+ 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); }
15
+
16
+ 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; }
17
+
18
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
19
+
20
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
21
+
22
+ /**
23
+ * A hook that handles pagination.
24
+ * @param data - The data array to paginate.
25
+ * @param {Object} options
26
+ * @param {number} [options.itemsPerPage] - Number of items per page. Returns all items if no value has been provided.
27
+ * @param {number} [options.initialPage=1] - Initial page number. Defaults to 1.
28
+ * @param {boolean} [options.autoResetPage=false] - Whether to reset the page number to 1 when the data changes.
29
+ */
30
+ function usePagination(data, options) {
31
+ var _data$length;
32
+
33
+ var defaultOptions = {
34
+ initialPage: 1,
35
+ autoResetPage: false
36
+ };
37
+
38
+ var _Object$assign = Object.assign(defaultOptions, options),
39
+ itemsPerPage = _Object$assign.itemsPerPage,
40
+ initialPage = _Object$assign.initialPage,
41
+ autoResetPage = _Object$assign.autoResetPage;
42
+
43
+ var totalItems = (_data$length = data === null || data === void 0 ? void 0 : data.length) !== null && _data$length !== void 0 ? _data$length : 0;
44
+ var initialPageIndex = initialPage > 0 ? initialPage - 1 : 0;
45
+
46
+ var _useState = (0, _react.useState)(initialPageIndex),
47
+ _useState2 = _slicedToArray(_useState, 2),
48
+ pageIndex = _useState2[0],
49
+ setPageIndex = _useState2[1];
50
+
51
+ var startIndex = typeof itemsPerPage === "number" ? pageIndex * itemsPerPage : 0;
52
+
53
+ var paginate = function paginate(pageNumber) {
54
+ return setPageIndex(pageNumber - 1);
55
+ };
56
+
57
+ (0, _react.useEffect)(function () {
58
+ if (typeof itemsPerPage === "number" && startIndex >= totalItems) {
59
+ !autoResetPage && Math.floor(totalItems / itemsPerPage) > 0 ? // go to the last available page if the current page is out of bounds
60
+ setPageIndex(Math.floor(totalItems / itemsPerPage) - 1) : // go to the initial page if autoResetPage is true
61
+ setPageIndex(0);
62
+ }
63
+ }, [pageIndex, startIndex, setPageIndex, totalItems, itemsPerPage, autoResetPage]);
64
+ var pageData = (0, _react.useMemo)(function () {
65
+ return typeof itemsPerPage === "number" ? data === null || data === void 0 ? void 0 : data.slice(startIndex, startIndex + itemsPerPage) : data;
66
+ }, [startIndex, data, itemsPerPage]);
67
+ return {
68
+ pageData: pageData,
69
+ currentPage: pageIndex + 1,
70
+ paginate: paginate,
71
+ itemsPerPage: itemsPerPage,
72
+ totalItems: totalItems
73
+ };
74
+ }
package/dist/index.d.ts CHANGED
@@ -19,6 +19,7 @@ export { default as List } from "./components/List";
19
19
  export { default as Loader } from "./components/Loader";
20
20
  export { default as MainTable } from "./components/MainTable";
21
21
  export { default as ModularTable } from "./components/ModularTable";
22
+ export { default as Navigation } from "./components/Navigation";
22
23
  export { default as Modal } from "./components/Modal";
23
24
  export { default as Notification, NotificationSeverity, } from "./components/Notification";
24
25
  export { default as Pagination } from "./components/Pagination";
@@ -31,6 +32,7 @@ export { default as Select } from "./components/Select";
31
32
  export { default as Slider } from "./components/Slider";
32
33
  export { default as Switch } from "./components/Switch";
33
34
  export { default as Spinner } from "./components/Spinner";
35
+ export { default as StatusLabel, StatusLabelAppearance, } from "./components/StatusLabel";
34
36
  export { default as Strip } from "./components/Strip";
35
37
  export { default as SummaryButton } from "./components/SummaryButton";
36
38
  export { default as Table } from "./components/Table";
@@ -63,6 +65,7 @@ export type { ListProps } from "./components/List";
63
65
  export type { MainTableProps } from "./components/MainTable";
64
66
  export type { ModularTableProps } from "./components/ModularTable";
65
67
  export type { ModalProps } from "./components/Modal";
68
+ export type { GenerateLink, LogoProps, NavigationProps, NavItem, NavLink, } from "./components/Navigation";
66
69
  export type { NotificationProps } from "./components/Notification";
67
70
  export type { PaginationProps } from "./components/Pagination";
68
71
  export type { RadioInputProps } from "./components/RadioInput";
@@ -72,6 +75,7 @@ export type { SearchBoxProps } from "./components/SearchBox";
72
75
  export type { SelectProps } from "./components/Select";
73
76
  export type { SliderProps } from "./components/Slider";
74
77
  export type { SpinnerProps } from "./components/Spinner";
78
+ export type { StatusLabelProps } from "./components/StatusLabel";
75
79
  export type { StripProps } from "./components/Strip";
76
80
  export type { SummaryButtonProps } from "./components/SummaryButton";
77
81
  export type { TableProps } from "./components/Table";
@@ -81,6 +85,6 @@ export type { TableRowProps } from "./components/TableRow";
81
85
  export type { TabsProps } from "./components/Tabs";
82
86
  export type { TextareaProps } from "./components/Textarea";
83
87
  export type { TooltipProps } from "./components/Tooltip";
84
- export { useWindowFitment, useListener, usePrevious, useThrottle, useId, } from "./hooks";
88
+ export { useClickOutside, useId, useListener, useOnEscapePressed, usePrevious, useThrottle, useWindowFitment, } from "./hooks";
85
89
  export type { WindowFitment } from "./hooks";
86
- export type { ClassName, Headings, PropsWithSpread, SortDirection, SubComponentProps, TSFixMe, ValueOf, } from "./types";
90
+ export type { ClassName, Headings, PropsWithSpread, SortDirection, SubComponentProps, Theme, TSFixMe, ValueOf, } from "./types";
package/dist/index.js CHANGED
@@ -155,6 +155,12 @@ Object.defineProperty(exports, "ModularTable", {
155
155
  return _ModularTable.default;
156
156
  }
157
157
  });
158
+ Object.defineProperty(exports, "Navigation", {
159
+ enumerable: true,
160
+ get: function get() {
161
+ return _Navigation.default;
162
+ }
163
+ });
158
164
  Object.defineProperty(exports, "Notification", {
159
165
  enumerable: true,
160
166
  get: function get() {
@@ -221,6 +227,18 @@ Object.defineProperty(exports, "Spinner", {
221
227
  return _Spinner.default;
222
228
  }
223
229
  });
230
+ Object.defineProperty(exports, "StatusLabel", {
231
+ enumerable: true,
232
+ get: function get() {
233
+ return _StatusLabel.default;
234
+ }
235
+ });
236
+ Object.defineProperty(exports, "StatusLabelAppearance", {
237
+ enumerable: true,
238
+ get: function get() {
239
+ return _StatusLabel.StatusLabelAppearance;
240
+ }
241
+ });
224
242
  Object.defineProperty(exports, "Strip", {
225
243
  enumerable: true,
226
244
  get: function get() {
@@ -281,6 +299,12 @@ Object.defineProperty(exports, "Tooltip", {
281
299
  return _Tooltip.default;
282
300
  }
283
301
  });
302
+ Object.defineProperty(exports, "useClickOutside", {
303
+ enumerable: true,
304
+ get: function get() {
305
+ return _hooks.useClickOutside;
306
+ }
307
+ });
284
308
  Object.defineProperty(exports, "useId", {
285
309
  enumerable: true,
286
310
  get: function get() {
@@ -293,6 +317,12 @@ Object.defineProperty(exports, "useListener", {
293
317
  return _hooks.useListener;
294
318
  }
295
319
  });
320
+ Object.defineProperty(exports, "useOnEscapePressed", {
321
+ enumerable: true,
322
+ get: function get() {
323
+ return _hooks.useOnEscapePressed;
324
+ }
325
+ });
296
326
  Object.defineProperty(exports, "usePrevious", {
297
327
  enumerable: true,
298
328
  get: function get() {
@@ -354,6 +384,8 @@ var _MainTable = _interopRequireDefault(require("./components/MainTable"));
354
384
 
355
385
  var _ModularTable = _interopRequireDefault(require("./components/ModularTable"));
356
386
 
387
+ var _Navigation = _interopRequireDefault(require("./components/Navigation"));
388
+
357
389
  var _Modal = _interopRequireDefault(require("./components/Modal"));
358
390
 
359
391
  var _Notification = _interopRequireWildcard(require("./components/Notification"));
@@ -378,6 +410,8 @@ var _Switch = _interopRequireDefault(require("./components/Switch"));
378
410
 
379
411
  var _Spinner = _interopRequireDefault(require("./components/Spinner"));
380
412
 
413
+ var _StatusLabel = _interopRequireWildcard(require("./components/StatusLabel"));
414
+
381
415
  var _Strip = _interopRequireDefault(require("./components/Strip"));
382
416
 
383
417
  var _SummaryButton = _interopRequireDefault(require("./components/SummaryButton"));
@@ -35,3 +35,16 @@ export declare type TSFixMe = any;
35
35
  * defined in EnumLike.
36
36
  */
37
37
  export declare type ValueOf<T> = T[keyof T];
38
+ /**
39
+ * The Vanilla theme types.
40
+ */
41
+ export declare enum Theme {
42
+ /**
43
+ * The dark Vanilla theme.
44
+ */
45
+ DARK = "dark",
46
+ /**
47
+ * The light Vanilla theme.
48
+ */
49
+ LIGHT = "light"
50
+ }
@@ -2,4 +2,52 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
- });
5
+ });
6
+ exports.Theme = void 0;
7
+
8
+ /**
9
+ * This type should be used for all className props in order to ensure
10
+ * consistency across components.
11
+ */
12
+
13
+ /**
14
+ * The allowable heading levels.
15
+ */
16
+
17
+ /**
18
+ * This type can be used when defining props that also spread the props of
19
+ * something else. It ensures that the defined component props are never
20
+ * overwritten by the spread props.
21
+ */
22
+
23
+ /**
24
+ * The allowable sort directions e.g. for a sortable table.
25
+ */
26
+
27
+ /**
28
+ * This type can be used when passing props to a sub component. It makes all
29
+ * component props optional.
30
+ */
31
+
32
+ /**
33
+ * This type is simply an alias for the 'any' type and should be used sparingly,
34
+ * if at all.
35
+ */
36
+ // eslint-disable-line @typescript-eslint/no-explicit-any
37
+
38
+ /**
39
+ * This type allows for converting an object const into an enum-like construct,
40
+ * e.g. value: ValueOf<typeof EnumLike> will only allow value to be a value
41
+ * defined in EnumLike.
42
+ */
43
+
44
+ /**
45
+ * The Vanilla theme types.
46
+ */
47
+ var Theme;
48
+ exports.Theme = Theme;
49
+
50
+ (function (Theme) {
51
+ Theme["DARK"] = "dark";
52
+ Theme["LIGHT"] = "light";
53
+ })(Theme || (exports.Theme = Theme = {}));