@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,7 +1,98 @@
1
- import React from'react';import{shallow}from'enzyme';import Checkbox from"./index";/**
1
+ import React from 'react';
2
+ import { shallow } from 'enzyme';
3
+ import Checkbox from "./index";
4
+
5
+ /**
2
6
  * Checked Icon
3
7
  * @returns {JSX}
4
- */var Checked=function Checked(){return React.createElement("div",null);};/**
8
+ */
9
+ const Checked = () => /*#__PURE__*/React.createElement("div", null);
10
+
11
+ /**
5
12
  * Unchecked Icon
6
13
  * @returns {JSX}
7
- */var Unchecked=function Unchecked(){return React.createElement("div",null);};describe('<Checkbox />',function(){it('should render the checkbox with the label before the icon',function(){var wrapper=shallow(React.createElement(Checkbox,{label:React.createElement("span",null,"Test Label Deluxe"),labelPosition:"left",checkedIcon:React.createElement(Checked,null),uncheckedIcon:React.createElement(Unchecked,null),checked:false}));var expected=React.createElement("div",null,React.createElement("span",null,"Test Label Deluxe"),React.createElement(Unchecked,null));expect(wrapper).toMatchSnapshot();expect(wrapper.matchesElement(expected)).toBeTruthy();});it('should render the checkbox with the label after the icon',function(){var wrapper=shallow(React.createElement(Checkbox,{label:React.createElement("span",null,"Test Label Deluxe"),labelPosition:"right",checkedIcon:React.createElement(Checked,null),uncheckedIcon:React.createElement(Unchecked,null),checked:false}));var expected=React.createElement("div",null,React.createElement(Unchecked,null),React.createElement("span",null,"Test Label Deluxe"));expect(wrapper).toMatchSnapshot();expect(wrapper.matchesElement(expected)).toBeTruthy();});it('should render the unchecked icon if "checked" is false',function(){var wrapper=shallow(React.createElement(Checkbox,{checked:false,label:"Test Label Deluxe",checkedIcon:React.createElement(Checked,null),uncheckedIcon:React.createElement(Unchecked,null)}));expect(wrapper).toMatchSnapshot();expect(wrapper.find(Checked).length).toBe(0);expect(wrapper.find(Unchecked).length).toBe(1);});it('should render the unchecked icon if "checked" is false',function(){var wrapper=shallow(React.createElement(Checkbox,{checked:true,label:"Test Label Deluxe",checkedIcon:React.createElement(Checked,null),uncheckedIcon:React.createElement(Unchecked,null)}));expect(wrapper).toMatchSnapshot();expect(wrapper.find(Checked).length).toBe(1);expect(wrapper.find(Unchecked).length).toBe(0);});it('should call the callback with the inverted value',function(){var spy=jest.fn();var wrapper=shallow(React.createElement(Checkbox,{label:"Test Label Deluxe",checkedIcon:React.createElement(Checked,null),uncheckedIcon:React.createElement(Unchecked,null),checked:false,onCheck:spy}));wrapper.simulate('click');expect(spy).toHaveBeenCalledWith(true);});it('should render an <input> element if a name prop is provided',function(){var wrapper=shallow(React.createElement(Checkbox,{label:"Test Label Deluxe",checkedIcon:React.createElement(Checked,null),uncheckedIcon:React.createElement(Unchecked,null),defaultChecked:false,name:"myCheckbox"}));var input=wrapper.find('input');expect(input.length).toBe(1);expect(input.prop('name')).toEqual('myCheckbox');expect(input.prop('value')).toEqual(0);});it('should work as an uncontrolled input',function(){var wrapper=shallow(React.createElement(Checkbox,{label:"Test Label Deluxe",checkedIcon:React.createElement(Checked,null),uncheckedIcon:React.createElement(Unchecked,null),defaultChecked:false}));wrapper.simulate('click');expect(wrapper.state('checked')).toBe(true);});});
14
+ */
15
+ const Unchecked = () => /*#__PURE__*/React.createElement("div", null);
16
+ describe('<Checkbox />', () => {
17
+ it('should render the checkbox with the label before the icon', () => {
18
+ const wrapper = shallow(/*#__PURE__*/React.createElement(Checkbox, {
19
+ label: /*#__PURE__*/React.createElement("span", null, "Test Label Deluxe"),
20
+ labelPosition: "left",
21
+ checkedIcon: /*#__PURE__*/React.createElement(Checked, null),
22
+ uncheckedIcon: /*#__PURE__*/React.createElement(Unchecked, null),
23
+ checked: false
24
+ }));
25
+ const expected = /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", null, "Test Label Deluxe"), /*#__PURE__*/React.createElement(Unchecked, null));
26
+ expect(wrapper).toMatchSnapshot();
27
+ expect(wrapper.matchesElement(expected)).toBeTruthy();
28
+ });
29
+ it('should render the checkbox with the label after the icon', () => {
30
+ const wrapper = shallow(/*#__PURE__*/React.createElement(Checkbox, {
31
+ label: /*#__PURE__*/React.createElement("span", null, "Test Label Deluxe"),
32
+ labelPosition: "right",
33
+ checkedIcon: /*#__PURE__*/React.createElement(Checked, null),
34
+ uncheckedIcon: /*#__PURE__*/React.createElement(Unchecked, null),
35
+ checked: false
36
+ }));
37
+ const expected = /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Unchecked, null), /*#__PURE__*/React.createElement("span", null, "Test Label Deluxe"));
38
+ expect(wrapper).toMatchSnapshot();
39
+ expect(wrapper.matchesElement(expected)).toBeTruthy();
40
+ });
41
+ it('should render the unchecked icon if "checked" is false', () => {
42
+ const wrapper = shallow(/*#__PURE__*/React.createElement(Checkbox, {
43
+ checked: false,
44
+ label: "Test Label Deluxe",
45
+ checkedIcon: /*#__PURE__*/React.createElement(Checked, null),
46
+ uncheckedIcon: /*#__PURE__*/React.createElement(Unchecked, null)
47
+ }));
48
+ expect(wrapper).toMatchSnapshot();
49
+ expect(wrapper.find(Checked).length).toBe(0);
50
+ expect(wrapper.find(Unchecked).length).toBe(1);
51
+ });
52
+ it('should render the unchecked icon if "checked" is false', () => {
53
+ const wrapper = shallow(/*#__PURE__*/React.createElement(Checkbox, {
54
+ checked: true,
55
+ label: "Test Label Deluxe",
56
+ checkedIcon: /*#__PURE__*/React.createElement(Checked, null),
57
+ uncheckedIcon: /*#__PURE__*/React.createElement(Unchecked, null)
58
+ }));
59
+ expect(wrapper).toMatchSnapshot();
60
+ expect(wrapper.find(Checked).length).toBe(1);
61
+ expect(wrapper.find(Unchecked).length).toBe(0);
62
+ });
63
+ it('should call the callback with the inverted value', () => {
64
+ const spy = jest.fn();
65
+ const wrapper = shallow(/*#__PURE__*/React.createElement(Checkbox, {
66
+ label: "Test Label Deluxe",
67
+ checkedIcon: /*#__PURE__*/React.createElement(Checked, null),
68
+ uncheckedIcon: /*#__PURE__*/React.createElement(Unchecked, null),
69
+ checked: false,
70
+ onCheck: spy
71
+ }));
72
+ wrapper.simulate('click');
73
+ expect(spy).toHaveBeenCalledWith(true);
74
+ });
75
+ it('should render an <input> element if a name prop is provided', () => {
76
+ const wrapper = shallow(/*#__PURE__*/React.createElement(Checkbox, {
77
+ label: "Test Label Deluxe",
78
+ checkedIcon: /*#__PURE__*/React.createElement(Checked, null),
79
+ uncheckedIcon: /*#__PURE__*/React.createElement(Unchecked, null),
80
+ defaultChecked: false,
81
+ name: "myCheckbox"
82
+ }));
83
+ const input = wrapper.find('input');
84
+ expect(input.length).toBe(1);
85
+ expect(input.prop('name')).toEqual('myCheckbox');
86
+ expect(input.prop('value')).toEqual(0);
87
+ });
88
+ it('should work as an uncontrolled input', () => {
89
+ const wrapper = shallow(/*#__PURE__*/React.createElement(Checkbox, {
90
+ label: "Test Label Deluxe",
91
+ checkedIcon: /*#__PURE__*/React.createElement(Checked, null),
92
+ uncheckedIcon: /*#__PURE__*/React.createElement(Unchecked, null),
93
+ defaultChecked: false
94
+ }));
95
+ wrapper.simulate('click');
96
+ expect(wrapper.state('checked')).toBe(true);
97
+ });
98
+ });
@@ -1,7 +1,18 @@
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 get from'lodash/get';/**
1
+ import get from 'lodash/get';
2
+
3
+ /**
2
4
  * Searches an object for the given paths.
3
5
  * Returns a new object with the values found at the end of each path.
4
6
  * @param {Object} obj The object to look through.
5
7
  * @param {Object} paths A set of paths to find inside the object.
6
8
  * @returns {Object}
7
- */var buildParams=function buildParams(obj,paths){var params={};Object.entries(paths).forEach(function(_ref){var _ref2=_slicedToArray(_ref,2),prop=_ref2[0],path=_ref2[1];var value=get(obj,path);params[prop]=typeof value!=='undefined'?value:null;});return params;};export default buildParams;
9
+ */
10
+ const buildParams = (obj, paths) => {
11
+ const params = {};
12
+ Object.entries(paths).forEach(([prop, path]) => {
13
+ const value = get(obj, path);
14
+ params[prop] = typeof value !== 'undefined' ? value : null;
15
+ });
16
+ return params;
17
+ };
18
+ export default buildParams;
@@ -1,6 +1,18 @@
1
- import React from'react';import PropTypes from'prop-types';import buildParams from"./helpers/buildParams";/**
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import buildParams from "./helpers/buildParams";
4
+
5
+ /**
2
6
  * @param {Function} props.children The child function to call.
3
7
  * @param {Object} props.context The react context.
4
8
  * @param {Object} props.props The props to create.
5
9
  * @returns {JSX}
6
- */var Consume=function Consume(_ref){var children=_ref.children,Consumer=_ref.context.Consumer,props=_ref.props;return React.createElement(Consumer,null,function(value){return children(buildParams(value,props));});};export default Consume;
10
+ */
11
+ const Consume = ({
12
+ children,
13
+ context: {
14
+ Consumer
15
+ },
16
+ props
17
+ }) => /*#__PURE__*/React.createElement(Consumer, null, value => children(buildParams(value, props)));
18
+ export default Consume;
@@ -1,37 +1,135 @@
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 padStart from'lodash/padStart';import I18n from"../I18n";/**
1
+ import React, { Component } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import padStart from 'lodash/padStart';
4
+ import I18n from "../I18n";
5
+
6
+ /**
2
7
  * Creates the appropriate format for a given time period.
3
8
  * @param {number} days The remaining days.
4
9
  * @param {number} hours The remaining hours.
5
10
  * @param {number} minutes The remaining minutes.
6
11
  * @param {number} seconds The remaining seconds.
7
12
  * @return {Object} String and params for the i18n component
8
- */export var getFormattedTimeString=function getFormattedTimeString(days,hours,minutes,seconds){var formattedHours=padStart(hours,2,'0');var formattedMinutes=padStart(minutes,2,'0');var formattedSeconds=padStart(seconds,2,'0');var hourlyFormat="".concat(formattedHours,":").concat(formattedMinutes,":").concat(formattedSeconds);return{string:'common.countdown',params:{days:days,time:hourlyFormat}};};/**
13
+ */
14
+ export const getFormattedTimeString = (days, hours, minutes, seconds) => {
15
+ const formattedHours = padStart(hours, 2, '0');
16
+ const formattedMinutes = padStart(minutes, 2, '0');
17
+ const formattedSeconds = padStart(seconds, 2, '0');
18
+ const hourlyFormat = `${formattedHours}:${formattedMinutes}:${formattedSeconds}`;
19
+ return {
20
+ string: 'common.countdown',
21
+ params: {
22
+ days,
23
+ time: hourlyFormat
24
+ }
25
+ };
26
+ };
27
+
28
+ /**
9
29
  * Creates a formatted duration string for a given time span represented as unix time stamp.
10
30
  * @param {number} timeSpanInput The remaining time span (in seconds).
11
31
  * @return {Object} String and params for the I18n component
12
- */var createFormattedTime=function createFormattedTime(timeSpanInput){var timeSpan=Math.max(0,timeSpanInput);// Calculate remaining days, hours, minutes and seconds.
13
- var days=Math.floor(timeSpan/86400);var hours=Math.floor(timeSpan%86400/3600);var minutes=Math.floor(timeSpan%3600/60);var seconds=timeSpan%60;return getFormattedTimeString(days,hours,minutes,seconds);};/**
32
+ */
33
+ const createFormattedTime = timeSpanInput => {
34
+ const timeSpan = Math.max(0, timeSpanInput);
35
+
36
+ // Calculate remaining days, hours, minutes and seconds.
37
+ const days = Math.floor(timeSpan / 86400);
38
+ const hours = Math.floor(timeSpan % 86400 / 3600);
39
+ const minutes = Math.floor(timeSpan % 3600 / 60);
40
+ const seconds = timeSpan % 60;
41
+ return getFormattedTimeString(days, hours, minutes, seconds);
42
+ };
43
+
44
+ /**
14
45
  * The Countdown timer component.
15
- */var CountdownTimer=/*#__PURE__*/function(_Component){/**
46
+ */
47
+ class CountdownTimer extends Component {
48
+ /**
16
49
  * The component constructor.
17
50
  * @param {Object} props The component properties.
18
- */function CountdownTimer(props){var _this2;_classCallCheck(this,CountdownTimer);_this2=_callSuper(this,CountdownTimer,[props]);_this2.intervalHandle=null;_this2.remainingTime=_this2.getRemainingTime();_this2.expired=_this2.remainingTime<=0;// Calculate the initial formatted time string.
19
- _this2.state={formattedTime:createFormattedTime(_this2.remainingTime)};return _this2;}/**
51
+ */
52
+ constructor(props) {
53
+ super(props);
54
+ this.intervalHandle = null;
55
+ this.remainingTime = this.getRemainingTime();
56
+ this.expired = this.remainingTime <= 0;
57
+
58
+ // Calculate the initial formatted time string.
59
+ this.state = {
60
+ formattedTime: createFormattedTime(this.remainingTime)
61
+ };
62
+ }
63
+
64
+ /**
20
65
  * Installs a new interval to update the timer if the component did mount.
21
- */_inherits(CountdownTimer,_Component);return _createClass(CountdownTimer,[{key:"componentDidMount",value:function componentDidMount(){var _this3=this;// Install the interval.
22
- this.intervalHandle=setInterval(function(){/**
66
+ */
67
+ componentDidMount() {
68
+ // Install the interval.
69
+ this.intervalHandle = setInterval(() => {
70
+ /**
23
71
  * To allow mocked tests of the timing functions and still be able to deal
24
72
  * with paused execution, the delta time is expected to be at least 1.
25
- */_this3.remainingTime=_this3.getRemainingTime();_this3.updateTimer();},1000);}/**
73
+ */
74
+ this.remainingTime = this.getRemainingTime();
75
+ this.updateTimer();
76
+ }, 1000);
77
+ }
78
+
79
+ /**
26
80
  * Clears the timer interval.
27
- */},{key:"componentWillUnmount",value:function componentWillUnmount(){if(this.intervalHandle){clearInterval(this.intervalHandle);}}/**
81
+ */
82
+ componentWillUnmount() {
83
+ if (this.intervalHandle) {
84
+ clearInterval(this.intervalHandle);
85
+ }
86
+ }
87
+
88
+ /**
28
89
  * @returns {number} The remaining time until the timer runs out.
29
- */},{key:"getRemainingTime",value:function getRemainingTime(){return Math.ceil(this.props.timeout-Date.now()/1000);}/**
90
+ */
91
+ getRemainingTime() {
92
+ return Math.ceil(this.props.timeout - Date.now() / 1000);
93
+ }
94
+
95
+ /**
30
96
  * Updates the formatted time. Will not cause a re-rendering of the component.
31
- */},{key:"updateTimer",value:function updateTimer(){// Calculate the remaining time until the timer is expired. Also ignore negative durations.
32
- var deltaTime=Math.max(0,this.remainingTime);var isExpired=deltaTime<=0;if(isExpired&&!this.expired){this.expired=true;// Clear the interval.
33
- clearInterval(this.intervalHandle);this.intervalHandle=null;// The timer just expired, invoke the callback.
34
- if(this.props.onExpire){this.props.onExpire();}}this.setState({formattedTime:createFormattedTime(deltaTime)});}/**
97
+ */
98
+ updateTimer() {
99
+ // Calculate the remaining time until the timer is expired. Also ignore negative durations.
100
+ const deltaTime = Math.max(0, this.remainingTime);
101
+ const isExpired = deltaTime <= 0;
102
+ if (isExpired && !this.expired) {
103
+ this.expired = true;
104
+
105
+ // Clear the interval.
106
+ clearInterval(this.intervalHandle);
107
+ this.intervalHandle = null;
108
+
109
+ // The timer just expired, invoke the callback.
110
+ if (this.props.onExpire) {
111
+ this.props.onExpire();
112
+ }
113
+ }
114
+ this.setState({
115
+ formattedTime: createFormattedTime(deltaTime)
116
+ });
117
+ }
118
+
119
+ /**
35
120
  * Renders the element.
36
121
  * @return {JSX.Element}
37
- */},{key:"render",value:function render(){return React.createElement(I18n.Text,{string:this.state.formattedTime.string,params:this.state.formattedTime.params,className:"".concat(this.props.className," common__countdown-timer")});}}]);}(Component);_defineProperty(CountdownTimer,"defaultProps",{className:'',onExpire:null});export default CountdownTimer;
122
+ */
123
+ render() {
124
+ return /*#__PURE__*/React.createElement(I18n.Text, {
125
+ string: this.state.formattedTime.string,
126
+ params: this.state.formattedTime.params,
127
+ className: `${this.props.className} common__countdown-timer`
128
+ });
129
+ }
130
+ }
131
+ CountdownTimer.defaultProps = {
132
+ className: '',
133
+ onExpire: null
134
+ };
135
+ export default CountdownTimer;
@@ -1,4 +1,10 @@
1
- import React from'react';import{shallow}from'enzyme';import CountdownTimer,{getFormattedTimeString}from"./index";describe('<CountdownTimer>',function(){jest.useFakeTimers();/**
1
+ import React from 'react';
2
+ import { shallow } from 'enzyme';
3
+ import CountdownTimer, { getFormattedTimeString } from "./index";
4
+ describe('<CountdownTimer>', () => {
5
+ jest.useFakeTimers();
6
+
7
+ /**
2
8
  * Creates a new countdown timer element.
3
9
  * @param {number} remainingDays The remaining days.
4
10
  * @param {number} remainingHours The remaining hours.
@@ -6,21 +12,129 @@ import React from'react';import{shallow}from'enzyme';import CountdownTimer,{getF
6
12
  * @param {number} remainingSeconds The remaining seconds.
7
13
  * @param {Function} callback The expiration callback.
8
14
  * @return {JSX}
9
- */var createTimerElement=function createTimerElement(remainingDays,remainingHours,remainingMinutes,remainingSeconds,callback){var timeout=Math.floor(Date.now()/1000)+remainingDays*86400+remainingHours*3600+remainingMinutes*60+remainingSeconds;var wrapper=shallow(React.createElement(CountdownTimer,{timeout:timeout,onExpire:callback}));var currentTimeOffset=timeout-Math.floor(Date.now()/1000);wrapper.instance().getRemainingTime=function(){currentTimeOffset-=1;return currentTimeOffset;};return wrapper;};/**
15
+ */
16
+ const createTimerElement = (remainingDays, remainingHours, remainingMinutes, remainingSeconds, callback) => {
17
+ const timeout = Math.floor(Date.now() / 1000) + remainingDays * 86400 + remainingHours * 3600 + remainingMinutes * 60 + remainingSeconds;
18
+ const wrapper = shallow(/*#__PURE__*/React.createElement(CountdownTimer, {
19
+ timeout: timeout,
20
+ onExpire: callback
21
+ }));
22
+ let currentTimeOffset = timeout - Math.floor(Date.now() / 1000);
23
+ wrapper.instance().getRemainingTime = () => {
24
+ currentTimeOffset -= 1;
25
+ return currentTimeOffset;
26
+ };
27
+ return wrapper;
28
+ };
29
+
30
+ /**
10
31
  * Performs a time format check for a specific remaining time.
11
32
  * @param {number} remainingDays The remaining days.
12
33
  * @param {number} remainingHours The remaining hours.
13
34
  * @param {number} remainingMinutes The remaining minutes.
14
35
  * @param {number} remainingSeconds The remaining seconds.
15
- */var performFormatCheck=function performFormatCheck(remainingDays,remainingHours,remainingMinutes,remainingSeconds){jest.clearAllTimers();setInterval.mock.calls=[];var wrapper=createTimerElement(remainingDays,remainingHours,remainingMinutes,remainingSeconds,null);var expectedTimeFormat=getFormattedTimeString(remainingDays,remainingHours,remainingMinutes,remainingSeconds-1// Expect the decremented timeout.
16
- );// We cannot perform a snapshot match here because the timestamp changes for each call.
17
- expect(setInterval.mock.calls.length).toBe(1);jest.runTimersToTime(1000);wrapper.update();var _wrapper$props=wrapper.props(),params=_wrapper$props.params,string=_wrapper$props.string;var renderedTimeFormat={params:params,string:string};expect(renderedTimeFormat).toEqual(expectedTimeFormat);};it('should render the correct time for < 24h',function(){return performFormatCheck(0,0,0,5);});it('should render the correct time for 24h - 48h',function(){return performFormatCheck(1,12,6,5);});it('should render the correct time for > 2d',function(){return performFormatCheck(30,1,2,3);});it('should not render negative durations',function(){jest.clearAllTimers();var wrapper=createTimerElement(-1,-2,-3,-5,null);var expectedTimeFormat=getFormattedTimeString(0,0,0,0);jest.runTimersToTime(1000);var _wrapper$props2=wrapper.props(),params=_wrapper$props2.params,string=_wrapper$props2.string;var renderedTimeFormat={params:params,string:string};expect(renderedTimeFormat).toEqual(expectedTimeFormat);});it('should stop at 00:00:00 when the timer expires',function(){var wrapper=createTimerElement(0,0,0,1,null);var expectedTimeFormat=getFormattedTimeString(0,0,0,0);var renderedTimeFormat;// Run down to 00:00:00.
18
- jest.runTimersToTime(1000);wrapper.update();var _wrapper$props3=wrapper.props(),params=_wrapper$props3.params,string=_wrapper$props3.string;renderedTimeFormat={params:params,string:string};expect(renderedTimeFormat).toEqual(expectedTimeFormat);// Advance time a bit further and make sure the timer stays at 00:00:00.
19
- jest.runTimersToTime(1000);var _wrapper$props4=wrapper.props();params=_wrapper$props4.params;string=_wrapper$props4.string;renderedTimeFormat={params:params,string:string};expect(renderedTimeFormat).toEqual(expectedTimeFormat);});it('should invoke the callback when the timer expires',function(){var timesCallbackInvoked=0;/**
36
+ */
37
+ const performFormatCheck = (remainingDays, remainingHours, remainingMinutes, remainingSeconds) => {
38
+ jest.clearAllTimers();
39
+ setInterval.mock.calls = [];
40
+ const wrapper = createTimerElement(remainingDays, remainingHours, remainingMinutes, remainingSeconds, null);
41
+ const expectedTimeFormat = getFormattedTimeString(remainingDays, remainingHours, remainingMinutes, remainingSeconds - 1 // Expect the decremented timeout.
42
+ );
43
+
44
+ // We cannot perform a snapshot match here because the timestamp changes for each call.
45
+ expect(setInterval.mock.calls.length).toBe(1);
46
+ jest.runTimersToTime(1000);
47
+ wrapper.update();
48
+ const {
49
+ params,
50
+ string
51
+ } = wrapper.props();
52
+ const renderedTimeFormat = {
53
+ params,
54
+ string
55
+ };
56
+ expect(renderedTimeFormat).toEqual(expectedTimeFormat);
57
+ };
58
+ it('should render the correct time for < 24h', () => performFormatCheck(0, 0, 0, 5));
59
+ it('should render the correct time for 24h - 48h', () => performFormatCheck(1, 12, 6, 5));
60
+ it('should render the correct time for > 2d', () => performFormatCheck(30, 1, 2, 3));
61
+ it('should not render negative durations', () => {
62
+ jest.clearAllTimers();
63
+ const wrapper = createTimerElement(-1, -2, -3, -5, null);
64
+ const expectedTimeFormat = getFormattedTimeString(0, 0, 0, 0);
65
+ jest.runTimersToTime(1000);
66
+ const {
67
+ params,
68
+ string
69
+ } = wrapper.props();
70
+ const renderedTimeFormat = {
71
+ params,
72
+ string
73
+ };
74
+ expect(renderedTimeFormat).toEqual(expectedTimeFormat);
75
+ });
76
+ it('should stop at 00:00:00 when the timer expires', () => {
77
+ const wrapper = createTimerElement(0, 0, 0, 1, null);
78
+ const expectedTimeFormat = getFormattedTimeString(0, 0, 0, 0);
79
+ let renderedTimeFormat;
80
+
81
+ // Run down to 00:00:00.
82
+ jest.runTimersToTime(1000);
83
+ wrapper.update();
84
+ let {
85
+ params,
86
+ string
87
+ } = wrapper.props();
88
+ renderedTimeFormat = {
89
+ params,
90
+ string
91
+ };
92
+ expect(renderedTimeFormat).toEqual(expectedTimeFormat);
93
+
94
+ // Advance time a bit further and make sure the timer stays at 00:00:00.
95
+ jest.runTimersToTime(1000);
96
+ ({
97
+ params,
98
+ string
99
+ } = wrapper.props());
100
+ renderedTimeFormat = {
101
+ params,
102
+ string
103
+ };
104
+ expect(renderedTimeFormat).toEqual(expectedTimeFormat);
105
+ });
106
+ it('should invoke the callback when the timer expires', () => {
107
+ let timesCallbackInvoked = 0;
108
+ /**
20
109
  * The callback method will just increment a counter when invoked.
21
- */var callback=function callback(){timesCallbackInvoked+=1;};createTimerElement(0,0,0,2,callback);// The timer is not expired yet. Make sure the callback is not invoked.
22
- jest.runTimersToTime(1000);expect(timesCallbackInvoked).toBe(0);// The timer should expire by now.
23
- jest.runTimersToTime(1000);expect(timesCallbackInvoked).toBe(1);// Run it again and make sure it won't be called twice.
24
- jest.runTimersToTime(1000);expect(timesCallbackInvoked).toBe(1);});it('should not invoke the callback when the timeout is already expired.',function(){var timesCallbackInvoked=0;/**
110
+ */
111
+ const callback = () => {
112
+ timesCallbackInvoked += 1;
113
+ };
114
+ createTimerElement(0, 0, 0, 2, callback);
115
+
116
+ // The timer is not expired yet. Make sure the callback is not invoked.
117
+ jest.runTimersToTime(1000);
118
+ expect(timesCallbackInvoked).toBe(0);
119
+
120
+ // The timer should expire by now.
121
+ jest.runTimersToTime(1000);
122
+ expect(timesCallbackInvoked).toBe(1);
123
+
124
+ // Run it again and make sure it won't be called twice.
125
+ jest.runTimersToTime(1000);
126
+ expect(timesCallbackInvoked).toBe(1);
127
+ });
128
+ it('should not invoke the callback when the timeout is already expired.', () => {
129
+ let timesCallbackInvoked = 0;
130
+ /**
25
131
  * The callback method will just increment a counter when invoked.
26
- */var callback=function callback(){timesCallbackInvoked+=1;};createTimerElement(0,0,0,0,callback);jest.runTimersToTime(1000);expect(timesCallbackInvoked).toBe(0);});});
132
+ */
133
+ const callback = () => {
134
+ timesCallbackInvoked += 1;
135
+ };
136
+ createTimerElement(0, 0, 0, 0, callback);
137
+ jest.runTimersToTime(1000);
138
+ expect(timesCallbackInvoked).toBe(0);
139
+ });
140
+ });
@@ -1,25 +1,140 @@
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';import styles from"./style";/**
1
+ import React, { Component } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import classNames from 'classnames';
4
+ import styles from "./style";
5
+
6
+ /**
2
7
  * Drawer component.
3
- */var Drawer=/*#__PURE__*/function(_Component){/**
8
+ */
9
+ class Drawer extends Component {
10
+ /**
4
11
  * Initializes the Drawer component.
5
12
  * @param {Object} props The components props.
6
- */function Drawer(props){var _this2;_classCallCheck(this,Drawer);_this2=_callSuper(this,Drawer,[props]);/**
7
- * Syncs the internal active state when an animation ends.
8
- */_defineProperty(_this2,"handleAnimationEnd",function(){_this2.setState({active:_this2.props.isOpen});if(!_this2.props.isOpen){_this2.props.onDidClose();}else{_this2.props.onDidOpen();}});_this2.sheetRef=React.createRef();_this2.state={active:props.isOpen};return _this2;}/** inheritdoc */_inherits(Drawer,_Component);return _createClass(Drawer,[{key:"componentDidMount",value:function componentDidMount(){if(this.props.isOpen){if(this.sheetRef.current){this.sheetRef.current.focus();}}}/**
13
+ */
14
+ constructor(props) {
15
+ super(props);
16
+ /**
17
+ * Syncs the internal active state when an animation ends.
18
+ */
19
+ this.handleAnimationEnd = () => {
20
+ this.setState({
21
+ active: this.props.isOpen
22
+ });
23
+ if (!this.props.isOpen) {
24
+ this.props.onDidClose();
25
+ } else {
26
+ this.props.onDidOpen();
27
+ }
28
+ };
29
+ this.sheetRef = /*#__PURE__*/React.createRef();
30
+ this.state = {
31
+ active: props.isOpen
32
+ };
33
+ }
34
+
35
+ /** inheritdoc */
36
+ componentDidMount() {
37
+ if (this.props.isOpen) {
38
+ if (this.sheetRef.current) {
39
+ this.sheetRef.current.focus();
40
+ }
41
+ }
42
+ }
43
+
44
+ /**
9
45
  * Update state when isOpen changes.
10
46
  * @param {Object} nextProps The next component props.
11
- */},{key:"UNSAFE_componentWillReceiveProps",value:function UNSAFE_componentWillReceiveProps(nextProps){if(this.props.isOpen!==nextProps.isOpen){if(nextProps.isOpen){if(typeof nextProps.onOpen==='function'){nextProps.onOpen();}this.setState({active:true});}else if(typeof nextProps.onClose==='function'){nextProps.onClose();}}}/**
47
+ */
48
+ UNSAFE_componentWillReceiveProps(nextProps) {
49
+ if (this.props.isOpen !== nextProps.isOpen) {
50
+ if (nextProps.isOpen) {
51
+ if (typeof nextProps.onOpen === 'function') {
52
+ nextProps.onOpen();
53
+ }
54
+ this.setState({
55
+ active: true
56
+ });
57
+ } else if (typeof nextProps.onClose === 'function') {
58
+ nextProps.onClose();
59
+ }
60
+ }
61
+ }
62
+
63
+ /**
12
64
  * Set focus for a11y when sheet opens
13
65
  * @param {Object} prevProps The previous component props.
14
- */},{key:"componentDidUpdate",value:function componentDidUpdate(prevProps){if(!prevProps.isOpen&&this.props.isOpen){if(this.sheetRef.current){this.sheetRef.current.focus();}}}},{key:"render",value:/**
66
+ */
67
+ componentDidUpdate(prevProps) {
68
+ if (!prevProps.isOpen && this.props.isOpen) {
69
+ if (this.sheetRef.current) {
70
+ this.sheetRef.current.focus();
71
+ }
72
+ }
73
+ }
74
+ /**
15
75
  * Renders the component.
16
76
  * @returns {JSX}
17
- */function render(){var _this3=this;var _this$props=this.props,className=_this$props.className,children=_this$props.children,isOpen=_this$props.isOpen,animation=_this$props.animation;var active=this.state.active;var animationIn=animation["in"]||styles.animation["in"];var animationOut=animation.out||styles.animation.out;var combinedClassName=classNames(className,styles.container,_defineProperty({},animationIn,isOpen),_defineProperty({},animationOut,!isOpen),'common__drawer');var style={};if(typeof animation.duration==='number'){style.animationDuration="".concat(animation.duration,"ms");}return active?React.createElement("div",{ref:this.sheetRef,className:combinedClassName,style:style,onAnimationEnd:function onAnimationEnd(){var _this3$sheetRef;_this3.handleAnimationEnd();// clear any residual animation style to fix a11y issue on Android
18
- // (focus ring is misaligned)
19
- if((_this3$sheetRef=_this3.sheetRef)===null||_this3$sheetRef===void 0?void 0:_this3$sheetRef.style){_this3.sheetRef.style.animation='';_this3.sheetRef.style.transform='none';}},role:"dialog","aria-modal":true,tabIndex:-1},children):null;}}]);}(Component);/**
20
- * The component prop types.
21
- * @type {Object}
22
- */ /**
23
- * The component default props.
24
- * @type {Object}
25
- */_defineProperty(Drawer,"defaultProps",{className:'',children:null,isOpen:false,onOpen:function onOpen(){},onClose:function onClose(){},onDidClose:function onDidClose(){},onDidOpen:function onDidOpen(){},animation:{duration:null,"in":'',out:''}});export default Drawer;
77
+ */
78
+ render() {
79
+ const {
80
+ className,
81
+ children,
82
+ isOpen,
83
+ animation
84
+ } = this.props;
85
+ const {
86
+ active
87
+ } = this.state;
88
+ const animationIn = animation.in || styles.animation.in;
89
+ const animationOut = animation.out || styles.animation.out;
90
+ const combinedClassName = classNames(className, styles.container, {
91
+ [animationIn]: isOpen
92
+ }, {
93
+ [animationOut]: !isOpen
94
+ }, 'common__drawer');
95
+ const style = {};
96
+ if (typeof animation.duration === 'number') {
97
+ style.animationDuration = `${animation.duration}ms`;
98
+ }
99
+ return active ? /*#__PURE__*/React.createElement("div", {
100
+ ref: this.sheetRef,
101
+ className: combinedClassName,
102
+ style: style,
103
+ onAnimationEnd: () => {
104
+ this.handleAnimationEnd();
105
+ // clear any residual animation style to fix a11y issue on Android
106
+ // (focus ring is misaligned)
107
+ if (this.sheetRef?.style) {
108
+ this.sheetRef.style.animation = '';
109
+ this.sheetRef.style.transform = 'none';
110
+ }
111
+ },
112
+ role: "dialog",
113
+ "aria-modal": true,
114
+ tabIndex: -1
115
+ }, children) : null;
116
+ }
117
+ }
118
+ /**
119
+ * The component prop types.
120
+ * @type {Object}
121
+ */
122
+ /**
123
+ * The component default props.
124
+ * @type {Object}
125
+ */
126
+ Drawer.defaultProps = {
127
+ className: '',
128
+ children: null,
129
+ isOpen: false,
130
+ onOpen: () => {},
131
+ onClose: () => {},
132
+ onDidClose: () => {},
133
+ onDidOpen: () => {},
134
+ animation: {
135
+ duration: null,
136
+ in: '',
137
+ out: ''
138
+ }
139
+ };
140
+ export default Drawer;