@shopgate/pwa-ui-shared 7.30.0-alpha.7 → 7.30.0-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +63 -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 +65 -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 +308 -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 +40 -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,6 +1,124 @@
1
- import React from'react';import{Provider}from'react-redux';import configureStore from'redux-mock-store';import{mount}from'enzyme';import mockRenderOptions from'@shopgate/pwa-common/helpers/mocks/mockRenderOptions';import appConfig from'@shopgate/pwa-common/helpers/config';import FavoritesButton from"./index";import{mockedStateEmpty,mockedStateOnList,mockedStateNotOnList}from"./mock";var mockedStore=configureStore();var dispatcher=jest.fn();jest.mock('@shopgate/pwa-common/helpers/config');jest.mock('@shopgate/pwa-common-commerce/favorites/selectors/index',function(){return{isFetching:function isFetching(){return false;}};});beforeEach(function(){jest.resetModules();});describe('<FavoritesButton />',function(){var component=null;/**
1
+ import React from 'react';
2
+ import { Provider } from 'react-redux';
3
+ import configureStore from 'redux-mock-store';
4
+ import { mount } from 'enzyme';
5
+ import mockRenderOptions from '@shopgate/pwa-common/helpers/mocks/mockRenderOptions';
6
+ import appConfig from '@shopgate/pwa-common/helpers/config';
7
+ import FavoritesButton from "./index";
8
+ import { mockedStateEmpty, mockedStateOnList, mockedStateNotOnList } from "./mock";
9
+ const mockedStore = configureStore();
10
+ const dispatcher = jest.fn();
11
+ jest.mock('@shopgate/pwa-common/helpers/config');
12
+ jest.mock('@shopgate/pwa-common-commerce/favorites/selectors/index', () => ({
13
+ isFetching: () => false
14
+ }));
15
+ beforeEach(() => {
16
+ jest.resetModules();
17
+ });
18
+ describe('<FavoritesButton />', () => {
19
+ let component = null;
20
+
21
+ /**
2
22
  * Creates component with provided store state.
3
23
  * @param {Object} mockedState Mocked stage.
4
24
  * @param {Object} props Additional props.
5
25
  * @return {ReactWrapper}
6
- */var createComponent=function createComponent(mockedState){var props=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{active:false};var store=mockedStore(mockedState);store.dispatch=dispatcher;return mount(React.createElement(Provider,{store:store},React.createElement(FavoritesButton,props)),mockRenderOptions);};beforeEach(function(){dispatcher.mockReset();});it('should only render when no favorites set',function(){component=createComponent(mockedStateEmpty);expect(component).toMatchSnapshot();expect(component.find('Heart').exists()).toBe(false);expect(component.find('HeartOutline').exists()).toBe(true);component.find('button').simulate('click');});it('should render when favorites set',function(){component=createComponent(mockedStateOnList,{active:true});expect(component).toMatchSnapshot();expect(component.find('Heart').exists()).toBe(true);expect(component.find('HeartOutline').exists()).toBe(false);});it('should add to favorites on click',function(){component=createComponent(mockedStateNotOnList,{productId:'1',active:false});expect(component.find('Heart').exists()).toBe(false);expect(component.find('HeartOutline').exists()).toBe(true);component.find('button').simulate('click');component.update();expect(dispatcher).toHaveBeenCalled();});it('should remove from favorites on click',function(done){component=createComponent(mockedStateOnList,{productId:'1',active:true});expect(component.find('Heart').exists()).toBe(true);expect(component.find('HeartOutline').exists()).toBe(false);component.find('button').simulate('click');component.update();setTimeout(function(){expect(dispatcher).toHaveBeenCalled();done();},0);});it('should process ripple complete callback',function(){var onRippleComplete=jest.fn();component=createComponent(mockedStateOnList,{productId:'1',active:true,onRippleComplete:onRippleComplete});component.find('Ripple').instance().props.onComplete();component.update();expect(onRippleComplete).toHaveBeenCalled();});it('should only react on first click',function(done){component=createComponent(mockedStateOnList,{once:true,productId:'1',active:false});component.find('button').simulate('click');component.update();component.find('button').simulate('click');component.update();setTimeout(function(){expect(dispatcher.mock.calls.length).toBe(1);done();},1);});it('should only react on both clicks',function(done){component=createComponent(mockedStateOnList,{productId:'1',active:false});component.find('button').simulate('click');component.update();component.find('button').simulate('click');component.update();setTimeout(function(){expect(dispatcher.mock.calls.length).toBe(2);done();},1);});it('should render null when feature flag is off',function(){jest.spyOn(appConfig,'hasFavorites','get').mockReturnValue(false);component=createComponent(mockedStateOnList);expect(component.isEmptyRender()).toBe(true);});});
26
+ */
27
+ const createComponent = (mockedState, props = {
28
+ active: false
29
+ }) => {
30
+ const store = mockedStore(mockedState);
31
+ store.dispatch = dispatcher;
32
+ return mount(/*#__PURE__*/React.createElement(Provider, {
33
+ store: store
34
+ }, /*#__PURE__*/React.createElement(FavoritesButton, props)), mockRenderOptions);
35
+ };
36
+ beforeEach(() => {
37
+ dispatcher.mockReset();
38
+ });
39
+ it('should only render when no favorites set', () => {
40
+ component = createComponent(mockedStateEmpty);
41
+ expect(component).toMatchSnapshot();
42
+ expect(component.find('Heart').exists()).toBe(false);
43
+ expect(component.find('HeartOutline').exists()).toBe(true);
44
+ component.find('button').simulate('click');
45
+ });
46
+ it('should render when favorites set', () => {
47
+ component = createComponent(mockedStateOnList, {
48
+ active: true
49
+ });
50
+ expect(component).toMatchSnapshot();
51
+ expect(component.find('Heart').exists()).toBe(true);
52
+ expect(component.find('HeartOutline').exists()).toBe(false);
53
+ });
54
+ it('should add to favorites on click', () => {
55
+ component = createComponent(mockedStateNotOnList, {
56
+ productId: '1',
57
+ active: false
58
+ });
59
+ expect(component.find('Heart').exists()).toBe(false);
60
+ expect(component.find('HeartOutline').exists()).toBe(true);
61
+ component.find('button').simulate('click');
62
+ component.update();
63
+ expect(dispatcher).toHaveBeenCalled();
64
+ });
65
+ it('should remove from favorites on click', done => {
66
+ component = createComponent(mockedStateOnList, {
67
+ productId: '1',
68
+ active: true
69
+ });
70
+ expect(component.find('Heart').exists()).toBe(true);
71
+ expect(component.find('HeartOutline').exists()).toBe(false);
72
+ component.find('button').simulate('click');
73
+ component.update();
74
+ setTimeout(() => {
75
+ expect(dispatcher).toHaveBeenCalled();
76
+ done();
77
+ }, 0);
78
+ });
79
+ it('should process ripple complete callback', () => {
80
+ const onRippleComplete = jest.fn();
81
+ component = createComponent(mockedStateOnList, {
82
+ productId: '1',
83
+ active: true,
84
+ onRippleComplete
85
+ });
86
+ component.find('Ripple').instance().props.onComplete();
87
+ component.update();
88
+ expect(onRippleComplete).toHaveBeenCalled();
89
+ });
90
+ it('should only react on first click', done => {
91
+ component = createComponent(mockedStateOnList, {
92
+ once: true,
93
+ productId: '1',
94
+ active: false
95
+ });
96
+ component.find('button').simulate('click');
97
+ component.update();
98
+ component.find('button').simulate('click');
99
+ component.update();
100
+ setTimeout(() => {
101
+ expect(dispatcher.mock.calls.length).toBe(1);
102
+ done();
103
+ }, 1);
104
+ });
105
+ it('should only react on both clicks', done => {
106
+ component = createComponent(mockedStateOnList, {
107
+ productId: '1',
108
+ active: false
109
+ });
110
+ component.find('button').simulate('click');
111
+ component.update();
112
+ component.find('button').simulate('click');
113
+ component.update();
114
+ setTimeout(() => {
115
+ expect(dispatcher.mock.calls.length).toBe(2);
116
+ done();
117
+ }, 1);
118
+ });
119
+ it('should render null when feature flag is off', () => {
120
+ jest.spyOn(appConfig, 'hasFavorites', 'get').mockReturnValue(false);
121
+ component = createComponent(mockedStateOnList);
122
+ expect(component.isEmptyRender()).toBe(true);
123
+ });
124
+ });
@@ -1 +1,26 @@
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{themeShadows,themeColors}from'@shopgate/pwa-common/helpers/config';var buttonProto={display:'block',position:'relative',background:themeColors.light,borderRadius:'50%',padding:0,fontSize:20,lineHeight:1,color:"var(--color-secondary, ".concat(themeColors.accent,")"),outline:0};var buttonFlat=css(buttonProto).toString();var button=css(_extends({},buttonProto,{boxShadow:themeShadows.buttons.elevated})).toString();var ripple=css({padding:6}).toString();export default{buttonFlat:buttonFlat,button:button,ripple:ripple};
1
+ import { css } from 'glamor';
2
+ import { themeShadows, themeColors } from '@shopgate/pwa-common/helpers/config';
3
+ const buttonProto = {
4
+ display: 'block',
5
+ position: 'relative',
6
+ background: themeColors.light,
7
+ borderRadius: '50%',
8
+ padding: 0,
9
+ fontSize: 20,
10
+ lineHeight: 1,
11
+ color: `var(--color-secondary, ${themeColors.accent})`,
12
+ outline: 0
13
+ };
14
+ const buttonFlat = css(buttonProto).toString();
15
+ const button = css({
16
+ ...buttonProto,
17
+ boxShadow: themeShadows.buttons.elevated
18
+ }).toString();
19
+ const ripple = css({
20
+ padding: 6
21
+ }).toString();
22
+ export default {
23
+ buttonFlat,
24
+ button,
25
+ ripple
26
+ };
@@ -1,10 +1,44 @@
1
- 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;}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{logger}from'@shopgate/pwa-core/helpers';import iso3166 from"../iso-3166-2";/**
1
+ import "core-js/modules/es.array.reduce.js";
2
+ import { logger } from '@shopgate/pwa-core/helpers';
3
+ import iso3166 from "../iso-3166-2";
4
+
5
+ /**
2
6
  * Get country list for
3
7
  * @param {Object} countryElement Configuration of which form fields to render
4
8
  * @param {?Object} optional object to prepend optional choice
5
9
  * @return {Object}
6
- */export default(function(countryElement){var optional=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;// Check validity of the country element options list "countries"
7
- if(countryElement.countries!==null&&countryElement.countries!==undefined&&!Array.isArray(countryElement.countries)){logger.error("Error: Invalid property type 'countries' in element "+"'".concat(countryElement.id,"'. Must be 'array', 'null' or 'undefined'"));return{};}// Build country display list for the country element (whitelist)
8
- // For 'null', 'undefined' and '[]' it shows all countries
9
- var countryKeys;if(countryElement.countries.length>0){countryKeys=countryElement.countries;}else{countryKeys=Object.keys(iso3166);}var countryList=countryKeys.reduce(function(reducer,countryCode){if(!iso3166[countryCode]){logger.error("Error: unknown country code [".concat(countryCode,"]"));return reducer;}return _extends({},reducer,_defineProperty({},countryCode,iso3166[countryCode].name));},{});// Add a "no selection" element
10
- if(countryElement.required){return countryList;}return _extends({},optional,{},countryList);});
10
+ */
11
+ export default (countryElement, optional = null) => {
12
+ // Check validity of the country element options list "countries"
13
+ if (countryElement.countries !== null && countryElement.countries !== undefined && !Array.isArray(countryElement.countries)) {
14
+ logger.error("Error: Invalid property type 'countries' in element " + `'${countryElement.id}'. Must be 'array', 'null' or 'undefined'`);
15
+ return {};
16
+ }
17
+ // Build country display list for the country element (whitelist)
18
+ // For 'null', 'undefined' and '[]' it shows all countries
19
+ let countryKeys;
20
+ if (countryElement.countries.length > 0) {
21
+ countryKeys = countryElement.countries;
22
+ } else {
23
+ countryKeys = Object.keys(iso3166);
24
+ }
25
+ const countryList = countryKeys.reduce((reducer, countryCode) => {
26
+ if (!iso3166[countryCode]) {
27
+ logger.error(`Error: unknown country code [${countryCode}]`);
28
+ return reducer;
29
+ }
30
+ return {
31
+ ...reducer,
32
+ [countryCode]: iso3166[countryCode].name
33
+ };
34
+ }, {});
35
+
36
+ // Add a "no selection" element
37
+ if (countryElement.required) {
38
+ return countryList;
39
+ }
40
+ return {
41
+ ...optional,
42
+ ...countryList
43
+ };
44
+ };
@@ -1,10 +1,39 @@
1
- function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance");}function _iterableToArrayLimit(arr,i){var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[Symbol.iterator](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"]!=null)_i["return"]();}finally{if(_d)throw _e;}}return _arr;}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr;}import{ELEMENT_TYPE_CHECKBOX,ELEMENT_TYPE_SELECT}from"../elementTypes";/**
1
+ import { ELEMENT_TYPE_CHECKBOX, ELEMENT_TYPE_SELECT } from "../elementTypes";
2
+
3
+ /**
2
4
  * Prepare state of formData for form builder
3
5
  * @param {Object} formElements form elements
4
6
  * @param {Object} defaults form defaults
5
7
  * @returns {Object}
6
- */export default(function(){var formElements=arguments.length>0&&arguments[0]!==undefined?arguments[0]:[];var defaults=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var formDefaults={};// Take only those defaults from props, that are actually represented by an element
7
- formElements.forEach(function(element){var defaultState=element.type===ELEMENT_TYPE_CHECKBOX?false:'';if(element.type===ELEMENT_TYPE_SELECT&&!element["default"]){var _Object$keys=Object.keys(element.options);var _Object$keys2=_slicedToArray(_Object$keys,1);defaultState=_Object$keys2[0];}// Use default from element config as a base
8
- if(element["default"]!==undefined&&element["default"]!==null){defaultState=element["default"];}// Take defaults from "customAttributes" property or from the higher level, based on element
9
- if(element.custom&&defaults.customAttributes!==undefined){if(defaults.customAttributes[element.id]!==undefined){defaultState=defaults.customAttributes[element.id];}}else if(!element.custom&&defaults[element.id]!==undefined){defaultState=defaults[element.id];}// Save default into the form state and into defaults property if one was set
10
- if(defaultState!==undefined){formDefaults[element.id]=defaultState;}});return formDefaults;});
8
+ */
9
+ export default (formElements = [], defaults = {}) => {
10
+ const formDefaults = {};
11
+
12
+ // Take only those defaults from props, that are actually represented by an element
13
+ formElements.forEach(element => {
14
+ let defaultState = element.type === ELEMENT_TYPE_CHECKBOX ? false : '';
15
+ if (element.type === ELEMENT_TYPE_SELECT && !element.default) {
16
+ [defaultState] = Object.keys(element.options);
17
+ }
18
+
19
+ // Use default from element config as a base
20
+ if (element.default !== undefined && element.default !== null) {
21
+ defaultState = element.default;
22
+ }
23
+
24
+ // Take defaults from "customAttributes" property or from the higher level, based on element
25
+ if (element.custom && defaults.customAttributes !== undefined) {
26
+ if (defaults.customAttributes[element.id] !== undefined) {
27
+ defaultState = defaults.customAttributes[element.id];
28
+ }
29
+ } else if (!element.custom && defaults[element.id] !== undefined) {
30
+ defaultState = defaults[element.id];
31
+ }
32
+
33
+ // Save default into the form state and into defaults property if one was set
34
+ if (defaultState !== undefined) {
35
+ formDefaults[element.id] = defaultState;
36
+ }
37
+ });
38
+ return formDefaults;
39
+ };
@@ -1,4 +1,10 @@
1
- var _excluded=["custom"];function _objectWithoutProperties(source,excluded){if(source==null)return{};var target=_objectWithoutPropertiesLoose(source,excluded);var key,i;if(Object.getOwnPropertySymbols){var sourceSymbolKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceSymbolKeys.length;i++){key=sourceSymbolKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key];}}return target;}function _objectWithoutPropertiesLoose(source,excluded){if(source==null)return{};var target={};var sourceKeys=Object.keys(source);var key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;target[key]=source[key];}return target;}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{logger}from'@shopgate/pwa-core/helpers';import{ELEMENT_TYPE_COUNTRY,ELEMENT_TYPE_PROVINCE}from"../elementTypes";/** Noop function */var noop=function noop(){};/**
1
+ import { logger } from '@shopgate/pwa-core/helpers';
2
+ import { ELEMENT_TYPE_COUNTRY, ELEMENT_TYPE_PROVINCE } from "../elementTypes";
3
+
4
+ /** Noop function */
5
+ const noop = () => {};
6
+
7
+ /**
2
8
  * @typedef {Object} FormElement
3
9
  * @property {string} id
4
10
  * @property {boolean} custom
@@ -11,21 +17,73 @@ var _excluded=["custom"];function _objectWithoutProperties(source,excluded){if(s
11
17
  * @property {boolean|null|undefined} required
12
18
  * @property {boolean|null|undefined} visible
13
19
  * @property {FormFieldAction[]|null|undefined} actions
14
- */ /**
20
+ */
21
+
22
+ /**
15
23
  * Takes a list of which elements to render based on the respective element type
16
24
  *
17
25
  * @param {Form} formConfig Configuration of which form fields to render
18
26
  * @param {Function} elementChangeHandler change handler
19
27
  * @return {FormElement[]}
20
- */export default(function(formConfig){var elementChangeHandler=arguments.length>1&&arguments[1]!==undefined?arguments[1]:noop;/**
28
+ */
29
+ export default (formConfig, elementChangeHandler = noop) => {
30
+ /**
21
31
  * @type {FormElement[]}
22
- */var elementList=[];var hasCountryElement=false;var hasProvinceElement=false;/**
32
+ */
33
+ const elementList = [];
34
+ let hasCountryElement = false;
35
+ let hasProvinceElement = false;
36
+
37
+ /**
23
38
  * @param {string} id id
24
39
  * @param {AnyFormField} field field
25
40
  * @param {boolean} custom custom
26
- */var addFormElement=function addFormElement(id,field){var custom=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;// The "custom" field is just a placeholder for more fields
27
- if(typeof field.type!=='string'){return;}// Make sure country and province elements are only added once
28
- if(field.type===ELEMENT_TYPE_COUNTRY){if(hasCountryElement){logger.error("Error: Can not add multiple elements of type '".concat(field.type,"'"));return;}hasCountryElement=true;}if(field.type===ELEMENT_TYPE_PROVINCE){if(hasProvinceElement){logger.error("Error: Can not add multiple elements of type '".concat(field.type,"'"));return;}hasProvinceElement=true;}elementList.push(_extends({id:id},field,{custom:custom,handleChange:function handleChange(value){return elementChangeHandler(id,value);}}));};// Extract custom fields, do not mix with normal fields
29
- var _formConfig$fields=formConfig.fields,custom=_formConfig$fields.custom,restFields=_objectWithoutProperties(_formConfig$fields,_excluded);// Add all non-custom attributes and mark them as such
30
- Object.keys(restFields).forEach(function(id){addFormElement(id,formConfig.fields[id]);});// Add custom fields to the element list
31
- if(custom){Object.keys(custom).forEach(function(id){addFormElement(id,formConfig.fields.custom[id],true);});}return elementList;});
41
+ */
42
+ const addFormElement = (id, field, custom = false) => {
43
+ // The "custom" field is just a placeholder for more fields
44
+ if (typeof field.type !== 'string') {
45
+ return;
46
+ }
47
+
48
+ // Make sure country and province elements are only added once
49
+ if (field.type === ELEMENT_TYPE_COUNTRY) {
50
+ if (hasCountryElement) {
51
+ logger.error(`Error: Can not add multiple elements of type '${field.type}'`);
52
+ return;
53
+ }
54
+ hasCountryElement = true;
55
+ }
56
+ if (field.type === ELEMENT_TYPE_PROVINCE) {
57
+ if (hasProvinceElement) {
58
+ logger.error(`Error: Can not add multiple elements of type '${field.type}'`);
59
+ return;
60
+ }
61
+ hasProvinceElement = true;
62
+ }
63
+ elementList.push({
64
+ id,
65
+ ...field,
66
+ custom,
67
+ handleChange: value => elementChangeHandler(id, value)
68
+ });
69
+ };
70
+
71
+ // Extract custom fields, do not mix with normal fields
72
+ const {
73
+ custom,
74
+ ...restFields
75
+ } = formConfig.fields;
76
+
77
+ // Add all non-custom attributes and mark them as such
78
+ Object.keys(restFields).forEach(id => {
79
+ addFormElement(id, formConfig.fields[id]);
80
+ });
81
+
82
+ // Add custom fields to the element list
83
+ if (custom) {
84
+ Object.keys(custom).forEach(id => {
85
+ addFormElement(id, formConfig.fields.custom[id], true);
86
+ });
87
+ }
88
+ return elementList;
89
+ };
@@ -1,7 +1,24 @@
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 iso3166 from"../iso-3166-2";/**
1
+ import iso3166 from "../iso-3166-2";
2
+
3
+ /**
2
4
  * Returns a list of provinces based on the given country id
3
5
  *
4
6
  * @param {string} countryCode Country code of the country to fetch provinces from
5
7
  * @param {?Object} optional object to prepend optional choice
6
8
  * @return {Object}
7
- */export default(function(countryCode){var optional=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;if(!iso3166){return{};}/** @property {iso3166} divisions */var provinceList=iso3166[countryCode]?iso3166[countryCode].divisions:{};if(!optional){return provinceList;}return _extends({},optional,{},provinceList);});
9
+ */
10
+ export default (countryCode, optional = null) => {
11
+ if (!iso3166) {
12
+ return {};
13
+ }
14
+
15
+ /** @property {iso3166} divisions */
16
+ const provinceList = iso3166[countryCode] ? iso3166[countryCode].divisions : {};
17
+ if (!optional) {
18
+ return provinceList;
19
+ }
20
+ return {
21
+ ...optional,
22
+ ...provinceList
23
+ };
24
+ };
@@ -1,5 +1,10 @@
1
- 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;}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);}/**
1
+ import "core-js/modules/es.array.reduce.js";
2
+ /**
2
3
  * Builds an Object, that contains all validation errors given as array of objects
3
4
  * @param {{path: string, message: string}[]} validationErrors Associated object containing errors
4
5
  * @return {Object}
5
- */export default(function(validationErrors){return validationErrors.reduce(function(result,validationError){return _extends({},result,_defineProperty({},validationError.path,validationError.message));},{});});
6
+ */
7
+ export default validationErrors => validationErrors.reduce((result, validationError) => ({
8
+ ...result,
9
+ [validationError.path]: validationError.message
10
+ }), {});
@@ -1,2 +1,22 @@
1
- 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;}export var ACTION_TYPE_UPDATE_PROVINCE_ELEMENT='updateProvinceElement';export var ACTION_TYPE_SET_VISIBILITY='setVisibility';export var ACTION_TYPE_SET_VALUE='setValue';export var ACTION_TYPE_TRANSFORM='transform';export var ACTION_SET_VALUE_FIXED='fixed';export var ACTION_SET_VALUE_COPY_FROM='copyFrom';export var ACTION_SET_VALUE_LENGTH_OF='lengthOf';export var ACTION_RULE_TYPE_NOT_IN='notIn';export var ACTION_RULE_TYPE_ONE_OF='oneOf';export var ACTION_RULE_TYPE_BOOLEAN='boolean';export var ACTION_RULE_TYPE_REGEX='regex';// Rule data is formatted as array
2
- export var ACTION_RULE_DATA_TYPES=_defineProperty(_defineProperty(_defineProperty(_defineProperty({},ACTION_RULE_TYPE_NOT_IN,'array'),ACTION_RULE_TYPE_ONE_OF,'array'),ACTION_RULE_TYPE_BOOLEAN,'boolean'),ACTION_RULE_TYPE_REGEX,'string');export var ACTION_RULES_CONCAT_METHOD_ALL='all';export var ACTION_RULES_CONCAT_METHOD_ANY='any';export var ACTION_RULES_CONCAT_METHOD_NONE='none';
1
+ export const ACTION_TYPE_UPDATE_PROVINCE_ELEMENT = 'updateProvinceElement';
2
+ export const ACTION_TYPE_SET_VISIBILITY = 'setVisibility';
3
+ export const ACTION_TYPE_SET_VALUE = 'setValue';
4
+ export const ACTION_TYPE_TRANSFORM = 'transform';
5
+ export const ACTION_SET_VALUE_FIXED = 'fixed';
6
+ export const ACTION_SET_VALUE_COPY_FROM = 'copyFrom';
7
+ export const ACTION_SET_VALUE_LENGTH_OF = 'lengthOf';
8
+ export const ACTION_RULE_TYPE_NOT_IN = 'notIn';
9
+ export const ACTION_RULE_TYPE_ONE_OF = 'oneOf';
10
+ export const ACTION_RULE_TYPE_BOOLEAN = 'boolean';
11
+ export const ACTION_RULE_TYPE_REGEX = 'regex';
12
+
13
+ // Rule data is formatted as array
14
+ export const ACTION_RULE_DATA_TYPES = {
15
+ [ACTION_RULE_TYPE_NOT_IN]: 'array',
16
+ [ACTION_RULE_TYPE_ONE_OF]: 'array',
17
+ [ACTION_RULE_TYPE_BOOLEAN]: 'boolean',
18
+ [ACTION_RULE_TYPE_REGEX]: 'string'
19
+ };
20
+ export const ACTION_RULES_CONCAT_METHOD_ALL = 'all';
21
+ export const ACTION_RULES_CONCAT_METHOD_ANY = 'any';
22
+ export const ACTION_RULES_CONCAT_METHOD_NONE = 'none';