carbon-react 106.6.0 → 106.6.3

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/__internal__/popover/popover.component.js +4 -5
  2. package/esm/__spec_helper__/expect.d.ts +8 -1
  3. package/esm/__spec_helper__/expect.js +1 -5
  4. package/esm/__spec_helper__/test-utils.d.ts +71 -33
  5. package/esm/__spec_helper__/test-utils.js +63 -65
  6. package/esm/components/action-popover/action-popover-context.d.ts +7 -2
  7. package/esm/components/action-popover/action-popover-context.js +1 -1
  8. package/esm/components/action-popover/action-popover-divider/action-popover-divider.component.d.ts +1 -1
  9. package/esm/components/action-popover/action-popover-item/action-popover-item.component.d.ts +28 -41
  10. package/esm/components/action-popover/action-popover-item/action-popover-item.component.js +99 -118
  11. package/esm/components/action-popover/action-popover-menu/action-popover-menu.component.d.ts +35 -2
  12. package/esm/components/action-popover/action-popover-menu/action-popover-menu.component.js +42 -53
  13. package/esm/components/action-popover/action-popover-menu-button/action-popover-menu-button.component.d.ts +20 -18
  14. package/esm/components/action-popover/action-popover-menu-button/action-popover-menu-button.component.js +13 -5
  15. package/esm/components/action-popover/action-popover-test.stories.js +76 -0
  16. package/esm/components/action-popover/action-popover.component.d.ts +30 -53
  17. package/esm/components/action-popover/action-popover.component.js +205 -67
  18. package/esm/components/action-popover/action-popover.style.d.ts +17 -11
  19. package/esm/components/action-popover/action-popover.style.js +20 -26
  20. package/esm/components/action-popover/index.d.ts +9 -5
  21. package/esm/components/box/box.component.d.ts +12 -1
  22. package/esm/components/box/box.component.js +12 -23
  23. package/esm/components/box/box.config.d.ts +10 -12
  24. package/esm/components/box/index.d.ts +2 -1
  25. package/esm/components/dismissible-box/dismissible-box.style.d.ts +1 -2
  26. package/esm/components/drawer/drawer.style.d.ts +1 -2
  27. package/esm/components/duelling-picklist/picklist/picklist.style.d.ts +2 -3
  28. package/esm/components/flat-table/flat-table.style.d.ts +1 -2
  29. package/esm/components/form/form.component.js +2 -1
  30. package/esm/components/modal/modal.component.js +3 -60
  31. package/esm/components/select/select.style.js +1 -1
  32. package/esm/components/toast/toast.component.js +3 -13
  33. package/esm/hooks/__internal__/useModalManager/index.d.ts +1 -0
  34. package/esm/hooks/__internal__/useModalManager/index.js +1 -0
  35. package/esm/hooks/__internal__/useModalManager/useModalManager.d.ts +3 -0
  36. package/esm/hooks/__internal__/useModalManager/useModalManager.js +66 -0
  37. package/lib/__internal__/popover/popover.component.js +4 -5
  38. package/lib/__spec_helper__/expect.d.ts +8 -1
  39. package/lib/__spec_helper__/expect.js +2 -4
  40. package/lib/__spec_helper__/test-utils.d.ts +71 -33
  41. package/lib/__spec_helper__/test-utils.js +63 -65
  42. package/lib/components/action-popover/action-popover-context.d.ts +7 -2
  43. package/lib/components/action-popover/action-popover-context.js +1 -1
  44. package/lib/components/action-popover/action-popover-divider/action-popover-divider.component.d.ts +1 -1
  45. package/lib/components/action-popover/action-popover-item/action-popover-item.component.d.ts +28 -41
  46. package/lib/components/action-popover/action-popover-item/action-popover-item.component.js +100 -119
  47. package/lib/components/action-popover/action-popover-menu/action-popover-menu.component.d.ts +35 -2
  48. package/lib/components/action-popover/action-popover-menu/action-popover-menu.component.js +44 -55
  49. package/lib/components/action-popover/action-popover-menu-button/action-popover-menu-button.component.d.ts +20 -18
  50. package/lib/components/action-popover/action-popover-menu-button/action-popover-menu-button.component.js +13 -5
  51. package/lib/components/action-popover/action-popover-test.stories.js +95 -0
  52. package/lib/components/action-popover/action-popover.component.d.ts +30 -53
  53. package/lib/components/action-popover/action-popover.component.js +206 -71
  54. package/lib/components/action-popover/action-popover.style.d.ts +17 -11
  55. package/lib/components/action-popover/action-popover.style.js +21 -28
  56. package/lib/components/action-popover/index.d.ts +9 -5
  57. package/lib/components/box/box.component.d.ts +12 -1
  58. package/lib/components/box/box.component.js +13 -26
  59. package/lib/components/box/box.config.d.ts +10 -12
  60. package/lib/components/box/index.d.ts +2 -1
  61. package/lib/components/dismissible-box/dismissible-box.style.d.ts +1 -2
  62. package/lib/components/drawer/drawer.style.d.ts +1 -2
  63. package/lib/components/duelling-picklist/picklist/picklist.style.d.ts +2 -3
  64. package/lib/components/flat-table/flat-table.style.d.ts +1 -2
  65. package/lib/components/form/form.component.js +2 -1
  66. package/lib/components/modal/modal.component.js +3 -62
  67. package/lib/components/select/select.style.js +1 -1
  68. package/lib/components/toast/toast.component.js +4 -17
  69. package/lib/hooks/__internal__/useModalManager/index.d.ts +1 -0
  70. package/lib/hooks/__internal__/useModalManager/index.js +15 -0
  71. package/lib/hooks/__internal__/useModalManager/package.json +6 -0
  72. package/lib/hooks/__internal__/useModalManager/useModalManager.d.ts +3 -0
  73. package/lib/hooks/__internal__/useModalManager/useModalManager.js +79 -0
  74. package/package.json +5 -1
  75. package/esm/components/action-popover/action-popover-divider/action-popover-divider.d.ts +0 -12
  76. package/esm/components/action-popover/action-popover-item/action-popover-item.d.ts +0 -26
  77. package/esm/components/action-popover/action-popover-menu/action-popover-menu.d.ts +0 -33
  78. package/esm/components/action-popover/action-popover-menu-button/action-popover-menu-button.d.ts +0 -13
  79. package/esm/components/action-popover/action-popover.d.ts +0 -39
  80. package/esm/components/box/box.d.ts +0 -31
  81. package/lib/components/action-popover/action-popover-divider/action-popover-divider.d.ts +0 -12
  82. package/lib/components/action-popover/action-popover-item/action-popover-item.d.ts +0 -26
  83. package/lib/components/action-popover/action-popover-menu/action-popover-menu.d.ts +0 -33
  84. package/lib/components/action-popover/action-popover-menu-button/action-popover-menu-button.d.ts +0 -13
  85. package/lib/components/action-popover/action-popover.d.ts +0 -39
  86. package/lib/components/box/box.d.ts +0 -31
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.StyledMenuItem = exports.MenuButtonOverrideWrapper = exports.SubMenuItemIcon = exports.MenuItemDivider = exports.MenuItemIcon = exports.StyledButtonIcon = exports.ButtonIcon = exports.MenuButton = exports.MenuItemFactory = exports.Menu = void 0;
6
+ exports.StyledMenuItem = exports.MenuButtonOverrideWrapper = exports.SubMenuItemIcon = exports.MenuItemDivider = exports.MenuItemIcon = exports.StyledButtonIcon = exports.ButtonIcon = exports.MenuButton = exports.Menu = void 0;
7
7
 
8
8
  var _styledComponents = _interopRequireWildcard(require("styled-components"));
9
9
 
@@ -40,13 +40,7 @@ exports.Menu = Menu;
40
40
  const StyledMenuItem = _styledComponents.default.button`
41
41
  text-decoration: none;
42
42
  background-color: var(--colorsActionMajorYang100);
43
- `;
44
- exports.StyledMenuItem = StyledMenuItem;
45
-
46
- const MenuItemFactory = button => (0, _styledComponents.default)(button)`
47
- cursor: ${({
48
- disabled
49
- }) => disabled ? "not-allowed" : "pointer"};
43
+ cursor: pointer;
50
44
  box-sizing: border-box;
51
45
  padding: 0 var(--spacing150);
52
46
  position: relative;
@@ -57,44 +51,43 @@ const MenuItemFactory = button => (0, _styledComponents.default)(button)`
57
51
  align-items: center;
58
52
  border: none;
59
53
  width: 100%;
60
- color: ${({
61
- disabled
62
- }) => disabled ? "var(--colorsUtilityYin030)" : "var(--colorsUtilityYin090)"};
54
+ color: var(--colorsUtilityYin090);
63
55
  font-size: 14px;
64
56
  font-weight: 700;
65
57
  justify-content: ${({
66
58
  horizontalAlignment
67
59
  }) => horizontalAlignment === "left" ? "flex-start" : "flex-end"};
68
- &:focus,
69
- &:hover {
70
- ${({
71
- disabled
72
- }) => !disabled && (0, _styledComponents.css)`
73
- background-color: var(--colorsUtilityMajor025);
74
- `}
75
- }
60
+
76
61
  &:focus {
77
62
  outline: var(--borderWidth300) solid var(--colorsSemanticFocus500);
78
63
  z-index: 1;
79
64
  }
65
+
80
66
  ${({
81
- disabled
82
- }) => !disabled && (0, _styledComponents.css)`
67
+ isDisabled
68
+ }) => isDisabled && (0, _styledComponents.css)`
69
+ color: var(--colorsUtilityYin030);
70
+ cursor: not-allowed;
71
+
83
72
  && ${_icon2.default} {
84
- cursor: pointer;
73
+ cursor: not-allowed;
74
+ color: var(--colorsUtilityYin030);
85
75
  }
86
76
  `}
77
+
87
78
  ${({
88
- disabled
89
- }) => disabled && (0, _styledComponents.css)`
79
+ isDisabled
80
+ }) => !isDisabled && (0, _styledComponents.css)`
81
+ &:focus,
82
+ &:hover {
83
+ background-color: var(--colorsUtilityMajor025);
84
+ }
90
85
  && ${_icon2.default} {
91
- cursor: not-allowed;
92
- color: var(--colorsUtilityYin030);
86
+ cursor: pointer;
93
87
  }
94
88
  `}
95
89
  `;
96
-
97
- exports.MenuItemFactory = MenuItemFactory;
90
+ exports.StyledMenuItem = StyledMenuItem;
98
91
  const MenuItemDivider = _styledComponents.default.div.attrs({
99
92
  "data-element": "action-popover-divider"
100
93
  })`
@@ -1,5 +1,9 @@
1
- export { default as ActionPopover } from "./action-popover";
2
- export { default as ActionPopoverMenu } from "./action-popover-menu/action-popover-menu";
3
- export { default as ActionPopoverItem } from "./action-popover-item/action-popover-item";
4
- export { default as ActionPopoverMenuButton } from "./action-popover-menu-button";
5
- export { default as ActionPopoverDivider } from "./action-popover-divider/action-popover-divider";
1
+ export { default as ActionPopover } from "./action-popover.component";
2
+ export type { ActionPopoverProps } from "./action-popover.component";
3
+ export { default as ActionPopoverMenu } from "./action-popover-menu/action-popover-menu.component";
4
+ export type { ActionPopoverMenuProps } from "./action-popover-menu/action-popover-menu.component";
5
+ export { default as ActionPopoverItem } from "./action-popover-item/action-popover-item.component";
6
+ export type { ActionPopoverItemProps } from "./action-popover-item/action-popover-item.component";
7
+ export { default as ActionPopoverMenuButton } from "./action-popover-menu-button/action-popover-menu-button.component";
8
+ export type { ActionPopoverMenuButtonProps } from "./action-popover-menu-button/action-popover-menu-button.component";
9
+ export { default as ActionPopoverDivider } from "./action-popover-divider/action-popover-divider.component";
@@ -1,2 +1,13 @@
1
+ import React from "react";
2
+ import { SpaceProps, LayoutProps, FlexboxProps, ColorProps } from "styled-system";
3
+ export declare type OverflowWrap = "break-word" | "anywhere";
4
+ export declare type ScrollVariant = "light" | "dark";
5
+ export interface BoxProps extends SpaceProps, LayoutProps, FlexboxProps, ColorProps {
6
+ as?: keyof JSX.IntrinsicElements | React.ComponentType<any>;
7
+ /** String to set Box content break strategy. Note "anywhere" is not supported in Safari */
8
+ overflowWrap?: OverflowWrap;
9
+ /** scroll styling attribute */
10
+ scrollVariant?: ScrollVariant;
11
+ }
12
+ declare const Box: import("styled-components").StyledComponent<"div", any, BoxProps, never>;
1
13
  export default Box;
2
- declare const Box: import("styled-components").StyledComponent<"div", any, {}, never>;
@@ -5,10 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- var _propTypes = _interopRequireDefault(require("@styled-system/prop-types"));
9
-
10
- var _propTypes2 = _interopRequireDefault(require("prop-types"));
11
-
12
8
  var _styledComponents = _interopRequireWildcard(require("styled-components"));
13
9
 
14
10
  var _styledSystem = require("styled-system");
@@ -19,17 +15,27 @@ var _color = _interopRequireDefault(require("../../style/utils/color"));
19
15
 
20
16
  var _box = _interopRequireDefault(require("./box.config"));
21
17
 
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
22
20
  function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
23
21
 
24
22
  function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
25
23
 
26
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
-
28
24
  const Box = _styledComponents.default.div`
29
25
  ${_styledSystem.space}
30
26
  ${_styledSystem.layout}
31
27
  ${_styledSystem.flexbox}
32
- ${_color.default}
28
+ ${({
29
+ color,
30
+ bg,
31
+ backgroundColor,
32
+ ...rest
33
+ }) => (0, _color.default)({
34
+ color,
35
+ bg,
36
+ backgroundColor,
37
+ ...rest
38
+ })}
33
39
 
34
40
  ${({
35
41
  overflowWrap
@@ -54,25 +60,6 @@ const Box = _styledComponents.default.div`
54
60
  }
55
61
  `}
56
62
  `;
57
- Box.propTypes = {
58
- /** Styled system box props */
59
- ..._propTypes.default.space,
60
-
61
- /** Styled system flex props */
62
- ..._propTypes.default.flexbox,
63
-
64
- /** Styled system layout props */
65
- ..._propTypes.default.layout,
66
-
67
- /** Styled system color props */
68
- ..._propTypes.default.color,
69
-
70
- /** String to set Box content break strategy. Note "anywhere" is not supported in Safari and IE11 */
71
- overflowWrap: _propTypes2.default.oneOf(["break-word", "anywhere"]),
72
-
73
- /** scroll styling attribute */
74
- scrollVariant: _propTypes2.default.oneOf(["light", "dark"])
75
- };
76
63
  Box.defaultProps = {
77
64
  theme: _base.default
78
65
  };
@@ -1,13 +1,11 @@
1
- declare namespace _default {
2
- namespace light {
3
- const thumb: string;
4
- const track: string;
5
- }
6
- namespace dark {
7
- const thumb_1: string;
8
- export { thumb_1 as thumb };
9
- const track_1: string;
10
- export { track_1 as track };
11
- }
12
- }
1
+ declare const _default: {
2
+ light: {
3
+ thumb: string;
4
+ track: string;
5
+ };
6
+ dark: {
7
+ thumb: string;
8
+ track: string;
9
+ };
10
+ };
13
11
  export default _default;
@@ -1 +1,2 @@
1
- export { default } from "./box";
1
+ export { default } from "./box.component";
2
+ export type { BoxProps } from "./box.component";
@@ -1,3 +1,2 @@
1
- declare var _default: import("styled-components").StyledComponent<typeof Box, any, {}, never>;
1
+ declare var _default: import("styled-components").StyledComponent<"div", any, import("../box").BoxProps, never>;
2
2
  export default _default;
3
- import Box from "../box";
@@ -2,9 +2,8 @@ export const StyledSidebarHeader: import("styled-components").StyledComponent<"d
2
2
  export const StyledDrawerWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
3
3
  export const StyledDrawerContent: import("styled-components").StyledComponent<"div", any, {}, never>;
4
4
  export const StyledDrawerChildren: import("styled-components").StyledComponent<"div", any, {}, never>;
5
- export const StyledDrawerSidebar: import("styled-components").StyledComponent<typeof Box, any, {}, never>;
5
+ export const StyledDrawerSidebar: import("styled-components").StyledComponent<"div", any, import("../box").BoxProps, never>;
6
6
  export const StyledSidebarTitle: import("styled-components").StyledComponent<"div", any, {}, never>;
7
7
  export const StyledButton: import("styled-components").StyledComponent<"button", any, {
8
8
  type: "button";
9
9
  }, "type">;
10
- import Box from "../box";
@@ -1,5 +1,4 @@
1
- export const StyledPicklist: import("styled-components").StyledComponent<typeof Box, any, {
2
- as: "ul";
1
+ export const StyledPicklist: import("styled-components").StyledComponent<"div", any, import("../../box").BoxProps & {
2
+ as: string;
3
3
  }, "as">;
4
4
  export const StyledEmptyContainer: import("styled-components").StyledComponent<"li", any, {}, never>;
5
- import Box from "../../box";
@@ -1,5 +1,4 @@
1
- export const StyledFlatTableWrapper: import("styled-components").StyledComponent<typeof Box, any, {}, never>;
1
+ export const StyledFlatTableWrapper: import("styled-components").StyledComponent<"div", any, import("../box").BoxProps, never>;
2
2
  export const StyledFlatTable: import("styled-components").StyledComponent<"table", any, {}, never>;
3
3
  export const StyledFlatTableFooter: import("styled-components").StyledComponent<"div", any, {}, never>;
4
4
  export const StyledTableContainer: import("styled-components").StyledComponent<"div", any, {}, never>;
5
- import Box from "../box";
@@ -45,6 +45,7 @@ const Form = ({
45
45
  } = (0, _react.useContext)(_sidebar.SidebarContext);
46
46
  const formRef = (0, _react.useRef)();
47
47
  const formFooterRef = (0, _react.useRef)();
48
+ const renderFooter = !!(saveButton || leftSideButtons || rightSideButtons || errorCount || warningCount);
48
49
  return /*#__PURE__*/_react.default.createElement(_form.StyledForm, _extends({
49
50
  ref: formRef,
50
51
  stickyFooter: stickyFooter,
@@ -58,7 +59,7 @@ const Form = ({
58
59
  "data-element": "form-content",
59
60
  stickyFooter: stickyFooter,
60
61
  className: stickyFooter ? "sticky" : ""
61
- }, children), /*#__PURE__*/_react.default.createElement(_form.StyledFormFooter, {
62
+ }, children), renderFooter && /*#__PURE__*/_react.default.createElement(_form.StyledFormFooter, {
62
63
  "data-element": "form-footer",
63
64
  className: stickyFooter ? "sticky" : "",
64
65
  ref: formFooterRef,
@@ -17,7 +17,7 @@ var _portal = _interopRequireDefault(require("../portal"));
17
17
 
18
18
  var _events = _interopRequireDefault(require("../../__internal__/utils/helpers/events"));
19
19
 
20
- var _modalManager = _interopRequireDefault(require("./__internal__/modal-manager"));
20
+ var _useModalManager = _interopRequireDefault(require("../../hooks/__internal__/useModalManager"));
21
21
 
22
22
  var _modal = require("./modal.style");
23
23
 
@@ -46,8 +46,6 @@ const Modal = ({
46
46
  const ref = (0, _react.useRef)();
47
47
  const backgroundNodeRef = (0, _react.useRef)();
48
48
  const contentNodeRef = (0, _react.useRef)();
49
- const listenerAdded = (0, _react.useRef)(false);
50
- const modalRegistered = (0, _react.useRef)(false);
51
49
  const [isAnimationComplete, setAnimationComplete] = (0, _react.useState)(false);
52
50
  const [triggerRefocusFlag, setTriggerRefocusFlag] = (0, _react.useState)(false);
53
51
  const {
@@ -73,69 +71,12 @@ const Modal = ({
73
71
  };
74
72
  }, [allowScroll, enableBackgroundUI]);
75
73
  const closeModal = (0, _react.useCallback)(ev => {
76
- const isTopmost = _modalManager.default.isTopmost(ref.current);
77
-
78
- if (onCancel && !disableClose && !disableEscKey && _events.default.isEscKey(ev) && isTopmost) {
74
+ if (onCancel && !disableClose && !disableEscKey && _events.default.isEscKey(ev)) {
79
75
  ev.stopImmediatePropagation();
80
76
  onCancel(ev);
81
77
  }
82
78
  }, [disableClose, disableEscKey, onCancel]);
83
- const addListener = (0, _react.useCallback)(() => {
84
- /* istanbul ignore else */
85
- if (!listenerAdded.current) {
86
- document.addEventListener("keyup", closeModal);
87
- listenerAdded.current = true;
88
- }
89
- }, [closeModal]);
90
- const removeListener = (0, _react.useCallback)(() => {
91
- if (listenerAdded.current) {
92
- document.removeEventListener("keyup", closeModal);
93
- listenerAdded.current = false;
94
- }
95
- }, [closeModal]);
96
- (0, _react.useEffect)(() => {
97
- if (open) {
98
- addListener();
99
- }
100
-
101
- if (!open) {
102
- removeListener();
103
- }
104
- }, [addListener, open, removeListener]);
105
- (0, _react.useEffect)(() => {
106
- return () => {
107
- removeListener();
108
- };
109
- }, [removeListener]);
110
- const registerModal = (0, _react.useCallback)(() => {
111
- /* istanbul ignore else */
112
- if (!modalRegistered.current) {
113
- _modalManager.default.addModal(ref.current, setTriggerRefocusFlag);
114
-
115
- modalRegistered.current = true;
116
- }
117
- }, []);
118
- const unregisterModal = (0, _react.useCallback)(() => {
119
- if (modalRegistered.current) {
120
- _modalManager.default.removeModal(ref.current);
121
-
122
- modalRegistered.current = false;
123
- }
124
- }, []);
125
- (0, _react.useEffect)(() => {
126
- if (open) {
127
- registerModal();
128
- }
129
-
130
- if (!open) {
131
- unregisterModal();
132
- }
133
- }, [open, registerModal, unregisterModal]);
134
- (0, _react.useEffect)(() => {
135
- return () => {
136
- unregisterModal();
137
- };
138
- }, [unregisterModal]);
79
+ (0, _useModalManager.default)(open, closeModal, ref, setTriggerRefocusFlag);
139
80
  let background;
140
81
  let content;
141
82
 
@@ -37,7 +37,7 @@ const StyledSelect = _styledComponents.default.div`
37
37
  position: relative;
38
38
 
39
39
  ${_input.default} {
40
- cursor: "text";
40
+ cursor: text;
41
41
 
42
42
  ${disabled && (0, _styledComponents.css)`
43
43
  cursor: not-allowed;
@@ -21,12 +21,12 @@ var _toast = require("./toast.style");
21
21
 
22
22
  var _iconButton = _interopRequireDefault(require("../icon-button"));
23
23
 
24
- var _modalManager = _interopRequireDefault(require("../modal/__internal__/modal-manager"));
25
-
26
24
  var _events = _interopRequireDefault(require("../../__internal__/utils/helpers/events"));
27
25
 
28
26
  var _useLocale = _interopRequireDefault(require("../../hooks/__internal__/useLocale"));
29
27
 
28
+ var _useModalManager = _interopRequireDefault(require("../../hooks/__internal__/useModalManager"));
29
+
30
30
  var _logger = _interopRequireDefault(require("../../__internal__/utils/logger"));
31
31
 
32
32
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -68,25 +68,12 @@ const Toast = ({
68
68
  return (0, _classnames.default)(className);
69
69
  }, [className]);
70
70
  const dismissToast = (0, _react.useCallback)(ev => {
71
- const isTopmost = _modalManager.default.isTopmost(toastRef.current);
72
-
73
- if (onDismiss && _events.default.isEscKey(ev) && isTopmost) {
71
+ if (onDismiss && _events.default.isEscKey(ev)) {
74
72
  ev.stopImmediatePropagation();
75
73
  onDismiss(ev);
76
74
  }
77
75
  }, [onDismiss]);
78
- (0, _react.useEffect)(() => {
79
- const currentElement = toastRef.current;
80
-
81
- _modalManager.default.addModal(currentElement);
82
-
83
- document.addEventListener("keyup", dismissToast);
84
- return () => {
85
- _modalManager.default.removeModal(currentElement);
86
-
87
- document.removeEventListener("keyup", dismissToast);
88
- };
89
- }, [dismissToast]);
76
+ (0, _useModalManager.default)(open, dismissToast, toastRef);
90
77
  (0, _react.useEffect)(() => {
91
78
  clearTimeout(timer.current);
92
79
 
@@ -0,0 +1 @@
1
+ export { default } from "./useModalManager";
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "default", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _useModalManager.default;
10
+ }
11
+ });
12
+
13
+ var _useModalManager = _interopRequireDefault(require("./useModalManager"));
14
+
15
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -0,0 +1,6 @@
1
+ {
2
+ "sideEffects": false,
3
+ "module": "../../../../esm/hooks/__internal__/useModalManager/index.js",
4
+ "main": "./index.js",
5
+ "types": "./index.d.ts"
6
+ }
@@ -0,0 +1,3 @@
1
+ import React from "react";
2
+ declare const useModalManager: (open: boolean, closeModal: (e: KeyboardEvent) => void, modalRef: React.RefObject<HTMLElement>, setTriggerRefocusFlag?: ((flag: boolean) => void) | undefined) => void;
3
+ export default useModalManager;
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _react = require("react");
9
+
10
+ var _modalManager = _interopRequireDefault(require("../../../components/modal/__internal__/modal-manager"));
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ const useModalManager = (open, closeModal, modalRef, setTriggerRefocusFlag) => {
15
+ const listenerAdded = (0, _react.useRef)(false);
16
+ const modalRegistered = (0, _react.useRef)(false);
17
+ const handleClose = (0, _react.useCallback)(ev => {
18
+ const isTopmost = _modalManager.default.isTopmost(modalRef.current);
19
+
20
+ if (isTopmost) {
21
+ closeModal(ev);
22
+ }
23
+ }, [modalRef, closeModal]);
24
+ const addListener = (0, _react.useCallback)(() => {
25
+ /* istanbul ignore else */
26
+ if (!listenerAdded.current) {
27
+ document.addEventListener("keyup", handleClose);
28
+ listenerAdded.current = true;
29
+ }
30
+ }, [handleClose]);
31
+ const removeListener = (0, _react.useCallback)(() => {
32
+ if (listenerAdded.current) {
33
+ document.removeEventListener("keyup", handleClose);
34
+ listenerAdded.current = false;
35
+ }
36
+ }, [handleClose]);
37
+ (0, _react.useEffect)(() => {
38
+ if (open) {
39
+ addListener();
40
+ } else {
41
+ removeListener();
42
+ }
43
+ }, [addListener, open, removeListener]);
44
+ (0, _react.useEffect)(() => {
45
+ return () => {
46
+ removeListener();
47
+ };
48
+ }, [removeListener]);
49
+ const registerModal = (0, _react.useCallback)(() => {
50
+ /* istanbul ignore else */
51
+ if (!modalRegistered.current) {
52
+ _modalManager.default.addModal(modalRef.current, setTriggerRefocusFlag);
53
+
54
+ modalRegistered.current = true;
55
+ }
56
+ }, [modalRef, setTriggerRefocusFlag]);
57
+ const unregisterModal = (0, _react.useCallback)(() => {
58
+ if (modalRegistered.current) {
59
+ _modalManager.default.removeModal(modalRef.current);
60
+
61
+ modalRegistered.current = false;
62
+ }
63
+ }, [modalRef]);
64
+ (0, _react.useEffect)(() => {
65
+ if (open) {
66
+ registerModal();
67
+ } else {
68
+ unregisterModal();
69
+ }
70
+ }, [open, registerModal, unregisterModal]);
71
+ (0, _react.useEffect)(() => {
72
+ return () => {
73
+ unregisterModal();
74
+ };
75
+ }, [unregisterModal]);
76
+ };
77
+
78
+ var _default = useModalManager;
79
+ exports.default = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-react",
3
- "version": "106.6.0",
3
+ "version": "106.6.3",
4
4
  "description": "A library of reusable React components for easily building user interfaces.",
5
5
  "engineStrict": true,
6
6
  "engines": {
@@ -98,6 +98,7 @@
98
98
  "@types/react": "16.9.56",
99
99
  "@types/react-dom": "16.9.8",
100
100
  "@types/react-test-renderer": "^17.0.1",
101
+ "@types/sprintf-js": "^1.1.2",
101
102
  "@types/styled-components": "^5.1.9",
102
103
  "@types/uuid": "^8.3.3",
103
104
  "@typescript-eslint/eslint-plugin": "^5.4.0",
@@ -112,6 +113,7 @@
112
113
  "conventional-changelog-conventionalcommits": "^4.5.0",
113
114
  "core-js": "^3.20.3",
114
115
  "cross-env": "^5.2.0",
116
+ "css-loader": "4.0.0",
115
117
  "cypress": "^9.6.0",
116
118
  "cypress-axe": "^0.14.0",
117
119
  "cypress-cucumber-preprocessor": "^4.3.1",
@@ -138,6 +140,7 @@
138
140
  "eslint-plugin-react-hooks": "^4.2.0",
139
141
  "events": "~1.1.1",
140
142
  "fast-glob": "^3.2.7",
143
+ "file-loader": "^6.2.0",
141
144
  "fs-extra": "^10.0.0",
142
145
  "husky": "^4.3.6",
143
146
  "jest": "^26.6.3",
@@ -159,6 +162,7 @@
159
162
  "ts-node": "^10.4.0",
160
163
  "typescript": "^4.6.2",
161
164
  "typescript-to-proptypes": "^2.2.1",
165
+ "url-loader": "^4.1.1",
162
166
  "uuid": "^8.3.2",
163
167
  "webpack-dev-server": "^4.0.0"
164
168
  },
@@ -1,12 +0,0 @@
1
- import { StyledComponentProps } from "styled-components";
2
-
3
- declare function ActionPopoverDivider(
4
- attrs: StyledComponentProps<
5
- "div",
6
- Record<string, unknown>,
7
- Record<string, unknown>,
8
- ""
9
- >
10
- ): JSX.Element;
11
-
12
- export default ActionPopoverDivider;
@@ -1,26 +0,0 @@
1
- import { IconType } from "components/icon/icon";
2
- import * as React from "react";
3
- import { ActionPopoverMenuProps } from "../action-popover-menu/action-popover-menu";
4
-
5
- export interface ActionPopoverItemProps {
6
- /** The text label to display for this Item */
7
- children: string;
8
- /** Flag to indicate if item is disabled */
9
- disabled?: boolean;
10
- /** allows to provide download prop that works dependent with href */
11
- download?: boolean;
12
- /** allows to provide href prop */
13
- href?: string;
14
- /** The name of the icon to display next to the label */
15
- icon?: IconType;
16
- /** Callback to run when item is clicked */
17
- onClick?: (ev: React.MouseEvent<HTMLElement>) => void;
18
- /** Submenu component for item */
19
- submenu?: React.ReactElement<ActionPopoverMenuProps>;
20
- }
21
-
22
- declare function MenuItem(props: ActionPopoverItemProps): JSX.Element;
23
- declare function ActionPopoverItem(props: ActionPopoverItemProps): JSX.Element;
24
-
25
- export { MenuItem };
26
- export default ActionPopoverItem;
@@ -1,33 +0,0 @@
1
- import * as React from "react";
2
- import ActionPopoverDivider from "../action-popover-divider/action-popover-divider";
3
- import { ActionPopoverItemProps } from "../action-popover-item/action-popover-item";
4
-
5
- type ActionPopoverChild =
6
- | React.ReactElement<ActionPopoverItemProps>
7
- | typeof ActionPopoverDivider
8
- | boolean
9
- | null
10
- | undefined;
11
-
12
- export interface ActionPopoverMenuProps {
13
- /** Children for the menu */
14
- children?: ActionPopoverChild | ActionPopoverChild[];
15
- /** Index to control which item is focused */
16
- focusIndex?: number;
17
- /** Flag to indicate whether a menu should open */
18
- isOpen?: boolean;
19
- /** A unique ID for the menu */
20
- menuID?: string;
21
- /** Callback to set the index of the focused item */
22
- setFocusIndex?: (args: number) => any;
23
- /** Callback to set the isOpen flag */
24
- setOpen?: (args: boolean) => any;
25
- /** Unique ID for the menu's parent */
26
- parentID?: string;
27
- }
28
-
29
- declare function ActionPopoverMenu(
30
- props: ActionPopoverMenuProps & React.RefAttributes<HTMLDivElement>
31
- ): JSX.Element;
32
-
33
- export default ActionPopoverMenu;
@@ -1,13 +0,0 @@
1
- export interface ActionPopoverMenuButtonProps {
2
- children?: string;
3
- buttonType?: string;
4
- iconType?: string;
5
- iconPosition?: string;
6
- size?: string;
7
- }
8
-
9
- declare function ActionPopoverMenuButton(
10
- props: ActionPopoverMenuButtonProps
11
- ): JSX.Element;
12
-
13
- export default ActionPopoverMenuButton;