@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
package/AddToCartButton/style.js
CHANGED
|
@@ -1,32 +1,148 @@
|
|
|
1
|
-
|
|
1
|
+
import { css } from 'glamor';
|
|
2
|
+
import spring from 'css-spring';
|
|
3
|
+
import { themeConfig } from '@shopgate/pwa-common/helpers/config';
|
|
4
|
+
const options = {
|
|
5
|
+
stiffness: 381.47,
|
|
6
|
+
damping: 15
|
|
7
|
+
};
|
|
8
|
+
const buttonSize = 40;
|
|
9
|
+
const iconSize = 20;
|
|
10
|
+
|
|
11
|
+
/**
|
|
2
12
|
* Keyframe animations to create spring animation.
|
|
3
13
|
* spring(..) automatically calculates all steps for the keyframe animation.
|
|
4
|
-
*/
|
|
14
|
+
*/
|
|
15
|
+
const springFromTopKeyframes = css.keyframes(spring({
|
|
16
|
+
transform: 'translate3d(0, 300%, 0)'
|
|
17
|
+
}, {
|
|
18
|
+
transform: 'translate3d(0, -50%, 0)'
|
|
19
|
+
}, options));
|
|
20
|
+
const springFromBottomKeyframes = css.keyframes(spring({
|
|
21
|
+
transform: 'translate3d(0, -300%, 0)'
|
|
22
|
+
}, {
|
|
23
|
+
transform: 'translate3d(0, -50%, 0)'
|
|
24
|
+
}, options));
|
|
25
|
+
const springToTopKeyframes = css.keyframes(spring({
|
|
26
|
+
transform: 'translate3d(0, -50%, 0)'
|
|
27
|
+
}, {
|
|
28
|
+
transform: 'translate3d(0, 300%, 0)'
|
|
29
|
+
}, options));
|
|
30
|
+
const springToBottomKeyframes = css.keyframes(spring({
|
|
31
|
+
transform: 'translate3d(0, -50%, 0)'
|
|
32
|
+
}, {
|
|
33
|
+
transform: 'translate3d(0, -300%, 0)'
|
|
34
|
+
}, options));
|
|
35
|
+
const springFromBottom = css({
|
|
36
|
+
animation: `${springFromBottomKeyframes} 600ms`
|
|
37
|
+
}).toString();
|
|
38
|
+
const springFromTop = css({
|
|
39
|
+
animation: `${springFromTopKeyframes} 600ms`
|
|
40
|
+
}).toString();
|
|
41
|
+
const springToTop = css({
|
|
42
|
+
animation: `${springToTopKeyframes} 600ms`
|
|
43
|
+
}).toString();
|
|
44
|
+
const springToBottom = css({
|
|
45
|
+
animation: `${springToBottomKeyframes} 600ms`
|
|
46
|
+
}).toString();
|
|
47
|
+
|
|
48
|
+
/**
|
|
5
49
|
* Circular button and container for the icons.
|
|
6
50
|
* Default styles.
|
|
7
51
|
* @param {number} bSize Size of the button.
|
|
8
52
|
* @param {number} iSize Size of the icon.
|
|
9
53
|
* @return {string} Class name
|
|
10
|
-
*/
|
|
11
|
-
|
|
54
|
+
*/
|
|
55
|
+
const buttonWrapperDefault = (bSize, iSize) => ({
|
|
56
|
+
transition: 'background 450ms cubic-bezier(0.4, 0.0, 0.2, 1)',
|
|
57
|
+
borderRadius: '50%',
|
|
58
|
+
width: bSize,
|
|
59
|
+
height: bSize,
|
|
60
|
+
position: 'relative',
|
|
61
|
+
fontSize: iSize,
|
|
62
|
+
outline: 0,
|
|
63
|
+
paddingLeft: (bSize - iSize) / 2,
|
|
64
|
+
paddingRight: (bSize - iSize) / 2,
|
|
65
|
+
zIndex: 2,
|
|
66
|
+
// Prevents the icons to be visible outside of the circle
|
|
67
|
+
overflow: 'hidden',
|
|
68
|
+
flexShrink: 0
|
|
69
|
+
});
|
|
70
|
+
/**
|
|
12
71
|
* Circular button and container for the icons.
|
|
13
72
|
* @param {number} bSize Size of the button.
|
|
14
73
|
* @param {number} iSize Size of the icon.
|
|
15
74
|
* @return {string} Class name
|
|
16
|
-
*/
|
|
75
|
+
*/
|
|
76
|
+
const buttonWrapper = (bSize, iSize) => css({
|
|
77
|
+
...buttonWrapperDefault(bSize, iSize)
|
|
78
|
+
}).toString();
|
|
79
|
+
|
|
80
|
+
/**
|
|
17
81
|
* Circular button and container for the icons.
|
|
18
82
|
* Without shadow.
|
|
19
83
|
* @param {number} bSize Size of the button.
|
|
20
84
|
* @param {number} iSize Size of the icon.
|
|
21
85
|
* @return {string} Class name
|
|
22
|
-
*/
|
|
86
|
+
*/
|
|
87
|
+
const buttonWrapperNoShadow = (bSize, iSize) => css({
|
|
88
|
+
...buttonWrapperDefault(bSize, iSize)
|
|
89
|
+
}).toString();
|
|
90
|
+
|
|
91
|
+
/**
|
|
23
92
|
* Styling that is applied to the button when cart icon is shown.
|
|
24
|
-
*/
|
|
93
|
+
*/
|
|
94
|
+
const buttonReady = css({
|
|
95
|
+
background: `var(--color-button-cta, ${themeConfig.colors.cta})`,
|
|
96
|
+
color: `var(--color-button-cta-contrast, ${themeConfig.colors.ctaContrast})`
|
|
97
|
+
}).toString();
|
|
98
|
+
|
|
99
|
+
/**
|
|
25
100
|
* Styling that is applied to the button when checkmark is shown.
|
|
26
|
-
*/
|
|
101
|
+
*/
|
|
102
|
+
const buttonSuccess = css({
|
|
103
|
+
background: `var(--color-button-cta-contrast, ${themeConfig.colors.ctaContrast})`,
|
|
104
|
+
color: `var(--color-button-cta, ${themeConfig.colors.cta})`
|
|
105
|
+
}).toString();
|
|
106
|
+
|
|
107
|
+
/**
|
|
27
108
|
* Styling that is applied to the button when it is disabled.
|
|
28
|
-
*/
|
|
109
|
+
*/
|
|
110
|
+
const buttonDisabled = css({
|
|
111
|
+
background: themeConfig.colors.shade5,
|
|
112
|
+
color: `var(--color-button-cta-contrast, ${themeConfig.colors.ctaContrast})`,
|
|
113
|
+
boxShadow: themeConfig.shadows.buttons.disabled
|
|
114
|
+
}).toString();
|
|
115
|
+
|
|
116
|
+
/**
|
|
29
117
|
* Basic icon style that is always applied to all icons.
|
|
30
|
-
*/
|
|
118
|
+
*/
|
|
119
|
+
const icon = css({
|
|
120
|
+
transition: 'opacity 450ms cubic-bezier(0.4, 0.0, 0.2, 1)',
|
|
121
|
+
opacity: 1,
|
|
122
|
+
position: 'absolute'
|
|
123
|
+
}).toString();
|
|
124
|
+
|
|
125
|
+
/**
|
|
31
126
|
* Icon style that is applied only to the spinner icon.
|
|
32
|
-
*/
|
|
127
|
+
*/
|
|
128
|
+
const spinnerIcon = css({
|
|
129
|
+
left: '50%',
|
|
130
|
+
top: '50%',
|
|
131
|
+
marginTop: -themeConfig.variables.loadingIndicator.size / 2,
|
|
132
|
+
marginLeft: -themeConfig.variables.loadingIndicator.size / 2
|
|
133
|
+
}).toString();
|
|
134
|
+
export default {
|
|
135
|
+
buttonWrapper,
|
|
136
|
+
buttonWrapperNoShadow,
|
|
137
|
+
buttonReady,
|
|
138
|
+
buttonSuccess,
|
|
139
|
+
buttonDisabled,
|
|
140
|
+
buttonSize,
|
|
141
|
+
icon,
|
|
142
|
+
iconSize,
|
|
143
|
+
spinnerIcon,
|
|
144
|
+
springFromBottom,
|
|
145
|
+
springFromTop,
|
|
146
|
+
springToBottom,
|
|
147
|
+
springToTop
|
|
148
|
+
};
|
package/Availability/index.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import React from'react';
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { AVAILABILITY_STATE_OK, AVAILABILITY_STATE_WARNING, AVAILABILITY_STATE_ALERT } from '@shopgate/pwa-common-commerce/product/constants';
|
|
4
|
+
import styles from "./style";
|
|
5
|
+
|
|
6
|
+
/**
|
|
2
7
|
* This component renders the availability text for a product
|
|
3
8
|
* @param {Object} props The component props
|
|
4
9
|
* @param {string} props.text The availability text
|
|
@@ -7,4 +12,31 @@ import React from'react';import PropTypes from'prop-types';import{AVAILABILITY_S
|
|
|
7
12
|
* state of the availability text is "ok"
|
|
8
13
|
* @param {string} [props.className] CSS classes
|
|
9
14
|
* @return {JSX}
|
|
10
|
-
*/
|
|
15
|
+
*/
|
|
16
|
+
const Availability = ({
|
|
17
|
+
text,
|
|
18
|
+
state,
|
|
19
|
+
showWhenAvailable = false,
|
|
20
|
+
className = null
|
|
21
|
+
}) => {
|
|
22
|
+
if (!text || state === AVAILABILITY_STATE_OK && !showWhenAvailable) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
let style = styles.stateOk;
|
|
26
|
+
if (state === AVAILABILITY_STATE_WARNING) {
|
|
27
|
+
style = styles.stateWarning;
|
|
28
|
+
}
|
|
29
|
+
if (state === AVAILABILITY_STATE_ALERT) {
|
|
30
|
+
style = styles.stateAlert;
|
|
31
|
+
}
|
|
32
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
33
|
+
className: `ui-shared__availability ${className} ${style}`,
|
|
34
|
+
"data-test-id": `availabilityText: ${text}`
|
|
35
|
+
}, text);
|
|
36
|
+
};
|
|
37
|
+
Availability.defaultProps = {
|
|
38
|
+
className: '',
|
|
39
|
+
showWhenAvailable: false,
|
|
40
|
+
state: AVAILABILITY_STATE_OK
|
|
41
|
+
};
|
|
42
|
+
export default Availability;
|
package/Availability/spec.js
CHANGED
|
@@ -1 +1,41 @@
|
|
|
1
|
-
import React from'react';
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { mount } from 'enzyme';
|
|
3
|
+
import { AVAILABILITY_STATE_OK, AVAILABILITY_STATE_WARNING, AVAILABILITY_STATE_ALERT } from '@shopgate/pwa-common-commerce/product/constants';
|
|
4
|
+
import Availability from "./index";
|
|
5
|
+
describe('<Availability />', () => {
|
|
6
|
+
it('should not render when text is empty', () => {
|
|
7
|
+
const wrapper = mount(/*#__PURE__*/React.createElement(Availability, {
|
|
8
|
+
text: ""
|
|
9
|
+
}));
|
|
10
|
+
expect(wrapper).toMatchSnapshot();
|
|
11
|
+
});
|
|
12
|
+
it('should not render by default if state is "ok"', () => {
|
|
13
|
+
const wrapper = mount(/*#__PURE__*/React.createElement(Availability, {
|
|
14
|
+
state: AVAILABILITY_STATE_OK,
|
|
15
|
+
text: "Available"
|
|
16
|
+
}));
|
|
17
|
+
expect(wrapper).toMatchSnapshot();
|
|
18
|
+
});
|
|
19
|
+
it('should render if state is "ok" when "showWhenAvailable" is set', () => {
|
|
20
|
+
const wrapper = mount(/*#__PURE__*/React.createElement(Availability, {
|
|
21
|
+
state: AVAILABILITY_STATE_OK,
|
|
22
|
+
text: "Available",
|
|
23
|
+
showWhenAvailable: true
|
|
24
|
+
}));
|
|
25
|
+
expect(wrapper).toMatchSnapshot();
|
|
26
|
+
});
|
|
27
|
+
it('should render if state is "warning"', () => {
|
|
28
|
+
const wrapper = mount(/*#__PURE__*/React.createElement(Availability, {
|
|
29
|
+
state: AVAILABILITY_STATE_WARNING,
|
|
30
|
+
text: "Only 5 left"
|
|
31
|
+
}));
|
|
32
|
+
expect(wrapper).toMatchSnapshot();
|
|
33
|
+
});
|
|
34
|
+
it('should render if state is "warning"', () => {
|
|
35
|
+
const wrapper = mount(/*#__PURE__*/React.createElement(Availability, {
|
|
36
|
+
state: AVAILABILITY_STATE_ALERT,
|
|
37
|
+
text: "Out of stock"
|
|
38
|
+
}));
|
|
39
|
+
expect(wrapper).toMatchSnapshot();
|
|
40
|
+
});
|
|
41
|
+
});
|
package/Availability/style.js
CHANGED
|
@@ -1 +1,19 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { css } from 'glamor';
|
|
2
|
+
import { themeConfig } from '@shopgate/pwa-common/helpers/config';
|
|
3
|
+
const stateOk = css({
|
|
4
|
+
fontSize: '0.875rem',
|
|
5
|
+
color: `var(--color-state-ok, ${themeConfig.colors.success})`
|
|
6
|
+
}).toString();
|
|
7
|
+
const stateWarning = css({
|
|
8
|
+
fontSize: '0.875rem',
|
|
9
|
+
color: `var(--color-state-warning, ${themeConfig.colors.warning})`
|
|
10
|
+
}).toString();
|
|
11
|
+
const stateAlert = css({
|
|
12
|
+
fontSize: '0.875rem',
|
|
13
|
+
color: `var(--color-state-alert, ${themeConfig.colors.error})`
|
|
14
|
+
}).toString();
|
|
15
|
+
export default {
|
|
16
|
+
stateOk,
|
|
17
|
+
stateWarning,
|
|
18
|
+
stateAlert
|
|
19
|
+
};
|
package/Button/index.js
CHANGED
|
@@ -1,14 +1,85 @@
|
|
|
1
|
-
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import React, { Component } from 'react';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import BaseButton from '@shopgate/pwa-common/components/Button';
|
|
5
|
+
import styles from "./style";
|
|
6
|
+
/**
|
|
2
7
|
* The basic button component. This components applies Material Design styles and acts as
|
|
3
8
|
* base to more feature-rich button components such as ActionButton and RippleButton, but can
|
|
4
9
|
* also be used as standalone component or any other kind of new button.
|
|
5
|
-
*/
|
|
10
|
+
*/
|
|
11
|
+
class Button extends Component {
|
|
12
|
+
/**
|
|
6
13
|
* Getter for style depending on prop type.
|
|
7
14
|
* @returns {Object}
|
|
8
|
-
*/
|
|
15
|
+
*/
|
|
16
|
+
get style() {
|
|
17
|
+
const {
|
|
18
|
+
flat,
|
|
19
|
+
disabled
|
|
20
|
+
} = this.props;
|
|
21
|
+
switch (this.props.type) {
|
|
22
|
+
case 'plain':
|
|
23
|
+
return styles.plain();
|
|
24
|
+
case 'regular':
|
|
25
|
+
return styles.regular(disabled);
|
|
26
|
+
case 'simple':
|
|
27
|
+
return styles.simple(disabled);
|
|
28
|
+
default:
|
|
29
|
+
case 'primary':
|
|
30
|
+
return styles.primary(disabled, flat);
|
|
31
|
+
case 'secondary':
|
|
32
|
+
return styles.secondary(disabled, flat);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
9
37
|
* Getter for the calculated button props.
|
|
10
38
|
* @returns {Object}
|
|
11
|
-
*/
|
|
39
|
+
*/
|
|
40
|
+
get buttonProps() {
|
|
41
|
+
const {
|
|
42
|
+
className,
|
|
43
|
+
disabled,
|
|
44
|
+
onClick,
|
|
45
|
+
testId,
|
|
46
|
+
type,
|
|
47
|
+
wrapContent,
|
|
48
|
+
flat,
|
|
49
|
+
...rest
|
|
50
|
+
} = this.props;
|
|
51
|
+
const buttonProps = {
|
|
52
|
+
className,
|
|
53
|
+
disabled,
|
|
54
|
+
onClick,
|
|
55
|
+
...rest
|
|
56
|
+
};
|
|
57
|
+
return buttonProps;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
12
61
|
* Renders the component.
|
|
13
62
|
* @return {JSX}
|
|
14
|
-
*/
|
|
63
|
+
*/
|
|
64
|
+
render() {
|
|
65
|
+
const {
|
|
66
|
+
style
|
|
67
|
+
} = this;
|
|
68
|
+
const content = this.props.wrapContent ? /*#__PURE__*/React.createElement("div", {
|
|
69
|
+
className: style.content
|
|
70
|
+
}, this.props.children) : this.props.children;
|
|
71
|
+
return /*#__PURE__*/React.createElement(BaseButton, _extends({}, this.buttonProps, {
|
|
72
|
+
className: `ui-shared__button ${style.button} ${this.props.className}`,
|
|
73
|
+
testId: this.props.testId
|
|
74
|
+
}), content);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
Button.defaultProps = {
|
|
78
|
+
...BaseButton.defaultProps,
|
|
79
|
+
className: '',
|
|
80
|
+
flat: false,
|
|
81
|
+
type: 'primary',
|
|
82
|
+
wrapContent: true,
|
|
83
|
+
testId: 'Button'
|
|
84
|
+
};
|
|
85
|
+
export default Button;
|
package/Button/spec.js
CHANGED
|
@@ -1 +1,33 @@
|
|
|
1
|
-
import trim from'lodash/trim';
|
|
1
|
+
import trim from 'lodash/trim';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { shallow } from 'enzyme';
|
|
4
|
+
import Button from "./index";
|
|
5
|
+
import styles from "./style";
|
|
6
|
+
describe('<Button />', () => {
|
|
7
|
+
it('should render as a regular button if type is omitted', () => {
|
|
8
|
+
const wrapper = shallow(/*#__PURE__*/React.createElement(Button, null, "Press me"));
|
|
9
|
+
expect(wrapper).toMatchSnapshot();
|
|
10
|
+
expect(wrapper.render().text()).toEqual('Press me');
|
|
11
|
+
});
|
|
12
|
+
it('should render as a regular button if type is explicitly defined', () => {
|
|
13
|
+
const wrapper = shallow(/*#__PURE__*/React.createElement(Button, {
|
|
14
|
+
type: "regular"
|
|
15
|
+
}, "Press me"));
|
|
16
|
+
expect(wrapper).toMatchSnapshot();
|
|
17
|
+
expect(trim(wrapper.prop('className'))).toEqual(`ui-shared__button ${styles.regular(false).button}`);
|
|
18
|
+
});
|
|
19
|
+
it('should render as a primary button', () => {
|
|
20
|
+
const wrapper = shallow(/*#__PURE__*/React.createElement(Button, {
|
|
21
|
+
type: "primary"
|
|
22
|
+
}, "Press me"));
|
|
23
|
+
expect(trim(wrapper.prop('className'))).toEqual(`ui-shared__button ${styles.primary(false, false).button}`);
|
|
24
|
+
expect(wrapper).toMatchSnapshot();
|
|
25
|
+
});
|
|
26
|
+
it('should render as a secondary button', () => {
|
|
27
|
+
const wrapper = shallow(/*#__PURE__*/React.createElement(Button, {
|
|
28
|
+
type: "secondary"
|
|
29
|
+
}, "Press me"));
|
|
30
|
+
expect(trim(wrapper.prop('className'))).toEqual(`ui-shared__button ${styles.secondary(false, false).button}`);
|
|
31
|
+
expect(wrapper).toMatchSnapshot();
|
|
32
|
+
});
|
|
33
|
+
});
|
package/Button/style.js
CHANGED
|
@@ -1,46 +1,155 @@
|
|
|
1
|
-
|
|
1
|
+
import { css } from 'glamor';
|
|
2
|
+
import { themeConfig } from '@shopgate/pwa-common/helpers/config';
|
|
3
|
+
const {
|
|
4
|
+
colors
|
|
5
|
+
} = themeConfig;
|
|
6
|
+
const buttonPadding = `0 ${themeConfig.variables.gap.big}px 0`;
|
|
7
|
+
|
|
8
|
+
/**
|
|
2
9
|
* Creates the button style.
|
|
3
10
|
* @param {string} text The text color.
|
|
4
11
|
* @param {string|null} background The fill color.
|
|
5
12
|
* @return {Object} The button style.
|
|
6
|
-
*/
|
|
13
|
+
*/
|
|
14
|
+
const button = (text, background) => ({
|
|
15
|
+
position: 'relative',
|
|
16
|
+
display: 'inline-block',
|
|
17
|
+
outline: 0,
|
|
18
|
+
color: text,
|
|
19
|
+
backgroundColor: background,
|
|
20
|
+
minWidth: 64,
|
|
21
|
+
overflow: 'hidden',
|
|
22
|
+
':disabled': {
|
|
23
|
+
cursor: 'not-allowed'
|
|
24
|
+
},
|
|
25
|
+
...themeConfig.variables.buttonBase
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
/**
|
|
7
29
|
* The basic content wrapper styles.
|
|
8
|
-
*/
|
|
30
|
+
*/
|
|
31
|
+
const contentWrapper = css({
|
|
32
|
+
padding: buttonPadding
|
|
33
|
+
}).toString();
|
|
34
|
+
|
|
35
|
+
/**
|
|
9
36
|
* Creates the button styles object.
|
|
10
37
|
* @param {string} textColor The text color.
|
|
11
38
|
* @param {string|null} fillColor The fill color.
|
|
12
39
|
* @return {Object} The styles object.
|
|
13
|
-
*/
|
|
40
|
+
*/
|
|
41
|
+
const createButtonStyles = (textColor, fillColor) => {
|
|
42
|
+
const buttonStyle = {
|
|
43
|
+
...button(textColor, fillColor)
|
|
44
|
+
};
|
|
45
|
+
const contentStyle = {
|
|
46
|
+
padding: buttonPadding,
|
|
47
|
+
color: buttonStyle.color
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
button: css(buttonStyle).toString(),
|
|
51
|
+
content: css(contentStyle).toString()
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
14
56
|
* Creates a plain button style object without any styling.
|
|
15
57
|
* @return {Object}
|
|
16
|
-
*/
|
|
58
|
+
*/
|
|
59
|
+
const plain = () => ({
|
|
60
|
+
button: css({
|
|
61
|
+
padding: 0,
|
|
62
|
+
outline: 0,
|
|
63
|
+
border: 0,
|
|
64
|
+
textAlign: 'left'
|
|
65
|
+
}).toString(),
|
|
66
|
+
content: ''
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
/**
|
|
17
70
|
* Creates a simple button style object.
|
|
18
71
|
* @param {boolean} disabled Whether this button is disabled.
|
|
19
72
|
* @return {Object}
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
|
|
73
|
+
*/
|
|
74
|
+
const simple = disabled => {
|
|
75
|
+
if (disabled) {
|
|
76
|
+
// simple disabled button style.
|
|
77
|
+
return createButtonStyles(themeConfig.colors.shade4, themeConfig.colors.shade7);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// simple enabled button style.
|
|
81
|
+
return createButtonStyles(themeConfig.colors.dark, themeConfig.colors.shade7);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/**
|
|
23
85
|
* The regular flat button style.
|
|
24
86
|
* @param {boolean} disabled Whether this button is disabled.
|
|
25
87
|
* @return {Object} An object of style definitions.
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
|
|
88
|
+
*/
|
|
89
|
+
const regular = disabled => {
|
|
90
|
+
if (disabled) {
|
|
91
|
+
// Flat disabled button style.
|
|
92
|
+
return createButtonStyles(colors.shade4, null);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Flat enabled button style.
|
|
96
|
+
return createButtonStyles(colors.dark, null);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/**
|
|
29
100
|
* The primary button style.
|
|
30
101
|
* @param {boolean} disabled Whether this button is disabled.
|
|
31
102
|
* @param {boolean} flat Whether this button should be rendered flat.
|
|
32
103
|
* @return {Object} An object of style definitions.
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
104
|
+
*/
|
|
105
|
+
const primary = (disabled, flat) => {
|
|
106
|
+
if (!flat) {
|
|
107
|
+
if (disabled) {
|
|
108
|
+
// Regular disabled button style.
|
|
109
|
+
return createButtonStyles(colors.shade4, colors.shade7);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Regular enabled button style.
|
|
113
|
+
return createButtonStyles(`var(--color-secondary-contrast, ${colors.accentContrast})`, `var(--color-secondary, ${colors.accent})`);
|
|
114
|
+
}
|
|
115
|
+
if (disabled) {
|
|
116
|
+
// Flat disabled button style.
|
|
117
|
+
return createButtonStyles(colors.shade4, null);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Flat enabled button style.
|
|
121
|
+
return createButtonStyles(`var(--color-secondary, ${colors.accent})`, null);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/**
|
|
38
125
|
* The secondary button style.
|
|
39
126
|
* @param {boolean} disabled Whether this button is disabled.
|
|
40
127
|
* @param {boolean} flat Whether this button should be rendered flat.
|
|
41
128
|
* @return {Object} An object of style definitions.
|
|
42
|
-
*/
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
129
|
+
*/
|
|
130
|
+
const secondary = (disabled, flat) => {
|
|
131
|
+
if (!flat) {
|
|
132
|
+
if (disabled) {
|
|
133
|
+
// Regular disabled button style.
|
|
134
|
+
return createButtonStyles(colors.shade4, colors.shade7);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Regular enabled button style.
|
|
138
|
+
return createButtonStyles(`var(--color-primary-contrast, ${colors.primaryContrast})`, `var(--color-primary, ${colors.primary})`);
|
|
139
|
+
}
|
|
140
|
+
if (disabled) {
|
|
141
|
+
// Flat disabled button style.
|
|
142
|
+
return createButtonStyles(colors.shade4, null);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Flat enabled button style.
|
|
146
|
+
return createButtonStyles(`var(--color-primary, ${colors.primary})`, null);
|
|
147
|
+
};
|
|
148
|
+
export default {
|
|
149
|
+
plain,
|
|
150
|
+
regular,
|
|
151
|
+
simple,
|
|
152
|
+
primary,
|
|
153
|
+
secondary,
|
|
154
|
+
contentWrapper
|
|
155
|
+
};
|
package/ButtonLink/connector.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import{connect}from'react-redux';
|
|
1
|
+
import { connect } from 'react-redux';
|
|
2
|
+
import { historyPush } from '@shopgate/pwa-common/actions/router';
|
|
3
|
+
|
|
4
|
+
/**
|
|
2
5
|
* @param {Function} dispatch The redux dispatch function.
|
|
3
6
|
* @return {Object}
|
|
4
|
-
*/
|
|
7
|
+
*/
|
|
8
|
+
const mapDispatchToProps = dispatch => ({
|
|
9
|
+
navigate: pathname => dispatch(historyPush({
|
|
10
|
+
pathname
|
|
11
|
+
}))
|
|
12
|
+
});
|
|
13
|
+
export default connect(null, mapDispatchToProps);
|