@shopgate/pwa-common 7.30.3 → 7.31.0-alpha.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.
Files changed (112) hide show
  1. package/App.js +0 -2
  2. package/actions/app/handleLink.js +1 -0
  3. package/collections/AuthRoutes.js +1 -0
  4. package/collections/PersistedReducers.js +1 -0
  5. package/collections/media-providers/Vimeo.js +1 -1
  6. package/collections/media-providers/style.js +1 -1
  7. package/components/Backdrop/index.js +18 -3
  8. package/components/Button/index.js +40 -52
  9. package/components/Checkbox/index.js +1 -1
  10. package/components/Drawer/index.js +118 -132
  11. package/components/Drawer/spec.js +4 -2
  12. package/components/Dropdown/index.js +52 -68
  13. package/components/Grid/components/Item/index.js +37 -40
  14. package/components/Grid/index.js +36 -34
  15. package/components/HtmlSanitizer/index.js +60 -7
  16. package/components/I18n/components/FormatNumber/spec.js +1 -0
  17. package/components/Icon/index.d.ts +36 -0
  18. package/components/Icon/index.d.ts.map +1 -0
  19. package/components/Icon/index.js +39 -28
  20. package/components/Image/Image.js +27 -6
  21. package/components/Image/ImageInner.js +32 -25
  22. package/components/InfiniteContainer/index.js +5 -7
  23. package/components/InfiniteContainer/spec.js +13 -17
  24. package/components/Link/index.js +75 -84
  25. package/components/List/components/Item/index.js +19 -10
  26. package/components/List/spec.js +1 -3
  27. package/components/Loading/index.d.ts +6 -0
  28. package/components/Loading/index.d.ts.map +1 -0
  29. package/components/Modal/index.js +41 -7
  30. package/components/Picker/index.js +18 -194
  31. package/components/Portal/index.d.ts +50 -0
  32. package/components/Portal/index.d.ts.map +1 -0
  33. package/components/ProductCharacteristics/index.js +14 -276
  34. package/components/RangeSlider/index.js +15 -258
  35. package/components/Select/components/Item/index.js +18 -7
  36. package/components/Select/index.js +108 -144
  37. package/components/Select/spec.js +49 -16
  38. package/components/SelectBox/components/Item/index.js +49 -51
  39. package/components/SelectBox/index.js +140 -160
  40. package/components/SurroundPortals/index.d.ts +24 -0
  41. package/components/SurroundPortals/index.d.ts.map +1 -0
  42. package/components/SurroundPortals/index.js +3 -13
  43. package/components/Swiper/components/SwiperItem/index.js +13 -4
  44. package/components/Swiper/components/SwiperItem/spec.js +3 -2
  45. package/components/Swiper/index.js +80 -12
  46. package/components/Widgets/components/Widget/index.js +54 -56
  47. package/components/Widgets/components/Widget/spec.js +12 -8
  48. package/components/Widgets/components/WidgetGrid/index.js +39 -53
  49. package/components/Widgets/components/WidgetGrid/spec.js +12 -8
  50. package/constants/Configuration.js +2 -1
  51. package/constants/Portals.d.ts +101 -0
  52. package/constants/Portals.d.ts.map +1 -0
  53. package/helpers/config/index.d.ts +94 -0
  54. package/helpers/config/index.d.ts.map +1 -0
  55. package/helpers/config/mock.d.ts +23 -0
  56. package/helpers/config/mock.d.ts.map +1 -0
  57. package/helpers/config/theme.d.ts +7 -0
  58. package/helpers/config/theme.d.ts.map +1 -0
  59. package/helpers/data/index.d.ts +35 -0
  60. package/helpers/data/index.d.ts.map +1 -0
  61. package/helpers/data/index.js +1 -0
  62. package/helpers/html/handleDOM.js +1 -0
  63. package/helpers/portals/portalCollection.d.ts +30 -0
  64. package/helpers/portals/portalCollection.d.ts.map +1 -0
  65. package/helpers/style/index.js +1 -0
  66. package/helpers/validation/index.d.ts +10 -0
  67. package/helpers/validation/index.d.ts.map +1 -0
  68. package/package.json +4 -3
  69. package/selectors/client.js +1 -0
  70. package/styles/reset/form.js +46 -51
  71. package/styles/reset/media.js +21 -19
  72. package/styles/reset/root.js +28 -26
  73. package/styles/reset/table.js +9 -7
  74. package/styles/reset/typography.js +24 -22
  75. package/subscriptions/error.js +1 -0
  76. package/subscriptions/helpers/handleLinks.js +1 -0
  77. package/subscriptions/router.js +1 -0
  78. package/tsconfig.build.json +16 -0
  79. package/tsconfig.json +3 -0
  80. package/components/Backdrop/style.js +0 -11
  81. package/components/Button/style.js +0 -6
  82. package/components/Drawer/style.js +0 -37
  83. package/components/Dropdown/style.js +0 -4
  84. package/components/Grid/components/Item/style.js +0 -23
  85. package/components/Grid/style.js +0 -14
  86. package/components/Icon/style.js +0 -6
  87. package/components/Image/style.js +0 -32
  88. package/components/Link/style.js +0 -10
  89. package/components/List/components/Item/style.js +0 -16
  90. package/components/Modal/style.js +0 -36
  91. package/components/Picker/components/Button/index.js +0 -42
  92. package/components/Picker/components/Button/style.js +0 -19
  93. package/components/Picker/components/List/index.js +0 -38
  94. package/components/Picker/components/List/style.js +0 -17
  95. package/components/Picker/components/Modal/index.js +0 -76
  96. package/components/Picker/components/Modal/style.js +0 -78
  97. package/components/Picker/spec.js +0 -88
  98. package/components/ProductCharacteristics/connector.js +0 -41
  99. package/components/ProductCharacteristics/context.js +0 -2
  100. package/components/ProductCharacteristics/helpers/index.js +0 -162
  101. package/components/RangeSlider/components/Handle/index.js +0 -34
  102. package/components/RangeSlider/components/Handle/style.js +0 -14
  103. package/components/RangeSlider/helper.js +0 -85
  104. package/components/RangeSlider/style.js +0 -14
  105. package/components/Select/components/Item/style.js +0 -4
  106. package/components/Select/style.js +0 -17
  107. package/components/SelectBox/components/Item/style.js +0 -7
  108. package/components/SelectBox/style.js +0 -18
  109. package/components/Swiper/components/SwiperItem/styles.js +0 -5
  110. package/components/Swiper/styles.js +0 -76
  111. package/components/Widgets/components/Widget/style.js +0 -27
  112. package/components/Widgets/components/WidgetGrid/style.js +0 -8
package/App.js CHANGED
@@ -3,7 +3,6 @@ import React, { Component } from 'react';
3
3
  import PropTypes from 'prop-types';
4
4
  import { Provider } from 'react-redux';
5
5
  import { CookiesProvider } from 'react-cookie';
6
- import { loadCustomStyles } from '@shopgate/engage/styles';
7
6
  import ErrorBoundary from "./components/ErrorBoundary";
8
7
  import { appDidStart } from "./action-creators/app";
9
8
  import I18n from "./components/I18n";
@@ -43,7 +42,6 @@ let App = /*#__PURE__*/function (_Component) {
43
42
  this.props.store.dispatch(appDidStart(`${window.location.pathname}${window.location.search}`));
44
43
  };
45
44
  performAppStart();
46
- loadCustomStyles();
47
45
  }
48
46
 
49
47
  /**
@@ -1,3 +1,4 @@
1
+ import "core-js/modules/es.array.includes.js";
1
2
  import "core-js/modules/es.string.replace.js";
2
3
  import "core-js/modules/web.url.js";
3
4
  import "core-js/modules/web.url.to-json.js";
@@ -1,3 +1,4 @@
1
+ import "core-js/modules/es.array.includes.js";
1
2
  import pathMatch from 'path-match';
2
3
 
3
4
  /**
@@ -1,3 +1,4 @@
1
+ import "core-js/modules/es.array.includes.js";
1
2
  /**
2
3
  * Class to maintain the persisted redux reducers.
3
4
  */
@@ -87,7 +87,7 @@ let VimeoMediaProvider = /*#__PURE__*/function (_MediaProvider) {
87
87
  * sandbox attributes to improve security and layout behavior.
88
88
  *
89
89
  * @param {Document} document - The DOM document containing iframes to optimize.
90
- * @returns {YouTubeMediaProvider}
90
+ * @returns {VimeoMediaProvider}
91
91
  */;
92
92
  _proto.applyIframeOptimizations = function applyIframeOptimizations(document) {
93
93
  const iframes = this.getMediaContainers(document);
@@ -1,4 +1,4 @@
1
- import { css } from 'glamor';
1
+ import { css } from '@shopgate/engage/styles';
2
2
  import { themeConfig } from '@shopgate/pwa-common/helpers/config';
3
3
  const {
4
4
  colors
@@ -1,15 +1,27 @@
1
1
  import React, { useEffect, useMemo, useRef } from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { Transition } from 'react-transition-group';
4
+ import { makeStyles } from '@shopgate/engage/styles';
4
5
  import { toggleBodyScroll } from '@shopgate/engage/styles/helpers';
5
- import style from "./style";
6
+ import { jsx as _jsx } from "react/jsx-runtime";
7
+ const useStyles = makeStyles()({
8
+ backdrop: {
9
+ position: 'fixed',
10
+ top: 0,
11
+ right: 0,
12
+ bottom: 0,
13
+ left: 0,
14
+ // Prevents that content behind the backdrop is clickable
15
+ pointerEvents: 'all',
16
+ touchAction: 'none'
17
+ }
18
+ });
6
19
 
7
20
  /**
8
21
  * Backdrop component
9
22
  * @param {Object} props The component props.
10
23
  * @returns {JSX.Element}
11
24
  */
12
- import { jsx as _jsx } from "react/jsx-runtime";
13
25
  function Backdrop({
14
26
  className,
15
27
  color,
@@ -20,6 +32,9 @@ function Backdrop({
20
32
  onClick,
21
33
  opacity
22
34
  }) {
35
+ const {
36
+ classes
37
+ } = useStyles();
23
38
  // Stable id for body scroll lock
24
39
  const bodyScrollRef = useRef(Math.random().toString(36).slice(2) + Math.random().toString(36).slice(2));
25
40
  const nodeRef = useRef(null);
@@ -66,7 +81,7 @@ function Backdrop({
66
81
  pointerEvents: 'none'
67
82
  }
68
83
  }), [targetOpacity]);
69
- const combinedClassName = `${style} ${className} common__backdrop`;
84
+ const combinedClassName = `${classes.backdrop} ${className} common__backdrop`;
70
85
  return /*#__PURE__*/_jsx(Transition, {
71
86
  in: isVisible,
72
87
  timeout: duration,
@@ -1,64 +1,52 @@
1
- import _createClass from "@babel/runtime/helpers/createClass";
2
- import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
3
- import React, { Component } from 'react';
1
+ import React, { memo } from 'react';
4
2
  import PropTypes from 'prop-types';
5
- import style from "./style";
3
+ import { makeStyles } from '@shopgate/engage/styles';
4
+ import { jsx as _jsx } from "react/jsx-runtime";
5
+ const useStyles = makeStyles()(() => ({
6
+ root: {
7
+ '&:focus': {
8
+ outline: 0
9
+ }
10
+ }
11
+ }));
6
12
 
7
13
  /**
8
14
  * The button component.
15
+ * @param {Object} props Props.
16
+ * @returns {JSX.Element}
9
17
  */
10
- import { jsx as _jsx } from "react/jsx-runtime";
11
- let Button = /*#__PURE__*/function (_Component) {
12
- function Button() {
13
- return _Component.apply(this, arguments) || this;
14
- }
15
- _inheritsLoose(Button, _Component);
16
- var _proto = Button.prototype;
17
- /**
18
- * Renders the component.
19
- * @returns {JSX.Element}
20
- */
21
- _proto.render = function render() {
22
- return (
23
- /*#__PURE__*/
24
- // eslint-disable-next-line react/button-has-type
25
- _jsx("button", {
26
- "data-test-id": this.props.testId,
27
- ...this.buttonProps,
28
- children: this.props.children
29
- })
30
- );
18
+ const Button = ({
19
+ children,
20
+ className,
21
+ disabled,
22
+ onClick,
23
+ testId,
24
+ ...rest
25
+ }) => {
26
+ const {
27
+ classes,
28
+ cx
29
+ } = useStyles();
30
+ const buttonProps = {
31
+ className: cx(classes.root, 'common__button', className),
32
+ disabled,
33
+ onClick: disabled ? null : onClick,
34
+ ...rest
31
35
  };
32
- return _createClass(Button, [{
33
- key: "buttonProps",
34
- get:
35
- /**
36
- * Getter for the calculated button props.
37
- * @returns {Object}
38
- */
39
- function () {
40
- const {
41
- children,
42
- testId,
43
- className,
44
- disabled,
45
- onClick,
46
- ...props
47
- } = this.props;
48
- const buttonProps = {
49
- className: `${className} ${style} common__button`,
50
- disabled,
51
- onClick: disabled ? null : onClick,
52
- ...props
53
- };
54
- return buttonProps;
55
- }
56
- }]);
57
- }(Component);
36
+ return (
37
+ /*#__PURE__*/
38
+ // eslint-disable-next-line react/button-has-type
39
+ _jsx("button", {
40
+ "data-test-id": testId,
41
+ ...buttonProps,
42
+ children: children
43
+ })
44
+ );
45
+ };
58
46
  Button.defaultProps = {
59
47
  className: '',
60
48
  disabled: false,
61
49
  onClick: null,
62
50
  testId: 'Button'
63
51
  };
64
- export default Button;
52
+ export default /*#__PURE__*/memo(Button);
@@ -39,7 +39,7 @@ let Checkbox = /*#__PURE__*/function (_Component) {
39
39
  */
40
40
  _this.isChecked = () => typeof _this.props.defaultChecked === 'undefined' ? _this.props.checked // Controlled.
41
41
  : _this.state.checked // Uncontrolled.
42
- ;
42
+ ;
43
43
  /**
44
44
  * Inverts the current "checked" value and calls the callback function with it.
45
45
  * If the checkbox is uncontrolled, it keeps track of the value.
@@ -1,148 +1,134 @@
1
- import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
2
- import React, { Component } from 'react';
1
+ import React, { useState, useEffect, useRef, useCallback, memo } from 'react';
3
2
  import PropTypes from 'prop-types';
4
- import classNames from 'classnames';
5
- import styles from "./style";
3
+ import { makeStyles, keyframes } from '@shopgate/engage/styles';
4
+ import { jsx as _jsx } from "react/jsx-runtime";
5
+ const duration = 150;
6
+ const easing = 'ease';
7
+ const slideInBaseDrawer = keyframes({
8
+ '0%': {
9
+ transform: 'translateY(100%)'
10
+ },
11
+ '100%': {
12
+ transform: 'translateY(0)'
13
+ }
14
+ });
15
+ const slideOutBaseDrawer = keyframes({
16
+ '0%': {
17
+ transform: 'translateY(0)'
18
+ },
19
+ '100%': {
20
+ transform: 'translateY(100%)'
21
+ }
22
+ });
23
+ const useStyles = makeStyles()(() => ({
24
+ container: {
25
+ position: 'fixed',
26
+ bottom: 0,
27
+ left: 0,
28
+ zIndex: 5
29
+ },
30
+ animationIn: {
31
+ animation: `${slideInBaseDrawer} ${duration}ms 1 forwards ${easing}`
32
+ },
33
+ animationOut: {
34
+ animation: `${slideOutBaseDrawer} ${duration}ms 1 forwards ${easing}`
35
+ }
36
+ }));
6
37
 
7
38
  /**
8
39
  * Drawer component.
40
+ * @param {Object} props Props.
41
+ * @returns {JSX.Element|null}
9
42
  */
10
- import { jsx as _jsx } from "react/jsx-runtime";
11
- let Drawer = /*#__PURE__*/function (_Component) {
12
- /**
13
- * Initializes the Drawer component.
14
- * @param {Object} props The components props.
15
- */
16
- function Drawer(props) {
17
- var _this;
18
- _this = _Component.call(this, props) || this;
19
- /**
20
- * Syncs the internal active state when an animation ends.
21
- */
22
- _this.handleAnimationEnd = () => {
23
- _this.setState({
24
- active: _this.props.isOpen
25
- });
26
- if (!_this.props.isOpen) {
27
- _this.props.onDidClose();
28
- } else {
29
- _this.props.onDidOpen();
30
- }
31
- };
32
- _this.sheetRef = /*#__PURE__*/React.createRef();
33
- _this.state = {
34
- active: props.isOpen
35
- };
36
- return _this;
37
- }
38
-
39
- /** inheritdoc */
40
- _inheritsLoose(Drawer, _Component);
41
- var _proto = Drawer.prototype;
42
- _proto.componentDidMount = function componentDidMount() {
43
- if (this.props.isOpen) {
44
- if (this.sheetRef.current) {
45
- this.sheetRef.current.focus();
46
- }
43
+ const Drawer = ({
44
+ animation,
45
+ children,
46
+ className,
47
+ isOpen,
48
+ onOpen,
49
+ onClose,
50
+ onDidClose,
51
+ onDidOpen
52
+ }) => {
53
+ const {
54
+ classes,
55
+ cx
56
+ } = useStyles();
57
+ const [active, setActive] = useState(isOpen);
58
+ const sheetRef = useRef(null);
59
+ const isFirstIsOpenSync = useRef(true);
60
+ const onOpenRef = useRef(onOpen);
61
+ const onCloseRef = useRef(onClose);
62
+ onOpenRef.current = onOpen;
63
+ onCloseRef.current = onClose;
64
+ useEffect(() => {
65
+ if (isFirstIsOpenSync.current) {
66
+ isFirstIsOpenSync.current = false;
67
+ return;
47
68
  }
48
- }
49
-
50
- /**
51
- * Update state when isOpen changes.
52
- * @param {Object} nextProps The next component props.
53
- */;
54
- _proto.UNSAFE_componentWillReceiveProps = function UNSAFE_componentWillReceiveProps(nextProps) {
55
- if (this.props.isOpen !== nextProps.isOpen) {
56
- if (nextProps.isOpen) {
57
- if (typeof nextProps.onOpen === 'function') {
58
- nextProps.onOpen();
59
- }
60
- this.setState({
61
- active: true
62
- });
63
- } else if (typeof nextProps.onClose === 'function') {
64
- nextProps.onClose();
65
- }
69
+ if (isOpen) {
70
+ onOpenRef.current();
71
+ setActive(true);
72
+ } else {
73
+ onCloseRef.current();
66
74
  }
67
- }
68
-
69
- /**
70
- * Set focus for a11y when sheet opens
71
- * @param {Object} prevProps The previous component props.
72
- */;
73
- _proto.componentDidUpdate = function componentDidUpdate(prevProps) {
74
- if (!prevProps.isOpen && this.props.isOpen) {
75
- if (this.sheetRef.current) {
76
- this.sheetRef.current.focus();
77
- }
75
+ }, [isOpen]);
76
+ useEffect(() => {
77
+ if (isOpen && sheetRef.current) {
78
+ sheetRef.current.focus();
78
79
  }
79
- };
80
- /**
81
- * Renders the component.
82
- * @returns {JSX}
83
- */
84
- _proto.render = function render() {
85
- const {
86
- className,
87
- children,
88
- isOpen,
89
- animation
90
- } = this.props;
91
- const {
92
- active
93
- } = this.state;
94
- const animationIn = animation.in || styles.animation.in;
95
- const animationOut = animation.out || styles.animation.out;
96
- const combinedClassName = classNames(className, styles.container, {
97
- [animationIn]: isOpen
98
- }, {
99
- [animationOut]: !isOpen
100
- }, 'common__drawer');
101
- const style = {};
102
- if (typeof animation.duration === 'number') {
103
- style.animationDuration = `${animation.duration}ms`;
80
+ }, [isOpen]);
81
+ const handleAnimationEnd = useCallback(() => {
82
+ setActive(isOpen);
83
+ if (!isOpen) {
84
+ onDidClose();
85
+ } else {
86
+ onDidOpen();
104
87
  }
105
- return active ? /*#__PURE__*/_jsx("div", {
106
- ref: this.sheetRef,
107
- className: combinedClassName,
108
- style: style,
109
- onAnimationEnd: () => {
110
- this.handleAnimationEnd();
111
- // clear any residual animation style to fix a11y issue on Android
112
- // (focus ring is misaligned)
113
- if (this.sheetRef?.style) {
114
- this.sheetRef.style.animation = '';
115
- this.sheetRef.style.transform = 'none';
116
- }
117
- },
118
- role: "dialog",
119
- "aria-modal": true,
120
- tabIndex: -1,
121
- children: children
122
- }) : null;
123
- };
124
- return Drawer;
125
- }(Component);
126
- /**
127
- * The component prop types.
128
- * @type {Object}
129
- */
130
- /**
131
- * The component default props.
132
- * @type {Object}
133
- */
88
+ }, [isOpen, onDidClose, onDidOpen]);
89
+ const animationIn = animation.in || classes.animationIn;
90
+ const animationOut = animation.out || classes.animationOut;
91
+ const combinedClassName = cx(classes.container, {
92
+ [animationIn]: isOpen
93
+ }, {
94
+ [animationOut]: !isOpen
95
+ }, className, 'common__drawer');
96
+ const style = {};
97
+ if (typeof animation.duration === 'number') {
98
+ style.animationDuration = `${animation.duration}ms`;
99
+ }
100
+ if (!active) {
101
+ return null;
102
+ }
103
+ return /*#__PURE__*/_jsx("div", {
104
+ ref: sheetRef,
105
+ className: combinedClassName,
106
+ style: style,
107
+ onAnimationEnd: () => {
108
+ handleAnimationEnd();
109
+ if (sheetRef?.current?.style) {
110
+ sheetRef.current.style.animation = '';
111
+ sheetRef.current.style.transform = 'none';
112
+ }
113
+ },
114
+ role: "dialog",
115
+ "aria-modal": true,
116
+ tabIndex: -1,
117
+ children: children
118
+ });
119
+ };
134
120
  Drawer.defaultProps = {
135
- className: '',
121
+ animation: {
122
+ duration: null,
123
+ in: '',
124
+ out: ''
125
+ },
136
126
  children: null,
127
+ className: '',
137
128
  isOpen: false,
138
129
  onOpen: () => {},
139
130
  onClose: () => {},
140
131
  onDidClose: () => {},
141
- onDidOpen: () => {},
142
- animation: {
143
- duration: null,
144
- in: '',
145
- out: ''
146
- }
132
+ onDidOpen: () => {}
147
133
  };
148
- export default Drawer;
134
+ export default /*#__PURE__*/memo(Drawer);
@@ -53,9 +53,10 @@ describe('<Drawer />', () => {
53
53
  wrapper.setProps({
54
54
  isOpen: true
55
55
  });
56
+ wrapper.update();
56
57
  expect(onOpen).toBeCalled();
57
58
  expect(onDidOpen).not.toBeCalled();
58
- wrapper.simulate('animationEnd');
59
+ wrapper.find('[role="dialog"]').simulate('animationEnd');
59
60
  expect(onDidOpen).toBeCalled();
60
61
  });
61
62
  it('should execute callback when drawer close animation did end', () => {
@@ -69,9 +70,10 @@ describe('<Drawer />', () => {
69
70
  wrapper.setProps({
70
71
  isOpen: false
71
72
  });
73
+ wrapper.update();
72
74
  expect(onClose).toBeCalled();
73
75
  expect(onDidClose).not.toBeCalled();
74
- wrapper.simulate('animationEnd');
76
+ wrapper.find('[role="dialog"]').simulate('animationEnd');
75
77
  expect(onDidClose).toBeCalled();
76
78
  });
77
79
  });
@@ -1,78 +1,62 @@
1
- import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
2
- import React, { Component } from 'react';
1
+ import React, { useState, useLayoutEffect, memo } from 'react';
3
2
  import PropTypes from 'prop-types';
3
+ import { makeStyles } from '@shopgate/engage/styles';
4
4
  import Transition from "../Transition";
5
- import styles from "./style";
6
5
  import transitions from "./transitions";
7
-
8
- /**
9
- * This component slides it's child content up or down based on it's isOpen property.
10
- * @returns {JSX}
11
- */
12
6
  import { jsx as _jsx } from "react/jsx-runtime";
13
- let Dropdown = /*#__PURE__*/function (_Component) {
14
- /**
15
- * Constructor
16
- * @param {Object} props Props of the Component
17
- */
18
- function Dropdown(props) {
19
- var _this;
20
- _this = _Component.call(this, props) || this;
21
- _this.state = {
22
- initialRender: true
23
- };
24
- return _this;
7
+ const useStyles = makeStyles()(() => ({
8
+ container: {
9
+ overflow: 'hidden'
25
10
  }
11
+ }));
26
12
 
27
- /**
28
- * Update the initialRender state if the isOpen state changes from false to true
29
- * @param {Object} nextProps The new props
30
- */
31
- _inheritsLoose(Dropdown, _Component);
32
- var _proto = Dropdown.prototype;
33
- _proto.UNSAFE_componentWillReceiveProps = function UNSAFE_componentWillReceiveProps(nextProps) {
34
- if (this.props.isOpen === false && nextProps.isOpen === true) {
35
- this.setState({
36
- initialRender: false
37
- });
13
+ /**
14
+ * This component slides its child content up or down based on its isOpen property.
15
+ * @param {Object} props Props.
16
+ * @returns {JSX.Element}
17
+ */
18
+ const Dropdown = ({
19
+ children,
20
+ className,
21
+ duration,
22
+ easing,
23
+ isOpen,
24
+ onComplete,
25
+ onStart
26
+ }) => {
27
+ const {
28
+ classes,
29
+ cx
30
+ } = useStyles();
31
+ const [initialRender, setInitialRender] = useState(true);
32
+ useLayoutEffect(() => {
33
+ if (isOpen === true) {
34
+ setInitialRender(false);
38
35
  }
36
+ }, [isOpen]);
37
+ let transitionProps;
38
+ if (isOpen && initialRender) {
39
+ transitionProps = transitions.initialOpen;
40
+ } else if (isOpen) {
41
+ transitionProps = transitions.open;
42
+ } else if (initialRender) {
43
+ transitionProps = transitions.initialClose;
44
+ } else {
45
+ transitionProps = transitions.close;
39
46
  }
40
-
41
- /**
42
- * Only update the component if isOpen changed
43
- * @param {Object} nextProps The new props
44
- * @returns {boolean}
45
- */;
46
- _proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
47
- return this.props.isOpen !== nextProps.isOpen;
48
- }
49
-
50
- /**
51
- * Renders the component.
52
- * @returns {JSX}
53
- */;
54
- _proto.render = function render() {
55
- let transitionProps;
56
- if (this.props.isOpen) {
57
- transitionProps = this.state.initialRender ? transitions.initialOpen : transitions.open;
58
- } else {
59
- transitionProps = this.state.initialRender ? transitions.initialClose : transitions.close;
60
- }
61
- return /*#__PURE__*/_jsx(Transition, {
62
- ...transitionProps,
63
- onComplete: this.props.onComplete,
64
- onStart: this.props.onStart,
65
- duration: this.props.duration,
66
- easing: this.props.easing,
67
- children: /*#__PURE__*/_jsx("div", {
68
- className: `${styles} ${this.props.className} common__dropdown`,
69
- "aria-hidden": !this.props.isOpen,
70
- children: this.props.children
71
- })
72
- });
73
- };
74
- return Dropdown;
75
- }(Component);
47
+ return /*#__PURE__*/_jsx(Transition, {
48
+ ...transitionProps,
49
+ onComplete: onComplete,
50
+ onStart: onStart,
51
+ duration: duration,
52
+ easing: easing,
53
+ children: /*#__PURE__*/_jsx("div", {
54
+ className: cx(classes.container, className, 'common__dropdown'),
55
+ "aria-hidden": !isOpen,
56
+ children: children
57
+ })
58
+ });
59
+ };
76
60
  Dropdown.defaultProps = {
77
61
  className: '',
78
62
  children: null,
@@ -82,4 +66,4 @@ Dropdown.defaultProps = {
82
66
  onComplete: () => {},
83
67
  onStart: () => {}
84
68
  };
85
- export default Dropdown;
69
+ export default /*#__PURE__*/memo(Dropdown, (prev, next) => prev.isOpen === next.isOpen);