@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.
- 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/HtmlSanitizer/index.js +60 -7
- 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/Configuration.js +2 -1
- 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/components/Link/index.js
CHANGED
|
@@ -1,100 +1,91 @@
|
|
|
1
|
-
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
2
1
|
import "core-js/modules/es.string.replace.js";
|
|
3
|
-
import React, {
|
|
2
|
+
import React, { useCallback } from 'react';
|
|
4
3
|
import PropTypes from 'prop-types';
|
|
5
4
|
import { hasWebBridge } from '@shopgate/engage/core';
|
|
5
|
+
import { makeStyles } from '@shopgate/engage/styles';
|
|
6
6
|
import connect from "./connector";
|
|
7
|
-
import
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
const useStyles = makeStyles()({
|
|
9
|
+
link: {
|
|
10
|
+
padding: 0,
|
|
11
|
+
margin: 0,
|
|
12
|
+
border: 'none',
|
|
13
|
+
textAlign: 'left',
|
|
14
|
+
alignItems: 'stretch',
|
|
15
|
+
width: '100%',
|
|
16
|
+
cursor: 'pointer'
|
|
17
|
+
}
|
|
18
|
+
});
|
|
8
19
|
|
|
9
20
|
/**
|
|
10
21
|
* Link component.
|
|
11
22
|
* @param {Object} props Props for the component.
|
|
12
|
-
* @returns {JSX}
|
|
23
|
+
* @returns {JSX.Element}
|
|
13
24
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
const Link = ({
|
|
26
|
+
children,
|
|
27
|
+
historyPush,
|
|
28
|
+
historyReplace,
|
|
29
|
+
href,
|
|
30
|
+
'aria-hidden': ariaHidden,
|
|
31
|
+
'aria-label': ariaLabel,
|
|
32
|
+
className,
|
|
33
|
+
disabled,
|
|
34
|
+
replace,
|
|
35
|
+
role,
|
|
36
|
+
state,
|
|
37
|
+
tabIndex,
|
|
38
|
+
tag,
|
|
39
|
+
target
|
|
40
|
+
}) => {
|
|
41
|
+
const {
|
|
42
|
+
classes,
|
|
43
|
+
cx
|
|
44
|
+
} = useStyles();
|
|
45
|
+
const handleOpenLink = useCallback(e => {
|
|
46
|
+
e.preventDefault();
|
|
47
|
+
if (disabled) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const params = {
|
|
51
|
+
pathname: href,
|
|
52
|
+
state: {
|
|
53
|
+
...(state || {}),
|
|
54
|
+
...(target ? {
|
|
55
|
+
target
|
|
56
|
+
} : {})
|
|
27
57
|
}
|
|
28
|
-
const params = {
|
|
29
|
-
pathname: _this.props.href,
|
|
30
|
-
state: {
|
|
31
|
-
...(_this.props.state || {}),
|
|
32
|
-
...(_this.props.target ? {
|
|
33
|
-
target: _this.props.target
|
|
34
|
-
} : {})
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
// setTimeout prevents double click while VoiceOver is active
|
|
39
|
-
setTimeout(() => {
|
|
40
|
-
if (_this.props.replace) {
|
|
41
|
-
_this.props.historyReplace(params);
|
|
42
|
-
} else {
|
|
43
|
-
_this.props.historyPush(params);
|
|
44
|
-
}
|
|
45
|
-
}, 0);
|
|
46
58
|
};
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (event.key === 'Enter' || event.key === ' ') {
|
|
53
|
-
_this.handleOpenLink(event);
|
|
59
|
+
setTimeout(() => {
|
|
60
|
+
if (replace) {
|
|
61
|
+
historyReplace(params);
|
|
62
|
+
} else {
|
|
63
|
+
historyPush(params);
|
|
54
64
|
}
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Renders the component.
|
|
62
|
-
* @returns {JSX.Element}
|
|
63
|
-
*/
|
|
64
|
-
_proto.render = function render() {
|
|
65
|
-
const {
|
|
66
|
-
tag,
|
|
67
|
-
className,
|
|
68
|
-
href,
|
|
69
|
-
children,
|
|
70
|
-
role,
|
|
71
|
-
'aria-label': ariaLabel,
|
|
72
|
-
'aria-hidden': ariaHidden,
|
|
73
|
-
tabIndex
|
|
74
|
-
} = this.props;
|
|
75
|
-
let Tag = tag;
|
|
76
|
-
if (!hasWebBridge() && tag === 'a') {
|
|
77
|
-
/**
|
|
78
|
-
* Don't use link tags on apps. Sometimes links are really opened since the preventDefault
|
|
79
|
-
* doesn't work as expected which results in white pages.
|
|
80
|
-
*/
|
|
81
|
-
Tag = 'span';
|
|
65
|
+
}, 0);
|
|
66
|
+
}, [disabled, href, historyPush, historyReplace, replace, state, target]);
|
|
67
|
+
const handleKeyDown = useCallback(event => {
|
|
68
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
69
|
+
handleOpenLink(event);
|
|
82
70
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
71
|
+
}, [handleOpenLink]);
|
|
72
|
+
let Tag = tag;
|
|
73
|
+
if (!hasWebBridge() && tag === 'a') {
|
|
74
|
+
Tag = 'span';
|
|
75
|
+
}
|
|
76
|
+
return /*#__PURE__*/_jsx(Tag, {
|
|
77
|
+
className: cx(classes.link, className, 'common__link'),
|
|
78
|
+
onClick: handleOpenLink,
|
|
79
|
+
onKeyDown: handleKeyDown,
|
|
80
|
+
role: role,
|
|
81
|
+
"data-test-id": `link: ${href}`,
|
|
82
|
+
"aria-label": ariaLabel,
|
|
83
|
+
tabIndex: tabIndex,
|
|
84
|
+
"aria-hidden": ariaHidden,
|
|
85
|
+
href: href && Tag === 'a' ? href : null,
|
|
86
|
+
children: children
|
|
87
|
+
});
|
|
88
|
+
};
|
|
98
89
|
Link.defaultProps = {
|
|
99
90
|
'aria-hidden': null,
|
|
100
91
|
'aria-label': null,
|
|
@@ -1,30 +1,39 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import
|
|
3
|
+
import { makeStyles } from '@shopgate/engage/styles';
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
+
const useStyles = makeStyles()({
|
|
6
|
+
item: {
|
|
7
|
+
display: 'block',
|
|
8
|
+
position: 'relative'
|
|
9
|
+
},
|
|
10
|
+
unselected: {
|
|
11
|
+
zIndex: 1
|
|
12
|
+
},
|
|
13
|
+
selected: {
|
|
14
|
+
zIndex: 2
|
|
15
|
+
}
|
|
16
|
+
});
|
|
4
17
|
|
|
5
18
|
/**
|
|
6
19
|
* The ListItem component.
|
|
7
20
|
* @returns {JSX}
|
|
8
21
|
*/
|
|
9
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
22
|
const ListItem = ({
|
|
11
23
|
children,
|
|
12
24
|
className,
|
|
13
25
|
isSelected,
|
|
14
26
|
role
|
|
15
27
|
}) => {
|
|
28
|
+
const {
|
|
29
|
+
classes,
|
|
30
|
+
cx
|
|
31
|
+
} = useStyles();
|
|
16
32
|
if (!React.Children.count(children)) {
|
|
17
33
|
return null;
|
|
18
34
|
}
|
|
19
|
-
let classes = styles.item;
|
|
20
|
-
if (className) {
|
|
21
|
-
classes += ` ${className}`;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Add selected or unselected styling.
|
|
25
|
-
classes += ` common__list__list-item ${isSelected ? styles.selected : styles.unselected}`;
|
|
26
35
|
return /*#__PURE__*/_jsx("li", {
|
|
27
|
-
className: classes,
|
|
36
|
+
className: cx(classes.item, className, 'common__list__list-item', isSelected ? classes.selected : classes.unselected),
|
|
28
37
|
"data-test-id": "listItem",
|
|
29
38
|
role: role,
|
|
30
39
|
children: children
|
package/components/List/spec.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
1
|
import React from 'react';
|
|
3
2
|
import { shallow } from 'enzyme';
|
|
4
3
|
import List from "./index";
|
|
@@ -24,5 +23,4 @@ describe('<List />', () => {
|
|
|
24
23
|
expect(wrapper.find(List.Item).length).toBe(0);
|
|
25
24
|
expect(console.error).toHaveBeenCalledTimes(1);
|
|
26
25
|
});
|
|
27
|
-
});
|
|
28
|
-
/* eslint-enable no-console */
|
|
26
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../components/Loading/index.jsx"],"names":[],"mappings":";AAAA;;GAEG;AACH,4BAFY,IAAI,CAEU"}
|
|
@@ -2,8 +2,39 @@ import React, { forwardRef } from 'react';
|
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { createPortal } from 'react-dom';
|
|
4
4
|
import { useTrackModalState } from '@shopgate/engage/a11y/hooks';
|
|
5
|
-
import
|
|
6
|
-
import
|
|
5
|
+
import { makeStyles, responsiveMediaQuery } from '@shopgate/engage/styles';
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
const useStyles = makeStyles()({
|
|
8
|
+
container: {
|
|
9
|
+
position: 'fixed',
|
|
10
|
+
top: 0,
|
|
11
|
+
bottom: 0,
|
|
12
|
+
left: 0,
|
|
13
|
+
right: 0,
|
|
14
|
+
overflow: 'hidden',
|
|
15
|
+
zIndex: 2000
|
|
16
|
+
},
|
|
17
|
+
layout: {
|
|
18
|
+
display: 'flex',
|
|
19
|
+
flexDirection: 'column',
|
|
20
|
+
alignItems: 'center',
|
|
21
|
+
justifyContent: 'center',
|
|
22
|
+
height: '100%'
|
|
23
|
+
},
|
|
24
|
+
content: {
|
|
25
|
+
position: 'relative',
|
|
26
|
+
maxWidth: '100vw',
|
|
27
|
+
maxHeight: '100vh',
|
|
28
|
+
paddingTop: 'var(--safe-area-inset-top)',
|
|
29
|
+
paddingBottom: 'var(--safe-area-inset-bottom)',
|
|
30
|
+
overflowY: 'scroll',
|
|
31
|
+
[responsiveMediaQuery('>xs', {
|
|
32
|
+
webOnly: true
|
|
33
|
+
})]: {
|
|
34
|
+
overflowY: 'initial'
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
});
|
|
7
38
|
|
|
8
39
|
/**
|
|
9
40
|
* The Modal component.
|
|
@@ -11,24 +42,27 @@ import styles from "./style";
|
|
|
11
42
|
* @param {Object} props.classes The component classes.
|
|
12
43
|
* @returns {JSX.Element}
|
|
13
44
|
*/
|
|
14
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
45
|
const Modal = /*#__PURE__*/forwardRef(({
|
|
16
46
|
children,
|
|
17
|
-
classes,
|
|
47
|
+
classes: customClasses,
|
|
18
48
|
...props
|
|
19
49
|
}, ref) => {
|
|
50
|
+
const {
|
|
51
|
+
classes,
|
|
52
|
+
cx
|
|
53
|
+
} = useStyles();
|
|
20
54
|
// Track modal visibility for accessibility purposes.
|
|
21
55
|
useTrackModalState();
|
|
22
56
|
return /*#__PURE__*/createPortal(/*#__PURE__*/_jsx("div", {
|
|
23
|
-
className:
|
|
57
|
+
className: cx(classes.container, customClasses?.container, 'common__modal'),
|
|
24
58
|
role: "alertdialog",
|
|
25
59
|
"aria-modal": true,
|
|
26
60
|
...props,
|
|
27
61
|
ref: ref,
|
|
28
62
|
children: /*#__PURE__*/_jsx("div", {
|
|
29
|
-
className:
|
|
63
|
+
className: cx(classes.layout, customClasses?.layout),
|
|
30
64
|
children: /*#__PURE__*/_jsx("div", {
|
|
31
|
-
className:
|
|
65
|
+
className: cx(classes.content, customClasses?.content),
|
|
32
66
|
children: children
|
|
33
67
|
})
|
|
34
68
|
})
|
|
@@ -1,197 +1,21 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import PropTypes from 'prop-types';
|
|
5
|
-
import { ConnectedReactPortal } from '@shopgate/engage/components';
|
|
6
|
-
import { withForwardedRef } from '@shopgate/engage/core';
|
|
7
|
-
import PickerModal from "./components/Modal";
|
|
8
|
-
import PickerButton from "./components/Button";
|
|
9
|
-
import PickerList from "./components/List";
|
|
1
|
+
import React, { useEffect, forwardRef } from 'react';
|
|
2
|
+
import { logger } from '@shopgate/engage/core/helpers';
|
|
3
|
+
import { Picker } from '@shopgate/engage/components';
|
|
10
4
|
|
|
11
5
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* @param {
|
|
15
|
-
* @returns {
|
|
16
|
-
* @deprecated Use Picker from engage instead
|
|
6
|
+
* @deprecated Use `import { Picker } from '@shopgate/engage/components'` instead.
|
|
7
|
+
* @param {Object} props The component props.
|
|
8
|
+
* @param {Object} ref Forwarded ref.
|
|
9
|
+
* @returns {JSX}
|
|
17
10
|
*/
|
|
18
|
-
import { jsx as _jsx
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
...item
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
return itemDefaults;
|
|
33
|
-
}
|
|
34
|
-
return null;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Finds an item index in a list of items by value.
|
|
39
|
-
* @param {Array} items - The list of items.
|
|
40
|
-
* @param {*} value - The value to look for.
|
|
41
|
-
* @returns {number} The found item index or undefined.
|
|
42
|
-
*/
|
|
43
|
-
const findItemIndexByValue = (items, value) => items.map(normalizeItem).findIndex(item => item.value === value);
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* The picker component (acts like a selectbox).
|
|
47
|
-
* @deprecated Will be remove in Engage v7.0.0.
|
|
48
|
-
* Please use `import { Picker } from '@shopgate/engage/components'` instead.
|
|
49
|
-
*/
|
|
50
|
-
let Picker = /*#__PURE__*/function (_Component) {
|
|
51
|
-
/**
|
|
52
|
-
* The constructor.
|
|
53
|
-
* @param {Object} props - The component props.
|
|
54
|
-
*/
|
|
55
|
-
function Picker(props) {
|
|
56
|
-
var _this;
|
|
57
|
-
_this = _Component.call(this, props) || this;
|
|
58
|
-
/**
|
|
59
|
-
* Triggers the onChange callback if the selected value has changed.
|
|
60
|
-
* @param {Object} nextValue - The value the user picked.
|
|
61
|
-
*/
|
|
62
|
-
_this.triggerChangeCallback = nextValue => {
|
|
63
|
-
const nextSelectedIndex = findItemIndexByValue(_this.props.items, nextValue);
|
|
64
|
-
if (nextSelectedIndex > -1 && _this.state.selectedIndex !== nextSelectedIndex) {
|
|
65
|
-
_this.props.onChange(nextValue);
|
|
66
|
-
}
|
|
67
|
-
_this.props.onSelect(nextValue);
|
|
68
|
-
};
|
|
69
|
-
/**
|
|
70
|
-
* Triggers the onChange callback if the selected value has changed.
|
|
71
|
-
* @param {Object} nextOpenState - The value the user picked.
|
|
72
|
-
*/
|
|
73
|
-
_this.triggerCloseCallback = nextOpenState => {
|
|
74
|
-
if (_this.state.isOpen && !nextOpenState) {
|
|
75
|
-
_this.props.onClose();
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
/**
|
|
79
|
-
* Gets called when a new item is selected
|
|
80
|
-
* @param {string} value - The selected value.
|
|
81
|
-
*/
|
|
82
|
-
_this.handleItemSelect = value => {
|
|
83
|
-
_this.triggerChangeCallback(value);
|
|
84
|
-
_this.setState({
|
|
85
|
-
selectedIndex: findItemIndexByValue(_this.props.items, value)
|
|
86
|
-
});
|
|
87
|
-
};
|
|
88
|
-
/**
|
|
89
|
-
* Sets or toggles the open state of the component.
|
|
90
|
-
* @param {boolean} [open] New open state.
|
|
91
|
-
*/
|
|
92
|
-
_this.toggleOpenState = open => {
|
|
93
|
-
_this.setState(({
|
|
94
|
-
isOpen
|
|
95
|
-
}) => {
|
|
96
|
-
const nextIsOpen = typeof open === 'boolean' ? open : !isOpen;
|
|
97
|
-
_this.triggerCloseCallback(nextIsOpen);
|
|
98
|
-
return {
|
|
99
|
-
isOpen: nextIsOpen
|
|
100
|
-
};
|
|
101
|
-
});
|
|
102
|
-
};
|
|
103
|
-
_this.state = {
|
|
104
|
-
selectedIndex: findItemIndexByValue(props.items, props.value),
|
|
105
|
-
isOpen: props.isOpen
|
|
106
|
-
};
|
|
107
|
-
return _this;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Updates the selected item when the value prop changes.
|
|
112
|
-
* @param {Object} nextProps - The next props.
|
|
113
|
-
*/
|
|
114
|
-
_inheritsLoose(Picker, _Component);
|
|
115
|
-
var _proto = Picker.prototype;
|
|
116
|
-
_proto.UNSAFE_componentWillReceiveProps = function UNSAFE_componentWillReceiveProps(nextProps) {
|
|
117
|
-
// Only update if a value is present and also changed.
|
|
118
|
-
if (!this.selectedItem || nextProps.value !== this.selectedItem.value) {
|
|
119
|
-
this.setState({
|
|
120
|
-
selectedIndex: findItemIndexByValue(nextProps.items, nextProps.value)
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
if (this.props.isOpen !== nextProps.isOpen && nextProps.isOpen !== this.state.isOpen) {
|
|
124
|
-
this.setState({
|
|
125
|
-
isOpen: nextProps.isOpen
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Getter for the selected item.
|
|
132
|
-
*/;
|
|
133
|
-
/**
|
|
134
|
-
* Renders the component.
|
|
135
|
-
* @returns {JSX}
|
|
136
|
-
*/
|
|
137
|
-
_proto.render = function render() {
|
|
138
|
-
const hasSelection = !!this.selectedItem;
|
|
139
|
-
const buttonValue = hasSelection ? this.selectedItem.label : '';
|
|
140
|
-
const buttonLabel = hasSelection ? this.props.label : this.props.placeholder;
|
|
141
|
-
const buttonProps = {
|
|
142
|
-
...this.props.buttonProps,
|
|
143
|
-
label: buttonLabel,
|
|
144
|
-
value: buttonValue,
|
|
145
|
-
disabled: this.props.disabled,
|
|
146
|
-
openList: this.props.disabled ? null : () => {
|
|
147
|
-
this.toggleOpenState(true);
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
const modalProps = {
|
|
151
|
-
isOpen: this.state.isOpen,
|
|
152
|
-
duration: this.props.duration,
|
|
153
|
-
onClose: () => this.toggleOpenState(false)
|
|
154
|
-
};
|
|
155
|
-
const listProps = {
|
|
156
|
-
items: this.props.items.map(normalizeItem),
|
|
157
|
-
selectedIndex: this.state.selectedIndex,
|
|
158
|
-
onSelect: this.handleItemSelect
|
|
159
|
-
};
|
|
160
|
-
return /*#__PURE__*/_jsxs("div", {
|
|
161
|
-
role: "button",
|
|
162
|
-
className: `${this.props.className} common__picker`,
|
|
163
|
-
ref: this.props.forwardedRef,
|
|
164
|
-
tabIndex: 0,
|
|
165
|
-
"aria-haspopup": true,
|
|
166
|
-
children: [/*#__PURE__*/React.createElement(this.props.buttonComponent, buttonProps), /*#__PURE__*/_jsx(ConnectedReactPortal, {
|
|
167
|
-
isOpened: true,
|
|
168
|
-
children: /*#__PURE__*/React.createElement(this.props.modalComponent, modalProps, /*#__PURE__*/React.createElement(this.props.listComponent, listProps))
|
|
169
|
-
})]
|
|
170
|
-
});
|
|
171
|
-
};
|
|
172
|
-
return _createClass(Picker, [{
|
|
173
|
-
key: "selectedItem",
|
|
174
|
-
get: function () {
|
|
175
|
-
return normalizeItem(this.props.items[this.state.selectedIndex]);
|
|
176
|
-
}
|
|
177
|
-
}]);
|
|
178
|
-
}(Component);
|
|
179
|
-
Picker.defaultProps = {
|
|
180
|
-
buttonComponent: PickerButton,
|
|
181
|
-
buttonProps: {},
|
|
182
|
-
duration: 300,
|
|
183
|
-
disabled: false,
|
|
184
|
-
forwardedRef: null,
|
|
185
|
-
label: '',
|
|
186
|
-
listComponent: PickerList,
|
|
187
|
-
modalComponent: PickerModal,
|
|
188
|
-
className: '',
|
|
189
|
-
isOpen: false,
|
|
190
|
-
items: [],
|
|
191
|
-
onChange: () => {},
|
|
192
|
-
onClose: () => {},
|
|
193
|
-
onSelect: () => {},
|
|
194
|
-
placeholder: 'Pick ...',
|
|
195
|
-
value: null
|
|
196
|
-
};
|
|
197
|
-
export default withForwardedRef(Picker);
|
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
const DeprecatedPicker = /*#__PURE__*/forwardRef((props, ref) => {
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
logger.warn('===== Picker deprecated =====\n' + 'The Picker component ' + '(@shopgate/pwa-common/components/Picker) is deprecated.\n' + 'Please use: import { Picker } from \'@shopgate/engage/components\'.\n' + '===================================');
|
|
15
|
+
}, []);
|
|
16
|
+
return /*#__PURE__*/_jsx(Picker, {
|
|
17
|
+
...props,
|
|
18
|
+
ref: ref
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
export default DeprecatedPicker;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export default Portal;
|
|
2
|
+
/**
|
|
3
|
+
* The Portal component.
|
|
4
|
+
*/
|
|
5
|
+
declare class Portal extends React.PureComponent<any, any, any> {
|
|
6
|
+
static propTypes: {
|
|
7
|
+
name: PropTypes.Validator<string>;
|
|
8
|
+
children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
9
|
+
props: PropTypes.Requireable<PropTypes.InferProps<PropTypes.ValidationMap<any>>>;
|
|
10
|
+
};
|
|
11
|
+
static defaultProps: {
|
|
12
|
+
children: null;
|
|
13
|
+
props: null;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Constructor.
|
|
17
|
+
* @param {Object} props The component props.
|
|
18
|
+
*/
|
|
19
|
+
constructor(props: Object);
|
|
20
|
+
state: {
|
|
21
|
+
hasError: boolean;
|
|
22
|
+
};
|
|
23
|
+
components: any[];
|
|
24
|
+
/**
|
|
25
|
+
* Catches errors.
|
|
26
|
+
* @param {Error} error The caught error.
|
|
27
|
+
* @param {Object} info The stacktrace info.
|
|
28
|
+
*/
|
|
29
|
+
componentDidCatch(error: Error, info: Object): void;
|
|
30
|
+
/**
|
|
31
|
+
* Returns the portal components.
|
|
32
|
+
* @param {Object} props - The props to pass to the component.
|
|
33
|
+
* @return {Array}
|
|
34
|
+
*/
|
|
35
|
+
getRenderedComponents: (props: Object) => any[];
|
|
36
|
+
/**
|
|
37
|
+
* Returns the portal components.
|
|
38
|
+
* @param {string} name Name of the portal position
|
|
39
|
+
* @return {Array}
|
|
40
|
+
*/
|
|
41
|
+
getPortalComponents: (name: string) => any[];
|
|
42
|
+
/**
|
|
43
|
+
* Renders the component.
|
|
44
|
+
* @return {JSX}
|
|
45
|
+
*/
|
|
46
|
+
render(): JSX;
|
|
47
|
+
}
|
|
48
|
+
import React from 'react';
|
|
49
|
+
import PropTypes from 'prop-types';
|
|
50
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../components/Portal/index.jsx"],"names":[],"mappings":";AAOA;;GAEG;AACH;IACE;;;;MAIE;IAEF;;;MAGE;IAEF;;;OAGG;IACH,mBAFW,MAAM,EAUhB;IALC;;MAEC;IAED,kBAAsD;IAGxD;;;;OAIG;IACH,yBAHW,KAAK,QACL,MAAM,QAKhB;IAED;;;;OAIG;IACH,wBAAyB,OAHd,MAGmB,WAa5B;IAEF;;;;OAIG;IACH,sBAAuB,MAHZ,MAGgB,WA0CzB;IAEF;;;OAGG;IACH,UAFY,GAAG,CAiCd;CACF;kBAvJ8C,OAAO;sBAChC,YAAY"}
|