@shopgate/pwa-ui-shared 7.30.0-alpha.10 → 7.30.0-alpha.11
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/AccordionContainer/index.js +17 -11
- package/AccordionContainer/spec.js +12 -3
- package/ActionButton/index.js +47 -33
- package/ActionButton/spec.js +5 -1
- package/AddToCartButton/index.js +44 -33
- package/AddToCartButton/mock.js +20 -8
- package/AddToCartButton/spec.js +4 -3
- package/Availability/index.js +5 -3
- package/Availability/spec.js +6 -5
- package/Button/index.js +73 -58
- package/Button/spec.js +16 -10
- package/ButtonLink/index.js +20 -12
- package/ButtonLink/spec.js +5 -3
- package/Card/index.js +5 -3
- package/CardList/components/Item/index.js +5 -3
- package/CardList/index.js +21 -12
- package/CartTotalLine/components/Amount/index.js +10 -8
- package/CartTotalLine/components/Hint/index.js +7 -5
- package/CartTotalLine/components/Label/index.js +12 -10
- package/CartTotalLine/components/Spacer/index.js +5 -3
- package/CartTotalLine/index.js +5 -3
- package/Checkbox/index.js +6 -5
- package/Chip/index.js +28 -22
- package/Chip/spec.js +9 -6
- package/ContextMenu/ContextMenuProvider.js +5 -3
- package/ContextMenu/components/Item/index.js +14 -11
- package/ContextMenu/components/Position/index.js +20 -12
- package/ContextMenu/index.js +54 -44
- package/ContextMenu/spec.js +31 -20
- package/Dialog/components/HtmlContentDialog/index.js +9 -7
- package/Dialog/components/HtmlContentDialog/spec.js +9 -6
- package/Dialog/components/PipelineErrorDialog/index.js +106 -47
- package/Dialog/components/PipelineErrorDialog/spec.js +5 -4
- package/Dialog/components/TextMessageDialog/index.js +9 -7
- package/Dialog/components/TextMessageDialog/spec.js +9 -6
- package/Dialog/components/VariantSelectModal/index.js +7 -5
- package/Dialog/components/VariantSelectModal/spec.js +6 -3
- package/Dialog/index.js +12 -8
- package/Dialog/spec.js +7 -6
- package/DiscountBadge/index.js +10 -8
- package/DiscountBadge/spec.js +3 -2
- package/FavoritesButton/index.js +40 -31
- package/FavoritesButton/spec.js +7 -3
- package/Form/Builder/classes/ActionListener/index.js +400 -401
- package/Form/Builder/components/CheckboxElement.js +13 -5
- package/Form/Builder/components/CountryElement.js +13 -5
- package/Form/Builder/components/ProvinceElement.js +13 -5
- package/Form/Builder/components/RadioElement.js +19 -11
- package/Form/Builder/components/SelectElement.js +26 -16
- package/Form/Builder/components/TextElement.js +13 -5
- package/Form/Builder/index.js +70 -60
- package/Form/Builder/spec.js +10 -9
- package/Form/Checkbox/index.js +31 -21
- package/Form/InfoField/index.js +19 -12
- package/Form/InfoField/spec.js +4 -1
- package/Form/Password/index.js +22 -15
- package/Form/Password/spec.js +10 -5
- package/Form/RadioGroup/components/Item/index.js +34 -25
- package/Form/RadioGroup/index.js +37 -28
- package/Form/RadioGroup/spec.js +45 -31
- package/Form/Select/index.js +52 -43
- package/Form/Select/spec.js +5 -2
- package/Form/SelectContextChoices/index.js +26 -22
- package/Form/SelectContextChoices/spec.js +4 -1
- package/Form/TextField/index.js +40 -27
- package/Form/TextField/spec.js +34 -21
- package/Form/index.js +23 -15
- package/FormElement/components/ErrorText/index.js +7 -5
- package/FormElement/components/Label/index.js +6 -4
- package/FormElement/components/Placeholder/index.js +7 -5
- package/FormElement/components/Underline/index.js +8 -6
- package/FormElement/index.js +62 -46
- package/FormElement/spec.js +10 -9
- package/Glow/index.js +30 -22
- package/Glow/spec.js +6 -1
- package/IndicatorCircle/index.js +10 -8
- package/IndicatorCircle/spec.js +3 -2
- package/LoadingIndicator/index.js +8 -6
- package/Manufacturer/index.js +9 -7
- package/MessageBar/index.js +20 -17
- package/MessageBar/spec.js +6 -5
- package/NoResults/components/Icon/index.js +134 -110
- package/NoResults/index.js +27 -21
- package/Placeholder/index.js +13 -5
- package/PlaceholderLabel/index.js +2 -1
- package/PlaceholderLabel/spec.js +13 -6
- package/PlaceholderParagraph/index.js +13 -12
- package/PlaceholderParagraph/spec.js +13 -6
- package/Price/index.js +46 -28
- package/PriceInfo/index.js +2 -1
- package/PriceStriked/index.js +41 -29
- package/ProductProperties/index.js +13 -10
- package/ProgressBar/index.js +28 -19
- package/ProgressBar/spec.js +2 -1
- package/RadioButton/index.js +6 -5
- package/RadioButton/spec.js +3 -2
- package/RatingNumber/index.js +2 -1
- package/RatingStars/index.js +50 -34
- package/RatingStars/spec.js +7 -6
- package/Ripple/components/RippleAnimation/index.js +12 -10
- package/Ripple/index.js +72 -62
- package/RippleButton/index.js +44 -27
- package/RippleButton/spec.js +20 -13
- package/ScannerOverlay/components/CameraOverlay/index.js +8 -5
- package/ScannerOverlay/components/ScannerBar/components/FlashlightButton/index.js +25 -21
- package/ScannerOverlay/components/ScannerBar/components/ScannerInstructions/index.js +7 -5
- package/ScannerOverlay/components/ScannerBar/index.js +17 -12
- package/ScannerOverlay/index.js +24 -15
- package/Sheet/components/Header/components/SearchBar/index.js +35 -28
- package/Sheet/components/Header/components/SearchBar/spec.js +2 -1
- package/Sheet/components/Header/index.js +47 -34
- package/Sheet/components/Header/spec.js +2 -1
- package/Sheet/index.js +80 -65
- package/Sheet/spec.js +27 -14
- package/TaxDisclaimer/index.js +13 -10
- package/TaxDisclaimer/spec.js +3 -2
- package/TextField/components/ErrorText/index.js +7 -5
- package/TextField/components/FormElement/index.js +4 -3
- package/TextField/components/Hint/index.js +7 -5
- package/TextField/components/Label/index.js +6 -4
- package/TextField/components/Underline/index.js +8 -6
- package/TextField/index.js +102 -85
- package/TextField/spec.js +37 -23
- package/ToggleIcon/index.js +23 -15
- package/ToggleIcon/spec.js +12 -8
- package/icons/AccountBoxIcon.js +5 -4
- package/icons/AddMoreIcon.js +5 -4
- package/icons/ArrowDropIcon.js +5 -4
- package/icons/ArrowIcon.js +5 -4
- package/icons/BarcodeScannerIcon.js +5 -4
- package/icons/BoxIcon.js +5 -4
- package/icons/BrowseIcon.js +5 -4
- package/icons/BurgerIcon.js +5 -4
- package/icons/CalendarIcon.js +5 -5
- package/icons/CartCouponIcon.js +5 -4
- package/icons/CartIcon.js +5 -4
- package/icons/CartPlusIcon.js +5 -4
- package/icons/CheckIcon.js +5 -4
- package/icons/CheckedIcon.js +5 -4
- package/icons/ChevronIcon.js +5 -4
- package/icons/CreditCardIcon.js +5 -4
- package/icons/CrossIcon.js +5 -4
- package/icons/DescriptionIcon.js +5 -4
- package/icons/FilterIcon.js +5 -4
- package/icons/FlashDisabledIcon.js +5 -4
- package/icons/FlashEnabledIcon.js +5 -4
- package/icons/GridIcon.js +5 -4
- package/icons/HeartIcon.js +5 -4
- package/icons/HeartOutlineIcon.js +5 -4
- package/icons/HeartPlusIcon.js +5 -4
- package/icons/HeartPlusOutlineIcon.js +5 -4
- package/icons/HomeIcon.js +5 -4
- package/icons/InfoIcon.js +5 -4
- package/icons/InfoOutlineIcon.js +5 -4
- package/icons/ListIcon.js +5 -4
- package/icons/LocalShippingIcon.js +5 -4
- package/icons/LocationIcon.js +5 -4
- package/icons/LocatorIcon.js +5 -4
- package/icons/LockIcon.js +5 -4
- package/icons/LogoutIcon.js +5 -4
- package/icons/MagnifierIcon.js +5 -4
- package/icons/MapMarkerIcon.js +5 -4
- package/icons/MoreIcon.js +5 -4
- package/icons/MoreVertIcon.js +5 -4
- package/icons/NotificationIcon.js +5 -4
- package/icons/PersonIcon.js +5 -4
- package/icons/PhoneIcon.js +5 -4
- package/icons/PlaceholderIcon.js +5 -4
- package/icons/RadioCheckedIcon.js +5 -4
- package/icons/RadioUncheckedIcon.js +5 -4
- package/icons/SecurityIcon.js +5 -4
- package/icons/ShippingMethodIcon.js +5 -4
- package/icons/ShoppingCartIcon.js +5 -4
- package/icons/SortIcon.js +5 -4
- package/icons/StarHalfIcon.js +5 -4
- package/icons/StarIcon.js +5 -4
- package/icons/StarOutlineIcon.js +5 -4
- package/icons/StopIcon.js +5 -4
- package/icons/TickIcon.js +5 -4
- package/icons/TimeIcon.js +5 -4
- package/icons/TrashIcon.js +5 -4
- package/icons/TrashOutlineIcon.js +5 -4
- package/icons/UncheckedIcon.js +5 -4
- package/icons/ViewListIcon.js +5 -4
- package/icons/VisibilityIcon.js +5 -4
- package/icons/VisibilityOffIcon.js +5 -4
- package/icons/WarningIcon.js +5 -4
- package/package.json +7 -8
package/Form/Select/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
2
2
|
import React, { Component } from 'react';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
import classNames from 'classnames';
|
|
@@ -9,54 +9,59 @@ import styles from "./style";
|
|
|
9
9
|
/**
|
|
10
10
|
* A component that provides a styled select for user input in material design.
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
let Select = /*#__PURE__*/function (_Component) {
|
|
13
14
|
/**
|
|
14
15
|
* Creates a new text field component.
|
|
15
16
|
* @param {Object} props The component properties.
|
|
16
17
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
function Select(props) {
|
|
19
|
+
var _this;
|
|
20
|
+
_this = _Component.call(this, props) || this;
|
|
19
21
|
/**
|
|
20
22
|
* @param {string} value The entered text.
|
|
21
23
|
*/
|
|
22
|
-
|
|
24
|
+
_this.handleChange = ({
|
|
23
25
|
target
|
|
24
26
|
}) => {
|
|
25
27
|
const {
|
|
26
28
|
multiple
|
|
27
|
-
} =
|
|
29
|
+
} = _this.props;
|
|
28
30
|
let {
|
|
29
31
|
value
|
|
30
32
|
} = target;
|
|
31
33
|
if (multiple) {
|
|
32
34
|
value = Array.from(target.selectedOptions, option => option.value);
|
|
33
35
|
}
|
|
34
|
-
if (!
|
|
35
|
-
|
|
36
|
+
if (!_this.props.isControlled) {
|
|
37
|
+
_this.setState({
|
|
36
38
|
value
|
|
37
39
|
});
|
|
38
40
|
}
|
|
39
|
-
|
|
41
|
+
_this.props.onChange(value);
|
|
40
42
|
};
|
|
41
43
|
/**
|
|
42
44
|
* @param {boolean} isFocused focused
|
|
43
45
|
*/
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
_this.handleFocusChange = isFocused => {
|
|
47
|
+
_this.setState({
|
|
46
48
|
isFocused
|
|
47
49
|
});
|
|
48
50
|
};
|
|
49
|
-
|
|
51
|
+
_this.state = {
|
|
50
52
|
value: props.value,
|
|
51
53
|
isFocused: false
|
|
52
54
|
};
|
|
55
|
+
return _this;
|
|
53
56
|
}
|
|
54
57
|
|
|
55
58
|
/**
|
|
56
59
|
* Corrects the selected value to the first option when the initial value is not located within
|
|
57
60
|
* the options.
|
|
58
61
|
*/
|
|
59
|
-
|
|
62
|
+
_inheritsLoose(Select, _Component);
|
|
63
|
+
var _proto = Select.prototype;
|
|
64
|
+
_proto.componentDidMount = function componentDidMount() {
|
|
60
65
|
const {
|
|
61
66
|
multiple,
|
|
62
67
|
options
|
|
@@ -79,16 +84,16 @@ class Select extends Component {
|
|
|
79
84
|
/**
|
|
80
85
|
* Update state with new props.
|
|
81
86
|
* @param {Object} nextProps The new props.
|
|
82
|
-
|
|
83
|
-
UNSAFE_componentWillReceiveProps(nextProps) {
|
|
87
|
+
*/;
|
|
88
|
+
_proto.UNSAFE_componentWillReceiveProps = function UNSAFE_componentWillReceiveProps(nextProps) {
|
|
84
89
|
this.setState({
|
|
85
90
|
value: nextProps.value
|
|
86
91
|
});
|
|
87
|
-
}
|
|
92
|
+
};
|
|
88
93
|
/**
|
|
89
94
|
* @return {JSX.Element}
|
|
90
95
|
*/
|
|
91
|
-
render() {
|
|
96
|
+
_proto.render = function render() {
|
|
92
97
|
const {
|
|
93
98
|
name,
|
|
94
99
|
options,
|
|
@@ -109,7 +114,7 @@ class Select extends Component {
|
|
|
109
114
|
value,
|
|
110
115
|
isFocused
|
|
111
116
|
} = this.state;
|
|
112
|
-
return /*#__PURE__*/
|
|
117
|
+
return /*#__PURE__*/_jsxs(FormElement, {
|
|
113
118
|
className: `${className} ui-shared__form__select`,
|
|
114
119
|
placeholder: placeholder,
|
|
115
120
|
htmlFor: name,
|
|
@@ -120,31 +125,35 @@ class Select extends Component {
|
|
|
120
125
|
hasValue: !!value || !!options[''],
|
|
121
126
|
hasPlaceholder: !disabled || value !== '',
|
|
122
127
|
disabled: disabled,
|
|
123
|
-
showErrorText: showErrorText
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
128
|
+
showErrorText: showErrorText,
|
|
129
|
+
children: [/*#__PURE__*/_jsx("select", {
|
|
130
|
+
id: name,
|
|
131
|
+
name: name,
|
|
132
|
+
onChange: this.handleChange,
|
|
133
|
+
onFocus: () => this.handleFocusChange(true),
|
|
134
|
+
onBlur: () => this.handleFocusChange(false),
|
|
135
|
+
value: value,
|
|
136
|
+
className: classNames(styles.select, 'select'),
|
|
137
|
+
disabled: disabled,
|
|
138
|
+
required: required,
|
|
139
|
+
"aria-invalid": ariaInvalid,
|
|
140
|
+
"aria-describedby": ariaDescribedBy,
|
|
141
|
+
...(multiple && {
|
|
142
|
+
multiple,
|
|
143
|
+
size
|
|
144
|
+
}),
|
|
145
|
+
children: Object.keys(options).map(key => /*#__PURE__*/_jsx("option", {
|
|
146
|
+
className: "option",
|
|
147
|
+
value: key,
|
|
148
|
+
children: options[key]
|
|
149
|
+
}, `${name}_${key}`))
|
|
150
|
+
}), /*#__PURE__*/_jsx(Chevron, {
|
|
151
|
+
className: styles.chevron
|
|
152
|
+
})]
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
return Select;
|
|
156
|
+
}(Component);
|
|
148
157
|
Select.defaultProps = {
|
|
149
158
|
'aria-invalid': false,
|
|
150
159
|
'aria-describedby': null,
|
package/Form/Select/spec.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
2
1
|
import React from 'react';
|
|
3
2
|
import { mount } from 'enzyme';
|
|
4
3
|
import Select from "./index";
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
5
|
const inputProps = {
|
|
6
6
|
name: 'test-name'
|
|
7
7
|
};
|
|
@@ -29,7 +29,10 @@ describe('<Select />', () => {
|
|
|
29
29
|
it(test, () => {
|
|
30
30
|
const testFixtures = tests[test];
|
|
31
31
|
// eslint-disable-next-line extra-rules/no-single-line-objects
|
|
32
|
-
const wrapper = mount(/*#__PURE__*/
|
|
32
|
+
const wrapper = mount(/*#__PURE__*/_jsx(Select, {
|
|
33
|
+
...inputProps,
|
|
34
|
+
...testFixtures
|
|
35
|
+
}));
|
|
33
36
|
expect(wrapper).toMatchSnapshot();
|
|
34
37
|
});
|
|
35
38
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useState, useCallback
|
|
1
|
+
import React, { useState, useCallback } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import pick from 'lodash/pick';
|
|
4
4
|
import { i18n } from '@shopgate/engage/core';
|
|
@@ -11,6 +11,7 @@ import styles from "./style";
|
|
|
11
11
|
* @param {Object} props .
|
|
12
12
|
* @returns {JSX}
|
|
13
13
|
*/
|
|
14
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
15
|
const SelectContextChoices = ({
|
|
15
16
|
options,
|
|
16
17
|
onChange,
|
|
@@ -34,37 +35,40 @@ const SelectContextChoices = ({
|
|
|
34
35
|
// Eliminate value
|
|
35
36
|
onChange(value.filter(v => v !== key));
|
|
36
37
|
} else {
|
|
37
|
-
onChange([
|
|
38
|
+
onChange([].concat(value, [key]));
|
|
38
39
|
}
|
|
39
40
|
}, [onChange, value]);
|
|
40
41
|
const hasValue = !!value && !!value.length;
|
|
41
42
|
const values = hasValue ? Object.values(pick(options, value)) : [];
|
|
42
|
-
return /*#__PURE__*/
|
|
43
|
+
return /*#__PURE__*/_jsxs(InfoField, {
|
|
43
44
|
className: className,
|
|
44
45
|
label: label,
|
|
45
46
|
errorText: errorText,
|
|
46
47
|
showErrorText: showErrorText,
|
|
47
48
|
hasValue: true,
|
|
48
|
-
rightElement: /*#__PURE__*/
|
|
49
|
+
rightElement: /*#__PURE__*/_jsx(Chevron, {
|
|
49
50
|
className: styles.chevron
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
51
|
+
}),
|
|
52
|
+
children: [/*#__PURE__*/_jsxs("div", {
|
|
53
|
+
role: "button",
|
|
54
|
+
onClick: () => setOpened(true),
|
|
55
|
+
"aria-hidden": true,
|
|
56
|
+
tabIndex: "0",
|
|
57
|
+
className: styles.toggle,
|
|
58
|
+
children: [!hasValue && (placeholder || i18n.text('common.please_choose')), hasValue && values.join(', ')]
|
|
59
|
+
}), /*#__PURE__*/_jsx(ContextMenu, {
|
|
60
|
+
isOpened: opened,
|
|
61
|
+
onStateChange: onMenuChange,
|
|
62
|
+
showToggle: false,
|
|
63
|
+
scroll: true,
|
|
64
|
+
children: Object.keys(options).map(key => /*#__PURE__*/_jsx(ContextMenu.Item, {
|
|
65
|
+
autoClose: false,
|
|
66
|
+
onClick: () => onItemClick(key),
|
|
67
|
+
className: hasValue && value.includes(key) ? styles.itemSelected : '',
|
|
68
|
+
children: options[key]
|
|
69
|
+
}, key))
|
|
70
|
+
})]
|
|
71
|
+
});
|
|
68
72
|
};
|
|
69
73
|
SelectContextChoices.defaultProps = {
|
|
70
74
|
className: '',
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { shallow } from 'enzyme';
|
|
3
3
|
import SelectContextChoices from "./index";
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
5
|
jest.mock('@shopgate/engage/a11y/components');
|
|
5
6
|
jest.mock('@shopgate/engage/components');
|
|
6
7
|
describe('<SelectContextChoices />', () => {
|
|
@@ -26,7 +27,9 @@ describe('<SelectContextChoices />', () => {
|
|
|
26
27
|
Object.keys(tests).forEach(test => {
|
|
27
28
|
it(test, () => {
|
|
28
29
|
const testFixtures = tests[test];
|
|
29
|
-
const wrapper = shallow(/*#__PURE__*/
|
|
30
|
+
const wrapper = shallow(/*#__PURE__*/_jsx(SelectContextChoices, {
|
|
31
|
+
...testFixtures
|
|
32
|
+
}));
|
|
30
33
|
expect(wrapper).toMatchSnapshot();
|
|
31
34
|
});
|
|
32
35
|
});
|
package/Form/TextField/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
2
2
|
import React, { Component } from 'react';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
import Input from '@shopgate/pwa-common/components/Input';
|
|
@@ -9,37 +9,42 @@ import style from "./style";
|
|
|
9
9
|
/**
|
|
10
10
|
* No operational
|
|
11
11
|
*/
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
13
|
const noop = () => {};
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* TextField component
|
|
16
17
|
*/
|
|
17
|
-
|
|
18
|
+
let TextField = /*#__PURE__*/function (_Component) {
|
|
18
19
|
/**
|
|
19
20
|
* Creates a new text field component.
|
|
20
21
|
* @param {Object} props The component properties.
|
|
21
22
|
*/
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
function TextField(props) {
|
|
24
|
+
var _this;
|
|
25
|
+
_this = _Component.call(this, props) || this;
|
|
24
26
|
/**
|
|
25
27
|
* Internal focus event handler.
|
|
26
28
|
* @param {boolean} isFocused Whether the input component is focused.
|
|
27
29
|
*/
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
_this.handleFocusChange = isFocused => {
|
|
31
|
+
_this.setState({
|
|
30
32
|
isFocused
|
|
31
33
|
});
|
|
32
|
-
|
|
34
|
+
_this.props.onFocusChange(isFocused);
|
|
33
35
|
};
|
|
34
|
-
|
|
36
|
+
_this.state = {
|
|
35
37
|
isFocused: false
|
|
36
38
|
};
|
|
39
|
+
return _this;
|
|
37
40
|
}
|
|
41
|
+
_inheritsLoose(TextField, _Component);
|
|
42
|
+
var _proto = TextField.prototype;
|
|
38
43
|
/**
|
|
39
44
|
* Renders the text field.
|
|
40
45
|
* @return {JSX.Element}
|
|
41
46
|
*/
|
|
42
|
-
render() {
|
|
47
|
+
_proto.render = function render() {
|
|
43
48
|
const {
|
|
44
49
|
className,
|
|
45
50
|
placeholder,
|
|
@@ -50,7 +55,7 @@ class TextField extends Component {
|
|
|
50
55
|
hasUnderline,
|
|
51
56
|
...props
|
|
52
57
|
} = this.props;
|
|
53
|
-
return /*#__PURE__*/
|
|
58
|
+
return /*#__PURE__*/_jsx(FormElement, {
|
|
54
59
|
className: `${className} ui-shared__form__text-field`,
|
|
55
60
|
htmlFor: props.name,
|
|
56
61
|
placeholder: placeholder,
|
|
@@ -59,26 +64,34 @@ class TextField extends Component {
|
|
|
59
64
|
hasLeftElement: !!leftElement,
|
|
60
65
|
hasUnderline: hasUnderline,
|
|
61
66
|
hasValue: !!props.value,
|
|
62
|
-
isFocused: this.state.isFocused
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
isFocused: this.state.isFocused,
|
|
68
|
+
children: /*#__PURE__*/_jsxs(Grid, {
|
|
69
|
+
children: [leftElement && /*#__PURE__*/_jsx(Grid.Item, {
|
|
70
|
+
grow: 0,
|
|
71
|
+
className: style.element,
|
|
72
|
+
children: leftElement
|
|
73
|
+
}), /*#__PURE__*/_jsx(Grid.Item, {
|
|
74
|
+
grow: 1,
|
|
75
|
+
className: style.container,
|
|
76
|
+
children: /*#__PURE__*/_jsx(Input, {
|
|
77
|
+
...props,
|
|
78
|
+
onFocusChange: this.handleFocusChange,
|
|
79
|
+
className: `
|
|
72
80
|
${style[props.multiLine ? 'multiLine' : 'input']}
|
|
73
81
|
${leftElement ? style.leftOffset : ''}
|
|
74
82
|
`,
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
83
|
+
validateOnBlur: true
|
|
84
|
+
})
|
|
85
|
+
}), rightElement && /*#__PURE__*/_jsx(Grid.Item, {
|
|
86
|
+
grow: 0,
|
|
87
|
+
className: style.element,
|
|
88
|
+
children: rightElement
|
|
89
|
+
})]
|
|
90
|
+
})
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
return TextField;
|
|
94
|
+
}(Component);
|
|
82
95
|
TextField.defaultProps = {
|
|
83
96
|
attributes: null,
|
|
84
97
|
className: '',
|
package/Form/TextField/spec.js
CHANGED
|
@@ -1,35 +1,40 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
2
1
|
import React from 'react';
|
|
3
2
|
import { mount } from 'enzyme';
|
|
4
3
|
import TextField from "./index";
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
5
|
const inputProps = {
|
|
6
6
|
name: 'test-input'
|
|
7
7
|
};
|
|
8
8
|
describe('<TextField>', () => {
|
|
9
9
|
it('should render a simple text field', () => {
|
|
10
|
-
const wrapper = mount(/*#__PURE__*/
|
|
10
|
+
const wrapper = mount(/*#__PURE__*/_jsx(TextField, {
|
|
11
|
+
...inputProps
|
|
12
|
+
}));
|
|
11
13
|
expect(wrapper).toMatchSnapshot();
|
|
12
14
|
expect(wrapper.find('input').length).toBe(1);
|
|
13
15
|
});
|
|
14
16
|
it('should render the text field as password', () => {
|
|
15
|
-
const wrapper = mount(/*#__PURE__*/
|
|
17
|
+
const wrapper = mount(/*#__PURE__*/_jsx(TextField, {
|
|
18
|
+
...inputProps,
|
|
16
19
|
password: true
|
|
17
|
-
}))
|
|
20
|
+
}));
|
|
18
21
|
expect(wrapper).toMatchSnapshot();
|
|
19
22
|
expect(wrapper.find('input[type="password"]').length).toBe(1);
|
|
20
23
|
});
|
|
21
24
|
it('should render the text field with a default value', () => {
|
|
22
|
-
const wrapper = mount(/*#__PURE__*/
|
|
25
|
+
const wrapper = mount(/*#__PURE__*/_jsx(TextField, {
|
|
26
|
+
...inputProps,
|
|
23
27
|
value: "FooBar"
|
|
24
|
-
}))
|
|
28
|
+
}));
|
|
25
29
|
expect(wrapper).toMatchSnapshot();
|
|
26
30
|
expect(wrapper.find('input[value="FooBar"]').length).toBe(1);
|
|
27
31
|
});
|
|
28
32
|
it('should trigger the onChange callback', () => {
|
|
29
33
|
const onChangeMock = jest.fn();
|
|
30
|
-
const wrapper = mount(/*#__PURE__*/
|
|
34
|
+
const wrapper = mount(/*#__PURE__*/_jsx(TextField, {
|
|
35
|
+
...inputProps,
|
|
31
36
|
onChange: onChangeMock
|
|
32
|
-
}))
|
|
37
|
+
}));
|
|
33
38
|
wrapper.find('input').simulate('change', {
|
|
34
39
|
target: {
|
|
35
40
|
value: 'a'
|
|
@@ -39,7 +44,9 @@ describe('<TextField>', () => {
|
|
|
39
44
|
expect(wrapper.find('input').props().value).toEqual('a');
|
|
40
45
|
});
|
|
41
46
|
it('should receive the correct value while typing', () => {
|
|
42
|
-
const wrapper = mount(/*#__PURE__*/
|
|
47
|
+
const wrapper = mount(/*#__PURE__*/_jsx(TextField, {
|
|
48
|
+
...inputProps
|
|
49
|
+
}));
|
|
43
50
|
const input = wrapper.find('input');
|
|
44
51
|
input.simulate('change', {
|
|
45
52
|
target: {
|
|
@@ -50,9 +57,10 @@ describe('<TextField>', () => {
|
|
|
50
57
|
expect(input.instance().value).toBe('foobar');
|
|
51
58
|
});
|
|
52
59
|
it('should sanitize the input', () => {
|
|
53
|
-
const wrapper = mount(/*#__PURE__*/
|
|
60
|
+
const wrapper = mount(/*#__PURE__*/_jsx(TextField, {
|
|
61
|
+
...inputProps,
|
|
54
62
|
onSanitize: value => value.toUpperCase()
|
|
55
|
-
}))
|
|
63
|
+
}));
|
|
56
64
|
const input = wrapper.find('input');
|
|
57
65
|
input.simulate('change', {
|
|
58
66
|
target: {
|
|
@@ -64,17 +72,19 @@ describe('<TextField>', () => {
|
|
|
64
72
|
});
|
|
65
73
|
it('should trigger the validation callback', () => {
|
|
66
74
|
const onValidateMock = jest.fn();
|
|
67
|
-
const wrapper = mount(/*#__PURE__*/
|
|
75
|
+
const wrapper = mount(/*#__PURE__*/_jsx(TextField, {
|
|
76
|
+
...inputProps,
|
|
68
77
|
onValidate: onValidateMock
|
|
69
|
-
}))
|
|
78
|
+
}));
|
|
70
79
|
expect(wrapper).toMatchSnapshot();
|
|
71
80
|
expect(onValidateMock).toHaveBeenCalled();
|
|
72
81
|
});
|
|
73
82
|
it('should focus the input', () => {
|
|
74
83
|
const onFocusMock = jest.fn();
|
|
75
|
-
const wrapper = mount(/*#__PURE__*/
|
|
84
|
+
const wrapper = mount(/*#__PURE__*/_jsx(TextField, {
|
|
85
|
+
...inputProps,
|
|
76
86
|
onFocusChange: onFocusMock
|
|
77
|
-
}))
|
|
87
|
+
}));
|
|
78
88
|
const input = wrapper.find('SimpleInput');
|
|
79
89
|
expect(wrapper).toMatchSnapshot();
|
|
80
90
|
expect(input.instance().isFocused).toBe(false);
|
|
@@ -85,25 +95,28 @@ describe('<TextField>', () => {
|
|
|
85
95
|
});
|
|
86
96
|
it('should show the error message', () => {
|
|
87
97
|
const errorText = 'This is an error here';
|
|
88
|
-
const wrapper = mount(/*#__PURE__*/
|
|
98
|
+
const wrapper = mount(/*#__PURE__*/_jsx(TextField, {
|
|
99
|
+
...inputProps,
|
|
89
100
|
errorText: errorText
|
|
90
|
-
}))
|
|
101
|
+
}));
|
|
91
102
|
expect(wrapper).toMatchSnapshot();
|
|
92
103
|
expect(wrapper.find('ErrorText').find('Translate').at(0).props().string).toEqual(errorText);
|
|
93
104
|
});
|
|
94
105
|
it('should show the label', () => {
|
|
95
106
|
const label = 'This is the label';
|
|
96
|
-
const wrapper = mount(/*#__PURE__*/
|
|
107
|
+
const wrapper = mount(/*#__PURE__*/_jsx(TextField, {
|
|
108
|
+
...inputProps,
|
|
97
109
|
label: label
|
|
98
|
-
}))
|
|
110
|
+
}));
|
|
99
111
|
expect(wrapper).toMatchSnapshot();
|
|
100
112
|
expect(wrapper.find('Label').find('Translate').props().string).toEqual(label);
|
|
101
113
|
});
|
|
102
114
|
it('should show the placeholder text', () => {
|
|
103
115
|
const placeholder = 'This is the placeholder text';
|
|
104
|
-
const wrapper = mount(/*#__PURE__*/
|
|
116
|
+
const wrapper = mount(/*#__PURE__*/_jsx(TextField, {
|
|
117
|
+
...inputProps,
|
|
105
118
|
placeholder: placeholder
|
|
106
|
-
}))
|
|
119
|
+
}));
|
|
107
120
|
expect(wrapper).toMatchSnapshot();
|
|
108
121
|
expect(wrapper.find('Placeholder').find('Translate').at(0).props().string).toEqual(placeholder);
|
|
109
122
|
});
|
package/Form/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
1
2
|
import React, { PureComponent } from 'react';
|
|
2
3
|
import PropTypes from 'prop-types';
|
|
3
4
|
|
|
@@ -5,53 +6,60 @@ import PropTypes from 'prop-types';
|
|
|
5
6
|
* Form component that handles keyboard submit, next buttons, ...
|
|
6
7
|
* @deprecated Use `@shopgate/engage/components/Form` instead.
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
+
let Form = /*#__PURE__*/function (_PureComponent) {
|
|
9
11
|
/**
|
|
10
12
|
* Initializes the form component.
|
|
11
13
|
* @param {Object} props The components props.
|
|
12
14
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
function Form(props) {
|
|
16
|
+
var _this;
|
|
17
|
+
_this = _PureComponent.call(this, props) || this;
|
|
15
18
|
/**
|
|
16
19
|
* Handles the form submit.
|
|
17
20
|
* @param {Object} event The event that caused the submit.
|
|
18
21
|
*/
|
|
19
|
-
|
|
22
|
+
_this.handleSubmit = event => {
|
|
20
23
|
event.preventDefault();
|
|
21
|
-
const inputFocused = [
|
|
24
|
+
const inputFocused = [].concat(_this.formElement.current.querySelectorAll('input')).some(input => document.activeElement === input);
|
|
22
25
|
if (inputFocused) {
|
|
23
26
|
document.activeElement.blur();
|
|
24
27
|
}
|
|
25
|
-
|
|
28
|
+
_this.props.onSubmit();
|
|
26
29
|
};
|
|
27
30
|
/**
|
|
28
31
|
* Handles form submits by key.
|
|
29
32
|
* @param {Object} event The event that caused the keypress.
|
|
30
33
|
*/
|
|
31
|
-
|
|
34
|
+
_this.handleKeyPress = event => {
|
|
32
35
|
// Enter key and on iOS also the "Done" button.
|
|
33
36
|
if (event.which === 13) {
|
|
34
|
-
|
|
37
|
+
_this.handleSubmit(event);
|
|
35
38
|
}
|
|
36
39
|
};
|
|
37
|
-
|
|
40
|
+
_this.formElement = /*#__PURE__*/React.createRef();
|
|
41
|
+
return _this;
|
|
38
42
|
}
|
|
43
|
+
_inheritsLoose(Form, _PureComponent);
|
|
44
|
+
var _proto = Form.prototype;
|
|
39
45
|
/**
|
|
40
46
|
* Renders the component.
|
|
41
47
|
* @returns {JSX}
|
|
42
48
|
*/
|
|
43
|
-
render() {
|
|
49
|
+
_proto.render = function render() {
|
|
44
50
|
/* eslint-disable jsx-a11y/no-noninteractive-element-interactions */
|
|
45
|
-
return /*#__PURE__*/
|
|
51
|
+
return /*#__PURE__*/_jsx("form", {
|
|
46
52
|
action: "#",
|
|
47
53
|
onSubmit: this.handleSubmit,
|
|
48
54
|
onKeyPress: this.handleKeyPress,
|
|
49
55
|
ref: this.formElement,
|
|
50
|
-
className: "ui-shared__form"
|
|
51
|
-
|
|
56
|
+
className: "ui-shared__form",
|
|
57
|
+
children: this.props.children
|
|
58
|
+
});
|
|
52
59
|
/* eslint-enable jsx-a11y/no-noninteractive-element-interactions */
|
|
53
|
-
}
|
|
54
|
-
|
|
60
|
+
};
|
|
61
|
+
return Form;
|
|
62
|
+
}(PureComponent);
|
|
55
63
|
Form.defaultProps = {
|
|
56
64
|
onSubmit: () => {}
|
|
57
65
|
};
|
|
@@ -9,21 +9,23 @@ import styles from "./style";
|
|
|
9
9
|
* @param {Object} props The component props.
|
|
10
10
|
* @returns {JSX.Element}
|
|
11
11
|
*/
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
13
|
const ErrorText = ({
|
|
13
14
|
className,
|
|
14
15
|
errorText,
|
|
15
16
|
translate,
|
|
16
17
|
elementName,
|
|
17
18
|
ariaHidden
|
|
18
|
-
}) => /*#__PURE__*/
|
|
19
|
+
}) => /*#__PURE__*/_jsxs("div", {
|
|
19
20
|
id: `ariaError-${elementName}`,
|
|
20
21
|
className: classNames(className, styles, 'errorText'),
|
|
21
22
|
"aria-live": "assertive",
|
|
22
23
|
"aria-atomic": "true",
|
|
23
|
-
"aria-hidden": ariaHidden
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}), !translate && errorText
|
|
24
|
+
"aria-hidden": ariaHidden,
|
|
25
|
+
children: [translate && /*#__PURE__*/_jsx(I18n.Text, {
|
|
26
|
+
string: errorText
|
|
27
|
+
}), !translate && errorText]
|
|
28
|
+
});
|
|
27
29
|
ErrorText.defaultProps = {
|
|
28
30
|
className: null,
|
|
29
31
|
errorText: null,
|
|
@@ -9,6 +9,7 @@ import styles from "./style";
|
|
|
9
9
|
* @param {Object} props The component props.
|
|
10
10
|
* @return {JSX}
|
|
11
11
|
*/
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
13
|
const Label = ({
|
|
13
14
|
hasErrorMessage,
|
|
14
15
|
htmlFor,
|
|
@@ -18,14 +19,15 @@ const Label = ({
|
|
|
18
19
|
labelStatic
|
|
19
20
|
}) => {
|
|
20
21
|
const labelStyles = styles.labelStyles(isFocused, isFloating, hasErrorMessage, labelStatic);
|
|
21
|
-
return /*#__PURE__*/ /* eslint-disable-next-line jsx-a11y/label-has-associated-control */
|
|
22
|
+
return /*#__PURE__*/ /* eslint-disable-next-line jsx-a11y/label-has-associated-control */_jsx("label", {
|
|
22
23
|
htmlFor: htmlFor,
|
|
23
24
|
className: classNames(labelStyles, 'label', {
|
|
24
25
|
floating: isFloating
|
|
26
|
+
}),
|
|
27
|
+
children: /*#__PURE__*/_jsx(I18n.Text, {
|
|
28
|
+
string: label
|
|
25
29
|
})
|
|
26
|
-
}
|
|
27
|
-
string: label
|
|
28
|
-
}));
|
|
30
|
+
});
|
|
29
31
|
};
|
|
30
32
|
Label.defaultProps = {
|
|
31
33
|
htmlFor: '',
|