@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
|
@@ -1,15 +1,27 @@
|
|
|
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
|
|
3
|
+
import { makeStyles } from '@shopgate/engage/styles';
|
|
5
4
|
import SelectItem from "./components/Item";
|
|
6
5
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
6
|
const DEFAULT_PLACEHOLDER_TEXT = 'Select ...';
|
|
7
|
+
const useStyles = makeStyles()(() => ({
|
|
8
|
+
container: {
|
|
9
|
+
margin: 0,
|
|
10
|
+
padding: 0
|
|
11
|
+
},
|
|
12
|
+
selectHandle: {
|
|
13
|
+
float: 'right'
|
|
14
|
+
},
|
|
15
|
+
items: {
|
|
16
|
+
position: 'absolute',
|
|
17
|
+
width: '100%'
|
|
18
|
+
}
|
|
19
|
+
}));
|
|
8
20
|
|
|
9
21
|
/**
|
|
10
22
|
* Finds an item in a list of items by value.
|
|
11
|
-
* @param {Array} items
|
|
12
|
-
* @param {*} value
|
|
23
|
+
* @param {Array} items The list of items.
|
|
24
|
+
* @param {*} value The value to look for.
|
|
13
25
|
* @returns {*} The found item or undefined.
|
|
14
26
|
*/
|
|
15
27
|
const findItemByValue = (items, value) => items.filter(item => item.value === value).shift();
|
|
@@ -17,7 +29,7 @@ const findItemByValue = (items, value) => items.filter(item => item.value === va
|
|
|
17
29
|
/**
|
|
18
30
|
* Converts an item of any type (e.g. string or number)
|
|
19
31
|
* to an object representation containing value and label properties.
|
|
20
|
-
* @param {*} item
|
|
32
|
+
* @param {*} item An item of any type.
|
|
21
33
|
* @returns {Object} An object representation of the item.
|
|
22
34
|
*/
|
|
23
35
|
const normalizeItem = item => ({
|
|
@@ -27,149 +39,101 @@ const normalizeItem = item => ({
|
|
|
27
39
|
|
|
28
40
|
/**
|
|
29
41
|
* The select component.
|
|
30
|
-
* @param {Object} props
|
|
31
|
-
* @
|
|
42
|
+
* @param {Object} props Props.
|
|
43
|
+
* @returns {JSX.Element}
|
|
32
44
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
const Select = ({
|
|
46
|
+
className,
|
|
47
|
+
items,
|
|
48
|
+
onChange,
|
|
49
|
+
placeholder,
|
|
50
|
+
value
|
|
51
|
+
}) => {
|
|
52
|
+
const {
|
|
53
|
+
classes,
|
|
54
|
+
cx
|
|
55
|
+
} = useStyles();
|
|
56
|
+
const domElement = useRef(null);
|
|
57
|
+
const [selected, setSelected] = useState(() => {
|
|
58
|
+
if (!value) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
return normalizeItem(findItemByValue(items, value));
|
|
62
|
+
});
|
|
63
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
if (!value) {
|
|
66
|
+
setSelected(null);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const next = normalizeItem(findItemByValue(items, value));
|
|
70
|
+
setSelected(prev => {
|
|
71
|
+
if (!prev || prev.value !== next?.value) {
|
|
72
|
+
return next;
|
|
51
73
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
_this.setState({
|
|
61
|
-
isOpen: false
|
|
62
|
-
});
|
|
74
|
+
return prev;
|
|
75
|
+
});
|
|
76
|
+
}, [value, items]);
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
// eslint-disable-next-line require-jsdoc
|
|
79
|
+
const handleInteractionOutside = event => {
|
|
80
|
+
if (domElement.current && !domElement.current.contains(event.target)) {
|
|
81
|
+
setIsOpen(false);
|
|
63
82
|
}
|
|
64
83
|
};
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const stateUpdate = {
|
|
72
|
-
selected: {
|
|
73
|
-
label,
|
|
74
|
-
value
|
|
75
|
-
},
|
|
76
|
-
isOpen: false
|
|
77
|
-
};
|
|
78
|
-
_this.triggerChangeCallback(stateUpdate);
|
|
79
|
-
_this.setState(stateUpdate);
|
|
80
|
-
};
|
|
81
|
-
/**
|
|
82
|
-
* Toggles the open state of the component.
|
|
83
|
-
*/
|
|
84
|
-
_this.toggleOpenState = () => {
|
|
85
|
-
_this.setState(({
|
|
86
|
-
isOpen
|
|
87
|
-
}) => ({
|
|
88
|
-
isOpen: !isOpen
|
|
89
|
-
}));
|
|
90
|
-
};
|
|
91
|
-
_this.state = {
|
|
92
|
-
selected: null,
|
|
93
|
-
isOpen: false
|
|
94
|
-
};
|
|
95
|
-
_this.domElement = null;
|
|
96
|
-
if (props.value) {
|
|
97
|
-
_this.state.selected = normalizeItem(findItemByValue(props.items, props.value));
|
|
84
|
+
document.addEventListener('touchstart', handleInteractionOutside);
|
|
85
|
+
return () => document.removeEventListener('touchstart', handleInteractionOutside);
|
|
86
|
+
}, []);
|
|
87
|
+
const triggerChangeCallback = useCallback(nextSelected => {
|
|
88
|
+
if (selected && selected.value === nextSelected.value) {
|
|
89
|
+
return;
|
|
98
90
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Adds event listener when the component is mounted.
|
|
104
|
-
*/
|
|
105
|
-
_inheritsLoose(Select, _Component);
|
|
106
|
-
var _proto = Select.prototype;
|
|
107
|
-
_proto.componentDidMount = function componentDidMount() {
|
|
108
|
-
document.addEventListener('touchstart', this.handleInteractionOutside);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Updates the selected item when the value prop changes.
|
|
113
|
-
* @param {Object} nextProps - The next props.
|
|
114
|
-
*/;
|
|
115
|
-
_proto.UNSAFE_componentWillReceiveProps = function UNSAFE_componentWillReceiveProps(nextProps) {
|
|
116
|
-
if (!this.state.selected || nextProps.value !== this.state.selected.value) {
|
|
117
|
-
this.state.selected = normalizeItem(findItemByValue(nextProps.items, nextProps.value));
|
|
91
|
+
if (onChange instanceof Function) {
|
|
92
|
+
onChange(nextSelected.value);
|
|
118
93
|
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
children:
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
};
|
|
163
|
-
return Select;
|
|
164
|
-
}(Component);
|
|
165
|
-
/**
|
|
166
|
-
* The component prop types.
|
|
167
|
-
* @type {Object}
|
|
168
|
-
*/
|
|
169
|
-
/**
|
|
170
|
-
* The component default props.
|
|
171
|
-
* @type {Object}
|
|
172
|
-
*/
|
|
94
|
+
}, [onChange, selected]);
|
|
95
|
+
const handleItemSelect = useCallback((itemValue, label) => {
|
|
96
|
+
const stateUpdate = {
|
|
97
|
+
label,
|
|
98
|
+
value: itemValue
|
|
99
|
+
};
|
|
100
|
+
triggerChangeCallback(stateUpdate);
|
|
101
|
+
setSelected(stateUpdate);
|
|
102
|
+
setIsOpen(false);
|
|
103
|
+
}, [triggerChangeCallback]);
|
|
104
|
+
const toggleOpenState = useCallback(() => {
|
|
105
|
+
setIsOpen(open => !open);
|
|
106
|
+
}, []);
|
|
107
|
+
const hasSelection = selected && selected.value !== undefined;
|
|
108
|
+
const selectedLabel = hasSelection ? selected.label : placeholder;
|
|
109
|
+
const itemsMarkup = isOpen ? /*#__PURE__*/_jsx("div", {
|
|
110
|
+
className: classes.items,
|
|
111
|
+
children: items.map(item => {
|
|
112
|
+
const normalizedItem = normalizeItem(item);
|
|
113
|
+
const itemSelected = hasSelection && selected.value === normalizedItem.value;
|
|
114
|
+
return /*#__PURE__*/_jsx(SelectItem, {
|
|
115
|
+
value: normalizedItem.value,
|
|
116
|
+
label: normalizedItem.label,
|
|
117
|
+
selected: itemSelected,
|
|
118
|
+
onSelect: handleItemSelect
|
|
119
|
+
}, normalizedItem.value);
|
|
120
|
+
})
|
|
121
|
+
}) : null;
|
|
122
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
123
|
+
className: cx(classes.container, className, 'common_select'),
|
|
124
|
+
ref: domElement,
|
|
125
|
+
children: [/*#__PURE__*/_jsxs("div", {
|
|
126
|
+
onTouchStart: toggleOpenState,
|
|
127
|
+
role: "presentation",
|
|
128
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
129
|
+
children: selectedLabel
|
|
130
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
131
|
+
className: classes.selectHandle,
|
|
132
|
+
children: "\u25BE"
|
|
133
|
+
})]
|
|
134
|
+
}), itemsMarkup]
|
|
135
|
+
});
|
|
136
|
+
};
|
|
173
137
|
Select.defaultProps = {
|
|
174
138
|
className: '',
|
|
175
139
|
items: [],
|
|
@@ -177,4 +141,4 @@ Select.defaultProps = {
|
|
|
177
141
|
placeholder: DEFAULT_PLACEHOLDER_TEXT,
|
|
178
142
|
value: null
|
|
179
143
|
};
|
|
180
|
-
export default Select;
|
|
144
|
+
export default /*#__PURE__*/memo(Select);
|
|
@@ -1,22 +1,56 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { mount } from 'enzyme';
|
|
3
|
+
import { act } from 'react-dom/test-utils';
|
|
3
4
|
import Select from "./index";
|
|
4
5
|
import SelectItem from "./components/Item";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Returns whether the given Enzyme wrapper contains at least one node
|
|
9
|
+
* with a class name that ends with the provided suffix.
|
|
10
|
+
*
|
|
11
|
+
* This checks individual class tokens, so it works with elements that
|
|
12
|
+
* have multiple classes.
|
|
13
|
+
*
|
|
14
|
+
* @param {Object} wrapper Enzyme wrapper (mount or shallow result).
|
|
15
|
+
* @param {string} suffix Class name suffix to match, e.g. "-innerShadow".
|
|
16
|
+
* @returns {boolean} True if a matching node exists.
|
|
17
|
+
*/
|
|
5
18
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
19
|
+
export function containsClassWithEnding(wrapper, suffix) {
|
|
20
|
+
if (!wrapper || typeof wrapper.findWhere !== 'function' || !suffix) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
return wrapper.findWhere(node => {
|
|
24
|
+
const className = node.prop('className');
|
|
25
|
+
if (typeof className !== 'string') {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
return className.split(/\s+/).some(cls => cls.endsWith(suffix));
|
|
29
|
+
}).length > 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Helper to simulate toggling the open state by touching the handle area.
|
|
34
|
+
* @param {Object} wrapper Enzyme wrapper.
|
|
35
|
+
*/
|
|
36
|
+
const toggleOpen = wrapper => {
|
|
37
|
+
wrapper.find('[role="presentation"]').simulate('touchstart');
|
|
38
|
+
wrapper.update();
|
|
39
|
+
};
|
|
6
40
|
describe('<Select />', () => {
|
|
7
41
|
jest.useFakeTimers();
|
|
8
42
|
it('opens and closes the item list', () => {
|
|
9
|
-
const wrapper =
|
|
10
|
-
|
|
11
|
-
wrapper
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
wrapper
|
|
15
|
-
expect(wrapper
|
|
43
|
+
const wrapper = mount(/*#__PURE__*/_jsx(Select, {}));
|
|
44
|
+
expect(wrapper.find(SelectItem).length).toBe(0);
|
|
45
|
+
toggleOpen(wrapper);
|
|
46
|
+
// opened – still 0 items because no items prop
|
|
47
|
+
expect(containsClassWithEnding(wrapper, '-items')).toBe(true);
|
|
48
|
+
toggleOpen(wrapper);
|
|
49
|
+
expect(containsClassWithEnding(wrapper, '-items')).toBe(false);
|
|
16
50
|
});
|
|
17
51
|
it('renders without items', () => {
|
|
18
52
|
const wrapper = mount(/*#__PURE__*/_jsx(Select, {}));
|
|
19
|
-
wrapper
|
|
53
|
+
toggleOpen(wrapper);
|
|
20
54
|
expect(wrapper).toMatchSnapshot();
|
|
21
55
|
expect(wrapper.find(SelectItem).length).toBe(0);
|
|
22
56
|
});
|
|
@@ -33,8 +67,7 @@ describe('<Select />', () => {
|
|
|
33
67
|
const wrapper = mount(/*#__PURE__*/_jsx(Select, {
|
|
34
68
|
items: items
|
|
35
69
|
}));
|
|
36
|
-
wrapper
|
|
37
|
-
wrapper.update();
|
|
70
|
+
toggleOpen(wrapper);
|
|
38
71
|
expect(wrapper).toMatchSnapshot();
|
|
39
72
|
expect(wrapper.find(SelectItem).length).toBe(items.length);
|
|
40
73
|
});
|
|
@@ -48,8 +81,7 @@ describe('<Select />', () => {
|
|
|
48
81
|
const wrapper = mount(/*#__PURE__*/_jsx(Select, {
|
|
49
82
|
items: items
|
|
50
83
|
}));
|
|
51
|
-
wrapper
|
|
52
|
-
wrapper.update();
|
|
84
|
+
toggleOpen(wrapper);
|
|
53
85
|
expect(wrapper).toMatchSnapshot();
|
|
54
86
|
expect(wrapper.find(SelectItem).length).toBe(items.length);
|
|
55
87
|
let i = 0;
|
|
@@ -80,10 +112,11 @@ describe('<Select />', () => {
|
|
|
80
112
|
items: items,
|
|
81
113
|
onChange: callback
|
|
82
114
|
}));
|
|
83
|
-
wrapper
|
|
84
|
-
wrapper.update();
|
|
115
|
+
toggleOpen(wrapper);
|
|
85
116
|
expect(wrapper).toMatchSnapshot();
|
|
86
117
|
const node = wrapper.find(SelectItem).at(selectionIndex);
|
|
87
|
-
|
|
118
|
+
act(() => {
|
|
119
|
+
node.prop('onSelect')(node.prop('value'), node.prop('label'));
|
|
120
|
+
});
|
|
88
121
|
});
|
|
89
122
|
});
|
|
@@ -1,62 +1,60 @@
|
|
|
1
|
-
import
|
|
2
|
-
import React, { Component } from 'react';
|
|
3
|
-
import classNames from 'classnames';
|
|
1
|
+
import React, { useCallback, memo } from 'react';
|
|
4
2
|
import PropTypes from 'prop-types';
|
|
3
|
+
import { makeStyles } from '@shopgate/engage/styles';
|
|
5
4
|
import I18n from "../../../I18n";
|
|
6
|
-
import {
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
const useStyles = makeStyles()(() => ({
|
|
7
|
+
item: {
|
|
8
|
+
cursor: 'pointer'
|
|
9
|
+
}
|
|
10
|
+
}));
|
|
7
11
|
|
|
8
12
|
/**
|
|
9
13
|
* The SelectBoxItem component.
|
|
10
|
-
* @param {Object} props
|
|
11
|
-
* @returns {JSX}
|
|
14
|
+
* @param {Object} props Props.
|
|
15
|
+
* @returns {JSX.Element}
|
|
12
16
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
})
|
|
17
|
+
const SelectBoxItem = ({
|
|
18
|
+
handleSelectionUpdate,
|
|
19
|
+
isSelected,
|
|
20
|
+
label,
|
|
21
|
+
value,
|
|
22
|
+
wrapper: Wrapper,
|
|
23
|
+
classNames: classNamesProp,
|
|
24
|
+
forwardedRef
|
|
25
|
+
}) => {
|
|
26
|
+
const {
|
|
27
|
+
classes,
|
|
28
|
+
cx
|
|
29
|
+
} = useStyles();
|
|
30
|
+
const {
|
|
31
|
+
selectItem,
|
|
32
|
+
selectItemSelected
|
|
33
|
+
} = classNamesProp;
|
|
34
|
+
const onSelect = useCallback(() => {
|
|
35
|
+
handleSelectionUpdate(value);
|
|
36
|
+
}, [handleSelectionUpdate, value]);
|
|
37
|
+
return /*#__PURE__*/_jsx("li", {
|
|
38
|
+
className: cx(classes.item, {
|
|
39
|
+
[selectItemSelected]: isSelected,
|
|
40
|
+
selectItem
|
|
41
|
+
}),
|
|
42
|
+
onKeyUp: () => {},
|
|
43
|
+
onClick: onSelect,
|
|
44
|
+
"data-test-id": label,
|
|
45
|
+
role: "menuitem",
|
|
46
|
+
ref: forwardedRef,
|
|
47
|
+
tabIndex: isSelected ? '0' : '-1',
|
|
48
|
+
"aria-current": isSelected,
|
|
49
|
+
children: /*#__PURE__*/_jsx(Wrapper, {
|
|
50
|
+
children: /*#__PURE__*/_jsx(I18n.Text, {
|
|
51
|
+
string: label
|
|
53
52
|
})
|
|
54
|
-
})
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
}(Component);
|
|
53
|
+
})
|
|
54
|
+
});
|
|
55
|
+
};
|
|
58
56
|
SelectBoxItem.defaultProps = {
|
|
59
57
|
forwardedRef: null,
|
|
60
58
|
classNames: {}
|
|
61
59
|
};
|
|
62
|
-
export default SelectBoxItem;
|
|
60
|
+
export default /*#__PURE__*/memo(SelectBoxItem);
|