@shopgate/pwa-common 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 (306) hide show
  1. package/App.js +48 -6
  2. package/action-creators/app/index.js +75 -12
  3. package/action-creators/app/spec.js +96 -1
  4. package/action-creators/client/index.js +27 -5
  5. package/action-creators/client/spec.js +44 -1
  6. package/action-creators/error/index.js +15 -3
  7. package/action-creators/index.js +9 -1
  8. package/action-creators/menu/index.js +23 -4
  9. package/action-creators/menu/spec.js +37 -1
  10. package/action-creators/modal/index.js +15 -3
  11. package/action-creators/modal/spec.js +26 -1
  12. package/action-creators/page/index.js +24 -4
  13. package/action-creators/page/spec.js +38 -1
  14. package/action-creators/router/index.js +48 -7
  15. package/action-creators/url/index.js +24 -4
  16. package/action-creators/url/spec.js +45 -1
  17. package/action-creators/user/index.js +90 -13
  18. package/action-creators/user/spec.js +186 -2
  19. package/actions/app/handleDeepLink.js +11 -2
  20. package/actions/app/handleLink.js +62 -6
  21. package/actions/app/handlePushNotification.js +32 -4
  22. package/actions/app/handleUniversalLink.js +11 -2
  23. package/actions/app/registerLinkEvents.js +24 -3
  24. package/actions/client/fetchClientInformation.js +26 -2
  25. package/actions/menu/fetchMenu.js +23 -2
  26. package/actions/modal/closeModal.js +18 -2
  27. package/actions/modal/promiseMap.js +3 -1
  28. package/actions/modal/showModal.js +54 -8
  29. package/actions/page/fetchPageConfig.js +69 -2
  30. package/actions/page/getPageConfig.js +6 -2
  31. package/actions/page/index.js +1 -1
  32. package/actions/router/historyPop.js +12 -2
  33. package/actions/router/historyPopToRoute.js +27 -2
  34. package/actions/router/historyPush.js +12 -2
  35. package/actions/router/historyRedirect.js +21 -2
  36. package/actions/router/historyReplace.js +20 -3
  37. package/actions/router/historyReset.js +11 -2
  38. package/actions/router/historyResetTo.js +12 -2
  39. package/actions/router/index.js +17 -1
  40. package/actions/router/routeDidPop.js +11 -2
  41. package/actions/router/routeDidPush.js +13 -2
  42. package/actions/router/routeDidReplace.js +11 -2
  43. package/actions/router/routeDidReset.js +11 -2
  44. package/actions/router/routeDidUpdate.js +10 -2
  45. package/actions/router/routeWillPop.js +11 -2
  46. package/actions/router/routeWillPush.js +13 -2
  47. package/actions/router/routeWillReplace.js +11 -2
  48. package/actions/router/routeWillReset.js +11 -2
  49. package/actions/router/windowOpenOverride.js +10 -2
  50. package/actions/user/fetchRegisterUrl.js +36 -2
  51. package/actions/user/fetchUser.js +29 -3
  52. package/actions/user/getUser.js +6 -2
  53. package/actions/user/index.js +1 -1
  54. package/actions/user/login.js +76 -9
  55. package/actions/user/logout.js +30 -2
  56. package/collections/AuthRoutes.js +73 -14
  57. package/collections/Configuration.js +54 -7
  58. package/collections/EmbeddedMedia.js +84 -11
  59. package/collections/PersistedReducers.js +41 -6
  60. package/collections/Redirects.js +103 -17
  61. package/collections/index.js +5 -1
  62. package/collections/media-providers/MediaProvider.js +151 -26
  63. package/collections/media-providers/Vimeo.js +113 -19
  64. package/collections/media-providers/YouTube.js +74 -14
  65. package/collections/media-providers/index.js +3 -1
  66. package/collections/media-providers/style.js +52 -2
  67. package/components/Backdrop/index.js +95 -6
  68. package/components/Backdrop/spec.js +23 -1
  69. package/components/Backdrop/style.js +11 -2
  70. package/components/Button/index.js +47 -5
  71. package/components/Button/spec.js +36 -1
  72. package/components/Button/style.js +6 -1
  73. package/components/Checkbox/index.js +126 -32
  74. package/components/Checkbox/spec.js +94 -3
  75. package/components/Consume/helpers/buildParams.js +13 -2
  76. package/components/Consume/index.js +14 -2
  77. package/components/CountdownTimer/index.js +115 -17
  78. package/components/CountdownTimer/spec.js +126 -12
  79. package/components/Drawer/index.js +131 -16
  80. package/components/Drawer/spec.js +76 -1
  81. package/components/Drawer/style.js +37 -1
  82. package/components/Dropdown/index.js +65 -6
  83. package/components/Dropdown/style.js +4 -1
  84. package/components/Dropdown/transitions.js +34 -1
  85. package/components/Ellipsis/index.js +16 -2
  86. package/components/Ellipsis/spec.js +13 -1
  87. package/components/EmbeddedMedia/index.js +56 -6
  88. package/components/EmbeddedMedia/spec.js +52 -3
  89. package/components/ErrorBoundary/connector.js +9 -2
  90. package/components/ErrorBoundary/index.js +43 -7
  91. package/components/Grid/components/Item/index.js +40 -4
  92. package/components/Grid/components/Item/spec.js +23 -1
  93. package/components/Grid/components/Item/style.js +17 -3
  94. package/components/Grid/index.js +36 -4
  95. package/components/Grid/spec.js +23 -1
  96. package/components/Grid/style.js +11 -2
  97. package/components/HtmlSanitizer/connector.js +24 -3
  98. package/components/HtmlSanitizer/index.js +104 -12
  99. package/components/HtmlSanitizer/spec.js +207 -6
  100. package/components/I18n/components/FormatDate/index.js +26 -2
  101. package/components/I18n/components/FormatDate/spec.js +46 -1
  102. package/components/I18n/components/FormatNumber/index.js +34 -2
  103. package/components/I18n/components/FormatNumber/spec.js +41 -2
  104. package/components/I18n/components/FormatPrice/index.js +32 -2
  105. package/components/I18n/components/FormatPrice/spec.js +46 -1
  106. package/components/I18n/components/FormatTime/index.js +26 -2
  107. package/components/I18n/components/FormatTime/spec.js +43 -2
  108. package/components/I18n/components/I18nProvider/index.js +52 -9
  109. package/components/I18n/components/I18nProvider/spec.js +39 -1
  110. package/components/I18n/components/Placeholder/index.js +8 -2
  111. package/components/I18n/components/Placeholder/spec.js +30 -1
  112. package/components/I18n/components/Translate/index.js +68 -7
  113. package/components/I18n/components/Translate/spec.js +30 -1
  114. package/components/I18n/index.js +16 -1
  115. package/components/Icon/index.js +25 -2
  116. package/components/Icon/style.js +6 -1
  117. package/components/Image/Image.js +176 -19
  118. package/components/Image/ImageInner.js +48 -2
  119. package/components/Image/index.js +1 -1
  120. package/components/Image/style.js +29 -2
  121. package/components/InfiniteContainer/index.js +381 -49
  122. package/components/InfiniteContainer/spec.js +199 -10
  123. package/components/Input/components/DateInput.js +262 -6
  124. package/components/Input/components/MultiLineInput.js +98 -12
  125. package/components/Input/components/SimpleInput.js +207 -31
  126. package/components/Input/index.js +32 -3
  127. package/components/Input/spec.js +122 -1
  128. package/components/KeyboardConsumer/index.js +48 -7
  129. package/components/Link/connector.js +7 -1
  130. package/components/Link/index.js +96 -11
  131. package/components/Link/spec.js +56 -1
  132. package/components/Link/style.js +10 -1
  133. package/components/List/components/Item/index.js +35 -3
  134. package/components/List/components/Item/style.js +16 -1
  135. package/components/List/index.js +20 -2
  136. package/components/List/spec.js +31 -1
  137. package/components/Loading/index.js +6 -2
  138. package/components/Modal/index.js +38 -3
  139. package/components/Modal/style.js +36 -1
  140. package/components/ModalContainer/connector.js +17 -3
  141. package/components/ModalContainer/index.js +36 -3
  142. package/components/ModalContainer/spec.js +105 -5
  143. package/components/Picker/components/Button/index.js +34 -2
  144. package/components/Picker/components/Button/style.js +19 -1
  145. package/components/Picker/components/List/index.js +33 -2
  146. package/components/Picker/components/List/style.js +17 -1
  147. package/components/Picker/components/Modal/index.js +60 -7
  148. package/components/Picker/components/Modal/style.js +78 -1
  149. package/components/Picker/index.js +167 -21
  150. package/components/Picker/spec.js +83 -2
  151. package/components/Portal/index.js +130 -19
  152. package/components/ProductCharacteristics/connector.js +33 -4
  153. package/components/ProductCharacteristics/context.js +2 -1
  154. package/components/ProductCharacteristics/helpers/index.js +135 -21
  155. package/components/ProductCharacteristics/index.js +266 -31
  156. package/components/RangeSlider/components/Handle/index.js +25 -2
  157. package/components/RangeSlider/components/Handle/style.js +14 -1
  158. package/components/RangeSlider/helper.js +43 -8
  159. package/components/RangeSlider/index.js +228 -38
  160. package/components/RangeSlider/style.js +14 -1
  161. package/components/Route/RouteNotFound.js +46 -3
  162. package/components/Route/index.js +78 -10
  163. package/components/Router/connector.js +9 -2
  164. package/components/Router/index.js +237 -31
  165. package/components/ScannerContainer/connector.js +9 -2
  166. package/components/ScannerContainer/index.js +42 -6
  167. package/components/Select/components/Item/index.js +20 -4
  168. package/components/Select/components/Item/style.js +4 -1
  169. package/components/Select/index.js +149 -28
  170. package/components/Select/spec.js +86 -2
  171. package/components/Select/style.js +17 -1
  172. package/components/SelectBox/components/Item/index.js +47 -5
  173. package/components/SelectBox/components/Item/style.js +7 -1
  174. package/components/SelectBox/index.js +173 -17
  175. package/components/SelectBox/spec.js +59 -3
  176. package/components/SelectBox/style.js +18 -1
  177. package/components/Slider/index.js +6 -2
  178. package/components/SurroundPortals/index.js +26 -2
  179. package/components/Swiper/components/SwiperItem/index.js +28 -4
  180. package/components/Swiper/components/SwiperItem/spec.js +17 -1
  181. package/components/Swiper/components/SwiperItem/styles.js +5 -1
  182. package/components/Swiper/index.js +210 -18
  183. package/components/Swiper/styles.js +75 -7
  184. package/components/Toaster/index.js +10 -2
  185. package/components/Transition/index.js +89 -13
  186. package/components/Widgets/components/Widget/index.js +52 -4
  187. package/components/Widgets/components/Widget/spec.js +68 -3
  188. package/components/Widgets/components/Widget/style.js +21 -3
  189. package/components/Widgets/components/WidgetGrid/index.js +52 -7
  190. package/components/Widgets/components/WidgetGrid/spec.js +46 -2
  191. package/components/Widgets/components/WidgetGrid/style.js +8 -1
  192. package/components/Widgets/helpers/shouldShowWidget.js +44 -7
  193. package/components/Widgets/index.js +127 -15
  194. package/components/Widgets/spec.js +213 -6
  195. package/components/index.js +9 -1
  196. package/constants/ActionTypes.js +97 -19
  197. package/constants/Configuration.js +12 -2
  198. package/constants/Device.js +29 -2
  199. package/constants/DisplayOptions.js +8 -1
  200. package/constants/MenuIDs.js +2 -1
  201. package/constants/ModalTypes.js +1 -1
  202. package/constants/PageIDs.js +1 -1
  203. package/constants/Pipelines.js +7 -1
  204. package/constants/Portals.js +136 -3
  205. package/constants/Registration.js +3 -1
  206. package/constants/RoutePaths.js +13 -2
  207. package/constants/Tracking.js +3 -1
  208. package/constants/client.js +6 -1
  209. package/constants/ui.js +2 -1
  210. package/constants/user.js +6 -2
  211. package/context/index.js +33 -3
  212. package/helpers/config/index.js +139 -21
  213. package/helpers/config/mock.js +200 -8
  214. package/helpers/config/theme.js +50 -4
  215. package/helpers/data/index.js +204 -29
  216. package/helpers/data/spec.js +187 -7
  217. package/helpers/date/index.js +58 -6
  218. package/helpers/date/spec.js +92 -1
  219. package/helpers/dom/index.js +48 -11
  220. package/helpers/environment/index.js +14 -2
  221. package/helpers/html/decodeHTML.js +7 -1
  222. package/helpers/html/handleDOM.js +172 -21
  223. package/helpers/html/parseHTML.js +67 -12
  224. package/helpers/i18n/getDateFormatter.js +23 -4
  225. package/helpers/i18n/getNumberFormatter.js +32 -4
  226. package/helpers/i18n/getPriceFormatter.js +38 -4
  227. package/helpers/i18n/getTimeFormatter.js +23 -4
  228. package/helpers/i18n/getTranslator.js +62 -8
  229. package/helpers/i18n/index.js +5 -1
  230. package/helpers/i18n/mergeTranslations.js +36 -9
  231. package/helpers/i18n/messageCache.js +3 -1
  232. package/helpers/legacy/index.js +47 -9
  233. package/helpers/modal/withShowModal.js +13 -2
  234. package/helpers/portals/portalCollection.js +28 -6
  235. package/helpers/portals/routePortals.js +12 -1
  236. package/helpers/redux/compareObjects.js +7 -2
  237. package/helpers/redux/generateResultHash.js +36 -3
  238. package/helpers/redux/generateSortedHash.js +7 -2
  239. package/helpers/redux/hasExpired.js +10 -2
  240. package/helpers/redux/index.js +7 -1
  241. package/helpers/redux/mutable.js +143 -24
  242. package/helpers/redux/shouldFetchData.js +46 -10
  243. package/helpers/redux/shouldFetchFilters.js +17 -4
  244. package/helpers/router/index.js +49 -5
  245. package/helpers/style/index.js +43 -4
  246. package/helpers/style/spec.js +108 -2
  247. package/helpers/tracking/index.js +52 -9
  248. package/helpers/validation/index.js +39 -12
  249. package/helpers/validation/spec.js +10 -1
  250. package/package.json +3 -3
  251. package/providers/index.js +4 -1
  252. package/providers/loading/context.js +2 -1
  253. package/providers/loading/index.js +137 -22
  254. package/providers/toast/context.js +2 -1
  255. package/providers/toast/index.js +105 -11
  256. package/reducers/client/connectivity.js +22 -2
  257. package/reducers/client/index.js +7 -1
  258. package/reducers/client/info.js +27 -2
  259. package/reducers/index.js +23 -4
  260. package/reducers/menu/index.js +5 -1
  261. package/reducers/menu/menusById.js +41 -2
  262. package/reducers/modal/index.js +14 -2
  263. package/reducers/page/index.js +68 -5
  264. package/reducers/router/index.js +48 -2
  265. package/reducers/url/index.js +42 -3
  266. package/reducers/user/data.js +27 -2
  267. package/reducers/user/index.js +7 -1
  268. package/reducers/user/login.js +65 -2
  269. package/selectors/client.js +138 -21
  270. package/selectors/history.js +49 -11
  271. package/selectors/menu.js +34 -6
  272. package/selectors/modal.js +15 -4
  273. package/selectors/page.js +25 -4
  274. package/selectors/router.js +154 -30
  275. package/selectors/url.js +25 -4
  276. package/selectors/user.js +90 -13
  277. package/store/index.js +60 -6
  278. package/store/middelwares/logger.js +7 -1
  279. package/store/middelwares/streams.js +19 -2
  280. package/streams/app.js +60 -8
  281. package/streams/client.js +8 -2
  282. package/streams/error.js +14 -3
  283. package/streams/index.js +6 -1
  284. package/streams/interval.js +6 -2
  285. package/streams/main.js +27 -2
  286. package/streams/router.js +45 -8
  287. package/streams/user.js +89 -15
  288. package/streams/view.js +97 -25
  289. package/styles/reset/form.js +57 -5
  290. package/styles/reset/index.js +6 -1
  291. package/styles/reset/media.js +22 -1
  292. package/styles/reset/root.js +33 -1
  293. package/styles/reset/table.js +10 -1
  294. package/styles/reset/typography.js +26 -1
  295. package/subscriptions/app.js +148 -17
  296. package/subscriptions/error.js +292 -13
  297. package/subscriptions/helpers/buildRegisterUrl.js +25 -6
  298. package/subscriptions/helpers/clearUpInAppBrowser.js +14 -3
  299. package/subscriptions/helpers/handleLinks.js +267 -25
  300. package/subscriptions/helpers/pipeline.js +12 -1
  301. package/subscriptions/history.js +34 -6
  302. package/subscriptions/index.js +25 -4
  303. package/subscriptions/menu.js +22 -5
  304. package/subscriptions/mock.js +39 -7
  305. package/subscriptions/router.js +336 -23
  306. package/subscriptions/user.js +93 -3
@@ -1,31 +1,91 @@
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 _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;}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);}import URLSearchParams from'url-search-params';import MediaProvider from"./MediaProvider";/* eslint-disable class-methods-use-this */ /**
1
+ import URLSearchParams from 'url-search-params';
2
+ import MediaProvider from "./MediaProvider";
3
+
4
+ /* eslint-disable class-methods-use-this */
5
+
6
+ /**
2
7
  * The YouTube media provider class.
3
- */var YouTubeMediaProvider=/*#__PURE__*/function(_MediaProvider){function YouTubeMediaProvider(){_classCallCheck(this,YouTubeMediaProvider);return _callSuper(this,YouTubeMediaProvider,arguments);}_inherits(YouTubeMediaProvider,_MediaProvider);return _createClass(YouTubeMediaProvider,[{key:"getMediaContainers",value:/**
8
+ */
9
+ class YouTubeMediaProvider extends MediaProvider {
10
+ /**
4
11
  * Retrieves a list of media containers for YouTube.
5
12
  * @param {ParentNode} container A DOM container that may contain YouTube iframes.
6
13
  * @returns {NodeListOf<Element>}
7
- */function getMediaContainers(container){return container.querySelectorAll('iframe[src*="youtube.com"], iframe[src*="youtube-nocookie.com"]');}/**
14
+ */
15
+ getMediaContainers(container) {
16
+ return container.querySelectorAll('iframe[src*="youtube.com"], iframe[src*="youtube-nocookie.com"]');
17
+ }
18
+
19
+ /**
8
20
  * Add a DOM container with embedded videos.
9
21
  * @override
10
22
  * @param {ParentNode} container A DOM container.
11
23
  * @returns {YouTubeMediaProvider}
12
- */},{key:"add",value:function add(container){var iframes=this.getMediaContainers(container);if(!iframes.length){return this;}this.containers.set(container,iframes);return this;}/**
24
+ */
25
+ add(container) {
26
+ const iframes = this.getMediaContainers(container);
27
+ if (!iframes.length) {
28
+ return this;
29
+ }
30
+ this.containers.set(container, iframes);
31
+ return this;
32
+ }
33
+
34
+ /**
13
35
  * Applies optimizations to embedded media iframes within the given container.
14
36
  * Common enhancements include adding responsive wrappers and appropriate
15
37
  * sandbox attributes to improve security and layout behavior.
16
38
  *
17
39
  * @param {Document} document - The DOM document containing iframes to optimize.
18
40
  * @returns {YouTubeMediaProvider}
19
- */},{key:"applyIframeOptimizations",value:function applyIframeOptimizations(document){var _this2=this;var iframes=this.getMediaContainers(document);if(!iframes.length){return this;}// Update the video urls to enable stopping videos via the event API.
20
- iframes.forEach(function(iframe,index){// Block clicks on YouTube icon
21
- iframes[index].setAttribute('sandbox','allow-forms allow-scripts allow-pointer-lock allow-same-origin allow-top-navigation');_this2.responsify(iframe);var src=iframe.getAttribute('src');var _src$split=src.split('?'),_src$split2=_slicedToArray(_src$split,2),url=_src$split2[0],query=_src$split2[1];var urlParams=new URLSearchParams(query);// Enable the js api to allow sending events to the iframe.
22
- urlParams.set('enablejsapi',1);// Enable controls to avoid the iframe not being resumable because of controls=0 param on ios.
23
- urlParams.set('controls',1);iframes[index].setAttribute('src',"".concat(url,"?").concat(urlParams.toString()));});return this;}/**
41
+ */
42
+ applyIframeOptimizations(document) {
43
+ const iframes = this.getMediaContainers(document);
44
+ if (!iframes.length) {
45
+ return this;
46
+ }
47
+
48
+ // Update the video urls to enable stopping videos via the event API.
49
+ iframes.forEach((iframe, index) => {
50
+ // Block clicks on YouTube icon
51
+ iframes[index].setAttribute('sandbox', 'allow-forms allow-scripts allow-pointer-lock allow-same-origin allow-top-navigation');
52
+ this.responsify(iframe);
53
+ const src = iframe.getAttribute('src');
54
+ const [url, query] = src.split('?');
55
+ const urlParams = new URLSearchParams(query);
56
+
57
+ // Enable the js api to allow sending events to the iframe.
58
+ urlParams.set('enablejsapi', 1);
59
+ // Enable controls to avoid the iframe not being resumable because of controls=0 param on ios.
60
+ urlParams.set('controls', 1);
61
+ iframes[index].setAttribute('src', `${url}?${urlParams.toString()}`);
62
+ });
63
+ return this;
64
+ }
65
+
66
+ /**
24
67
  * Stops all playing videos within the DOM containers.
25
68
  * @override
26
69
  * @returns {YouTubeMediaProvider}
27
- */},{key:"stop",value:function stop(){// Select all iframes in the document. Actually this should be done via the iframes
28
- // registered in this.containers, but that doesn't seem to work reliably anymore.
29
- // Since we had to find a quick fix for CURB-5033 we now select all iframes in the document
30
- // via the media container selector and then stop the videos.
31
- var iframes=this.getMediaContainers(document);iframes.forEach(function(iframe){var _iframe$contentWindow;if(typeof(iframe===null||iframe===void 0?void 0:(_iframe$contentWindow=iframe.contentWindow)===null||_iframe$contentWindow===void 0?void 0:_iframe$contentWindow.postMessage)==='function'){iframe.contentWindow.postMessage(JSON.stringify({event:'command',func:'stopVideo',args:[]}),'*');}});return this;}}]);}(MediaProvider);export default YouTubeMediaProvider;/* eslint-enable class-methods-use-this */
70
+ */
71
+ stop() {
72
+ // Select all iframes in the document. Actually this should be done via the iframes
73
+ // registered in this.containers, but that doesn't seem to work reliably anymore.
74
+ // Since we had to find a quick fix for CURB-5033 we now select all iframes in the document
75
+ // via the media container selector and then stop the videos.
76
+ const iframes = this.getMediaContainers(document);
77
+ iframes.forEach(iframe => {
78
+ if (typeof iframe?.contentWindow?.postMessage === 'function') {
79
+ iframe.contentWindow.postMessage(JSON.stringify({
80
+ event: 'command',
81
+ func: 'stopVideo',
82
+ args: []
83
+ }), '*');
84
+ }
85
+ });
86
+ return this;
87
+ }
88
+ }
89
+ export default YouTubeMediaProvider;
90
+
91
+ /* eslint-enable class-methods-use-this */
@@ -1 +1,3 @@
1
- export{default as MediaProvider}from"./MediaProvider";export{default as Vimeo}from"./Vimeo";export{default as YouTube}from"./YouTube";
1
+ export { default as MediaProvider } from "./MediaProvider";
2
+ export { default as Vimeo } from "./Vimeo";
3
+ export { default as YouTube } from "./YouTube";
@@ -1,2 +1,52 @@
1
- import{css}from'glamor';import{themeConfig}from'@shopgate/pwa-common/helpers/config';var colors=themeConfig.colors;var responsiveContainer=css({position:'relative',height:0,overflow:'hidden',padding:'56.25% 0 0 0',fontSize:'0.875rem',' iframe, object, embed':{position:'absolute',top:0,left:0,width:'100%',height:'100%',border:0}});var consentContainer=css({position:'absolute',height:'100%',width:'100%',padding:16,lineHeight:'1.2rem',display:'flex',flexDirection:'column',justifyContent:'center',textAlign:'center',gap:16,background:colors.shade10,border:"1px solid ".concat(colors.shade5),// Add a tiny little border radius to make the message container look nice with padding
2
- borderRadius:4,top:0});var consentLink=css({textAlign:'center',color:colors.primary,fontWeight:500}).toString();var consentIcon=css({fill:colors.shade5,height:40});export default{responsiveContainer:responsiveContainer,consentContainer:consentContainer,consentLink:consentLink,consentIcon:consentIcon};
1
+ import { css } from 'glamor';
2
+ import { themeConfig } from '@shopgate/pwa-common/helpers/config';
3
+ const {
4
+ colors
5
+ } = themeConfig;
6
+ const responsiveContainer = css({
7
+ position: 'relative',
8
+ height: 0,
9
+ overflow: 'hidden',
10
+ padding: '56.25% 0 0 0',
11
+ fontSize: '0.875rem',
12
+ ' iframe, object, embed': {
13
+ position: 'absolute',
14
+ top: 0,
15
+ left: 0,
16
+ width: '100%',
17
+ height: '100%',
18
+ border: 0
19
+ }
20
+ });
21
+ const consentContainer = css({
22
+ position: 'absolute',
23
+ height: '100%',
24
+ width: '100%',
25
+ padding: 16,
26
+ lineHeight: '1.2rem',
27
+ display: 'flex',
28
+ flexDirection: 'column',
29
+ justifyContent: 'center',
30
+ textAlign: 'center',
31
+ gap: 16,
32
+ background: colors.shade10,
33
+ border: `1px solid ${colors.shade5}`,
34
+ // Add a tiny little border radius to make the message container look nice with padding
35
+ borderRadius: 4,
36
+ top: 0
37
+ });
38
+ const consentLink = css({
39
+ textAlign: 'center',
40
+ color: colors.primary,
41
+ fontWeight: 500
42
+ }).toString();
43
+ const consentIcon = css({
44
+ fill: colors.shade5,
45
+ height: 40
46
+ });
47
+ export default {
48
+ responsiveContainer,
49
+ consentContainer,
50
+ consentLink,
51
+ consentIcon
52
+ };
@@ -1,9 +1,98 @@
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,{useEffect,useMemo,useRef}from'react';import PropTypes from'prop-types';import{Transition}from'react-transition-group';import{toggleBodyScroll}from'@shopgate/engage/styles/helpers';import style from"./style";/**
1
+ import React, { useEffect, useMemo, useRef } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { Transition } from 'react-transition-group';
4
+ import { toggleBodyScroll } from '@shopgate/engage/styles/helpers';
5
+ import style from "./style";
6
+
7
+ /**
2
8
  * Backdrop component
3
9
  * @param {Object} props The component props.
4
10
  * @returns {JSX.Element}
5
- */function Backdrop(_ref){var className=_ref.className,color=_ref.color,duration=_ref.duration,isVisible=_ref.isVisible,level=_ref.level,lockBodyScroll=_ref.lockBodyScroll,onClick=_ref.onClick,opacity=_ref.opacity;// Stable id for body scroll lock
6
- var bodyScrollRef=useRef(Math.random().toString(36).slice(2)+Math.random().toString(36).slice(2));var nodeRef=useRef(null);// Lock / unlock body scroll based on visibility
7
- useEffect(function(){if(!lockBodyScroll)return undefined;var refId=bodyScrollRef.current;toggleBodyScroll(isVisible,refId);return function(){toggleBodyScroll(false,refId);};},[isVisible,lockBodyScroll]);var baseStyle=useMemo(function(){return{background:color,zIndex:level,transition:"opacity ".concat(duration,"ms ease-out"),// start hidden by default; pointer events only when shown
8
- opacity:0,pointerEvents:'none'};},[color,level,duration]);var targetOpacity=useMemo(function(){return opacity/100;},[opacity]);// Map Transition states to inline styles (equivalent to your old childrenStyles)
9
- var transitionStyles=useMemo(function(){return{entering:{opacity:targetOpacity,pointerEvents:'auto'},entered:{opacity:targetOpacity,pointerEvents:'auto'},exiting:{opacity:0,pointerEvents:'none'},exited:{opacity:0,pointerEvents:'none'},unmounted:{opacity:0,pointerEvents:'none'}};},[targetOpacity]);var combinedClassName="".concat(style," ").concat(className," common__backdrop");return React.createElement(Transition,{"in":isVisible,timeout:duration,mountOnEnter:true,unmountOnExit:true,appear:true,nodeRef:nodeRef},function(state){return React.createElement("div",{ref:nodeRef,"data-test-id":"Backdrop","aria-hidden":true,className:combinedClassName,onClick:onClick,style:_extends({},baseStyle,{},transitionStyles[state])});});}Backdrop.defaultProps={className:'',color:'#000',duration:200,isVisible:false,level:2,onClick:function onClick(){},opacity:50,lockBodyScroll:true};export default React.memo(Backdrop,function(prev,next){return prev.isVisible===next.isVisible&&prev.className===next.className&&prev.color===next.color&&prev.duration===next.duration&&prev.level===next.level&&prev.lockBodyScroll===next.lockBodyScroll&&prev.opacity===next.opacity&&prev.onClick===next.onClick;});
11
+ */
12
+ function Backdrop({
13
+ className,
14
+ color,
15
+ duration,
16
+ isVisible,
17
+ level,
18
+ lockBodyScroll,
19
+ onClick,
20
+ opacity
21
+ }) {
22
+ // Stable id for body scroll lock
23
+ const bodyScrollRef = useRef(Math.random().toString(36).slice(2) + Math.random().toString(36).slice(2));
24
+ const nodeRef = useRef(null);
25
+
26
+ // Lock / unlock body scroll based on visibility
27
+ useEffect(() => {
28
+ if (!lockBodyScroll) return undefined;
29
+ const refId = bodyScrollRef.current;
30
+ toggleBodyScroll(isVisible, refId);
31
+ return () => {
32
+ toggleBodyScroll(false, refId);
33
+ };
34
+ }, [isVisible, lockBodyScroll]);
35
+ const baseStyle = useMemo(() => ({
36
+ background: color,
37
+ zIndex: level,
38
+ transition: `opacity ${duration}ms ease-out`,
39
+ // start hidden by default; pointer events only when shown
40
+ opacity: 0,
41
+ pointerEvents: 'none'
42
+ }), [color, level, duration]);
43
+ const targetOpacity = useMemo(() => opacity / 100, [opacity]);
44
+
45
+ // Map Transition states to inline styles
46
+ const transitionStyles = useMemo(() => ({
47
+ entering: {
48
+ opacity: targetOpacity,
49
+ pointerEvents: 'auto'
50
+ },
51
+ entered: {
52
+ opacity: targetOpacity,
53
+ pointerEvents: 'auto'
54
+ },
55
+ exiting: {
56
+ opacity: 0,
57
+ pointerEvents: 'none'
58
+ },
59
+ exited: {
60
+ opacity: 0,
61
+ pointerEvents: 'none'
62
+ },
63
+ unmounted: {
64
+ opacity: 0,
65
+ pointerEvents: 'none'
66
+ }
67
+ }), [targetOpacity]);
68
+ const combinedClassName = `${style} ${className} common__backdrop`;
69
+ return /*#__PURE__*/React.createElement(Transition, {
70
+ in: isVisible,
71
+ timeout: duration,
72
+ mountOnEnter: true,
73
+ unmountOnExit: true,
74
+ appear: true,
75
+ nodeRef: nodeRef
76
+ }, state => /*#__PURE__*/React.createElement("div", {
77
+ ref: nodeRef,
78
+ "data-test-id": "Backdrop",
79
+ "aria-hidden": true,
80
+ className: combinedClassName,
81
+ onClick: onClick,
82
+ style: {
83
+ ...baseStyle,
84
+ ...transitionStyles[state]
85
+ }
86
+ }));
87
+ }
88
+ Backdrop.defaultProps = {
89
+ className: '',
90
+ color: '#000',
91
+ duration: 200,
92
+ isVisible: false,
93
+ level: 2,
94
+ onClick: () => {},
95
+ opacity: 50,
96
+ lockBodyScroll: true
97
+ };
98
+ export default /*#__PURE__*/React.memo(Backdrop, (prev, next) => prev.isVisible === next.isVisible && prev.className === next.className && prev.color === next.color && prev.duration === next.duration && prev.level === next.level && prev.lockBodyScroll === next.lockBodyScroll && prev.opacity === next.opacity && prev.onClick === next.onClick);
@@ -1 +1,23 @@
1
- import React from'react';import{shallow,mount}from'enzyme';import Backdrop from"./index";describe('<Backdrop />',function(){var mockOpen;beforeEach(function(){mockOpen=jest.fn();});it('should render',function(){var wrapper=shallow(React.createElement(Backdrop,{isVisible:true}));expect(wrapper).toMatchSnapshot();});it('should execute callback when Backdrop is clicked',function(){var wrapper=mount(React.createElement(Backdrop,{isVisible:true,onClick:mockOpen}));wrapper.find('div').simulate('click');expect(mockOpen).toBeCalled();});});
1
+ import React from 'react';
2
+ import { shallow, mount } from 'enzyme';
3
+ import Backdrop from "./index";
4
+ describe('<Backdrop />', () => {
5
+ let mockOpen;
6
+ beforeEach(() => {
7
+ mockOpen = jest.fn();
8
+ });
9
+ it('should render', () => {
10
+ const wrapper = shallow(/*#__PURE__*/React.createElement(Backdrop, {
11
+ isVisible: true
12
+ }));
13
+ expect(wrapper).toMatchSnapshot();
14
+ });
15
+ it('should execute callback when Backdrop is clicked', () => {
16
+ const wrapper = mount(/*#__PURE__*/React.createElement(Backdrop, {
17
+ isVisible: true,
18
+ onClick: mockOpen
19
+ }));
20
+ wrapper.find('div').simulate('click');
21
+ expect(mockOpen).toBeCalled();
22
+ });
23
+ });
@@ -1,2 +1,11 @@
1
- import{css}from'glamor';export default css({position:'fixed',top:0,right:0,bottom:0,left:0,// Prevents that content behind the backdrop is clickable
2
- pointerEvents:'all',touchAction:'none'});
1
+ import { css } from 'glamor';
2
+ export default css({
3
+ position: 'fixed',
4
+ top: 0,
5
+ right: 0,
6
+ bottom: 0,
7
+ left: 0,
8
+ // Prevents that content behind the backdrop is clickable
9
+ pointerEvents: 'all',
10
+ touchAction: 'none'
11
+ });
@@ -1,10 +1,52 @@
1
- var _excluded=["children","testId","className","disabled","onClick"];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 _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 _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 style from"./style";/**
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import React, { Component } from 'react';
3
+ import PropTypes from 'prop-types';
4
+ import style from "./style";
5
+
6
+ /**
2
7
  * The button component.
3
- */var Button=/*#__PURE__*/function(_Component){function Button(){_classCallCheck(this,Button);return _callSuper(this,Button,arguments);}_inherits(Button,_Component);return _createClass(Button,[{key:"buttonProps",get:/**
8
+ */
9
+ class Button extends Component {
10
+ /**
4
11
  * Getter for the calculated button props.
5
12
  * @returns {Object}
6
- */function get(){var _this$props=this.props,children=_this$props.children,testId=_this$props.testId,className=_this$props.className,disabled=_this$props.disabled,onClick=_this$props.onClick,props=_objectWithoutProperties(_this$props,_excluded);var buttonProps=_extends({className:"".concat(className," ").concat(style," common__button"),disabled:disabled,onClick:disabled?null:onClick},props);return buttonProps;}/**
13
+ */
14
+ get buttonProps() {
15
+ const {
16
+ children,
17
+ testId,
18
+ className,
19
+ disabled,
20
+ onClick,
21
+ ...props
22
+ } = this.props;
23
+ const buttonProps = {
24
+ className: `${className} ${style} common__button`,
25
+ disabled,
26
+ onClick: disabled ? null : onClick,
27
+ ...props
28
+ };
29
+ return buttonProps;
30
+ }
31
+
32
+ /**
7
33
  * Renders the component.
8
34
  * @returns {JSX.Element}
9
- */},{key:"render",value:function render(){return(// eslint-disable-next-line react/button-has-type
10
- React.createElement("button",_extends({"data-test-id":this.props.testId},this.buttonProps),this.props.children));}}]);}(Component);_defineProperty(Button,"defaultProps",{className:'',disabled:false,onClick:null,testId:'Button'});export default Button;
35
+ */
36
+ render() {
37
+ return (
38
+ /*#__PURE__*/
39
+ // eslint-disable-next-line react/button-has-type
40
+ React.createElement("button", _extends({
41
+ "data-test-id": this.props.testId
42
+ }, this.buttonProps), this.props.children)
43
+ );
44
+ }
45
+ }
46
+ Button.defaultProps = {
47
+ className: '',
48
+ disabled: false,
49
+ onClick: null,
50
+ testId: 'Button'
51
+ };
52
+ export default Button;
@@ -1 +1,36 @@
1
- import React from'react';import{shallow}from'enzyme';import Button from"./index";describe('<Button />',function(){it('should render the button',function(){var wrapper=shallow(React.createElement(Button,null,"My content"));expect(wrapper).toMatchSnapshot();expect(wrapper.find('button').length).toBe(1);});it('should render the button in disabled state',function(){var wrapper=shallow(React.createElement(Button,{disabled:true},"My content"));expect(wrapper).toMatchSnapshot();expect(wrapper.find('button[disabled]').length).toBe(1);});it('should trigger the click event',function(){var callback=jest.fn();var wrapper=shallow(React.createElement(Button,{onClick:callback},"My content"));wrapper.simulate('click');expect(wrapper).toMatchSnapshot();expect(callback).toHaveBeenCalled();});it('should not trigger the click event when disabled',function(){var callback=jest.fn();var wrapper=shallow(React.createElement(Button,{disabled:true,onClick:callback},"My content"));wrapper.simulate('click');expect(wrapper).toMatchSnapshot();expect(callback).not.toHaveBeenCalled();});});
1
+ import React from 'react';
2
+ import { shallow } from 'enzyme';
3
+ import Button from "./index";
4
+ describe('<Button />', () => {
5
+ it('should render the button', () => {
6
+ const wrapper = shallow(/*#__PURE__*/React.createElement(Button, null, "My content"));
7
+ expect(wrapper).toMatchSnapshot();
8
+ expect(wrapper.find('button').length).toBe(1);
9
+ });
10
+ it('should render the button in disabled state', () => {
11
+ const wrapper = shallow(/*#__PURE__*/React.createElement(Button, {
12
+ disabled: true
13
+ }, "My content"));
14
+ expect(wrapper).toMatchSnapshot();
15
+ expect(wrapper.find('button[disabled]').length).toBe(1);
16
+ });
17
+ it('should trigger the click event', () => {
18
+ const callback = jest.fn();
19
+ const wrapper = shallow(/*#__PURE__*/React.createElement(Button, {
20
+ onClick: callback
21
+ }, "My content"));
22
+ wrapper.simulate('click');
23
+ expect(wrapper).toMatchSnapshot();
24
+ expect(callback).toHaveBeenCalled();
25
+ });
26
+ it('should not trigger the click event when disabled', () => {
27
+ const callback = jest.fn();
28
+ const wrapper = shallow(/*#__PURE__*/React.createElement(Button, {
29
+ disabled: true,
30
+ onClick: callback
31
+ }, "My content"));
32
+ wrapper.simulate('click');
33
+ expect(wrapper).toMatchSnapshot();
34
+ expect(callback).not.toHaveBeenCalled();
35
+ });
36
+ });
@@ -1 +1,6 @@
1
- import{css}from'glamor';export default css({':focus':{outline:0}}).toString();
1
+ import { css } from 'glamor';
2
+ export default css({
3
+ ':focus': {
4
+ outline: 0
5
+ }
6
+ }).toString();
@@ -1,4 +1,8 @@
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 classNames from'classnames';/**
1
+ import React, { Component } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import classNames from 'classnames';
4
+
5
+ /**
2
6
  * @typedef {Object} CheckboxProps
3
7
  * @property {React.ReactNode} checkedIcon React component used as icon for the checked state
4
8
  * @property {React.ReactNode} uncheckedIcon React component used as icon for the unchecked state
@@ -10,45 +14,135 @@ function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="s
10
14
  * @property {"left"|"right"} [labelPosition] Position for the lable (default `"left"`)
11
15
  * @property {string} [name] Name for the hidden input tag
12
16
  * @property {Function} [onCheck] Callback invoked when checkbox is toggled
13
- */ /**
17
+ */
18
+
19
+ /**
14
20
  * Base checkbox component.
15
21
  * @extends {React.Component<CheckboxProps>}
16
22
  * @returns {JSX.Element}
17
- */var Checkbox=/*#__PURE__*/function(_Component){/**
23
+ */
24
+ class Checkbox extends Component {
25
+ /**
18
26
  * The checkbox component constructor.
19
27
  * It checks if the checkbox is a controlled or uncontrolled input and sets an internal state if
20
28
  * uncontrolled to keep track of th checked-state.
21
29
  * @param {Object} props The Checkbox properties.
22
- */function Checkbox(props){var _this2;_classCallCheck(this,Checkbox);_this2=_callSuper(this,Checkbox,[props]);/**
23
- * Returns if the checkbox is checked or not.
24
- * @return {boolean} Is the checkbox checked?
25
- */_defineProperty(_this2,"isChecked",function(){return typeof _this2.props.defaultChecked==='undefined'?_this2.props.checked// Controlled.
26
- :_this2.state.checked// Uncontrolled.
27
- ;});/**
28
- * Inverts the current "checked" value and calls the callback function with it.
29
- * If the checkbox is uncontrolled, it keeps track of the value.
30
- */_defineProperty(_this2,"handleCheck",function(){if(_this2.props.disabled){return;}var checked=!_this2.isChecked();if(typeof _this2.props.defaultChecked!=='undefined'){// Uncontrolled.
31
- _this2.setState({checked:checked});}_this2.props.onCheck(checked);});/**
32
- * Handler for keyDown events of the checkbox
33
- * @param {Object} e The keyDown event payload
34
- */_defineProperty(_this2,"handleKeyDown",function(e){if(e.key===' '){// Toggle checkbox on "space" - mocks behavior of native checkboxes
35
- _this2.handleCheck();}});/**
36
- * Renders the checked/unchecked icon.
37
- * @returns {JSX}
38
- */_defineProperty(_this2,"renderIcon",function(){return _this2.isChecked()?_this2.props.checkedIcon:_this2.props.uncheckedIcon;});/**
39
- * Renders an input if a "name" prop is provided.
40
- * @returns {JSX}
41
- */_defineProperty(_this2,"renderInput",function(){var _this3=_this2,name=_this3.props.name,isChecked=_this3.isChecked;return _this2.props.name?React.createElement("input",{className:"input",type:"hidden",name:name,value:isChecked()?1:0}):null;});/**
42
- * Renders the label if "side" matches he labelPosition prop.
43
- * @param {string} side Used to check against which side to render the label on.
44
- * @returns {JSX}
45
- */_defineProperty(_this2,"renderLabelIfItIsOnThe",function(side){return _this2.props.labelPosition===side?_this2.props.label:null;});if(typeof props.defaultChecked!=='undefined'){// Uncontrolled input.
46
- _this2.state={checked:props.defaultChecked};}else{// Controlled input
47
- _this2.state={checked:props.checked};}return _this2;}/**
30
+ */
31
+ constructor(props) {
32
+ super(props);
33
+ /**
34
+ * Returns if the checkbox is checked or not.
35
+ * @return {boolean} Is the checkbox checked?
36
+ */
37
+ this.isChecked = () => typeof this.props.defaultChecked === 'undefined' ? this.props.checked // Controlled.
38
+ : this.state.checked // Uncontrolled.
39
+ ;
40
+ /**
41
+ * Inverts the current "checked" value and calls the callback function with it.
42
+ * If the checkbox is uncontrolled, it keeps track of the value.
43
+ */
44
+ this.handleCheck = () => {
45
+ if (this.props.disabled) {
46
+ return;
47
+ }
48
+ const checked = !this.isChecked();
49
+ if (typeof this.props.defaultChecked !== 'undefined') {
50
+ // Uncontrolled.
51
+ this.setState({
52
+ checked
53
+ });
54
+ }
55
+ this.props.onCheck(checked);
56
+ };
57
+ /**
58
+ * Handler for keyDown events of the checkbox
59
+ * @param {Object} e The keyDown event payload
60
+ */
61
+ this.handleKeyDown = e => {
62
+ if (e.key === ' ') {
63
+ // Toggle checkbox on "space" - mocks behavior of native checkboxes
64
+ this.handleCheck();
65
+ }
66
+ };
67
+ /**
68
+ * Renders the checked/unchecked icon.
69
+ * @returns {JSX}
70
+ */
71
+ this.renderIcon = () => this.isChecked() ? this.props.checkedIcon : this.props.uncheckedIcon;
72
+ /**
73
+ * Renders an input if a "name" prop is provided.
74
+ * @returns {JSX}
75
+ */
76
+ this.renderInput = () => {
77
+ const {
78
+ props: {
79
+ name
80
+ },
81
+ isChecked
82
+ } = this;
83
+ return this.props.name ? /*#__PURE__*/React.createElement("input", {
84
+ className: "input",
85
+ type: "hidden",
86
+ name: name,
87
+ value: isChecked() ? 1 : 0
88
+ }) : null;
89
+ };
90
+ /**
91
+ * Renders the label if "side" matches he labelPosition prop.
92
+ * @param {string} side Used to check against which side to render the label on.
93
+ * @returns {JSX}
94
+ */
95
+ this.renderLabelIfItIsOnThe = side => this.props.labelPosition === side ? this.props.label : null;
96
+ if (typeof props.defaultChecked !== 'undefined') {
97
+ // Uncontrolled input.
98
+ this.state = {
99
+ checked: props.defaultChecked
100
+ };
101
+ } else {
102
+ // Controlled input
103
+ this.state = {
104
+ checked: props.checked
105
+ };
106
+ }
107
+ }
108
+
109
+ /**
48
110
  * Make sure state is updated with new checked value when input is controlled
49
111
  * @param {Object} nextProps Contains the new "checked" status
50
- */_inherits(Checkbox,_Component);return _createClass(Checkbox,[{key:"UNSAFE_componentWillReceiveProps",value:function UNSAFE_componentWillReceiveProps(nextProps){// Update only for controlled input
51
- if(typeof this.props.defaultChecked==='undefined'){if(this.state.checked!==nextProps.checked){this.setState({checked:nextProps.checked});}}}},{key:"render",value:/**
112
+ */
113
+ UNSAFE_componentWillReceiveProps(nextProps) {
114
+ // Update only for controlled input
115
+ if (typeof this.props.defaultChecked === 'undefined') {
116
+ if (this.state.checked !== nextProps.checked) {
117
+ this.setState({
118
+ checked: nextProps.checked
119
+ });
120
+ }
121
+ }
122
+ }
123
+ /**
52
124
  * Renders the checkbox component.
53
125
  * @returns {JSX}
54
- */function render(){return React.createElement("div",{className:classNames(this.props.className,'checkbox','common__checkbox'),onClick:this.handleCheck,onKeyDown:this.handleKeyDown,role:"checkbox","aria-checked":this.props.checked,tabIndex:0},this.renderInput(),this.renderLabelIfItIsOnThe('left'),this.renderIcon(),this.renderLabelIfItIsOnThe('right'));}}]);}(Component);_defineProperty(Checkbox,"defaultProps",{checked:undefined,className:undefined,defaultChecked:undefined,disabled:false,label:null,labelPosition:'left',name:undefined,onCheck:function onCheck(){}});export default Checkbox;
126
+ */
127
+ render() {
128
+ return /*#__PURE__*/React.createElement("div", {
129
+ className: classNames(this.props.className, 'checkbox', 'common__checkbox'),
130
+ onClick: this.handleCheck,
131
+ onKeyDown: this.handleKeyDown,
132
+ role: "checkbox",
133
+ "aria-checked": this.props.checked,
134
+ tabIndex: 0
135
+ }, this.renderInput(), this.renderLabelIfItIsOnThe('left'), this.renderIcon(), this.renderLabelIfItIsOnThe('right'));
136
+ }
137
+ }
138
+ Checkbox.defaultProps = {
139
+ checked: undefined,
140
+ className: undefined,
141
+ defaultChecked: undefined,
142
+ disabled: false,
143
+ label: null,
144
+ labelPosition: 'left',
145
+ name: undefined,
146
+ onCheck: () => {}
147
+ };
148
+ export default Checkbox;