@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 +1,45 @@
1
- import{css}from'glamor';import{themeConfig}from'@shopgate/pwa-common/helpers/config';var container=css({position:'relative'}).toString();var button=css({display:'block',fontSize:'1.5rem',outline:0,padding:0,color:'inherit'}).toString();var disabled=css({cursor:'not-allowed'}).toString();var overlay=css({position:'fixed',top:0,right:0,bottom:0,left:0,zIndex:10}).toString();var menu=css({position:'absolute',top:0,left:0,padding:"".concat(themeConfig.variables.gap.small,"px 0"),minWidth:130,background:themeConfig.colors.light,borderRadius:2,boxShadow:themeConfig.shadows.contextMenu}).toString();var scrollable=css({maxHeight:'30vh',overflowY:'auto'}).toString();export default{container:container,button:button,menu:menu,overlay:overlay,disabled:disabled,scrollable:scrollable};
1
+ import { css } from 'glamor';
2
+ import { themeConfig } from '@shopgate/pwa-common/helpers/config';
3
+ const container = css({
4
+ position: 'relative'
5
+ }).toString();
6
+ const button = css({
7
+ display: 'block',
8
+ fontSize: '1.5rem',
9
+ outline: 0,
10
+ padding: 0,
11
+ color: 'inherit'
12
+ }).toString();
13
+ const disabled = css({
14
+ cursor: 'not-allowed'
15
+ }).toString();
16
+ const overlay = css({
17
+ position: 'fixed',
18
+ top: 0,
19
+ right: 0,
20
+ bottom: 0,
21
+ left: 0,
22
+ zIndex: 10
23
+ }).toString();
24
+ const menu = css({
25
+ position: 'absolute',
26
+ top: 0,
27
+ left: 0,
28
+ padding: `${themeConfig.variables.gap.small}px 0`,
29
+ minWidth: 130,
30
+ background: themeConfig.colors.light,
31
+ borderRadius: 2,
32
+ boxShadow: themeConfig.shadows.contextMenu
33
+ }).toString();
34
+ const scrollable = css({
35
+ maxHeight: '30vh',
36
+ overflowY: 'auto'
37
+ }).toString();
38
+ export default {
39
+ container,
40
+ button,
41
+ menu,
42
+ overlay,
43
+ disabled,
44
+ scrollable
45
+ };
@@ -1,2 +1,6 @@
1
1
  // TODO: Move to ThemeContext
2
- import BaseDialogGMD from'@shopgate/pwa-ui-material/BaseDialog';import BaseDialogIOS from'@shopgate/pwa-ui-ios/BaseDialog';import{themeName}from'@shopgate/pwa-common/helpers/config';var isIos=themeName.includes('ios');export default isIos?BaseDialogIOS:BaseDialogGMD;
2
+ import BaseDialogGMD from '@shopgate/pwa-ui-material/BaseDialog';
3
+ import BaseDialogIOS from '@shopgate/pwa-ui-ios/BaseDialog';
4
+ import { themeName } from '@shopgate/pwa-common/helpers/config';
5
+ const isIos = themeName.includes('ios');
6
+ export default isIos ? BaseDialogIOS : BaseDialogGMD;
@@ -1,6 +1,26 @@
1
- import React from'react';import PropTypes from'prop-types';import BasicDialog from"../BasicDialog";/**
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import BasicDialog from "../BasicDialog";
4
+
5
+ /**
2
6
  * Renders a simple dialog with a title and html content as a message.
3
7
  * This is the default dialog if no type has been specified.
4
8
  * @param {Object} props The component properties.
5
9
  * @returns {JSX.Element} The rendered component.
6
- */var HtmlContentDialog=function HtmlContentDialog(_ref){var actions=_ref.actions,message=_ref.message,title=_ref.title;return React.createElement(BasicDialog,{title:title,actions:actions},React.createElement("div",{dangerouslySetInnerHTML:{__html:message}}));};HtmlContentDialog.defaultProps={title:BasicDialog.defaultProps.title};export default HtmlContentDialog;
10
+ */
11
+ const HtmlContentDialog = ({
12
+ actions,
13
+ message,
14
+ title
15
+ }) => /*#__PURE__*/React.createElement(BasicDialog, {
16
+ title: title,
17
+ actions: actions
18
+ }, /*#__PURE__*/React.createElement("div", {
19
+ dangerouslySetInnerHTML: {
20
+ __html: message
21
+ }
22
+ }));
23
+ HtmlContentDialog.defaultProps = {
24
+ title: BasicDialog.defaultProps.title
25
+ };
26
+ export default HtmlContentDialog;
@@ -1 +1,59 @@
1
- import React from'react';import{shallow}from'enzyme';import HtmlContentDialog from"./index";var message='<p><i>This is a html message.</i></p>';var title='This is the title.';jest.mock('@shopgate/engage/a11y/components');describe('<HtmlContentDialog />',function(){it('should render with minimal props',function(){var wrapper=shallow(React.createElement(HtmlContentDialog,{message:message,actions:[]}));expect(wrapper).toMatchSnapshot();expect(wrapper.html()).toMatch(message);});it('should render with title and html message',function(){var wrapper=shallow(React.createElement(HtmlContentDialog,{title:title,message:message,actions:[]}));expect(wrapper).toMatchSnapshot();expect(wrapper.html()).toMatch(title);});it('should render with title, html message and messageParams',function(){var wrapper=shallow(React.createElement(HtmlContentDialog,{title:title,message:"Message with {name}",params:{name:'Placeholder'},actions:[]}));expect(wrapper).toMatchSnapshot();});it('should render the actions',function(){var actions=[{label:'fooAction',action:function action(){}}];var wrapper=shallow(React.createElement(HtmlContentDialog,{title:title,message:message,actions:actions}));expect(wrapper).toMatchSnapshot();expect(wrapper.html()).toMatch(actions[0].label);});it('should pass title through',function(){var customTitle=React.createElement("div",null,"Title");var wrapper=shallow(React.createElement(HtmlContentDialog,{title:customTitle,message:message,params:{},actions:[]}));expect(wrapper.find('BasicDialog').prop('title')).toEqual(customTitle);});});
1
+ import React from 'react';
2
+ import { shallow } from 'enzyme';
3
+ import HtmlContentDialog from "./index";
4
+ const message = '<p><i>This is a html message.</i></p>';
5
+ const title = 'This is the title.';
6
+ jest.mock('@shopgate/engage/a11y/components');
7
+ describe('<HtmlContentDialog />', () => {
8
+ it('should render with minimal props', () => {
9
+ const wrapper = shallow(/*#__PURE__*/React.createElement(HtmlContentDialog, {
10
+ message: message,
11
+ actions: []
12
+ }));
13
+ expect(wrapper).toMatchSnapshot();
14
+ expect(wrapper.html()).toMatch(message);
15
+ });
16
+ it('should render with title and html message', () => {
17
+ const wrapper = shallow(/*#__PURE__*/React.createElement(HtmlContentDialog, {
18
+ title: title,
19
+ message: message,
20
+ actions: []
21
+ }));
22
+ expect(wrapper).toMatchSnapshot();
23
+ expect(wrapper.html()).toMatch(title);
24
+ });
25
+ it('should render with title, html message and messageParams', () => {
26
+ const wrapper = shallow(/*#__PURE__*/React.createElement(HtmlContentDialog, {
27
+ title: title,
28
+ message: "Message with {name}",
29
+ params: {
30
+ name: 'Placeholder'
31
+ },
32
+ actions: []
33
+ }));
34
+ expect(wrapper).toMatchSnapshot();
35
+ });
36
+ it('should render the actions', () => {
37
+ const actions = [{
38
+ label: 'fooAction',
39
+ action: () => {}
40
+ }];
41
+ const wrapper = shallow(/*#__PURE__*/React.createElement(HtmlContentDialog, {
42
+ title: title,
43
+ message: message,
44
+ actions: actions
45
+ }));
46
+ expect(wrapper).toMatchSnapshot();
47
+ expect(wrapper.html()).toMatch(actions[0].label);
48
+ });
49
+ it('should pass title through', () => {
50
+ const customTitle = /*#__PURE__*/React.createElement("div", null, "Title");
51
+ const wrapper = shallow(/*#__PURE__*/React.createElement(HtmlContentDialog, {
52
+ title: customTitle,
53
+ message: message,
54
+ params: {},
55
+ actions: []
56
+ }));
57
+ expect(wrapper.find('BasicDialog').prop('title')).toEqual(customTitle);
58
+ });
59
+ });
@@ -1,36 +1,125 @@
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 React,{Component}from'react';import PropTypes from'prop-types';import I18n from'@shopgate/pwa-common/components/I18n';import BasicDialog from"../BasicDialog";/**
1
+ import React, { Component } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import I18n from '@shopgate/pwa-common/components/I18n';
4
+ import BasicDialog from "../BasicDialog";
5
+
6
+ /**
2
7
  * The number of taps required until the dialog switches to/from developer mode.
3
- */var requiredTapsToSwitchModes=10;/**
8
+ */
9
+ const requiredTapsToSwitchModes = 10;
10
+
11
+ /**
4
12
  * The timeout between repeated tapping on the message (in ms).
5
- */var switchModeTapTimeout=4000/requiredTapsToSwitchModes;/**
13
+ */
14
+ const switchModeTapTimeout = 4000 / requiredTapsToSwitchModes;
15
+
16
+ /**
6
17
  * This component displays a pipeline error dialog.
7
18
  * The special behaviour of this message is that the user may tap the message body
8
19
  * ten times until it reveals additional information about the error that occurred.
9
- */var PipelineErrorDialog=/*#__PURE__*/function(_Component){/**
20
+ */
21
+ class PipelineErrorDialog extends Component {
22
+ /**
10
23
  * Creates the component.
11
24
  * @param {Object} props The component props.
12
- */function PipelineErrorDialog(props){var _this2;_classCallCheck(this,PipelineErrorDialog);_this2=_callSuper(this,PipelineErrorDialog,[props]);/**
13
- * Clears the tap counter once the
14
- */_defineProperty(_this2,"handleTapTimeout",function(){_this2.tapCounter=0;});/**
15
- * User tapped the message, increase the tap counter and switch view modes if required.
16
- */_defineProperty(_this2,"handleClick",function(){_this2.tapCounter+=1;if(_this2.tapTimeout){// Clear the timeout.
17
- clearTimeout(_this2.tapTimeout);}if(_this2.tapCounter>=requiredTapsToSwitchModes){// Switch modes and reset the tap counter.
18
- _this2.tapCounter=0;_this2.setState(function(_ref){var devMode=_ref.devMode;return{devMode:!devMode};});}else{_this2.tapTimeout=setTimeout(_this2.handleTapTimeout,switchModeTapTimeout);}});/**
19
- * Renders the error message in developer mode.
20
- * @returns {JSX}
21
- */_defineProperty(_this2,"renderDevErrorMessage",function(){/**
22
- * Checks the input to be truthy, "0" or "false" and enables it to be rendered then.
23
- * @param {Object|string|number|boolean} value The value to be checked if it should be rendered.
24
- * @returns {boolean}
25
- */var checkValue=function checkValue(value){return!!value||value===0||value===false;};var params=_this2.props.params;return React.createElement("div",{"aria-hidden":true},React.createElement("span",null,React.createElement("strong",null,"Pipeline:"),React.createElement("span",null," ".concat(params.pipeline)),React.createElement("br",null)),checkValue(params.entityId)&&React.createElement("span",null,React.createElement("strong",null,"Entity id:"),React.createElement("span",null," ".concat(params.entityId)),React.createElement("br",null)),checkValue(params.code)&&React.createElement("span",null,React.createElement("strong",null,"Code:"),React.createElement("span",null," ".concat(params.code)),React.createElement("br",null)),React.createElement("span",null,React.createElement("strong",null,"Message:"),React.createElement("span",null," ".concat(params.message)),React.createElement("br",null)),checkValue(params.translated)&&React.createElement("span",null,React.createElement("strong",null,"Message Translated:"),React.createElement("span",null," ".concat(params.translated.toString())),React.createElement("br",null)),checkValue(params.messageParams)&&React.createElement("p",null,React.createElement("strong",null,"Message Params:"),React.createElement("br",null),React.createElement("span",null,JSON.stringify(params.messageParams,null,' ')),React.createElement("br",null)),checkValue(params.request)&&React.createElement("p",null,React.createElement("strong",null,"Request Params:"),React.createElement("br",null),React.createElement("span",null,JSON.stringify(params.request,null,' ')),React.createElement("br",null)));});/**
26
- * Renders the regular error message in user mode.
27
- * @returns {JSX}
28
- */_defineProperty(_this2,"renderUserErrorMessage",function(){var _this2$props=_this2.props,_this2$props$message=_this2$props.message,message=_this2$props$message===void 0?'':_this2$props$message,_this2$props$params=_this2$props.params,params=_this2$props$params===void 0?{}:_this2$props$params;return React.createElement(React.Fragment,null,!!params.translated&&(message||params.message||React.createElement(I18n.Text,{string:"modal.body_error"})),!params.translated&&React.createElement(I18n.Text,{string:message||params.message||'modal.body_error',params:params.messageParams||{}}));});_this2.tapTimeout=null;_this2.tapCounter=0;_this2.state={devMode:false// Indicating whether we are in dev mode.
29
- };return _this2;}/**
25
+ */
26
+ constructor(props) {
27
+ super(props);
28
+ /**
29
+ * Clears the tap counter once the
30
+ */
31
+ this.handleTapTimeout = () => {
32
+ this.tapCounter = 0;
33
+ };
34
+ /**
35
+ * User tapped the message, increase the tap counter and switch view modes if required.
36
+ */
37
+ this.handleClick = () => {
38
+ this.tapCounter += 1;
39
+ if (this.tapTimeout) {
40
+ // Clear the timeout.
41
+ clearTimeout(this.tapTimeout);
42
+ }
43
+ if (this.tapCounter >= requiredTapsToSwitchModes) {
44
+ // Switch modes and reset the tap counter.
45
+ this.tapCounter = 0;
46
+ this.setState(({
47
+ devMode
48
+ }) => ({
49
+ devMode: !devMode
50
+ }));
51
+ } else {
52
+ this.tapTimeout = setTimeout(this.handleTapTimeout, switchModeTapTimeout);
53
+ }
54
+ };
55
+ /**
56
+ * Renders the error message in developer mode.
57
+ * @returns {JSX}
58
+ */
59
+ this.renderDevErrorMessage = () => {
60
+ /**
61
+ * Checks the input to be truthy, "0" or "false" and enables it to be rendered then.
62
+ * @param {Object|string|number|boolean} value The value to be checked if it should be rendered.
63
+ * @returns {boolean}
64
+ */
65
+ const checkValue = value => !!value || value === 0 || value === false;
66
+ const {
67
+ params
68
+ } = this.props;
69
+ return /*#__PURE__*/React.createElement("div", {
70
+ "aria-hidden": true
71
+ }, /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement("strong", null, "Pipeline:"), /*#__PURE__*/React.createElement("span", null, ` ${params.pipeline}`), /*#__PURE__*/React.createElement("br", null)), checkValue(params.entityId) && /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement("strong", null, "Entity id:"), /*#__PURE__*/React.createElement("span", null, ` ${params.entityId}`), /*#__PURE__*/React.createElement("br", null)), checkValue(params.code) && /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement("strong", null, "Code:"), /*#__PURE__*/React.createElement("span", null, ` ${params.code}`), /*#__PURE__*/React.createElement("br", null)), /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement("strong", null, "Message:"), /*#__PURE__*/React.createElement("span", null, ` ${params.message}`), /*#__PURE__*/React.createElement("br", null)), checkValue(params.translated) && /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement("strong", null, "Message Translated:"), /*#__PURE__*/React.createElement("span", null, ` ${params.translated.toString()}`), /*#__PURE__*/React.createElement("br", null)), checkValue(params.messageParams) && /*#__PURE__*/React.createElement("p", null, /*#__PURE__*/React.createElement("strong", null, "Message Params:"), /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("span", null, JSON.stringify(params.messageParams, null, ' ')), /*#__PURE__*/React.createElement("br", null)), checkValue(params.request) && /*#__PURE__*/React.createElement("p", null, /*#__PURE__*/React.createElement("strong", null, "Request Params:"), /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("span", null, JSON.stringify(params.request, null, ' ')), /*#__PURE__*/React.createElement("br", null)));
72
+ };
73
+ /**
74
+ * Renders the regular error message in user mode.
75
+ * @returns {JSX}
76
+ */
77
+ this.renderUserErrorMessage = () => {
78
+ const {
79
+ message = '',
80
+ params = {}
81
+ } = this.props;
82
+ return /*#__PURE__*/React.createElement(React.Fragment, null, !!params.translated && (message || params.message || /*#__PURE__*/React.createElement(I18n.Text, {
83
+ string: "modal.body_error"
84
+ })), !params.translated && /*#__PURE__*/React.createElement(I18n.Text, {
85
+ string: message || params.message || 'modal.body_error',
86
+ params: params.messageParams || {}
87
+ }));
88
+ };
89
+ this.tapTimeout = null;
90
+ this.tapCounter = 0;
91
+ this.state = {
92
+ devMode: false // Indicating whether we are in dev mode.
93
+ };
94
+ }
95
+
96
+ /**
30
97
  * @return {string} The title based on the current state of the dialog.
31
- */_inherits(PipelineErrorDialog,_Component);return _createClass(PipelineErrorDialog,[{key:"title",get:function get(){return this.state.devMode?'Pipeline Error':'modal.title_error';}/**
98
+ */
99
+ get title() {
100
+ return this.state.devMode ? 'Pipeline Error' : 'modal.title_error';
101
+ }
102
+
103
+ /**
32
104
  * @return {JSX} The content component based on the the current state of the dialog.
33
- */},{key:"content",get:function get(){return this.state.devMode?this.renderDevErrorMessage():this.renderUserErrorMessage();}},{key:"render",value:/**
105
+ */
106
+ get content() {
107
+ return this.state.devMode ? this.renderDevErrorMessage() : this.renderUserErrorMessage();
108
+ }
109
+ /**
34
110
  * Renders the error message depending on the current mode.
35
111
  * @return {JSX}
36
- */function render(){return React.createElement(BasicDialog,{title:this.title,actions:this.props.actions},React.createElement("div",{onClick:this.handleClick},this.content));}}]);}(Component);_defineProperty(PipelineErrorDialog,"defaultProps",{message:''});export default PipelineErrorDialog;
112
+ */
113
+ render() {
114
+ return /*#__PURE__*/React.createElement(BasicDialog, {
115
+ title: this.title,
116
+ actions: this.props.actions
117
+ }, /*#__PURE__*/React.createElement("div", {
118
+ onClick: this.handleClick
119
+ }, this.content));
120
+ }
121
+ }
122
+ PipelineErrorDialog.defaultProps = {
123
+ message: ''
124
+ };
125
+ export default PipelineErrorDialog;
@@ -1,14 +1,94 @@
1
- import React from'react';import{mount}from'enzyme';import PipelineErrorDialog from"./index";jest.mock('@shopgate/engage/a11y/components');describe('<PipelineErrorDialog />',function(){var defaultParams={code:'123',message:'Error message',pipeline:'fakePipeline',request:{}};it('should render with minimal props',function(){var wrapper=mount(React.createElement(PipelineErrorDialog,{actions:[],params:defaultParams}));expect(wrapper).toMatchSnapshot();});it('should show a custom message if a message is is provided',function(){var message='Custom message';var wrapper=mount(React.createElement(PipelineErrorDialog,{actions:[],message:message,params:defaultParams}));expect(wrapper).toMatchSnapshot();expect(wrapper.html()).toMatch(message);});it('should switch modes on tap',function(){var wrapper=mount(React.createElement(PipelineErrorDialog,{actions:[],params:defaultParams}));var numTaps=10;var clickElement=wrapper.find('div[onClick]');// Dev mode should be disabled.
2
- for(var i=0;i<numTaps;i+=1){expect(wrapper.state().devMode).toBe(false);clickElement.simulate('click');}// Dev mode should be enabled.
3
- for(var _i2=0;_i2<numTaps;_i2+=1){expect(wrapper.state().devMode).toBe(true);clickElement.simulate('click');}// Dev mode should be disabled again.
4
- expect(wrapper.state().devMode).toBe(false);});it('should not switch modes if tapped too slow',function(){jest.useFakeTimers();var wrapper=mount(React.createElement(PipelineErrorDialog,{actions:[],params:defaultParams}));var numTaps=10;var numTapsUntilTimeout=Math.round(numTaps/2);var clickElement=wrapper.find('div[onClick]');// Dev mode should be disabled.
5
- expect(wrapper.state().devMode).toBe(false);/**
1
+ import React from 'react';
2
+ import { mount } from 'enzyme';
3
+ import PipelineErrorDialog from "./index";
4
+ jest.mock('@shopgate/engage/a11y/components');
5
+ describe('<PipelineErrorDialog />', () => {
6
+ const defaultParams = {
7
+ code: '123',
8
+ message: 'Error message',
9
+ pipeline: 'fakePipeline',
10
+ request: {}
11
+ };
12
+ it('should render with minimal props', () => {
13
+ const wrapper = mount(/*#__PURE__*/React.createElement(PipelineErrorDialog, {
14
+ actions: [],
15
+ params: defaultParams
16
+ }));
17
+ expect(wrapper).toMatchSnapshot();
18
+ });
19
+ it('should show a custom message if a message is is provided', () => {
20
+ const message = 'Custom message';
21
+ const wrapper = mount(/*#__PURE__*/React.createElement(PipelineErrorDialog, {
22
+ actions: [],
23
+ message: message,
24
+ params: defaultParams
25
+ }));
26
+ expect(wrapper).toMatchSnapshot();
27
+ expect(wrapper.html()).toMatch(message);
28
+ });
29
+ it('should switch modes on tap', () => {
30
+ const wrapper = mount(/*#__PURE__*/React.createElement(PipelineErrorDialog, {
31
+ actions: [],
32
+ params: defaultParams
33
+ }));
34
+ const numTaps = 10;
35
+ const clickElement = wrapper.find('div[onClick]');
36
+
37
+ // Dev mode should be disabled.
38
+ for (let i = 0; i < numTaps; i += 1) {
39
+ expect(wrapper.state().devMode).toBe(false);
40
+ clickElement.simulate('click');
41
+ }
42
+
43
+ // Dev mode should be enabled.
44
+ for (let i = 0; i < numTaps; i += 1) {
45
+ expect(wrapper.state().devMode).toBe(true);
46
+ clickElement.simulate('click');
47
+ }
48
+
49
+ // Dev mode should be disabled again.
50
+ expect(wrapper.state().devMode).toBe(false);
51
+ });
52
+ it('should not switch modes if tapped too slow', () => {
53
+ jest.useFakeTimers();
54
+ const wrapper = mount(/*#__PURE__*/React.createElement(PipelineErrorDialog, {
55
+ actions: [],
56
+ params: defaultParams
57
+ }));
58
+ const numTaps = 10;
59
+ const numTapsUntilTimeout = Math.round(numTaps / 2);
60
+ const clickElement = wrapper.find('div[onClick]');
61
+
62
+ // Dev mode should be disabled.
63
+ expect(wrapper.state().devMode).toBe(false);
64
+
65
+ /**
6
66
  * Simulates multiple tap events.
7
67
  * @param {number} amount The number of tap events to simulate in a row.
8
- */var tapOnElement=function tapOnElement(amount){if(amount>0){clickElement.simulate('click');tapOnElement(amount-1);}};// Tap a few times.
9
- tapOnElement(numTapsUntilTimeout);// Trigger a timeout (user was too slow).
10
- jest.runAllTimers();// Tap the remaining times.
11
- tapOnElement(numTaps-numTapsUntilTimeout);// We timed out and should not be in dev mode by now.
12
- expect(wrapper.state().devMode).toBe(false);// Add the remaining amount of taps to enter dev mode.
13
- tapOnElement(numTapsUntilTimeout);// This time dev mode should be enabled.
14
- expect(wrapper.state().devMode).toBe(true);});});
68
+ */
69
+ const tapOnElement = amount => {
70
+ if (amount > 0) {
71
+ clickElement.simulate('click');
72
+ tapOnElement(amount - 1);
73
+ }
74
+ };
75
+
76
+ // Tap a few times.
77
+ tapOnElement(numTapsUntilTimeout);
78
+
79
+ // Trigger a timeout (user was too slow).
80
+ jest.runAllTimers();
81
+
82
+ // Tap the remaining times.
83
+ tapOnElement(numTaps - numTapsUntilTimeout);
84
+
85
+ // We timed out and should not be in dev mode by now.
86
+ expect(wrapper.state().devMode).toBe(false);
87
+
88
+ // Add the remaining amount of taps to enter dev mode.
89
+ tapOnElement(numTapsUntilTimeout);
90
+
91
+ // This time dev mode should be enabled.
92
+ expect(wrapper.state().devMode).toBe(true);
93
+ });
94
+ });
@@ -1,6 +1,32 @@
1
- import React from'react';import PropTypes from'prop-types';import I18n from'@shopgate/pwa-common/components/I18n';import{i18n,nl2br}from'@shopgate/engage/core';import BasicDialog from"../BasicDialog";/**
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import I18n from '@shopgate/pwa-common/components/I18n';
4
+ import { i18n, nl2br } from '@shopgate/engage/core';
5
+ import BasicDialog from "../BasicDialog";
6
+
7
+ /**
2
8
  * Renders a simple dialog with a title and a text message.
3
9
  * This is the default dialog if no type has been specified.
4
10
  * @param {Object} props The component properties.
5
11
  * @returns {JSX} The rendered component.
6
- */var TextMessageDialog=function TextMessageDialog(_ref){var actions=_ref.actions,message=_ref.message,title=_ref.title,params=_ref.params,children=_ref.children;return React.createElement(BasicDialog,{title:title,actions:actions},React.createElement("span",{dangerouslySetInnerHTML:{__html:nl2br(i18n.text(message,params))}}),children);};TextMessageDialog.defaultProps={title:BasicDialog.defaultProps.title,params:I18n.Text.defaultProps.params,children:null};export default TextMessageDialog;
12
+ */
13
+ const TextMessageDialog = ({
14
+ actions,
15
+ message,
16
+ title,
17
+ params,
18
+ children
19
+ }) => /*#__PURE__*/React.createElement(BasicDialog, {
20
+ title: title,
21
+ actions: actions
22
+ }, /*#__PURE__*/React.createElement("span", {
23
+ dangerouslySetInnerHTML: {
24
+ __html: nl2br(i18n.text(message, params))
25
+ }
26
+ }), children);
27
+ TextMessageDialog.defaultProps = {
28
+ title: BasicDialog.defaultProps.title,
29
+ params: I18n.Text.defaultProps.params,
30
+ children: null
31
+ };
32
+ export default TextMessageDialog;
@@ -1 +1,59 @@
1
- import React from'react';import{shallow}from'enzyme';import TextMessageDialog from"./index";var message='This is the message.';var title='This is the title.';jest.mock('@shopgate/engage/a11y/components');describe('<TextMessageDialog />',function(){it('should render with minimal props',function(){var wrapper=shallow(React.createElement(TextMessageDialog,{message:message,actions:[]}));expect(wrapper).toMatchSnapshot();expect(wrapper.html()).toMatch(message);});it('should render with title and message',function(){var wrapper=shallow(React.createElement(TextMessageDialog,{title:title,message:message,actions:[]}));expect(wrapper).toMatchSnapshot();expect(wrapper.html()).toMatch(title);});it('should render with title, message and messageParams',function(){var wrapper=shallow(React.createElement(TextMessageDialog,{title:title,message:"Message with {name}",params:{name:'Placeholder'},actions:[]}));expect(wrapper).toMatchSnapshot();});it('should render the actions',function(){var actions=[{label:'fooAction',action:function action(){}}];var wrapper=shallow(React.createElement(TextMessageDialog,{title:title,message:message,actions:actions}));expect(wrapper).toMatchSnapshot();expect(wrapper.html()).toMatch(actions[0].label);});it('should pass title through',function(){var customTitle=React.createElement("div",null,"Title");var wrapper=shallow(React.createElement(TextMessageDialog,{title:customTitle,message:message,params:{},actions:[]}));expect(wrapper.find('BasicDialog').prop('title')).toEqual(customTitle);});});
1
+ import React from 'react';
2
+ import { shallow } from 'enzyme';
3
+ import TextMessageDialog from "./index";
4
+ const message = 'This is the message.';
5
+ const title = 'This is the title.';
6
+ jest.mock('@shopgate/engage/a11y/components');
7
+ describe('<TextMessageDialog />', () => {
8
+ it('should render with minimal props', () => {
9
+ const wrapper = shallow(/*#__PURE__*/React.createElement(TextMessageDialog, {
10
+ message: message,
11
+ actions: []
12
+ }));
13
+ expect(wrapper).toMatchSnapshot();
14
+ expect(wrapper.html()).toMatch(message);
15
+ });
16
+ it('should render with title and message', () => {
17
+ const wrapper = shallow(/*#__PURE__*/React.createElement(TextMessageDialog, {
18
+ title: title,
19
+ message: message,
20
+ actions: []
21
+ }));
22
+ expect(wrapper).toMatchSnapshot();
23
+ expect(wrapper.html()).toMatch(title);
24
+ });
25
+ it('should render with title, message and messageParams', () => {
26
+ const wrapper = shallow(/*#__PURE__*/React.createElement(TextMessageDialog, {
27
+ title: title,
28
+ message: "Message with {name}",
29
+ params: {
30
+ name: 'Placeholder'
31
+ },
32
+ actions: []
33
+ }));
34
+ expect(wrapper).toMatchSnapshot();
35
+ });
36
+ it('should render the actions', () => {
37
+ const actions = [{
38
+ label: 'fooAction',
39
+ action: () => {}
40
+ }];
41
+ const wrapper = shallow(/*#__PURE__*/React.createElement(TextMessageDialog, {
42
+ title: title,
43
+ message: message,
44
+ actions: actions
45
+ }));
46
+ expect(wrapper).toMatchSnapshot();
47
+ expect(wrapper.html()).toMatch(actions[0].label);
48
+ });
49
+ it('should pass title through', () => {
50
+ const customTitle = /*#__PURE__*/React.createElement("div", null, "Title");
51
+ const wrapper = shallow(/*#__PURE__*/React.createElement(TextMessageDialog, {
52
+ title: customTitle,
53
+ message: message,
54
+ params: {},
55
+ actions: []
56
+ }));
57
+ expect(wrapper.find('BasicDialog').prop('title')).toEqual(customTitle);
58
+ });
59
+ });
@@ -1,5 +1,14 @@
1
- import{connect}from'react-redux';import{historyPush}from'@shopgate/pwa-common/actions/router';/**
1
+ import { connect } from 'react-redux';
2
+ import { historyPush } from '@shopgate/pwa-common/actions/router';
3
+
4
+ /**
2
5
  * Connects the dispatch function to a callable function in the props.
3
6
  * @param {Function} dispatch The redux dispatch function.
4
7
  * @return {Object} The extended component props.
5
- */var mapDispatchToProps=function mapDispatchToProps(dispatch){return{navigate:function navigate(pathname){return dispatch(historyPush({pathname:pathname}));}};};export default connect(null,mapDispatchToProps);
8
+ */
9
+ const mapDispatchToProps = dispatch => ({
10
+ navigate: pathname => dispatch(historyPush({
11
+ pathname
12
+ }))
13
+ });
14
+ export default connect(null, mapDispatchToProps);
@@ -1,14 +1,50 @@
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 React from'react';import PropTypes from'prop-types';import I18n from'@shopgate/pwa-common/components/I18n';import{ITEM_PATH}from'@shopgate/pwa-common-commerce/product/constants';import{bin2hex}from'@shopgate/pwa-common/helpers/data';import BasicDialog from"../BasicDialog";import connect from"./connector";/**
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import I18n from '@shopgate/pwa-common/components/I18n';
4
+ import { ITEM_PATH } from '@shopgate/pwa-common-commerce/product/constants';
5
+ import { bin2hex } from '@shopgate/pwa-common/helpers/data';
6
+ import BasicDialog from "../BasicDialog";
7
+ import connect from "./connector";
8
+
9
+ /**
2
10
  * Reorders the actions for the modal so that the confirmation button will be rendered last.
3
11
  * Also attaches a navigation action to the confirmation action.
4
12
  * @param {Array} actions The confirm and dismiss actions.
5
13
  * @param {string} productId The product id passed through params.
6
14
  * @param {string} navigate The navigate action.
7
15
  * @return {Array} Reordered and extended actions.
8
- */var reorderActions=function reorderActions(actions,_ref,navigate){var productId=_ref.productId;var confirmAction;var orderedActions=actions;orderedActions.forEach(function(act,index){if(act.action.name!=='onConfirm'){return;}confirmAction=_extends({},act,{action:function action(){// Execute default action
9
- act.action();// Navigate to product details page
10
- if(productId){navigate("".concat(ITEM_PATH,"/").concat(bin2hex(productId)));}}});orderedActions.splice(index,1);});// Push the confirm action last so that we have the button rendered at the bottom right of modal.
11
- if(confirmAction){orderedActions.push(confirmAction);}return orderedActions;};/**
16
+ */
17
+ const reorderActions = (actions, {
18
+ productId
19
+ }, navigate) => {
20
+ let confirmAction;
21
+ const orderedActions = actions;
22
+ orderedActions.forEach((act, index) => {
23
+ if (act.action.name !== 'onConfirm') {
24
+ return;
25
+ }
26
+ confirmAction = {
27
+ ...act,
28
+ action: () => {
29
+ // Execute default action
30
+ act.action();
31
+ // Navigate to product details page
32
+ if (productId) {
33
+ navigate(`${ITEM_PATH}/${bin2hex(productId)}`);
34
+ }
35
+ }
36
+ };
37
+ orderedActions.splice(index, 1);
38
+ });
39
+
40
+ // Push the confirm action last so that we have the button rendered at the bottom right of modal.
41
+ if (confirmAction) {
42
+ orderedActions.push(confirmAction);
43
+ }
44
+ return orderedActions;
45
+ };
46
+
47
+ /**
12
48
  * Renders a simple dialog with a title and a text message.
13
49
  * @param {Array} actions The modal button actions.
14
50
  * @param {string} message The modal message.
@@ -16,4 +52,27 @@ if(confirmAction){orderedActions.push(confirmAction);}return orderedActions;};/*
16
52
  * @param {Object} params The modal params.
17
53
  * @return {JSX} The rendered component.
18
54
  * @constructor
19
- */var VariantSelectModal=function VariantSelectModal(_ref2){var actions=_ref2.actions,message=_ref2.message,navigate=_ref2.navigate,title=_ref2.title,params=_ref2.params;var parsedActions=reorderActions(actions,params,navigate);return React.createElement(BasicDialog,{title:title,actions:parsedActions},React.createElement(I18n.Text,{string:message}));};VariantSelectModal.defaultProps={params:{productId:null},title:BasicDialog.defaultProps.title};export default connect(VariantSelectModal);export{VariantSelectModal as UnwrappedVariantSelectModal};
55
+ */
56
+ const VariantSelectModal = ({
57
+ actions,
58
+ message,
59
+ navigate,
60
+ title,
61
+ params
62
+ }) => {
63
+ const parsedActions = reorderActions(actions, params, navigate);
64
+ return /*#__PURE__*/React.createElement(BasicDialog, {
65
+ title: title,
66
+ actions: parsedActions
67
+ }, /*#__PURE__*/React.createElement(I18n.Text, {
68
+ string: message
69
+ }));
70
+ };
71
+ VariantSelectModal.defaultProps = {
72
+ params: {
73
+ productId: null
74
+ },
75
+ title: BasicDialog.defaultProps.title
76
+ };
77
+ export default connect(VariantSelectModal);
78
+ export { VariantSelectModal as UnwrappedVariantSelectModal };