@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
|
@@ -9,20 +9,22 @@ 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 = props => {
|
|
13
14
|
const labelStyles = styles.labelStyles(props.isFocused, props.isFloating, props.hasErrorMessage);
|
|
14
15
|
return (
|
|
15
16
|
/*#__PURE__*/
|
|
16
17
|
// eslint-disable-next-line jsx-a11y/label-has-associated-control
|
|
17
|
-
|
|
18
|
+
_jsx("label", {
|
|
18
19
|
htmlFor: props.name,
|
|
19
20
|
"aria-hidden": true,
|
|
20
21
|
className: classNames(labelStyles, 'label', {
|
|
21
22
|
floating: props.isFloating
|
|
23
|
+
}),
|
|
24
|
+
children: /*#__PURE__*/_jsx(I18n.Text, {
|
|
25
|
+
string: props.label
|
|
22
26
|
})
|
|
23
|
-
}
|
|
24
|
-
string: props.label
|
|
25
|
-
}))
|
|
27
|
+
})
|
|
26
28
|
);
|
|
27
29
|
};
|
|
28
30
|
Label.defaultProps = {
|
|
@@ -8,13 +8,15 @@ import styles from "./style";
|
|
|
8
8
|
* @param {Object} props The component props.
|
|
9
9
|
* @return {JSX}
|
|
10
10
|
*/
|
|
11
|
-
|
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
const Underline = props => /*#__PURE__*/_jsx("div", {
|
|
12
13
|
className: classNames(styles.underlineWrapper, 'underline'),
|
|
13
|
-
"aria-hidden": true
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
})
|
|
14
|
+
"aria-hidden": true,
|
|
15
|
+
children: /*#__PURE__*/_jsx("div", {
|
|
16
|
+
className: styles.underline,
|
|
17
|
+
style: styles.underlineStyle(props.isFocused, props.hasErrorMessage)
|
|
18
|
+
})
|
|
19
|
+
});
|
|
18
20
|
Underline.defaultProps = {
|
|
19
21
|
isFocused: false,
|
|
20
22
|
hasErrorMessage: false
|
package/TextField/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
2
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
1
3
|
import React, { Component } from 'react';
|
|
2
4
|
import PropTypes from 'prop-types';
|
|
3
5
|
import classNames from 'classnames';
|
|
@@ -11,30 +13,32 @@ import FormElement from "./components/FormElement/index";
|
|
|
11
13
|
/**
|
|
12
14
|
* A component that provides a styled text field for user input in material design.
|
|
13
15
|
*/
|
|
14
|
-
|
|
16
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
|
+
let TextField = /*#__PURE__*/function (_Component) {
|
|
15
18
|
/**
|
|
16
19
|
* Creates a new text field component.
|
|
17
20
|
* @param {Object} props The component properties.
|
|
18
21
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
function TextField(props) {
|
|
23
|
+
var _this;
|
|
24
|
+
_this = _Component.call(this, props) || this;
|
|
21
25
|
/**
|
|
22
26
|
* Internal focus event handler.
|
|
23
27
|
* @param {boolean} isFocused Whether the input component is focused.
|
|
24
28
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
29
|
+
_this.handleFocusChange = isFocused => {
|
|
30
|
+
_this.setState({
|
|
27
31
|
isFocused
|
|
28
32
|
});
|
|
29
|
-
|
|
33
|
+
_this.props.onFocusChange(isFocused);
|
|
30
34
|
};
|
|
31
35
|
/**
|
|
32
36
|
* Updates the state if the input value has been changed.
|
|
33
37
|
* @param {string} value The entered text.
|
|
34
38
|
* @param {Object} event The original event object.
|
|
35
39
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
40
|
+
_this.handleChange = (value, event) => {
|
|
41
|
+
_this.props.onChange(value, event);
|
|
38
42
|
};
|
|
39
43
|
/**
|
|
40
44
|
* Updates the validation error text if required.
|
|
@@ -42,8 +46,8 @@ class TextField extends Component {
|
|
|
42
46
|
* @param {boolean} isInitial Whether this is the initial value of the input field.
|
|
43
47
|
* @return {boolean} Whether the validation was successful.
|
|
44
48
|
*/
|
|
45
|
-
|
|
46
|
-
const validationError =
|
|
49
|
+
_this.handleValidate = (value, isInitial) => {
|
|
50
|
+
const validationError = _this.props.onValidate(value);
|
|
47
51
|
if (validationError !== true && validationError) {
|
|
48
52
|
/**
|
|
49
53
|
* An error message was returned by the validation callback. Update the state.
|
|
@@ -51,15 +55,15 @@ class TextField extends Component {
|
|
|
51
55
|
* sure we're not calling setState() in this situation.
|
|
52
56
|
*/
|
|
53
57
|
if (!isInitial) {
|
|
54
|
-
|
|
58
|
+
_this.setState({
|
|
55
59
|
validationError
|
|
56
60
|
});
|
|
57
61
|
} else {
|
|
58
|
-
|
|
62
|
+
_this.state.validationError = validationError;
|
|
59
63
|
}
|
|
60
|
-
} else if (
|
|
64
|
+
} else if (_this.state.validationError) {
|
|
61
65
|
// There was no error, clear the state variable.
|
|
62
|
-
|
|
66
|
+
_this.setState({
|
|
63
67
|
validationError: null
|
|
64
68
|
});
|
|
65
69
|
}
|
|
@@ -67,48 +71,23 @@ class TextField extends Component {
|
|
|
67
71
|
// Forward the boolean result to the input field.
|
|
68
72
|
return validationError === true;
|
|
69
73
|
};
|
|
70
|
-
|
|
74
|
+
_this.state = {
|
|
71
75
|
isFocused: false,
|
|
72
76
|
validationError: null
|
|
73
77
|
};
|
|
78
|
+
return _this;
|
|
74
79
|
}
|
|
75
80
|
|
|
76
81
|
/**
|
|
77
82
|
* @returns {boolean} Whether the text field is currently focused.
|
|
78
83
|
*/
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* @returns {boolean} Whether the label is currently floating.
|
|
85
|
-
*/
|
|
86
|
-
get isLabelFloating() {
|
|
87
|
-
// On Firefox empty date inputs always show a placeholder with date pattern
|
|
88
|
-
if (navigator.userAgent.includes('Firefox') && this.props.type === 'date') {
|
|
89
|
-
return true;
|
|
90
|
-
}
|
|
91
|
-
return this.isFocused || !!this.props.value;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* @returns {boolean} Whether the hint text is currently visible.
|
|
96
|
-
*/
|
|
97
|
-
get isHintVisible() {
|
|
98
|
-
return this.isFocused && !this.props.value;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* @return {boolean} Whether the error message is set.
|
|
103
|
-
*/
|
|
104
|
-
get hasErrorMessage() {
|
|
105
|
-
return !!(this.state.validationError || this.props.errorText);
|
|
106
|
-
}
|
|
84
|
+
_inheritsLoose(TextField, _Component);
|
|
85
|
+
var _proto = TextField.prototype;
|
|
107
86
|
/**
|
|
108
87
|
* Renders the text field.
|
|
109
88
|
* @return {JSX.Element}
|
|
110
89
|
*/
|
|
111
|
-
render() {
|
|
90
|
+
_proto.render = function render() {
|
|
112
91
|
const styleType = this.props.multiLine ? 'multiLine' : 'input';
|
|
113
92
|
const style = styles.container[styleType];
|
|
114
93
|
const {
|
|
@@ -130,50 +109,88 @@ class TextField extends Component {
|
|
|
130
109
|
translateErrorText,
|
|
131
110
|
required
|
|
132
111
|
} = this.props;
|
|
133
|
-
return /*#__PURE__*/
|
|
112
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
134
113
|
className: classNames(style, className, 'textField', 'ui-shared__text-field', {
|
|
135
114
|
disabled
|
|
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
|
-
|
|
115
|
+
}),
|
|
116
|
+
children: [/*#__PURE__*/_jsx(Hint, {
|
|
117
|
+
visible: this.isHintVisible,
|
|
118
|
+
hintText: hintText
|
|
119
|
+
}), /*#__PURE__*/_jsx(Label, {
|
|
120
|
+
name: name,
|
|
121
|
+
label: label,
|
|
122
|
+
isFocused: this.isFocused,
|
|
123
|
+
isFloating: this.isLabelFloating,
|
|
124
|
+
hasErrorMessage: this.hasErrorMessage
|
|
125
|
+
}), /*#__PURE__*/_jsx(FormElement, {
|
|
126
|
+
id: name,
|
|
127
|
+
multiLine: multiLine,
|
|
128
|
+
name: name,
|
|
129
|
+
setRef: setRef,
|
|
130
|
+
onFocusChange: this.handleFocusChange,
|
|
131
|
+
onChange: this.handleChange,
|
|
132
|
+
onSanitize: onSanitize,
|
|
133
|
+
onValidate: this.handleValidate,
|
|
134
|
+
password: password,
|
|
135
|
+
type: type,
|
|
136
|
+
value: value,
|
|
137
|
+
isControlled: isControlled,
|
|
138
|
+
inputComponent: inputComponent,
|
|
139
|
+
disabled: disabled,
|
|
140
|
+
required: required,
|
|
141
|
+
attributes: {
|
|
142
|
+
'aria-invalid': !!errorText,
|
|
143
|
+
'aria-describedby': this.hasErrorMessage ? `ariaError-${name}` : null
|
|
144
|
+
}
|
|
145
|
+
}), /*#__PURE__*/_jsx(Underline, {
|
|
146
|
+
isFocused: this.isFocused,
|
|
147
|
+
hasErrorMessage: this.hasErrorMessage
|
|
148
|
+
}), showErrorText && /*#__PURE__*/_jsx(ErrorText, {
|
|
149
|
+
validationError: this.state.validationError,
|
|
150
|
+
errorText: errorText,
|
|
151
|
+
translate: translateErrorText,
|
|
152
|
+
elementName: name
|
|
153
|
+
})]
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
return _createClass(TextField, [{
|
|
157
|
+
key: "isFocused",
|
|
158
|
+
get: function () {
|
|
159
|
+
return this.state.isFocused;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* @returns {boolean} Whether the label is currently floating.
|
|
164
|
+
*/
|
|
165
|
+
}, {
|
|
166
|
+
key: "isLabelFloating",
|
|
167
|
+
get: function () {
|
|
168
|
+
// On Firefox empty date inputs always show a placeholder with date pattern
|
|
169
|
+
if (navigator.userAgent.includes('Firefox') && this.props.type === 'date') {
|
|
170
|
+
return true;
|
|
165
171
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
172
|
+
return this.isFocused || !!this.props.value;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* @returns {boolean} Whether the hint text is currently visible.
|
|
177
|
+
*/
|
|
178
|
+
}, {
|
|
179
|
+
key: "isHintVisible",
|
|
180
|
+
get: function () {
|
|
181
|
+
return this.isFocused && !this.props.value;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* @return {boolean} Whether the error message is set.
|
|
186
|
+
*/
|
|
187
|
+
}, {
|
|
188
|
+
key: "hasErrorMessage",
|
|
189
|
+
get: function () {
|
|
190
|
+
return !!(this.state.validationError || this.props.errorText);
|
|
191
|
+
}
|
|
192
|
+
}]);
|
|
193
|
+
}(Component);
|
|
177
194
|
TextField.defaultProps = {
|
|
178
195
|
className: '',
|
|
179
196
|
errorText: '',
|
package/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('input');
|
|
79
89
|
expect(wrapper).toMatchSnapshot();
|
|
80
90
|
expect(wrapper.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('Translate').at(2).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 hint text', () => {
|
|
103
115
|
const hintText = 'This is the hint text';
|
|
104
|
-
const wrapper = mount(/*#__PURE__*/
|
|
116
|
+
const wrapper = mount(/*#__PURE__*/_jsx(TextField, {
|
|
117
|
+
...inputProps,
|
|
105
118
|
hintText: hintText
|
|
106
|
-
}))
|
|
119
|
+
}));
|
|
107
120
|
expect(wrapper).toMatchSnapshot();
|
|
108
121
|
expect(wrapper.find('Hint').find('Translate').at(0).props().string).toEqual(hintText);
|
|
109
122
|
});
|
|
@@ -113,9 +126,10 @@ describe('<TextField />', () => {
|
|
|
113
126
|
* @return {string} The error message.
|
|
114
127
|
*/
|
|
115
128
|
const onValidate = () => 'Custom validation error';
|
|
116
|
-
const wrapper = mount(/*#__PURE__*/
|
|
129
|
+
const wrapper = mount(/*#__PURE__*/_jsx(TextField, {
|
|
130
|
+
...inputProps,
|
|
117
131
|
onValidate: onValidate
|
|
118
|
-
}))
|
|
132
|
+
}));
|
|
119
133
|
wrapper.find('input').simulate('blur');
|
|
120
134
|
expect(wrapper).toMatchSnapshot();
|
|
121
135
|
// Expect at least one element containing the validation error text.
|
package/ToggleIcon/index.js
CHANGED
|
@@ -1,48 +1,54 @@
|
|
|
1
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
1
2
|
import React, { Component } from 'react';
|
|
2
3
|
import PropTypes from 'prop-types';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* No operational default handler
|
|
6
7
|
*/
|
|
8
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
9
|
const noop = () => {};
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
12
|
* An toggle icon with toggle handlers.
|
|
11
13
|
*/
|
|
12
|
-
|
|
14
|
+
let ToggleIcon = /*#__PURE__*/function (_Component) {
|
|
13
15
|
/**
|
|
14
16
|
* @param {Object} props The component properties.
|
|
15
17
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
function ToggleIcon(props) {
|
|
19
|
+
var _this;
|
|
20
|
+
_this = _Component.call(this, props) || this;
|
|
18
21
|
/**
|
|
19
22
|
* Toggle icon
|
|
20
23
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
_this.handleToggle = () => {
|
|
25
|
+
_this.setState(({
|
|
23
26
|
on
|
|
24
27
|
}) => ({
|
|
25
28
|
on: !on
|
|
26
|
-
}), () =>
|
|
29
|
+
}), () => _this.props.toggleHandler(_this.state.on));
|
|
27
30
|
};
|
|
28
|
-
|
|
31
|
+
_this.state = {
|
|
29
32
|
on: props.on
|
|
30
33
|
};
|
|
34
|
+
return _this;
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
/**
|
|
34
38
|
* Reset state to received props
|
|
35
39
|
* @param {Object} nextProps next props
|
|
36
40
|
*/
|
|
37
|
-
|
|
41
|
+
_inheritsLoose(ToggleIcon, _Component);
|
|
42
|
+
var _proto = ToggleIcon.prototype;
|
|
43
|
+
_proto.UNSAFE_componentWillReceiveProps = function UNSAFE_componentWillReceiveProps(nextProps) {
|
|
38
44
|
this.setState({
|
|
39
45
|
on: nextProps.on
|
|
40
46
|
});
|
|
41
|
-
}
|
|
47
|
+
};
|
|
42
48
|
/**
|
|
43
49
|
* @return {*}
|
|
44
50
|
*/
|
|
45
|
-
render() {
|
|
51
|
+
_proto.render = function render() {
|
|
46
52
|
const {
|
|
47
53
|
onIcon,
|
|
48
54
|
offIcon
|
|
@@ -50,13 +56,15 @@ class ToggleIcon extends Component {
|
|
|
50
56
|
const {
|
|
51
57
|
on
|
|
52
58
|
} = this.state;
|
|
53
|
-
return /*#__PURE__*/
|
|
59
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
54
60
|
className: "ui-shared__toggle-icon",
|
|
55
61
|
onClick: this.handleToggle,
|
|
56
|
-
"aria-hidden": true
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
62
|
+
"aria-hidden": true,
|
|
63
|
+
children: [on && onIcon, !on && offIcon]
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
return ToggleIcon;
|
|
67
|
+
}(Component);
|
|
60
68
|
ToggleIcon.defaultProps = {
|
|
61
69
|
on: true,
|
|
62
70
|
toggleHandler: noop
|
package/ToggleIcon/spec.js
CHANGED
|
@@ -1,33 +1,37 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
2
1
|
import React from 'react';
|
|
3
2
|
import { mount } from 'enzyme';
|
|
4
3
|
import ToggleIcon from "./index";
|
|
5
4
|
import VisibilityIcon from "../icons/VisibilityIcon";
|
|
6
5
|
import VisibilityOffIcon from "../icons/VisibilityOffIcon";
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
7
|
const inputProps = {
|
|
8
|
-
onIcon: /*#__PURE__*/
|
|
9
|
-
offIcon: /*#__PURE__*/
|
|
8
|
+
onIcon: /*#__PURE__*/_jsx(VisibilityIcon, {}),
|
|
9
|
+
offIcon: /*#__PURE__*/_jsx(VisibilityOffIcon, {})
|
|
10
10
|
};
|
|
11
11
|
describe('<ToggleIcon>', () => {
|
|
12
12
|
it('should render a toggle icon', () => {
|
|
13
|
-
const wrapper = mount(/*#__PURE__*/
|
|
13
|
+
const wrapper = mount(/*#__PURE__*/_jsx(ToggleIcon, {
|
|
14
|
+
...inputProps
|
|
15
|
+
}));
|
|
14
16
|
expect(wrapper).toMatchSnapshot();
|
|
15
17
|
expect(wrapper.find('VisibilityIcon').length).toBe(1);
|
|
16
18
|
expect(wrapper.find('VisibilityOffIcon').length).toBe(0);
|
|
17
19
|
});
|
|
18
20
|
it('should render a toggle icon with false as default', () => {
|
|
19
|
-
const wrapper = mount(/*#__PURE__*/
|
|
21
|
+
const wrapper = mount(/*#__PURE__*/_jsx(ToggleIcon, {
|
|
22
|
+
...inputProps,
|
|
20
23
|
on: false
|
|
21
|
-
}))
|
|
24
|
+
}));
|
|
22
25
|
expect(wrapper).toMatchSnapshot();
|
|
23
26
|
expect(wrapper.find('VisibilityIcon').length).toBe(0);
|
|
24
27
|
expect(wrapper.find('VisibilityOffIcon').length).toBe(1);
|
|
25
28
|
});
|
|
26
29
|
it('should trigger the toggleHandler callback', () => {
|
|
27
30
|
const mockToggleHandler = jest.fn();
|
|
28
|
-
const wrapper = mount(/*#__PURE__*/
|
|
31
|
+
const wrapper = mount(/*#__PURE__*/_jsx(ToggleIcon, {
|
|
32
|
+
...inputProps,
|
|
29
33
|
toggleHandler: mockToggleHandler
|
|
30
|
-
}))
|
|
34
|
+
}));
|
|
31
35
|
wrapper.find('div').simulate('click');
|
|
32
36
|
expect(wrapper).toMatchSnapshot();
|
|
33
37
|
expect(mockToggleHandler.mock.calls.length).toBe(1);
|
package/icons/AccountBoxIcon.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
2
1
|
import React from 'react';
|
|
3
2
|
import Icon from '@shopgate/pwa-common/components/Icon';
|
|
4
3
|
import { themeConfig } from '@shopgate/pwa-common/helpers/config';
|
|
@@ -8,7 +7,9 @@ import { themeConfig } from '@shopgate/pwa-common/helpers/config';
|
|
|
8
7
|
* @param {Object} props The icon component properties.
|
|
9
8
|
* @returns {JSX}
|
|
10
9
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
const AccountBox = props => /*#__PURE__*/_jsx(Icon, {
|
|
12
|
+
content: themeConfig.icons.accountBox,
|
|
13
|
+
...props
|
|
14
|
+
});
|
|
14
15
|
export default AccountBox;
|
package/icons/AddMoreIcon.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
2
1
|
import React from 'react';
|
|
3
2
|
import Icon from '@shopgate/pwa-common/components/Icon';
|
|
4
3
|
import { themeConfig } from '@shopgate/pwa-common/helpers/config';
|
|
@@ -8,7 +7,9 @@ import { themeConfig } from '@shopgate/pwa-common/helpers/config';
|
|
|
8
7
|
* @param {Object} props The icon component properties.
|
|
9
8
|
* @returns {JSX}
|
|
10
9
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
const AddMore = props => /*#__PURE__*/_jsx(Icon, {
|
|
12
|
+
content: themeConfig.icons.addMore,
|
|
13
|
+
...props
|
|
14
|
+
});
|
|
14
15
|
export default AddMore;
|
package/icons/ArrowDropIcon.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
2
1
|
import React from 'react';
|
|
3
2
|
import Icon from '@shopgate/pwa-common/components/Icon';
|
|
4
3
|
import { themeConfig } from '@shopgate/pwa-common/helpers/config';
|
|
@@ -8,7 +7,9 @@ import { themeConfig } from '@shopgate/pwa-common/helpers/config';
|
|
|
8
7
|
* @param {Object} props The icon component properties.
|
|
9
8
|
* @returns {JSX}
|
|
10
9
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
const ArrowDrop = props => /*#__PURE__*/_jsx(Icon, {
|
|
12
|
+
content: themeConfig.icons.arrowDrop,
|
|
13
|
+
...props
|
|
14
|
+
});
|
|
14
15
|
export default ArrowDrop;
|
package/icons/ArrowIcon.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
2
1
|
import React from 'react';
|
|
3
2
|
import PropTypes from 'prop-types';
|
|
4
3
|
import Icon from '@shopgate/pwa-common/components/Icon';
|
|
@@ -10,14 +9,16 @@ import { themeConfig } from '@shopgate/pwa-common/helpers/config';
|
|
|
10
9
|
* @param {boolean} props.shadow Whether to show a shadow under the arrow.
|
|
11
10
|
* @returns {JSX}
|
|
12
11
|
*/
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
13
|
const ArrowIcon = ({
|
|
14
14
|
shadow,
|
|
15
15
|
...props
|
|
16
16
|
}) => {
|
|
17
17
|
const content = shadow ? themeConfig.icons.arrowShadowed : themeConfig.icons.arrow;
|
|
18
|
-
return /*#__PURE__*/
|
|
19
|
-
content: content
|
|
20
|
-
|
|
18
|
+
return /*#__PURE__*/_jsx(Icon, {
|
|
19
|
+
content: content,
|
|
20
|
+
...props
|
|
21
|
+
});
|
|
21
22
|
};
|
|
22
23
|
ArrowIcon.defaultProps = {
|
|
23
24
|
shadow: false
|