@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.
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 +45 -40
  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 +55 -74
  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 +56 -49
  151. package/dist/hooks/useClickOutside.d.ts +0 -6
  152. package/dist/hooks/useClickOutside.js +0 -32
@@ -0,0 +1,12 @@
1
+ import { MutableRefObject, useRef } from "react";
2
+ /**
3
+ * Handle clicks outside an element.
4
+ */
5
+ export declare const useOnClickOutside: <E extends HTMLElement>(elementRef: MutableRefObject<E>, onClickOutside: () => void, { isEnabled }?: {
6
+ isEnabled: boolean;
7
+ }) => void;
8
+ /**
9
+ * Handle clicks outside an element.
10
+ * @returns A ref to pass to the element to handle clicks outside of.
11
+ */
12
+ export declare const useClickOutside: <E extends HTMLElement>(onClickOutside: () => void) => MutableRefObject<E>;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useOnClickOutside = exports.useClickOutside = void 0;
7
+ var _react = require("react");
8
+ /**
9
+ * Handle clicks outside an element.
10
+ */
11
+ const useOnClickOutside = function (elementRef, onClickOutside) {
12
+ let {
13
+ isEnabled
14
+ } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
15
+ isEnabled: true
16
+ };
17
+ const handleClickOutside = (0, _react.useCallback)(evt => {
18
+ var _evt$target, _elementRef$current;
19
+ const target = evt.target;
20
+ // The target might be something like an SVG node which doesn't provide
21
+ // the class name as a string.
22
+ const isValidTarget = typeof (evt === null || evt === void 0 || (_evt$target = evt.target) === null || _evt$target === void 0 ? void 0 : _evt$target.className) === "string";
23
+ if (!isValidTarget || elementRef !== null && elementRef !== void 0 && elementRef.current && !((_elementRef$current = elementRef.current) !== null && _elementRef$current !== void 0 && _elementRef$current.contains(target)) && elementRef.current !== target) {
24
+ onClickOutside();
25
+ }
26
+ }, [elementRef, onClickOutside]);
27
+ (0, _react.useEffect)(() => {
28
+ if (isEnabled) {
29
+ document.addEventListener("click", handleClickOutside, false);
30
+ }
31
+ return () => document.removeEventListener("click", handleClickOutside, false);
32
+ }, [handleClickOutside, isEnabled]);
33
+ };
34
+
35
+ /**
36
+ * Handle clicks outside an element.
37
+ * @returns A ref to pass to the element to handle clicks outside of.
38
+ */
39
+ exports.useOnClickOutside = useOnClickOutside;
40
+ const useClickOutside = onClickOutside => {
41
+ const ref = (0, _react.useRef)(null);
42
+ useOnClickOutside(ref, onClickOutside);
43
+ return ref;
44
+ };
45
+ exports.useClickOutside = useClickOutside;
@@ -1,4 +1,6 @@
1
1
  /**
2
2
  * Handle the escape key pressed.
3
3
  */
4
- export declare const useOnEscapePressed: (onEscape: () => void) => void;
4
+ export declare const useOnEscapePressed: (onEscape: () => void, { isEnabled }?: {
5
+ isEnabled: boolean;
6
+ }) => void;
@@ -8,17 +8,24 @@ var _react = require("react");
8
8
  /**
9
9
  * Handle the escape key pressed.
10
10
  */
11
- var useOnEscapePressed = function useOnEscapePressed(onEscape) {
12
- var keyDown = (0, _react.useCallback)(function (evt) {
11
+ const useOnEscapePressed = function (onEscape) {
12
+ let {
13
+ isEnabled
14
+ } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
15
+ isEnabled: true
16
+ };
17
+ const keyDown = (0, _react.useCallback)(evt => {
13
18
  if (evt.code === "Escape") {
14
19
  onEscape();
15
20
  }
16
21
  }, [onEscape]);
17
- (0, _react.useEffect)(function () {
18
- document.addEventListener("keydown", keyDown);
19
- return function () {
22
+ (0, _react.useEffect)(() => {
23
+ if (isEnabled) {
24
+ document.addEventListener("keydown", keyDown);
25
+ }
26
+ return () => {
20
27
  document.removeEventListener("keydown", keyDown);
21
28
  };
22
- }, [keyDown]);
29
+ }, [keyDown, isEnabled]);
23
30
  };
24
31
  exports.useOnEscapePressed = useOnEscapePressed;
@@ -5,12 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.usePagination = usePagination;
7
7
  var _react = require("react");
8
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
9
- 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."); }
10
- 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); }
11
- 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; }
12
- 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; } }
13
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
14
8
  /**
15
9
  * A hook that handles pagination.
16
10
  * @param data - The data array to paginate.
@@ -22,25 +16,21 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
22
16
 
23
17
  function usePagination(data, options) {
24
18
  var _data$length;
25
- var defaultOptions = {
19
+ const defaultOptions = {
26
20
  initialPage: 1,
27
21
  autoResetPage: false
28
22
  };
29
- var _Object$assign = Object.assign(defaultOptions, options),
30
- itemsPerPage = _Object$assign.itemsPerPage,
31
- initialPage = _Object$assign.initialPage,
32
- autoResetPage = _Object$assign.autoResetPage;
33
- var totalItems = (_data$length = data === null || data === void 0 ? void 0 : data.length) !== null && _data$length !== void 0 ? _data$length : 0;
34
- var initialPageIndex = initialPage > 0 ? initialPage - 1 : 0;
35
- var _useState = (0, _react.useState)(initialPageIndex),
36
- _useState2 = _slicedToArray(_useState, 2),
37
- pageIndex = _useState2[0],
38
- setPageIndex = _useState2[1];
39
- var startIndex = typeof itemsPerPage === "number" ? pageIndex * itemsPerPage : 0;
40
- var paginate = function paginate(pageNumber) {
41
- return setPageIndex(pageNumber - 1);
42
- };
43
- (0, _react.useEffect)(function () {
23
+ const {
24
+ itemsPerPage,
25
+ initialPage,
26
+ autoResetPage
27
+ } = Object.assign(defaultOptions, options);
28
+ const totalItems = (_data$length = data === null || data === void 0 ? void 0 : data.length) !== null && _data$length !== void 0 ? _data$length : 0;
29
+ const initialPageIndex = initialPage > 0 ? initialPage - 1 : 0;
30
+ const [pageIndex, setPageIndex] = (0, _react.useState)(initialPageIndex);
31
+ const startIndex = typeof itemsPerPage === "number" ? pageIndex * itemsPerPage : 0;
32
+ const paginate = pageNumber => setPageIndex(pageNumber - 1);
33
+ (0, _react.useEffect)(() => {
44
34
  if (typeof itemsPerPage === "number" && startIndex >= totalItems) {
45
35
  !autoResetPage && Math.floor(totalItems / itemsPerPage) > 0 ?
46
36
  // go to the last available page if the current page is out of bounds
@@ -49,14 +39,12 @@ function usePagination(data, options) {
49
39
  setPageIndex(0);
50
40
  }
51
41
  }, [pageIndex, startIndex, setPageIndex, totalItems, itemsPerPage, autoResetPage]);
52
- var pageData = (0, _react.useMemo)(function () {
53
- return typeof itemsPerPage === "number" ? data === null || data === void 0 ? void 0 : data.slice(startIndex, startIndex + itemsPerPage) : data;
54
- }, [startIndex, data, itemsPerPage]);
42
+ const pageData = (0, _react.useMemo)(() => typeof itemsPerPage === "number" ? data === null || data === void 0 ? void 0 : data.slice(startIndex, startIndex + itemsPerPage) : data, [startIndex, data, itemsPerPage]);
55
43
  return {
56
- pageData: pageData,
44
+ pageData,
57
45
  currentPage: pageIndex + 1,
58
- paginate: paginate,
59
- itemsPerPage: itemsPerPage,
60
- totalItems: totalItems
46
+ paginate,
47
+ itemsPerPage,
48
+ totalItems
61
49
  };
62
50
  }
@@ -11,10 +11,10 @@ var _react = require("react");
11
11
  * @param setInitial - Whether it should initialise with the current value.
12
12
  * @return The previous value.
13
13
  */
14
- var usePrevious = function usePrevious(value) {
15
- var setInitial = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
16
- var ref = (0, _react.useRef)(setInitial ? value : undefined);
17
- (0, _react.useEffect)(function () {
14
+ const usePrevious = function (value) {
15
+ let setInitial = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
16
+ const ref = (0, _react.useRef)(setInitial ? value : undefined);
17
+ (0, _react.useEffect)(() => {
18
18
  ref.current = value;
19
19
  }, [value]);
20
20
  return ref.current;
@@ -5,14 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.useThrottle = exports.THROTTLE_DELAY = void 0;
7
7
  var _react = require("react");
8
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
9
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
10
- 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); }
11
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
12
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
13
- 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; }
14
- var THROTTLE_DELAY = 1000 / 60;
15
- exports.THROTTLE_DELAY = THROTTLE_DELAY;
8
+ const THROTTLE_DELAY = exports.THROTTLE_DELAY = 1000 / 60;
16
9
  // eslint-disable-line @typescript-eslint/no-explicit-any
17
10
 
18
11
  /**
@@ -21,23 +14,23 @@ exports.THROTTLE_DELAY = THROTTLE_DELAY;
21
14
  * @param delay The throttle delay in ms.
22
15
  * @return The callback function wrapped in the throttle.
23
16
  */
24
- var useThrottle = function useThrottle(callback) {
25
- var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : THROTTLE_DELAY;
26
- var timeout = (0, _react.useRef)();
27
- var lastCall = (0, _react.useRef)();
28
- var lastArgs = (0, _react.useRef)(null);
29
- var throttle = (0, _react.useCallback)(function () {
17
+ const useThrottle = function (callback) {
18
+ let delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : THROTTLE_DELAY;
19
+ const timeout = (0, _react.useRef)();
20
+ const lastCall = (0, _react.useRef)();
21
+ const lastArgs = (0, _react.useRef)(null);
22
+ const throttle = (0, _react.useCallback)(function () {
30
23
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
31
24
  args[_key] = arguments[_key];
32
25
  }
33
26
  lastArgs.current = args;
34
- var callCallback = function callCallback() {
35
- callback.apply(void 0, _toConsumableArray(lastArgs.current));
27
+ const callCallback = () => {
28
+ callback(...lastArgs.current);
36
29
  lastCall.current = Date.now();
37
30
  timeout.current = null;
38
31
  };
39
- var createTimeout = function createTimeout() {
40
- timeout.current = window.setTimeout(function () {
32
+ const createTimeout = () => {
33
+ timeout.current = window.setTimeout(() => {
41
34
  callCallback();
42
35
  timeout.current = null;
43
36
  }, delay);
@@ -52,13 +45,11 @@ var useThrottle = function useThrottle(callback) {
52
45
  createTimeout();
53
46
  }
54
47
  }, [callback, delay]);
55
- (0, _react.useEffect)(function () {
56
- return function () {
57
- // Clear the timeout when unmounting.
58
- if (timeout.current) {
59
- clearTimeout(timeout.current);
60
- }
61
- };
48
+ (0, _react.useEffect)(() => () => {
49
+ // Clear the timeout when unmounting.
50
+ if (timeout.current) {
51
+ clearTimeout(timeout.current);
52
+ }
62
53
  }, []);
63
54
  return throttle;
64
55
  };
@@ -17,13 +17,13 @@ var _useListener = require("./useListener");
17
17
  * to the mouse. In this case refernceNode will be used to
18
18
  * listen for mouseover events.
19
19
  */
20
- var useWindowFitment = function useWindowFitment(targetNode, referenceNode, callback) {
21
- var spacer = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
22
- var shouldCheck = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
23
- var fromMouse = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
24
- var htmlRef = (0, _react.useRef)(document.querySelector("html"));
25
- var update = (0, _react.useCallback)(function (evt) {
26
- var referenceCoordinates;
20
+ const useWindowFitment = function (targetNode, referenceNode, callback) {
21
+ let spacer = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
22
+ let shouldCheck = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
23
+ let fromMouse = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
24
+ const htmlRef = (0, _react.useRef)(document.querySelector("html"));
25
+ const update = (0, _react.useCallback)(evt => {
26
+ let referenceCoordinates;
27
27
  if (fromMouse) {
28
28
  if (evt) {
29
29
  referenceCoordinates = {
@@ -38,26 +38,28 @@ var useWindowFitment = function useWindowFitment(targetNode, referenceNode, call
38
38
  referenceCoordinates = referenceNode.getBoundingClientRect();
39
39
  }
40
40
  if (shouldCheck && targetNode && referenceCoordinates) {
41
- var _targetNode$getBoundi = targetNode.getBoundingClientRect(),
42
- targetHeight = _targetNode$getBoundi.height,
43
- targetWidth = _targetNode$getBoundi.width;
44
- var _referenceCoordinates = referenceCoordinates,
45
- referenceHeight = _referenceCoordinates.height,
46
- referenceLeft = _referenceCoordinates.left,
47
- referenceTop = _referenceCoordinates.top,
48
- referenceWidth = _referenceCoordinates.width;
49
- var referenceBottom = referenceTop + referenceHeight;
50
- var referenceRight = referenceLeft + referenceWidth;
51
- var referenceCenterX = referenceLeft + referenceWidth / 2;
52
- var referenceCenterY = referenceTop + referenceHeight / 2;
53
- var windowLeft = htmlRef.current.scrollLeft;
54
- var windowRight = window.innerWidth - htmlRef.current.scrollLeft;
55
- var windowTop = 0;
56
- var windowBottom = window.innerHeight;
57
- var heightIncludingSpace = targetHeight + spacer;
58
- var widthIncludingSpace = targetWidth + spacer;
59
- var widthFromCenter = targetWidth / 2;
60
- var heightFromCenter = targetHeight / 2;
41
+ const {
42
+ height: targetHeight,
43
+ width: targetWidth
44
+ } = targetNode.getBoundingClientRect();
45
+ const {
46
+ height: referenceHeight,
47
+ left: referenceLeft,
48
+ top: referenceTop,
49
+ width: referenceWidth
50
+ } = referenceCoordinates;
51
+ const referenceBottom = referenceTop + referenceHeight;
52
+ const referenceRight = referenceLeft + referenceWidth;
53
+ const referenceCenterX = referenceLeft + referenceWidth / 2;
54
+ const referenceCenterY = referenceTop + referenceHeight / 2;
55
+ const windowLeft = htmlRef.current.scrollLeft;
56
+ const windowRight = window.innerWidth - htmlRef.current.scrollLeft;
57
+ const windowTop = 0;
58
+ const windowBottom = window.innerHeight;
59
+ const heightIncludingSpace = targetHeight + spacer;
60
+ const widthIncludingSpace = targetWidth + spacer;
61
+ const widthFromCenter = targetWidth / 2;
62
+ const heightFromCenter = targetHeight / 2;
61
63
  callback({
62
64
  fromTop: {
63
65
  fitsAbove: referenceTop - heightIncludingSpace > windowTop,
@@ -105,7 +107,7 @@ var useWindowFitment = function useWindowFitment(targetNode, referenceNode, call
105
107
  (0, _useListener.useListener)(window, update, "resize", true, shouldCheck && !fromMouse);
106
108
  (0, _useListener.useListener)(window, update, "scroll", true, shouldCheck && !fromMouse);
107
109
  (0, _useListener.useListener)(referenceNode, update, "mousemove", true, fromMouse && shouldCheck);
108
- (0, _react.useEffect)(function () {
110
+ (0, _react.useEffect)(() => {
109
111
  if (!fromMouse) {
110
112
  update();
111
113
  }
package/dist/index.d.ts CHANGED
@@ -47,6 +47,7 @@ export { default as TableRow } from "./components/TableRow";
47
47
  export { default as Tabs } from "./components/Tabs";
48
48
  export { default as Textarea } from "./components/Textarea";
49
49
  export { default as Tooltip } from "./components/Tooltip";
50
+ export { default as TablePagination } from "./components/TablePagination";
50
51
  export type { AccordionProps } from "./components/Accordion";
51
52
  export type { ActionButtonProps } from "./components/ActionButton";
52
53
  export type { ArticlePaginationProps } from "./components/ArticlePagination";
@@ -93,7 +94,8 @@ export type { TableRowProps } from "./components/TableRow";
93
94
  export type { TabsProps } from "./components/Tabs";
94
95
  export type { TextareaProps } from "./components/Textarea";
95
96
  export type { TooltipProps } from "./components/Tooltip";
96
- export { useClickOutside, useId, useListener, useOnEscapePressed, usePagination, usePrevious, useThrottle, useWindowFitment, } from "./hooks";
97
+ export type { TablePaginationProps } from "./components/TablePagination";
98
+ export { useOnClickOutside, useClickOutside, useId, useListener, useOnEscapePressed, usePagination, usePrevious, useThrottle, useWindowFitment, } from "./hooks";
97
99
  export type { WindowFitment } from "./hooks";
98
100
  export { isNavigationAnchor, isNavigationButton } from "./utils";
99
101
  export type { ClassName, Headings, PropsWithSpread, SortDirection, SubComponentProps, TSFixMe, ValueOf, } from "./types";