@shopgate/pwa-common 7.30.0-alpha.8 → 7.30.0-beta.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 +28 -13
- package/actions/app/handleUniversalLink.js +0 -2
- package/collections/AuthRoutes.js +15 -13
- package/collections/Configuration.js +11 -10
- package/collections/EmbeddedMedia.js +21 -19
- package/collections/PersistedReducers.js +11 -9
- package/collections/Redirects.js +15 -13
- package/collections/media-providers/MediaProvider.js +23 -21
- package/collections/media-providers/Vimeo.js +28 -22
- package/collections/media-providers/YouTube.js +17 -10
- package/components/Backdrop/index.js +15 -13
- package/components/Backdrop/spec.js +3 -2
- package/components/Button/index.js +41 -29
- package/components/Button/spec.js +16 -10
- package/components/Checkbox/index.js +36 -28
- package/components/Checkbox/spec.js +40 -27
- package/components/Consume/index.js +4 -1
- package/components/CountdownTimer/index.js +27 -20
- package/components/CountdownTimer/spec.js +39 -38
- package/components/Drawer/index.js +31 -23
- package/components/Drawer/spec.js +7 -6
- package/components/Dropdown/index.js +27 -18
- package/components/Ellipsis/index.js +5 -3
- package/components/Ellipsis/spec.js +5 -3
- package/components/EmbeddedMedia/index.js +9 -6
- package/components/EmbeddedMedia/spec.js +11 -2
- package/components/ErrorBoundary/index.js +26 -16
- package/components/Grid/components/Item/index.js +13 -6
- package/components/Grid/components/Item/spec.js +4 -3
- package/components/Grid/index.js +13 -6
- package/components/Grid/spec.js +4 -3
- package/components/HtmlSanitizer/index.js +42 -45
- package/components/HtmlSanitizer/spec.js +31 -21
- package/components/I18n/components/FormatDate/index.js +11 -4
- package/components/I18n/components/FormatDate/spec.js +22 -14
- package/components/I18n/components/FormatNumber/index.js +8 -6
- package/components/I18n/components/FormatNumber/spec.js +10 -5
- package/components/I18n/components/FormatPrice/index.js +5 -3
- package/components/I18n/components/FormatPrice/spec.js +22 -14
- package/components/I18n/components/FormatTime/index.js +11 -4
- package/components/I18n/components/FormatTime/spec.js +22 -14
- package/components/I18n/components/I18nProvider/index.js +18 -11
- package/components/I18n/components/I18nProvider/spec.js +2 -1
- package/components/I18n/components/Placeholder/index.js +10 -3
- package/components/I18n/components/Placeholder/spec.js +12 -5
- package/components/I18n/components/Translate/index.js +12 -8
- package/components/I18n/components/Translate/spec.js +9 -6
- package/components/Icon/index.js +2 -1
- package/components/Image/Image.js +23 -21
- package/components/Image/ImageInner.js +2 -1
- package/components/InfiniteContainer/index.js +59 -53
- package/components/InfiniteContainer/spec.js +10 -5
- package/components/Input/components/MultiLineInput.js +33 -26
- package/components/Input/components/SimpleInput.js +70 -54
- package/components/Input/index.js +7 -17
- package/components/Input/spec.js +12 -11
- package/components/KeyboardConsumer/index.js +19 -13
- package/components/Link/index.js +28 -20
- package/components/Link/spec.js +13 -9
- package/components/List/components/Item/index.js +5 -3
- package/components/List/index.js +5 -3
- package/components/List/spec.js +6 -9
- package/components/Loading/index.js +1 -3
- package/components/Modal/index.js +13 -10
- package/components/ModalContainer/spec.js +24 -20
- package/components/Picker/components/Button/index.js +18 -12
- package/components/Picker/components/List/index.js +19 -16
- package/components/Picker/components/Modal/index.js +34 -25
- package/components/Picker/index.js +44 -33
- package/components/Picker/spec.js +4 -1
- package/components/Portal/index.js +26 -17
- package/components/ProductCharacteristics/index.js +65 -57
- package/components/RangeSlider/components/Handle/index.js +7 -5
- package/components/RangeSlider/index.js +98 -84
- package/components/Route/RouteNotFound.js +30 -19
- package/components/Route/index.js +31 -21
- package/components/Router/index.js +51 -34
- package/components/ScannerContainer/index.js +17 -10
- package/components/Select/components/Item/index.js +5 -3
- package/components/Select/index.js +59 -47
- package/components/Select/spec.js +7 -6
- package/components/SelectBox/components/Item/index.js +23 -13
- package/components/SelectBox/index.js +83 -80
- package/components/SelectBox/spec.js +8 -5
- package/components/SurroundPortals/index.js +15 -11
- package/components/Swiper/components/SwiperItem/index.js +6 -5
- package/components/Swiper/components/SwiperItem/spec.js +12 -4
- package/components/Swiper/index.js +23 -20
- package/components/Toaster/index.js +4 -1
- package/components/Transition/index.js +19 -12
- package/components/Widgets/components/Widget/index.js +27 -16
- package/components/Widgets/components/Widget/spec.js +6 -5
- package/components/Widgets/components/WidgetGrid/index.js +27 -19
- package/components/Widgets/components/WidgetGrid/spec.js +5 -4
- package/components/Widgets/index.js +33 -26
- package/components/Widgets/spec.js +32 -18
- package/helpers/data/index.js +1 -1
- package/helpers/portals/portalCollection.js +13 -10
- package/helpers/redux/mutable.js +2 -2
- package/package.json +5 -6
- package/providers/loading/index.js +71 -57
- package/providers/toast/index.js +39 -28
- package/reducers/modal/index.js +1 -1
- package/store/index.js +1 -1
- package/subscriptions/helpers/buildRegisterUrl.js +1 -0
- package/components/Input/components/DateInput.js +0 -273
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
1
2
|
import "core-js/modules/es.string.replace.js";
|
|
2
3
|
import React from 'react';
|
|
3
4
|
import PropTypes from 'prop-types';
|
|
@@ -16,6 +17,7 @@ import connect from "./connector";
|
|
|
16
17
|
* Adds additional history listeners to compensate bugs and improve the behaviour within
|
|
17
18
|
* browser environments.
|
|
18
19
|
*/
|
|
20
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
19
21
|
const createBrowserListeners = () => {
|
|
20
22
|
const {
|
|
21
23
|
history
|
|
@@ -63,17 +65,18 @@ const createBrowserListeners = () => {
|
|
|
63
65
|
/**
|
|
64
66
|
* The Router component.
|
|
65
67
|
*/
|
|
66
|
-
|
|
68
|
+
let Router = /*#__PURE__*/function (_React$Component) {
|
|
67
69
|
/**
|
|
68
70
|
* @param {Object} props The component props.
|
|
69
71
|
*/
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
function Router(props) {
|
|
73
|
+
var _this;
|
|
74
|
+
_this = _React$Component.call(this, props) || this;
|
|
72
75
|
/**
|
|
73
76
|
* Updates the user initialized component state
|
|
74
77
|
*/
|
|
75
|
-
|
|
76
|
-
|
|
78
|
+
_this.setUserInitialized = () => {
|
|
79
|
+
_this.setState({
|
|
77
80
|
userInitialized: true
|
|
78
81
|
});
|
|
79
82
|
};
|
|
@@ -81,7 +84,7 @@ class Router extends React.Component {
|
|
|
81
84
|
* Determines the current location from the browser history
|
|
82
85
|
* @returns {string}
|
|
83
86
|
*/
|
|
84
|
-
|
|
87
|
+
_this.getHistoryLocation = () => {
|
|
85
88
|
const {
|
|
86
89
|
hash,
|
|
87
90
|
pathname,
|
|
@@ -93,11 +96,11 @@ class Router extends React.Component {
|
|
|
93
96
|
* Determines if the current route is a protected route
|
|
94
97
|
* @returns {null|string}
|
|
95
98
|
*/
|
|
96
|
-
|
|
99
|
+
_this.getRouteProtector = () => authRoutes.getProtector(_this.getHistoryLocation());
|
|
97
100
|
/**
|
|
98
101
|
* @param {Object} data Data for the update method
|
|
99
102
|
*/
|
|
100
|
-
|
|
103
|
+
_this.update = data => {
|
|
101
104
|
const {
|
|
102
105
|
prev,
|
|
103
106
|
next
|
|
@@ -107,12 +110,12 @@ class Router extends React.Component {
|
|
|
107
110
|
* The only change right now compared to the original component. When invoked for "onUpdate"
|
|
108
111
|
* only the updated route is passed instead of an object with prev and next.
|
|
109
112
|
*/
|
|
110
|
-
|
|
113
|
+
_this.setState({
|
|
111
114
|
updated: Date.now()
|
|
112
115
|
});
|
|
113
116
|
return;
|
|
114
117
|
}
|
|
115
|
-
|
|
118
|
+
_this.setState({
|
|
116
119
|
prev: prev ? prev.id : null,
|
|
117
120
|
next: next.id,
|
|
118
121
|
updated: Date.now()
|
|
@@ -121,22 +124,24 @@ class Router extends React.Component {
|
|
|
121
124
|
if (typeof props.history === 'function') {
|
|
122
125
|
router.constructor(props.history);
|
|
123
126
|
}
|
|
124
|
-
|
|
127
|
+
_this.contextValue = null;
|
|
128
|
+
_this.state = {
|
|
125
129
|
prev: null,
|
|
126
130
|
next: null,
|
|
127
131
|
updated: null,
|
|
128
132
|
userInitialized: false,
|
|
129
|
-
initialRouteProtected: !!
|
|
133
|
+
initialRouteProtected: !!_this.getRouteProtector()
|
|
130
134
|
};
|
|
131
|
-
UIEvents.addListener(EVENT_USER_INITIALIZED,
|
|
132
|
-
onDidPush(
|
|
133
|
-
onDidPop(
|
|
134
|
-
onDidReplace(
|
|
135
|
-
onDidReset(
|
|
136
|
-
onUpdate(
|
|
135
|
+
UIEvents.addListener(EVENT_USER_INITIALIZED, _this.setUserInitialized);
|
|
136
|
+
onDidPush(_this.update);
|
|
137
|
+
onDidPop(_this.update);
|
|
138
|
+
onDidReplace(_this.update);
|
|
139
|
+
onDidReset(_this.update);
|
|
140
|
+
onUpdate(_this.update);
|
|
137
141
|
if (hasWebBridge() || hasSGJavaScriptBridge()) {
|
|
138
142
|
createBrowserListeners();
|
|
139
143
|
}
|
|
144
|
+
return _this;
|
|
140
145
|
}
|
|
141
146
|
|
|
142
147
|
/**
|
|
@@ -144,7 +149,9 @@ class Router extends React.Component {
|
|
|
144
149
|
* @param {Object} nextState The next component state.
|
|
145
150
|
* @returns {boolean}
|
|
146
151
|
*/
|
|
147
|
-
|
|
152
|
+
_inheritsLoose(Router, _React$Component);
|
|
153
|
+
var _proto = Router.prototype;
|
|
154
|
+
_proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) {
|
|
148
155
|
const {
|
|
149
156
|
isUserLoggedIn
|
|
150
157
|
} = this.props;
|
|
@@ -159,8 +166,8 @@ class Router extends React.Component {
|
|
|
159
166
|
* Replaces the initial route with a protector if necessary
|
|
160
167
|
* @param {Object} nextProps The next component props
|
|
161
168
|
* @param {Object} nextState The next components state
|
|
162
|
-
|
|
163
|
-
UNSAFE_componentWillUpdate(nextProps, nextState) {
|
|
169
|
+
*/;
|
|
170
|
+
_proto.UNSAFE_componentWillUpdate = function UNSAFE_componentWillUpdate(nextProps, nextState) {
|
|
164
171
|
const {
|
|
165
172
|
isUserLoggedIn
|
|
166
173
|
} = nextProps;
|
|
@@ -203,6 +210,8 @@ class Router extends React.Component {
|
|
|
203
210
|
}
|
|
204
211
|
}
|
|
205
212
|
});
|
|
213
|
+
|
|
214
|
+
// eslint-disable-next-line react/no-will-update-set-state
|
|
206
215
|
this.setState({
|
|
207
216
|
initialRouteProtected: false
|
|
208
217
|
});
|
|
@@ -211,14 +220,14 @@ class Router extends React.Component {
|
|
|
211
220
|
|
|
212
221
|
/**
|
|
213
222
|
* Removes the listener for the EVENT_USER_INITIALIZED event
|
|
214
|
-
|
|
215
|
-
componentWillUnmount() {
|
|
223
|
+
*/;
|
|
224
|
+
_proto.componentWillUnmount = function componentWillUnmount() {
|
|
216
225
|
UIEvents.removeListener(EVENT_USER_INITIALIZED, this.setUserInitialized);
|
|
217
|
-
}
|
|
226
|
+
};
|
|
218
227
|
/**
|
|
219
228
|
* @returns {JSX}
|
|
220
229
|
*/
|
|
221
|
-
render() {
|
|
230
|
+
_proto.render = function render() {
|
|
222
231
|
const {
|
|
223
232
|
children
|
|
224
233
|
} = this.props;
|
|
@@ -236,15 +245,23 @@ class Router extends React.Component {
|
|
|
236
245
|
return null;
|
|
237
246
|
}
|
|
238
247
|
const stack = Array.from(routeStack.getAll());
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
+
const nextContextValue = {
|
|
249
|
+
prev,
|
|
250
|
+
next,
|
|
251
|
+
stack
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
// Only update the reference if something actually changed.
|
|
255
|
+
if (!this.contextValue || this.contextValue.prev !== prev || this.contextValue.next !== next || this.contextValue.stack !== stack) {
|
|
256
|
+
this.contextValue = nextContextValue;
|
|
257
|
+
}
|
|
258
|
+
return /*#__PURE__*/_jsx(RouterContext.Provider, {
|
|
259
|
+
value: this.contextValue,
|
|
260
|
+
children: children
|
|
261
|
+
});
|
|
262
|
+
};
|
|
263
|
+
return Router;
|
|
264
|
+
}(React.Component);
|
|
248
265
|
Router.defaultProps = {
|
|
249
266
|
history: null,
|
|
250
267
|
isUserLoggedIn: false
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
2
|
+
import { PureComponent } from 'react';
|
|
2
3
|
import PropTypes from 'prop-types';
|
|
3
4
|
import AppScanner from '@shopgate/pwa-core/classes/Scanner';
|
|
4
5
|
import connect from "./connector";
|
|
@@ -7,11 +8,16 @@ import connect from "./connector";
|
|
|
7
8
|
* Wraps the Scanner overlay with functionality to automatically open and close the scanner,
|
|
8
9
|
* as well as triggering the removal and reset of the background.
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
|
+
let ScannerContainer = /*#__PURE__*/function (_PureComponent) {
|
|
12
|
+
function ScannerContainer() {
|
|
13
|
+
return _PureComponent.apply(this, arguments) || this;
|
|
14
|
+
}
|
|
15
|
+
_inheritsLoose(ScannerContainer, _PureComponent);
|
|
16
|
+
var _proto = ScannerContainer.prototype;
|
|
11
17
|
/**
|
|
12
18
|
* Starts up the app scanner.
|
|
13
19
|
*/
|
|
14
|
-
async componentDidMount() {
|
|
20
|
+
_proto.componentDidMount = async function componentDidMount() {
|
|
15
21
|
// Avoid trying to open the scanner if the app does not support it.
|
|
16
22
|
if (!this.props.hasScannerSupport) {
|
|
17
23
|
return;
|
|
@@ -22,8 +28,8 @@ class ScannerContainer extends PureComponent {
|
|
|
22
28
|
|
|
23
29
|
/**
|
|
24
30
|
* Shut down the app scanner.
|
|
25
|
-
|
|
26
|
-
componentWillUnmount() {
|
|
31
|
+
*/;
|
|
32
|
+
_proto.componentWillUnmount = function componentWillUnmount() {
|
|
27
33
|
if (!this.props.hasScannerSupport) {
|
|
28
34
|
return;
|
|
29
35
|
}
|
|
@@ -34,11 +40,12 @@ class ScannerContainer extends PureComponent {
|
|
|
34
40
|
/**
|
|
35
41
|
* Does not render anything when the app does not support the scanner.
|
|
36
42
|
* @returns {JSX}
|
|
37
|
-
|
|
38
|
-
render() {
|
|
39
|
-
return
|
|
40
|
-
}
|
|
41
|
-
|
|
43
|
+
*/;
|
|
44
|
+
_proto.render = function render() {
|
|
45
|
+
return this.props.hasScannerSupport && this.props.children;
|
|
46
|
+
};
|
|
47
|
+
return ScannerContainer;
|
|
48
|
+
}(PureComponent);
|
|
42
49
|
ScannerContainer.defaultProps = {
|
|
43
50
|
children: null,
|
|
44
51
|
scannerDidClose: () => {},
|
|
@@ -8,10 +8,12 @@ import styles from "./style";
|
|
|
8
8
|
* @param {React.Children} props.children - Some content to display inside.
|
|
9
9
|
* @returns {JSX}
|
|
10
10
|
*/
|
|
11
|
-
|
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
const SelectItem = props => /*#__PURE__*/_jsx("div", {
|
|
12
13
|
className: `${styles} ${props.className}`,
|
|
13
|
-
onTouchEnd: () => props.onSelect(props.value, props.label)
|
|
14
|
-
|
|
14
|
+
onTouchEnd: () => props.onSelect(props.value, props.label),
|
|
15
|
+
children: props.label
|
|
16
|
+
});
|
|
15
17
|
|
|
16
18
|
/**
|
|
17
19
|
* The component prop types.
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
1
2
|
import React, { Component } from 'react';
|
|
2
3
|
import PropTypes from 'prop-types';
|
|
3
4
|
import styles from "./style";
|
|
4
5
|
import SelectItem from "./components/Item";
|
|
6
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
5
7
|
const DEFAULT_PLACEHOLDER_TEXT = 'Select ...';
|
|
6
8
|
|
|
7
9
|
/**
|
|
@@ -28,23 +30,24 @@ const normalizeItem = item => ({
|
|
|
28
30
|
* @param {Object} props - The component props.
|
|
29
31
|
* @param {React.Children} props.children - Some content to display inside.
|
|
30
32
|
*/
|
|
31
|
-
|
|
33
|
+
let Select = /*#__PURE__*/function (_Component) {
|
|
32
34
|
/**
|
|
33
35
|
* The constructor.
|
|
34
36
|
* @param {Object} props - The component props.
|
|
35
37
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
function Select(props) {
|
|
39
|
+
var _this;
|
|
40
|
+
_this = _Component.call(this, props) || this;
|
|
38
41
|
/**
|
|
39
42
|
* Triggers the onChange callback if the selected value has changed.
|
|
40
43
|
* @param {Object} nextState - The next state.
|
|
41
44
|
*/
|
|
42
|
-
|
|
43
|
-
if (
|
|
45
|
+
_this.triggerChangeCallback = nextState => {
|
|
46
|
+
if (_this.state.selected && _this.state.selected.value === nextState.selected.value) {
|
|
44
47
|
return;
|
|
45
48
|
}
|
|
46
|
-
if (
|
|
47
|
-
|
|
49
|
+
if (_this.props.onChange instanceof Function) {
|
|
50
|
+
_this.props.onChange(nextState.selected.value);
|
|
48
51
|
}
|
|
49
52
|
};
|
|
50
53
|
/**
|
|
@@ -52,9 +55,9 @@ class Select extends Component {
|
|
|
52
55
|
* In this case the select gets closed.
|
|
53
56
|
* @param {Event} event - The event of the user interaction (e.g. TouchEvent).
|
|
54
57
|
*/
|
|
55
|
-
|
|
56
|
-
if (!
|
|
57
|
-
|
|
58
|
+
_this.handleInteractionOutside = event => {
|
|
59
|
+
if (!_this.domElement.contains(event.target)) {
|
|
60
|
+
_this.setState({
|
|
58
61
|
isOpen: false
|
|
59
62
|
});
|
|
60
63
|
}
|
|
@@ -64,7 +67,7 @@ class Select extends Component {
|
|
|
64
67
|
* @param {*} value - The selected value.
|
|
65
68
|
* @param {string} label - The selected label.
|
|
66
69
|
*/
|
|
67
|
-
|
|
70
|
+
_this.handleItemSelect = (value, label) => {
|
|
68
71
|
const stateUpdate = {
|
|
69
72
|
selected: {
|
|
70
73
|
label,
|
|
@@ -72,41 +75,44 @@ class Select extends Component {
|
|
|
72
75
|
},
|
|
73
76
|
isOpen: false
|
|
74
77
|
};
|
|
75
|
-
|
|
76
|
-
|
|
78
|
+
_this.triggerChangeCallback(stateUpdate);
|
|
79
|
+
_this.setState(stateUpdate);
|
|
77
80
|
};
|
|
78
81
|
/**
|
|
79
82
|
* Toggles the open state of the component.
|
|
80
83
|
*/
|
|
81
|
-
|
|
82
|
-
|
|
84
|
+
_this.toggleOpenState = () => {
|
|
85
|
+
_this.setState(({
|
|
83
86
|
isOpen
|
|
84
87
|
}) => ({
|
|
85
88
|
isOpen: !isOpen
|
|
86
89
|
}));
|
|
87
90
|
};
|
|
88
|
-
|
|
91
|
+
_this.state = {
|
|
89
92
|
selected: null,
|
|
90
93
|
isOpen: false
|
|
91
94
|
};
|
|
92
|
-
|
|
95
|
+
_this.domElement = null;
|
|
93
96
|
if (props.value) {
|
|
94
|
-
|
|
97
|
+
_this.state.selected = normalizeItem(findItemByValue(props.items, props.value));
|
|
95
98
|
}
|
|
99
|
+
return _this;
|
|
96
100
|
}
|
|
97
101
|
|
|
98
102
|
/**
|
|
99
103
|
* Adds event listener when the component is mounted.
|
|
100
104
|
*/
|
|
101
|
-
|
|
105
|
+
_inheritsLoose(Select, _Component);
|
|
106
|
+
var _proto = Select.prototype;
|
|
107
|
+
_proto.componentDidMount = function componentDidMount() {
|
|
102
108
|
document.addEventListener('touchstart', this.handleInteractionOutside);
|
|
103
109
|
}
|
|
104
110
|
|
|
105
111
|
/**
|
|
106
112
|
* Updates the selected item when the value prop changes.
|
|
107
113
|
* @param {Object} nextProps - The next props.
|
|
108
|
-
|
|
109
|
-
UNSAFE_componentWillReceiveProps(nextProps) {
|
|
114
|
+
*/;
|
|
115
|
+
_proto.UNSAFE_componentWillReceiveProps = function UNSAFE_componentWillReceiveProps(nextProps) {
|
|
110
116
|
if (!this.state.selected || nextProps.value !== this.state.selected.value) {
|
|
111
117
|
this.state.selected = normalizeItem(findItemByValue(nextProps.items, nextProps.value));
|
|
112
118
|
}
|
|
@@ -114,42 +120,48 @@ class Select extends Component {
|
|
|
114
120
|
|
|
115
121
|
/**
|
|
116
122
|
* Removes event listener when the component will unmount.
|
|
117
|
-
|
|
118
|
-
componentWillUnmount() {
|
|
123
|
+
*/;
|
|
124
|
+
_proto.componentWillUnmount = function componentWillUnmount() {
|
|
119
125
|
document.removeEventListener('touchstart', this.handleInteractionOutside);
|
|
120
|
-
}
|
|
126
|
+
};
|
|
121
127
|
/**
|
|
122
128
|
* Renders the component.
|
|
123
129
|
* @returns {JSX}
|
|
124
130
|
*/
|
|
125
|
-
render() {
|
|
131
|
+
_proto.render = function render() {
|
|
126
132
|
const hasSelection = this.state.selected && this.state.selected.value !== undefined;
|
|
127
133
|
const selectedLabel = hasSelection ? this.state.selected.label : this.props.placeholder;
|
|
128
|
-
const items = this.state.isOpen ? /*#__PURE__*/
|
|
129
|
-
className: styles.items
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
})
|
|
140
|
-
})
|
|
141
|
-
return /*#__PURE__*/
|
|
134
|
+
const items = this.state.isOpen ? /*#__PURE__*/_jsx("div", {
|
|
135
|
+
className: styles.items,
|
|
136
|
+
children: this.props.items.map(item => {
|
|
137
|
+
const normalizedItem = normalizeItem(item);
|
|
138
|
+
const selected = hasSelection && this.state.selected.value === normalizedItem.value;
|
|
139
|
+
return /*#__PURE__*/_jsx(SelectItem, {
|
|
140
|
+
value: normalizedItem.value,
|
|
141
|
+
label: normalizedItem.label,
|
|
142
|
+
selected: selected,
|
|
143
|
+
onSelect: this.handleItemSelect
|
|
144
|
+
}, normalizedItem.value);
|
|
145
|
+
})
|
|
146
|
+
}) : null;
|
|
147
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
142
148
|
className: `${styles.container} ${this.props.className} common_select`,
|
|
143
149
|
ref: ref => {
|
|
144
150
|
this.domElement = ref;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
151
|
+
},
|
|
152
|
+
children: [/*#__PURE__*/_jsxs("div", {
|
|
153
|
+
onTouchStart: this.toggleOpenState,
|
|
154
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
155
|
+
children: selectedLabel
|
|
156
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
157
|
+
className: styles.selectHandle,
|
|
158
|
+
children: "\u25BE"
|
|
159
|
+
})]
|
|
160
|
+
}), items]
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
return Select;
|
|
164
|
+
}(Component);
|
|
153
165
|
/**
|
|
154
166
|
* The component prop types.
|
|
155
167
|
* @type {Object}
|
|
@@ -2,10 +2,11 @@ import React from 'react';
|
|
|
2
2
|
import { shallow, mount } from 'enzyme';
|
|
3
3
|
import Select from "./index";
|
|
4
4
|
import SelectItem from "./components/Item";
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
6
|
describe('<Select />', () => {
|
|
6
7
|
jest.useFakeTimers();
|
|
7
8
|
it('opens and closes the item list', () => {
|
|
8
|
-
const wrapper = shallow(/*#__PURE__*/
|
|
9
|
+
const wrapper = shallow(/*#__PURE__*/_jsx(Select, {}));
|
|
9
10
|
let previousOpenState = wrapper.state('isOpen');
|
|
10
11
|
wrapper.instance().toggleOpenState();
|
|
11
12
|
expect(wrapper.state('isOpen')).toBe(!previousOpenState);
|
|
@@ -14,14 +15,14 @@ describe('<Select />', () => {
|
|
|
14
15
|
expect(wrapper.state('isOpen')).toBe(!previousOpenState);
|
|
15
16
|
});
|
|
16
17
|
it('renders without items', () => {
|
|
17
|
-
const wrapper = mount(/*#__PURE__*/
|
|
18
|
+
const wrapper = mount(/*#__PURE__*/_jsx(Select, {}));
|
|
18
19
|
wrapper.instance().toggleOpenState();
|
|
19
20
|
expect(wrapper).toMatchSnapshot();
|
|
20
21
|
expect(wrapper.find(SelectItem).length).toBe(0);
|
|
21
22
|
});
|
|
22
23
|
it('renders with implicit items (closed)', () => {
|
|
23
24
|
const items = ['a', 'b', 'c', 'd', 'e', 'f'];
|
|
24
|
-
const wrapper = mount(/*#__PURE__*/
|
|
25
|
+
const wrapper = mount(/*#__PURE__*/_jsx(Select, {
|
|
25
26
|
items: items
|
|
26
27
|
}));
|
|
27
28
|
expect(wrapper).toMatchSnapshot();
|
|
@@ -29,7 +30,7 @@ describe('<Select />', () => {
|
|
|
29
30
|
});
|
|
30
31
|
it('renders with implicit items (opened)', () => {
|
|
31
32
|
const items = ['a', 'b', 'c', 'd', 'e', 'f'];
|
|
32
|
-
const wrapper = mount(/*#__PURE__*/
|
|
33
|
+
const wrapper = mount(/*#__PURE__*/_jsx(Select, {
|
|
33
34
|
items: items
|
|
34
35
|
}));
|
|
35
36
|
wrapper.instance().toggleOpenState();
|
|
@@ -44,7 +45,7 @@ describe('<Select />', () => {
|
|
|
44
45
|
value: 'e',
|
|
45
46
|
label: 'E'
|
|
46
47
|
}, 'f'];
|
|
47
|
-
const wrapper = mount(/*#__PURE__*/
|
|
48
|
+
const wrapper = mount(/*#__PURE__*/_jsx(Select, {
|
|
48
49
|
items: items
|
|
49
50
|
}));
|
|
50
51
|
wrapper.instance().toggleOpenState();
|
|
@@ -75,7 +76,7 @@ describe('<Select />', () => {
|
|
|
75
76
|
const callback = value => {
|
|
76
77
|
expect(value).toBe(items[selectionIndex]);
|
|
77
78
|
};
|
|
78
|
-
const wrapper = mount(/*#__PURE__*/
|
|
79
|
+
const wrapper = mount(/*#__PURE__*/_jsx(Select, {
|
|
79
80
|
items: items,
|
|
80
81
|
onChange: callback
|
|
81
82
|
}));
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
1
2
|
import React, { Component } from 'react';
|
|
2
3
|
import classNames from 'classnames';
|
|
3
4
|
import PropTypes from 'prop-types';
|
|
@@ -9,27 +10,32 @@ import { item } from "./style";
|
|
|
9
10
|
* @param {Object} props The components props.
|
|
10
11
|
* @returns {JSX}
|
|
11
12
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
let SelectBoxItem = /*#__PURE__*/function (_Component) {
|
|
15
|
+
function SelectBoxItem(...args) {
|
|
16
|
+
var _this;
|
|
17
|
+
_this = _Component.call.apply(_Component, [this].concat(args)) || this;
|
|
15
18
|
/**
|
|
16
19
|
* Calls the handleSelectionUpdate prop and prevents further events.
|
|
17
20
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
_this.handleSelectionUpdate = () => {
|
|
22
|
+
_this.props.handleSelectionUpdate(_this.props.value);
|
|
20
23
|
};
|
|
24
|
+
return _this;
|
|
21
25
|
}
|
|
26
|
+
_inheritsLoose(SelectBoxItem, _Component);
|
|
27
|
+
var _proto = SelectBoxItem.prototype;
|
|
22
28
|
/**
|
|
23
29
|
* Renders the component
|
|
24
30
|
* @returns {JSX}
|
|
25
31
|
*/
|
|
26
|
-
render() {
|
|
32
|
+
_proto.render = function render() {
|
|
27
33
|
const Wrapper = this.props.wrapper;
|
|
28
34
|
const {
|
|
29
35
|
selectItem,
|
|
30
36
|
selectItemSelected
|
|
31
37
|
} = this.props.classNames;
|
|
32
|
-
return /*#__PURE__*/
|
|
38
|
+
return /*#__PURE__*/_jsx("li", {
|
|
33
39
|
className: classNames(selectItem, item, {
|
|
34
40
|
[selectItemSelected]: this.props.isSelected
|
|
35
41
|
}),
|
|
@@ -39,12 +45,16 @@ class SelectBoxItem extends Component {
|
|
|
39
45
|
role: "menuitem",
|
|
40
46
|
ref: this.props.forwardedRef,
|
|
41
47
|
tabIndex: this.props.isSelected ? '0' : '-1',
|
|
42
|
-
"aria-current": this.props.isSelected
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
+
"aria-current": this.props.isSelected,
|
|
49
|
+
children: /*#__PURE__*/_jsx(Wrapper, {
|
|
50
|
+
children: /*#__PURE__*/_jsx(I18n.Text, {
|
|
51
|
+
string: this.props.label
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
return SelectBoxItem;
|
|
57
|
+
}(Component);
|
|
48
58
|
SelectBoxItem.defaultProps = {
|
|
49
59
|
forwardedRef: null,
|
|
50
60
|
classNames: {}
|