carbon-react 125.0.2 → 125.1.0

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.
@@ -12,6 +12,7 @@ export interface PopoverProps {
12
12
  reference: CustomRefObject<HTMLElement>;
13
13
  isOpen?: boolean;
14
14
  animationFrame?: boolean;
15
+ popoverStrategy?: "absolute" | "fixed";
15
16
  }
16
- declare const Popover: ({ children, placement, disablePortal, reference, middleware, disableBackgroundUI, isOpen, animationFrame, }: PopoverProps) => React.JSX.Element;
17
+ declare const Popover: ({ children, placement, disablePortal, reference, middleware, disableBackgroundUI, isOpen, animationFrame, popoverStrategy, }: PopoverProps) => React.JSX.Element;
17
18
  export default Popover;
@@ -17,7 +17,8 @@ const Popover = ({
17
17
  middleware = defaultMiddleware,
18
18
  disableBackgroundUI,
19
19
  isOpen = true,
20
- animationFrame
20
+ animationFrame,
21
+ popoverStrategy = "absolute"
21
22
  }) => {
22
23
  const elementDOM = useRef(null);
23
24
  const {
@@ -46,7 +47,8 @@ const Popover = ({
46
47
  floating: floatingReference,
47
48
  placement,
48
49
  middleware,
49
- animationFrame
50
+ animationFrame,
51
+ strategy: popoverStrategy
50
52
  });
51
53
  useEffect(() => {
52
54
  return () => {
@@ -55,6 +55,8 @@ export interface PopoverContainerProps extends PaddingProps {
55
55
  closeButtonAriaLabel?: string;
56
56
  /** Container aria label */
57
57
  containerAriaLabel?: string;
58
+ /** Disables the animation for the component */
59
+ disableAnimation?: boolean;
58
60
  }
59
- export declare const PopoverContainer: ({ children, title, position, open, onOpen, onClose, renderOpenComponent, renderCloseComponent, shouldCoverButton, ariaDescribedBy, openButtonAriaLabel, closeButtonAriaLabel, containerAriaLabel, ...rest }: PopoverContainerProps) => React.JSX.Element;
61
+ export declare const PopoverContainer: ({ children, title, position, open, onOpen, onClose, renderOpenComponent, renderCloseComponent, shouldCoverButton, ariaDescribedBy, openButtonAriaLabel, closeButtonAriaLabel, containerAriaLabel, disableAnimation, ...rest }: PopoverContainerProps) => React.JSX.Element;
60
62
  export default PopoverContainer;
@@ -3,6 +3,7 @@ import React, { useCallback, useEffect, useRef, useState } from "react";
3
3
  import PropTypes from "prop-types";
4
4
  import { Transition } from "react-transition-group";
5
5
  import { flip, offset } from "@floating-ui/dom";
6
+ import useMediaQuery from "../../hooks/useMediaQuery";
6
7
  import { PopoverContainerWrapperStyle, PopoverContainerHeaderStyle, PopoverContainerContentStyle, PopoverContainerCloseIcon, PopoverContainerTitleStyle, PopoverContainerOpenIcon } from "./popover-container.style";
7
8
  import Icon from "../icon";
8
9
  import Popover from "../../__internal__/popover";
@@ -67,6 +68,7 @@ export const PopoverContainer = ({
67
68
  openButtonAriaLabel,
68
69
  closeButtonAriaLabel = "close",
69
70
  containerAriaLabel,
71
+ disableAnimation = false,
70
72
  ...rest
71
73
  }) => {
72
74
  const isControlled = open !== undefined;
@@ -78,6 +80,7 @@ export const PopoverContainer = ({
78
80
  const popoverContentNodeRef = useRef(null);
79
81
  const popoverContainerId = title ? `PopoverContainer_${guid.current}` : undefined;
80
82
  const isOpen = isControlled ? open : isOpenInternal;
83
+ const reduceMotion = !useMediaQuery("screen and (prefers-reduced-motion: no-preference)");
81
84
  useEffect(() => {
82
85
  if (isOpen && closeButtonRef.current) setTimeout(() => closeButtonRef.current?.focus(), 0);
83
86
  }, [isOpen]);
@@ -147,6 +150,7 @@ export const PopoverContainer = ({
147
150
  unmountOnExit: true,
148
151
  nodeRef: popoverContentNodeRef
149
152
  }, state => isOpen && /*#__PURE__*/React.createElement(Popover, _extends({
153
+ popoverStrategy: disableAnimation || reduceMotion ? "fixed" : "absolute",
150
154
  reference: popoverReference,
151
155
  placement: position === "right" ? "bottom-start" : "bottom-end"
152
156
  }, shouldCoverButton && {
@@ -159,7 +163,8 @@ export const PopoverContainer = ({
159
163
  "aria-label": containerAriaLabel,
160
164
  "aria-describedby": ariaDescribedBy,
161
165
  p: "16px 24px",
162
- ref: popoverContentNodeRef
166
+ ref: popoverContentNodeRef,
167
+ disableAnimation: disableAnimation || reduceMotion
163
168
  }, filterStyledSystemPaddingProps(rest)), /*#__PURE__*/React.createElement(PopoverContainerHeaderStyle, null, /*#__PURE__*/React.createElement(PopoverContainerTitleStyle, {
164
169
  id: popoverContainerId,
165
170
  "data-element": "popover-container-title"
@@ -4,6 +4,7 @@ declare const PopoverContainerWrapperStyle: import("styled-components").StyledCo
4
4
  declare const PopoverContainerHeaderStyle: import("styled-components").StyledComponent<"div", any, {}, never>;
5
5
  declare type PopoverContainerContentStyleProps = {
6
6
  animationState?: TransitionStatus;
7
+ disableAnimation?: boolean;
7
8
  };
8
9
  declare const PopoverContainerContentStyle: import("styled-components").StyledComponent<"div", any, PopoverContainerContentStyleProps, never>;
9
10
  declare type AdditionalIconButtonProps = {
@@ -3,6 +3,33 @@ import { padding } from "styled-system";
3
3
  import { baseTheme } from "../../style/themes";
4
4
  import IconButton from "../icon-button";
5
5
  import StyledIcon from "../icon/icon.style";
6
+ function animationToRender({
7
+ animationState,
8
+ disableAnimation
9
+ }) {
10
+ if (disableAnimation) return "opacity: 1;";
11
+ switch (animationState) {
12
+ case "entering":
13
+ return `
14
+ opacity: 0;
15
+ transform: translateY(-8px);
16
+ `;
17
+ case "entered":
18
+ return `
19
+ opacity: 1;
20
+ transform: translateY(0);
21
+ transition: all 0.3s cubic-bezier(0.25, 0.25, 0, 1.5);
22
+ `;
23
+ case "exiting":
24
+ return `
25
+ opacity: 0;
26
+ transform: translateY(-8px);
27
+ transition: all 0.3s cubic-bezier(0.25, 0.25, 0, 1.5);
28
+ `;
29
+ default:
30
+ return "opacity: 0;";
31
+ }
32
+ }
6
33
  const PopoverContainerWrapperStyle = styled.div`
7
34
  position: relative;
8
35
  display: inline-block;
@@ -25,31 +52,7 @@ const PopoverContainerContentStyle = styled.div`
25
52
  theme
26
53
  }) => theme.zIndex.popover};
27
54
 
28
- ${({
29
- animationState
30
- }) => {
31
- switch (animationState) {
32
- case "entering":
33
- return `
34
- opacity: 0;
35
- transform: translateY(-8px);
36
- `;
37
- case "entered":
38
- return `
39
- opacity: 1;
40
- transform: translateY(0);
41
- transition: all 0.3s cubic-bezier(0.25, 0.25, 0, 1.5);
42
- `;
43
- case "exiting":
44
- return `
45
- opacity: 0;
46
- transform: translateY(-8px);
47
- transition: all 0.3s cubic-bezier(0.25, 0.25, 0, 1.5);
48
- `;
49
- default:
50
- return "opacity: 0";
51
- }
52
- }}
55
+ ${animationToRender}
53
56
  `;
54
57
  const PopoverContainerOpenIcon = styled(IconButton)`
55
58
  ${StyledIcon} {
@@ -12,6 +12,7 @@ export interface PopoverProps {
12
12
  reference: CustomRefObject<HTMLElement>;
13
13
  isOpen?: boolean;
14
14
  animationFrame?: boolean;
15
+ popoverStrategy?: "absolute" | "fixed";
15
16
  }
16
- declare const Popover: ({ children, placement, disablePortal, reference, middleware, disableBackgroundUI, isOpen, animationFrame, }: PopoverProps) => React.JSX.Element;
17
+ declare const Popover: ({ children, placement, disablePortal, reference, middleware, disableBackgroundUI, isOpen, animationFrame, popoverStrategy, }: PopoverProps) => React.JSX.Element;
17
18
  export default Popover;
@@ -26,7 +26,8 @@ const Popover = ({
26
26
  middleware = defaultMiddleware,
27
27
  disableBackgroundUI,
28
28
  isOpen = true,
29
- animationFrame
29
+ animationFrame,
30
+ popoverStrategy = "absolute"
30
31
  }) => {
31
32
  const elementDOM = (0, _react.useRef)(null);
32
33
  const {
@@ -55,7 +56,8 @@ const Popover = ({
55
56
  floating: floatingReference,
56
57
  placement,
57
58
  middleware,
58
- animationFrame
59
+ animationFrame,
60
+ strategy: popoverStrategy
59
61
  });
60
62
  (0, _react.useEffect)(() => {
61
63
  return () => {
@@ -55,6 +55,8 @@ export interface PopoverContainerProps extends PaddingProps {
55
55
  closeButtonAriaLabel?: string;
56
56
  /** Container aria label */
57
57
  containerAriaLabel?: string;
58
+ /** Disables the animation for the component */
59
+ disableAnimation?: boolean;
58
60
  }
59
- export declare const PopoverContainer: ({ children, title, position, open, onOpen, onClose, renderOpenComponent, renderCloseComponent, shouldCoverButton, ariaDescribedBy, openButtonAriaLabel, closeButtonAriaLabel, containerAriaLabel, ...rest }: PopoverContainerProps) => React.JSX.Element;
61
+ export declare const PopoverContainer: ({ children, title, position, open, onOpen, onClose, renderOpenComponent, renderCloseComponent, shouldCoverButton, ariaDescribedBy, openButtonAriaLabel, closeButtonAriaLabel, containerAriaLabel, disableAnimation, ...rest }: PopoverContainerProps) => React.JSX.Element;
60
62
  export default PopoverContainer;
@@ -8,6 +8,7 @@ var _react = _interopRequireWildcard(require("react"));
8
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
9
  var _reactTransitionGroup = require("react-transition-group");
10
10
  var _dom = require("@floating-ui/dom");
11
+ var _useMediaQuery = _interopRequireDefault(require("../../hooks/useMediaQuery"));
11
12
  var _popoverContainer = require("./popover-container.style");
12
13
  var _icon = _interopRequireDefault(require("../icon"));
13
14
  var _popover = _interopRequireDefault(require("../../__internal__/popover"));
@@ -78,6 +79,7 @@ const PopoverContainer = ({
78
79
  openButtonAriaLabel,
79
80
  closeButtonAriaLabel = "close",
80
81
  containerAriaLabel,
82
+ disableAnimation = false,
81
83
  ...rest
82
84
  }) => {
83
85
  const isControlled = open !== undefined;
@@ -89,6 +91,7 @@ const PopoverContainer = ({
89
91
  const popoverContentNodeRef = (0, _react.useRef)(null);
90
92
  const popoverContainerId = title ? `PopoverContainer_${guid.current}` : undefined;
91
93
  const isOpen = isControlled ? open : isOpenInternal;
94
+ const reduceMotion = !(0, _useMediaQuery.default)("screen and (prefers-reduced-motion: no-preference)");
92
95
  (0, _react.useEffect)(() => {
93
96
  if (isOpen && closeButtonRef.current) setTimeout(() => closeButtonRef.current?.focus(), 0);
94
97
  }, [isOpen]);
@@ -158,6 +161,7 @@ const PopoverContainer = ({
158
161
  unmountOnExit: true,
159
162
  nodeRef: popoverContentNodeRef
160
163
  }, state => isOpen && /*#__PURE__*/_react.default.createElement(_popover.default, _extends({
164
+ popoverStrategy: disableAnimation || reduceMotion ? "fixed" : "absolute",
161
165
  reference: popoverReference,
162
166
  placement: position === "right" ? "bottom-start" : "bottom-end"
163
167
  }, shouldCoverButton && {
@@ -170,7 +174,8 @@ const PopoverContainer = ({
170
174
  "aria-label": containerAriaLabel,
171
175
  "aria-describedby": ariaDescribedBy,
172
176
  p: "16px 24px",
173
- ref: popoverContentNodeRef
177
+ ref: popoverContentNodeRef,
178
+ disableAnimation: disableAnimation || reduceMotion
174
179
  }, (0, _utils.filterStyledSystemPaddingProps)(rest)), /*#__PURE__*/_react.default.createElement(_popoverContainer.PopoverContainerHeaderStyle, null, /*#__PURE__*/_react.default.createElement(_popoverContainer.PopoverContainerTitleStyle, {
175
180
  id: popoverContainerId,
176
181
  "data-element": "popover-container-title"
@@ -4,6 +4,7 @@ declare const PopoverContainerWrapperStyle: import("styled-components").StyledCo
4
4
  declare const PopoverContainerHeaderStyle: import("styled-components").StyledComponent<"div", any, {}, never>;
5
5
  declare type PopoverContainerContentStyleProps = {
6
6
  animationState?: TransitionStatus;
7
+ disableAnimation?: boolean;
7
8
  };
8
9
  declare const PopoverContainerContentStyle: import("styled-components").StyledComponent<"div", any, PopoverContainerContentStyleProps, never>;
9
10
  declare type AdditionalIconButtonProps = {
@@ -10,6 +10,33 @@ var _themes = require("../../style/themes");
10
10
  var _iconButton = _interopRequireDefault(require("../icon-button"));
11
11
  var _icon = _interopRequireDefault(require("../icon/icon.style"));
12
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+ function animationToRender({
14
+ animationState,
15
+ disableAnimation
16
+ }) {
17
+ if (disableAnimation) return "opacity: 1;";
18
+ switch (animationState) {
19
+ case "entering":
20
+ return `
21
+ opacity: 0;
22
+ transform: translateY(-8px);
23
+ `;
24
+ case "entered":
25
+ return `
26
+ opacity: 1;
27
+ transform: translateY(0);
28
+ transition: all 0.3s cubic-bezier(0.25, 0.25, 0, 1.5);
29
+ `;
30
+ case "exiting":
31
+ return `
32
+ opacity: 0;
33
+ transform: translateY(-8px);
34
+ transition: all 0.3s cubic-bezier(0.25, 0.25, 0, 1.5);
35
+ `;
36
+ default:
37
+ return "opacity: 0;";
38
+ }
39
+ }
13
40
  const PopoverContainerWrapperStyle = exports.PopoverContainerWrapperStyle = _styledComponents.default.div`
14
41
  position: relative;
15
42
  display: inline-block;
@@ -32,31 +59,7 @@ const PopoverContainerContentStyle = exports.PopoverContainerContentStyle = _sty
32
59
  theme
33
60
  }) => theme.zIndex.popover};
34
61
 
35
- ${({
36
- animationState
37
- }) => {
38
- switch (animationState) {
39
- case "entering":
40
- return `
41
- opacity: 0;
42
- transform: translateY(-8px);
43
- `;
44
- case "entered":
45
- return `
46
- opacity: 1;
47
- transform: translateY(0);
48
- transition: all 0.3s cubic-bezier(0.25, 0.25, 0, 1.5);
49
- `;
50
- case "exiting":
51
- return `
52
- opacity: 0;
53
- transform: translateY(-8px);
54
- transition: all 0.3s cubic-bezier(0.25, 0.25, 0, 1.5);
55
- `;
56
- default:
57
- return "opacity: 0";
58
- }
59
- }}
62
+ ${animationToRender}
60
63
  `;
61
64
  const PopoverContainerOpenIcon = exports.PopoverContainerOpenIcon = (0, _styledComponents.default)(_iconButton.default)`
62
65
  ${_icon.default} {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-react",
3
- "version": "125.0.2",
3
+ "version": "125.1.0",
4
4
  "description": "A library of reusable React components for easily building user interfaces.",
5
5
  "files": [
6
6
  "lib",