@shopgate/pwa-common 7.30.0-alpha.9 → 7.30.0-beta.2

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 (106) hide show
  1. package/App.js +28 -13
  2. package/actions/app/handleUniversalLink.js +0 -2
  3. package/collections/AuthRoutes.js +15 -13
  4. package/collections/Configuration.js +11 -10
  5. package/collections/EmbeddedMedia.js +21 -19
  6. package/collections/PersistedReducers.js +11 -9
  7. package/collections/Redirects.js +15 -13
  8. package/collections/media-providers/MediaProvider.js +23 -21
  9. package/collections/media-providers/Vimeo.js +28 -22
  10. package/collections/media-providers/YouTube.js +17 -10
  11. package/components/Backdrop/index.js +15 -13
  12. package/components/Backdrop/spec.js +3 -2
  13. package/components/Button/index.js +41 -29
  14. package/components/Button/spec.js +16 -10
  15. package/components/Checkbox/index.js +36 -28
  16. package/components/Checkbox/spec.js +40 -27
  17. package/components/Consume/index.js +4 -1
  18. package/components/CountdownTimer/index.js +27 -20
  19. package/components/CountdownTimer/spec.js +2 -1
  20. package/components/Drawer/index.js +31 -23
  21. package/components/Drawer/spec.js +7 -6
  22. package/components/Dropdown/index.js +27 -18
  23. package/components/Ellipsis/index.js +5 -3
  24. package/components/Ellipsis/spec.js +5 -3
  25. package/components/EmbeddedMedia/index.js +9 -6
  26. package/components/EmbeddedMedia/spec.js +11 -2
  27. package/components/ErrorBoundary/index.js +26 -16
  28. package/components/Grid/components/Item/index.js +13 -6
  29. package/components/Grid/components/Item/spec.js +4 -3
  30. package/components/Grid/index.js +13 -6
  31. package/components/Grid/spec.js +4 -3
  32. package/components/HtmlSanitizer/index.js +42 -45
  33. package/components/HtmlSanitizer/spec.js +16 -12
  34. package/components/I18n/components/FormatDate/index.js +11 -4
  35. package/components/I18n/components/FormatDate/spec.js +22 -14
  36. package/components/I18n/components/FormatNumber/index.js +8 -6
  37. package/components/I18n/components/FormatNumber/spec.js +10 -5
  38. package/components/I18n/components/FormatPrice/index.js +5 -3
  39. package/components/I18n/components/FormatPrice/spec.js +22 -14
  40. package/components/I18n/components/FormatTime/index.js +11 -4
  41. package/components/I18n/components/FormatTime/spec.js +22 -14
  42. package/components/I18n/components/I18nProvider/index.js +18 -11
  43. package/components/I18n/components/I18nProvider/spec.js +2 -1
  44. package/components/I18n/components/Placeholder/index.js +10 -3
  45. package/components/I18n/components/Placeholder/spec.js +12 -5
  46. package/components/I18n/components/Translate/index.js +12 -8
  47. package/components/I18n/components/Translate/spec.js +9 -6
  48. package/components/Icon/index.js +2 -1
  49. package/components/Image/Image.js +23 -21
  50. package/components/Image/ImageInner.js +2 -1
  51. package/components/InfiniteContainer/index.js +59 -53
  52. package/components/InfiniteContainer/spec.js +10 -5
  53. package/components/Input/components/MultiLineInput.js +33 -26
  54. package/components/Input/components/SimpleInput.js +70 -54
  55. package/components/Input/index.js +7 -17
  56. package/components/Input/spec.js +12 -11
  57. package/components/KeyboardConsumer/index.js +19 -13
  58. package/components/Link/index.js +28 -20
  59. package/components/Link/spec.js +13 -9
  60. package/components/List/components/Item/index.js +5 -3
  61. package/components/List/index.js +5 -3
  62. package/components/List/spec.js +6 -9
  63. package/components/Loading/index.js +1 -3
  64. package/components/Modal/index.js +13 -10
  65. package/components/ModalContainer/spec.js +24 -20
  66. package/components/Picker/components/Button/index.js +18 -12
  67. package/components/Picker/components/List/index.js +19 -16
  68. package/components/Picker/components/Modal/index.js +34 -25
  69. package/components/Picker/index.js +44 -33
  70. package/components/Picker/spec.js +4 -1
  71. package/components/Portal/index.js +26 -17
  72. package/components/ProductCharacteristics/index.js +65 -57
  73. package/components/RangeSlider/components/Handle/index.js +7 -5
  74. package/components/RangeSlider/index.js +98 -84
  75. package/components/Route/RouteNotFound.js +30 -19
  76. package/components/Route/index.js +31 -21
  77. package/components/Router/index.js +51 -34
  78. package/components/ScannerContainer/index.js +17 -10
  79. package/components/Select/components/Item/index.js +5 -3
  80. package/components/Select/index.js +59 -47
  81. package/components/Select/spec.js +7 -6
  82. package/components/SelectBox/components/Item/index.js +23 -13
  83. package/components/SelectBox/index.js +83 -80
  84. package/components/SelectBox/spec.js +8 -5
  85. package/components/SurroundPortals/index.js +15 -11
  86. package/components/Swiper/components/SwiperItem/index.js +6 -5
  87. package/components/Swiper/components/SwiperItem/spec.js +8 -4
  88. package/components/Swiper/index.js +23 -20
  89. package/components/Toaster/index.js +4 -1
  90. package/components/Transition/index.js +19 -12
  91. package/components/Widgets/components/Widget/index.js +27 -16
  92. package/components/Widgets/components/Widget/spec.js +5 -4
  93. package/components/Widgets/components/WidgetGrid/index.js +27 -19
  94. package/components/Widgets/components/WidgetGrid/spec.js +4 -3
  95. package/components/Widgets/index.js +33 -26
  96. package/components/Widgets/spec.js +12 -13
  97. package/helpers/data/index.js +1 -1
  98. package/helpers/portals/portalCollection.js +13 -10
  99. package/helpers/redux/mutable.js +2 -2
  100. package/package.json +5 -5
  101. package/providers/loading/index.js +71 -57
  102. package/providers/toast/index.js +39 -28
  103. package/reducers/modal/index.js +1 -1
  104. package/store/index.js +1 -1
  105. package/subscriptions/helpers/buildRegisterUrl.js +1 -0
  106. package/components/Input/components/DateInput.js +0 -273
@@ -1,20 +1,21 @@
1
1
  import React from 'react';
2
2
  import { shallow } from 'enzyme';
3
3
  import Grid from "./index";
4
+ import { jsx as _jsx } from "react/jsx-runtime";
4
5
  describe('<Grid />', () => {
5
6
  it('should render without any further props', () => {
6
- const wrapper = shallow(/*#__PURE__*/React.createElement(Grid, null));
7
+ const wrapper = shallow(/*#__PURE__*/_jsx(Grid, {}));
7
8
  expect(wrapper).toMatchSnapshot();
8
9
  });
9
10
  it('should be able to render a custom tag', () => {
10
- const wrapper = shallow(/*#__PURE__*/React.createElement(Grid, {
11
+ const wrapper = shallow(/*#__PURE__*/_jsx(Grid, {
11
12
  component: "article"
12
13
  }));
13
14
  expect(wrapper).toMatchSnapshot();
14
15
  expect(wrapper.type()).toEqual('article');
15
16
  });
16
17
  it('should add custom classes on demand', () => {
17
- const wrapper = shallow(/*#__PURE__*/React.createElement(Grid, {
18
+ const wrapper = shallow(/*#__PURE__*/_jsx(Grid, {
18
19
  className: "custom-class-name"
19
20
  }));
20
21
  expect(wrapper).toMatchSnapshot();
@@ -1,3 +1,4 @@
1
+ import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
1
2
  import React, { Component } from 'react';
2
3
  import PropTypes from 'prop-types';
3
4
  import classNames from 'classnames';
@@ -9,47 +10,41 @@ import connect from "./connector";
9
10
  /**
10
11
  * HtmlSanitizer component.
11
12
  */
12
- class HtmlSanitizer extends Component {
13
+ import { jsx as _jsx } from "react/jsx-runtime";
14
+ let HtmlSanitizer = /*#__PURE__*/function (_Component) {
13
15
  /**
14
16
  * @param {Object} props The component props.
15
17
  */
16
- constructor(props) {
17
- super(props);
18
+ function HtmlSanitizer(props) {
19
+ var _this;
20
+ _this = _Component.call(this, props) || this;
18
21
  /**
19
22
  * If the user tapped a link element, prevent the default behavior.
20
23
  * @param {Object} event The touchstart event.
21
24
  */
22
- this.handleTap = event => {
25
+ _this.handleClick = event => {
23
26
  const linkTag = event.target.closest('a');
24
- if (linkTag) {
25
- const {
26
- attributes: {
27
- href: {
28
- value: href = ''
29
- } = {},
30
- target: {
31
- value: target = ''
32
- } = {}
33
- } = {}
34
- } = linkTag;
35
- if (href) {
36
- event.preventDefault();
37
- if (this.props.settings.handleClick) {
38
- this.props.settings.handleClick(href, target);
39
- } else {
40
- this.props.navigate(href, target);
41
- }
42
- }
27
+ if (!linkTag) return;
28
+ const href = linkTag.getAttribute('href');
29
+ const target = linkTag.getAttribute('target') || '';
30
+ if (!href) return;
31
+ event.preventDefault();
32
+ if (_this.props.settings.handleClick) {
33
+ _this.props.settings.handleClick(href, target);
34
+ } else {
35
+ _this.props.navigate(href, target);
43
36
  }
44
37
  };
45
- this.htmlContainer = /*#__PURE__*/React.createRef();
38
+ _this.htmlContainer = /*#__PURE__*/React.createRef();
39
+ return _this;
46
40
  }
47
41
 
48
42
  /**
49
43
  * Registers the event handler for when the user taps inside the html content.
50
44
  */
51
- componentDidMount() {
52
- this.htmlContainer.current.addEventListener('click', this.handleTap, true);
45
+ _inheritsLoose(HtmlSanitizer, _Component);
46
+ var _proto = HtmlSanitizer.prototype;
47
+ _proto.componentDidMount = function componentDidMount() {
53
48
  embeddedMedia.add(this.htmlContainer.current);
54
49
  }
55
50
 
@@ -57,30 +52,29 @@ class HtmlSanitizer extends Component {
57
52
  * Only update if the HTML changed.
58
53
  * @param {Object} nextProps The next props for the component.
59
54
  * @return {boolean}
60
- */
61
- shouldComponentUpdate(nextProps) {
55
+ */;
56
+ _proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
62
57
  return nextProps.children !== this.props.children || nextProps.comfortCookiesAccepted !== this.props.comfortCookiesAccepted || nextProps.statisticsCookiesAccepted !== this.props.statisticsCookiesAccepted;
63
58
  }
64
59
 
65
60
  /**
66
61
  * Updates embedded media within the html container.
67
- */
68
- componentDidUpdate() {
62
+ */;
63
+ _proto.componentDidUpdate = function componentDidUpdate() {
69
64
  embeddedMedia.add(this.htmlContainer.current);
70
65
  }
71
66
 
72
67
  /**
73
68
  * Removes the event handler.
74
- */
75
- componentWillUnmount() {
76
- this.htmlContainer.current.removeEventListener('click', this.handleTap, true);
69
+ */;
70
+ _proto.componentWillUnmount = function componentWillUnmount() {
77
71
  embeddedMedia.remove(this.htmlContainer.current);
78
- }
72
+ };
79
73
  /**
80
74
  * Renders the component.
81
75
  * @returns {JSX}
82
76
  */
83
- render() {
77
+ _proto.render = function render() {
84
78
  const cookieConsentSettings = {
85
79
  comfortCookiesAccepted: this.props.comfortCookiesAccepted,
86
80
  statisticsCookiesAccepted: this.props.statisticsCookiesAccepted
@@ -91,16 +85,19 @@ class HtmlSanitizer extends Component {
91
85
  const {
92
86
  wrapper: Wrapper
93
87
  } = this.props;
94
- return /*#__PURE__*/React.createElement(Wrapper, {
95
- cookieConsentSettings: cookieConsentSettings
96
- }, /*#__PURE__*/React.createElement("div", {
97
- // eslint-disable-next-line react/no-danger
98
- dangerouslySetInnerHTML: innerHTML,
99
- ref: this.htmlContainer,
100
- className: classNames(this.props.className, 'common__html-sanitizer')
101
- }));
102
- }
103
- }
88
+ return /*#__PURE__*/_jsx(Wrapper, {
89
+ cookieConsentSettings: cookieConsentSettings,
90
+ children: /*#__PURE__*/_jsx("div", {
91
+ // eslint-disable-next-line react/no-danger
92
+ dangerouslySetInnerHTML: innerHTML,
93
+ ref: this.htmlContainer,
94
+ className: classNames(this.props.className, 'common__html-sanitizer'),
95
+ onClickCapture: this.handleClick
96
+ })
97
+ });
98
+ };
99
+ return HtmlSanitizer;
100
+ }(Component);
104
101
  HtmlSanitizer.defaultProps = {
105
102
  children: '',
106
103
  className: '',
@@ -1,10 +1,10 @@
1
- import _extends from "@babel/runtime/helpers/extends";
2
1
  /** @jest-environment jsdom */
3
2
 
4
3
  import React from 'react';
5
4
  import { mount } from 'enzyme';
6
5
  import { embeddedMedia } from '@shopgate/pwa-common/collections';
7
6
  import HtmlSanitizer from "./index";
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
8
  jest.mock("../EmbeddedMedia", () => ({
9
9
  children
10
10
  }) => children);
@@ -15,9 +15,11 @@ jest.mock("./connector", () => Cmp => Cmp);
15
15
  * @param {Object} props Component props.
16
16
  * @returns {JSX.Element}
17
17
  */
18
- const createWrapper = (html, props = {}) => mount(/*#__PURE__*/React.createElement(HtmlSanitizer, _extends({
19
- navigate: () => {}
20
- }, props), html));
18
+ const createWrapper = (html, props = {}) => mount(/*#__PURE__*/_jsx(HtmlSanitizer, {
19
+ navigate: () => {},
20
+ ...props,
21
+ children: html
22
+ }));
21
23
  describe('<HtmlSanitizer />', () => {
22
24
  let embeddedMediaAddSpy;
23
25
  let embeddedMediaRemoveSpy;
@@ -130,13 +132,14 @@ describe('<HtmlSanitizer />', () => {
130
132
  const attachNode = document.createElement('div');
131
133
  document.body.appendChild(attachNode);
132
134
  const html = '&lt;a id=&quot;link&quot; href=&quot;#follow-me-and-everything-is-alright&quot;&gt;Plain Link&lt;/a&gt;';
133
- const wrapper = mount(/*#__PURE__*/React.createElement(HtmlSanitizer, {
135
+ const wrapper = mount(/*#__PURE__*/_jsx(HtmlSanitizer, {
134
136
  decode: true,
135
137
  settings: {
136
138
  handleClick: mockedHandleClick
137
139
  },
138
- navigate: () => {}
139
- }, html), {
140
+ navigate: () => {},
141
+ children: html
142
+ }), {
140
143
  attachTo: attachNode
141
144
  });
142
145
  const aTag = attachNode.getElementsByTagName('a')[0];
@@ -145,7 +148,7 @@ describe('<HtmlSanitizer />', () => {
145
148
  target: aTag,
146
149
  preventDefault: () => {}
147
150
  };
148
- wrapper.instance().handleTap(event);
151
+ wrapper.instance().handleClick(event);
149
152
  expect(mockedHandleClick).toHaveBeenCalledTimes(1);
150
153
  expect(mockedHandleClick).toHaveBeenCalledWith('#follow-me-and-everything-is-alright', '');
151
154
  wrapper.unmount();
@@ -155,13 +158,14 @@ describe('<HtmlSanitizer />', () => {
155
158
  const attachNode = document.createElement('div');
156
159
  document.body.appendChild(attachNode);
157
160
  const html = '&lt;a id=&quot;link&quot; target=&quot;_blank&quot; href=&quot;#I-ll-be-the-one-to-tuck-you-in-at-night&quot;&gt;&lt;span&gt;Span Link&lt;/span&gt;&lt;/a&gt;';
158
- const wrapper = mount(/*#__PURE__*/React.createElement(HtmlSanitizer, {
161
+ const wrapper = mount(/*#__PURE__*/_jsx(HtmlSanitizer, {
159
162
  decode: true,
160
163
  settings: {
161
164
  handleClick: mockedHandleClick
162
165
  },
163
- navigate: () => {}
164
- }, html), {
166
+ navigate: () => {},
167
+ children: html
168
+ }), {
165
169
  attachTo: attachNode
166
170
  });
167
171
  const aTag = attachNode.getElementsByTagName('a')[0];
@@ -171,7 +175,7 @@ describe('<HtmlSanitizer />', () => {
171
175
  target: spanTag,
172
176
  preventDefault: () => {}
173
177
  };
174
- wrapper.instance().handleTap(event);
178
+ wrapper.instance().handleClick(event);
175
179
  expect(mockedHandleClick).toHaveBeenCalledTimes(1);
176
180
  expect(mockedHandleClick).toHaveBeenCalledWith('#I-ll-be-the-one-to-tuck-you-in-at-night', '_blank');
177
181
  });
@@ -7,13 +7,16 @@ import { i18n } from '@shopgate/engage/core/helpers/i18n';
7
7
  * @param {Object} props The component props.
8
8
  * @returns {JSX}
9
9
  */
10
+ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
10
11
  const FormatDate = ({
11
12
  timestamp,
12
13
  format
13
- }) => /*#__PURE__*/React.createElement(Fragment, null, FormatDate.format({
14
- timestamp,
15
- format
16
- }));
14
+ }) => /*#__PURE__*/_jsx(_Fragment, {
15
+ children: FormatDate.format({
16
+ timestamp,
17
+ format
18
+ })
19
+ });
17
20
  FormatDate.format = ({
18
21
  timestamp,
19
22
  format
@@ -23,6 +26,10 @@ FormatDate.format = ({
23
26
  }
24
27
  return i18n.date(timestamp, format);
25
28
  };
29
+ FormatDate.propTypes = {
30
+ timestamp: PropTypes.number.isRequired,
31
+ format: PropTypes.string
32
+ };
26
33
  FormatDate.defaultProps = {
27
34
  format: 'medium'
28
35
  };
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import { mount } from 'enzyme';
3
3
  import { i18n } from '@shopgate/engage/core';
4
4
  import I18n from "../../index";
5
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
5
6
  jest.unmock('@shopgate/engage/core/helpers/i18n');
6
7
  describe('<FormatDate />', () => {
7
8
  const locales = {
@@ -18,20 +19,27 @@ describe('<FormatDate />', () => {
18
19
  describe('Given the component was mounted to the DOM', () => {
19
20
  let renderedElement;
20
21
  it('should match snapshot', () => {
21
- renderedElement = mount(/*#__PURE__*/React.createElement(I18n.Provider, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", {
22
- className: "only-date"
23
- }, /*#__PURE__*/React.createElement(I18n.Date, {
24
- timestamp: timestamp,
25
- format: format
26
- })), /*#__PURE__*/React.createElement("span", {
27
- className: "text-with-date"
28
- }, /*#__PURE__*/React.createElement(I18n.Text, {
29
- string: "greeting"
30
- }, /*#__PURE__*/React.createElement(I18n.Date, {
31
- forKey: "date",
32
- timestamp: timestamp,
33
- format: format
34
- }))))));
22
+ renderedElement = mount(/*#__PURE__*/_jsx(I18n.Provider, {
23
+ children: /*#__PURE__*/_jsxs("div", {
24
+ children: [/*#__PURE__*/_jsx("span", {
25
+ className: "only-date",
26
+ children: /*#__PURE__*/_jsx(I18n.Date, {
27
+ timestamp: timestamp,
28
+ format: format
29
+ })
30
+ }), /*#__PURE__*/_jsx("span", {
31
+ className: "text-with-date",
32
+ children: /*#__PURE__*/_jsx(I18n.Text, {
33
+ string: "greeting",
34
+ children: /*#__PURE__*/_jsx(I18n.Date, {
35
+ forKey: "date",
36
+ timestamp: timestamp,
37
+ format: format
38
+ })
39
+ })
40
+ })]
41
+ })
42
+ }));
35
43
  expect(renderedElement).toMatchSnapshot();
36
44
  });
37
45
  it('should render formatted date', () => {
@@ -6,6 +6,7 @@ import { i18n } from '@shopgate/engage/core/helpers/i18n';
6
6
  * @param {Object} props The component props.
7
7
  * @returns {JSX}
8
8
  */
9
+ import { jsx as _jsx } from "react/jsx-runtime";
9
10
  const FormatNumber = ({
10
11
  className,
11
12
  number,
@@ -17,12 +18,13 @@ const FormatNumber = ({
17
18
  fractions
18
19
  });
19
20
  }
20
- return /*#__PURE__*/React.createElement("span", {
21
- className: className
22
- }, FormatNumber.format({
23
- number,
24
- fractions
25
- }));
21
+ return /*#__PURE__*/_jsx("span", {
22
+ className: className,
23
+ children: FormatNumber.format({
24
+ number,
25
+ fractions
26
+ })
27
+ });
26
28
  };
27
29
  FormatNumber.format = props => {
28
30
  if (!i18n.ready) {
@@ -3,11 +3,12 @@ import { mount } from 'enzyme';
3
3
  import { i18n } from '@shopgate/engage/core';
4
4
  import I18n from "../../index";
5
5
  import FormatNumber from "./index";
6
+ import { jsx as _jsx } from "react/jsx-runtime";
6
7
  jest.unmock('@shopgate/engage/core/helpers/i18n');
7
8
  describe('<FormatNumber>', () => {
8
9
  describe('i18n not ready', () => {
9
10
  it('should return same number and className when i18n is not ready', () => {
10
- const component = mount(/*#__PURE__*/React.createElement(FormatNumber, {
11
+ const component = mount(/*#__PURE__*/_jsx(FormatNumber, {
11
12
  number: 1,
12
13
  fractions: 2,
13
14
  className: "some-class"
@@ -30,10 +31,14 @@ describe('<FormatNumber>', () => {
30
31
  * @param {number} fractions Decimal points.
31
32
  * @returns {Object}
32
33
  */
33
- const makeComponent = (number, fractions) => mount(/*#__PURE__*/React.createElement(I18n.Provider, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(FormatNumber, {
34
- number: number,
35
- fractions: fractions
36
- }))));
34
+ const makeComponent = (number, fractions) => mount(/*#__PURE__*/_jsx(I18n.Provider, {
35
+ children: /*#__PURE__*/_jsx("div", {
36
+ children: /*#__PURE__*/_jsx(FormatNumber, {
37
+ number: number,
38
+ fractions: fractions
39
+ })
40
+ })
41
+ }));
37
42
  pairs.forEach(([input, expexted, fractions]) => {
38
43
  it(`should format ${input} into ${expexted}`, () => {
39
44
  const component = makeComponent(input, fractions);
@@ -6,6 +6,7 @@ import { i18n } from '@shopgate/engage/core/helpers/i18n';
6
6
  * @param {Object} props The component props.
7
7
  * @returns {JSX}
8
8
  */
9
+ import { jsx as _jsx } from "react/jsx-runtime";
9
10
  const FormatPrice = props => {
10
11
  const {
11
12
  className,
@@ -14,9 +15,10 @@ const FormatPrice = props => {
14
15
  if (!className) {
15
16
  return FormatPrice.format(formatProps);
16
17
  }
17
- return /*#__PURE__*/React.createElement("span", {
18
- className: className
19
- }, FormatPrice.format(formatProps));
18
+ return /*#__PURE__*/_jsx("span", {
19
+ className: className,
20
+ children: FormatPrice.format(formatProps)
21
+ });
20
22
  };
21
23
  FormatPrice.format = ({
22
24
  price,
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import { mount } from 'enzyme';
3
3
  import { i18n } from '@shopgate/engage/core';
4
4
  import I18n from "../../index";
5
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
5
6
  jest.unmock('@shopgate/engage/core/helpers/i18n');
6
7
  describe('<FormatPrice />', () => {
7
8
  const locales = {
@@ -18,20 +19,27 @@ describe('<FormatPrice />', () => {
18
19
  describe('Given the component was mounted to the DOM', () => {
19
20
  let renderedElement;
20
21
  it('should match snapshot', () => {
21
- renderedElement = mount(/*#__PURE__*/React.createElement(I18n.Provider, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", {
22
- className: "only-price"
23
- }, /*#__PURE__*/React.createElement(I18n.Price, {
24
- price: price,
25
- currency: currency
26
- })), /*#__PURE__*/React.createElement("span", {
27
- className: "text-with-price"
28
- }, /*#__PURE__*/React.createElement(I18n.Text, {
29
- string: "greeting"
30
- }, /*#__PURE__*/React.createElement(I18n.Price, {
31
- forKey: "price",
32
- price: price,
33
- currency: currency
34
- }))))));
22
+ renderedElement = mount(/*#__PURE__*/_jsx(I18n.Provider, {
23
+ children: /*#__PURE__*/_jsxs("div", {
24
+ children: [/*#__PURE__*/_jsx("span", {
25
+ className: "only-price",
26
+ children: /*#__PURE__*/_jsx(I18n.Price, {
27
+ price: price,
28
+ currency: currency
29
+ })
30
+ }), /*#__PURE__*/_jsx("span", {
31
+ className: "text-with-price",
32
+ children: /*#__PURE__*/_jsx(I18n.Text, {
33
+ string: "greeting",
34
+ children: /*#__PURE__*/_jsx(I18n.Price, {
35
+ forKey: "price",
36
+ price: price,
37
+ currency: currency
38
+ })
39
+ })
40
+ })]
41
+ })
42
+ }));
35
43
  expect(renderedElement).toMatchSnapshot();
36
44
  });
37
45
  it('should render formatted price', () => {
@@ -7,13 +7,16 @@ import { i18n } from '@shopgate/engage/core/helpers/i18n';
7
7
  * @param {Object} props The component props.
8
8
  * @returns {JSX}
9
9
  */
10
+ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
10
11
  const FormatTime = ({
11
12
  timestamp,
12
13
  format
13
- }) => /*#__PURE__*/React.createElement(Fragment, null, FormatTime.format({
14
- timestamp,
15
- format
16
- }));
14
+ }) => /*#__PURE__*/_jsx(_Fragment, {
15
+ children: FormatTime.format({
16
+ timestamp,
17
+ format
18
+ })
19
+ });
17
20
  FormatTime.format = ({
18
21
  timestamp,
19
22
  format
@@ -23,6 +26,10 @@ FormatTime.format = ({
23
26
  }
24
27
  return i18n.time(timestamp, format);
25
28
  };
29
+ FormatTime.propTypes = {
30
+ timestamp: PropTypes.number.isRequired,
31
+ format: PropTypes.string
32
+ };
26
33
  FormatTime.defaultProps = {
27
34
  format: 'medium'
28
35
  };
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import { mount } from 'enzyme';
3
3
  import { i18n } from '@shopgate/engage/core';
4
4
  import I18n from "../../index";
5
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
5
6
  jest.unmock('@shopgate/engage/core/helpers/i18n');
6
7
  describe('<FormatTime />', () => {
7
8
  const locales = {
@@ -17,20 +18,27 @@ describe('<FormatTime />', () => {
17
18
  });
18
19
  describe('Given the component was mounted to the DOM', () => {
19
20
  // TODO: Handle snapshot test.
20
- const renderedElement = mount(/*#__PURE__*/React.createElement(I18n.Provider, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", {
21
- className: "only-time"
22
- }, /*#__PURE__*/React.createElement(I18n.Time, {
23
- timestamp: timestamp,
24
- format: format
25
- })), /*#__PURE__*/React.createElement("span", {
26
- className: "text-with-time"
27
- }, /*#__PURE__*/React.createElement(I18n.Text, {
28
- string: "greeting"
29
- }, /*#__PURE__*/React.createElement(I18n.Time, {
30
- forKey: "time",
31
- timestamp: timestamp,
32
- format: format
33
- }))))));
21
+ const renderedElement = mount(/*#__PURE__*/_jsx(I18n.Provider, {
22
+ children: /*#__PURE__*/_jsxs("div", {
23
+ children: [/*#__PURE__*/_jsx("span", {
24
+ className: "only-time",
25
+ children: /*#__PURE__*/_jsx(I18n.Time, {
26
+ timestamp: timestamp,
27
+ format: format
28
+ })
29
+ }), /*#__PURE__*/_jsx("span", {
30
+ className: "text-with-time",
31
+ children: /*#__PURE__*/_jsx(I18n.Text, {
32
+ string: "greeting",
33
+ children: /*#__PURE__*/_jsx(I18n.Time, {
34
+ forKey: "time",
35
+ timestamp: timestamp,
36
+ format: format
37
+ })
38
+ })
39
+ })]
40
+ })
41
+ }));
34
42
  it('should render formatted time', () => {
35
43
  const text = renderedElement.find('.only-time').text();
36
44
  expect(text).toBe(formattedTime);
@@ -1,3 +1,4 @@
1
+ import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
1
2
  import React, { Component } from 'react';
2
3
  import PropTypes from 'prop-types';
3
4
  import { i18n } from '@shopgate/engage/core/helpers/i18n';
@@ -7,53 +8,59 @@ import { logger } from '@shopgate/pwa-core/helpers';
7
8
  * A React component that provides child components with i18n features.
8
9
  * @returns {React.Component}
9
10
  */
10
- export default class I18nProvider extends Component {
11
+ let I18nProvider = /*#__PURE__*/function (_Component) {
11
12
  /**
12
13
  * @inheritDoc
13
14
  */
14
- constructor(props) {
15
- super(props);
15
+ function I18nProvider(props) {
16
+ var _this;
17
+ _this = _Component.call(this, props) || this;
16
18
  // eslint-disable-next-line react/prop-types
17
19
  /**
18
20
  * Gets a shortcut to i18n functionality with preset language.
19
21
  * @returns {Object}
20
22
  */
21
- this.getI18nInstance = () => ({
23
+ _this.getI18nInstance = () => ({
22
24
  __: i18n.text,
23
25
  _p: i18n.price,
24
26
  _d: i18n.date,
25
27
  _t: i18n.time,
26
28
  _n: i18n.number
27
29
  });
28
- if (this.props.lang || this.props.locales) {
30
+ if (_this.props.lang || _this.props.locales) {
29
31
  logger.warn(`===== I18nProvider deprecated =====\nI18nProvider and it's related components (@shopgate/pwa-common/component/I18n) or context types are deprecated and will be removed in @shopgate/engage v7.0.0.\nPlease use { i18n } from @shopgate/engage/core.\n===================================
30
32
  `);
31
33
  }
34
+ return _this;
32
35
  }
33
36
 
34
37
  /**
35
38
  * Provides context for child components.
36
39
  * @returns {Object}
37
40
  */
38
- getChildContext() {
41
+ _inheritsLoose(I18nProvider, _Component);
42
+ var _proto = I18nProvider.prototype;
43
+ _proto.getChildContext = function getChildContext() {
39
44
  return {
40
45
  i18n: this.getI18nInstance
41
46
  };
42
- }
47
+ };
43
48
  /**
44
49
  * Renders the component.
45
50
  * @returns {JSX}
46
51
  */
47
- render() {
52
+ _proto.render = function render() {
48
53
  const {
49
54
  children
50
55
  } = this.props;
51
56
  return children ? /*#__PURE__*/React.cloneElement(children) : null;
52
- }
53
- }
57
+ };
58
+ return I18nProvider;
59
+ }(Component);
54
60
  I18nProvider.childContextTypes = {
55
61
  i18n: PropTypes.func.isRequired
56
62
  };
57
63
  I18nProvider.defaultProps = {
58
64
  children: null
59
- };
65
+ };
66
+ export { I18nProvider as default };
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import { shallow } from 'enzyme';
3
3
  import { i18n as i18nHelper } from '@shopgate/engage/core';
4
4
  import I18nProvider from "./index";
5
+ import { jsx as _jsx } from "react/jsx-runtime";
5
6
  jest.unmock('@shopgate/engage/core/helpers/i18n');
6
7
  describe('<I18nProvider />', () => {
7
8
  const locales = {
@@ -16,7 +17,7 @@ describe('<I18nProvider />', () => {
16
17
  let renderedElement;
17
18
  let renderedInstance;
18
19
  it('should match snapshot', () => {
19
- renderedElement = shallow(/*#__PURE__*/React.createElement(I18nProvider, null));
20
+ renderedElement = shallow(/*#__PURE__*/_jsx(I18nProvider, {}));
20
21
  renderedInstance = renderedElement.instance();
21
22
  expect(renderedElement).toMatchSnapshot();
22
23
  });