carbon-react 105.0.2 → 105.1.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 (86) hide show
  1. package/esm/__spec_helper__/mock-match-media.d.ts +3 -1
  2. package/esm/components/button/button.component.js +1 -1
  3. package/esm/components/flat-table/flat-table-body-draggable/flat-table-body-draggable.component.js +10 -3
  4. package/esm/components/flat-table/flat-table-body-draggable/flat-table-body-draggable.style.d.ts +2 -0
  5. package/esm/components/flat-table/flat-table-body-draggable/flat-table-body-draggable.style.js +9 -0
  6. package/esm/components/flat-table/flat-table-row/flat-table-row.style.js +0 -1
  7. package/esm/components/multi-action-button/multi-action-button.component.js +1 -1
  8. package/esm/components/select/option/index.d.ts +1 -1
  9. package/esm/components/split-button/split-button.component.js +1 -1
  10. package/esm/components/tile/tile.component.d.ts +3 -2
  11. package/esm/components/tile/tile.component.js +14 -2
  12. package/esm/components/tile/tile.d.ts +2 -0
  13. package/esm/components/toast/toast.component.d.ts +1 -1
  14. package/esm/components/toast/toast.component.js +10 -2
  15. package/esm/hooks/__internal__/useCharacterCount/index.d.ts +1 -2
  16. package/esm/hooks/__internal__/useCharacterCount/index.js +1 -18
  17. package/esm/hooks/__internal__/useCharacterCount/useCharacterCount.d.ts +3 -0
  18. package/esm/hooks/__internal__/useCharacterCount/useCharacterCount.js +24 -0
  19. package/esm/hooks/__internal__/useInputAccessibility/index.d.ts +1 -24
  20. package/esm/hooks/__internal__/useInputAccessibility/useInputAccessibility.d.ts +11 -11
  21. package/esm/hooks/__internal__/useInputAccessibility/useInputAccessibility.js +1 -3
  22. package/esm/hooks/__internal__/useIsAboveBreakpoint/index.d.ts +1 -1
  23. package/esm/hooks/__internal__/useIsAboveBreakpoint/index.js +1 -6
  24. package/esm/hooks/__internal__/useIsAboveBreakpoint/useIsAboveBreakpoint.d.ts +1 -0
  25. package/esm/hooks/__internal__/useIsAboveBreakpoint/useIsAboveBreakpoint.js +6 -0
  26. package/esm/hooks/__internal__/useLocale/index.d.ts +1 -1
  27. package/esm/hooks/__internal__/useLocale/index.js +1 -5
  28. package/esm/hooks/__internal__/useLocale/useLocale.d.ts +1 -0
  29. package/esm/hooks/__internal__/useLocale/useLocale.js +5 -0
  30. package/esm/hooks/__internal__/useResizeObserver/index.d.ts +1 -10
  31. package/esm/hooks/__internal__/useResizeObserver/index.js +1 -23
  32. package/esm/hooks/__internal__/useResizeObserver/useResizeObserver.d.ts +8 -0
  33. package/esm/hooks/__internal__/useResizeObserver/useResizeObserver.js +29 -0
  34. package/esm/hooks/__internal__/useScrollBlock/index.d.ts +1 -4
  35. package/esm/hooks/__internal__/useScrollBlock/scroll-block-manager.d.ts +23 -9
  36. package/esm/hooks/__internal__/useScrollBlock/scroll-block-manager.js +24 -12
  37. package/esm/hooks/__internal__/useScrollBlock/useScrollBlock.d.ts +2 -2
  38. package/esm/hooks/__internal__/useScrollBlock/useScrollBlock.js +3 -5
  39. package/esm/hooks/useMediaQuery/index.d.ts +1 -1
  40. package/esm/hooks/useMediaQuery/index.js +1 -19
  41. package/esm/hooks/useMediaQuery/useMediaQuery.d.ts +1 -0
  42. package/esm/hooks/useMediaQuery/useMediaQuery.js +19 -0
  43. package/lib/__spec_helper__/mock-match-media.d.ts +3 -1
  44. package/lib/components/button/button.component.js +1 -1
  45. package/lib/components/flat-table/flat-table-body-draggable/flat-table-body-draggable.component.js +10 -3
  46. package/lib/components/flat-table/flat-table-body-draggable/flat-table-body-draggable.style.d.ts +2 -0
  47. package/lib/components/flat-table/flat-table-body-draggable/flat-table-body-draggable.style.js +22 -0
  48. package/lib/components/flat-table/flat-table-row/flat-table-row.style.js +0 -1
  49. package/lib/components/multi-action-button/multi-action-button.component.js +1 -1
  50. package/lib/components/select/option/index.d.ts +1 -1
  51. package/lib/components/split-button/split-button.component.js +1 -1
  52. package/lib/components/tile/tile.component.d.ts +3 -2
  53. package/lib/components/tile/tile.component.js +17 -2
  54. package/lib/components/tile/tile.d.ts +2 -0
  55. package/lib/components/toast/toast.component.d.ts +1 -1
  56. package/lib/components/toast/toast.component.js +13 -2
  57. package/lib/components/vertical-divider/vertical-divider.component.js +3 -0
  58. package/lib/hooks/__internal__/useCharacterCount/index.d.ts +1 -2
  59. package/lib/hooks/__internal__/useCharacterCount/index.js +8 -27
  60. package/lib/hooks/__internal__/useCharacterCount/useCharacterCount.d.ts +3 -0
  61. package/lib/hooks/__internal__/useCharacterCount/useCharacterCount.js +40 -0
  62. package/lib/hooks/__internal__/useInputAccessibility/index.d.ts +1 -24
  63. package/lib/hooks/__internal__/useInputAccessibility/useInputAccessibility.d.ts +11 -11
  64. package/lib/hooks/__internal__/useInputAccessibility/useInputAccessibility.js +1 -3
  65. package/lib/hooks/__internal__/useIsAboveBreakpoint/index.d.ts +1 -1
  66. package/lib/hooks/__internal__/useIsAboveBreakpoint/index.js +8 -9
  67. package/lib/hooks/__internal__/useIsAboveBreakpoint/useIsAboveBreakpoint.d.ts +1 -0
  68. package/lib/hooks/__internal__/useIsAboveBreakpoint/useIsAboveBreakpoint.js +16 -0
  69. package/lib/hooks/__internal__/useLocale/index.d.ts +1 -1
  70. package/lib/hooks/__internal__/useLocale/index.js +8 -9
  71. package/lib/hooks/__internal__/useLocale/useLocale.d.ts +1 -0
  72. package/lib/hooks/__internal__/useLocale/useLocale.js +16 -0
  73. package/lib/hooks/__internal__/useResizeObserver/index.d.ts +1 -10
  74. package/lib/hooks/__internal__/useResizeObserver/index.js +8 -24
  75. package/lib/hooks/__internal__/useResizeObserver/useResizeObserver.d.ts +8 -0
  76. package/lib/hooks/__internal__/useResizeObserver/useResizeObserver.js +37 -0
  77. package/lib/hooks/__internal__/useScrollBlock/index.d.ts +1 -4
  78. package/lib/hooks/__internal__/useScrollBlock/scroll-block-manager.d.ts +23 -9
  79. package/lib/hooks/__internal__/useScrollBlock/scroll-block-manager.js +24 -12
  80. package/lib/hooks/__internal__/useScrollBlock/useScrollBlock.d.ts +2 -2
  81. package/lib/hooks/__internal__/useScrollBlock/useScrollBlock.js +3 -5
  82. package/lib/hooks/useMediaQuery/index.d.ts +1 -1
  83. package/lib/hooks/useMediaQuery/index.js +8 -25
  84. package/lib/hooks/useMediaQuery/useMediaQuery.d.ts +1 -0
  85. package/lib/hooks/useMediaQuery/useMediaQuery.js +32 -0
  86. package/package.json +5 -3
@@ -1,4 +1,6 @@
1
1
  declare function setup(): void;
2
- declare function mockMatchMedia(matches?: boolean): jest.Mock;
2
+ declare function mockMatchMedia(
3
+ matches?: boolean
4
+ ): { removeListener: jest.Mock };
3
5
 
4
6
  export { setup, mockMatchMedia };
@@ -78,7 +78,7 @@ const Button = ({
78
78
  if (!deprecatedWarnTriggered && as) {
79
79
  deprecatedWarnTriggered = true;
80
80
  Logger.deprecate( // eslint-disable-next-line max-len
81
- "The `as` prop is deprecated and will soon be removed. You should use the `buttonType` prop to achieve the same styling. The following codemod is available to help with updating your code https://github.com/Sage/carbon-codemod/tree/master/transforms/rename-prop");
81
+ "The `as` prop is deprecated and will soon be removed from the `Button` component interface. You should use the `buttonType` prop to achieve the same styling. The following codemod is available to help with updating your code https://github.com/Sage/carbon-codemod/tree/master/transforms/rename-prop");
82
82
  }
83
83
 
84
84
  const [internalRef, setInternalRef] = useState(null);
@@ -5,7 +5,7 @@ import { useDrop, DndProvider } from "react-dnd";
5
5
  import { HTML5Backend } from "react-dnd-html5-backend";
6
6
  import PropTypes from "prop-types";
7
7
  import StyledIcon from "../../icon/icon.style";
8
- import FlatTableBody from "../flat-table-body/flat-table-body.component";
8
+ import StyledFlatTableBodyDraggable from "./flat-table-body-draggable.style";
9
9
  import FlatTableCell from "../flat-table-cell/flat-table-cell.component";
10
10
 
11
11
  const DropTarget = ({
@@ -13,16 +13,23 @@ const DropTarget = ({
13
13
  getOrder,
14
14
  ...rest
15
15
  }) => {
16
+ const [isDragging, setIsDragging] = useState(false);
16
17
  const [, drop] = useDrop({
17
18
  accept: "flatTableRow",
19
+ hover: (_, monitor) => {
20
+ if (!isDragging && monitor.isOver()) setIsDragging(true);
21
+ },
18
22
 
19
23
  drop() {
24
+ setIsDragging(false);
20
25
  getOrder();
21
26
  }
22
27
 
23
28
  });
24
- return /*#__PURE__*/React.createElement(FlatTableBody, _extends({
25
- ref: drop
29
+ return /*#__PURE__*/React.createElement(StyledFlatTableBodyDraggable, _extends({
30
+ "data-testid": "flat-table-body-draggable",
31
+ ref: drop,
32
+ isDragging: isDragging
26
33
  }, rest), children);
27
34
  };
28
35
 
@@ -0,0 +1,2 @@
1
+ export default StyledFlatTableBodyDraggable;
2
+ declare const StyledFlatTableBodyDraggable: import("styled-components").StyledComponent<"tbody", any, {}, never>;
@@ -0,0 +1,9 @@
1
+ import styled, { css } from "styled-components";
2
+ const StyledFlatTableBodyDraggable = styled.tbody`
3
+ ${({
4
+ isDragging
5
+ }) => isDragging && css`
6
+ cursor: grabbing;
7
+ `}
8
+ `;
9
+ export default StyledFlatTableBodyDraggable;
@@ -248,7 +248,6 @@ const StyledFlatTableRow = styled.tr`
248
248
  ${isDragging && css`
249
249
  border: ${isInSidebar ? "var(--colorsUtilityMajor300)" : "var(--colorsUtilityMajor200)"}
250
250
  2px solid;
251
- cursor: grabbing;
252
251
  ${allCellTypes} {
253
252
  background-color: ${isInSidebar ? "var(--colorsUtilityMajor200)" : "var(--colorsUtilityMajor150)"};
254
253
  }
@@ -27,7 +27,7 @@ const MultiActionButton = ({
27
27
  if (!deprecatedWarnTriggered && as) {
28
28
  deprecatedWarnTriggered = true;
29
29
  Logger.deprecate( // eslint-disable-next-line max-len
30
- "The `as` prop is deprecated and will soon be removed. You should use the `buttonType` prop to achieve the same styling. The following codemod is available to help with updating your code https://github.com/Sage/carbon-codemod/tree/master/transforms/rename-prop");
30
+ "The `as` prop is deprecated and will soon be removed from the `MultiActionButton` component interface. You should use the `buttonType` prop to achieve the same styling. The following codemod is available to help with updating your code https://github.com/Sage/carbon-codemod/tree/master/transforms/rename-prop");
31
31
  }
32
32
 
33
33
  const ref = useRef();
@@ -4,7 +4,7 @@ export interface OptionProps {
4
4
  /** The option's visible text, displayed within <Textbox> of <Select>, and used for filtering */
5
5
  text: string;
6
6
  /** Optional: alternative rendered content, displayed within <SelectList> of <Select> (eg: an icon, an image, etc) */
7
- children?: React.ComponentType;
7
+ children?: React.ReactNode;
8
8
  /** The option's invisible internal value */
9
9
  value: string | Record<string, unknown>;
10
10
  /** MultiSelect only - custom Pill border color - provide any color from palette or any valid css color value. */
@@ -37,7 +37,7 @@ const SplitButton = ({
37
37
  if (!deprecatedWarnTriggered && as) {
38
38
  deprecatedWarnTriggered = true;
39
39
  Logger.deprecate( // eslint-disable-next-line max-len
40
- "The `as` prop is deprecated and will soon be removed. You should use the `buttonType` prop to achieve the same styling. The following codemod is available to help with updating your code https://github.com/Sage/carbon-codemod/tree/master/transforms/rename-prop");
40
+ "The `as` prop is deprecated and will soon be removed from the `SplitButton` component interface. You should use the `buttonType` prop to achieve the same styling. The following codemod is available to help with updating your code https://github.com/Sage/carbon-codemod/tree/master/transforms/rename-prop");
41
41
  }
42
42
 
43
43
  const theme = useContext(ThemeContext) || baseTheme;
@@ -1,7 +1,8 @@
1
1
  export default Tile;
2
- declare function Tile({ as, p, children, orientation, width, ...props }: {
2
+ declare function Tile({ as, variant, p, children, orientation, width, ...props }: {
3
3
  [x: string]: any;
4
- as?: string | undefined;
4
+ as: any;
5
+ variant?: string | undefined;
5
6
  p?: number | undefined;
6
7
  children: any;
7
8
  orientation?: string | undefined;
@@ -4,15 +4,24 @@ import React from "react";
4
4
  import PropTypes from "prop-types";
5
5
  import propTypes from "@styled-system/prop-types";
6
6
  import { StyledTile, TileContent } from "./tile.style.js";
7
+ import Logger from "../../__internal__/utils/logger";
8
+ let deprecatedWarnTriggered = false;
7
9
 
8
10
  const Tile = ({
9
- as = "tile",
11
+ as,
12
+ variant = "tile",
10
13
  p = 3,
11
14
  children,
12
15
  orientation = "horizontal",
13
16
  width,
14
17
  ...props
15
18
  }) => {
19
+ if (!deprecatedWarnTriggered && as) {
20
+ deprecatedWarnTriggered = true;
21
+ Logger.deprecate( // eslint-disable-next-line max-len
22
+ "The `as` prop is deprecated and will soon be removed from the `Tile` component interface. You should use the `variant` prop to achieve the same styling. The following codemod is available to help with updating your code https://github.com/Sage/carbon-codemod/tree/master/transforms/rename-prop");
23
+ }
24
+
16
25
  const isHorizontal = () => orientation === "horizontal";
17
26
 
18
27
  const isVertical = () => orientation === "vertical";
@@ -41,7 +50,7 @@ const Tile = ({
41
50
  }), /*#__PURE__*/React.cloneElement(child, childProps));
42
51
  });
43
52
  return /*#__PURE__*/React.createElement(StyledTile, _extends({
44
- tileTheme: as,
53
+ tileTheme: as || variant,
45
54
  width: width,
46
55
  "data-component": "tile",
47
56
  isHorizontal: isHorizontal(orientation),
@@ -56,6 +65,9 @@ Tile.propTypes = {
56
65
  /** Sets the theme of the tile - either 'tile' or 'transparent' */
57
66
  as: PropTypes.oneOf(["tile", "transparent"]),
58
67
 
68
+ /** Sets the theme of the tile - either 'tile' or 'transparent' */
69
+ variant: PropTypes.oneOf(["tile", "transparent"]),
70
+
59
71
  /**
60
72
  * The content to render within the tile. Each child will be wrapped with
61
73
  * a TileContent wrapper, which allows any individual child component to take a
@@ -4,6 +4,8 @@ import { SpaceProps } from "styled-system";
4
4
  export interface TileProps extends SpaceProps {
5
5
  /** Sets the theme of the tile - either 'tile' or 'transparent' */
6
6
  as?: "tile" | "transparent";
7
+ /** Sets the theme of the tile - either 'tile' or 'transparent' */
8
+ variant?: "tile" | "transparent";
7
9
  /**
8
10
  * The content to render within the tile. Each child will be wrapped with
9
11
  * a TileContent wrapper, which allows any individual child component to take a
@@ -1,7 +1,7 @@
1
1
  export default Toast;
2
2
  declare function Toast({ as, children, className, id, isCenter, maxWidth, onDismiss, open, targetPortalId, timeout, variant, ...restProps }: {
3
3
  [x: string]: any;
4
- as?: string | undefined;
4
+ as: any;
5
5
  children: any;
6
6
  className: any;
7
7
  id: any;
@@ -11,9 +11,11 @@ import IconButton from "../icon-button";
11
11
  import ModalManager from "../modal/__internal__/modal-manager";
12
12
  import Events from "../../__internal__/utils/helpers/events";
13
13
  import useLocale from "../../hooks/__internal__/useLocale";
14
+ import Logger from "../../__internal__/utils/logger";
15
+ let deprecatedWarnTriggered = false;
14
16
 
15
17
  const Toast = ({
16
- as = "success",
18
+ as,
17
19
  children,
18
20
  className,
19
21
  id,
@@ -26,6 +28,12 @@ const Toast = ({
26
28
  variant,
27
29
  ...restProps
28
30
  }) => {
31
+ if (!deprecatedWarnTriggered && as) {
32
+ deprecatedWarnTriggered = true;
33
+ Logger.deprecate( // eslint-disable-next-line max-len
34
+ "The `as` prop is deprecated and will soon be removed from the `Toast` component interface. You should use the `variant` prop to achieve the same styling. The following codemod is available to help with updating your code https://github.com/Sage/carbon-codemod/tree/master/transforms/rename-prop");
35
+ }
36
+
29
37
  const locale = useLocale();
30
38
  const toastRef = useRef();
31
39
  const timer = useRef();
@@ -74,7 +82,7 @@ const Toast = ({
74
82
  if (!open) return null;
75
83
  const toastProps = {
76
84
  isCenter,
77
- variant: variant || as,
85
+ variant: variant || as || "success",
78
86
  id,
79
87
  maxWidth
80
88
  };
@@ -1,2 +1 @@
1
- export default useCharacterCount;
2
- declare function useCharacterCount(value: any, characterLimit: any, warnOverLimit?: boolean, enforceCharacterLimit?: boolean): any[];
1
+ export { default } from "./useCharacterCount";
@@ -1,18 +1 @@
1
- import React, { useMemo } from "react";
2
- import CharacterCount from "../../../__internal__/character-count";
3
- import useLocale from "../useLocale";
4
-
5
- const getFormatNumber = (value, locale) => new Intl.NumberFormat(locale).format(value);
6
-
7
- const useCharacterCount = (value, characterLimit, warnOverLimit = false, enforceCharacterLimit = true) => {
8
- const l = useLocale();
9
- const isOverLimit = useMemo(() => value && value.length > parseInt(characterLimit, 10), [value, characterLimit]);
10
- return [enforceCharacterLimit && characterLimit ? characterLimit : undefined, characterLimit ? /*#__PURE__*/React.createElement(CharacterCount, {
11
- isOverLimit: isOverLimit && warnOverLimit,
12
- value: getFormatNumber(value.length, l.locale()),
13
- limit: getFormatNumber(characterLimit, l.locale()),
14
- "data-element": "character-limit"
15
- }) : null];
16
- };
17
-
18
- export default useCharacterCount;
1
+ export { default } from "./useCharacterCount";
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ declare const useCharacterCount: (value: string, characterLimit?: string | undefined, warnOverLimit?: boolean, enforceCharacterLimit?: boolean) => [string | undefined, JSX.Element | null];
3
+ export default useCharacterCount;
@@ -0,0 +1,24 @@
1
+ import React, { useMemo } from "react";
2
+ import CharacterCount from "../../../__internal__/character-count";
3
+ import useLocale from "../useLocale";
4
+
5
+ const getFormatNumber = (value, locale) => new Intl.NumberFormat(locale).format(value);
6
+
7
+ const useCharacterCount = (value, characterLimit, warnOverLimit = false, enforceCharacterLimit = true) => {
8
+ const l = useLocale();
9
+ const isOverLimit = useMemo(() => {
10
+ if (value && characterLimit) {
11
+ return value.length > parseInt(characterLimit, 10);
12
+ }
13
+
14
+ return false;
15
+ }, [value, characterLimit]);
16
+ return [enforceCharacterLimit && characterLimit ? characterLimit : undefined, characterLimit ? /*#__PURE__*/React.createElement(CharacterCount, {
17
+ isOverLimit: isOverLimit && warnOverLimit,
18
+ value: getFormatNumber(value.length, l.locale()),
19
+ limit: getFormatNumber(+characterLimit, l.locale()),
20
+ "data-element": "character-limit"
21
+ }) : null];
22
+ };
23
+
24
+ export default useCharacterCount;
@@ -1,24 +1 @@
1
- interface InputAccessibilityProperties {
2
- labelId?: string;
3
- tooltipId?: string;
4
- fieldHelpId?: string;
5
- ariaDescribedBy?: string;
6
- ariaLabelledBy?: string;
7
- }
8
-
9
- export default function useInputAccessibility(
10
- /** Input id - */
11
- id: string,
12
- /** Error validation message */
13
- error?: string,
14
- /** Warning validation message */
15
- warning?: string,
16
- /** Info validation message */
17
- info?: string,
18
- /** Label */
19
- label?: string,
20
- /** labelHelp message */
21
- labelHelp?: string,
22
- /** fieldHelp message */
23
- fieldHelp?: string
24
- ): void;
1
+ export { default } from "./useInputAccessibility";
@@ -1,14 +1,14 @@
1
1
  export default function useInputAccessibility({ id, error, warning, info, label, fieldHelp, }: {
2
- id: any;
3
- error: any;
4
- warning: any;
5
- info: any;
6
- label: any;
7
- fieldHelp: any;
2
+ id: string;
3
+ error?: string;
4
+ warning?: string;
5
+ info?: string;
6
+ label?: string;
7
+ fieldHelp?: string;
8
8
  }): {
9
- labelId: string | undefined;
10
- validationIconId: string | undefined;
11
- fieldHelpId: string | undefined;
12
- ariaDescribedBy: string;
13
- ariaLabelledBy: string | undefined;
9
+ labelId?: string;
10
+ validationIconId?: string;
11
+ fieldHelpId?: string;
12
+ ariaDescribedBy?: string;
13
+ ariaLabelledBy?: string;
14
14
  };
@@ -7,9 +7,7 @@ export default function useInputAccessibility({
7
7
  fieldHelp
8
8
  }) {
9
9
  const labelId = label ? `${id}-label` : undefined;
10
- const validationIconId = [error, warning, info].filter(validation => {
11
- return validation && typeof validation === "string";
12
- }).length ? `${id}-validation-icon` : undefined;
10
+ const validationIconId = [error, warning, info].filter(validation => validation && typeof validation === "string").length ? `${id}-validation-icon` : undefined;
13
11
  const fieldHelpId = fieldHelp ? `${id}-field-help` : undefined;
14
12
  const ariaDescribedBy = [fieldHelpId, validationIconId].filter(Boolean).join(" ");
15
13
  const ariaLabelledBy = labelId;
@@ -1 +1 @@
1
- export default function useIsAboveBreakpoint(breakpoint?: number): boolean;
1
+ export { default } from "./useIsAboveBreakpoint";
@@ -1,6 +1 @@
1
- import useMediaQuery from "../../useMediaQuery";
2
- export default function useIsAboveBreakpoint(breakpoint) {
3
- const matchesQuery = useMediaQuery(`(min-width:${breakpoint}px)`);
4
- if (!breakpoint) return undefined;
5
- return matchesQuery;
6
- }
1
+ export { default } from "./useIsAboveBreakpoint";
@@ -0,0 +1 @@
1
+ export default function useIsAboveBreakpoint(breakpoint?: number): boolean | undefined;
@@ -0,0 +1,6 @@
1
+ import useMediaQuery from "../../useMediaQuery";
2
+ export default function useIsAboveBreakpoint(breakpoint) {
3
+ const matchesQuery = useMediaQuery(`(min-width:${breakpoint}px)`);
4
+ if (!breakpoint) return undefined;
5
+ return matchesQuery;
6
+ }
@@ -1 +1 @@
1
- export default function useLocale(): import("../../../locales/locale").default;
1
+ export { default } from "./useLocale";
@@ -1,5 +1 @@
1
- import { useContext } from "react";
2
- import Context from "../../../__internal__/i18n-context";
3
- export default function useLocale() {
4
- return useContext(Context);
5
- }
1
+ export { default } from "./useLocale";
@@ -0,0 +1 @@
1
+ export default function useLocale(): import("../../../locales/locale").default;
@@ -0,0 +1,5 @@
1
+ import { useContext } from "react";
2
+ import Context from "../../../__internal__/i18n-context";
3
+ export default function useLocale() {
4
+ return useContext(Context);
5
+ }
@@ -1,10 +1 @@
1
- import * as React from "react";
2
-
3
- export default function useResizeObserver(
4
- /** Reference to the resizable HTML element - */
5
- ref: React.RefObject<HTMLElement>,
6
- /** Callback meant to be executed on element resize */
7
- onResize: () => void,
8
- /** Flag to indicate whether hook should be disabled */
9
- disabled?: boolean
10
- ): void;
1
+ export { default } from "./useResizeObserver";
@@ -1,23 +1 @@
1
- import { useRef, useLayoutEffect } from "react";
2
- export default function useResizeObserver(ref, onResize, disabled) {
3
- const observer = useRef(null);
4
- const onResizeRef = useRef(null);
5
- onResizeRef.current = onResize;
6
- useLayoutEffect(() => {
7
- const referenceRef = ref.current;
8
-
9
- if (!disabled) {
10
- observer.current = new ResizeObserver(() => {
11
- onResizeRef === null || onResizeRef === void 0 ? void 0 : onResizeRef.current();
12
- });
13
- observer.current.observe(referenceRef);
14
- }
15
-
16
- return () => {
17
- if (!disabled) {
18
- observer.current.unobserve(referenceRef);
19
- observer.current.disconnect();
20
- }
21
- };
22
- }, [ref, disabled]);
23
- }
1
+ export { default } from "./useResizeObserver";
@@ -0,0 +1,8 @@
1
+ import { RefObject } from "react";
2
+ export default function useResizeObserver(
3
+ /** Reference to the resizable HTML element */
4
+ ref: RefObject<Element>,
5
+ /** Callback meant to be executed on element resize */
6
+ onResize: () => void,
7
+ /** Flag to indicate whether hook should be disabled */
8
+ disabled?: boolean): void;
@@ -0,0 +1,29 @@
1
+ import { useRef, useLayoutEffect } from "react";
2
+ export default function useResizeObserver(
3
+ /** Reference to the resizable HTML element */
4
+ ref,
5
+ /** Callback meant to be executed on element resize */
6
+ onResize,
7
+ /** Flag to indicate whether hook should be disabled */
8
+ disabled) {
9
+ const observer = useRef();
10
+ const onResizeRef = useRef(onResize);
11
+ onResizeRef.current = onResize;
12
+ useLayoutEffect(() => {
13
+ const referenceRef = ref.current;
14
+
15
+ if (!disabled && referenceRef) {
16
+ observer.current = new ResizeObserver(() => {
17
+ onResizeRef === null || onResizeRef === void 0 ? void 0 : onResizeRef.current();
18
+ });
19
+ observer.current.observe(referenceRef);
20
+ }
21
+
22
+ return () => {
23
+ if (!disabled && referenceRef && observer.current) {
24
+ observer.current.unobserve(referenceRef);
25
+ observer.current.disconnect();
26
+ }
27
+ };
28
+ }, [ref, disabled]);
29
+ }
@@ -1,4 +1 @@
1
- export default function useScrollBlock(): {
2
- blockScroll: () => void;
3
- allowScroll: () => void;
4
- };
1
+ export { default } from "./useScrollBlock";
@@ -1,12 +1,26 @@
1
- export default ScrollBlockManager;
1
+ declare global {
2
+ interface Window {
3
+ __CARBON_INTERNALS_SCROLL_BLOCKERS?: {
4
+ components: {
5
+ [key: string]: boolean;
6
+ };
7
+ originalValues: string[];
8
+ restoreValues?: (() => void) | null;
9
+ };
10
+ }
11
+ }
2
12
  declare class ScrollBlockManager {
3
- components: any;
4
- originalValues: any;
5
- registerComponent(id: any): void;
6
- unregisterComponent(id: any): void;
7
- saveOriginalValues(values: any): void;
8
- saveRestoreValuesCallback(callback: any): void;
9
- getRestoreValuesCallback(): any;
10
- getOriginalValues(): any;
13
+ components: {
14
+ [key: string]: boolean;
15
+ };
16
+ originalValues: string[];
17
+ constructor();
18
+ registerComponent(id: string): void;
19
+ unregisterComponent(id: string): void;
20
+ saveRestoreValuesCallback(callback: (() => void) | null): void;
21
+ getRestoreValuesCallback(): (() => void) | null | undefined;
22
+ saveOriginalValues(values: string[]): void;
23
+ getOriginalValues(): string[];
11
24
  isBlocked(): boolean;
12
25
  }
26
+ export default ScrollBlockManager;
@@ -4,19 +4,26 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
4
4
 
5
5
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
6
6
 
7
- // TODO: This component can be refactored to remove redundant code after
8
- // we can confirm that all Sage products use version 105.0.0^
7
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
8
+
9
+ // TODO: This component can be refactored to remove redundant code
10
+ // once we can confirm that all Sage products use version 105.0.0^
9
11
  let ScrollBlockManager = /*#__PURE__*/function () {
10
12
  function ScrollBlockManager() {
11
13
  _classCallCheck(this, ScrollBlockManager);
12
14
 
15
+ _defineProperty(this, "components", void 0);
16
+
17
+ _defineProperty(this, "originalValues", void 0);
18
+
13
19
  // Due to possibility of multiple carbon versions using it
14
20
  // it is necessary to maintain same structure in this global variable
15
21
  if (!window.__CARBON_INTERNALS_SCROLL_BLOCKERS) {
16
22
  window.__CARBON_INTERNALS_SCROLL_BLOCKERS = {
17
23
  components: {},
18
24
  // originalValues can be removed
19
- originalValues: []
25
+ originalValues: [],
26
+ restoreValues: null
20
27
  };
21
28
  }
22
29
 
@@ -34,23 +41,28 @@ let ScrollBlockManager = /*#__PURE__*/function () {
34
41
  key: "unregisterComponent",
35
42
  value: function unregisterComponent(id) {
36
43
  delete this.components[id];
37
- } // TODO: saveOriginalValues can be removed
38
-
39
- }, {
40
- key: "saveOriginalValues",
41
- value: function saveOriginalValues(values) {
42
- this.originalValues.length = 0;
43
- this.originalValues.push(...values);
44
44
  }
45
45
  }, {
46
46
  key: "saveRestoreValuesCallback",
47
47
  value: function saveRestoreValuesCallback(callback) {
48
- window.__CARBON_INTERNALS_SCROLL_BLOCKERS.restoreValues = callback;
48
+ /* istanbul ignore else */
49
+ if (window.__CARBON_INTERNALS_SCROLL_BLOCKERS) {
50
+ window.__CARBON_INTERNALS_SCROLL_BLOCKERS.restoreValues = callback;
51
+ }
49
52
  }
50
53
  }, {
51
54
  key: "getRestoreValuesCallback",
52
55
  value: function getRestoreValuesCallback() {
53
- return window.__CARBON_INTERNALS_SCROLL_BLOCKERS.restoreValues;
56
+ var _window$__CARBON_INTE;
57
+
58
+ return (_window$__CARBON_INTE = window.__CARBON_INTERNALS_SCROLL_BLOCKERS) === null || _window$__CARBON_INTE === void 0 ? void 0 : _window$__CARBON_INTE.restoreValues;
59
+ } // TODO: saveOriginalValues can be removed
60
+
61
+ }, {
62
+ key: "saveOriginalValues",
63
+ value: function saveOriginalValues(values) {
64
+ this.originalValues.length = 0;
65
+ this.originalValues.push(...values);
54
66
  } // TODO: getOriginalValues can be removed
55
67
 
56
68
  }, {
@@ -1,5 +1,5 @@
1
- export default useScrollBlock;
2
- declare function useScrollBlock(): {
1
+ declare const useScrollBlock: () => {
3
2
  blockScroll: () => void;
4
3
  allowScroll: () => void;
5
4
  };
5
+ export default useScrollBlock;
@@ -4,20 +4,18 @@ import ScrollBlockManager from "./scroll-block-manager"; // TODO: This component
4
4
  // we can confirm that all Sage products use version 105.0.0^
5
5
 
6
6
  const scrollBlockManager = new ScrollBlockManager();
7
- /* istanbul ignore next */
8
-
9
- const safeDocument = typeof document !== "undefined" ? document : {};
10
7
 
11
8
  const useScrollBlock = () => {
12
9
  const {
13
10
  current: containerGuid
14
11
  } = useRef(guid());
15
- const originalValuesRef = useRef();
12
+ const originalValuesRef = useRef([]);
16
13
  const rules = useMemo(() => {
14
+ /* istanbul ignore next */
17
15
  const {
18
16
  documentElement,
19
17
  body
20
- } = safeDocument;
18
+ } = document || {};
21
19
  const scrollBarWidth = window.innerWidth - documentElement.clientWidth;
22
20
  const bodyPaddingRight = parseInt(window.getComputedStyle(body).getPropertyValue("padding-right")) || 0;
23
21
  return [// TODO: First two entries of this array with the documentElement can be removed
@@ -1 +1 @@
1
- export default function useMediaQuery(query: string): boolean;
1
+ export { default } from "./useMediaQuery";