@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/Sheet/index.js
CHANGED
|
@@ -1,26 +1,179 @@
|
|
|
1
|
-
|
|
1
|
+
import React, { Component } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import throttle from 'lodash/throttle';
|
|
4
|
+
import classNames from 'classnames';
|
|
5
|
+
import UIEvents from '@shopgate/pwa-core/emitters/ui';
|
|
6
|
+
import Backdrop from '@shopgate/pwa-common/components/Backdrop';
|
|
7
|
+
import Drawer from '@shopgate/pwa-common/components/Drawer';
|
|
8
|
+
import ProgressBar from "../ProgressBar";
|
|
9
|
+
import Header from "./components/Header";
|
|
10
|
+
import styles from "./style";
|
|
11
|
+
export const SHEET_EVENTS = {
|
|
12
|
+
OPEN: 'Sheet.open',
|
|
13
|
+
CLOSE: 'Sheet.close'
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
2
17
|
* Sheet component.
|
|
3
|
-
*/
|
|
18
|
+
*/
|
|
19
|
+
class Sheet extends Component {
|
|
20
|
+
/**
|
|
4
21
|
* The constructor.
|
|
5
22
|
* @param {Object} props The component props.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
23
|
+
*/
|
|
24
|
+
constructor(props) {
|
|
25
|
+
super(props);
|
|
26
|
+
/**
|
|
27
|
+
* Close the Sheet.
|
|
28
|
+
*/
|
|
29
|
+
this.handleScroll = throttle(() => {
|
|
30
|
+
const scrolled = this.content.current.scrollTop !== 0;
|
|
31
|
+
if (this.state.scrolled !== scrolled) {
|
|
32
|
+
this.setState({
|
|
33
|
+
scrolled
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}, 10);
|
|
37
|
+
/**
|
|
38
|
+
* Close the Sheet.
|
|
39
|
+
*/
|
|
40
|
+
this.handleClose = () => {
|
|
41
|
+
this.props.onClose();
|
|
42
|
+
this.setState({
|
|
43
|
+
isOpen: false,
|
|
44
|
+
scrolled: false
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
/** The Sheet is opened */
|
|
48
|
+
this.handleDidOpen = () => {
|
|
49
|
+
UIEvents.emit(SHEET_EVENTS.OPEN);
|
|
50
|
+
this.props.onDidOpen();
|
|
51
|
+
};
|
|
52
|
+
/** The Sheet is closed */
|
|
53
|
+
this.handleDidClose = () => {
|
|
54
|
+
UIEvents.emit(SHEET_EVENTS.CLOSE);
|
|
55
|
+
this.props.onDidClose();
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* New value from SearchBar
|
|
59
|
+
* @param {string} value .
|
|
60
|
+
*/
|
|
61
|
+
this.handleSearchInput = value => {
|
|
62
|
+
this.setState({
|
|
63
|
+
query: value
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
this.content = /*#__PURE__*/React.createRef();
|
|
67
|
+
this.state = {
|
|
68
|
+
isOpen: props.isOpen,
|
|
69
|
+
scrolled: false,
|
|
70
|
+
query: ''
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
14
75
|
* Change isOpen state for new incoming props.
|
|
15
76
|
* @param {Object} nextProps The next component props.
|
|
16
|
-
*/
|
|
77
|
+
*/
|
|
78
|
+
UNSAFE_componentWillReceiveProps({
|
|
79
|
+
isOpen
|
|
80
|
+
}) {
|
|
81
|
+
if (this.state.isOpen !== isOpen) {
|
|
82
|
+
this.setState({
|
|
83
|
+
isOpen
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
17
88
|
* Getter for the animation props of the Sheet.
|
|
18
89
|
* @returns {Object}
|
|
19
|
-
*/
|
|
90
|
+
*/
|
|
91
|
+
get animationProps() {
|
|
92
|
+
return {
|
|
93
|
+
duration: this.props.duration,
|
|
94
|
+
...styles.drawerAnimation,
|
|
95
|
+
...this.props.animation
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
20
99
|
* Renders the component.
|
|
21
100
|
* @returns {JSX}
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
101
|
+
*/
|
|
102
|
+
render() {
|
|
103
|
+
const {
|
|
104
|
+
allowClose
|
|
105
|
+
} = this.props;
|
|
106
|
+
const children = React.Children.map(this.props.children, child => (/*#__PURE__*/React.cloneElement(child,
|
|
107
|
+
// Only add onClose prop to other components
|
|
108
|
+
typeof child.type === 'function' && this.props.onClose !== null ? {
|
|
109
|
+
onClose: this.props.onClose,
|
|
110
|
+
query: this.state.query
|
|
111
|
+
} : {})));
|
|
112
|
+
const drawerClassNames = classNames(styles.container, {
|
|
113
|
+
[this.props.className]: this.props.className
|
|
114
|
+
});
|
|
115
|
+
const contentClassNames = classNames(styles.content, {
|
|
116
|
+
[styles.containerFullScreen]: this.props.showSearch
|
|
117
|
+
}, {
|
|
118
|
+
[this.props.contentClassName]: this.props.contentClassName
|
|
119
|
+
}, {
|
|
120
|
+
[styles.shadow]: !this.props.backdrop
|
|
121
|
+
});
|
|
122
|
+
return /*#__PURE__*/React.createElement("section", {
|
|
123
|
+
className: classNames('ui-shared__sheet', {
|
|
124
|
+
[styles.section]: this.state.isOpen
|
|
125
|
+
})
|
|
126
|
+
}, /*#__PURE__*/React.createElement(Drawer, {
|
|
127
|
+
className: drawerClassNames,
|
|
128
|
+
isOpen: this.state.isOpen,
|
|
129
|
+
onDidOpen: this.handleDidOpen,
|
|
130
|
+
onDidClose: this.handleDidClose,
|
|
131
|
+
onOpen: this.props.onOpen,
|
|
132
|
+
onClose: this.handleClose,
|
|
133
|
+
animation: this.animationProps
|
|
134
|
+
}, this.props.title && /*#__PURE__*/React.createElement(Sheet.Header, {
|
|
135
|
+
showSearch: this.props.showSearch,
|
|
136
|
+
handleChange: this.handleSearchInput,
|
|
137
|
+
onToggleClose: this.handleClose,
|
|
138
|
+
shadow: this.state.scrolled,
|
|
139
|
+
title: this.props.title,
|
|
140
|
+
allowClose: allowClose
|
|
141
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
142
|
+
className: styles.progressBarContainer
|
|
143
|
+
}, /*#__PURE__*/React.createElement(ProgressBar, {
|
|
144
|
+
isVisible: this.props.isLoading
|
|
145
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
146
|
+
ref: this.content,
|
|
147
|
+
onScroll: this.handleScroll,
|
|
148
|
+
className: contentClassNames
|
|
149
|
+
}, children)), this.props.backdrop && /*#__PURE__*/React.createElement(Backdrop, {
|
|
150
|
+
isVisible: this.state.isOpen,
|
|
151
|
+
level: 4,
|
|
152
|
+
onClick: allowClose ? this.handleClose : () => {},
|
|
153
|
+
opacity: 20
|
|
154
|
+
}));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
Sheet.Header = Header;
|
|
158
|
+
/**
|
|
159
|
+
* The component default props.
|
|
160
|
+
* @type {Object}
|
|
161
|
+
*/
|
|
162
|
+
Sheet.defaultProps = {
|
|
163
|
+
animation: {},
|
|
164
|
+
backdrop: true,
|
|
165
|
+
children: null,
|
|
166
|
+
className: null,
|
|
167
|
+
contentClassName: null,
|
|
168
|
+
duration: 300,
|
|
169
|
+
isOpen: false,
|
|
170
|
+
isLoading: false,
|
|
171
|
+
onClose: () => {},
|
|
172
|
+
onDidClose: () => {},
|
|
173
|
+
onDidOpen: () => {},
|
|
174
|
+
onOpen: () => {},
|
|
175
|
+
title: '',
|
|
176
|
+
showSearch: false,
|
|
177
|
+
allowClose: true
|
|
178
|
+
};
|
|
179
|
+
export default Sheet;
|
package/Sheet/spec.js
CHANGED
|
@@ -1,5 +1,85 @@
|
|
|
1
|
-
import React from'react';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { shallow, mount } from 'enzyme';
|
|
3
|
+
import mockRenderOptions from '@shopgate/pwa-common/helpers/mocks/mockRenderOptions';
|
|
4
|
+
import UIEvents from '@shopgate/pwa-core/emitters/ui';
|
|
5
|
+
import Sheet, { SHEET_EVENTS } from "./index";
|
|
6
|
+
window.requestAnimationFrame = () => {};
|
|
7
|
+
jest.mock('@shopgate/pwa-core/emitters/ui', () => ({
|
|
8
|
+
emit: jest.fn()
|
|
9
|
+
}));
|
|
10
|
+
jest.mock('@shopgate/engage/a11y/components');
|
|
11
|
+
describe('<Sheet />', () => {
|
|
12
|
+
it('should render closed without content', () => {
|
|
13
|
+
const wrapper = shallow(/*#__PURE__*/React.createElement(Sheet, null));
|
|
14
|
+
expect(wrapper).toMatchSnapshot();
|
|
15
|
+
});
|
|
16
|
+
it('should render opened without content', () => {
|
|
17
|
+
const wrapper = shallow(/*#__PURE__*/React.createElement(Sheet, {
|
|
18
|
+
isOpen: true
|
|
19
|
+
}));
|
|
20
|
+
expect(wrapper).toMatchSnapshot();
|
|
21
|
+
});
|
|
22
|
+
it('should render with content and title', () => {
|
|
23
|
+
const wrapper = shallow(/*#__PURE__*/React.createElement(Sheet, {
|
|
24
|
+
isOpen: true,
|
|
25
|
+
title: "Test-Title"
|
|
26
|
+
}, /*#__PURE__*/React.createElement("div", null, "Test")));
|
|
27
|
+
expect(wrapper).toMatchSnapshot();
|
|
28
|
+
});
|
|
29
|
+
it('should call onDidOpen callback when the Sheet was opened', () => {
|
|
30
|
+
const onOpen = jest.fn();
|
|
31
|
+
const onDidOpen = jest.fn();
|
|
32
|
+
const wrapper = mount(/*#__PURE__*/React.createElement(Sheet, {
|
|
33
|
+
isOpen: false,
|
|
34
|
+
onOpen: onOpen,
|
|
35
|
+
onDidOpen: onDidOpen
|
|
36
|
+
}, /*#__PURE__*/React.createElement("div", null, "Test")), mockRenderOptions);
|
|
37
|
+
expect(onOpen).not.toHaveBeenCalled();
|
|
38
|
+
expect(onDidOpen).not.toHaveBeenCalled();
|
|
39
|
+
wrapper.setProps({
|
|
40
|
+
isOpen: true
|
|
41
|
+
});
|
|
42
|
+
expect(onOpen).toHaveBeenCalled();
|
|
43
|
+
wrapper.find('Drawer').simulate('animationEnd');
|
|
44
|
+
expect(onDidOpen).toHaveBeenCalled();
|
|
45
|
+
expect(UIEvents.emit).nthCalledWith(1, SHEET_EVENTS.OPEN);
|
|
46
|
+
});
|
|
47
|
+
it('should trigger onClose callback and close the Sheet', () => {
|
|
48
|
+
const onCloseSpy = jest.fn();
|
|
49
|
+
const wrapper = mount(/*#__PURE__*/React.createElement(Sheet, {
|
|
50
|
+
isOpen: true,
|
|
51
|
+
title: "Test-Title",
|
|
52
|
+
onClose: onCloseSpy
|
|
53
|
+
}, /*#__PURE__*/React.createElement("div", null, "Test")), mockRenderOptions);
|
|
54
|
+
|
|
55
|
+
// Trigger a click on the close button of the Sheet.
|
|
56
|
+
wrapper.find('button').first().simulate('click');
|
|
57
|
+
return new Promise(resolve => {
|
|
58
|
+
// Wait until the drawer is closed and has updated it's state.
|
|
59
|
+
setTimeout(() => {
|
|
60
|
+
resolve();
|
|
61
|
+
}, wrapper.find('Drawer').prop('animation').duration);
|
|
62
|
+
}).then(() => {
|
|
63
|
+
// Check if onClose callback was called.
|
|
64
|
+
expect(onCloseSpy).toHaveBeenCalled();
|
|
65
|
+
|
|
66
|
+
// Check if the Drawer component was closed.
|
|
67
|
+
expect(wrapper.find('Drawer').prop('isOpen')).not.toBeTruthy();
|
|
68
|
+
expect(wrapper).toMatchSnapshot();
|
|
69
|
+
wrapper.find('Drawer').simulate('animationEnd');
|
|
70
|
+
expect(UIEvents.emit).nthCalledWith(2, SHEET_EVENTS.CLOSE);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
it('should open', () => {
|
|
74
|
+
const wrapper = mount(/*#__PURE__*/React.createElement(Sheet, {
|
|
75
|
+
isOpen: false,
|
|
76
|
+
title: "Test-Title"
|
|
77
|
+
}, /*#__PURE__*/React.createElement("div", null, "Test")), mockRenderOptions);
|
|
78
|
+
wrapper.setProps({
|
|
79
|
+
isOpen: true
|
|
80
|
+
});
|
|
81
|
+
wrapper.update();
|
|
82
|
+
expect(wrapper.find('Drawer').prop('isOpen')).toBeTruthy();
|
|
83
|
+
expect(wrapper).toMatchSnapshot();
|
|
84
|
+
});
|
|
85
|
+
});
|
package/Sheet/style.js
CHANGED
|
@@ -1,2 +1,143 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { css } from 'glamor';
|
|
2
|
+
import { themeConfig } from '@shopgate/pwa-common/helpers/config';
|
|
3
|
+
import { responsiveMediaQuery } from '@shopgate/engage/styles';
|
|
4
|
+
const duration = 300;
|
|
5
|
+
const easing = 'cubic-bezier(0.25, 0.1, 0.25, 1)';
|
|
6
|
+
const section = css({
|
|
7
|
+
[responsiveMediaQuery('>sm', {
|
|
8
|
+
webOnly: true
|
|
9
|
+
})]: {
|
|
10
|
+
display: 'flex',
|
|
11
|
+
justifyContent: 'center',
|
|
12
|
+
alignItems: 'center',
|
|
13
|
+
width: '80%',
|
|
14
|
+
position: 'fixed',
|
|
15
|
+
left: 0,
|
|
16
|
+
right: 0,
|
|
17
|
+
top: 0,
|
|
18
|
+
bottom: 0,
|
|
19
|
+
margin: 'auto',
|
|
20
|
+
zIndex: 100
|
|
21
|
+
}
|
|
22
|
+
}).toString();
|
|
23
|
+
const container = css({
|
|
24
|
+
bottom: 0,
|
|
25
|
+
background: themeConfig.colors.light,
|
|
26
|
+
width: '100vw',
|
|
27
|
+
[responsiveMediaQuery('<xl', {
|
|
28
|
+
appOnly: true
|
|
29
|
+
})]: {
|
|
30
|
+
// Max width was introduced in PWA6 CCP-2496
|
|
31
|
+
maxWidth: 640
|
|
32
|
+
},
|
|
33
|
+
left: 0,
|
|
34
|
+
right: 0,
|
|
35
|
+
margin: '0 auto',
|
|
36
|
+
color: `var(--color-text-high-emphasis, ${themeConfig.colors.dark})`,
|
|
37
|
+
[responsiveMediaQuery('>sm', {
|
|
38
|
+
webOnly: true
|
|
39
|
+
})]: {
|
|
40
|
+
position: 'initial'
|
|
41
|
+
},
|
|
42
|
+
[responsiveMediaQuery('>md', {
|
|
43
|
+
webOnly: true
|
|
44
|
+
})]: {
|
|
45
|
+
width: '60%'
|
|
46
|
+
}
|
|
47
|
+
}).toString();
|
|
48
|
+
const containerFullScreen = css({
|
|
49
|
+
height: [`calc(100vh - ${themeConfig.variables.navigator.height}px - 51px)`, `calc(100vh - ${themeConfig.variables.navigator.height}px - 51px - var(--safe-area-inset-top))`]
|
|
50
|
+
});
|
|
51
|
+
const searchBarWrapper = css({
|
|
52
|
+
backgroundColor: 'white',
|
|
53
|
+
height: 52,
|
|
54
|
+
position: 'sticky',
|
|
55
|
+
width: '100%',
|
|
56
|
+
top: 0,
|
|
57
|
+
zIndex: 2
|
|
58
|
+
});
|
|
59
|
+
const progressBarContainer = css({
|
|
60
|
+
position: 'relative'
|
|
61
|
+
}).toString();
|
|
62
|
+
const shadow = css({
|
|
63
|
+
boxShadow: themeConfig.shadows.sheet
|
|
64
|
+
}).toString();
|
|
65
|
+
const content = css({
|
|
66
|
+
maxHeight: [`calc(var(--vh-100, 100vh) - ${themeConfig.variables.navigator.height}px)`, `calc(var(--vh-100, 100vh) - ${themeConfig.variables.navigator.height}px - var(--safe-area-inset-top))`],
|
|
67
|
+
[responsiveMediaQuery('>sm', {
|
|
68
|
+
webOnly: true
|
|
69
|
+
})]: {
|
|
70
|
+
maxHeight: [`calc(var(--vh-80, 80vh) - ${themeConfig.variables.navigator.height}px)`, `calc(var(--vh-80, 80vh) - ${themeConfig.variables.navigator.height}px - var(--safe-area-inset-top))`]
|
|
71
|
+
},
|
|
72
|
+
paddingBottom: ['var(--safe-area-inset-bottom)'],
|
|
73
|
+
overflowY: 'scroll',
|
|
74
|
+
WebkitOverflowScrolling: 'touch'
|
|
75
|
+
}).toString();
|
|
76
|
+
const slideInSheetDrawer = css.keyframes({
|
|
77
|
+
'0%': {
|
|
78
|
+
transform: 'translateY(100%)'
|
|
79
|
+
},
|
|
80
|
+
'100%': {
|
|
81
|
+
transform: 'translateY(0)'
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
const fadeInSheetDrawer = css.keyframes({
|
|
85
|
+
'0%': {
|
|
86
|
+
opacity: 0
|
|
87
|
+
},
|
|
88
|
+
'100%': {
|
|
89
|
+
opacity: 1
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
const slideOutSheetDrawer = css.keyframes({
|
|
93
|
+
'0%': {
|
|
94
|
+
transform: 'translateY(0)'
|
|
95
|
+
},
|
|
96
|
+
'100%': {
|
|
97
|
+
transform: 'translateY(100%)'
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
const fadeOutSheetDrawer = css.keyframes({
|
|
101
|
+
'0%': {
|
|
102
|
+
opacity: 1
|
|
103
|
+
},
|
|
104
|
+
'100%': {
|
|
105
|
+
opacity: 0
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
const drawerAnimation = {
|
|
109
|
+
in: css({
|
|
110
|
+
[responsiveMediaQuery('<=sm', {
|
|
111
|
+
appAlways: true
|
|
112
|
+
})]: {
|
|
113
|
+
animation: `${slideInSheetDrawer} ${duration}ms 1 both ${easing}`
|
|
114
|
+
},
|
|
115
|
+
[responsiveMediaQuery('>sm', {
|
|
116
|
+
webOnly: true
|
|
117
|
+
})]: {
|
|
118
|
+
animation: `${fadeInSheetDrawer} ${duration}ms 1 both ${easing}`
|
|
119
|
+
}
|
|
120
|
+
}).toString(),
|
|
121
|
+
out: css({
|
|
122
|
+
[responsiveMediaQuery('<=sm', {
|
|
123
|
+
appAlways: true
|
|
124
|
+
})]: {
|
|
125
|
+
animation: `${slideOutSheetDrawer} ${duration}ms 1 both ${easing}`
|
|
126
|
+
},
|
|
127
|
+
[responsiveMediaQuery('>sm', {
|
|
128
|
+
webOnly: true
|
|
129
|
+
})]: {
|
|
130
|
+
animation: `${fadeOutSheetDrawer} ${duration}ms 1 both ${easing}`
|
|
131
|
+
}
|
|
132
|
+
}).toString()
|
|
133
|
+
};
|
|
134
|
+
export default {
|
|
135
|
+
section,
|
|
136
|
+
container,
|
|
137
|
+
containerFullScreen,
|
|
138
|
+
searchBarWrapper,
|
|
139
|
+
progressBarContainer,
|
|
140
|
+
shadow,
|
|
141
|
+
content,
|
|
142
|
+
drawerAnimation
|
|
143
|
+
};
|
package/TaxDisclaimer/index.js
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
|
-
import React from'react';
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import SurroundPortals from '@shopgate/pwa-common/components/SurroundPortals';
|
|
3
|
+
import { PRODUCT_TAX_DISCLAIMER } from '@shopgate/pwa-common-commerce/product/constants/Portals';
|
|
4
|
+
import I18n from '@shopgate/pwa-common/components/I18n';
|
|
5
|
+
import showTaxDisclaimer from '@shopgate/pwa-common-commerce/market/helpers/showTaxDisclaimer';
|
|
6
|
+
import { useWidgetSettings } from '@shopgate/engage/core/hooks/useWidgetSettings';
|
|
7
|
+
import styles from "./style";
|
|
8
|
+
|
|
9
|
+
/**
|
|
2
10
|
* TaxDisclaimer component.
|
|
3
11
|
* @returns {Function}
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
|
|
12
|
+
*/
|
|
13
|
+
const TaxDisclaimer = () => {
|
|
14
|
+
// Added with PWA 6 - CCP-2372
|
|
15
|
+
const {
|
|
16
|
+
show,
|
|
17
|
+
text
|
|
18
|
+
} = useWidgetSettings('@shopgate/engage/components/TaxDisclaimer');
|
|
19
|
+
|
|
20
|
+
// use widget setting if set to true/false, otherwise use market logic
|
|
21
|
+
const showDisclaimer = typeof show === 'boolean' ? show : showTaxDisclaimer;
|
|
22
|
+
return /*#__PURE__*/React.createElement(SurroundPortals, {
|
|
23
|
+
portalName: PRODUCT_TAX_DISCLAIMER,
|
|
24
|
+
portalProps: {
|
|
25
|
+
showTaxDisclaimer: showDisclaimer
|
|
26
|
+
}
|
|
27
|
+
}, showDisclaimer && /*#__PURE__*/React.createElement("div", {
|
|
28
|
+
"data-test-id": "taxDisclaimer",
|
|
29
|
+
"aria-hidden": true,
|
|
30
|
+
className: "ui-shared__tax-disclaimer"
|
|
31
|
+
}, /*#__PURE__*/React.createElement(I18n.Text, {
|
|
32
|
+
className: styles,
|
|
33
|
+
string: text || 'product.tax_disclaimer'
|
|
34
|
+
})));
|
|
35
|
+
};
|
|
36
|
+
export default TaxDisclaimer;
|
package/TaxDisclaimer/spec.js
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
-
import React from'react';
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { shallow } from 'enzyme';
|
|
3
|
+
import I18n from '@shopgate/pwa-common/components/I18n';
|
|
4
|
+
jest.mock('@shopgate/engage/core/hooks/useWidgetSettings', () => ({
|
|
5
|
+
useWidgetSettings: jest.fn().mockReturnValue({
|
|
6
|
+
show: null,
|
|
7
|
+
hint: '*',
|
|
8
|
+
text: null
|
|
9
|
+
})
|
|
10
|
+
}));
|
|
11
|
+
describe('<TaxDisclaimer />', () => {
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
jest.resetModules();
|
|
14
|
+
});
|
|
15
|
+
it('should display the component', () => {
|
|
16
|
+
jest.mock('@shopgate/pwa-common-commerce/market/helpers/showTaxDisclaimer', () => true);
|
|
17
|
+
// eslint-disable-next-line global-require
|
|
18
|
+
const TaxDisclaimer = require("./index").default;
|
|
19
|
+
const wrapper = shallow(/*#__PURE__*/React.createElement(TaxDisclaimer, null));
|
|
20
|
+
expect(wrapper).toMatchSnapshot();
|
|
21
|
+
expect(wrapper.find(I18n.Text).exists()).toBe(true);
|
|
22
|
+
});
|
|
23
|
+
it('should display null', () => {
|
|
24
|
+
jest.mock('@shopgate/pwa-common-commerce/market/helpers/showTaxDisclaimer', () => false);
|
|
25
|
+
// eslint-disable-next-line global-require
|
|
26
|
+
const TaxDisclaimer = require("./index").default;
|
|
27
|
+
const wrapper = shallow(/*#__PURE__*/React.createElement(TaxDisclaimer, null));
|
|
28
|
+
expect(wrapper).toMatchSnapshot();
|
|
29
|
+
expect(wrapper.find(I18n.Text).exists()).toBe(false);
|
|
30
|
+
});
|
|
31
|
+
});
|
package/TaxDisclaimer/style.js
CHANGED
|
@@ -1 +1,9 @@
|
|
|
1
|
-
import{css}from'glamor';
|
|
1
|
+
import { css } from 'glamor';
|
|
2
|
+
import { themeConfig } from '@shopgate/pwa-common/helpers/config';
|
|
3
|
+
export default css({
|
|
4
|
+
background: themeConfig.colors.background,
|
|
5
|
+
display: 'block',
|
|
6
|
+
fontSize: 12,
|
|
7
|
+
padding: `20px ${themeConfig.variables.gap.big}px`,
|
|
8
|
+
textAlign: 'left'
|
|
9
|
+
}).toString();
|
|
@@ -1,5 +1,36 @@
|
|
|
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
|
* Error message component.
|
|
3
9
|
* @param {Object} props The component props.
|
|
4
10
|
* @returns {JSX.Element}
|
|
5
|
-
*/
|
|
11
|
+
*/
|
|
12
|
+
const ErrorText = ({
|
|
13
|
+
elementName,
|
|
14
|
+
validationError,
|
|
15
|
+
errorText,
|
|
16
|
+
ariaHidden,
|
|
17
|
+
translate,
|
|
18
|
+
className
|
|
19
|
+
}) => /*#__PURE__*/React.createElement("div", {
|
|
20
|
+
id: `ariaError-${elementName}`,
|
|
21
|
+
className: classNames(className, styles.error, 'errorText'),
|
|
22
|
+
"aria-live": "assertive",
|
|
23
|
+
"aria-atomic": "true",
|
|
24
|
+
"aria-hidden": ariaHidden
|
|
25
|
+
}, translate && /*#__PURE__*/React.createElement(I18n.Text, {
|
|
26
|
+
string: validationError || errorText
|
|
27
|
+
}), !translate && (validationError || errorText));
|
|
28
|
+
ErrorText.defaultProps = {
|
|
29
|
+
className: '',
|
|
30
|
+
errorText: null,
|
|
31
|
+
elementName: null,
|
|
32
|
+
translate: true,
|
|
33
|
+
ariaHidden: false,
|
|
34
|
+
validationError: null
|
|
35
|
+
};
|
|
36
|
+
export default ErrorText;
|
|
@@ -1,5 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
import { css } from 'glamor';
|
|
2
|
+
import { themeConfig } from '@shopgate/pwa-common/helpers/config';
|
|
3
|
+
|
|
4
|
+
/**
|
|
2
5
|
* The style object for a one line text element with an ellipsis on overflow.
|
|
3
|
-
*/
|
|
6
|
+
*/
|
|
7
|
+
const ellipsisLine = {
|
|
8
|
+
overflow: 'hidden',
|
|
9
|
+
width: '100%',
|
|
10
|
+
whiteSpace: 'nowrap',
|
|
11
|
+
textOverflow: 'ellipsis'
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
4
15
|
* The styles for the error message.
|
|
5
|
-
*/
|
|
16
|
+
*/
|
|
17
|
+
const error = css({
|
|
18
|
+
position: 'absolute',
|
|
19
|
+
bottom: 2,
|
|
20
|
+
fontSize: 12,
|
|
21
|
+
lineHeight: '14px',
|
|
22
|
+
color: `var(--color-state-alert, ${themeConfig.colors.error})`,
|
|
23
|
+
...ellipsisLine
|
|
24
|
+
}).toString();
|
|
25
|
+
export default {
|
|
26
|
+
error
|
|
27
|
+
};
|
|
@@ -1,5 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import Input from '@shopgate/pwa-common/components/Input';
|
|
5
|
+
import styles from "./style";
|
|
6
|
+
|
|
7
|
+
/**
|
|
2
8
|
* Creates an input or a multiLine based on the type prop.
|
|
3
9
|
* @param {Object} props The props.
|
|
4
10
|
* @returns {JSX.Element}
|
|
5
|
-
*/
|
|
11
|
+
*/
|
|
12
|
+
const FormElement = props => {
|
|
13
|
+
const styleType = props.multiLine ? 'multiLine' : 'input';
|
|
14
|
+
return /*#__PURE__*/React.createElement(Input, _extends({}, props, {
|
|
15
|
+
className: styles[styleType],
|
|
16
|
+
validateOnBlur: true
|
|
17
|
+
}));
|
|
18
|
+
};
|
|
19
|
+
FormElement.defaultProps = {
|
|
20
|
+
multiLine: false
|
|
21
|
+
};
|
|
22
|
+
export default FormElement;
|