@shopgate/pwa-ui-shared 7.30.0-alpha.7 → 7.30.0-alpha.9
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 +39 -5
- package/AccordionContainer/spec.js +25 -2
- package/ActionButton/index.js +63 -7
- package/ActionButton/spec.js +63 -2
- package/ActionButton/style.js +22 -1
- package/AddToCartButton/index.js +184 -27
- package/AddToCartButton/mock.js +18 -4
- package/AddToCartButton/spec.js +65 -2
- package/AddToCartButton/style.js +127 -11
- package/Availability/index.js +34 -2
- package/Availability/spec.js +41 -1
- package/Availability/style.js +19 -1
- package/Button/index.js +76 -5
- package/Button/spec.js +33 -1
- package/Button/style.js +130 -21
- package/ButtonLink/connector.js +11 -2
- package/ButtonLink/index.js +44 -6
- package/ButtonLink/spec.js +23 -1
- package/Card/index.js +19 -2
- package/Card/style.js +11 -1
- package/CardList/components/Item/index.js +26 -2
- package/CardList/components/Item/style.js +7 -1
- package/CardList/index.js +34 -3
- package/CartTotalLine/components/Amount/index.js +28 -2
- package/CartTotalLine/components/Amount/style.js +8 -1
- package/CartTotalLine/components/Hint/index.js +23 -2
- package/CartTotalLine/components/Hint/style.js +12 -1
- package/CartTotalLine/components/Label/index.js +36 -2
- package/CartTotalLine/components/Label/style.js +17 -1
- package/CartTotalLine/components/Spacer/index.js +16 -2
- package/CartTotalLine/index.js +39 -2
- package/CartTotalLine/style.js +31 -1
- package/Checkbox/index.js +31 -2
- package/Checkbox/style.js +18 -1
- package/Chip/index.js +61 -2
- package/Chip/spec.js +24 -1
- package/Chip/style.js +71 -3
- package/ContextMenu/ContextMenu.hooks.js +6 -2
- package/ContextMenu/ContextMenuProvider.context.js +9 -3
- package/ContextMenu/ContextMenuProvider.js +21 -2
- package/ContextMenu/components/Item/index.js +67 -5
- package/ContextMenu/components/Item/style.js +32 -3
- package/ContextMenu/components/Position/index.js +61 -10
- package/ContextMenu/components/Position/style.js +11 -1
- package/ContextMenu/index.js +124 -3
- package/ContextMenu/spec.js +101 -2
- package/ContextMenu/style.js +45 -1
- package/Dialog/components/BasicDialog/index.js +5 -1
- package/Dialog/components/HtmlContentDialog/index.js +22 -2
- package/Dialog/components/HtmlContentDialog/spec.js +59 -1
- package/Dialog/components/PipelineErrorDialog/index.js +114 -25
- package/Dialog/components/PipelineErrorDialog/spec.js +92 -12
- package/Dialog/components/TextMessageDialog/index.js +28 -2
- package/Dialog/components/TextMessageDialog/spec.js +59 -1
- package/Dialog/components/VariantSelectModal/connector.js +11 -2
- package/Dialog/components/VariantSelectModal/index.js +65 -6
- package/Dialog/components/VariantSelectModal/spec.js +51 -2
- package/Dialog/constants.js +6 -1
- package/Dialog/index.js +114 -7
- package/Dialog/spec.js +81 -3
- package/DiscountBadge/index.js +30 -2
- package/DiscountBadge/spec.js +19 -1
- package/DiscountBadge/style.js +34 -2
- package/FavoritesButton/connector.js +18 -3
- package/FavoritesButton/index.js +118 -15
- package/FavoritesButton/mock.js +50 -4
- package/FavoritesButton/spec.js +120 -2
- package/FavoritesButton/style.js +26 -1
- package/Form/Builder/builders/buildCountryList.js +40 -6
- package/Form/Builder/builders/buildFormDefaults.js +35 -6
- package/Form/Builder/builders/buildFormElements.js +68 -10
- package/Form/Builder/builders/buildProvinceList.js +19 -2
- package/Form/Builder/builders/buildValidationErrorList.js +7 -2
- package/Form/Builder/classes/ActionListener/constants.js +22 -2
- package/Form/Builder/classes/ActionListener/index.js +441 -93
- package/Form/Builder/classes/ActionListener/spec.js +321 -19
- package/Form/Builder/components/CheckboxElement.js +35 -3
- package/Form/Builder/components/CountryElement.js +40 -3
- package/Form/Builder/components/ProvinceElement.js +40 -3
- package/Form/Builder/components/RadioElement.js +41 -3
- package/Form/Builder/components/SelectElement.js +39 -3
- package/Form/Builder/components/TextElement.js +49 -4
- package/Form/Builder/elementTypes.js +11 -1
- package/Form/Builder/index.js +298 -52
- package/Form/Builder/iso-3166-2.js +4943 -1
- package/Form/Builder/spec.js +308 -16
- package/Form/Checkbox/index.js +66 -4
- package/Form/Checkbox/style.js +25 -2
- package/Form/InfoField/index.js +50 -2
- package/Form/InfoField/spec.js +9 -1
- package/Form/InfoField/style.js +11 -1
- package/Form/Password/index.js +51 -6
- package/Form/Password/spec.js +34 -1
- package/Form/Password/style.js +11 -1
- package/Form/RadioGroup/components/Item/index.js +59 -3
- package/Form/RadioGroup/components/Item/style.js +32 -2
- package/Form/RadioGroup/index.js +101 -9
- package/Form/RadioGroup/spec.js +83 -3
- package/Form/RadioGroup/style.js +18 -2
- package/Form/Select/index.js +158 -10
- package/Form/Select/spec.js +36 -5
- package/Form/Select/style.js +27 -1
- package/Form/SelectContextChoices/index.js +77 -3
- package/Form/SelectContextChoices/spec.js +33 -4
- package/Form/SelectContextChoices/style.js +23 -1
- package/Form/TextField/index.js +92 -8
- package/Form/TextField/spec.js +110 -1
- package/Form/TextField/style.js +66 -8
- package/Form/index.js +54 -13
- package/FormElement/components/ErrorText/index.js +31 -2
- package/FormElement/components/ErrorText/style.js +13 -1
- package/FormElement/components/Label/index.js +35 -2
- package/FormElement/components/Label/style.js +76 -8
- package/FormElement/components/Placeholder/index.js +26 -2
- package/FormElement/components/Placeholder/style.js +48 -6
- package/FormElement/components/Underline/index.js +18 -2
- package/FormElement/components/Underline/style.js +51 -4
- package/FormElement/index.js +91 -6
- package/FormElement/spec.js +67 -2
- package/FormElement/style.js +13 -2
- package/Glow/index.js +90 -7
- package/Glow/spec.js +9 -1
- package/Glow/style.js +18 -1
- package/IndicatorCircle/index.js +33 -3
- package/IndicatorCircle/spec.js +28 -1
- package/IndicatorCircle/style.js +57 -3
- package/LoadingIndicator/index.js +29 -2
- package/LoadingIndicator/style.js +20 -1
- package/Manufacturer/index.js +20 -2
- package/Manufacturer/style.js +5 -1
- package/MessageBar/index.js +36 -2
- package/MessageBar/spec.js +79 -1
- package/MessageBar/style.js +38 -1
- package/NoResults/components/Icon/index.js +130 -2
- package/NoResults/components/Icon/style.js +17 -1
- package/NoResults/index.js +46 -2
- package/NoResults/style.js +31 -1
- package/Placeholder/index.js +25 -3
- package/Placeholder/style.js +11 -1
- package/PlaceholderLabel/index.js +27 -2
- package/PlaceholderLabel/spec.js +19 -1
- package/PlaceholderLabel/style.js +12 -1
- package/PlaceholderParagraph/index.js +36 -2
- package/PlaceholderParagraph/spec.js +19 -1
- package/Price/index.js +88 -7
- package/Price/style.js +22 -1
- package/PriceInfo/index.js +20 -2
- package/PriceInfo/style.js +5 -1
- package/PriceStriked/index.js +83 -12
- package/PriceStriked/style.js +33 -3
- package/ProductProperties/index.js +32 -2
- package/ProgressBar/index.js +101 -13
- package/ProgressBar/spec.js +13 -1
- package/ProgressBar/style.js +83 -2
- package/RadioButton/index.js +18 -2
- package/RadioButton/spec.js +21 -1
- package/RadioButton/style.js +21 -1
- package/RatingNumber/index.js +29 -2
- package/RatingStars/constants.js +2 -1
- package/RatingStars/index.js +130 -12
- package/RatingStars/spec.js +90 -3
- package/RatingStars/style.js +51 -2
- package/Ripple/components/RippleAnimation/index.js +88 -6
- package/Ripple/index.js +218 -40
- package/Ripple/style.js +18 -1
- package/RippleButton/index.js +52 -5
- package/RippleButton/spec.js +45 -1
- package/ScannerOverlay/components/CameraOverlay/index.js +13 -2
- package/ScannerOverlay/components/CameraOverlay/style.js +40 -1
- package/ScannerOverlay/components/ScannerBar/components/FlashlightButton/index.js +34 -2
- package/ScannerOverlay/components/ScannerBar/components/FlashlightButton/style.js +28 -1
- package/ScannerOverlay/components/ScannerBar/components/ScannerInstructions/index.js +11 -2
- package/ScannerOverlay/components/ScannerBar/index.js +31 -2
- package/ScannerOverlay/components/ScannerBar/style.js +20 -1
- package/ScannerOverlay/index.js +47 -7
- package/Sheet/components/Header/components/SearchBar/index.js +46 -2
- package/Sheet/components/Header/components/SearchBar/spec.js +21 -3
- package/Sheet/components/Header/components/SearchBar/style.js +47 -1
- package/Sheet/components/Header/index.js +75 -7
- package/Sheet/components/Header/spec.js +14 -1
- package/Sheet/components/Header/style.js +50 -1
- package/Sheet/index.js +170 -17
- package/Sheet/spec.js +85 -5
- package/Sheet/style.js +143 -2
- package/TaxDisclaimer/index.js +34 -4
- package/TaxDisclaimer/spec.js +31 -3
- package/TaxDisclaimer/style.js +9 -1
- package/TextField/components/ErrorText/index.js +33 -2
- package/TextField/components/ErrorText/style.js +25 -3
- package/TextField/components/FormElement/index.js +19 -2
- package/TextField/components/FormElement/style.js +32 -4
- package/TextField/components/Hint/index.js +21 -2
- package/TextField/components/Hint/style.js +40 -5
- package/TextField/components/Label/index.js +32 -3
- package/TextField/components/Label/style.js +68 -8
- package/TextField/components/Underline/index.js +19 -2
- package/TextField/components/Underline/style.js +51 -4
- package/TextField/index.js +189 -27
- package/TextField/spec.js +128 -3
- package/TextField/style.js +34 -4
- package/ToggleIcon/index.js +58 -8
- package/ToggleIcon/spec.js +35 -1
- package/icons/AccountBoxIcon.js +11 -2
- package/icons/AddMoreIcon.js +11 -2
- package/icons/ArrowDropIcon.js +11 -2
- package/icons/ArrowIcon.js +21 -2
- package/icons/BarcodeScannerIcon.js +11 -2
- package/icons/BoxIcon.js +11 -2
- package/icons/BrowseIcon.js +11 -2
- package/icons/BurgerIcon.js +11 -2
- package/icons/CalendarIcon.js +15 -3
- package/icons/CartCouponIcon.js +72 -2
- package/icons/CartIcon.js +11 -2
- package/icons/CartPlusIcon.js +11 -2
- package/icons/CheckIcon.js +11 -2
- package/icons/CheckedIcon.js +11 -2
- package/icons/ChevronIcon.js +11 -2
- package/icons/CreditCardIcon.js +11 -2
- package/icons/CrossIcon.js +11 -2
- package/icons/DescriptionIcon.js +11 -2
- package/icons/FilterIcon.js +11 -2
- package/icons/FlashDisabledIcon.js +11 -2
- package/icons/FlashEnabledIcon.js +11 -2
- package/icons/GridIcon.js +11 -2
- package/icons/HeartIcon.js +11 -2
- package/icons/HeartOutlineIcon.js +11 -2
- package/icons/HeartPlusIcon.js +12 -2
- package/icons/HeartPlusOutlineIcon.js +12 -2
- package/icons/HomeIcon.js +11 -2
- package/icons/InfoIcon.js +11 -2
- package/icons/InfoOutlineIcon.js +11 -2
- package/icons/ListIcon.js +11 -2
- package/icons/LocalShippingIcon.js +11 -2
- package/icons/LocationIcon.js +13 -3
- package/icons/LocatorIcon.js +11 -2
- package/icons/LockIcon.js +11 -2
- package/icons/LogoutIcon.js +11 -2
- package/icons/MagnifierIcon.js +11 -2
- package/icons/MapMarkerIcon.js +24 -3
- package/icons/MoreIcon.js +11 -2
- package/icons/MoreVertIcon.js +11 -2
- package/icons/NotificationIcon.js +14 -3
- package/icons/PersonIcon.js +12 -2
- package/icons/PhoneIcon.js +13 -3
- package/icons/PlaceholderIcon.js +11 -2
- package/icons/RadioCheckedIcon.js +11 -2
- package/icons/RadioUncheckedIcon.js +11 -2
- package/icons/SecurityIcon.js +11 -2
- package/icons/ShippingMethodIcon.js +18 -3
- package/icons/ShoppingCartIcon.js +11 -2
- package/icons/SortIcon.js +11 -2
- package/icons/StarHalfIcon.js +18 -2
- package/icons/StarIcon.js +18 -2
- package/icons/StarOutlineIcon.js +11 -2
- package/icons/StopIcon.js +11 -2
- package/icons/TickIcon.js +11 -2
- package/icons/TimeIcon.js +14 -3
- package/icons/TrashIcon.js +11 -2
- package/icons/TrashOutlineIcon.js +12 -2
- package/icons/UncheckedIcon.js +11 -2
- package/icons/ViewListIcon.js +11 -2
- package/icons/VisibilityIcon.js +11 -2
- package/icons/VisibilityOffIcon.js +11 -2
- package/icons/WarningIcon.js +11 -2
- package/index.js +13 -1
- package/package.json +5 -5
|
@@ -1,6 +1,62 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _camelCase from "lodash/camelCase";
|
|
3
|
+
import React, { PureComponent } from 'react';
|
|
4
|
+
import PropTypes from 'prop-types';
|
|
5
|
+
import classNames from 'classnames';
|
|
6
|
+
import { I18n, CheckedIcon, UncheckedIcon } from '@shopgate/engage/components';
|
|
7
|
+
import style from "./style";
|
|
8
|
+
|
|
9
|
+
/**
|
|
2
10
|
* RadioItem component.
|
|
3
|
-
*/
|
|
11
|
+
*/
|
|
12
|
+
class RadioItem extends PureComponent {
|
|
13
|
+
/**
|
|
4
14
|
* Renders the component.
|
|
5
15
|
* @returns {JSX.Element}
|
|
6
|
-
*/
|
|
16
|
+
*/
|
|
17
|
+
render() {
|
|
18
|
+
const {
|
|
19
|
+
label: ItemLabel,
|
|
20
|
+
name,
|
|
21
|
+
onChange,
|
|
22
|
+
checked,
|
|
23
|
+
className,
|
|
24
|
+
attributes,
|
|
25
|
+
id
|
|
26
|
+
} = this.props;
|
|
27
|
+
const {
|
|
28
|
+
disabled
|
|
29
|
+
} = attributes || {};
|
|
30
|
+
return /*#__PURE__*/React.createElement("label", {
|
|
31
|
+
className: classNames(style.container, className, {
|
|
32
|
+
[style.disabled]: !!disabled
|
|
33
|
+
}, _camelCase(name), 'radioItem'),
|
|
34
|
+
htmlFor: id || name
|
|
35
|
+
}, checked && /*#__PURE__*/React.createElement(CheckedIcon, {
|
|
36
|
+
className: classNames(style.active, style.icon, 'checkedIcon')
|
|
37
|
+
}), !checked && /*#__PURE__*/React.createElement(UncheckedIcon, {
|
|
38
|
+
className: classNames(style.icon, 'uncheckedIcon')
|
|
39
|
+
}), /*#__PURE__*/React.createElement("input", _extends({
|
|
40
|
+
className: classNames('sr-only', 'input'),
|
|
41
|
+
checked: checked,
|
|
42
|
+
id: id || name,
|
|
43
|
+
type: "radio",
|
|
44
|
+
name: name,
|
|
45
|
+
onChange: onChange,
|
|
46
|
+
"aria-labelledby": `${id || name}-label`
|
|
47
|
+
}, attributes)), /*#__PURE__*/React.createElement(I18n.Text, {
|
|
48
|
+
string: ItemLabel,
|
|
49
|
+
"aria-hidden": true,
|
|
50
|
+
id: `${id || name}-label`,
|
|
51
|
+
className: classNames(style.label, 'label')
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
RadioItem.defaultProps = {
|
|
56
|
+
attributes: null,
|
|
57
|
+
id: null,
|
|
58
|
+
checked: false,
|
|
59
|
+
className: '',
|
|
60
|
+
onChange: () => {}
|
|
61
|
+
};
|
|
62
|
+
export default RadioItem;
|
|
@@ -1,2 +1,32 @@
|
|
|
1
|
-
import{css}from'glamor';
|
|
2
|
-
|
|
1
|
+
import { css } from 'glamor';
|
|
2
|
+
import { themeConfig } from '@shopgate/pwa-common/helpers/config';
|
|
3
|
+
const container = css({
|
|
4
|
+
display: 'flex',
|
|
5
|
+
marginLeft: -1 // Removes margin of svg.
|
|
6
|
+
}).toString();
|
|
7
|
+
const icon = css({
|
|
8
|
+
width: 24,
|
|
9
|
+
height: 24,
|
|
10
|
+
flexShrink: 0
|
|
11
|
+
}).toString();
|
|
12
|
+
const disabled = css({
|
|
13
|
+
opacity: 0.25,
|
|
14
|
+
pointerEvents: 'none'
|
|
15
|
+
}).toString();
|
|
16
|
+
const label = css({
|
|
17
|
+
flex: 1,
|
|
18
|
+
fontSize: '1rem',
|
|
19
|
+
lineHeight: 1.5,
|
|
20
|
+
marginLeft: themeConfig.variables.gap.small,
|
|
21
|
+
marginBottom: themeConfig.variables.gap.small
|
|
22
|
+
}).toString();
|
|
23
|
+
const active = css({
|
|
24
|
+
color: `var(--color-primary, ${themeConfig.colors.primary})`
|
|
25
|
+
}).toString();
|
|
26
|
+
export default {
|
|
27
|
+
icon,
|
|
28
|
+
disabled,
|
|
29
|
+
container,
|
|
30
|
+
label,
|
|
31
|
+
active
|
|
32
|
+
};
|
package/Form/RadioGroup/index.js
CHANGED
|
@@ -1,13 +1,105 @@
|
|
|
1
|
-
|
|
1
|
+
import React, { Component, Children, cloneElement } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import FormElement from '@shopgate/pwa-ui-shared/FormElement';
|
|
5
|
+
import style from "./style";
|
|
6
|
+
|
|
7
|
+
/**
|
|
2
8
|
* RadioGroup component.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
|
|
9
|
+
*/
|
|
10
|
+
class RadioGroup extends Component {
|
|
11
|
+
/**
|
|
12
|
+
* Initializes the component.
|
|
13
|
+
* @param {Object} props The components props.
|
|
14
|
+
*/
|
|
15
|
+
constructor(props) {
|
|
16
|
+
super(props);
|
|
17
|
+
/**
|
|
18
|
+
* @param {string} event click from radio element
|
|
19
|
+
*/
|
|
20
|
+
this.handleChange = ({
|
|
21
|
+
target: {
|
|
22
|
+
name
|
|
23
|
+
}
|
|
24
|
+
}) => {
|
|
25
|
+
if (this.props.disabled) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (!this.props.isControlled) {
|
|
29
|
+
this.setState({
|
|
30
|
+
value: name
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
this.props.onChange(name);
|
|
34
|
+
};
|
|
35
|
+
this.state = {
|
|
36
|
+
value: props.value
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
6
41
|
* @param {Object} nextProps props
|
|
7
|
-
*/
|
|
42
|
+
*/
|
|
43
|
+
UNSAFE_componentWillReceiveProps(nextProps) {
|
|
44
|
+
if (this.props.isControlled && this.state.value !== nextProps.value) {
|
|
45
|
+
this.setState({
|
|
46
|
+
value: nextProps.value
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
8
51
|
* Renders the component.
|
|
9
52
|
* @returns {JSX}
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
53
|
+
*/
|
|
54
|
+
render() {
|
|
55
|
+
const {
|
|
56
|
+
children,
|
|
57
|
+
className,
|
|
58
|
+
label,
|
|
59
|
+
errorText,
|
|
60
|
+
direction,
|
|
61
|
+
name,
|
|
62
|
+
translateErrorText,
|
|
63
|
+
disabled,
|
|
64
|
+
showErrorText
|
|
65
|
+
} = this.props;
|
|
66
|
+
return /*#__PURE__*/React.createElement(FormElement, {
|
|
67
|
+
className: classNames(className, 'radioGroup', 'ui-shared__form__radio-group', {
|
|
68
|
+
disabled
|
|
69
|
+
}),
|
|
70
|
+
label: label,
|
|
71
|
+
labelStatic: true,
|
|
72
|
+
errorText: errorText,
|
|
73
|
+
translateErrorText: translateErrorText,
|
|
74
|
+
showErrorText: showErrorText,
|
|
75
|
+
htmlFor: "none",
|
|
76
|
+
hasUnderline: false,
|
|
77
|
+
hasValue: true
|
|
78
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
79
|
+
className: classNames(style.container(direction), 'radioGroup')
|
|
80
|
+
}, Children.map(children, child => {
|
|
81
|
+
if (!child) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
return /*#__PURE__*/cloneElement(child, {
|
|
85
|
+
key: `${name}_${child.props.name}`,
|
|
86
|
+
checked: this.state.value === child.props.name,
|
|
87
|
+
onChange: this.handleChange
|
|
88
|
+
});
|
|
89
|
+
})));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
RadioGroup.defaultProps = {
|
|
93
|
+
onChange: () => {},
|
|
94
|
+
children: null,
|
|
95
|
+
className: '',
|
|
96
|
+
direction: 'column',
|
|
97
|
+
disabled: false,
|
|
98
|
+
errorText: '',
|
|
99
|
+
isControlled: false,
|
|
100
|
+
label: '',
|
|
101
|
+
translateErrorText: true,
|
|
102
|
+
value: null,
|
|
103
|
+
showErrorText: true
|
|
104
|
+
};
|
|
105
|
+
export default RadioGroup;
|
package/Form/RadioGroup/spec.js
CHANGED
|
@@ -1,3 +1,83 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { mount } from 'enzyme';
|
|
4
|
+
import RadioItem from "./components/Item";
|
|
5
|
+
import RadioGroup from '.';
|
|
6
|
+
const defProps = {
|
|
7
|
+
name: 'radio'
|
|
8
|
+
};
|
|
9
|
+
jest.mock('@shopgate/engage/components');
|
|
10
|
+
describe('<RadioGroup />', () => {
|
|
11
|
+
it('should render empty group', () => {
|
|
12
|
+
const wrapper = mount(/*#__PURE__*/React.createElement(RadioGroup, defProps));
|
|
13
|
+
expect(wrapper).toMatchSnapshot();
|
|
14
|
+
});
|
|
15
|
+
it('should render column group with items', () => {
|
|
16
|
+
const wrapper = mount(/*#__PURE__*/React.createElement(RadioGroup, defProps, /*#__PURE__*/React.createElement(RadioItem, {
|
|
17
|
+
name: "foo",
|
|
18
|
+
label: "foo"
|
|
19
|
+
})));
|
|
20
|
+
expect(wrapper).toMatchSnapshot();
|
|
21
|
+
expect(wrapper.find(RadioItem).length).toEqual(1);
|
|
22
|
+
expect(typeof wrapper.find(RadioItem).prop('onChange')).toEqual('function');
|
|
23
|
+
});
|
|
24
|
+
it('should render rows group with items', () => {
|
|
25
|
+
const wrapper = mount(/*#__PURE__*/React.createElement(RadioGroup, _extends({}, defProps, {
|
|
26
|
+
direction: "rows"
|
|
27
|
+
}), /*#__PURE__*/React.createElement(RadioItem, {
|
|
28
|
+
name: "foo",
|
|
29
|
+
label: "foo"
|
|
30
|
+
})));
|
|
31
|
+
expect(wrapper).toMatchSnapshot();
|
|
32
|
+
});
|
|
33
|
+
it('should use default value', () => {
|
|
34
|
+
const wrapper = mount(/*#__PURE__*/React.createElement(RadioGroup, _extends({}, defProps, {
|
|
35
|
+
value: "foo"
|
|
36
|
+
}), /*#__PURE__*/React.createElement(RadioItem, {
|
|
37
|
+
name: "foo",
|
|
38
|
+
label: "foo"
|
|
39
|
+
})));
|
|
40
|
+
expect(wrapper).toMatchSnapshot();
|
|
41
|
+
expect(wrapper.find(RadioItem).length).toEqual(1);
|
|
42
|
+
expect(wrapper.find(RadioItem).prop('checked')).toEqual(true);
|
|
43
|
+
});
|
|
44
|
+
it('should have on value at a time', () => {
|
|
45
|
+
const wrapper = mount(/*#__PURE__*/React.createElement(RadioGroup, defProps, /*#__PURE__*/React.createElement(RadioItem, {
|
|
46
|
+
name: "foo",
|
|
47
|
+
label: "foo"
|
|
48
|
+
}), /*#__PURE__*/React.createElement(RadioItem, {
|
|
49
|
+
name: "bar",
|
|
50
|
+
label: "bar"
|
|
51
|
+
})));
|
|
52
|
+
expect(wrapper).toMatchSnapshot();
|
|
53
|
+
expect(wrapper.find(RadioItem).length).toEqual(2);
|
|
54
|
+
const radio1 = wrapper.find(RadioItem).at(0).find('input');
|
|
55
|
+
const radio2 = wrapper.find(RadioItem).at(1).find('input');
|
|
56
|
+
|
|
57
|
+
// First element value
|
|
58
|
+
radio1.simulate('change');
|
|
59
|
+
wrapper.update();
|
|
60
|
+
expect(wrapper.find(RadioItem).at(0).prop('checked')).toEqual(true);
|
|
61
|
+
expect(wrapper.find(RadioItem).at(1).prop('checked')).toEqual(false);
|
|
62
|
+
|
|
63
|
+
// Second element value
|
|
64
|
+
radio2.simulate('change');
|
|
65
|
+
wrapper.update();
|
|
66
|
+
expect(wrapper.find(RadioItem).at(0).prop('checked')).toEqual(false);
|
|
67
|
+
expect(wrapper.find(RadioItem).at(1).prop('checked')).toEqual(true);
|
|
68
|
+
});
|
|
69
|
+
it('should call onChange callback', () => {
|
|
70
|
+
const onChange = jest.fn();
|
|
71
|
+
const wrapper = mount(/*#__PURE__*/React.createElement(RadioGroup, _extends({}, defProps, {
|
|
72
|
+
onChange: onChange
|
|
73
|
+
}), /*#__PURE__*/React.createElement(RadioItem, {
|
|
74
|
+
name: "foo",
|
|
75
|
+
label: "foo"
|
|
76
|
+
})));
|
|
77
|
+
expect(wrapper).toMatchSnapshot();
|
|
78
|
+
expect(wrapper.find(RadioItem).length).toEqual(1);
|
|
79
|
+
const radio = wrapper.find(RadioItem).at(0).find('input');
|
|
80
|
+
radio.simulate('change');
|
|
81
|
+
expect(onChange).toHaveBeenCalledWith('foo');
|
|
82
|
+
});
|
|
83
|
+
});
|
package/Form/RadioGroup/style.js
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
import{css}from'glamor';
|
|
1
|
+
import { css } from 'glamor';
|
|
2
|
+
import { themeConfig } from '@shopgate/pwa-common/helpers/config';
|
|
3
|
+
|
|
4
|
+
/**
|
|
2
5
|
* @param {string} direction flex direction
|
|
3
6
|
* @returns {*}
|
|
4
|
-
*/
|
|
7
|
+
*/
|
|
8
|
+
const container = direction => css({
|
|
9
|
+
display: 'flex',
|
|
10
|
+
flexDirection: direction
|
|
11
|
+
}).toString();
|
|
12
|
+
const label = css({
|
|
13
|
+
fontSize: '0.8rem',
|
|
14
|
+
paddingBottom: themeConfig.variables.gap.small,
|
|
15
|
+
color: themeConfig.colors.shade12
|
|
16
|
+
}).toString();
|
|
17
|
+
export default {
|
|
18
|
+
container,
|
|
19
|
+
label
|
|
20
|
+
};
|
package/Form/Select/index.js
CHANGED
|
@@ -1,18 +1,166 @@
|
|
|
1
|
-
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import React, { Component } from 'react';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import classNames from 'classnames';
|
|
5
|
+
import Chevron from "../../icons/ChevronIcon";
|
|
6
|
+
import FormElement from "../../FormElement";
|
|
7
|
+
import styles from "./style";
|
|
8
|
+
|
|
9
|
+
/**
|
|
2
10
|
* A component that provides a styled select for user input in material design.
|
|
3
|
-
*/
|
|
11
|
+
*/
|
|
12
|
+
class Select extends Component {
|
|
13
|
+
/**
|
|
4
14
|
* Creates a new text field component.
|
|
5
15
|
* @param {Object} props The component properties.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
16
|
+
*/
|
|
17
|
+
constructor(props) {
|
|
18
|
+
super(props);
|
|
19
|
+
/**
|
|
20
|
+
* @param {string} value The entered text.
|
|
21
|
+
*/
|
|
22
|
+
this.handleChange = ({
|
|
23
|
+
target
|
|
24
|
+
}) => {
|
|
25
|
+
const {
|
|
26
|
+
multiple
|
|
27
|
+
} = this.props;
|
|
28
|
+
let {
|
|
29
|
+
value
|
|
30
|
+
} = target;
|
|
31
|
+
if (multiple) {
|
|
32
|
+
value = Array.from(target.selectedOptions, option => option.value);
|
|
33
|
+
}
|
|
34
|
+
if (!this.props.isControlled) {
|
|
35
|
+
this.setState({
|
|
36
|
+
value
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
this.props.onChange(value);
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* @param {boolean} isFocused focused
|
|
43
|
+
*/
|
|
44
|
+
this.handleFocusChange = isFocused => {
|
|
45
|
+
this.setState({
|
|
46
|
+
isFocused
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
this.state = {
|
|
50
|
+
value: props.value,
|
|
51
|
+
isFocused: false
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
11
56
|
* Corrects the selected value to the first option when the initial value is not located within
|
|
12
57
|
* the options.
|
|
13
|
-
*/
|
|
58
|
+
*/
|
|
59
|
+
componentDidMount() {
|
|
60
|
+
const {
|
|
61
|
+
multiple,
|
|
62
|
+
options
|
|
63
|
+
} = this.props;
|
|
64
|
+
const {
|
|
65
|
+
value
|
|
66
|
+
} = this.state;
|
|
67
|
+
if (!multiple && options?.[value] === undefined) {
|
|
68
|
+
const fallback = Object.entries(options)?.[0]?.[0];
|
|
69
|
+
if (fallback !== undefined) {
|
|
70
|
+
this.handleChange({
|
|
71
|
+
target: {
|
|
72
|
+
value: fallback
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
14
80
|
* Update state with new props.
|
|
15
81
|
* @param {Object} nextProps The new props.
|
|
16
|
-
*/
|
|
82
|
+
*/
|
|
83
|
+
UNSAFE_componentWillReceiveProps(nextProps) {
|
|
84
|
+
this.setState({
|
|
85
|
+
value: nextProps.value
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
17
89
|
* @return {JSX.Element}
|
|
18
|
-
*/
|
|
90
|
+
*/
|
|
91
|
+
render() {
|
|
92
|
+
const {
|
|
93
|
+
name,
|
|
94
|
+
options,
|
|
95
|
+
translateErrorText,
|
|
96
|
+
disabled,
|
|
97
|
+
multiple,
|
|
98
|
+
size,
|
|
99
|
+
showErrorText,
|
|
100
|
+
className,
|
|
101
|
+
placeholder,
|
|
102
|
+
label,
|
|
103
|
+
errorText,
|
|
104
|
+
required,
|
|
105
|
+
'aria-invalid': ariaInvalid,
|
|
106
|
+
'aria-describedby': ariaDescribedBy
|
|
107
|
+
} = this.props;
|
|
108
|
+
const {
|
|
109
|
+
value,
|
|
110
|
+
isFocused
|
|
111
|
+
} = this.state;
|
|
112
|
+
return /*#__PURE__*/React.createElement(FormElement, {
|
|
113
|
+
className: `${className} ui-shared__form__select`,
|
|
114
|
+
placeholder: placeholder,
|
|
115
|
+
htmlFor: name,
|
|
116
|
+
label: label,
|
|
117
|
+
errorText: errorText,
|
|
118
|
+
translateErrorText: translateErrorText,
|
|
119
|
+
isFocused: isFocused,
|
|
120
|
+
hasValue: !!value || !!options[''],
|
|
121
|
+
hasPlaceholder: !disabled || value !== '',
|
|
122
|
+
disabled: disabled,
|
|
123
|
+
showErrorText: showErrorText
|
|
124
|
+
}, /*#__PURE__*/React.createElement("select", _extends({
|
|
125
|
+
id: name,
|
|
126
|
+
name: name,
|
|
127
|
+
onChange: this.handleChange,
|
|
128
|
+
onFocus: () => this.handleFocusChange(true),
|
|
129
|
+
onBlur: () => this.handleFocusChange(false),
|
|
130
|
+
value: value,
|
|
131
|
+
className: classNames(styles.select, 'select'),
|
|
132
|
+
disabled: disabled,
|
|
133
|
+
required: required,
|
|
134
|
+
"aria-invalid": ariaInvalid,
|
|
135
|
+
"aria-describedby": ariaDescribedBy
|
|
136
|
+
}, multiple && {
|
|
137
|
+
multiple,
|
|
138
|
+
size
|
|
139
|
+
}), Object.keys(options).map(key => /*#__PURE__*/React.createElement("option", {
|
|
140
|
+
className: "option",
|
|
141
|
+
value: key,
|
|
142
|
+
key: `${name}_${key}`
|
|
143
|
+
}, options[key]))), /*#__PURE__*/React.createElement(Chevron, {
|
|
144
|
+
className: styles.chevron
|
|
145
|
+
}));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
Select.defaultProps = {
|
|
149
|
+
'aria-invalid': false,
|
|
150
|
+
'aria-describedby': null,
|
|
151
|
+
className: '',
|
|
152
|
+
errorText: '',
|
|
153
|
+
isControlled: false,
|
|
154
|
+
placeholder: '',
|
|
155
|
+
label: '',
|
|
156
|
+
onChange: () => {},
|
|
157
|
+
options: {},
|
|
158
|
+
translateErrorText: true,
|
|
159
|
+
showErrorText: true,
|
|
160
|
+
size: null,
|
|
161
|
+
value: '',
|
|
162
|
+
disabled: false,
|
|
163
|
+
required: false,
|
|
164
|
+
multiple: false
|
|
165
|
+
};
|
|
166
|
+
export default Select;
|
package/Form/Select/spec.js
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { mount } from 'enzyme';
|
|
4
|
+
import Select from "./index";
|
|
5
|
+
const inputProps = {
|
|
6
|
+
name: 'test-name'
|
|
7
|
+
};
|
|
8
|
+
describe('<Select />', () => {
|
|
9
|
+
// Simple tests for snapshots
|
|
10
|
+
const tests = {
|
|
11
|
+
'should render select with no options': {},
|
|
12
|
+
// eslint-disable-next-line extra-rules/no-single-line-objects
|
|
13
|
+
'should render select with 2 options': {
|
|
14
|
+
options: {
|
|
15
|
+
DE: 'Germany',
|
|
16
|
+
US: 'United states'
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
// eslint-disable-next-line extra-rules/no-single-line-objects
|
|
20
|
+
'should render select with 1 selected option': {
|
|
21
|
+
options: {
|
|
22
|
+
DE: 'Germany',
|
|
23
|
+
US: 'United states'
|
|
24
|
+
},
|
|
25
|
+
value: 'DE'
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
Object.keys(tests).forEach(test => {
|
|
29
|
+
it(test, () => {
|
|
30
|
+
const testFixtures = tests[test];
|
|
31
|
+
// eslint-disable-next-line extra-rules/no-single-line-objects
|
|
32
|
+
const wrapper = mount(/*#__PURE__*/React.createElement(Select, _extends({}, inputProps, testFixtures)));
|
|
33
|
+
expect(wrapper).toMatchSnapshot();
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
});
|
package/Form/Select/style.js
CHANGED
|
@@ -1 +1,27 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { css } from 'glamor';
|
|
2
|
+
const select = css({
|
|
3
|
+
appearance: 'none',
|
|
4
|
+
position: 'relative',
|
|
5
|
+
overflow: 'hidden',
|
|
6
|
+
whiteSpace: 'nowrap',
|
|
7
|
+
textOverflow: 'ellipsis',
|
|
8
|
+
padding: '0 20px 0 0',
|
|
9
|
+
width: '100%',
|
|
10
|
+
margin: '24px 0 0 0',
|
|
11
|
+
outline: 0,
|
|
12
|
+
fontSize: 16,
|
|
13
|
+
lineHeight: '19px',
|
|
14
|
+
zIndex: 10
|
|
15
|
+
}).toString();
|
|
16
|
+
const chevron = css({
|
|
17
|
+
position: 'absolute',
|
|
18
|
+
top: '50%',
|
|
19
|
+
right: 0,
|
|
20
|
+
transform: 'translateY(-50%) rotateZ(-90deg)',
|
|
21
|
+
fontSize: '1.3em !important',
|
|
22
|
+
marginTop: -3
|
|
23
|
+
}).toString();
|
|
24
|
+
export default {
|
|
25
|
+
select,
|
|
26
|
+
chevron
|
|
27
|
+
};
|