carbon-react 106.6.2 → 106.6.5
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.
- package/esm/__spec_helper__/expect.d.ts +8 -1
- package/esm/__spec_helper__/expect.js +1 -5
- package/esm/__spec_helper__/test-utils.d.ts +71 -33
- package/esm/__spec_helper__/test-utils.js +63 -65
- package/esm/components/action-popover/action-popover-context.d.ts +7 -2
- package/esm/components/action-popover/action-popover-context.js +1 -1
- package/esm/components/action-popover/action-popover-divider/action-popover-divider.component.d.ts +1 -1
- package/esm/components/action-popover/action-popover-item/action-popover-item.component.d.ts +28 -41
- package/esm/components/action-popover/action-popover-item/action-popover-item.component.js +99 -118
- package/esm/components/action-popover/action-popover-menu/action-popover-menu.component.d.ts +35 -2
- package/esm/components/action-popover/action-popover-menu/action-popover-menu.component.js +42 -53
- package/esm/components/action-popover/action-popover-menu-button/action-popover-menu-button.component.d.ts +20 -18
- package/esm/components/action-popover/action-popover-menu-button/action-popover-menu-button.component.js +13 -5
- package/esm/components/action-popover/action-popover-test.stories.js +76 -0
- package/esm/components/action-popover/action-popover.component.d.ts +30 -53
- package/esm/components/action-popover/action-popover.component.js +205 -67
- package/esm/components/action-popover/action-popover.style.d.ts +17 -11
- package/esm/components/action-popover/action-popover.style.js +20 -26
- package/esm/components/action-popover/index.d.ts +9 -5
- package/esm/components/button-bar/button-bar-test.stories.js +122 -0
- package/esm/components/button-bar/button-bar.component.d.ts +12 -15
- package/esm/components/button-bar/button-bar.component.js +331 -33
- package/esm/components/button-bar/button-bar.config.d.ts +2 -2
- package/esm/components/button-bar/button-bar.style.d.ts +4 -4
- package/esm/components/button-bar/button-bar.style.js +18 -33
- package/esm/components/button-bar/index.d.ts +2 -1
- package/esm/components/heading/heading.component.d.ts +7 -47
- package/esm/components/heading/heading.component.js +1 -48
- package/esm/components/link/link.component.js +1 -5
- package/esm/components/menu/__internal__/spec-helper/index.js +2 -1
- package/esm/components/menu/__internal__/submenu/submenu.component.js +21 -4
- package/esm/components/menu/menu.component.js +2 -1
- package/esm/components/menu/scrollable-block/scrollable-block.component.js +4 -2
- package/esm/components/modal/modal.component.js +3 -60
- package/esm/components/toast/toast.component.js +3 -13
- package/esm/hooks/__internal__/useModalManager/index.d.ts +1 -0
- package/esm/hooks/__internal__/useModalManager/index.js +1 -0
- package/esm/hooks/__internal__/useModalManager/useModalManager.d.ts +3 -0
- package/esm/hooks/__internal__/useModalManager/useModalManager.js +66 -0
- package/lib/__spec_helper__/expect.d.ts +8 -1
- package/lib/__spec_helper__/expect.js +2 -4
- package/lib/__spec_helper__/test-utils.d.ts +71 -33
- package/lib/__spec_helper__/test-utils.js +63 -65
- package/lib/components/action-popover/action-popover-context.d.ts +7 -2
- package/lib/components/action-popover/action-popover-context.js +1 -1
- package/lib/components/action-popover/action-popover-divider/action-popover-divider.component.d.ts +1 -1
- package/lib/components/action-popover/action-popover-item/action-popover-item.component.d.ts +28 -41
- package/lib/components/action-popover/action-popover-item/action-popover-item.component.js +100 -119
- package/lib/components/action-popover/action-popover-menu/action-popover-menu.component.d.ts +35 -2
- package/lib/components/action-popover/action-popover-menu/action-popover-menu.component.js +44 -55
- package/lib/components/action-popover/action-popover-menu-button/action-popover-menu-button.component.d.ts +20 -18
- package/lib/components/action-popover/action-popover-menu-button/action-popover-menu-button.component.js +13 -5
- package/lib/components/action-popover/action-popover-test.stories.js +95 -0
- package/lib/components/action-popover/action-popover.component.d.ts +30 -53
- package/lib/components/action-popover/action-popover.component.js +206 -71
- package/lib/components/action-popover/action-popover.style.d.ts +17 -11
- package/lib/components/action-popover/action-popover.style.js +21 -28
- package/lib/components/action-popover/index.d.ts +9 -5
- package/lib/components/button-bar/button-bar-test.stories.js +145 -0
- package/lib/components/button-bar/button-bar.component.d.ts +12 -15
- package/lib/components/button-bar/button-bar.component.js +336 -35
- package/lib/components/button-bar/button-bar.config.d.ts +2 -2
- package/lib/components/button-bar/button-bar.style.d.ts +4 -4
- package/lib/components/button-bar/button-bar.style.js +18 -35
- package/lib/components/button-bar/index.d.ts +2 -1
- package/lib/components/heading/heading.component.d.ts +7 -47
- package/lib/components/heading/heading.component.js +1 -48
- package/lib/components/link/link.component.js +1 -5
- package/lib/components/menu/__internal__/spec-helper/index.js +2 -1
- package/lib/components/menu/__internal__/submenu/submenu.component.js +21 -4
- package/lib/components/menu/menu.component.js +2 -1
- package/lib/components/menu/scrollable-block/scrollable-block.component.js +4 -2
- package/lib/components/modal/modal.component.js +3 -62
- package/lib/components/toast/toast.component.js +4 -17
- package/lib/hooks/__internal__/useModalManager/index.d.ts +1 -0
- package/lib/hooks/__internal__/useModalManager/index.js +15 -0
- package/lib/hooks/__internal__/useModalManager/package.json +6 -0
- package/lib/hooks/__internal__/useModalManager/useModalManager.d.ts +3 -0
- package/lib/hooks/__internal__/useModalManager/useModalManager.js +79 -0
- package/package.json +5 -1
- package/esm/components/action-popover/action-popover-divider/action-popover-divider.d.ts +0 -12
- package/esm/components/action-popover/action-popover-item/action-popover-item.d.ts +0 -26
- package/esm/components/action-popover/action-popover-menu/action-popover-menu.d.ts +0 -33
- package/esm/components/action-popover/action-popover-menu-button/action-popover-menu-button.d.ts +0 -13
- package/esm/components/action-popover/action-popover.d.ts +0 -39
- package/esm/components/button-bar/button-bar.d.ts +0 -24
- package/lib/components/action-popover/action-popover-divider/action-popover-divider.d.ts +0 -12
- package/lib/components/action-popover/action-popover-item/action-popover-item.d.ts +0 -26
- package/lib/components/action-popover/action-popover-menu/action-popover-menu.d.ts +0 -33
- package/lib/components/action-popover/action-popover-menu-button/action-popover-menu-button.d.ts +0 -13
- package/lib/components/action-popover/action-popover.d.ts +0 -39
- package/lib/components/button-bar/button-bar.d.ts +0 -24
|
@@ -2,53 +2,13 @@ export default Heading;
|
|
|
2
2
|
declare class Heading extends React.Component<any, any, any> {
|
|
3
3
|
constructor(props: any);
|
|
4
4
|
constructor(props: any, context: any);
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Returns the back button.
|
|
14
|
-
*
|
|
15
|
-
* @method back
|
|
16
|
-
* @return {Object} JSX
|
|
17
|
-
*/
|
|
18
|
-
get back(): Object;
|
|
19
|
-
/**
|
|
20
|
-
* Returns the subheader.
|
|
21
|
-
*
|
|
22
|
-
* @method subheader
|
|
23
|
-
* @return {Object} JSX
|
|
24
|
-
*/
|
|
25
|
-
get subheader(): Object;
|
|
26
|
-
/**
|
|
27
|
-
* Returns the separator if enabled and needed.
|
|
28
|
-
*
|
|
29
|
-
* @method separator
|
|
30
|
-
* @return {Object} JSX
|
|
31
|
-
*/
|
|
32
|
-
get separator(): Object;
|
|
33
|
-
/**
|
|
34
|
-
* Returns the separator if enabled and needed.
|
|
35
|
-
*
|
|
36
|
-
* @method divider
|
|
37
|
-
* @return {Object} JSX
|
|
38
|
-
*/
|
|
39
|
-
get divider(): Object;
|
|
40
|
-
/**
|
|
41
|
-
* Returns pills if provided
|
|
42
|
-
*
|
|
43
|
-
* @method pills
|
|
44
|
-
* @return {Object} JSX
|
|
45
|
-
*/
|
|
46
|
-
get pills(): Object;
|
|
47
|
-
/**
|
|
48
|
-
* @method render
|
|
49
|
-
* @return {Object} JSX
|
|
50
|
-
*/
|
|
51
|
-
render(): Object;
|
|
5
|
+
get help(): JSX.Element | null;
|
|
6
|
+
get back(): JSX.Element | null;
|
|
7
|
+
get subheader(): JSX.Element | null;
|
|
8
|
+
get separator(): JSX.Element | null;
|
|
9
|
+
get divider(): JSX.Element | null;
|
|
10
|
+
get pills(): JSX.Element | null;
|
|
11
|
+
render(): JSX.Element | null;
|
|
52
12
|
}
|
|
53
13
|
declare namespace Heading {
|
|
54
14
|
const propTypes: {
|
|
@@ -41,14 +41,7 @@ let Heading = /*#__PURE__*/function (_React$Component) {
|
|
|
41
41
|
|
|
42
42
|
_createClass(Heading, [{
|
|
43
43
|
key: "help",
|
|
44
|
-
get:
|
|
45
|
-
/**
|
|
46
|
-
* Returns the help component.
|
|
47
|
-
*
|
|
48
|
-
* @method help
|
|
49
|
-
* @return {Object} JSX
|
|
50
|
-
*/
|
|
51
|
-
function () {
|
|
44
|
+
get: function () {
|
|
52
45
|
if (!this.props.help && !this.props.helpLink) {
|
|
53
46
|
return null;
|
|
54
47
|
}
|
|
@@ -60,13 +53,6 @@ let Heading = /*#__PURE__*/function (_React$Component) {
|
|
|
60
53
|
ariaLabel: this.props.helpAriaLabel
|
|
61
54
|
}, this.props.help);
|
|
62
55
|
}
|
|
63
|
-
/**
|
|
64
|
-
* Returns the back button.
|
|
65
|
-
*
|
|
66
|
-
* @method back
|
|
67
|
-
* @return {Object} JSX
|
|
68
|
-
*/
|
|
69
|
-
|
|
70
56
|
}, {
|
|
71
57
|
key: "back",
|
|
72
58
|
get: function () {
|
|
@@ -95,13 +81,6 @@ let Heading = /*#__PURE__*/function (_React$Component) {
|
|
|
95
81
|
divider: this.props.divider
|
|
96
82
|
}));
|
|
97
83
|
}
|
|
98
|
-
/**
|
|
99
|
-
* Returns the subheader.
|
|
100
|
-
*
|
|
101
|
-
* @method subheader
|
|
102
|
-
* @return {Object} JSX
|
|
103
|
-
*/
|
|
104
|
-
|
|
105
84
|
}, {
|
|
106
85
|
key: "subheader",
|
|
107
86
|
get: function () {
|
|
@@ -116,25 +95,11 @@ let Heading = /*#__PURE__*/function (_React$Component) {
|
|
|
116
95
|
hasSeparator: this.props.separator
|
|
117
96
|
}, this.props.subheader);
|
|
118
97
|
}
|
|
119
|
-
/**
|
|
120
|
-
* Returns the separator if enabled and needed.
|
|
121
|
-
*
|
|
122
|
-
* @method separator
|
|
123
|
-
* @return {Object} JSX
|
|
124
|
-
*/
|
|
125
|
-
|
|
126
98
|
}, {
|
|
127
99
|
key: "separator",
|
|
128
100
|
get: function () {
|
|
129
101
|
return this.props.separator ? /*#__PURE__*/React.createElement(StyledSeparator, null) : null;
|
|
130
102
|
}
|
|
131
|
-
/**
|
|
132
|
-
* Returns the separator if enabled and needed.
|
|
133
|
-
*
|
|
134
|
-
* @method divider
|
|
135
|
-
* @return {Object} JSX
|
|
136
|
-
*/
|
|
137
|
-
|
|
138
103
|
}, {
|
|
139
104
|
key: "divider",
|
|
140
105
|
get: function () {
|
|
@@ -142,13 +107,6 @@ let Heading = /*#__PURE__*/function (_React$Component) {
|
|
|
142
107
|
"data-element": "divider"
|
|
143
108
|
}) : null;
|
|
144
109
|
}
|
|
145
|
-
/**
|
|
146
|
-
* Returns pills if provided
|
|
147
|
-
*
|
|
148
|
-
* @method pills
|
|
149
|
-
* @return {Object} JSX
|
|
150
|
-
*/
|
|
151
|
-
|
|
152
110
|
}, {
|
|
153
111
|
key: "pills",
|
|
154
112
|
get: function () {
|
|
@@ -156,11 +114,6 @@ let Heading = /*#__PURE__*/function (_React$Component) {
|
|
|
156
114
|
"data-element": "pills"
|
|
157
115
|
}, this.props.pills) : null;
|
|
158
116
|
}
|
|
159
|
-
/**
|
|
160
|
-
* @method render
|
|
161
|
-
* @return {Object} JSX
|
|
162
|
-
*/
|
|
163
|
-
|
|
164
117
|
}, {
|
|
165
118
|
key: "render",
|
|
166
119
|
value: function render() {
|
|
@@ -86,11 +86,7 @@ const Link = /*#__PURE__*/React.forwardRef(({
|
|
|
86
86
|
type = "button";
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
return /*#__PURE__*/React.createElement(type,
|
|
90
|
-
...(type === "button" && {
|
|
91
|
-
role: "link"
|
|
92
|
-
})
|
|
93
|
-
}, /*#__PURE__*/React.createElement(React.Fragment, null, renderLinkIcon(), /*#__PURE__*/React.createElement(StyledContent, null, isSkipLink ? l.link.skipLinkLabel() : children), renderLinkIcon("right")));
|
|
89
|
+
return /*#__PURE__*/React.createElement(type, componentProps, /*#__PURE__*/React.createElement(React.Fragment, null, renderLinkIcon(), /*#__PURE__*/React.createElement(StyledContent, null, isSkipLink ? l.link.skipLinkLabel() : children), renderLinkIcon("right")));
|
|
94
90
|
};
|
|
95
91
|
|
|
96
92
|
return /*#__PURE__*/React.createElement(StyledLink, _extends({
|
|
@@ -9,7 +9,8 @@ const events = {
|
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
const openSubmenu = wrapper => {
|
|
12
|
-
const
|
|
12
|
+
const menuWrapper = wrapper.find('[data-component="submenu-wrapper"]');
|
|
13
|
+
const menuItem = menuWrapper.exists("a") ? menuWrapper.find("a") : menuWrapper.find("button");
|
|
13
14
|
menuItem.getDOMNode().focus();
|
|
14
15
|
act(() => {
|
|
15
16
|
wrapper.find(StyledMenuItemWrapper).at(0).props().onKeyDown(events.space);
|
|
@@ -27,6 +27,7 @@ const Submenu = /*#__PURE__*/React.forwardRef(({
|
|
|
27
27
|
asPassiveItem,
|
|
28
28
|
onSubmenuOpen,
|
|
29
29
|
onSubmenuClose,
|
|
30
|
+
onClick,
|
|
30
31
|
...rest
|
|
31
32
|
}, ref) => {
|
|
32
33
|
const [blockDoubleFocus, setBlockDoubleFocus] = useState(false);
|
|
@@ -188,6 +189,17 @@ const Submenu = /*#__PURE__*/React.forwardRef(({
|
|
|
188
189
|
closeSubmenu();
|
|
189
190
|
}
|
|
190
191
|
}, [closeSubmenu]);
|
|
192
|
+
|
|
193
|
+
const handleClick = event => {
|
|
194
|
+
if (clickToOpen) {
|
|
195
|
+
openSubmenu();
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (onClick) {
|
|
199
|
+
onClick(event);
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
|
|
191
203
|
useEffect(() => {
|
|
192
204
|
if (characterString !== "") {
|
|
193
205
|
const nextIndex = characterNavigation(characterString, React.Children.toArray(formattedChildren), submenuFocusIndex);
|
|
@@ -241,7 +253,6 @@ const Submenu = /*#__PURE__*/React.forwardRef(({
|
|
|
241
253
|
"data-component": "submenu-wrapper",
|
|
242
254
|
onMouseOver: !clickToOpen ? () => openSubmenu() : undefined,
|
|
243
255
|
onMouseLeave: () => closeSubmenu(),
|
|
244
|
-
onClick: clickToOpen ? () => openSubmenu() : undefined,
|
|
245
256
|
ref: submenuRef,
|
|
246
257
|
isSubmenuOpen: submenuOpen
|
|
247
258
|
}, /*#__PURE__*/React.createElement(StyledMenuItemWrapper, _extends({}, rest, {
|
|
@@ -256,14 +267,17 @@ const Submenu = /*#__PURE__*/React.forwardRef(({
|
|
|
256
267
|
hasSubmenu: true,
|
|
257
268
|
showDropdownArrow: showDropdownArrow,
|
|
258
269
|
onKeyDown: handleKeyDown,
|
|
270
|
+
onClick: handleClick,
|
|
259
271
|
clickToOpen: clickToOpen,
|
|
260
272
|
href: href,
|
|
261
|
-
maxWidth: maxWidth
|
|
273
|
+
maxWidth: maxWidth,
|
|
274
|
+
"aria-expanded": submenuOpen
|
|
262
275
|
}), title), submenuOpen && /*#__PURE__*/React.createElement(StyledSubmenu, {
|
|
263
276
|
"data-component": "submenu",
|
|
264
277
|
submenuDirection: submenuDirection,
|
|
265
278
|
variant: variant,
|
|
266
|
-
menuType: menuContext.menuType
|
|
279
|
+
menuType: menuContext.menuType,
|
|
280
|
+
role: "list"
|
|
267
281
|
}, React.Children.map(children, (child, index) => /*#__PURE__*/React.createElement(SubmenuContext.Provider, {
|
|
268
282
|
value: {
|
|
269
283
|
isFocused: !blockDoubleFocus && submenuFocusIndex === index,
|
|
@@ -320,6 +334,9 @@ Submenu.propTypes = {
|
|
|
320
334
|
onSubmenuOpen: PropTypes.func,
|
|
321
335
|
|
|
322
336
|
/** Callback triggered when submenu closes. Only valid with submenu prop */
|
|
323
|
-
onSubmenuClose: PropTypes.func
|
|
337
|
+
onSubmenuClose: PropTypes.func,
|
|
338
|
+
|
|
339
|
+
/** Callback triggered when the top-level menu item is clicked */
|
|
340
|
+
onClick: PropTypes.func
|
|
324
341
|
};
|
|
325
342
|
export default Submenu;
|
|
@@ -36,7 +36,8 @@ const Menu = ({
|
|
|
36
36
|
"data-component": "menu",
|
|
37
37
|
menuType: menuType
|
|
38
38
|
}, rest, {
|
|
39
|
-
ref: ref
|
|
39
|
+
ref: ref,
|
|
40
|
+
role: "list"
|
|
40
41
|
}), React.Children.map(children, (child, index) => {
|
|
41
42
|
const isFocused = focusedItemIndex === index;
|
|
42
43
|
return /*#__PURE__*/React.createElement(MenuContext.Provider, {
|
|
@@ -29,12 +29,14 @@ const ScrollableBlock = ({
|
|
|
29
29
|
return /*#__PURE__*/React.createElement(StyledScrollableBlock, _extends({
|
|
30
30
|
"data-component": "submenu-scrollable-block",
|
|
31
31
|
menuType: menuContext.menuType,
|
|
32
|
-
variant: variant
|
|
32
|
+
variant: variant,
|
|
33
|
+
role: "presentation"
|
|
33
34
|
}, rest), /*#__PURE__*/React.createElement(Box, {
|
|
34
35
|
overflowY: "scroll",
|
|
35
36
|
scrollVariant: scrollVariants[menuContext.menuType],
|
|
36
37
|
height: height,
|
|
37
|
-
p: 0
|
|
38
|
+
p: 0,
|
|
39
|
+
role: "presentation"
|
|
38
40
|
}, React.Children.map(children, (child, index) => {
|
|
39
41
|
let isFocused = false;
|
|
40
42
|
const blockItemFocused = focusIndex >= blockIndex;
|
|
@@ -6,7 +6,7 @@ import { TransitionGroup, CSSTransition } from "react-transition-group";
|
|
|
6
6
|
import useScrollBlock from "../../hooks/__internal__/useScrollBlock";
|
|
7
7
|
import Portal from "../portal";
|
|
8
8
|
import Events from "../../__internal__/utils/helpers/events";
|
|
9
|
-
import
|
|
9
|
+
import useModalManager from "../../hooks/__internal__/useModalManager";
|
|
10
10
|
import { StyledModal, StyledModalBackground } from "./modal.style";
|
|
11
11
|
export const ModalContext = /*#__PURE__*/React.createContext({});
|
|
12
12
|
|
|
@@ -23,8 +23,6 @@ const Modal = ({
|
|
|
23
23
|
const ref = useRef();
|
|
24
24
|
const backgroundNodeRef = useRef();
|
|
25
25
|
const contentNodeRef = useRef();
|
|
26
|
-
const listenerAdded = useRef(false);
|
|
27
|
-
const modalRegistered = useRef(false);
|
|
28
26
|
const [isAnimationComplete, setAnimationComplete] = useState(false);
|
|
29
27
|
const [triggerRefocusFlag, setTriggerRefocusFlag] = useState(false);
|
|
30
28
|
const {
|
|
@@ -50,67 +48,12 @@ const Modal = ({
|
|
|
50
48
|
};
|
|
51
49
|
}, [allowScroll, enableBackgroundUI]);
|
|
52
50
|
const closeModal = useCallback(ev => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (onCancel && !disableClose && !disableEscKey && Events.isEscKey(ev) && isTopmost) {
|
|
51
|
+
if (onCancel && !disableClose && !disableEscKey && Events.isEscKey(ev)) {
|
|
56
52
|
ev.stopImmediatePropagation();
|
|
57
53
|
onCancel(ev);
|
|
58
54
|
}
|
|
59
55
|
}, [disableClose, disableEscKey, onCancel]);
|
|
60
|
-
|
|
61
|
-
/* istanbul ignore else */
|
|
62
|
-
if (!listenerAdded.current) {
|
|
63
|
-
document.addEventListener("keyup", closeModal);
|
|
64
|
-
listenerAdded.current = true;
|
|
65
|
-
}
|
|
66
|
-
}, [closeModal]);
|
|
67
|
-
const removeListener = useCallback(() => {
|
|
68
|
-
if (listenerAdded.current) {
|
|
69
|
-
document.removeEventListener("keyup", closeModal);
|
|
70
|
-
listenerAdded.current = false;
|
|
71
|
-
}
|
|
72
|
-
}, [closeModal]);
|
|
73
|
-
useEffect(() => {
|
|
74
|
-
if (open) {
|
|
75
|
-
addListener();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (!open) {
|
|
79
|
-
removeListener();
|
|
80
|
-
}
|
|
81
|
-
}, [addListener, open, removeListener]);
|
|
82
|
-
useEffect(() => {
|
|
83
|
-
return () => {
|
|
84
|
-
removeListener();
|
|
85
|
-
};
|
|
86
|
-
}, [removeListener]);
|
|
87
|
-
const registerModal = useCallback(() => {
|
|
88
|
-
/* istanbul ignore else */
|
|
89
|
-
if (!modalRegistered.current) {
|
|
90
|
-
ModalManager.addModal(ref.current, setTriggerRefocusFlag);
|
|
91
|
-
modalRegistered.current = true;
|
|
92
|
-
}
|
|
93
|
-
}, []);
|
|
94
|
-
const unregisterModal = useCallback(() => {
|
|
95
|
-
if (modalRegistered.current) {
|
|
96
|
-
ModalManager.removeModal(ref.current);
|
|
97
|
-
modalRegistered.current = false;
|
|
98
|
-
}
|
|
99
|
-
}, []);
|
|
100
|
-
useEffect(() => {
|
|
101
|
-
if (open) {
|
|
102
|
-
registerModal();
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (!open) {
|
|
106
|
-
unregisterModal();
|
|
107
|
-
}
|
|
108
|
-
}, [open, registerModal, unregisterModal]);
|
|
109
|
-
useEffect(() => {
|
|
110
|
-
return () => {
|
|
111
|
-
unregisterModal();
|
|
112
|
-
};
|
|
113
|
-
}, [unregisterModal]);
|
|
56
|
+
useModalManager(open, closeModal, ref, setTriggerRefocusFlag);
|
|
114
57
|
let background;
|
|
115
58
|
let content;
|
|
116
59
|
|
|
@@ -8,9 +8,9 @@ import Icon from "../icon";
|
|
|
8
8
|
import tagComponent from "../../__internal__/utils/helpers/tags/tags";
|
|
9
9
|
import { ToastStyle, TypeIcon, ToastContentStyle, ToastWrapper, StyledPortal } from "./toast.style";
|
|
10
10
|
import IconButton from "../icon-button";
|
|
11
|
-
import ModalManager from "../modal/__internal__/modal-manager";
|
|
12
11
|
import Events from "../../__internal__/utils/helpers/events";
|
|
13
12
|
import useLocale from "../../hooks/__internal__/useLocale";
|
|
13
|
+
import useModalManager from "../../hooks/__internal__/useModalManager";
|
|
14
14
|
import Logger from "../../__internal__/utils/logger";
|
|
15
15
|
let deprecatedWarnTriggered = false;
|
|
16
16
|
|
|
@@ -42,22 +42,12 @@ const Toast = ({
|
|
|
42
42
|
return classNames(className);
|
|
43
43
|
}, [className]);
|
|
44
44
|
const dismissToast = useCallback(ev => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (onDismiss && Events.isEscKey(ev) && isTopmost) {
|
|
45
|
+
if (onDismiss && Events.isEscKey(ev)) {
|
|
48
46
|
ev.stopImmediatePropagation();
|
|
49
47
|
onDismiss(ev);
|
|
50
48
|
}
|
|
51
49
|
}, [onDismiss]);
|
|
52
|
-
|
|
53
|
-
const currentElement = toastRef.current;
|
|
54
|
-
ModalManager.addModal(currentElement);
|
|
55
|
-
document.addEventListener("keyup", dismissToast);
|
|
56
|
-
return () => {
|
|
57
|
-
ModalManager.removeModal(currentElement);
|
|
58
|
-
document.removeEventListener("keyup", dismissToast);
|
|
59
|
-
};
|
|
60
|
-
}, [dismissToast]);
|
|
50
|
+
useModalManager(open, dismissToast, toastRef);
|
|
61
51
|
useEffect(() => {
|
|
62
52
|
clearTimeout(timer.current);
|
|
63
53
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./useModalManager";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./useModalManager";
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { useEffect, useRef, useCallback } from "react";
|
|
2
|
+
import ModalManager from "../../../components/modal/__internal__/modal-manager";
|
|
3
|
+
|
|
4
|
+
const useModalManager = (open, closeModal, modalRef, setTriggerRefocusFlag) => {
|
|
5
|
+
const listenerAdded = useRef(false);
|
|
6
|
+
const modalRegistered = useRef(false);
|
|
7
|
+
const handleClose = useCallback(ev => {
|
|
8
|
+
const isTopmost = ModalManager.isTopmost(modalRef.current);
|
|
9
|
+
|
|
10
|
+
if (isTopmost) {
|
|
11
|
+
closeModal(ev);
|
|
12
|
+
}
|
|
13
|
+
}, [modalRef, closeModal]);
|
|
14
|
+
const addListener = useCallback(() => {
|
|
15
|
+
/* istanbul ignore else */
|
|
16
|
+
if (!listenerAdded.current) {
|
|
17
|
+
document.addEventListener("keyup", handleClose);
|
|
18
|
+
listenerAdded.current = true;
|
|
19
|
+
}
|
|
20
|
+
}, [handleClose]);
|
|
21
|
+
const removeListener = useCallback(() => {
|
|
22
|
+
if (listenerAdded.current) {
|
|
23
|
+
document.removeEventListener("keyup", handleClose);
|
|
24
|
+
listenerAdded.current = false;
|
|
25
|
+
}
|
|
26
|
+
}, [handleClose]);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (open) {
|
|
29
|
+
addListener();
|
|
30
|
+
} else {
|
|
31
|
+
removeListener();
|
|
32
|
+
}
|
|
33
|
+
}, [addListener, open, removeListener]);
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
return () => {
|
|
36
|
+
removeListener();
|
|
37
|
+
};
|
|
38
|
+
}, [removeListener]);
|
|
39
|
+
const registerModal = useCallback(() => {
|
|
40
|
+
/* istanbul ignore else */
|
|
41
|
+
if (!modalRegistered.current) {
|
|
42
|
+
ModalManager.addModal(modalRef.current, setTriggerRefocusFlag);
|
|
43
|
+
modalRegistered.current = true;
|
|
44
|
+
}
|
|
45
|
+
}, [modalRef, setTriggerRefocusFlag]);
|
|
46
|
+
const unregisterModal = useCallback(() => {
|
|
47
|
+
if (modalRegistered.current) {
|
|
48
|
+
ModalManager.removeModal(modalRef.current);
|
|
49
|
+
modalRegistered.current = false;
|
|
50
|
+
}
|
|
51
|
+
}, [modalRef]);
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
if (open) {
|
|
54
|
+
registerModal();
|
|
55
|
+
} else {
|
|
56
|
+
unregisterModal();
|
|
57
|
+
}
|
|
58
|
+
}, [open, registerModal, unregisterModal]);
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
return () => {
|
|
61
|
+
unregisterModal();
|
|
62
|
+
};
|
|
63
|
+
}, [unregisterModal]);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export default useModalManager;
|
|
@@ -4,9 +4,7 @@ require("jest-styled-components");
|
|
|
4
4
|
|
|
5
5
|
var _enzyme = require("enzyme");
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
diff
|
|
9
|
-
} = require("jest-matcher-utils");
|
|
7
|
+
var _jestMatcherUtils = require("jest-matcher-utils");
|
|
10
8
|
|
|
11
9
|
expect.extend({
|
|
12
10
|
toBeFocused(received) {
|
|
@@ -19,7 +17,7 @@ expect.extend({
|
|
|
19
17
|
const hint = this.utils.matcherHint("toBeFocused", "DOMNode", "", options);
|
|
20
18
|
|
|
21
19
|
const positive = () => {
|
|
22
|
-
const diffString = diff(expected, DOMNode, {
|
|
20
|
+
const diffString = (0, _jestMatcherUtils.diff)(expected, DOMNode, {
|
|
23
21
|
expand: this.expand
|
|
24
22
|
});
|
|
25
23
|
return `${hint}\n\n${// eslint-disable-next-line multiline-ternary
|
|
@@ -1,34 +1,72 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export function selectedItemOf(wrapper: any): any;
|
|
6
|
-
export function childrenFrom(node: any): any;
|
|
7
|
-
export function makeArrayKeys(n: any): number[];
|
|
8
|
-
export const keyboard: {};
|
|
9
|
-
export function assertKeyboardTraversal({ num, nonSelectables, }: {
|
|
10
|
-
num: any;
|
|
11
|
-
nonSelectables?: any[] | undefined;
|
|
12
|
-
}): (wrapper: any) => void;
|
|
13
|
-
export function assertHoverTraversal({ num, nonSelectables, }: {
|
|
14
|
-
num: any;
|
|
15
|
-
nonSelectables?: any[] | undefined;
|
|
16
|
-
}): (wrapper: any) => void;
|
|
17
|
-
export function listFrom(wrapper: any): any;
|
|
18
|
-
export function click(wrapper: any): any;
|
|
19
|
-
export namespace simulate {
|
|
20
|
-
export { keydown };
|
|
21
|
-
}
|
|
22
|
-
export const carbonThemesJestTable: (string | Partial<import("style/themes/base/base-theme.config").ThemeObject> | undefined)[][];
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ReactWrapper, ShallowWrapper } from "enzyme";
|
|
3
|
+
import { LayoutProps, FlexboxProps, BackgroundProps } from "styled-system";
|
|
4
|
+
import { ReactTestRendererJSON } from "react-test-renderer";
|
|
23
5
|
import { mockMatchMedia } from "./mock-match-media";
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
6
|
+
declare const toCSSCase: (str: string) => string;
|
|
7
|
+
declare const assertStyleMatch: <Props>(styleSpec: {
|
|
8
|
+
[key: string]: string | number | undefined;
|
|
9
|
+
}, component: ReactWrapper<Props, {}, import("react").Component<{}, {}, any>> | ShallowWrapper<Props, {}, import("react").Component<{}, {}, any>> | ReactTestRendererJSON | ReactTestRendererJSON[] | null, opts?: jest.Options | undefined) => void;
|
|
10
|
+
declare const makeArrayKeys: (n: number) => number[];
|
|
11
|
+
declare const keyMap: {
|
|
12
|
+
readonly UpArrow: 38;
|
|
13
|
+
readonly DownArrow: 40;
|
|
14
|
+
readonly RightArrow: 39;
|
|
15
|
+
readonly LeftArrow: 37;
|
|
16
|
+
readonly Enter: 13;
|
|
17
|
+
readonly Tab: 9;
|
|
18
|
+
readonly Space: 32;
|
|
19
|
+
readonly Escape: 27;
|
|
20
|
+
readonly End: 35;
|
|
21
|
+
readonly Home: 36;
|
|
22
|
+
readonly D: 68;
|
|
23
|
+
readonly E: 69;
|
|
24
|
+
readonly P: 80;
|
|
25
|
+
readonly Z: 90;
|
|
26
|
+
readonly 1: 49;
|
|
27
|
+
};
|
|
28
|
+
declare type Keys = keyof typeof keyMap;
|
|
29
|
+
declare type MappedKeys = `press${Keys}`;
|
|
30
|
+
declare type KeyboardAccumulatorType = Record<MappedKeys, () => void>;
|
|
31
|
+
declare const keyboard: KeyboardAccumulatorType;
|
|
32
|
+
declare type KeydownAccumulatorType = Record<MappedKeys, (wrapper: ReactWrapper<any>, options?: {
|
|
33
|
+
shiftKey: boolean;
|
|
34
|
+
}) => void>;
|
|
35
|
+
declare const simulate: {
|
|
36
|
+
keydown: KeydownAccumulatorType;
|
|
37
|
+
};
|
|
38
|
+
declare const listFrom: (wrapper: ReactWrapper) => ReactWrapper<import("enzyme").HTMLAttributes, any, import("react").Component<{}, {}, any>>;
|
|
39
|
+
declare const childrenFrom: (node: ReactWrapper) => ReactWrapper<any, any, import("react").Component<{}, {}, any>>;
|
|
40
|
+
declare const hoverList: (wrapper: ReactWrapper) => (item: number) => void;
|
|
41
|
+
declare const click: (wrapper: ReactWrapper) => ReactWrapper<{}, {}, import("react").Component<{}, {}, any>>;
|
|
42
|
+
declare const selectedItemOf: (wrapper: ReactWrapper) => number;
|
|
43
|
+
declare const assertKeyboardTraversal: ({ num, nonSelectables, }: {
|
|
44
|
+
num: number;
|
|
45
|
+
nonSelectables?: number[] | undefined;
|
|
46
|
+
}) => (wrapper: ReactWrapper) => void;
|
|
47
|
+
declare const assertHoverTraversal: ({ num, nonSelectables, }: {
|
|
48
|
+
num: number;
|
|
49
|
+
nonSelectables?: number[] | undefined;
|
|
50
|
+
}) => (wrapper: ReactWrapper) => void;
|
|
51
|
+
declare const carbonThemesJestTable: (string | Partial<import("style/themes/base/base-theme.config").ThemeObject> | undefined)[][];
|
|
52
|
+
declare const marginProps: readonly [readonly ["m", "margin"], readonly ["ml", "marginLeft"], readonly ["mr", "marginRight"], readonly ["mt", "marginTop"], readonly ["mb", "marginBottom"], readonly ["mx", "marginLeft"], readonly ["mx", "marginRight"], readonly ["my", "marginTop"], readonly ["my", "marginBottom"]];
|
|
53
|
+
declare type MarginProps = {
|
|
54
|
+
[K in typeof marginProps[number][0]]?: string | number;
|
|
55
|
+
};
|
|
56
|
+
declare const paddingProps: readonly [readonly ["p", "padding"], readonly ["pl", "paddingLeft"], readonly ["pr", "paddingRight"], readonly ["pt", "paddingTop"], readonly ["pb", "paddingBottom"], readonly ["px", "paddingLeft"], readonly ["px", "paddingRight"], readonly ["py", "paddingTop"], readonly ["py", "paddingBottom"]];
|
|
57
|
+
declare type PaddingProps = {
|
|
58
|
+
[K in typeof paddingProps[number][0]]?: string | number;
|
|
59
|
+
};
|
|
60
|
+
export declare const getDefaultValue: (value?: string | number | undefined) => string | number | undefined;
|
|
61
|
+
declare const testStyledSystemMargin: (component: (spacingProps?: MarginProps | undefined) => JSX.Element, defaults?: MarginProps | undefined, styleContainer?: ((wrapper: ReactWrapper) => ReactWrapper) | undefined, assertOpts?: jest.Options | undefined) => void;
|
|
62
|
+
declare const testStyledSystemPadding: (component: (spacingProps?: PaddingProps | undefined) => JSX.Element, defaults?: PaddingProps | undefined, styleContainer?: ((wrapper: ReactWrapper) => ReactWrapper) | undefined, assertOpts?: jest.Options | undefined) => void;
|
|
63
|
+
declare const testStyledSystemSpacing: (component: (spacingProps?: MarginProps | PaddingProps | undefined) => JSX.Element, defaults?: MarginProps | PaddingProps | undefined, styleContainer?: ((wrapper: ReactWrapper) => ReactWrapper) | undefined, assertOpts?: jest.Options | undefined) => void;
|
|
64
|
+
declare const testStyledSystemColor: (component: (colorProperties?: any) => JSX.Element, styleContainer?: ((wrapper: ReactWrapper) => void) | undefined) => void;
|
|
65
|
+
declare const testStyledSystemWidth: (component: (widthProperties?: {
|
|
66
|
+
width: string;
|
|
67
|
+
} | undefined) => JSX.Element, styleContainer?: ((wrapper: ReactWrapper) => ReactWrapper) | undefined) => void;
|
|
68
|
+
declare const testStyledSystemLayout: (component: (layoutProperties?: LayoutProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined) => JSX.Element, styleContainer?: ((wrapper: ReactWrapper) => ReactWrapper) | undefined) => void;
|
|
69
|
+
declare const testStyledSystemFlexBox: (component: (flexboxProperties?: FlexboxProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined) => JSX.Element, styleContainer?: ((wrapper: ReactWrapper) => ReactWrapper) | undefined) => void;
|
|
70
|
+
declare const testStyledSystemBackground: (component: (backgroundProperties?: BackgroundProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.Background<import("styled-system").TLengthStyledSystem>> | undefined) => JSX.Element, styleContainer?: ((wrapper: ReactWrapper) => ReactWrapper) | undefined) => void;
|
|
71
|
+
declare const expectConsoleOutput: (message: string, type?: "warn" | "error") => () => void;
|
|
72
|
+
export { assertStyleMatch, toCSSCase, hoverList, selectedItemOf, childrenFrom, makeArrayKeys, keyboard, assertKeyboardTraversal, assertHoverTraversal, listFrom, click, simulate, carbonThemesJestTable, mockMatchMedia, testStyledSystemSpacing, testStyledSystemMargin, testStyledSystemPadding, testStyledSystemColor, testStyledSystemWidth, testStyledSystemLayout, testStyledSystemFlexBox, testStyledSystemBackground, expectConsoleOutput, };
|