carbon-react 126.2.1 → 126.3.1
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/__internal__/popover/popover.component.d.ts +3 -2
- package/esm/__internal__/popover/popover.component.js +3 -2
- package/esm/components/loader/loader-square.style.d.ts +2 -0
- package/esm/components/loader/loader-square.style.js +3 -2
- package/esm/components/loader/loader.component.d.ts +4 -2
- package/esm/components/loader/loader.component.js +13 -13
- package/esm/components/popover-container/popover-container.component.js +51 -41
- package/esm/components/step-sequence/step-sequence.component.js +6 -0
- package/esm/hooks/__internal__/useFocusPortalContent/index.d.ts +1 -0
- package/esm/hooks/__internal__/useFocusPortalContent/index.js +1 -0
- package/esm/hooks/__internal__/useFocusPortalContent/useFocusPortalContent.d.ts +3 -0
- package/esm/hooks/__internal__/useFocusPortalContent/useFocusPortalContent.js +52 -0
- package/lib/__internal__/popover/popover.component.d.ts +3 -2
- package/lib/__internal__/popover/popover.component.js +3 -2
- package/lib/components/loader/loader-square.style.d.ts +2 -0
- package/lib/components/loader/loader-square.style.js +3 -2
- package/lib/components/loader/loader.component.d.ts +4 -2
- package/lib/components/loader/loader.component.js +13 -13
- package/lib/components/popover-container/popover-container.component.js +51 -41
- package/lib/components/step-sequence/step-sequence.component.js +6 -0
- package/lib/hooks/__internal__/useFocusPortalContent/index.d.ts +1 -0
- package/lib/hooks/__internal__/useFocusPortalContent/index.js +13 -0
- package/lib/hooks/__internal__/useFocusPortalContent/package.json +6 -0
- package/lib/hooks/__internal__/useFocusPortalContent/useFocusPortalContent.d.ts +3 -0
- package/lib/hooks/__internal__/useFocusPortalContent/useFocusPortalContent.js +60 -0
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { MutableRefObject } from "react";
|
|
2
2
|
import { Placement, Middleware } from "@floating-ui/dom";
|
|
3
3
|
declare type CustomRefObject<T> = {
|
|
4
4
|
current?: T | null;
|
|
@@ -13,6 +13,7 @@ export interface PopoverProps {
|
|
|
13
13
|
isOpen?: boolean;
|
|
14
14
|
animationFrame?: boolean;
|
|
15
15
|
popoverStrategy?: "absolute" | "fixed";
|
|
16
|
+
childRefOverride?: MutableRefObject<HTMLDivElement | null>;
|
|
16
17
|
}
|
|
17
|
-
declare const Popover: ({ children, placement, disablePortal, reference, middleware, disableBackgroundUI, isOpen, animationFrame, popoverStrategy, }: PopoverProps) => React.JSX.Element;
|
|
18
|
+
declare const Popover: ({ children, placement, disablePortal, reference, middleware, disableBackgroundUI, isOpen, animationFrame, popoverStrategy, childRefOverride, }: PopoverProps) => React.JSX.Element;
|
|
18
19
|
export default Popover;
|
|
@@ -18,7 +18,8 @@ const Popover = ({
|
|
|
18
18
|
disableBackgroundUI,
|
|
19
19
|
isOpen = true,
|
|
20
20
|
animationFrame,
|
|
21
|
-
popoverStrategy = "absolute"
|
|
21
|
+
popoverStrategy = "absolute",
|
|
22
|
+
childRefOverride
|
|
22
23
|
}) => {
|
|
23
24
|
const elementDOM = useRef(null);
|
|
24
25
|
const {
|
|
@@ -30,7 +31,7 @@ const Popover = ({
|
|
|
30
31
|
elementDOM.current = document.createElement("div");
|
|
31
32
|
mountNode.appendChild(elementDOM.current);
|
|
32
33
|
}
|
|
33
|
-
const childRef = React.Children.only(children).ref;
|
|
34
|
+
const childRef = childRefOverride || React.Children.only(children).ref;
|
|
34
35
|
const innerRef = useRef(null);
|
|
35
36
|
const floatingReference = childRef || innerRef;
|
|
36
37
|
let content;
|
|
@@ -5,6 +5,8 @@ export interface StyledLoaderSquareProps {
|
|
|
5
5
|
isInsideButton?: boolean;
|
|
6
6
|
/** Applies slate color. Available only when isInsideButton is true. */
|
|
7
7
|
isActive?: boolean;
|
|
8
|
+
/** The background color of each loader square */
|
|
9
|
+
backgroundColor?: string;
|
|
8
10
|
}
|
|
9
11
|
declare const StyledLoaderSquare: import("styled-components").StyledComponent<"div", any, StyledLoaderSquareProps, never>;
|
|
10
12
|
export default StyledLoaderSquare;
|
|
@@ -38,10 +38,11 @@ const StyledLoaderSquare = styled.div`
|
|
|
38
38
|
size,
|
|
39
39
|
isInsideButton,
|
|
40
40
|
isActive,
|
|
41
|
-
theme
|
|
41
|
+
theme,
|
|
42
|
+
backgroundColor
|
|
42
43
|
}) => css`
|
|
43
44
|
animation: ${loaderAnimation} 1s infinite ease-in-out both;
|
|
44
|
-
background-color:
|
|
45
|
+
background-color: ${backgroundColor};
|
|
45
46
|
display: inline-block;
|
|
46
47
|
${getDimentions(size, theme.roundedCornersOptOut)}
|
|
47
48
|
|
|
@@ -2,9 +2,11 @@ import React from "react";
|
|
|
2
2
|
import { MarginProps } from "styled-system";
|
|
3
3
|
import { TagProps } from "../../__internal__/utils/helpers/tags/tags";
|
|
4
4
|
import { StyledLoaderSquareProps } from "./loader-square.style";
|
|
5
|
-
export interface LoaderProps extends StyledLoaderSquareProps, MarginProps, TagProps {
|
|
5
|
+
export interface LoaderProps extends Omit<StyledLoaderSquareProps, "backgroundColor">, MarginProps, TagProps {
|
|
6
|
+
/** Toggle between the default variant and gradient variant */
|
|
7
|
+
variant?: string;
|
|
6
8
|
/** Specify a custom accessible name for the Loader component */
|
|
7
9
|
"aria-label"?: string;
|
|
8
10
|
}
|
|
9
|
-
export declare const Loader: ({ "aria-label": ariaLabel, size, isInsideButton, isActive, ...rest }: LoaderProps) => React.JSX.Element;
|
|
11
|
+
export declare const Loader: ({ variant, "aria-label": ariaLabel, size, isInsideButton, isActive, ...rest }: LoaderProps) => React.JSX.Element;
|
|
10
12
|
export default Loader;
|
|
@@ -8,6 +8,7 @@ import tagComponent from "../../__internal__/utils/helpers/tags/tags";
|
|
|
8
8
|
import StyledLoader from "./loader.style";
|
|
9
9
|
import StyledLoaderSquare from "./loader-square.style";
|
|
10
10
|
export const Loader = ({
|
|
11
|
+
variant = "default",
|
|
11
12
|
"aria-label": ariaLabel,
|
|
12
13
|
size = "medium",
|
|
13
14
|
isInsideButton,
|
|
@@ -16,21 +17,20 @@ export const Loader = ({
|
|
|
16
17
|
}) => {
|
|
17
18
|
const l = useLocale();
|
|
18
19
|
const reduceMotion = !useMediaQuery("screen and (prefers-reduced-motion: no-preference)");
|
|
20
|
+
const loaderSquareProps = {
|
|
21
|
+
isInsideButton,
|
|
22
|
+
isActive,
|
|
23
|
+
size,
|
|
24
|
+
variant
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// FE-6368 has been raised for the below, changed hex values for design tokens (when added)
|
|
19
28
|
return /*#__PURE__*/React.createElement(StyledLoader, _extends({
|
|
20
29
|
"aria-label": ariaLabel || l.loader.loading(),
|
|
21
30
|
role: "progressbar"
|
|
22
|
-
}, tagComponent("loader", rest), filterStyledSystemMarginProps(rest)), reduceMotion ? l.loader.loading() : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(StyledLoaderSquare, {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}), /*#__PURE__*/React.createElement(StyledLoaderSquare, {
|
|
27
|
-
isInsideButton: isInsideButton,
|
|
28
|
-
isActive: isActive,
|
|
29
|
-
size: size
|
|
30
|
-
}), /*#__PURE__*/React.createElement(StyledLoaderSquare, {
|
|
31
|
-
isInsideButton: isInsideButton,
|
|
32
|
-
isActive: isActive,
|
|
33
|
-
size: size
|
|
34
|
-
})));
|
|
31
|
+
}, tagComponent("loader", rest), filterStyledSystemMarginProps(rest)), reduceMotion ? l.loader.loading() : /*#__PURE__*/React.createElement(React.Fragment, null, ["#13A038", "#0092DB", "#8F49FE"].map(color => /*#__PURE__*/React.createElement(StyledLoaderSquare, _extends({
|
|
32
|
+
key: color,
|
|
33
|
+
backgroundColor: variant === "gradient" ? color : "var(--colorsActionMajor500)"
|
|
34
|
+
}, loaderSquareProps)))));
|
|
35
35
|
};
|
|
36
36
|
export default Loader;
|
|
@@ -13,6 +13,7 @@ import useClickAwayListener from "../../hooks/__internal__/useClickAwayListener"
|
|
|
13
13
|
import Events from "../../__internal__/utils/helpers/events";
|
|
14
14
|
import FocusTrap from "../../__internal__/focus-trap";
|
|
15
15
|
import { ModalContext } from "../modal";
|
|
16
|
+
import useFocusPortalContent from "../../hooks/__internal__/useFocusPortalContent";
|
|
16
17
|
export const renderOpen = ({
|
|
17
18
|
tabIndex,
|
|
18
19
|
onClick,
|
|
@@ -22,18 +23,20 @@ export const renderOpen = ({
|
|
|
22
23
|
id,
|
|
23
24
|
"aria-expanded": ariaExpanded,
|
|
24
25
|
"aria-haspopup": ariaHasPopup
|
|
25
|
-
}) =>
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
26
|
+
}) => {
|
|
27
|
+
return /*#__PURE__*/React.createElement(PopoverContainerOpenIcon, {
|
|
28
|
+
tabIndex: tabIndex,
|
|
29
|
+
onClick: onClick,
|
|
30
|
+
"data-element": dataElement,
|
|
31
|
+
ref: ref,
|
|
32
|
+
"aria-label": ariaLabel,
|
|
33
|
+
"aria-haspopup": ariaHasPopup,
|
|
34
|
+
"aria-expanded": ariaExpanded,
|
|
35
|
+
id: id
|
|
36
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
37
|
+
type: "settings"
|
|
38
|
+
}));
|
|
39
|
+
};
|
|
37
40
|
export const renderClose = ({
|
|
38
41
|
"data-element": dataElement,
|
|
39
42
|
tabIndex,
|
|
@@ -84,8 +87,12 @@ export const PopoverContainer = ({
|
|
|
84
87
|
const isOpen = isControlled ? open : isOpenInternal;
|
|
85
88
|
const reduceMotion = !useMediaQuery("screen and (prefers-reduced-motion: no-preference)");
|
|
86
89
|
const closePopover = useCallback(ev => {
|
|
87
|
-
if (!isControlled)
|
|
88
|
-
|
|
90
|
+
if (!isControlled) {
|
|
91
|
+
setIsOpenInternal(false);
|
|
92
|
+
}
|
|
93
|
+
if (onClose) {
|
|
94
|
+
onClose(ev);
|
|
95
|
+
}
|
|
89
96
|
if (isOpen && openButtonRef.current) {
|
|
90
97
|
openButtonRef.current.focus();
|
|
91
98
|
}
|
|
@@ -115,6 +122,7 @@ export const PopoverContainer = ({
|
|
|
115
122
|
const handleCloseButtonClick = e => {
|
|
116
123
|
closePopover(e);
|
|
117
124
|
};
|
|
125
|
+
useFocusPortalContent(shouldCoverButton ? undefined : popoverContentNodeRef, shouldCoverButton ? undefined : openButtonRef, closePopover);
|
|
118
126
|
const renderOpenComponentProps = {
|
|
119
127
|
tabIndex: 0,
|
|
120
128
|
"aria-expanded": isOpen,
|
|
@@ -139,25 +147,7 @@ export const PopoverContainer = ({
|
|
|
139
147
|
};
|
|
140
148
|
const handleClick = useClickAwayListener(handleClickAway, "mousedown");
|
|
141
149
|
const [isAnimationComplete, setIsAnimationComplete] = useState(false);
|
|
142
|
-
const popover = /*#__PURE__*/React.createElement(
|
|
143
|
-
in: isOpen,
|
|
144
|
-
timeout: {
|
|
145
|
-
exit: 300
|
|
146
|
-
},
|
|
147
|
-
appear: true,
|
|
148
|
-
mountOnEnter: true,
|
|
149
|
-
unmountOnExit: true,
|
|
150
|
-
nodeRef: popoverContentNodeRef,
|
|
151
|
-
onEntered: shouldCoverButton ? /* istanbul ignore next */() => setIsAnimationComplete(true) : undefined,
|
|
152
|
-
onExiting: shouldCoverButton ? /* istanbul ignore next */() => setIsAnimationComplete(false) : undefined
|
|
153
|
-
}, state => isOpen && /*#__PURE__*/React.createElement(Popover, _extends({
|
|
154
|
-
disablePortal: true,
|
|
155
|
-
reference: popoverReference,
|
|
156
|
-
placement: position === "right" ? "bottom-start" : "bottom-end",
|
|
157
|
-
popoverStrategy: disableAnimation || reduceMotion ? "fixed" : "absolute"
|
|
158
|
-
}, shouldCoverButton && {
|
|
159
|
-
middleware: popoverMiddleware
|
|
160
|
-
}), /*#__PURE__*/React.createElement(PopoverContainerContentStyle, _extends({
|
|
150
|
+
const popover = state => /*#__PURE__*/React.createElement(PopoverContainerContentStyle, _extends({
|
|
161
151
|
"data-element": "popover-container-content",
|
|
162
152
|
role: "dialog",
|
|
163
153
|
animationState: state,
|
|
@@ -171,19 +161,39 @@ export const PopoverContainer = ({
|
|
|
171
161
|
}, filterStyledSystemPaddingProps(rest)), /*#__PURE__*/React.createElement(PopoverContainerHeaderStyle, null, /*#__PURE__*/React.createElement(PopoverContainerTitleStyle, {
|
|
172
162
|
id: popoverContainerId,
|
|
173
163
|
"data-element": "popover-container-title"
|
|
174
|
-
}, title), renderCloseComponent(renderCloseComponentProps)), children)
|
|
175
|
-
|
|
176
|
-
"data-component": "popover-container",
|
|
177
|
-
onMouseDown: handleClick
|
|
178
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
179
|
-
ref: popoverReference
|
|
180
|
-
}, renderOpenComponent(renderOpenComponentProps)), shouldCoverButton ? /*#__PURE__*/React.createElement(ModalContext.Provider, {
|
|
164
|
+
}, title), renderCloseComponent(renderCloseComponentProps)), children);
|
|
165
|
+
const childrenToRender = state => shouldCoverButton ? /*#__PURE__*/React.createElement(ModalContext.Provider, {
|
|
181
166
|
value: {
|
|
182
167
|
isAnimationComplete
|
|
183
168
|
}
|
|
184
169
|
}, /*#__PURE__*/React.createElement(FocusTrap, {
|
|
185
170
|
wrapperRef: popoverContentNodeRef,
|
|
186
171
|
isOpen: isOpen
|
|
187
|
-
}, popover)) : popover);
|
|
172
|
+
}, popover(state))) : popover(state);
|
|
173
|
+
return /*#__PURE__*/React.createElement(PopoverContainerWrapperStyle, {
|
|
174
|
+
"data-component": "popover-container",
|
|
175
|
+
onMouseDown: handleClick
|
|
176
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
177
|
+
ref: popoverReference
|
|
178
|
+
}, renderOpenComponent(renderOpenComponentProps)), /*#__PURE__*/React.createElement(Transition, {
|
|
179
|
+
in: isOpen,
|
|
180
|
+
timeout: {
|
|
181
|
+
exit: 300
|
|
182
|
+
},
|
|
183
|
+
appear: true,
|
|
184
|
+
mountOnEnter: true,
|
|
185
|
+
unmountOnExit: true,
|
|
186
|
+
nodeRef: popoverContentNodeRef,
|
|
187
|
+
onEntered: shouldCoverButton ? /* istanbul ignore next */() => setIsAnimationComplete(true) : undefined,
|
|
188
|
+
onExiting: shouldCoverButton ? /* istanbul ignore next */() => setIsAnimationComplete(false) : undefined
|
|
189
|
+
}, state => isOpen && /*#__PURE__*/React.createElement(Popover, _extends({
|
|
190
|
+
reference: popoverReference,
|
|
191
|
+
placement: position === "right" ? "bottom-start" : "bottom-end",
|
|
192
|
+
popoverStrategy: disableAnimation || reduceMotion ? "fixed" : "absolute"
|
|
193
|
+
}, shouldCoverButton && {
|
|
194
|
+
middleware: popoverMiddleware
|
|
195
|
+
}, {
|
|
196
|
+
childRefOverride: popoverContentNodeRef
|
|
197
|
+
}), childrenToRender(state))));
|
|
188
198
|
};
|
|
189
199
|
export default PopoverContainer;
|
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
2
|
import React from "react";
|
|
3
3
|
import PropTypes from "prop-types";
|
|
4
|
+
import Logger from "../../__internal__/utils/logger";
|
|
4
5
|
import StyledStepSequence from "./step-sequence.style";
|
|
5
6
|
export const StepSequenceContext = /*#__PURE__*/React.createContext({
|
|
6
7
|
orientation: "horizontal"
|
|
7
8
|
});
|
|
9
|
+
let deprecateWarnTriggered = false;
|
|
8
10
|
export const StepSequence = ({
|
|
9
11
|
children,
|
|
10
12
|
orientation = "horizontal",
|
|
11
13
|
...props
|
|
12
14
|
}) => {
|
|
15
|
+
if (!deprecateWarnTriggered) {
|
|
16
|
+
deprecateWarnTriggered = true;
|
|
17
|
+
Logger.deprecate("The `StepSequence` component is deprecated and will soon be removed," + " please use the `StepFlow` component instead.");
|
|
18
|
+
}
|
|
13
19
|
return /*#__PURE__*/React.createElement(StyledStepSequence, _extends({
|
|
14
20
|
"data-component": "step-sequence",
|
|
15
21
|
orientation: orientation,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./useFocusPortalContent";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./useFocusPortalContent";
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import Events from "../../../__internal__/utils/helpers/events";
|
|
3
|
+
import { defaultFocusableSelectors } from "../../../__internal__/focus-trap/focus-trap-utils";
|
|
4
|
+
export default ((container, target, focusCallback) => {
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
const handleFocusPortalContent = ev => {
|
|
7
|
+
if (container?.current && target?.current) {
|
|
8
|
+
const focusableElementsInContainer = Array.from(container.current?.querySelectorAll(defaultFocusableSelectors) || /* istanbul ignore next */[]);
|
|
9
|
+
if (target?.current === document.activeElement) {
|
|
10
|
+
if (Events.isTabKey(ev) && !Events.isShiftKey(ev) && focusableElementsInContainer[0]) {
|
|
11
|
+
ev.preventDefault();
|
|
12
|
+
focusableElementsInContainer[0]?.focus();
|
|
13
|
+
}
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/* istanbul ignore if */
|
|
18
|
+
if (!focusableElementsInContainer.length) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const lastElementFocused = focusableElementsInContainer[focusableElementsInContainer.length - 1] === document.activeElement;
|
|
22
|
+
const firstElementFocused = focusableElementsInContainer[0] === document.activeElement;
|
|
23
|
+
if (Events.isTabKey(ev)) {
|
|
24
|
+
// last element focused inside portal navigate to next element in DOM after the target/ trigger element
|
|
25
|
+
if (lastElementFocused && !Events.isShiftKey(ev)) {
|
|
26
|
+
ev.preventDefault();
|
|
27
|
+
const allFocusableElements = Array.from(document.querySelectorAll(defaultFocusableSelectors) || /* istanbul ignore next */[]);
|
|
28
|
+
const filteredElements = allFocusableElements.filter(el => el === target.current || Number(el.tabIndex) !== -1);
|
|
29
|
+
const nextIndex = filteredElements.indexOf(target.current) + 1;
|
|
30
|
+
focusCallback?.(ev);
|
|
31
|
+
filteredElements[nextIndex]?.focus();
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
// first element focused inside portal navigate back to the target/ trigger element
|
|
35
|
+
if (firstElementFocused && Events.isShiftKey(ev)) {
|
|
36
|
+
ev.preventDefault();
|
|
37
|
+
focusCallback?.(ev);
|
|
38
|
+
|
|
39
|
+
/* istanbul ignore else */
|
|
40
|
+
if (target.current !== document.activeElement) {
|
|
41
|
+
target.current?.focus();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
document.addEventListener("keydown", handleFocusPortalContent);
|
|
48
|
+
return () => {
|
|
49
|
+
document.removeEventListener("keydown", handleFocusPortalContent);
|
|
50
|
+
};
|
|
51
|
+
}, [target, container, focusCallback]);
|
|
52
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { MutableRefObject } from "react";
|
|
2
2
|
import { Placement, Middleware } from "@floating-ui/dom";
|
|
3
3
|
declare type CustomRefObject<T> = {
|
|
4
4
|
current?: T | null;
|
|
@@ -13,6 +13,7 @@ export interface PopoverProps {
|
|
|
13
13
|
isOpen?: boolean;
|
|
14
14
|
animationFrame?: boolean;
|
|
15
15
|
popoverStrategy?: "absolute" | "fixed";
|
|
16
|
+
childRefOverride?: MutableRefObject<HTMLDivElement | null>;
|
|
16
17
|
}
|
|
17
|
-
declare const Popover: ({ children, placement, disablePortal, reference, middleware, disableBackgroundUI, isOpen, animationFrame, popoverStrategy, }: PopoverProps) => React.JSX.Element;
|
|
18
|
+
declare const Popover: ({ children, placement, disablePortal, reference, middleware, disableBackgroundUI, isOpen, animationFrame, popoverStrategy, childRefOverride, }: PopoverProps) => React.JSX.Element;
|
|
18
19
|
export default Popover;
|
|
@@ -27,7 +27,8 @@ const Popover = ({
|
|
|
27
27
|
disableBackgroundUI,
|
|
28
28
|
isOpen = true,
|
|
29
29
|
animationFrame,
|
|
30
|
-
popoverStrategy = "absolute"
|
|
30
|
+
popoverStrategy = "absolute",
|
|
31
|
+
childRefOverride
|
|
31
32
|
}) => {
|
|
32
33
|
const elementDOM = (0, _react.useRef)(null);
|
|
33
34
|
const {
|
|
@@ -39,7 +40,7 @@ const Popover = ({
|
|
|
39
40
|
elementDOM.current = document.createElement("div");
|
|
40
41
|
mountNode.appendChild(elementDOM.current);
|
|
41
42
|
}
|
|
42
|
-
const childRef = _react.default.Children.only(children).ref;
|
|
43
|
+
const childRef = childRefOverride || _react.default.Children.only(children).ref;
|
|
43
44
|
const innerRef = (0, _react.useRef)(null);
|
|
44
45
|
const floatingReference = childRef || innerRef;
|
|
45
46
|
let content;
|
|
@@ -5,6 +5,8 @@ export interface StyledLoaderSquareProps {
|
|
|
5
5
|
isInsideButton?: boolean;
|
|
6
6
|
/** Applies slate color. Available only when isInsideButton is true. */
|
|
7
7
|
isActive?: boolean;
|
|
8
|
+
/** The background color of each loader square */
|
|
9
|
+
backgroundColor?: string;
|
|
8
10
|
}
|
|
9
11
|
declare const StyledLoaderSquare: import("styled-components").StyledComponent<"div", any, StyledLoaderSquareProps, never>;
|
|
10
12
|
export default StyledLoaderSquare;
|
|
@@ -47,10 +47,11 @@ const StyledLoaderSquare = _styledComponents.default.div`
|
|
|
47
47
|
size,
|
|
48
48
|
isInsideButton,
|
|
49
49
|
isActive,
|
|
50
|
-
theme
|
|
50
|
+
theme,
|
|
51
|
+
backgroundColor
|
|
51
52
|
}) => (0, _styledComponents.css)`
|
|
52
53
|
animation: ${loaderAnimation} 1s infinite ease-in-out both;
|
|
53
|
-
background-color:
|
|
54
|
+
background-color: ${backgroundColor};
|
|
54
55
|
display: inline-block;
|
|
55
56
|
${getDimentions(size, theme.roundedCornersOptOut)}
|
|
56
57
|
|
|
@@ -2,9 +2,11 @@ import React from "react";
|
|
|
2
2
|
import { MarginProps } from "styled-system";
|
|
3
3
|
import { TagProps } from "../../__internal__/utils/helpers/tags/tags";
|
|
4
4
|
import { StyledLoaderSquareProps } from "./loader-square.style";
|
|
5
|
-
export interface LoaderProps extends StyledLoaderSquareProps, MarginProps, TagProps {
|
|
5
|
+
export interface LoaderProps extends Omit<StyledLoaderSquareProps, "backgroundColor">, MarginProps, TagProps {
|
|
6
|
+
/** Toggle between the default variant and gradient variant */
|
|
7
|
+
variant?: string;
|
|
6
8
|
/** Specify a custom accessible name for the Loader component */
|
|
7
9
|
"aria-label"?: string;
|
|
8
10
|
}
|
|
9
|
-
export declare const Loader: ({ "aria-label": ariaLabel, size, isInsideButton, isActive, ...rest }: LoaderProps) => React.JSX.Element;
|
|
11
|
+
export declare const Loader: ({ variant, "aria-label": ariaLabel, size, isInsideButton, isActive, ...rest }: LoaderProps) => React.JSX.Element;
|
|
10
12
|
export default Loader;
|
|
@@ -15,6 +15,7 @@ var _loaderSquare = _interopRequireDefault(require("./loader-square.style"));
|
|
|
15
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
16
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
17
17
|
const Loader = ({
|
|
18
|
+
variant = "default",
|
|
18
19
|
"aria-label": ariaLabel,
|
|
19
20
|
size = "medium",
|
|
20
21
|
isInsideButton,
|
|
@@ -23,22 +24,21 @@ const Loader = ({
|
|
|
23
24
|
}) => {
|
|
24
25
|
const l = (0, _useLocale.default)();
|
|
25
26
|
const reduceMotion = !(0, _useMediaQuery.default)("screen and (prefers-reduced-motion: no-preference)");
|
|
27
|
+
const loaderSquareProps = {
|
|
28
|
+
isInsideButton,
|
|
29
|
+
isActive,
|
|
30
|
+
size,
|
|
31
|
+
variant
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// FE-6368 has been raised for the below, changed hex values for design tokens (when added)
|
|
26
35
|
return /*#__PURE__*/_react.default.createElement(_loader.default, _extends({
|
|
27
36
|
"aria-label": ariaLabel || l.loader.loading(),
|
|
28
37
|
role: "progressbar"
|
|
29
|
-
}, (0, _tags.default)("loader", rest), (0, _utils.filterStyledSystemMarginProps)(rest)), reduceMotion ? l.loader.loading() : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_loaderSquare.default, {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}), /*#__PURE__*/_react.default.createElement(_loaderSquare.default, {
|
|
34
|
-
isInsideButton: isInsideButton,
|
|
35
|
-
isActive: isActive,
|
|
36
|
-
size: size
|
|
37
|
-
}), /*#__PURE__*/_react.default.createElement(_loaderSquare.default, {
|
|
38
|
-
isInsideButton: isInsideButton,
|
|
39
|
-
isActive: isActive,
|
|
40
|
-
size: size
|
|
41
|
-
})));
|
|
38
|
+
}, (0, _tags.default)("loader", rest), (0, _utils.filterStyledSystemMarginProps)(rest)), reduceMotion ? l.loader.loading() : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, ["#13A038", "#0092DB", "#8F49FE"].map(color => /*#__PURE__*/_react.default.createElement(_loaderSquare.default, _extends({
|
|
39
|
+
key: color,
|
|
40
|
+
backgroundColor: variant === "gradient" ? color : "var(--colorsActionMajor500)"
|
|
41
|
+
}, loaderSquareProps)))));
|
|
42
42
|
};
|
|
43
43
|
exports.Loader = Loader;
|
|
44
44
|
var _default = exports.default = Loader;
|
|
@@ -18,6 +18,7 @@ var _useClickAwayListener = _interopRequireDefault(require("../../hooks/__intern
|
|
|
18
18
|
var _events = _interopRequireDefault(require("../../__internal__/utils/helpers/events"));
|
|
19
19
|
var _focusTrap = _interopRequireDefault(require("../../__internal__/focus-trap"));
|
|
20
20
|
var _modal = require("../modal");
|
|
21
|
+
var _useFocusPortalContent = _interopRequireDefault(require("../../hooks/__internal__/useFocusPortalContent"));
|
|
21
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
23
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
23
24
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -31,18 +32,20 @@ const renderOpen = ({
|
|
|
31
32
|
id,
|
|
32
33
|
"aria-expanded": ariaExpanded,
|
|
33
34
|
"aria-haspopup": ariaHasPopup
|
|
34
|
-
}) =>
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
35
|
+
}) => {
|
|
36
|
+
return /*#__PURE__*/_react.default.createElement(_popoverContainer.PopoverContainerOpenIcon, {
|
|
37
|
+
tabIndex: tabIndex,
|
|
38
|
+
onClick: onClick,
|
|
39
|
+
"data-element": dataElement,
|
|
40
|
+
ref: ref,
|
|
41
|
+
"aria-label": ariaLabel,
|
|
42
|
+
"aria-haspopup": ariaHasPopup,
|
|
43
|
+
"aria-expanded": ariaExpanded,
|
|
44
|
+
id: id
|
|
45
|
+
}, /*#__PURE__*/_react.default.createElement(_icon.default, {
|
|
46
|
+
type: "settings"
|
|
47
|
+
}));
|
|
48
|
+
};
|
|
46
49
|
exports.renderOpen = renderOpen;
|
|
47
50
|
const renderClose = ({
|
|
48
51
|
"data-element": dataElement,
|
|
@@ -95,8 +98,12 @@ const PopoverContainer = ({
|
|
|
95
98
|
const isOpen = isControlled ? open : isOpenInternal;
|
|
96
99
|
const reduceMotion = !(0, _useMediaQuery.default)("screen and (prefers-reduced-motion: no-preference)");
|
|
97
100
|
const closePopover = (0, _react.useCallback)(ev => {
|
|
98
|
-
if (!isControlled)
|
|
99
|
-
|
|
101
|
+
if (!isControlled) {
|
|
102
|
+
setIsOpenInternal(false);
|
|
103
|
+
}
|
|
104
|
+
if (onClose) {
|
|
105
|
+
onClose(ev);
|
|
106
|
+
}
|
|
100
107
|
if (isOpen && openButtonRef.current) {
|
|
101
108
|
openButtonRef.current.focus();
|
|
102
109
|
}
|
|
@@ -126,6 +133,7 @@ const PopoverContainer = ({
|
|
|
126
133
|
const handleCloseButtonClick = e => {
|
|
127
134
|
closePopover(e);
|
|
128
135
|
};
|
|
136
|
+
(0, _useFocusPortalContent.default)(shouldCoverButton ? undefined : popoverContentNodeRef, shouldCoverButton ? undefined : openButtonRef, closePopover);
|
|
129
137
|
const renderOpenComponentProps = {
|
|
130
138
|
tabIndex: 0,
|
|
131
139
|
"aria-expanded": isOpen,
|
|
@@ -150,25 +158,7 @@ const PopoverContainer = ({
|
|
|
150
158
|
};
|
|
151
159
|
const handleClick = (0, _useClickAwayListener.default)(handleClickAway, "mousedown");
|
|
152
160
|
const [isAnimationComplete, setIsAnimationComplete] = (0, _react.useState)(false);
|
|
153
|
-
const popover = /*#__PURE__*/_react.default.createElement(
|
|
154
|
-
in: isOpen,
|
|
155
|
-
timeout: {
|
|
156
|
-
exit: 300
|
|
157
|
-
},
|
|
158
|
-
appear: true,
|
|
159
|
-
mountOnEnter: true,
|
|
160
|
-
unmountOnExit: true,
|
|
161
|
-
nodeRef: popoverContentNodeRef,
|
|
162
|
-
onEntered: shouldCoverButton ? /* istanbul ignore next */() => setIsAnimationComplete(true) : undefined,
|
|
163
|
-
onExiting: shouldCoverButton ? /* istanbul ignore next */() => setIsAnimationComplete(false) : undefined
|
|
164
|
-
}, state => isOpen && /*#__PURE__*/_react.default.createElement(_popover.default, _extends({
|
|
165
|
-
disablePortal: true,
|
|
166
|
-
reference: popoverReference,
|
|
167
|
-
placement: position === "right" ? "bottom-start" : "bottom-end",
|
|
168
|
-
popoverStrategy: disableAnimation || reduceMotion ? "fixed" : "absolute"
|
|
169
|
-
}, shouldCoverButton && {
|
|
170
|
-
middleware: popoverMiddleware
|
|
171
|
-
}), /*#__PURE__*/_react.default.createElement(_popoverContainer.PopoverContainerContentStyle, _extends({
|
|
161
|
+
const popover = state => /*#__PURE__*/_react.default.createElement(_popoverContainer.PopoverContainerContentStyle, _extends({
|
|
172
162
|
"data-element": "popover-container-content",
|
|
173
163
|
role: "dialog",
|
|
174
164
|
animationState: state,
|
|
@@ -182,20 +172,40 @@ const PopoverContainer = ({
|
|
|
182
172
|
}, (0, _utils.filterStyledSystemPaddingProps)(rest)), /*#__PURE__*/_react.default.createElement(_popoverContainer.PopoverContainerHeaderStyle, null, /*#__PURE__*/_react.default.createElement(_popoverContainer.PopoverContainerTitleStyle, {
|
|
183
173
|
id: popoverContainerId,
|
|
184
174
|
"data-element": "popover-container-title"
|
|
185
|
-
}, title), renderCloseComponent(renderCloseComponentProps)), children)
|
|
186
|
-
|
|
187
|
-
"data-component": "popover-container",
|
|
188
|
-
onMouseDown: handleClick
|
|
189
|
-
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
190
|
-
ref: popoverReference
|
|
191
|
-
}, renderOpenComponent(renderOpenComponentProps)), shouldCoverButton ? /*#__PURE__*/_react.default.createElement(_modal.ModalContext.Provider, {
|
|
175
|
+
}, title), renderCloseComponent(renderCloseComponentProps)), children);
|
|
176
|
+
const childrenToRender = state => shouldCoverButton ? /*#__PURE__*/_react.default.createElement(_modal.ModalContext.Provider, {
|
|
192
177
|
value: {
|
|
193
178
|
isAnimationComplete
|
|
194
179
|
}
|
|
195
180
|
}, /*#__PURE__*/_react.default.createElement(_focusTrap.default, {
|
|
196
181
|
wrapperRef: popoverContentNodeRef,
|
|
197
182
|
isOpen: isOpen
|
|
198
|
-
}, popover)) : popover);
|
|
183
|
+
}, popover(state))) : popover(state);
|
|
184
|
+
return /*#__PURE__*/_react.default.createElement(_popoverContainer.PopoverContainerWrapperStyle, {
|
|
185
|
+
"data-component": "popover-container",
|
|
186
|
+
onMouseDown: handleClick
|
|
187
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
188
|
+
ref: popoverReference
|
|
189
|
+
}, renderOpenComponent(renderOpenComponentProps)), /*#__PURE__*/_react.default.createElement(_reactTransitionGroup.Transition, {
|
|
190
|
+
in: isOpen,
|
|
191
|
+
timeout: {
|
|
192
|
+
exit: 300
|
|
193
|
+
},
|
|
194
|
+
appear: true,
|
|
195
|
+
mountOnEnter: true,
|
|
196
|
+
unmountOnExit: true,
|
|
197
|
+
nodeRef: popoverContentNodeRef,
|
|
198
|
+
onEntered: shouldCoverButton ? /* istanbul ignore next */() => setIsAnimationComplete(true) : undefined,
|
|
199
|
+
onExiting: shouldCoverButton ? /* istanbul ignore next */() => setIsAnimationComplete(false) : undefined
|
|
200
|
+
}, state => isOpen && /*#__PURE__*/_react.default.createElement(_popover.default, _extends({
|
|
201
|
+
reference: popoverReference,
|
|
202
|
+
placement: position === "right" ? "bottom-start" : "bottom-end",
|
|
203
|
+
popoverStrategy: disableAnimation || reduceMotion ? "fixed" : "absolute"
|
|
204
|
+
}, shouldCoverButton && {
|
|
205
|
+
middleware: popoverMiddleware
|
|
206
|
+
}, {
|
|
207
|
+
childRefOverride: popoverContentNodeRef
|
|
208
|
+
}), childrenToRender(state))));
|
|
199
209
|
};
|
|
200
210
|
exports.PopoverContainer = PopoverContainer;
|
|
201
211
|
var _default = exports.default = PopoverContainer;
|
|
@@ -6,17 +6,23 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = exports.StepSequenceContext = exports.StepSequence = void 0;
|
|
7
7
|
var _react = _interopRequireDefault(require("react"));
|
|
8
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
var _logger = _interopRequireDefault(require("../../__internal__/utils/logger"));
|
|
9
10
|
var _stepSequence = _interopRequireDefault(require("./step-sequence.style"));
|
|
10
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
12
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
12
13
|
const StepSequenceContext = exports.StepSequenceContext = /*#__PURE__*/_react.default.createContext({
|
|
13
14
|
orientation: "horizontal"
|
|
14
15
|
});
|
|
16
|
+
let deprecateWarnTriggered = false;
|
|
15
17
|
const StepSequence = ({
|
|
16
18
|
children,
|
|
17
19
|
orientation = "horizontal",
|
|
18
20
|
...props
|
|
19
21
|
}) => {
|
|
22
|
+
if (!deprecateWarnTriggered) {
|
|
23
|
+
deprecateWarnTriggered = true;
|
|
24
|
+
_logger.default.deprecate("The `StepSequence` component is deprecated and will soon be removed," + " please use the `StepFlow` component instead.");
|
|
25
|
+
}
|
|
20
26
|
return /*#__PURE__*/_react.default.createElement(_stepSequence.default, _extends({
|
|
21
27
|
"data-component": "step-sequence",
|
|
22
28
|
orientation: orientation,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./useFocusPortalContent";
|
|
@@ -0,0 +1,13 @@
|
|
|
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 _useFocusPortalContent.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _useFocusPortalContent = _interopRequireDefault(require("./useFocusPortalContent"));
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _events = _interopRequireDefault(require("../../../__internal__/utils/helpers/events"));
|
|
9
|
+
var _focusTrapUtils = require("../../../__internal__/focus-trap/focus-trap-utils");
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
var _default = (container, target, focusCallback) => {
|
|
12
|
+
(0, _react.useEffect)(() => {
|
|
13
|
+
const handleFocusPortalContent = ev => {
|
|
14
|
+
if (container?.current && target?.current) {
|
|
15
|
+
const focusableElementsInContainer = Array.from(container.current?.querySelectorAll(_focusTrapUtils.defaultFocusableSelectors) || /* istanbul ignore next */[]);
|
|
16
|
+
if (target?.current === document.activeElement) {
|
|
17
|
+
if (_events.default.isTabKey(ev) && !_events.default.isShiftKey(ev) && focusableElementsInContainer[0]) {
|
|
18
|
+
ev.preventDefault();
|
|
19
|
+
focusableElementsInContainer[0]?.focus();
|
|
20
|
+
}
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/* istanbul ignore if */
|
|
25
|
+
if (!focusableElementsInContainer.length) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const lastElementFocused = focusableElementsInContainer[focusableElementsInContainer.length - 1] === document.activeElement;
|
|
29
|
+
const firstElementFocused = focusableElementsInContainer[0] === document.activeElement;
|
|
30
|
+
if (_events.default.isTabKey(ev)) {
|
|
31
|
+
// last element focused inside portal navigate to next element in DOM after the target/ trigger element
|
|
32
|
+
if (lastElementFocused && !_events.default.isShiftKey(ev)) {
|
|
33
|
+
ev.preventDefault();
|
|
34
|
+
const allFocusableElements = Array.from(document.querySelectorAll(_focusTrapUtils.defaultFocusableSelectors) || /* istanbul ignore next */[]);
|
|
35
|
+
const filteredElements = allFocusableElements.filter(el => el === target.current || Number(el.tabIndex) !== -1);
|
|
36
|
+
const nextIndex = filteredElements.indexOf(target.current) + 1;
|
|
37
|
+
focusCallback?.(ev);
|
|
38
|
+
filteredElements[nextIndex]?.focus();
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
// first element focused inside portal navigate back to the target/ trigger element
|
|
42
|
+
if (firstElementFocused && _events.default.isShiftKey(ev)) {
|
|
43
|
+
ev.preventDefault();
|
|
44
|
+
focusCallback?.(ev);
|
|
45
|
+
|
|
46
|
+
/* istanbul ignore else */
|
|
47
|
+
if (target.current !== document.activeElement) {
|
|
48
|
+
target.current?.focus();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
document.addEventListener("keydown", handleFocusPortalContent);
|
|
55
|
+
return () => {
|
|
56
|
+
document.removeEventListener("keydown", handleFocusPortalContent);
|
|
57
|
+
};
|
|
58
|
+
}, [target, container, focusCallback]);
|
|
59
|
+
};
|
|
60
|
+
exports.default = _default;
|