@shopgate/pwa-common 7.30.0-alpha.9 → 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 +2 -1
- 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 +16 -12
- 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 +8 -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 +5 -4
- package/components/Widgets/components/WidgetGrid/index.js +27 -19
- package/components/Widgets/components/WidgetGrid/spec.js +4 -3
- package/components/Widgets/index.js +33 -26
- package/components/Widgets/spec.js +12 -13
- 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 -5
- 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,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: {}
|
|
@@ -1,3 +1,4 @@
|
|
|
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 classNames from 'classnames';
|
|
@@ -10,26 +11,22 @@ import styles from "./style";
|
|
|
10
11
|
/**
|
|
11
12
|
* The select box component.
|
|
12
13
|
*/
|
|
13
|
-
|
|
14
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
15
|
+
let SelectBox = /*#__PURE__*/function (_Component) {
|
|
14
16
|
/**
|
|
15
17
|
* Initializes the component.
|
|
16
18
|
* @param {Object} props The components props.
|
|
17
19
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
* When dropdown animation is finished.
|
|
22
|
-
*/
|
|
23
|
-
this.onDropdownComplete = () => {
|
|
24
|
-
this.dropdownCompleted = true;
|
|
25
|
-
};
|
|
20
|
+
function SelectBox(props) {
|
|
21
|
+
var _this;
|
|
22
|
+
_this = _Component.call(this, props) || this;
|
|
26
23
|
/**
|
|
27
24
|
* Handles any interaction the user does outside of the component.
|
|
28
25
|
* In this case the select gets closed.
|
|
29
26
|
* @param {Object} event The event object.
|
|
30
27
|
*/
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
_this.handleInteractionOutside = event => {
|
|
29
|
+
_this.setState({
|
|
33
30
|
isOpen: false
|
|
34
31
|
});
|
|
35
32
|
event.preventDefault();
|
|
@@ -38,61 +35,62 @@ class SelectBox extends Component {
|
|
|
38
35
|
/**
|
|
39
36
|
* Sets the open state to true
|
|
40
37
|
*/
|
|
41
|
-
|
|
42
|
-
if (
|
|
38
|
+
_this.handleOpenList = () => {
|
|
39
|
+
if (_this.state.isOpen) {
|
|
43
40
|
return;
|
|
44
41
|
}
|
|
45
|
-
|
|
46
|
-
this.setState({
|
|
42
|
+
_this.setState({
|
|
47
43
|
isOpen: true
|
|
48
44
|
});
|
|
49
|
-
if (
|
|
50
|
-
|
|
45
|
+
if (_this.firstItemRef) {
|
|
46
|
+
_this.firstItemRef.focus();
|
|
51
47
|
}
|
|
52
48
|
};
|
|
53
49
|
/**
|
|
54
50
|
* Sets the new active selection.
|
|
55
51
|
* @param {string} value Value of the selected item.
|
|
56
52
|
*/
|
|
57
|
-
|
|
58
|
-
const selection = find(
|
|
53
|
+
_this.handleSelectionUpdate = value => {
|
|
54
|
+
const selection = find(_this.props.items, {
|
|
59
55
|
value
|
|
60
56
|
});
|
|
61
|
-
|
|
57
|
+
_this.setState({
|
|
62
58
|
selected: selection,
|
|
63
59
|
isOpen: false
|
|
64
60
|
});
|
|
65
61
|
|
|
66
62
|
// Delay the callback to make sure actions are fired after animations are done.
|
|
67
63
|
setTimeout(() => {
|
|
68
|
-
|
|
69
|
-
},
|
|
70
|
-
if (
|
|
71
|
-
|
|
64
|
+
_this.props.handleSelectionUpdate(selection.value);
|
|
65
|
+
}, _this.props.duration);
|
|
66
|
+
if (_this.controlRef) {
|
|
67
|
+
_this.controlRef.focus();
|
|
72
68
|
}
|
|
73
69
|
};
|
|
74
70
|
/** @param {HTMLElement} ref The element */
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
_this.setControlRef = ref => {
|
|
72
|
+
_this.controlRef = ref;
|
|
77
73
|
};
|
|
78
74
|
/** @param {HTMLElement} ref The element */
|
|
79
|
-
|
|
80
|
-
|
|
75
|
+
_this.setFirstItemRef = ref => {
|
|
76
|
+
_this.firstItemRef = ref;
|
|
81
77
|
};
|
|
82
|
-
|
|
83
|
-
this.state = {
|
|
78
|
+
_this.state = {
|
|
84
79
|
isOpen: false,
|
|
85
80
|
selected: find(props.items, {
|
|
86
81
|
value: props.initialValue
|
|
87
82
|
})
|
|
88
83
|
};
|
|
84
|
+
return _this;
|
|
89
85
|
}
|
|
90
86
|
|
|
91
87
|
/**
|
|
92
88
|
* Reset selected when changing the initial value.
|
|
93
89
|
* @param {Object} nextProps The next props the component will receive.
|
|
94
90
|
*/
|
|
95
|
-
|
|
91
|
+
_inheritsLoose(SelectBox, _Component);
|
|
92
|
+
var _proto = SelectBox.prototype;
|
|
93
|
+
_proto.UNSAFE_componentWillReceiveProps = function UNSAFE_componentWillReceiveProps(nextProps) {
|
|
96
94
|
if (this.props.initialValue !== nextProps.initialValue) {
|
|
97
95
|
this.setState({
|
|
98
96
|
selected: find(nextProps.items, {
|
|
@@ -100,12 +98,12 @@ class SelectBox extends Component {
|
|
|
100
98
|
})
|
|
101
99
|
});
|
|
102
100
|
}
|
|
103
|
-
}
|
|
101
|
+
};
|
|
104
102
|
/**
|
|
105
103
|
* Renders the component
|
|
106
104
|
* @returns {JSX}
|
|
107
105
|
*/
|
|
108
|
-
render() {
|
|
106
|
+
_proto.render = function render() {
|
|
109
107
|
const Icon = this.props.icon;
|
|
110
108
|
const {
|
|
111
109
|
icon,
|
|
@@ -120,54 +118,59 @@ class SelectBox extends Component {
|
|
|
120
118
|
const iconClasses = classNames(icon, {
|
|
121
119
|
[iconOpen]: this.state.isOpen && iconOpen !== null
|
|
122
120
|
});
|
|
123
|
-
return /*#__PURE__*/
|
|
121
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
124
122
|
className: `${this.props.className} common__select-box`,
|
|
125
|
-
"data-test-id": this.props.testId
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
123
|
+
"data-test-id": this.props.testId,
|
|
124
|
+
children: [/*#__PURE__*/_jsxs("button", {
|
|
125
|
+
className: button,
|
|
126
|
+
onClick: this.handleOpenList,
|
|
127
|
+
"data-test-id": buttonLabel,
|
|
128
|
+
type: "button",
|
|
129
|
+
"aria-haspopup": true,
|
|
130
|
+
"aria-expanded": this.state.isOpen ? true : null,
|
|
131
|
+
"aria-controls": buttonLabel,
|
|
132
|
+
ref: this.setControlRef,
|
|
133
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
134
|
+
className: selection,
|
|
135
|
+
children: /*#__PURE__*/_jsx(I18n.Text, {
|
|
136
|
+
string: buttonLabel
|
|
137
|
+
})
|
|
138
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
139
|
+
className: iconClasses,
|
|
140
|
+
children: /*#__PURE__*/_jsx(Icon, {})
|
|
141
|
+
})]
|
|
142
|
+
}), /*#__PURE__*/_jsx(Dropdown, {
|
|
143
|
+
className: dropdown,
|
|
144
|
+
isOpen: this.state.isOpen,
|
|
145
|
+
duration: this.props.duration,
|
|
146
|
+
children: /*#__PURE__*/_jsx("ul", {
|
|
147
|
+
role: "menu",
|
|
148
|
+
id: buttonLabel,
|
|
149
|
+
tabIndex: "-1",
|
|
150
|
+
children: this.props.items.map(item => /*#__PURE__*/_jsx(SelectBoxItem, {
|
|
151
|
+
classNames: {
|
|
152
|
+
selectItem,
|
|
153
|
+
selectItemSelected
|
|
154
|
+
},
|
|
155
|
+
wrapper: this.props.item,
|
|
156
|
+
value: item.value,
|
|
157
|
+
label: item.label,
|
|
158
|
+
handleSelectionUpdate: this.handleSelectionUpdate,
|
|
159
|
+
isSelected: buttonLabel === item.label,
|
|
160
|
+
forwardedRef: buttonLabel === item.label ? this.setFirstItemRef : null
|
|
161
|
+
}, item.value))
|
|
162
|
+
})
|
|
163
|
+
}), this.state.isOpen && /*#__PURE__*/_jsx("button", {
|
|
164
|
+
className: styles.overlay,
|
|
165
|
+
onClick: this.handleInteractionOutside,
|
|
166
|
+
onTouchMove: this.handleInteractionOutside,
|
|
167
|
+
type: "button",
|
|
168
|
+
"aria-hidden": true
|
|
169
|
+
})]
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
return SelectBox;
|
|
173
|
+
}(Component);
|
|
171
174
|
SelectBox.defaultProps = {
|
|
172
175
|
className: '',
|
|
173
176
|
classNames: {},
|