@shopgate/pwa-common 7.30.4-beta.1 → 7.31.0-alpha.2
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/App.js +0 -2
- package/actions/app/handleLink.js +1 -0
- package/collections/AuthRoutes.js +1 -0
- package/collections/PersistedReducers.js +1 -0
- package/collections/media-providers/Vimeo.js +1 -1
- package/collections/media-providers/style.js +1 -1
- package/components/Backdrop/index.js +18 -3
- package/components/Button/index.js +40 -52
- package/components/Checkbox/index.js +1 -1
- package/components/Drawer/index.js +118 -132
- package/components/Drawer/spec.js +4 -2
- package/components/Dropdown/index.js +52 -68
- package/components/Grid/components/Item/index.js +37 -40
- package/components/Grid/index.js +36 -34
- package/components/I18n/components/FormatNumber/spec.js +1 -0
- package/components/Icon/index.d.ts +36 -0
- package/components/Icon/index.d.ts.map +1 -0
- package/components/Icon/index.js +39 -28
- package/components/Image/Image.js +27 -6
- package/components/Image/ImageInner.js +32 -25
- package/components/InfiniteContainer/index.js +5 -7
- package/components/InfiniteContainer/spec.js +13 -17
- package/components/Link/index.js +75 -84
- package/components/List/components/Item/index.js +19 -10
- package/components/List/spec.js +1 -3
- package/components/Loading/index.d.ts +6 -0
- package/components/Loading/index.d.ts.map +1 -0
- package/components/Modal/index.js +41 -7
- package/components/Picker/index.js +18 -194
- package/components/Portal/index.d.ts +50 -0
- package/components/Portal/index.d.ts.map +1 -0
- package/components/ProductCharacteristics/index.js +14 -276
- package/components/RangeSlider/index.js +15 -258
- package/components/Select/components/Item/index.js +18 -7
- package/components/Select/index.js +108 -144
- package/components/Select/spec.js +49 -16
- package/components/SelectBox/components/Item/index.js +49 -51
- package/components/SelectBox/index.js +140 -160
- package/components/SurroundPortals/index.d.ts +24 -0
- package/components/SurroundPortals/index.d.ts.map +1 -0
- package/components/SurroundPortals/index.js +3 -13
- package/components/Swiper/components/SwiperItem/index.js +13 -4
- package/components/Swiper/components/SwiperItem/spec.js +3 -2
- package/components/Swiper/index.js +80 -12
- package/components/Widgets/components/Widget/index.js +54 -56
- package/components/Widgets/components/Widget/spec.js +12 -8
- package/components/Widgets/components/WidgetGrid/index.js +39 -53
- package/components/Widgets/components/WidgetGrid/spec.js +12 -8
- package/constants/Portals.d.ts +101 -0
- package/constants/Portals.d.ts.map +1 -0
- package/helpers/config/index.d.ts +94 -0
- package/helpers/config/index.d.ts.map +1 -0
- package/helpers/config/mock.d.ts +23 -0
- package/helpers/config/mock.d.ts.map +1 -0
- package/helpers/config/theme.d.ts +7 -0
- package/helpers/config/theme.d.ts.map +1 -0
- package/helpers/data/index.d.ts +35 -0
- package/helpers/data/index.d.ts.map +1 -0
- package/helpers/data/index.js +1 -0
- package/helpers/html/handleDOM.js +1 -0
- package/helpers/portals/portalCollection.d.ts +30 -0
- package/helpers/portals/portalCollection.d.ts.map +1 -0
- package/helpers/style/index.js +1 -0
- package/helpers/validation/index.d.ts +10 -0
- package/helpers/validation/index.d.ts.map +1 -0
- package/package.json +4 -3
- package/selectors/client.js +1 -0
- package/styles/reset/form.js +46 -51
- package/styles/reset/media.js +21 -19
- package/styles/reset/root.js +28 -26
- package/styles/reset/table.js +9 -7
- package/styles/reset/typography.js +24 -22
- package/subscriptions/error.js +1 -0
- package/subscriptions/helpers/handleLinks.js +1 -0
- package/subscriptions/router.js +1 -0
- package/tsconfig.build.json +16 -0
- package/tsconfig.json +3 -0
- package/components/Backdrop/style.js +0 -11
- package/components/Button/style.js +0 -6
- package/components/Drawer/style.js +0 -37
- package/components/Dropdown/style.js +0 -4
- package/components/Grid/components/Item/style.js +0 -23
- package/components/Grid/style.js +0 -14
- package/components/Icon/style.js +0 -6
- package/components/Image/style.js +0 -32
- package/components/Link/style.js +0 -10
- package/components/List/components/Item/style.js +0 -16
- package/components/Modal/style.js +0 -36
- package/components/Picker/components/Button/index.js +0 -42
- package/components/Picker/components/Button/style.js +0 -19
- package/components/Picker/components/List/index.js +0 -38
- package/components/Picker/components/List/style.js +0 -17
- package/components/Picker/components/Modal/index.js +0 -76
- package/components/Picker/components/Modal/style.js +0 -78
- package/components/Picker/spec.js +0 -88
- package/components/ProductCharacteristics/connector.js +0 -41
- package/components/ProductCharacteristics/context.js +0 -2
- package/components/ProductCharacteristics/helpers/index.js +0 -162
- package/components/RangeSlider/components/Handle/index.js +0 -34
- package/components/RangeSlider/components/Handle/style.js +0 -14
- package/components/RangeSlider/helper.js +0 -85
- package/components/RangeSlider/style.js +0 -14
- package/components/Select/components/Item/style.js +0 -4
- package/components/Select/style.js +0 -17
- package/components/SelectBox/components/Item/style.js +0 -7
- package/components/SelectBox/style.js +0 -18
- package/components/Swiper/components/SwiperItem/styles.js +0 -5
- package/components/Swiper/styles.js +0 -76
- package/components/Widgets/components/Widget/style.js +0 -27
- 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
|
/**
|
|
@@ -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 {
|
|
90
|
+
* @returns {VimeoMediaProvider}
|
|
91
91
|
*/;
|
|
92
92
|
_proto.applyIframeOptimizations = function applyIframeOptimizations(document) {
|
|
93
93
|
const iframes = this.getMediaContainers(document);
|
|
@@ -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
|
|
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 = `${
|
|
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
|
|
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
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
|
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
|
|
5
|
-
import
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
52
|
-
|
|
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
|
-
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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);
|