@shopgate/pwa-ui-shared 7.30.0-alpha.7 → 7.30.0-alpha.8
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 +59 -2
- package/ActionButton/style.js +22 -1
- package/AddToCartButton/index.js +184 -27
- package/AddToCartButton/mock.js +18 -4
- package/AddToCartButton/spec.js +51 -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 +300 -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 +41 -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,34 @@
|
|
|
1
|
-
import{css}from'glamor'
|
|
1
|
+
import { css } from 'glamor';
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* The styles for the input field.
|
|
3
|
-
*/
|
|
5
|
+
*/
|
|
6
|
+
const input = css({
|
|
7
|
+
position: 'relative',
|
|
8
|
+
padding: 0,
|
|
9
|
+
width: '100%',
|
|
10
|
+
marginTop: 24,
|
|
11
|
+
outline: 0,
|
|
12
|
+
fontSize: 16,
|
|
13
|
+
lineHeight: '19px'
|
|
14
|
+
}).toString();
|
|
15
|
+
|
|
16
|
+
/**
|
|
4
17
|
* The styles for the multiLine.
|
|
5
|
-
*/
|
|
6
|
-
|
|
18
|
+
*/
|
|
19
|
+
const multiLine = css({
|
|
20
|
+
position: 'relative',
|
|
21
|
+
marginTop: 24,
|
|
22
|
+
marginBottom: 3,
|
|
23
|
+
padding: 0,
|
|
24
|
+
width: '100%',
|
|
25
|
+
outline: 0,
|
|
26
|
+
height: 19,
|
|
27
|
+
minHeight: 19,
|
|
28
|
+
lineHeight: '19px',
|
|
29
|
+
verticalAlign: 'top' // Important to avoid bottom whitespace.
|
|
30
|
+
}).toString();
|
|
31
|
+
export default {
|
|
32
|
+
input,
|
|
33
|
+
multiLine
|
|
34
|
+
};
|
|
@@ -1,6 +1,25 @@
|
|
|
1
|
-
import React from'react';
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import I18n from '@shopgate/pwa-common/components/I18n';
|
|
5
|
+
import styles from "./style";
|
|
6
|
+
|
|
7
|
+
/**
|
|
2
8
|
* The form element hint component.
|
|
3
9
|
* @param {string} hintText The hint text.
|
|
4
10
|
* @param {boolean} visible Sets the hint visibility.
|
|
5
11
|
* @return {JSX}
|
|
6
|
-
*/
|
|
12
|
+
*/
|
|
13
|
+
const Hint = ({
|
|
14
|
+
hintText,
|
|
15
|
+
visible
|
|
16
|
+
}) => /*#__PURE__*/React.createElement("div", {
|
|
17
|
+
className: classNames(styles.hintStyles(visible), 'hint')
|
|
18
|
+
}, /*#__PURE__*/React.createElement(I18n.Text, {
|
|
19
|
+
string: hintText
|
|
20
|
+
}));
|
|
21
|
+
Hint.defaultProps = {
|
|
22
|
+
hintText: '',
|
|
23
|
+
visible: false
|
|
24
|
+
};
|
|
25
|
+
export default Hint;
|
|
@@ -1,11 +1,46 @@
|
|
|
1
|
-
|
|
1
|
+
import { css } from 'glamor';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import { themeConfig } from '@shopgate/pwa-common/helpers/config';
|
|
4
|
+
|
|
5
|
+
/**
|
|
2
6
|
* The style object for a one line text element with an ellipsis on overflow.
|
|
3
|
-
*/
|
|
7
|
+
*/
|
|
8
|
+
const ellipsisLine = {
|
|
9
|
+
overflow: 'hidden',
|
|
10
|
+
width: '100%',
|
|
11
|
+
whiteSpace: 'nowrap',
|
|
12
|
+
textOverflow: 'ellipsis'
|
|
13
|
+
};
|
|
14
|
+
const easing = '450ms cubic-bezier(0.23, 1, 0.32, 1)';
|
|
15
|
+
|
|
16
|
+
/**
|
|
4
17
|
* The styles for the hint text.
|
|
5
|
-
*/
|
|
18
|
+
*/
|
|
19
|
+
const hint = css({
|
|
20
|
+
position: 'absolute',
|
|
21
|
+
pointerEvents: 'none',
|
|
22
|
+
bottom: 12,
|
|
23
|
+
color: themeConfig.colors.shade4,
|
|
24
|
+
willChange: 'transform',
|
|
25
|
+
transition: `opacity ${easing}`,
|
|
26
|
+
...ellipsisLine
|
|
27
|
+
}).toString();
|
|
28
|
+
|
|
29
|
+
/**
|
|
6
30
|
* The styles for the invisible hint text.
|
|
7
|
-
*/
|
|
31
|
+
*/
|
|
32
|
+
const hintInactive = css({
|
|
33
|
+
opacity: 0
|
|
34
|
+
}).toString();
|
|
35
|
+
|
|
36
|
+
/**
|
|
8
37
|
* Gets the style classes for the underline element.
|
|
9
38
|
* @param {boolean} visible Whether the hint is visible.
|
|
10
39
|
* @return {string} The style classes.
|
|
11
|
-
*/
|
|
40
|
+
*/
|
|
41
|
+
const hintStyles = (visible = false) => classNames(hint, {
|
|
42
|
+
[hintInactive]: !visible
|
|
43
|
+
});
|
|
44
|
+
export default {
|
|
45
|
+
hintStyles
|
|
46
|
+
};
|
|
@@ -1,6 +1,35 @@
|
|
|
1
|
-
import React from'react';
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import I18n from '@shopgate/pwa-common/components/I18n';
|
|
5
|
+
import styles from "./style";
|
|
6
|
+
|
|
7
|
+
/**
|
|
2
8
|
* Renders the label element.
|
|
3
9
|
* @param {Object} props The component props.
|
|
4
10
|
* @return {JSX}
|
|
5
|
-
*/
|
|
6
|
-
|
|
11
|
+
*/
|
|
12
|
+
const Label = props => {
|
|
13
|
+
const labelStyles = styles.labelStyles(props.isFocused, props.isFloating, props.hasErrorMessage);
|
|
14
|
+
return (
|
|
15
|
+
/*#__PURE__*/
|
|
16
|
+
// eslint-disable-next-line jsx-a11y/label-has-associated-control
|
|
17
|
+
React.createElement("label", {
|
|
18
|
+
htmlFor: props.name,
|
|
19
|
+
"aria-hidden": true,
|
|
20
|
+
className: classNames(labelStyles, 'label', {
|
|
21
|
+
floating: props.isFloating
|
|
22
|
+
})
|
|
23
|
+
}, /*#__PURE__*/React.createElement(I18n.Text, {
|
|
24
|
+
string: props.label
|
|
25
|
+
}))
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
Label.defaultProps = {
|
|
29
|
+
name: '',
|
|
30
|
+
label: '',
|
|
31
|
+
isFocused: false,
|
|
32
|
+
isFloating: false,
|
|
33
|
+
hasErrorMessage: false
|
|
34
|
+
};
|
|
35
|
+
export default Label;
|
|
@@ -1,20 +1,80 @@
|
|
|
1
|
-
|
|
1
|
+
import { css } from 'glamor';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import { themeConfig } from '@shopgate/pwa-common/helpers/config';
|
|
4
|
+
|
|
5
|
+
/**
|
|
2
6
|
* The style object for a one line text element with an ellipsis on overflow.
|
|
3
|
-
*/
|
|
7
|
+
*/
|
|
8
|
+
const ellipsisLine = {
|
|
9
|
+
overflow: 'hidden',
|
|
10
|
+
width: '100%',
|
|
11
|
+
whiteSpace: 'nowrap',
|
|
12
|
+
textOverflow: 'ellipsis'
|
|
13
|
+
};
|
|
14
|
+
const {
|
|
15
|
+
colors
|
|
16
|
+
} = themeConfig;
|
|
17
|
+
const easing = '450ms cubic-bezier(0.23, 1, 0.32, 1)';
|
|
18
|
+
|
|
19
|
+
/**
|
|
4
20
|
* The styles for the error label.
|
|
5
|
-
*/
|
|
21
|
+
*/
|
|
22
|
+
const labelError = css({
|
|
23
|
+
color: `var(--color-state-alert, ${colors.error})`
|
|
24
|
+
}).toString();
|
|
25
|
+
|
|
26
|
+
/**
|
|
6
27
|
* The styles for the regular label.
|
|
7
|
-
*/
|
|
28
|
+
*/
|
|
29
|
+
const labelRegular = css({
|
|
30
|
+
color: colors.shade4
|
|
31
|
+
}).toString();
|
|
32
|
+
|
|
33
|
+
/**
|
|
8
34
|
* The styles for the focused label.
|
|
9
|
-
*/
|
|
35
|
+
*/
|
|
36
|
+
const labelFocus = css({
|
|
37
|
+
color: colors.focus
|
|
38
|
+
}).toString();
|
|
39
|
+
|
|
40
|
+
/**
|
|
10
41
|
* The styles for the floating label.
|
|
11
|
-
*/
|
|
42
|
+
*/
|
|
43
|
+
const labelFloating = css({
|
|
44
|
+
transform: 'translate3d(0, -22px, 0) scale3d(0.75, 0.75, 0.75)'
|
|
45
|
+
}).toString();
|
|
46
|
+
|
|
47
|
+
/**
|
|
12
48
|
* The basic styles for the label.
|
|
13
49
|
* @type {string}
|
|
14
|
-
*/
|
|
50
|
+
*/
|
|
51
|
+
const label = css({
|
|
52
|
+
position: 'absolute',
|
|
53
|
+
left: 0,
|
|
54
|
+
top: 24,
|
|
55
|
+
lineHeight: '19px',
|
|
56
|
+
pointerEvents: 'none',
|
|
57
|
+
userSelect: 'none',
|
|
58
|
+
color: `var(--color-text-medium-emphasis, ${colors.shade6})`,
|
|
59
|
+
transformOrigin: 'left top 0px',
|
|
60
|
+
willChange: 'transform, color',
|
|
61
|
+
transition: `transform ${easing}, color ${easing}`,
|
|
62
|
+
...ellipsisLine
|
|
63
|
+
}).toString();
|
|
64
|
+
|
|
65
|
+
/**
|
|
15
66
|
* Gets the style classes for the label.
|
|
16
67
|
* @param {boolean} focused Whether the input field is focused.
|
|
17
68
|
* @param {boolean} floating Whether the label is floating.
|
|
18
69
|
* @param {boolean} error Whether the input field shows an error message.
|
|
19
70
|
* @return {string} The style classes.
|
|
20
|
-
*/
|
|
71
|
+
*/
|
|
72
|
+
const labelStyles = (focused = false, floating = false, error = false) => classNames(label, {
|
|
73
|
+
[labelFloating]: floating,
|
|
74
|
+
[labelRegular]: !focused,
|
|
75
|
+
[labelFocus]: !error && focused,
|
|
76
|
+
[labelError]: error && focused
|
|
77
|
+
});
|
|
78
|
+
export default {
|
|
79
|
+
labelStyles
|
|
80
|
+
};
|
|
@@ -1,5 +1,22 @@
|
|
|
1
|
-
import React from'react';
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import styles from "./style";
|
|
5
|
+
|
|
6
|
+
/**
|
|
2
7
|
* Renders the label element.
|
|
3
8
|
* @param {Object} props The component props.
|
|
4
9
|
* @return {JSX}
|
|
5
|
-
*/
|
|
10
|
+
*/
|
|
11
|
+
const Underline = props => /*#__PURE__*/React.createElement("div", {
|
|
12
|
+
className: classNames(styles.underlineWrapper, 'underline'),
|
|
13
|
+
"aria-hidden": true
|
|
14
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
15
|
+
className: styles.underline,
|
|
16
|
+
style: styles.underlineStyle(props.isFocused, props.hasErrorMessage)
|
|
17
|
+
}));
|
|
18
|
+
Underline.defaultProps = {
|
|
19
|
+
isFocused: false,
|
|
20
|
+
hasErrorMessage: false
|
|
21
|
+
};
|
|
22
|
+
export default Underline;
|
|
@@ -1,13 +1,60 @@
|
|
|
1
|
-
|
|
1
|
+
import { css } from 'glamor';
|
|
2
|
+
import color from 'color';
|
|
3
|
+
import { getCSSCustomProp } from '@shopgate/engage/styles';
|
|
4
|
+
import { themeConfig } from '@shopgate/pwa-common/helpers/config';
|
|
5
|
+
const {
|
|
6
|
+
colors
|
|
7
|
+
} = themeConfig;
|
|
8
|
+
const easing = '450ms cubic-bezier(0.23, 1, 0.32, 1)';
|
|
9
|
+
|
|
10
|
+
/**
|
|
2
11
|
* The styles for the underline wrapper element.
|
|
3
|
-
*/
|
|
12
|
+
*/
|
|
13
|
+
const underlineWrapper = css({
|
|
14
|
+
position: 'relative',
|
|
15
|
+
width: '100%',
|
|
16
|
+
borderBottom: `1px solid ${colors.shade12}`,
|
|
17
|
+
marginTop: 2,
|
|
18
|
+
marginBottom: 7
|
|
19
|
+
}).toString();
|
|
20
|
+
|
|
21
|
+
/**
|
|
4
22
|
* The styles for the underline element.
|
|
5
23
|
* @param {boolean} focused Whether the input field is focused.
|
|
6
24
|
* @param {boolean} error Whether the input field shows an error message.
|
|
7
25
|
* @return {string} The style class.
|
|
8
|
-
*/
|
|
26
|
+
*/
|
|
27
|
+
const underline = css({
|
|
28
|
+
position: 'relative',
|
|
29
|
+
width: '100%',
|
|
30
|
+
top: 1,
|
|
31
|
+
borderBottomWidth: 2,
|
|
32
|
+
borderBottomStyle: 'solid',
|
|
33
|
+
willChange: 'transform',
|
|
34
|
+
transition: `transform ${easing}`
|
|
35
|
+
}).toString();
|
|
36
|
+
|
|
37
|
+
/**
|
|
9
38
|
* Returns the underline style.
|
|
10
39
|
* @param {boolean} focused Is focused set or not.
|
|
11
40
|
* @param {boolean} hasError Has error set or not.
|
|
12
41
|
* @return {Object} style
|
|
13
|
-
*/
|
|
42
|
+
*/
|
|
43
|
+
const underlineStyle = (focused, hasError) => {
|
|
44
|
+
const primaryColor = getCSSCustomProp('--color-primary') || colors.primary;
|
|
45
|
+
let focusColor = '--color-primary';
|
|
46
|
+
if (color(primaryColor).luminosity() >= 0.8) {
|
|
47
|
+
focusColor = '--color-secondary';
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
borderBottomColor: hasError ? `var(--color-state-alert, ${colors.error})` : `var(${focusColor}, ${colors.focus})`,
|
|
51
|
+
...(!focused && !hasError && {
|
|
52
|
+
transform: 'scale3d(0,1,1)'
|
|
53
|
+
})
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
export default {
|
|
57
|
+
underline,
|
|
58
|
+
underlineWrapper,
|
|
59
|
+
underlineStyle
|
|
60
|
+
};
|
package/TextField/index.js
CHANGED
|
@@ -1,36 +1,198 @@
|
|
|
1
|
-
|
|
1
|
+
import React, { Component } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import Label from "./components/Label";
|
|
5
|
+
import Underline from "./components/Underline";
|
|
6
|
+
import ErrorText from "./components/ErrorText";
|
|
7
|
+
import Hint from "./components/Hint";
|
|
8
|
+
import styles from "./style";
|
|
9
|
+
import FormElement from "./components/FormElement/index";
|
|
10
|
+
|
|
11
|
+
/**
|
|
2
12
|
* A component that provides a styled text field for user input in material design.
|
|
3
|
-
*/
|
|
13
|
+
*/
|
|
14
|
+
class TextField extends Component {
|
|
15
|
+
/**
|
|
4
16
|
* Creates a new text field component.
|
|
5
17
|
* @param {Object} props The component properties.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
*/
|
|
19
|
+
constructor(props) {
|
|
20
|
+
super(props);
|
|
21
|
+
/**
|
|
22
|
+
* Internal focus event handler.
|
|
23
|
+
* @param {boolean} isFocused Whether the input component is focused.
|
|
24
|
+
*/
|
|
25
|
+
this.handleFocusChange = isFocused => {
|
|
26
|
+
this.setState({
|
|
27
|
+
isFocused
|
|
28
|
+
});
|
|
29
|
+
this.props.onFocusChange(isFocused);
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Updates the state if the input value has been changed.
|
|
33
|
+
* @param {string} value The entered text.
|
|
34
|
+
* @param {Object} event The original event object.
|
|
35
|
+
*/
|
|
36
|
+
this.handleChange = (value, event) => {
|
|
37
|
+
this.props.onChange(value, event);
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Updates the validation error text if required.
|
|
41
|
+
* @param {string} value The entered text.
|
|
42
|
+
* @param {boolean} isInitial Whether this is the initial value of the input field.
|
|
43
|
+
* @return {boolean} Whether the validation was successful.
|
|
44
|
+
*/
|
|
45
|
+
this.handleValidate = (value, isInitial) => {
|
|
46
|
+
const validationError = this.props.onValidate(value);
|
|
47
|
+
if (validationError !== true && validationError) {
|
|
48
|
+
/**
|
|
49
|
+
* An error message was returned by the validation callback. Update the state.
|
|
50
|
+
* Because the validation is performed when the component is constructed, we need to make
|
|
51
|
+
* sure we're not calling setState() in this situation.
|
|
52
|
+
*/
|
|
53
|
+
if (!isInitial) {
|
|
54
|
+
this.setState({
|
|
55
|
+
validationError
|
|
56
|
+
});
|
|
57
|
+
} else {
|
|
58
|
+
this.state.validationError = validationError;
|
|
59
|
+
}
|
|
60
|
+
} else if (this.state.validationError) {
|
|
61
|
+
// There was no error, clear the state variable.
|
|
62
|
+
this.setState({
|
|
63
|
+
validationError: null
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Forward the boolean result to the input field.
|
|
68
|
+
return validationError === true;
|
|
69
|
+
};
|
|
70
|
+
this.state = {
|
|
71
|
+
isFocused: false,
|
|
72
|
+
validationError: null
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
25
77
|
* @returns {boolean} Whether the text field is currently focused.
|
|
26
|
-
*/
|
|
78
|
+
*/
|
|
79
|
+
get isFocused() {
|
|
80
|
+
return this.state.isFocused;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
27
84
|
* @returns {boolean} Whether the label is currently floating.
|
|
28
|
-
*/
|
|
29
|
-
|
|
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
|
+
/**
|
|
30
95
|
* @returns {boolean} Whether the hint text is currently visible.
|
|
31
|
-
*/
|
|
96
|
+
*/
|
|
97
|
+
get isHintVisible() {
|
|
98
|
+
return this.isFocused && !this.props.value;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
32
102
|
* @return {boolean} Whether the error message is set.
|
|
33
|
-
*/
|
|
103
|
+
*/
|
|
104
|
+
get hasErrorMessage() {
|
|
105
|
+
return !!(this.state.validationError || this.props.errorText);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
34
108
|
* Renders the text field.
|
|
35
109
|
* @return {JSX.Element}
|
|
36
|
-
*/
|
|
110
|
+
*/
|
|
111
|
+
render() {
|
|
112
|
+
const styleType = this.props.multiLine ? 'multiLine' : 'input';
|
|
113
|
+
const style = styles.container[styleType];
|
|
114
|
+
const {
|
|
115
|
+
multiLine,
|
|
116
|
+
className,
|
|
117
|
+
disabled,
|
|
118
|
+
hintText,
|
|
119
|
+
name,
|
|
120
|
+
label,
|
|
121
|
+
setRef,
|
|
122
|
+
onSanitize,
|
|
123
|
+
password,
|
|
124
|
+
type,
|
|
125
|
+
value,
|
|
126
|
+
isControlled,
|
|
127
|
+
inputComponent,
|
|
128
|
+
showErrorText,
|
|
129
|
+
errorText,
|
|
130
|
+
translateErrorText,
|
|
131
|
+
required
|
|
132
|
+
} = this.props;
|
|
133
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
134
|
+
className: classNames(style, className, 'textField', 'ui-shared__text-field', {
|
|
135
|
+
disabled
|
|
136
|
+
})
|
|
137
|
+
}, /*#__PURE__*/React.createElement(Hint, {
|
|
138
|
+
visible: this.isHintVisible,
|
|
139
|
+
hintText: hintText
|
|
140
|
+
}), /*#__PURE__*/React.createElement(Label, {
|
|
141
|
+
name: name,
|
|
142
|
+
label: label,
|
|
143
|
+
isFocused: this.isFocused,
|
|
144
|
+
isFloating: this.isLabelFloating,
|
|
145
|
+
hasErrorMessage: this.hasErrorMessage
|
|
146
|
+
}), /*#__PURE__*/React.createElement(FormElement, {
|
|
147
|
+
id: name,
|
|
148
|
+
multiLine: multiLine,
|
|
149
|
+
name: name,
|
|
150
|
+
setRef: setRef,
|
|
151
|
+
onFocusChange: this.handleFocusChange,
|
|
152
|
+
onChange: this.handleChange,
|
|
153
|
+
onSanitize: onSanitize,
|
|
154
|
+
onValidate: this.handleValidate,
|
|
155
|
+
password: password,
|
|
156
|
+
type: type,
|
|
157
|
+
value: value,
|
|
158
|
+
isControlled: isControlled,
|
|
159
|
+
inputComponent: inputComponent,
|
|
160
|
+
disabled: disabled,
|
|
161
|
+
required: required,
|
|
162
|
+
attributes: {
|
|
163
|
+
'aria-invalid': !!errorText,
|
|
164
|
+
'aria-describedby': this.hasErrorMessage ? `ariaError-${name}` : null
|
|
165
|
+
}
|
|
166
|
+
}), /*#__PURE__*/React.createElement(Underline, {
|
|
167
|
+
isFocused: this.isFocused,
|
|
168
|
+
hasErrorMessage: this.hasErrorMessage
|
|
169
|
+
}), showErrorText && /*#__PURE__*/React.createElement(ErrorText, {
|
|
170
|
+
validationError: this.state.validationError,
|
|
171
|
+
errorText: errorText,
|
|
172
|
+
translate: translateErrorText,
|
|
173
|
+
elementName: name
|
|
174
|
+
}));
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
TextField.defaultProps = {
|
|
178
|
+
className: '',
|
|
179
|
+
errorText: '',
|
|
180
|
+
showErrorText: true,
|
|
181
|
+
setRef: () => {},
|
|
182
|
+
hintText: '',
|
|
183
|
+
isControlled: false,
|
|
184
|
+
label: '',
|
|
185
|
+
multiLine: false,
|
|
186
|
+
onChange: () => {},
|
|
187
|
+
onFocusChange: () => {},
|
|
188
|
+
onSanitize: value => value,
|
|
189
|
+
onValidate: () => true,
|
|
190
|
+
required: false,
|
|
191
|
+
password: false,
|
|
192
|
+
translateErrorText: true,
|
|
193
|
+
type: 'text',
|
|
194
|
+
value: '',
|
|
195
|
+
inputComponent: 'input',
|
|
196
|
+
disabled: false
|
|
197
|
+
};
|
|
198
|
+
export default TextField;
|