@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,281 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import isMatch from 'lodash/isMatch';
|
|
5
|
-
import { broadcastLiveMessage } from '@shopgate/engage/a11y';
|
|
6
|
-
import { responsiveCondition } from '@shopgate/engage/styles';
|
|
7
|
-
import connect from "./connector";
|
|
8
|
-
import VariantsContext from "./context";
|
|
9
|
-
import { isCharacteristicEnabled, getSelectedValue, prepareState, selectCharacteristics } from "./helpers";
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
|
+
import { logger } from '@shopgate/engage/core/helpers';
|
|
3
|
+
import { ProductCharacteristics } from '@shopgate/engage/product/components';
|
|
10
4
|
|
|
11
5
|
/**
|
|
12
|
-
*
|
|
13
|
-
* @
|
|
14
|
-
*
|
|
6
|
+
* @deprecated Use `import { ProductCharacteristics } from '@shopgate/engage/product/components'`.
|
|
7
|
+
* @param {Object} props The component props.
|
|
8
|
+
* @returns {JSX}
|
|
15
9
|
*/
|
|
16
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Sets the refs to the characteristics selects.
|
|
26
|
-
* @param {Object} props The props to check against.
|
|
27
|
-
*/
|
|
28
|
-
_this.setRefs = props => {
|
|
29
|
-
const {
|
|
30
|
-
variants
|
|
31
|
-
} = props;
|
|
32
|
-
if (variants) {
|
|
33
|
-
variants.characteristics.forEach(char => {
|
|
34
|
-
_this.refsStore[char.id] = /*#__PURE__*/React.createRef();
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
/**
|
|
39
|
-
* Checks if all selections have been made.
|
|
40
|
-
* @return {boolean}
|
|
41
|
-
*/
|
|
42
|
-
_this.checkSelection = () => {
|
|
43
|
-
const {
|
|
44
|
-
characteristics
|
|
45
|
-
} = _this.state;
|
|
46
|
-
const {
|
|
47
|
-
variants,
|
|
48
|
-
variantId
|
|
49
|
-
} = _this.props;
|
|
50
|
-
if (!variants) {
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
const filteredValues = Object.keys(characteristics).filter(key => !!characteristics[key]);
|
|
54
|
-
const selected = !!(filteredValues.length === variants.characteristics.length && variantId);
|
|
55
|
-
if (!selected) {
|
|
56
|
-
const firstUnselected = _this.findUnselectedCharacteristic();
|
|
57
|
-
if (firstUnselected) {
|
|
58
|
-
const ref = _this.refsStore[firstUnselected.id];
|
|
59
|
-
|
|
60
|
-
// Focus the item for screen readers and broadcast a related live message.
|
|
61
|
-
ref.current.focus();
|
|
62
|
-
const option = ref.current.innerText;
|
|
63
|
-
broadcastLiveMessage('product.pick_option_first', {
|
|
64
|
-
params: {
|
|
65
|
-
option
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
if (responsiveCondition('>xs', {
|
|
69
|
-
webOnly: true
|
|
70
|
-
})) {
|
|
71
|
-
ref.current.scrollIntoView({
|
|
72
|
-
behavior: 'smooth',
|
|
73
|
-
block: 'center'
|
|
74
|
-
});
|
|
75
|
-
} else {
|
|
76
|
-
ref.current.scrollIntoView({
|
|
77
|
-
behavior: 'smooth'
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
_this.setState({
|
|
81
|
-
highlight: firstUnselected.id
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return selected;
|
|
86
|
-
};
|
|
87
|
-
_this.checkSelectedCharacteristics = () => {
|
|
88
|
-
const {
|
|
89
|
-
characteristics
|
|
90
|
-
} = _this.state;
|
|
91
|
-
const {
|
|
92
|
-
variantId,
|
|
93
|
-
variants,
|
|
94
|
-
finishTimeout
|
|
95
|
-
} = _this.props;
|
|
96
|
-
if (!variants) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
const filteredValues = Object.keys(characteristics).filter(key => !!characteristics[key]);
|
|
100
|
-
if (filteredValues.length !== variants.characteristics.length) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
const products = variants.products.filter(product => isMatch(product.characteristics, characteristics));
|
|
104
|
-
if (!products.length) {
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
if (products[0].id === variantId) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
setTimeout(() => {
|
|
111
|
-
_this.props.navigate(products[0].id);
|
|
112
|
-
}, finishTimeout);
|
|
113
|
-
};
|
|
114
|
-
/**
|
|
115
|
-
* Stores a selected characteristic into the local state.
|
|
116
|
-
* @param {Object} selection The selected item.
|
|
117
|
-
*/
|
|
118
|
-
_this.handleSelection = selection => {
|
|
119
|
-
const {
|
|
120
|
-
variants,
|
|
121
|
-
setCharacteristics
|
|
122
|
-
} = _this.props;
|
|
123
|
-
const {
|
|
124
|
-
id,
|
|
125
|
-
value
|
|
126
|
-
} = selection;
|
|
127
|
-
_this.setState(({
|
|
128
|
-
characteristics
|
|
129
|
-
}) => {
|
|
130
|
-
const state = prepareState(id, value, characteristics, variants.characteristics, variants.products);
|
|
131
|
-
setCharacteristics(state);
|
|
132
|
-
return {
|
|
133
|
-
characteristics: {
|
|
134
|
-
...state
|
|
135
|
-
},
|
|
136
|
-
highlight: null
|
|
137
|
-
};
|
|
138
|
-
}, _this.checkSelectedCharacteristics);
|
|
139
|
-
};
|
|
140
|
-
/**
|
|
141
|
-
* @param {Object} selections The selections stored in the state.
|
|
142
|
-
* @param {string} charId The current characteristic ID.
|
|
143
|
-
* @param {Array} values The characteristic values.
|
|
144
|
-
* @param {number} charIndex The characteristic index.
|
|
145
|
-
* @param {string|null} selectedValue selectedValue
|
|
146
|
-
* @return {Array}
|
|
147
|
-
*/
|
|
148
|
-
_this.buildValues = (selections, charId, values, charIndex, selectedValue) => {
|
|
149
|
-
// If this is the first characteristic then all values are selectable.
|
|
150
|
-
if (charIndex === 0) {
|
|
151
|
-
return values.map(value => ({
|
|
152
|
-
...value,
|
|
153
|
-
selectable: true,
|
|
154
|
-
selected: selectedValue === value.id
|
|
155
|
-
}));
|
|
156
|
-
}
|
|
157
|
-
const {
|
|
158
|
-
variants
|
|
159
|
-
} = _this.props;
|
|
160
|
-
const subset = {};
|
|
161
|
-
Object.keys(selections).forEach((item, index) => {
|
|
162
|
-
if (index < charIndex) {
|
|
163
|
-
subset[item] = selections[item];
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
// Filter products that match or partially match the current characteristic selection.
|
|
168
|
-
const products = variants.products.filter(({
|
|
169
|
-
characteristics
|
|
170
|
-
}) => isMatch(characteristics, subset));
|
|
171
|
-
|
|
172
|
-
// Check if any of the values are present inside any of the matching products.
|
|
173
|
-
return values.map(value => {
|
|
174
|
-
const selectable = products.some(({
|
|
175
|
-
characteristics
|
|
176
|
-
}) => isMatch(characteristics, {
|
|
177
|
-
[charId]: value.id
|
|
178
|
-
}));
|
|
179
|
-
return {
|
|
180
|
-
...value,
|
|
181
|
-
selectable,
|
|
182
|
-
selected: selectedValue === value.id
|
|
183
|
-
};
|
|
184
|
-
});
|
|
185
|
-
};
|
|
186
|
-
/**
|
|
187
|
-
* Resets the highlight state
|
|
188
|
-
*/
|
|
189
|
-
_this.resetHighlight = () => {
|
|
190
|
-
_this.setState({
|
|
191
|
-
highlight: null
|
|
192
|
-
});
|
|
193
|
-
};
|
|
194
|
-
_this.refsStore = {};
|
|
195
|
-
_this.state = {
|
|
196
|
-
highlight: null,
|
|
197
|
-
characteristics: selectCharacteristics(_props)
|
|
198
|
-
};
|
|
199
|
-
_this.setRefs(_props);
|
|
200
|
-
_props.conditioner.addConditioner('product-variants', _this.checkSelection);
|
|
201
|
-
return _this;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/** @inheritDoc */
|
|
205
|
-
_inheritsLoose(ProductCharacteristics, _Component);
|
|
206
|
-
var _proto = ProductCharacteristics.prototype;
|
|
207
|
-
_proto.componentDidMount = function componentDidMount() {
|
|
208
|
-
this.checkSelectedCharacteristics();
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* @param {Object} nextProps The next component props.
|
|
213
|
-
*/;
|
|
214
|
-
_proto.UNSAFE_componentWillReceiveProps = function UNSAFE_componentWillReceiveProps(nextProps) {
|
|
215
|
-
if (!this.props.variants && nextProps.variants) {
|
|
216
|
-
// Initialize refs and characteristics when the variants prop was updated with a valid value.
|
|
217
|
-
this.setRefs(nextProps);
|
|
218
|
-
this.setState({
|
|
219
|
-
characteristics: selectCharacteristics(nextProps)
|
|
220
|
-
}, this.checkSelectedCharacteristics);
|
|
221
|
-
}
|
|
222
|
-
};
|
|
223
|
-
/**
|
|
224
|
-
* Finds the first unselected characteristic.
|
|
225
|
-
* @return {Object|null}
|
|
226
|
-
*/
|
|
227
|
-
_proto.findUnselectedCharacteristic = function findUnselectedCharacteristic() {
|
|
228
|
-
const {
|
|
229
|
-
characteristics
|
|
230
|
-
} = this.state;
|
|
231
|
-
const unselected = this.props.variants.characteristics.filter(char => !characteristics.hasOwnProperty(char.id));
|
|
232
|
-
if (unselected.length) {
|
|
233
|
-
return unselected[0];
|
|
234
|
-
}
|
|
235
|
-
return null;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* @return {JSX}
|
|
240
|
-
*/;
|
|
241
|
-
_proto.render = function render() {
|
|
242
|
-
const {
|
|
243
|
-
characteristics
|
|
244
|
-
} = this.state;
|
|
245
|
-
const {
|
|
246
|
-
variants
|
|
247
|
-
} = this.props;
|
|
248
|
-
if (!variants) {
|
|
249
|
-
return null;
|
|
250
|
-
}
|
|
251
|
-
return /*#__PURE__*/_jsx(VariantsContext.Provider, {
|
|
252
|
-
value: this.state,
|
|
253
|
-
children: variants.characteristics.map((char, index) => {
|
|
254
|
-
const disabled = !isCharacteristicEnabled(characteristics, index);
|
|
255
|
-
const selected = getSelectedValue(char.id, characteristics);
|
|
256
|
-
const values = this.buildValues(characteristics, char.id, char.values, index, selected);
|
|
257
|
-
return this.props.render({
|
|
258
|
-
charRef: this.refsStore[char.id],
|
|
259
|
-
disabled,
|
|
260
|
-
highlight: this.state.highlight === char.id,
|
|
261
|
-
id: char.id,
|
|
262
|
-
key: char.id,
|
|
263
|
-
label: char.label,
|
|
264
|
-
swatch: !!char.swatch,
|
|
265
|
-
// BETA
|
|
266
|
-
select: this.handleSelection,
|
|
267
|
-
selected,
|
|
268
|
-
values,
|
|
269
|
-
resetHighlight: this.resetHighlight
|
|
270
|
-
});
|
|
271
|
-
})
|
|
272
|
-
});
|
|
273
|
-
};
|
|
274
|
-
return ProductCharacteristics;
|
|
275
|
-
}(Component);
|
|
276
|
-
ProductCharacteristics.defaultProps = {
|
|
277
|
-
finishTimeout: 0,
|
|
278
|
-
variantId: null,
|
|
279
|
-
variants: null
|
|
11
|
+
const DeprecatedProductCharacteristics = props => {
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
logger.warn('===== ProductCharacteristics deprecated =====\n' + 'The ProductCharacteristics component ' + '(@shopgate/pwa-common/components/ProductCharacteristics) is deprecated.\n' + 'Please use: import { ProductCharacteristics } from \'@shopgate/engage/product/components\'.\n' + '===================================');
|
|
14
|
+
}, []);
|
|
15
|
+
return /*#__PURE__*/_jsx(ProductCharacteristics, {
|
|
16
|
+
...props
|
|
17
|
+
});
|
|
280
18
|
};
|
|
281
|
-
export default
|
|
19
|
+
export default DeprecatedProductCharacteristics;
|
|
@@ -1,262 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import PropTypes from 'prop-types';
|
|
5
|
-
import { logger } from '@shopgate/pwa-core/helpers';
|
|
6
|
-
import styles from "./style";
|
|
7
|
-
import RangeSliderHandle from "./components/Handle";
|
|
8
|
-
import { generateLinearEasingCallback, generateExponentialEasingCallback, getRangeStyle, getTouchPositionX, getAbsoluteValue, getRelativeValue } from "./helper";
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
|
+
import { logger } from '@shopgate/engage/core/helpers';
|
|
3
|
+
import { RangeSlider } from '@shopgate/engage/components';
|
|
9
4
|
|
|
10
5
|
/**
|
|
11
|
-
*
|
|
12
|
-
* @
|
|
13
|
-
*
|
|
6
|
+
* @deprecated Use `import { RangeSlider } from '@shopgate/engage/components'` instead.
|
|
7
|
+
* @param {Object} props Props.
|
|
8
|
+
* @returns {JSX.Element}
|
|
14
9
|
*/
|
|
15
|
-
import { jsx as _jsx
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
_this = _Component.call(this, props) || this;
|
|
24
|
-
/**
|
|
25
|
-
* Processes touch start events on handles.
|
|
26
|
-
* @param {Object} event The touch event
|
|
27
|
-
* @param {number} index The index of the touched handle.
|
|
28
|
-
*/
|
|
29
|
-
_this.handleTouchStart = (event, index) => {
|
|
30
|
-
_this.draggedHandle = index;
|
|
31
|
-
|
|
32
|
-
// Calculate the relative offset to the handles center
|
|
33
|
-
const handleDOMElement = event.target;
|
|
34
|
-
// Get the handles bounding rectangle ...
|
|
35
|
-
const handleRect = handleDOMElement.getBoundingClientRect();
|
|
36
|
-
// ... and calculate its absolute center.
|
|
37
|
-
const handleCenterX = handleRect.left + handleDOMElement.offsetWidth / 2;
|
|
38
|
-
// Store the signed distanced between the current touch offset and the handle center.
|
|
39
|
-
_this.touchOffset = getTouchPositionX(event) - handleCenterX;
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* Processes move events on handles.
|
|
43
|
-
* @param {Object} event The touch event
|
|
44
|
-
*/
|
|
45
|
-
_this.handleTouchMove = event => {
|
|
46
|
-
if (_this.props.min === _this.props.max) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
if (_this.draggedHandle === null) {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
const {
|
|
53
|
-
offsetWidth,
|
|
54
|
-
offsetLeft
|
|
55
|
-
} = _this.domElement;
|
|
56
|
-
// Calculate the absolute offset where the element was touched...
|
|
57
|
-
let deltaX = getTouchPositionX(event) - offsetLeft - _this.touchOffset;
|
|
58
|
-
|
|
59
|
-
// ...and convert it into a relative value between [0...1].
|
|
60
|
-
deltaX = Math.max(0, Math.min(1, deltaX / offsetWidth));
|
|
61
|
-
const stateUpdate = {};
|
|
62
|
-
if (_this.draggedHandle === 1) {
|
|
63
|
-
// Right handle dragged
|
|
64
|
-
if (_this.state.rangeMin < deltaX) {
|
|
65
|
-
stateUpdate.rangeMax = Math.min(1, deltaX);
|
|
66
|
-
_this.draggedHandlePixelOffset = Math.abs(stateUpdate.rangeMax - _this.state.rangeMax);
|
|
67
|
-
} else {
|
|
68
|
-
// Not in valid range, swap handles
|
|
69
|
-
_this.draggedHandle = 0;
|
|
70
|
-
stateUpdate.rangeMax = _this.state.rangeMin;
|
|
71
|
-
stateUpdate.rangeMin = deltaX;
|
|
72
|
-
_this.draggedHandlePixelOffset = Math.abs(stateUpdate.rangeMin - _this.state.rangeMin);
|
|
73
|
-
}
|
|
74
|
-
} else if (_this.draggedHandle === 0) {
|
|
75
|
-
// Left handle dragged
|
|
76
|
-
if (_this.state.rangeMax > deltaX) {
|
|
77
|
-
stateUpdate.rangeMin = Math.max(0, deltaX);
|
|
78
|
-
_this.draggedHandlePixelOffset = Math.abs(stateUpdate.rangeMin - _this.state.rangeMin);
|
|
79
|
-
} else {
|
|
80
|
-
// Not in valid range, swap handles
|
|
81
|
-
_this.draggedHandle = 1;
|
|
82
|
-
stateUpdate.rangeMin = _this.state.rangeMax;
|
|
83
|
-
stateUpdate.rangeMax = deltaX;
|
|
84
|
-
_this.draggedHandlePixelOffset = Math.abs(stateUpdate.rangeMax - _this.state.rangeMax);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
_this.draggedHandlePixelOffset *= _this.domElement.offsetWidth;
|
|
88
|
-
_this.setState(stateUpdate, _this.triggerChangeCallback);
|
|
89
|
-
};
|
|
90
|
-
/**
|
|
91
|
-
* Processes global touch end events for handles.
|
|
92
|
-
* @param {Object} e The touch event
|
|
93
|
-
*/
|
|
94
|
-
_this.handleTouchEnd = () => {
|
|
95
|
-
_this.touchOffset = 0;
|
|
96
|
-
_this.draggedHandle = null;
|
|
97
|
-
};
|
|
98
|
-
/**
|
|
99
|
-
* Processes outer range touch end events.
|
|
100
|
-
* @param {Object} event The touch event
|
|
101
|
-
*/
|
|
102
|
-
_this.handleRangeTouch = event => {
|
|
103
|
-
const {
|
|
104
|
-
offsetWidth,
|
|
105
|
-
offsetLeft
|
|
106
|
-
} = _this.domElement;
|
|
107
|
-
const dx = (getTouchPositionX(event) - offsetLeft) / offsetWidth;
|
|
108
|
-
const d0 = Math.abs(_this.state.rangeMin - dx);
|
|
109
|
-
const d1 = Math.abs(_this.state.rangeMax - dx);
|
|
110
|
-
if (d0 < d1) {
|
|
111
|
-
_this.draggedHandle = 0;
|
|
112
|
-
} else {
|
|
113
|
-
_this.draggedHandle = 1;
|
|
114
|
-
}
|
|
115
|
-
_this.handleTouchMove(event);
|
|
116
|
-
};
|
|
117
|
-
logger.warn('===== RangeSlider deprecated =====\nThe RangeSlider component and it\'s related components (@shopgate/pwa-common/component/RangeSlider) are deprecated and will be removed in @shopgate/engage v7.0.0.\nPlease use: import { RangeSlider } from \'@shopgate/engage/components\'.\n===================================');
|
|
118
|
-
_this.draggedHandle = null; // 0 for left handle, 1 for right handle or null
|
|
119
|
-
_this.domElement = null;
|
|
120
|
-
_this.touchOffset = 0;
|
|
121
|
-
_this.draggedHandlePixelOffset = 0; // The absolute pixel delta of the last handle move event.
|
|
122
|
-
|
|
123
|
-
_this.state = _this.getRange(props);
|
|
124
|
-
return _this;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Sets the global event listeners when component mounts.
|
|
129
|
-
*/
|
|
130
|
-
_inheritsLoose(RangeSlider, _Component);
|
|
131
|
-
var _proto = RangeSlider.prototype;
|
|
132
|
-
_proto.componentDidMount = function componentDidMount() {
|
|
133
|
-
document.addEventListener('touchend', this.handleTouchEnd);
|
|
134
|
-
document.addEventListener('touchmove', this.handleTouchMove);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Updates the component properties.
|
|
139
|
-
* @param {Object} newProps The new component properties.
|
|
140
|
-
*/;
|
|
141
|
-
_proto.UNSAFE_componentWillReceiveProps = function UNSAFE_componentWillReceiveProps(newProps) {
|
|
142
|
-
this.setState(this.getRange(newProps));
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Removes the global event listeners when component unmounts.
|
|
147
|
-
*/;
|
|
148
|
-
_proto.componentWillUnmount = function componentWillUnmount() {
|
|
149
|
-
document.removeEventListener('touchend', this.handleTouchEnd);
|
|
150
|
-
document.removeEventListener('touchmove', this.handleTouchMove);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Get the easing function.
|
|
155
|
-
*/;
|
|
156
|
-
/**
|
|
157
|
-
* Get range min and max from props.
|
|
158
|
-
* @param {Object} props The component props.
|
|
159
|
-
* @returns {Object} The new state
|
|
160
|
-
*/
|
|
161
|
-
_proto.getRange = function getRange(props) {
|
|
162
|
-
const {
|
|
163
|
-
value,
|
|
164
|
-
min,
|
|
165
|
-
max
|
|
166
|
-
} = props;
|
|
167
|
-
return {
|
|
168
|
-
rangeMin: this.invertedEase(getRelativeValue(value[0], min, max)),
|
|
169
|
-
rangeMax: this.invertedEase(getRelativeValue(value[1], min, max))
|
|
170
|
-
};
|
|
171
|
-
};
|
|
172
|
-
/**
|
|
173
|
-
* Calls the change callback in case of a state update.
|
|
174
|
-
*/
|
|
175
|
-
_proto.triggerChangeCallback = function triggerChangeCallback() {
|
|
176
|
-
const {
|
|
177
|
-
value,
|
|
178
|
-
onChange,
|
|
179
|
-
min,
|
|
180
|
-
max
|
|
181
|
-
} = this.props;
|
|
182
|
-
if (!onChange) {
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
const newRange = [getAbsoluteValue(this.ease(this.state.rangeMin), min, max, true), getAbsoluteValue(this.ease(this.state.rangeMax), min, max, true)];
|
|
186
|
-
if (newRange !== value) {
|
|
187
|
-
onChange(newRange);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Creates a new handle component.
|
|
193
|
-
* @param {number} index The index of the component. Must be either 0 or 1.
|
|
194
|
-
* @returns {JSX}
|
|
195
|
-
*/;
|
|
196
|
-
_proto.makeHandle = function makeHandle(index) {
|
|
197
|
-
return /*#__PURE__*/_jsx(RangeSliderHandle, {
|
|
198
|
-
index: index,
|
|
199
|
-
onTouchStart: this.handleTouchStart,
|
|
200
|
-
active: this.draggedHandle === index,
|
|
201
|
-
classNames: this.props.classNames
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* Renders the component.
|
|
207
|
-
* @returns {JSX}
|
|
208
|
-
*/;
|
|
209
|
-
_proto.render = function render() {
|
|
210
|
-
// Calculate the animation speed.
|
|
211
|
-
const animationSpeed = Math.round(1000 / this.props.animationSpeed * this.draggedHandlePixelOffset);
|
|
212
|
-
const rangeStyle = getRangeStyle(this.state.rangeMin, this.state.rangeMax, animationSpeed > 10 ? animationSpeed : 0);
|
|
213
|
-
return /*#__PURE__*/_jsx("div", {
|
|
214
|
-
className: `${this.props.classNames.container || ''} common__range-slider`,
|
|
215
|
-
onTouchStart: this.handleRangeTouch,
|
|
216
|
-
children: /*#__PURE__*/_jsx("div", {
|
|
217
|
-
className: `${this.props.classNames.outerRange || ''} ${styles.outerRange}`,
|
|
218
|
-
ref: ref => {
|
|
219
|
-
this.domElement = ref;
|
|
220
|
-
},
|
|
221
|
-
children: /*#__PURE__*/_jsxs("div", {
|
|
222
|
-
className: `${this.props.classNames.range || ''} ${styles.range}`,
|
|
223
|
-
style: rangeStyle,
|
|
224
|
-
children: [this.makeHandle(0), this.makeHandle(1)]
|
|
225
|
-
})
|
|
226
|
-
})
|
|
227
|
-
});
|
|
228
|
-
};
|
|
229
|
-
return _createClass(RangeSlider, [{
|
|
230
|
-
key: "ease",
|
|
231
|
-
get: function () {
|
|
232
|
-
return {
|
|
233
|
-
linear: generateLinearEasingCallback(this.props.resolution),
|
|
234
|
-
exponential: generateExponentialEasingCallback(this.props.factor)
|
|
235
|
-
}[this.props.easing];
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* Get the function to invert an eased value to it's original value.
|
|
240
|
-
*/
|
|
241
|
-
}, {
|
|
242
|
-
key: "invertedEase",
|
|
243
|
-
get: function () {
|
|
244
|
-
return {
|
|
245
|
-
linear: generateLinearEasingCallback(this.props.resolution),
|
|
246
|
-
exponential: generateExponentialEasingCallback(1 / this.props.factor)
|
|
247
|
-
}[this.props.easing];
|
|
248
|
-
}
|
|
249
|
-
}]);
|
|
250
|
-
}(Component);
|
|
251
|
-
RangeSlider.defaultProps = {
|
|
252
|
-
animationSpeed: 500,
|
|
253
|
-
classNames: {},
|
|
254
|
-
easing: 'linear',
|
|
255
|
-
factor: 2,
|
|
256
|
-
max: 100,
|
|
257
|
-
min: 0,
|
|
258
|
-
resolution: 1,
|
|
259
|
-
value: [0, 100],
|
|
260
|
-
onChange: null
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
const DeprecatedRangeSlider = props => {
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
logger.warn('===== RangeSlider deprecated =====\n' + 'The RangeSlider component and its related components ' + '(@shopgate/pwa-common/components/RangeSlider) are deprecated.\n' + 'Please use: import { RangeSlider } from \'@shopgate/engage/components\'.\n' + '===================================');
|
|
14
|
+
}, []);
|
|
15
|
+
return /*#__PURE__*/_jsx(RangeSlider, {
|
|
16
|
+
...props
|
|
17
|
+
});
|
|
261
18
|
};
|
|
262
|
-
export default
|
|
19
|
+
export default DeprecatedRangeSlider;
|
|
@@ -1,6 +1,12 @@
|
|
|
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
|
+
}
|
|
9
|
+
});
|
|
4
10
|
|
|
5
11
|
/**
|
|
6
12
|
* The select item component.
|
|
@@ -8,12 +14,17 @@ import styles from "./style";
|
|
|
8
14
|
* @param {React.Children} props.children - Some content to display inside.
|
|
9
15
|
* @returns {JSX}
|
|
10
16
|
*/
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
const SelectItem = props => {
|
|
18
|
+
const {
|
|
19
|
+
classes,
|
|
20
|
+
cx
|
|
21
|
+
} = useStyles();
|
|
22
|
+
return /*#__PURE__*/_jsx("div", {
|
|
23
|
+
className: cx(classes.item, props.className),
|
|
24
|
+
onTouchEnd: () => props.onSelect(props.value, props.label),
|
|
25
|
+
children: props.label
|
|
26
|
+
});
|
|
27
|
+
};
|
|
17
28
|
|
|
18
29
|
/**
|
|
19
30
|
* The component prop types.
|