@shopgate/pwa-ui-shared 7.30.0-alpha.6 → 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.
Files changed (266) hide show
  1. package/AccordionContainer/index.js +39 -5
  2. package/AccordionContainer/spec.js +25 -2
  3. package/ActionButton/index.js +63 -7
  4. package/ActionButton/spec.js +59 -2
  5. package/ActionButton/style.js +22 -1
  6. package/AddToCartButton/index.js +184 -27
  7. package/AddToCartButton/mock.js +18 -4
  8. package/AddToCartButton/spec.js +51 -2
  9. package/AddToCartButton/style.js +127 -11
  10. package/Availability/index.js +34 -2
  11. package/Availability/spec.js +41 -1
  12. package/Availability/style.js +19 -1
  13. package/Button/index.js +76 -5
  14. package/Button/spec.js +33 -1
  15. package/Button/style.js +130 -21
  16. package/ButtonLink/connector.js +11 -2
  17. package/ButtonLink/index.js +44 -6
  18. package/ButtonLink/spec.js +23 -1
  19. package/Card/index.js +19 -2
  20. package/Card/style.js +11 -1
  21. package/CardList/components/Item/index.js +26 -2
  22. package/CardList/components/Item/style.js +7 -1
  23. package/CardList/index.js +34 -3
  24. package/CartTotalLine/components/Amount/index.js +28 -2
  25. package/CartTotalLine/components/Amount/style.js +8 -1
  26. package/CartTotalLine/components/Hint/index.js +23 -2
  27. package/CartTotalLine/components/Hint/style.js +12 -1
  28. package/CartTotalLine/components/Label/index.js +36 -2
  29. package/CartTotalLine/components/Label/style.js +17 -1
  30. package/CartTotalLine/components/Spacer/index.js +16 -2
  31. package/CartTotalLine/index.js +39 -2
  32. package/CartTotalLine/style.js +31 -1
  33. package/Checkbox/index.js +31 -2
  34. package/Checkbox/style.js +18 -1
  35. package/Chip/index.js +61 -2
  36. package/Chip/spec.js +24 -1
  37. package/Chip/style.js +71 -3
  38. package/ContextMenu/ContextMenu.hooks.js +6 -2
  39. package/ContextMenu/ContextMenuProvider.context.js +9 -3
  40. package/ContextMenu/ContextMenuProvider.js +21 -2
  41. package/ContextMenu/components/Item/index.js +67 -5
  42. package/ContextMenu/components/Item/style.js +32 -3
  43. package/ContextMenu/components/Position/index.js +61 -10
  44. package/ContextMenu/components/Position/style.js +11 -1
  45. package/ContextMenu/index.js +124 -3
  46. package/ContextMenu/spec.js +101 -2
  47. package/ContextMenu/style.js +45 -1
  48. package/Dialog/components/BasicDialog/index.js +5 -1
  49. package/Dialog/components/HtmlContentDialog/index.js +22 -2
  50. package/Dialog/components/HtmlContentDialog/spec.js +59 -1
  51. package/Dialog/components/PipelineErrorDialog/index.js +114 -25
  52. package/Dialog/components/PipelineErrorDialog/spec.js +92 -12
  53. package/Dialog/components/TextMessageDialog/index.js +28 -2
  54. package/Dialog/components/TextMessageDialog/spec.js +59 -1
  55. package/Dialog/components/VariantSelectModal/connector.js +11 -2
  56. package/Dialog/components/VariantSelectModal/index.js +65 -6
  57. package/Dialog/components/VariantSelectModal/spec.js +51 -2
  58. package/Dialog/constants.js +6 -1
  59. package/Dialog/index.js +114 -7
  60. package/Dialog/spec.js +81 -3
  61. package/DiscountBadge/index.js +30 -2
  62. package/DiscountBadge/spec.js +19 -1
  63. package/DiscountBadge/style.js +34 -2
  64. package/FavoritesButton/connector.js +18 -3
  65. package/FavoritesButton/index.js +118 -15
  66. package/FavoritesButton/mock.js +50 -4
  67. package/FavoritesButton/spec.js +120 -2
  68. package/FavoritesButton/style.js +26 -1
  69. package/Form/Builder/builders/buildCountryList.js +40 -6
  70. package/Form/Builder/builders/buildFormDefaults.js +35 -6
  71. package/Form/Builder/builders/buildFormElements.js +68 -10
  72. package/Form/Builder/builders/buildProvinceList.js +19 -2
  73. package/Form/Builder/builders/buildValidationErrorList.js +7 -2
  74. package/Form/Builder/classes/ActionListener/constants.js +22 -2
  75. package/Form/Builder/classes/ActionListener/index.js +441 -93
  76. package/Form/Builder/classes/ActionListener/spec.js +321 -19
  77. package/Form/Builder/components/CheckboxElement.js +35 -3
  78. package/Form/Builder/components/CountryElement.js +40 -3
  79. package/Form/Builder/components/ProvinceElement.js +40 -3
  80. package/Form/Builder/components/RadioElement.js +41 -3
  81. package/Form/Builder/components/SelectElement.js +39 -3
  82. package/Form/Builder/components/TextElement.js +49 -4
  83. package/Form/Builder/elementTypes.js +11 -1
  84. package/Form/Builder/index.js +298 -52
  85. package/Form/Builder/iso-3166-2.js +4943 -1
  86. package/Form/Builder/spec.js +300 -16
  87. package/Form/Checkbox/index.js +66 -4
  88. package/Form/Checkbox/style.js +25 -2
  89. package/Form/InfoField/index.js +50 -2
  90. package/Form/InfoField/spec.js +9 -1
  91. package/Form/InfoField/style.js +11 -1
  92. package/Form/Password/index.js +51 -6
  93. package/Form/Password/spec.js +34 -1
  94. package/Form/Password/style.js +11 -1
  95. package/Form/RadioGroup/components/Item/index.js +59 -3
  96. package/Form/RadioGroup/components/Item/style.js +32 -2
  97. package/Form/RadioGroup/index.js +101 -9
  98. package/Form/RadioGroup/spec.js +83 -3
  99. package/Form/RadioGroup/style.js +18 -2
  100. package/Form/Select/index.js +158 -10
  101. package/Form/Select/spec.js +36 -5
  102. package/Form/Select/style.js +27 -1
  103. package/Form/SelectContextChoices/index.js +77 -3
  104. package/Form/SelectContextChoices/spec.js +33 -4
  105. package/Form/SelectContextChoices/style.js +23 -1
  106. package/Form/TextField/index.js +92 -8
  107. package/Form/TextField/spec.js +110 -1
  108. package/Form/TextField/style.js +66 -8
  109. package/Form/index.js +54 -13
  110. package/FormElement/components/ErrorText/index.js +31 -2
  111. package/FormElement/components/ErrorText/style.js +13 -1
  112. package/FormElement/components/Label/index.js +35 -2
  113. package/FormElement/components/Label/style.js +76 -8
  114. package/FormElement/components/Placeholder/index.js +26 -2
  115. package/FormElement/components/Placeholder/style.js +48 -6
  116. package/FormElement/components/Underline/index.js +18 -2
  117. package/FormElement/components/Underline/style.js +51 -4
  118. package/FormElement/index.js +91 -6
  119. package/FormElement/spec.js +67 -2
  120. package/FormElement/style.js +13 -2
  121. package/Glow/index.js +90 -7
  122. package/Glow/spec.js +9 -1
  123. package/Glow/style.js +18 -1
  124. package/IndicatorCircle/index.js +33 -3
  125. package/IndicatorCircle/spec.js +28 -1
  126. package/IndicatorCircle/style.js +57 -3
  127. package/LoadingIndicator/index.js +29 -2
  128. package/LoadingIndicator/style.js +20 -1
  129. package/Manufacturer/index.js +20 -2
  130. package/Manufacturer/style.js +5 -1
  131. package/MessageBar/index.js +36 -2
  132. package/MessageBar/spec.js +79 -1
  133. package/MessageBar/style.js +38 -1
  134. package/NoResults/components/Icon/index.js +130 -2
  135. package/NoResults/components/Icon/style.js +17 -1
  136. package/NoResults/index.js +46 -2
  137. package/NoResults/style.js +31 -1
  138. package/Placeholder/index.js +25 -3
  139. package/Placeholder/style.js +11 -1
  140. package/PlaceholderLabel/index.js +27 -2
  141. package/PlaceholderLabel/spec.js +19 -1
  142. package/PlaceholderLabel/style.js +12 -1
  143. package/PlaceholderParagraph/index.js +36 -2
  144. package/PlaceholderParagraph/spec.js +19 -1
  145. package/Price/index.js +88 -7
  146. package/Price/style.js +22 -1
  147. package/PriceInfo/index.js +20 -2
  148. package/PriceInfo/style.js +5 -1
  149. package/PriceStriked/index.js +83 -12
  150. package/PriceStriked/style.js +33 -3
  151. package/ProductProperties/index.js +32 -2
  152. package/ProgressBar/index.js +101 -13
  153. package/ProgressBar/spec.js +13 -1
  154. package/ProgressBar/style.js +83 -2
  155. package/RadioButton/index.js +18 -2
  156. package/RadioButton/spec.js +21 -1
  157. package/RadioButton/style.js +21 -1
  158. package/RatingNumber/index.js +29 -2
  159. package/RatingStars/constants.js +2 -1
  160. package/RatingStars/index.js +130 -12
  161. package/RatingStars/spec.js +90 -3
  162. package/RatingStars/style.js +51 -2
  163. package/Ripple/components/RippleAnimation/index.js +88 -6
  164. package/Ripple/index.js +218 -40
  165. package/Ripple/style.js +18 -1
  166. package/RippleButton/index.js +52 -5
  167. package/RippleButton/spec.js +45 -1
  168. package/ScannerOverlay/components/CameraOverlay/index.js +13 -2
  169. package/ScannerOverlay/components/CameraOverlay/style.js +41 -1
  170. package/ScannerOverlay/components/ScannerBar/components/FlashlightButton/index.js +34 -2
  171. package/ScannerOverlay/components/ScannerBar/components/FlashlightButton/style.js +28 -1
  172. package/ScannerOverlay/components/ScannerBar/components/ScannerInstructions/index.js +11 -2
  173. package/ScannerOverlay/components/ScannerBar/index.js +31 -2
  174. package/ScannerOverlay/components/ScannerBar/style.js +20 -1
  175. package/ScannerOverlay/index.js +47 -7
  176. package/Sheet/components/Header/components/SearchBar/index.js +46 -2
  177. package/Sheet/components/Header/components/SearchBar/spec.js +21 -3
  178. package/Sheet/components/Header/components/SearchBar/style.js +47 -1
  179. package/Sheet/components/Header/index.js +75 -7
  180. package/Sheet/components/Header/spec.js +14 -1
  181. package/Sheet/components/Header/style.js +50 -1
  182. package/Sheet/index.js +170 -17
  183. package/Sheet/spec.js +85 -5
  184. package/Sheet/style.js +143 -2
  185. package/TaxDisclaimer/index.js +34 -4
  186. package/TaxDisclaimer/spec.js +31 -3
  187. package/TaxDisclaimer/style.js +9 -1
  188. package/TextField/components/ErrorText/index.js +33 -2
  189. package/TextField/components/ErrorText/style.js +25 -3
  190. package/TextField/components/FormElement/index.js +19 -2
  191. package/TextField/components/FormElement/style.js +32 -4
  192. package/TextField/components/Hint/index.js +21 -2
  193. package/TextField/components/Hint/style.js +40 -5
  194. package/TextField/components/Label/index.js +32 -3
  195. package/TextField/components/Label/style.js +68 -8
  196. package/TextField/components/Underline/index.js +19 -2
  197. package/TextField/components/Underline/style.js +51 -4
  198. package/TextField/index.js +189 -27
  199. package/TextField/spec.js +128 -3
  200. package/TextField/style.js +34 -4
  201. package/ToggleIcon/index.js +58 -8
  202. package/ToggleIcon/spec.js +35 -1
  203. package/icons/AccountBoxIcon.js +11 -2
  204. package/icons/AddMoreIcon.js +11 -2
  205. package/icons/ArrowDropIcon.js +11 -2
  206. package/icons/ArrowIcon.js +21 -2
  207. package/icons/BarcodeScannerIcon.js +11 -2
  208. package/icons/BoxIcon.js +11 -2
  209. package/icons/BrowseIcon.js +11 -2
  210. package/icons/BurgerIcon.js +11 -2
  211. package/icons/CalendarIcon.js +15 -3
  212. package/icons/CartCouponIcon.js +72 -2
  213. package/icons/CartIcon.js +11 -2
  214. package/icons/CartPlusIcon.js +11 -2
  215. package/icons/CheckIcon.js +11 -2
  216. package/icons/CheckedIcon.js +11 -2
  217. package/icons/ChevronIcon.js +11 -2
  218. package/icons/CreditCardIcon.js +11 -2
  219. package/icons/CrossIcon.js +11 -2
  220. package/icons/DescriptionIcon.js +11 -2
  221. package/icons/FilterIcon.js +11 -2
  222. package/icons/FlashDisabledIcon.js +11 -2
  223. package/icons/FlashEnabledIcon.js +11 -2
  224. package/icons/GridIcon.js +11 -2
  225. package/icons/HeartIcon.js +11 -2
  226. package/icons/HeartOutlineIcon.js +11 -2
  227. package/icons/HeartPlusIcon.js +12 -2
  228. package/icons/HeartPlusOutlineIcon.js +12 -2
  229. package/icons/HomeIcon.js +11 -2
  230. package/icons/InfoIcon.js +11 -2
  231. package/icons/InfoOutlineIcon.js +11 -2
  232. package/icons/ListIcon.js +11 -2
  233. package/icons/LocalShippingIcon.js +11 -2
  234. package/icons/LocationIcon.js +13 -3
  235. package/icons/LocatorIcon.js +11 -2
  236. package/icons/LockIcon.js +11 -2
  237. package/icons/LogoutIcon.js +11 -2
  238. package/icons/MagnifierIcon.js +11 -2
  239. package/icons/MapMarkerIcon.js +24 -3
  240. package/icons/MoreIcon.js +11 -2
  241. package/icons/MoreVertIcon.js +11 -2
  242. package/icons/NotificationIcon.js +14 -3
  243. package/icons/PersonIcon.js +12 -2
  244. package/icons/PhoneIcon.js +13 -3
  245. package/icons/PlaceholderIcon.js +11 -2
  246. package/icons/RadioCheckedIcon.js +11 -2
  247. package/icons/RadioUncheckedIcon.js +11 -2
  248. package/icons/SecurityIcon.js +11 -2
  249. package/icons/ShippingMethodIcon.js +18 -3
  250. package/icons/ShoppingCartIcon.js +11 -2
  251. package/icons/SortIcon.js +11 -2
  252. package/icons/StarHalfIcon.js +18 -2
  253. package/icons/StarIcon.js +18 -2
  254. package/icons/StarOutlineIcon.js +11 -2
  255. package/icons/StopIcon.js +11 -2
  256. package/icons/TickIcon.js +11 -2
  257. package/icons/TimeIcon.js +14 -3
  258. package/icons/TrashIcon.js +11 -2
  259. package/icons/TrashOutlineIcon.js +12 -2
  260. package/icons/UncheckedIcon.js +11 -2
  261. package/icons/ViewListIcon.js +11 -2
  262. package/icons/VisibilityIcon.js +11 -2
  263. package/icons/VisibilityOffIcon.js +11 -2
  264. package/icons/WarningIcon.js +11 -2
  265. package/index.js +13 -1
  266. package/package.json +5 -5
@@ -1,8 +1,42 @@
1
- function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _typeof(obj);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor;}function _callSuper(_this,derived,args){function isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{return!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(e){return false;}}derived=_getPrototypeOf(derived);return _possibleConstructorReturn(_this,isNativeReflectConstruct()?Reflect.construct(derived,args||[],_getPrototypeOf(_this).constructor):derived.apply(_this,args));}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import{Component}from'react';import PropTypes from'prop-types';/**
1
+ import { Component } from 'react';
2
+ import PropTypes from 'prop-types';
3
+
4
+ /**
2
5
  * The Accordion container component.
3
- */var AccordionContainer=/*#__PURE__*/function(_Component){function AccordionContainer(props){var _this2;_classCallCheck(this,AccordionContainer);_this2=_callSuper(this,AccordionContainer,[props]);_defineProperty(_this2,"open",function(){_this2.setState({open:true});});_defineProperty(_this2,"close",function(){_this2.setState({open:false});});_this2.state={open:props.open};return _this2;}_inherits(AccordionContainer,_Component);return _createClass(AccordionContainer,[{key:"render",value:/**
4
- * @returns {JSX}
5
- */function render(){return this.props.children({handleClose:this.close,open:this.state.open,handleOpen:this.open});}}]);}(Component);_defineProperty(AccordionContainer,"defaultProps",{open:false/**
6
+ */
7
+ class AccordionContainer extends Component {
8
+ /**
6
9
  * Init
7
10
  * @param {Object} props Props
8
- */});export default AccordionContainer;
11
+ */
12
+ constructor(props) {
13
+ super(props);
14
+ this.open = () => {
15
+ this.setState({
16
+ open: true
17
+ });
18
+ };
19
+ this.close = () => {
20
+ this.setState({
21
+ open: false
22
+ });
23
+ };
24
+ this.state = {
25
+ open: props.open
26
+ };
27
+ }
28
+ /**
29
+ * @returns {JSX}
30
+ */
31
+ render() {
32
+ return this.props.children({
33
+ handleClose: this.close,
34
+ open: this.state.open,
35
+ handleOpen: this.open
36
+ });
37
+ }
38
+ }
39
+ AccordionContainer.defaultProps = {
40
+ open: false
41
+ };
42
+ export default AccordionContainer;
@@ -1,3 +1,26 @@
1
- function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _typeof(obj);}import React from'react';import{shallow}from'enzyme';import AccordionContainer from"./index";/**
1
+ import React from 'react';
2
+ import { shallow } from 'enzyme';
3
+ import AccordionContainer from "./index";
4
+
5
+ /**
2
6
  * @returns {JSX}
3
- */var Child=function Child(){return React.createElement("div",null);};describe('<AccordionContainer />',function(){it('should render children with props',function(){var wrapper=shallow(React.createElement(AccordionContainer,null,function(props){return React.createElement(Child,props);}));var props=wrapper.find('Child').props();expect(wrapper).toMatchSnapshot();expect(props.open).toEqual(false);expect(_typeof(props.handleOpen)).toEqual('function');expect(_typeof(props.handleClose)).toEqual('function');});it('should update children props when state changes',function(){var wrapper=shallow(React.createElement(AccordionContainer,null,function(props){return React.createElement(Child,props);}));wrapper.setState({open:true});expect(wrapper).toMatchSnapshot();expect(wrapper.find('Child').props().open).toEqual(true);});});
7
+ */
8
+ const Child = () => /*#__PURE__*/React.createElement("div", null);
9
+ describe('<AccordionContainer />', () => {
10
+ it('should render children with props', () => {
11
+ const wrapper = shallow(/*#__PURE__*/React.createElement(AccordionContainer, null, props => /*#__PURE__*/React.createElement(Child, props)));
12
+ const props = wrapper.find('Child').props();
13
+ expect(wrapper).toMatchSnapshot();
14
+ expect(props.open).toEqual(false);
15
+ expect(typeof props.handleOpen).toEqual('function');
16
+ expect(typeof props.handleClose).toEqual('function');
17
+ });
18
+ it('should update children props when state changes', () => {
19
+ const wrapper = shallow(/*#__PURE__*/React.createElement(AccordionContainer, null, props => /*#__PURE__*/React.createElement(Child, props)));
20
+ wrapper.setState({
21
+ open: true
22
+ });
23
+ expect(wrapper).toMatchSnapshot();
24
+ expect(wrapper.find('Child').props().open).toEqual(true);
25
+ });
26
+ });
@@ -1,12 +1,68 @@
1
- function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _typeof(obj);}function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor;}function _callSuper(_this,derived,args){function isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{return!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(e){return false;}}derived=_getPrototypeOf(derived);return _possibleConstructorReturn(_this,isNativeReflectConstruct()?Reflect.construct(derived,args||[],_getPrototypeOf(_this).constructor):derived.apply(_this,args));}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import React,{Component}from'react';import PropTypes from'prop-types';import IndicatorCircle from"../IndicatorCircle";import RippleButton from"../RippleButton";import styles from"./style";/**
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import React, { Component } from 'react';
3
+ import PropTypes from 'prop-types';
4
+ import IndicatorCircle from "../IndicatorCircle";
5
+ import RippleButton from "../RippleButton";
6
+ import styles from "./style";
7
+
8
+ /**
2
9
  * The action button component.
3
- */var ActionButton=/*#__PURE__*/function(_Component){function ActionButton(){var _this2;_classCallCheck(this,ActionButton);for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key];}_this2=_callSuper(this,ActionButton,[].concat(args));/**
4
- * The click handler
5
- * @param {Object} event The event object for the click handler
6
- */_defineProperty(_this2,"handleClick",function(event){var clickDelay=_this2.constructor.clickDelay;setTimeout(function(){_this2.props.onClick(event);},clickDelay);});return _this2;}_inherits(ActionButton,_Component);return _createClass(ActionButton,[{key:"buttonProps",get:/**
10
+ */
11
+ class ActionButton extends Component {
12
+ constructor(...args) {
13
+ super(...args);
14
+ /**
15
+ * The click handler
16
+ * @param {Object} event The event object for the click handler
17
+ */
18
+ this.handleClick = event => {
19
+ const {
20
+ clickDelay
21
+ } = this.constructor;
22
+ setTimeout(() => {
23
+ this.props.onClick(event);
24
+ }, clickDelay);
25
+ };
26
+ }
27
+ /**
7
28
  * Getter for the calculated button props.
8
29
  * @returns {Object}
9
- */function get(){var buttonProps={className:this.props.className,disabled:this.props.disabled,flat:this.props.flat,type:this.props.type};return buttonProps;}},{key:"render",value:/**
30
+ */
31
+ get buttonProps() {
32
+ const buttonProps = {
33
+ className: this.props.className,
34
+ disabled: this.props.disabled,
35
+ flat: this.props.flat,
36
+ type: this.props.type
37
+ };
38
+ return buttonProps;
39
+ }
40
+ /**
10
41
  * The render function.
11
42
  * @returns {JSX}
12
- */function render(){var containerClass=this.props.noGap?styles.noGapContainer:styles.container;if(this.props.loading){return React.createElement("div",{className:styles.containerCircle},React.createElement(IndicatorCircle,null));}return React.createElement("div",{className:"ui-shared__action-button ".concat(containerClass),"data-test-id":this.props.testId},React.createElement(RippleButton,_extends({},this.buttonProps,{onClick:this.handleClick}),this.props.children));}}]);}(Component);_defineProperty(ActionButton,"clickDelay",300);_defineProperty(ActionButton,"defaultProps",_extends({},RippleButton.defaultProps,{loading:false,type:'primary',flat:true,noGap:false,testId:null}));export default ActionButton;
43
+ */
44
+ render() {
45
+ const containerClass = this.props.noGap ? styles.noGapContainer : styles.container;
46
+ if (this.props.loading) {
47
+ return /*#__PURE__*/React.createElement("div", {
48
+ className: styles.containerCircle
49
+ }, /*#__PURE__*/React.createElement(IndicatorCircle, null));
50
+ }
51
+ return /*#__PURE__*/React.createElement("div", {
52
+ className: `ui-shared__action-button ${containerClass}`,
53
+ "data-test-id": this.props.testId
54
+ }, /*#__PURE__*/React.createElement(RippleButton, _extends({}, this.buttonProps, {
55
+ onClick: this.handleClick
56
+ }), this.props.children));
57
+ }
58
+ }
59
+ ActionButton.clickDelay = 300;
60
+ ActionButton.defaultProps = {
61
+ ...RippleButton.defaultProps,
62
+ loading: false,
63
+ type: 'primary',
64
+ flat: true,
65
+ noGap: false,
66
+ testId: null
67
+ };
68
+ export default ActionButton;
@@ -1,4 +1,61 @@
1
- import React from'react';import{shallow}from'enzyme';import IndicatorCircle from"../IndicatorCircle";import RippleButton from"../RippleButton";import ActionButton from"./index";describe('<ActionButton />',function(){var renderedElement;var mockOnClick;jest.useFakeTimers();/**
1
+ import React from 'react';
2
+ import { shallow } from 'enzyme';
3
+ import IndicatorCircle from "../IndicatorCircle";
4
+ import RippleButton from "../RippleButton";
5
+ import ActionButton from "./index";
6
+ describe('<ActionButton />', () => {
7
+ let renderedElement;
8
+ let mockOnClick;
9
+ jest.useFakeTimers();
10
+
11
+ /**
2
12
  * Renders the component.
3
13
  * @param {Object} props The component props.
4
- */var renderComponent=function renderComponent(){var props=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};renderedElement=shallow(React.createElement(ActionButton,props,"Action Button"));};describe('Given the component was mounted to the DOM',function(){beforeEach(function(){mockOnClick=jest.fn();renderComponent({onClick:mockOnClick});});it('should match snapshot',function(){expect(renderedElement).toMatchSnapshot();});it('should not show the loading indicator by default',function(){var indicator=renderedElement.find(IndicatorCircle);expect(indicator.length).toBe(0);});describe('Given the loading prop is set to true',function(){beforeEach(function(){renderedElement.setProps({loading:true});});it('should match snapshot',function(){expect(renderedElement).toMatchSnapshot();});it('should show the loading indicator',function(){var indicator=renderedElement.find(IndicatorCircle);expect(indicator.length).toBe(1);});});describe('Given the component gets clicked',function(){beforeEach(function(){renderedElement.find(RippleButton).simulate('click');});it('should use setTimeout for delaying the onClick handler',function(){expect(setTimeout.mock.calls.length).toBe(1);expect(setTimeout.mock.calls[0][1]).toBe(ActionButton.clickDelay);});it('should eventually call the onClick handler',function(){jest.runOnlyPendingTimers();expect(mockOnClick).toBeCalled();expect(mockOnClick.mock.calls.length).toBe(1);});});});});
14
+ */
15
+ const renderComponent = (props = {}) => {
16
+ renderedElement = shallow(/*#__PURE__*/React.createElement(ActionButton, props, "Action Button"));
17
+ };
18
+ describe('Given the component was mounted to the DOM', () => {
19
+ beforeEach(() => {
20
+ mockOnClick = jest.fn();
21
+ renderComponent({
22
+ onClick: mockOnClick
23
+ });
24
+ });
25
+ it('should match snapshot', () => {
26
+ expect(renderedElement).toMatchSnapshot();
27
+ });
28
+ it('should not show the loading indicator by default', () => {
29
+ const indicator = renderedElement.find(IndicatorCircle);
30
+ expect(indicator.length).toBe(0);
31
+ });
32
+ describe('Given the loading prop is set to true', () => {
33
+ beforeEach(() => {
34
+ renderedElement.setProps({
35
+ loading: true
36
+ });
37
+ });
38
+ it('should match snapshot', () => {
39
+ expect(renderedElement).toMatchSnapshot();
40
+ });
41
+ it('should show the loading indicator', () => {
42
+ const indicator = renderedElement.find(IndicatorCircle);
43
+ expect(indicator.length).toBe(1);
44
+ });
45
+ });
46
+ describe('Given the component gets clicked', () => {
47
+ beforeEach(() => {
48
+ renderedElement.find(RippleButton).simulate('click');
49
+ });
50
+ it('should use setTimeout for delaying the onClick handler', () => {
51
+ expect(setTimeout.mock.calls.length).toBe(1);
52
+ expect(setTimeout.mock.calls[0][1]).toBe(ActionButton.clickDelay);
53
+ });
54
+ it('should eventually call the onClick handler', () => {
55
+ jest.runOnlyPendingTimers();
56
+ expect(mockOnClick).toBeCalled();
57
+ expect(mockOnClick.mock.calls.length).toBe(1);
58
+ });
59
+ });
60
+ });
61
+ });
@@ -1 +1,22 @@
1
- function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}import{css}from'glamor';import{themeConfig}from'@shopgate/pwa-common/helpers/config';var halfGapBig=themeConfig.variables.gap.big/2;var containerBase={textAlign:'center'};var container=css(_extends({},containerBase,{margin:"".concat(halfGapBig,"px 0")})).toString();var noGapContainer=css(_extends({},containerBase)).toString();var containerCircle=css(_extends({},containerBase,{margin:"".concat(halfGapBig+5,"px 0")})).toString();export default{container:container,containerCircle:containerCircle,noGapContainer:noGapContainer};
1
+ import { css } from 'glamor';
2
+ import { themeConfig } from '@shopgate/pwa-common/helpers/config';
3
+ const halfGapBig = themeConfig.variables.gap.big / 2;
4
+ const containerBase = {
5
+ textAlign: 'center'
6
+ };
7
+ const container = css({
8
+ ...containerBase,
9
+ margin: `${halfGapBig}px 0`
10
+ }).toString();
11
+ const noGapContainer = css({
12
+ ...containerBase
13
+ }).toString();
14
+ const containerCircle = css({
15
+ ...containerBase,
16
+ margin: `${halfGapBig + 5}px 0`
17
+ }).toString();
18
+ export default {
19
+ container,
20
+ containerCircle,
21
+ noGapContainer
22
+ };
@@ -1,44 +1,201 @@
1
- import _regeneratorRuntime from"@babel/runtime/regenerator";function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _typeof(obj);}function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor;}function _callSuper(_this,derived,args){function isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{return!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(e){return false;}}derived=_getPrototypeOf(derived);return _possibleConstructorReturn(_this,isNativeReflectConstruct()?Reflect.construct(derived,args||[],_getPrototypeOf(_this).constructor):derived.apply(_this,args));}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import React,{Component}from'react';import PropTypes from'prop-types';import{themeConfig}from'@shopgate/pwa-common/helpers/config';import{withForwardedRef}from'@shopgate/engage/core';import CartPlusIcon from"../icons/CartPlusIcon";import TickIcon from"../icons/TickIcon";import IndicatorCircle from"../IndicatorCircle";import styles from"./style";/**
1
+ import React, { Component } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { themeConfig } from '@shopgate/pwa-common/helpers/config';
4
+ import { withForwardedRef } from '@shopgate/engage/core';
5
+ import CartPlusIcon from "../icons/CartPlusIcon";
6
+ import TickIcon from "../icons/TickIcon";
7
+ import IndicatorCircle from "../IndicatorCircle";
8
+ import styles from "./style";
9
+
10
+ /**
2
11
  * AddToCartButton component.
3
- */var AddToCartButton=/*#__PURE__*/function(_Component){/**
12
+ */
13
+ class AddToCartButton extends Component {
14
+ /**
4
15
  * Constructor for the AddToCartButton component.
5
16
  * @param {Object} props Props for the component.
6
- */function AddToCartButton(props){var _this2;_classCallCheck(this,AddToCartButton);_this2=_callSuper(this,AddToCartButton,[props]);/**
7
- * Handles the button click.
8
- * - Show checkmark.
9
- * - Add to cart.
10
- * - Wait 900ms.
11
- * - Show cart icon again.
12
- * @param {Event} e Event
13
- */_defineProperty(_this2,"handleClick",function(e){// Ignore clicks when check mark or loading spinner is shown or the button is disabled.
14
- if(_this2.state.showCheckmark||_this2.props.isLoading||_this2.props.isDisabled){return;}/** */var handleCompletion=function handleCompletion(){_this2.setState({showCheckmark:true});setTimeout(function(){_this2.setState({showCheckmark:false});},900);};var result=_this2.props.onClick(e);if(result===false){// Do not trigger animation when adding to cart was aborted by the parent component (PWA-2764)
15
- return;}if(result instanceof Promise){_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(){return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:_context.prev=0;_context.next=3;return result;case 3:handleCompletion();_context.next=8;break;case 6:_context.prev=6;_context.t0=_context["catch"](0);case 8:case"end":return _context.stop();}},_callee,null,[[0,6]]);}))();return;}handleCompletion();});/**
16
- * Handles the cart animation end event.
17
- * Resets the showCheckmark state to null in order to
18
- * prevent the icon from animating after changing visibility
19
- * of the view.
20
- * This is caused by CSS animations that get re-applied when
21
- * setting an element from hidden (display: none) to visible.
22
- */_defineProperty(_this2,"handleCartAnimationEnd",function(){if(_this2.state.showCheckmark===false){_this2.setState({showCheckmark:null});}_this2.props.onReset();});_this2.state={showCheckmark:null};return _this2;}_inherits(AddToCartButton,_Component);return _createClass(AddToCartButton,[{key:"render",value:/**
17
+ */
18
+ constructor(props) {
19
+ super(props);
20
+ /**
21
+ * Handles the button click.
22
+ * - Show checkmark.
23
+ * - Add to cart.
24
+ * - Wait 900ms.
25
+ * - Show cart icon again.
26
+ * @param {Event} e Event
27
+ */
28
+ this.handleClick = e => {
29
+ // Ignore clicks when check mark or loading spinner is shown or the button is disabled.
30
+ if (this.state.showCheckmark || this.props.isLoading || this.props.isDisabled) {
31
+ return;
32
+ }
33
+
34
+ /** */
35
+ const handleCompletion = () => {
36
+ this.setState({
37
+ showCheckmark: true
38
+ });
39
+ setTimeout(() => {
40
+ this.setState({
41
+ showCheckmark: false
42
+ });
43
+ }, 900);
44
+ };
45
+ const result = this.props.onClick(e);
46
+ if (result === false) {
47
+ // Do not trigger animation when adding to cart was aborted by the parent component (PWA-2764)
48
+ return;
49
+ }
50
+ if (result instanceof Promise) {
51
+ (async () => {
52
+ try {
53
+ await result;
54
+ handleCompletion();
55
+ } catch (error) {
56
+ // ignore error in button.
57
+ }
58
+ })();
59
+ return;
60
+ }
61
+ handleCompletion();
62
+ };
63
+ /**
64
+ * Handles the cart animation end event.
65
+ * Resets the showCheckmark state to null in order to
66
+ * prevent the icon from animating after changing visibility
67
+ * of the view.
68
+ * This is caused by CSS animations that get re-applied when
69
+ * setting an element from hidden (display: none) to visible.
70
+ */
71
+ this.handleCartAnimationEnd = () => {
72
+ if (this.state.showCheckmark === false) {
73
+ this.setState({
74
+ showCheckmark: null
75
+ });
76
+ }
77
+ this.props.onReset();
78
+ };
79
+ this.state = {
80
+ showCheckmark: null
81
+ };
82
+ }
83
+ /**
23
84
  * Renders the component
24
85
  * @returns {JSX}
25
- */function render(){// Set initial base styles
26
- var buttonStyle=styles.buttonReady;var tickIconStyle=styles.icon;var cartPlusIconStyle=styles.icon;// Depending on the isLoading prop we only show the spinner or the other way around.
27
- var iconOpacity=this.props.isLoading?{opacity:0}:{opacity:1};var spinnerInlineStyle=this.props.isLoading?{opacity:1}:{opacity:0};/**
86
+ */
87
+ render() {
88
+ // Set initial base styles
89
+ let buttonStyle = styles.buttonReady;
90
+ let tickIconStyle = styles.icon;
91
+ let cartPlusIconStyle = styles.icon;
92
+
93
+ // Depending on the isLoading prop we only show the spinner or the other way around.
94
+ const iconOpacity = this.props.isLoading ? {
95
+ opacity: 0
96
+ } : {
97
+ opacity: 1
98
+ };
99
+ const spinnerInlineStyle = this.props.isLoading ? {
100
+ opacity: 1
101
+ } : {
102
+ opacity: 0
103
+ };
104
+
105
+ /**
28
106
  * The initial positions for the icons:
29
107
  * Tick icon stays hidden on top, Cart icon stays visibly at the center
30
- */var tickInlineStyle=this.state.showCheckmark===null?_extends({transform:'translate3d(0, 300%, 0)'},iconOpacity):null;var cartInlineStyle=this.state.showCheckmark===null?_extends({transform:'translate3d(0, -50%, 0)'},iconOpacity):null;if(this.props.isDisabled&&!this.props.isLoading){buttonStyle=styles.buttonDisabled;}else if(this.state.showCheckmark){/**
108
+ */
109
+ let tickInlineStyle = this.state.showCheckmark === null ? {
110
+ transform: 'translate3d(0, 300%, 0)',
111
+ ...iconOpacity
112
+ } : null;
113
+ let cartInlineStyle = this.state.showCheckmark === null ? {
114
+ transform: 'translate3d(0, -50%, 0)',
115
+ ...iconOpacity
116
+ } : null;
117
+ if (this.props.isDisabled && !this.props.isLoading) {
118
+ buttonStyle = styles.buttonDisabled;
119
+ } else if (this.state.showCheckmark) {
120
+ /**
31
121
  * When checkmark should be shown, we start the spring transition
32
122
  * Tick icon springs in, and cart icon springs out.
33
- */tickIconStyle+=" ".concat(styles.springFromBottom);cartPlusIconStyle+=" ".concat(styles.springToTop);buttonStyle=styles.buttonSuccess;/**
123
+ */
124
+ tickIconStyle += ` ${styles.springFromBottom}`;
125
+ cartPlusIconStyle += ` ${styles.springToTop}`;
126
+ buttonStyle = styles.buttonSuccess;
127
+ /**
34
128
  * After the keyframe animation is done the transform values are reset
35
129
  * We add the inline style to make sure the icons stay where they are even after the animation
36
- */tickInlineStyle=_extends({transform:'translate3d(0, -50%, 0)'},iconOpacity);cartInlineStyle=_extends({transform:'translate3d(0, -300%, 0)'},iconOpacity);}else if(this.state.showCheckmark!==null){/**
130
+ */
131
+ tickInlineStyle = {
132
+ transform: 'translate3d(0, -50%, 0)',
133
+ ...iconOpacity
134
+ };
135
+ cartInlineStyle = {
136
+ transform: 'translate3d(0, -300%, 0)',
137
+ ...iconOpacity
138
+ };
139
+ } else if (this.state.showCheckmark !== null) {
140
+ /**
37
141
  * When checkmark should no longer be shown we start the spring out transition.
38
142
  * Tick icon springs out, cart icon spring in.
39
143
  * We don't want a animation when we initially go to the page therefore this only happens
40
144
  * after the user pressed the button.
41
- */tickIconStyle+=" ".concat(styles.springToBottom);cartPlusIconStyle+=" ".concat(styles.springFromTop);/**
145
+ */
146
+ tickIconStyle += ` ${styles.springToBottom}`;
147
+ cartPlusIconStyle += ` ${styles.springFromTop}`;
148
+ /**
42
149
  * After the keyframe animation is done the transform values are reset
43
150
  * We add the inline style to make sure the icons stay where they are even after the animation
44
- */cartInlineStyle=_extends({transform:'translate3d(0, -50%, 0)'},iconOpacity);tickInlineStyle=_extends({transform:'translate3d(0, -300%, 0)'},iconOpacity);}var className=styles.buttonWrapper(this.props.buttonSize,this.props.iconSize);if(this.props.noShadow){className=styles.buttonWrapperNoShadow(this.props.buttonSize,this.props.iconSize);}return React.createElement("button",{"data-test-id":"addToCartButton",className:"ui-shared__add-to-cart-button ".concat(this.props.className," ").concat(className," ").concat(buttonStyle),onClick:this.handleClick,"aria-hidden":this.props['aria-hidden'],"aria-label":this.props['aria-label'],"aria-disabled":this.props.isDisabled,ref:this.props.forwardedRef,type:"button"},this.props.isLoading&&React.createElement("div",{className:"".concat(styles.icon," ").concat(styles.spinnerIcon),style:spinnerInlineStyle},React.createElement(IndicatorCircle,{color:themeConfig.colors.primaryContrast,strokeWidth:5,paused:!this.props.isLoading})),React.createElement("div",{className:tickIconStyle,style:tickInlineStyle},React.createElement(TickIcon,null)),React.createElement("div",{className:cartPlusIconStyle,style:cartInlineStyle,onAnimationEnd:this.handleCartAnimationEnd},React.createElement(CartPlusIcon,null)));}}]);}(Component);_defineProperty(AddToCartButton,"defaultProps",{'aria-hidden':false,'aria-label':null,buttonSize:styles.buttonSize,className:null,forwardedRef:null,iconSize:styles.iconSize,noShadow:false,onReset:function onReset(){}});export default withForwardedRef(AddToCartButton);
151
+ */
152
+ cartInlineStyle = {
153
+ transform: 'translate3d(0, -50%, 0)',
154
+ ...iconOpacity
155
+ };
156
+ tickInlineStyle = {
157
+ transform: 'translate3d(0, -300%, 0)',
158
+ ...iconOpacity
159
+ };
160
+ }
161
+ let className = styles.buttonWrapper(this.props.buttonSize, this.props.iconSize);
162
+ if (this.props.noShadow) {
163
+ className = styles.buttonWrapperNoShadow(this.props.buttonSize, this.props.iconSize);
164
+ }
165
+ return /*#__PURE__*/React.createElement("button", {
166
+ "data-test-id": "addToCartButton",
167
+ className: `ui-shared__add-to-cart-button ${this.props.className} ${className} ${buttonStyle}`,
168
+ onClick: this.handleClick,
169
+ "aria-hidden": this.props['aria-hidden'],
170
+ "aria-label": this.props['aria-label'],
171
+ "aria-disabled": this.props.isDisabled,
172
+ ref: this.props.forwardedRef,
173
+ type: "button"
174
+ }, this.props.isLoading && /*#__PURE__*/React.createElement("div", {
175
+ className: `${styles.icon} ${styles.spinnerIcon}`,
176
+ style: spinnerInlineStyle
177
+ }, /*#__PURE__*/React.createElement(IndicatorCircle, {
178
+ color: themeConfig.colors.primaryContrast,
179
+ strokeWidth: 5,
180
+ paused: !this.props.isLoading
181
+ })), /*#__PURE__*/React.createElement("div", {
182
+ className: tickIconStyle,
183
+ style: tickInlineStyle
184
+ }, /*#__PURE__*/React.createElement(TickIcon, null)), /*#__PURE__*/React.createElement("div", {
185
+ className: cartPlusIconStyle,
186
+ style: cartInlineStyle,
187
+ onAnimationEnd: this.handleCartAnimationEnd
188
+ }, /*#__PURE__*/React.createElement(CartPlusIcon, null)));
189
+ }
190
+ }
191
+ AddToCartButton.defaultProps = {
192
+ 'aria-hidden': false,
193
+ 'aria-label': null,
194
+ buttonSize: styles.buttonSize,
195
+ className: null,
196
+ forwardedRef: null,
197
+ iconSize: styles.iconSize,
198
+ noShadow: false,
199
+ onReset: () => {}
200
+ };
201
+ export default withForwardedRef(AddToCartButton);
@@ -1,9 +1,23 @@
1
- var _Class,_temp;function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _typeof(obj);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor;}function _callSuper(_this,derived,args){function isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{return!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(e){return false;}}derived=_getPrototypeOf(derived);return _possibleConstructorReturn(_this,isNativeReflectConstruct()?Reflect.construct(derived,args||[],_getPrototypeOf(_this).constructor):derived.apply(_this,args));}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import React,{Component}from'react';import PropTypes from'prop-types';/**
1
+ var _Class;
2
+ import React, { Component } from 'react';
3
+ import PropTypes from 'prop-types';
4
+ /**
2
5
  * Mocked AddToCartButton.
3
6
  * @type {MockedAddToCartButton}
4
7
  * @deprecated
5
- */ // eslint-disable-next-line react/prefer-stateless-function
6
- export var MockedAddToCartButton=(_temp=_Class=/*#__PURE__*/function(_Component){function MockedAddToCartButton(){_classCallCheck(this,MockedAddToCartButton);return _callSuper(this,MockedAddToCartButton,arguments);}_inherits(MockedAddToCartButton,_Component);return _createClass(MockedAddToCartButton,[{key:"render",value:/**
8
+ */
9
+ // eslint-disable-next-line react/prefer-stateless-function
10
+ export const MockedAddToCartButton = (_Class = class MockedAddToCartButton extends Component {
11
+ /**
7
12
  * Renders mocked button.
8
13
  * @return {JSX}
9
- */function render(){return React.createElement("button",{onClick:this.props.onClick,type:"button"});}}]);}(Component),_defineProperty(_Class,"defaultProps",{onClick:function onClick(){}}),_temp);
14
+ */
15
+ render() {
16
+ return /*#__PURE__*/React.createElement("button", {
17
+ onClick: this.props.onClick,
18
+ type: "button"
19
+ });
20
+ }
21
+ }, _Class.defaultProps = {
22
+ onClick: () => {}
23
+ }, _Class);
@@ -1,4 +1,53 @@
1
- import _regeneratorRuntime from"@babel/runtime/regenerator";function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}import React from'react';import{mount}from'enzyme';import AddToCartButton from"./index";/**
1
+ import "core-js/modules/web.immediate.js";
2
+ import React from 'react';
3
+ import { mount } from 'enzyme';
4
+ import AddToCartButton from "./index";
5
+
6
+ /**
2
7
  * Flushes the promise queue.
3
8
  * @returns {Promise}
4
- */var flushPromises=function flushPromises(){return new Promise(function(resolve){return setImmediate(resolve);});};describe('<AddToCartButton />',function(){it('should render in loading state and should not be clickable',function(){var spy=jest.fn(function(){return new Promise(function(resolve){return resolve();});});var wrapper=mount(React.createElement(AddToCartButton,{onClick:spy,isLoading:true,isOrderable:true,isDisabled:false}));wrapper.find('button').prop('onClick')();expect(wrapper).toMatchSnapshot();expect(spy).toHaveBeenCalledTimes(0);});it('should render with checkmark icon and should not be clickable the second time',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(){var spy,wrapper;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:spy=jest.fn(function(){return new Promise(function(resolve){return resolve();});});wrapper=mount(React.createElement(AddToCartButton,{onClick:spy,isLoading:false,isOrderable:true,isDisabled:false}));wrapper.find('button').prop('onClick')();wrapper.update();_context.next=6;return flushPromises();case 6:wrapper.find('button').prop('onClick')();wrapper.update();_context.next=10;return flushPromises();case 10:expect(wrapper).toMatchSnapshot();expect(spy).toHaveBeenCalledTimes(1);case 12:case"end":return _context.stop();}},_callee);})));it('should render with cart icon and should be clickable',function(){var spy=jest.fn(function(){return new Promise(function(resolve){return resolve();});});var wrapper=mount(React.createElement(AddToCartButton,{onClick:spy,isLoading:false,isOrderable:true,isDisabled:false}));wrapper.find('button').prop('onClick')();expect(wrapper).toMatchSnapshot();expect(spy).toHaveBeenCalledTimes(1);});});
9
+ */
10
+ const flushPromises = () => new Promise(resolve => setImmediate(resolve));
11
+ describe('<AddToCartButton />', () => {
12
+ it('should render in loading state and should not be clickable', () => {
13
+ const spy = jest.fn(() => new Promise(resolve => resolve()));
14
+ const wrapper = mount(/*#__PURE__*/React.createElement(AddToCartButton, {
15
+ onClick: spy,
16
+ isLoading: true,
17
+ isOrderable: true,
18
+ isDisabled: false
19
+ }));
20
+ wrapper.find('button').prop('onClick')();
21
+ expect(wrapper).toMatchSnapshot();
22
+ expect(spy).toHaveBeenCalledTimes(0);
23
+ });
24
+ it('should render with checkmark icon and should not be clickable the second time', async () => {
25
+ const spy = jest.fn(() => new Promise(resolve => resolve()));
26
+ const wrapper = mount(/*#__PURE__*/React.createElement(AddToCartButton, {
27
+ onClick: spy,
28
+ isLoading: false,
29
+ isOrderable: true,
30
+ isDisabled: false
31
+ }));
32
+ wrapper.find('button').prop('onClick')();
33
+ wrapper.update();
34
+ await flushPromises();
35
+ wrapper.find('button').prop('onClick')();
36
+ wrapper.update();
37
+ await flushPromises();
38
+ expect(wrapper).toMatchSnapshot();
39
+ expect(spy).toHaveBeenCalledTimes(1);
40
+ });
41
+ it('should render with cart icon and should be clickable', () => {
42
+ const spy = jest.fn(() => new Promise(resolve => resolve()));
43
+ const wrapper = mount(/*#__PURE__*/React.createElement(AddToCartButton, {
44
+ onClick: spy,
45
+ isLoading: false,
46
+ isOrderable: true,
47
+ isDisabled: false
48
+ }));
49
+ wrapper.find('button').prop('onClick')();
50
+ expect(wrapper).toMatchSnapshot();
51
+ expect(spy).toHaveBeenCalledTimes(1);
52
+ });
53
+ });