@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,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import { shallow, mount } from 'enzyme';
3
3
  import { Disconnected as Link } from "./index";
4
+ import { jsx as _jsx } from "react/jsx-runtime";
4
5
  describe('<Link />', () => {
5
6
  const historyPush = jest.fn();
6
7
  const historyReplace = jest.fn();
@@ -16,21 +17,23 @@ describe('<Link />', () => {
16
17
  jest.useRealTimers();
17
18
  });
18
19
  it('renders with children', () => {
19
- const wrapper = shallow(/*#__PURE__*/React.createElement(Link, {
20
+ const wrapper = shallow(/*#__PURE__*/_jsx(Link, {
20
21
  href: pathname,
21
22
  historyPush: historyPush,
22
- historyReplace: historyReplace
23
- }, /*#__PURE__*/React.createElement("span", null)));
23
+ historyReplace: historyReplace,
24
+ children: /*#__PURE__*/_jsx("span", {})
25
+ }));
24
26
  expect(wrapper).toMatchSnapshot();
25
27
  expect(wrapper.find('span').length).toBe(1);
26
28
  });
27
29
  it('handles a push', () => {
28
- const wrapper = mount(/*#__PURE__*/React.createElement(Link, {
30
+ const wrapper = mount(/*#__PURE__*/_jsx(Link, {
29
31
  href: pathname,
30
32
  state: state,
31
33
  historyPush: historyPush,
32
- historyReplace: historyReplace
33
- }, /*#__PURE__*/React.createElement("span", null)));
34
+ historyReplace: historyReplace,
35
+ children: /*#__PURE__*/_jsx("span", {})
36
+ }));
34
37
  wrapper.find('div').simulate('click');
35
38
  jest.runAllTimers();
36
39
  expect(historyPush).toHaveBeenLastCalledWith({
@@ -39,13 +42,14 @@ describe('<Link />', () => {
39
42
  });
40
43
  });
41
44
  it('handles a replace', () => {
42
- const wrapper = mount(/*#__PURE__*/React.createElement(Link, {
45
+ const wrapper = mount(/*#__PURE__*/_jsx(Link, {
43
46
  href: pathname,
44
47
  historyPush: historyPush,
45
48
  historyReplace: historyReplace,
46
49
  state: state,
47
- replace: true
48
- }, /*#__PURE__*/React.createElement("span", null)));
50
+ replace: true,
51
+ children: /*#__PURE__*/_jsx("span", {})
52
+ }));
49
53
  wrapper.find('div').simulate('click');
50
54
  jest.runAllTimers();
51
55
  expect(historyReplace).toHaveBeenLastCalledWith({
@@ -6,6 +6,7 @@ import styles from "./style";
6
6
  * The ListItem component.
7
7
  * @returns {JSX}
8
8
  */
9
+ import { jsx as _jsx } from "react/jsx-runtime";
9
10
  const ListItem = ({
10
11
  children,
11
12
  className,
@@ -22,11 +23,12 @@ const ListItem = ({
22
23
 
23
24
  // Add selected or unselected styling.
24
25
  classes += ` common__list__list-item ${isSelected ? styles.selected : styles.unselected}`;
25
- return /*#__PURE__*/React.createElement("li", {
26
+ return /*#__PURE__*/_jsx("li", {
26
27
  className: classes,
27
28
  "data-test-id": "listItem",
28
- role: role
29
- }, children);
29
+ role: role,
30
+ children: children
31
+ });
30
32
  };
31
33
  ListItem.defaultProps = {
32
34
  className: null,
@@ -7,14 +7,16 @@ import ListItem from "./components/Item";
7
7
  * @param {Object} props The component props.
8
8
  * @returns {JSX}
9
9
  */
10
+ import { jsx as _jsx } from "react/jsx-runtime";
10
11
  const List = ({
11
12
  children,
12
13
  className,
13
14
  role
14
- }) => /*#__PURE__*/React.createElement("ul", {
15
+ }) => /*#__PURE__*/_jsx("ul", {
15
16
  className: `${className} common_list`,
16
- role: role
17
- }, children);
17
+ role: role,
18
+ children: children
19
+ });
18
20
  List.Item = ListItem;
19
21
  List.defaultProps = {
20
22
  className: '',
@@ -2,27 +2,24 @@
2
2
  import React from 'react';
3
3
  import { shallow } from 'enzyme';
4
4
  import List from "./index";
5
+ import { jsx as _jsx } from "react/jsx-runtime";
5
6
  console.error = jest.fn();
6
7
  describe('<List />', () => {
7
- const children = [/*#__PURE__*/React.createElement(List.Item, {
8
- key: "0"
9
- }), /*#__PURE__*/React.createElement(List.Item, {
10
- key: "1"
11
- }), /*#__PURE__*/React.createElement(List.Item, {
12
- key: "2"
13
- })];
8
+ const children = [/*#__PURE__*/_jsx(List.Item, {}, "0"), /*#__PURE__*/_jsx(List.Item, {}, "1"), /*#__PURE__*/_jsx(List.Item, {}, "2")];
14
9
  beforeEach(() => {
15
10
  jest.clearAllMocks();
16
11
  });
17
12
  it('renders with children', () => {
18
13
  const numChildren = children.length;
19
- const wrapper = shallow(/*#__PURE__*/React.createElement(List, null, children));
14
+ const wrapper = shallow(/*#__PURE__*/_jsx(List, {
15
+ children: children
16
+ }));
20
17
  expect(wrapper).toMatchSnapshot();
21
18
  expect(wrapper.find(List.Item).length).toBe(numChildren);
22
19
  expect(console.error).not.toHaveBeenCalled();
23
20
  });
24
21
  it('renders without children', () => {
25
- const wrapper = shallow(/*#__PURE__*/React.createElement(List, null));
22
+ const wrapper = shallow(/*#__PURE__*/_jsx(List, {}));
26
23
  expect(wrapper).toMatchSnapshot();
27
24
  expect(wrapper.find(List.Item).length).toBe(0);
28
25
  expect(console.error).toHaveBeenCalledTimes(1);
@@ -1,7 +1,5 @@
1
- import React, { Fragment } from 'react';
2
-
3
1
  /**
4
2
  * @return {null}
5
3
  */
6
- const Loading = () => /*#__PURE__*/React.createElement(Fragment, null, null);
4
+ const Loading = () => null;
7
5
  export default Loading;
@@ -1,4 +1,3 @@
1
- import _extends from "@babel/runtime/helpers/extends";
2
1
  import React, { forwardRef } from 'react';
3
2
  import PropTypes from 'prop-types';
4
3
  import { createPortal } from 'react-dom';
@@ -12,6 +11,7 @@ import styles from "./style";
12
11
  * @param {Object} props.classes The component classes.
13
12
  * @returns {JSX.Element}
14
13
  */
14
+ import { jsx as _jsx } from "react/jsx-runtime";
15
15
  const Modal = /*#__PURE__*/forwardRef(({
16
16
  children,
17
17
  classes,
@@ -19,17 +19,20 @@ const Modal = /*#__PURE__*/forwardRef(({
19
19
  }, ref) => {
20
20
  // Track modal visibility for accessibility purposes.
21
21
  useTrackModalState();
22
- return /*#__PURE__*/createPortal(/*#__PURE__*/React.createElement("div", _extends({
22
+ return /*#__PURE__*/createPortal(/*#__PURE__*/_jsx("div", {
23
23
  className: classNames(styles.container, classes?.container, 'common__modal'),
24
24
  role: "alertdialog",
25
- "aria-modal": true
26
- }, props, {
27
- ref: ref
28
- }), /*#__PURE__*/React.createElement("div", {
29
- className: classNames(styles.layout, classes?.layout)
30
- }, /*#__PURE__*/React.createElement("div", {
31
- className: classNames(styles.content, classes?.content)
32
- }, children))), document.getElementById('portals'));
25
+ "aria-modal": true,
26
+ ...props,
27
+ ref: ref,
28
+ children: /*#__PURE__*/_jsx("div", {
29
+ className: classNames(styles.layout, classes?.layout),
30
+ children: /*#__PURE__*/_jsx("div", {
31
+ className: classNames(styles.content, classes?.content),
32
+ children: children
33
+ })
34
+ })
35
+ }), document.getElementById('portals'));
33
36
  });
34
37
  Modal.defaultProps = {
35
38
  children: null,
@@ -1,4 +1,4 @@
1
- /* eslint-disable no-unused-vars */
1
+ /* eslint-disable no-unused-vars, jsx-a11y/control-has-associated-label */
2
2
  import React from 'react';
3
3
  import { mount } from 'enzyme';
4
4
  import { Provider } from 'react-redux';
@@ -9,6 +9,7 @@ import ModalContainer from "./index";
9
9
 
10
10
  // const store = configureStore({ modal: modalReducer });
11
11
  // Replacement for commented out configureStore()
12
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
12
13
  const store = {};
13
14
  jest.mock('redux-logger', () => ({
14
15
  createLogger: () => () => next => action => next(action)
@@ -25,17 +26,18 @@ const MockModal = ({
25
26
  onConfirm,
26
27
  // eslint-disable-line react/prop-types
27
28
  onDismiss // eslint-disable-line react/prop-types
28
- }) => /*#__PURE__*/React.createElement("div", {
29
- className: "modal"
30
- }, /*#__PURE__*/React.createElement("button", {
31
- className: "confirmBtn",
32
- onClick: onConfirm,
33
- type: "button"
34
- }), /*#__PURE__*/React.createElement("button", {
35
- className: "dismissBtn",
36
- onClick: onDismiss,
37
- type: "button"
38
- }));
29
+ }) => /*#__PURE__*/_jsxs("div", {
30
+ className: "modal",
31
+ children: [/*#__PURE__*/_jsx("button", {
32
+ className: "confirmBtn",
33
+ onClick: onConfirm,
34
+ type: "button"
35
+ }), /*#__PURE__*/_jsx("button", {
36
+ className: "dismissBtn",
37
+ onClick: onDismiss,
38
+ type: "button"
39
+ })]
40
+ });
39
41
  describe.skip('<ModalContainer />', () => {
40
42
  let renderedElement;
41
43
  const {
@@ -47,13 +49,15 @@ describe.skip('<ModalContainer />', () => {
47
49
  * The rendered component.
48
50
  */
49
51
  const renderComponent = () => {
50
- renderedElement = mount(/*#__PURE__*/React.createElement(Provider, {
51
- store: store
52
- }, /*#__PURE__*/React.createElement("div", {
53
- id: "container"
54
- }, /*#__PURE__*/React.createElement(ModalContainer, {
55
- component: MockModal
56
- }))));
52
+ renderedElement = mount(/*#__PURE__*/_jsx(Provider, {
53
+ store: store,
54
+ children: /*#__PURE__*/_jsx("div", {
55
+ id: "container",
56
+ children: /*#__PURE__*/_jsx(ModalContainer, {
57
+ component: MockModal
58
+ })
59
+ })
60
+ }));
57
61
  };
58
62
  beforeEach(() => {
59
63
  // Reset the modals state before each test.
@@ -108,4 +112,4 @@ describe.skip('<ModalContainer />', () => {
108
112
  });
109
113
  });
110
114
 
111
- /* eslint-enable no-unused-vars */
115
+ /* eslint-enable no-unused-vars, jsx-a11y/control-has-associated-label */
@@ -6,29 +6,35 @@ import styles from "./style";
6
6
  * The default button for the Picker component.
7
7
  * @returns {JSX} The button component.
8
8
  */
9
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
9
10
  const PickerButton = ({
10
11
  value,
11
12
  label,
12
13
  openList
13
14
  }) => {
14
15
  if (value !== null) {
15
- return /*#__PURE__*/React.createElement("button", {
16
+ return /*#__PURE__*/_jsxs("button", {
16
17
  className: styles.button,
17
18
  onClick: openList,
18
- type: "button"
19
- }, /*#__PURE__*/React.createElement("span", {
20
- className: styles.label
21
- }, label), /*#__PURE__*/React.createElement("span", {
22
- className: styles.value
23
- }, value));
19
+ type: "button",
20
+ children: [/*#__PURE__*/_jsx("span", {
21
+ className: styles.label,
22
+ children: label
23
+ }), /*#__PURE__*/_jsx("span", {
24
+ className: styles.value,
25
+ children: value
26
+ })]
27
+ });
24
28
  }
25
- return /*#__PURE__*/React.createElement("button", {
29
+ return /*#__PURE__*/_jsx("button", {
26
30
  className: styles.button,
27
31
  onClick: openList,
28
- type: "button"
29
- }, /*#__PURE__*/React.createElement("span", {
30
- className: styles.label
31
- }, label));
32
+ type: "button",
33
+ children: /*#__PURE__*/_jsx("span", {
34
+ className: styles.label,
35
+ children: label
36
+ })
37
+ });
32
38
  };
33
39
  PickerButton.defaultProps = {
34
40
  value: null
@@ -7,27 +7,30 @@ import styles from "./style";
7
7
  * The default button for the Picker component.
8
8
  * @returns {JSX} The button component.
9
9
  */
10
+ import { jsx as _jsx } from "react/jsx-runtime";
10
11
  const PickerList = ({
11
12
  items,
12
13
  onClose,
13
14
  onSelect,
14
15
  selectedIndex
15
- }) => /*#__PURE__*/React.createElement("ul", {
16
- className: "common__picker__list"
17
- }, items.map((item, currentIndex) => /*#__PURE__*/React.createElement("li", {
18
- key: item.value,
19
- className: classNames({
20
- [styles.active]: currentIndex === selectedIndex
21
- })
22
- }, /*#__PURE__*/React.createElement("button", {
23
- className: styles.button,
24
- disabled: item.disabled,
25
- onClick: () => {
26
- onSelect(item.value);
27
- onClose();
28
- },
29
- type: "button"
30
- }, item.label))));
16
+ }) => /*#__PURE__*/_jsx("ul", {
17
+ className: "common__picker__list",
18
+ children: items.map((item, currentIndex) => /*#__PURE__*/_jsx("li", {
19
+ className: classNames({
20
+ [styles.active]: currentIndex === selectedIndex
21
+ }),
22
+ children: /*#__PURE__*/_jsx("button", {
23
+ className: styles.button,
24
+ disabled: item.disabled,
25
+ onClick: () => {
26
+ onSelect(item.value);
27
+ onClose();
28
+ },
29
+ type: "button",
30
+ children: item.label
31
+ })
32
+ }, item.value))
33
+ });
31
34
  PickerList.defaultProps = {
32
35
  onClose: () => {},
33
36
  selectedIndex: null
@@ -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';
@@ -6,62 +7,70 @@ import styles from "./style";
6
7
  /**
7
8
  * The picker modal.
8
9
  */
9
- class PickerModal extends Component {
10
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
+ let PickerModal = /*#__PURE__*/function (_Component) {
10
12
  /**
11
13
  * The constructor.
12
14
  * @param {Object} props The props.
13
15
  */
14
- constructor(props) {
15
- super(props);
16
+ function PickerModal(props) {
17
+ var _this;
18
+ _this = _Component.call(this, props) || this;
16
19
  /**
17
20
  * Closes the modal after the closing animations have finished.
18
21
  */
19
- this.closeModal = () => {
20
- this.setState({
22
+ _this.closeModal = () => {
23
+ _this.setState({
21
24
  active: false
22
25
  });
23
- clearTimeout(this.timeout);
24
- this.timeout = setTimeout(this.props.onClose, styles.duration);
26
+ clearTimeout(_this.timeout);
27
+ _this.timeout = setTimeout(_this.props.onClose, styles.duration);
25
28
  };
26
- this.timeout = null;
27
- this.state = {
29
+ _this.timeout = null;
30
+ _this.state = {
28
31
  active: true
29
32
  };
33
+ return _this;
30
34
  }
31
35
 
32
36
  /**
33
37
  * Update state when isOpen changes.
34
38
  * @param {Object} nextProps The next component props.
35
39
  */
36
- UNSAFE_componentWillReceiveProps(nextProps) {
40
+ _inheritsLoose(PickerModal, _Component);
41
+ var _proto = PickerModal.prototype;
42
+ _proto.UNSAFE_componentWillReceiveProps = function UNSAFE_componentWillReceiveProps(nextProps) {
37
43
  if (this.props.isOpen !== nextProps.isOpen) {
38
44
  this.setState({
39
45
  active: nextProps.isOpen
40
46
  });
41
47
  }
42
- }
48
+ };
43
49
  /**
44
50
  * Render all the things!
45
51
  * @returns {JSX} The picker modal with the picker list inside.
46
52
  */
47
- render() {
53
+ _proto.render = function render() {
48
54
  const backgroundClassName = classNames(styles.background.base, {
49
55
  [styles.background.inactive]: !this.state.active
50
56
  });
51
57
  const containerClassName = classNames(styles.container.base, {
52
58
  [styles.container.inactive]: !this.state.active
53
59
  });
54
- return this.props.isOpen ? /*#__PURE__*/React.createElement("div", {
55
- className: `${styles.wrapper} common__picker__modal`
56
- }, /*#__PURE__*/React.createElement("div", {
57
- "aria-hidden": true,
58
- className: backgroundClassName,
59
- onClick: this.closeModal
60
- }), /*#__PURE__*/React.createElement("div", {
61
- className: containerClassName
62
- }, /*#__PURE__*/React.cloneElement(this.props.children, {
63
- onClose: this.closeModal
64
- }))) : null;
65
- }
66
- }
60
+ return this.props.isOpen ? /*#__PURE__*/_jsxs("div", {
61
+ className: `${styles.wrapper} common__picker__modal`,
62
+ children: [/*#__PURE__*/_jsx("div", {
63
+ "aria-hidden": true,
64
+ className: backgroundClassName,
65
+ onClick: this.closeModal
66
+ }), /*#__PURE__*/_jsx("div", {
67
+ className: containerClassName,
68
+ children: /*#__PURE__*/React.cloneElement(this.props.children, {
69
+ onClose: this.closeModal
70
+ })
71
+ })]
72
+ }) : null;
73
+ };
74
+ return PickerModal;
75
+ }(Component);
67
76
  export default PickerModal;
@@ -1,3 +1,5 @@
1
+ import _createClass from "@babel/runtime/helpers/createClass";
2
+ import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
1
3
  import React, { Component } from 'react';
2
4
  import PropTypes from 'prop-types';
3
5
  import { ConnectedReactPortal } from '@shopgate/engage/components';
@@ -13,6 +15,7 @@ import PickerList from "./components/List";
13
15
  * @returns {Object} An object representation of the item.
14
16
  * @deprecated Use Picker from engage instead
15
17
  */
18
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
16
19
  const normalizeItem = item => {
17
20
  if (item !== null && typeof item !== 'undefined') {
18
21
  const itemDefaults = {
@@ -44,69 +47,73 @@ const findItemIndexByValue = (items, value) => items.map(normalizeItem).findInde
44
47
  * @deprecated Will be remove in Engage v7.0.0.
45
48
  * Please use `import { Picker } from '@shopgate/engage/components'` instead.
46
49
  */
47
- class Picker extends Component {
50
+ let Picker = /*#__PURE__*/function (_Component) {
48
51
  /**
49
52
  * The constructor.
50
53
  * @param {Object} props - The component props.
51
54
  */
52
- constructor(props) {
53
- super(props);
55
+ function Picker(props) {
56
+ var _this;
57
+ _this = _Component.call(this, props) || this;
54
58
  /**
55
59
  * Triggers the onChange callback if the selected value has changed.
56
60
  * @param {Object} nextValue - The value the user picked.
57
61
  */
58
- this.triggerChangeCallback = nextValue => {
59
- const nextSelectedIndex = findItemIndexByValue(this.props.items, nextValue);
60
- if (nextSelectedIndex > -1 && this.state.selectedIndex !== nextSelectedIndex) {
61
- this.props.onChange(nextValue);
62
+ _this.triggerChangeCallback = nextValue => {
63
+ const nextSelectedIndex = findItemIndexByValue(_this.props.items, nextValue);
64
+ if (nextSelectedIndex > -1 && _this.state.selectedIndex !== nextSelectedIndex) {
65
+ _this.props.onChange(nextValue);
62
66
  }
63
- this.props.onSelect(nextValue);
67
+ _this.props.onSelect(nextValue);
64
68
  };
65
69
  /**
66
70
  * Triggers the onChange callback if the selected value has changed.
67
71
  * @param {Object} nextOpenState - The value the user picked.
68
72
  */
69
- this.triggerCloseCallback = nextOpenState => {
70
- if (this.state.isOpen && !nextOpenState) {
71
- this.props.onClose();
73
+ _this.triggerCloseCallback = nextOpenState => {
74
+ if (_this.state.isOpen && !nextOpenState) {
75
+ _this.props.onClose();
72
76
  }
73
77
  };
74
78
  /**
75
79
  * Gets called when a new item is selected
76
80
  * @param {string} value - The selected value.
77
81
  */
78
- this.handleItemSelect = value => {
79
- this.triggerChangeCallback(value);
80
- this.setState({
81
- selectedIndex: findItemIndexByValue(this.props.items, value)
82
+ _this.handleItemSelect = value => {
83
+ _this.triggerChangeCallback(value);
84
+ _this.setState({
85
+ selectedIndex: findItemIndexByValue(_this.props.items, value)
82
86
  });
83
87
  };
84
88
  /**
85
89
  * Sets or toggles the open state of the component.
86
90
  * @param {boolean} [open] New open state.
87
91
  */
88
- this.toggleOpenState = open => {
89
- this.setState(({
92
+ _this.toggleOpenState = open => {
93
+ _this.setState(({
90
94
  isOpen
91
95
  }) => {
92
96
  const nextIsOpen = typeof open === 'boolean' ? open : !isOpen;
93
- this.triggerCloseCallback(nextIsOpen);
97
+ _this.triggerCloseCallback(nextIsOpen);
94
98
  return {
95
99
  isOpen: nextIsOpen
96
100
  };
97
101
  });
98
102
  };
99
- this.state = {
103
+ _this.state = {
100
104
  selectedIndex: findItemIndexByValue(props.items, props.value),
101
105
  isOpen: props.isOpen
102
106
  };
107
+ return _this;
103
108
  }
104
109
 
105
110
  /**
106
111
  * Updates the selected item when the value prop changes.
107
112
  * @param {Object} nextProps - The next props.
108
113
  */
109
- UNSAFE_componentWillReceiveProps(nextProps) {
114
+ _inheritsLoose(Picker, _Component);
115
+ var _proto = Picker.prototype;
116
+ _proto.UNSAFE_componentWillReceiveProps = function UNSAFE_componentWillReceiveProps(nextProps) {
110
117
  // Only update if a value is present and also changed.
111
118
  if (!this.selectedItem || nextProps.value !== this.selectedItem.value) {
112
119
  this.setState({
@@ -122,15 +129,12 @@ class Picker extends Component {
122
129
 
123
130
  /**
124
131
  * Getter for the selected item.
125
- */
126
- get selectedItem() {
127
- return normalizeItem(this.props.items[this.state.selectedIndex]);
128
- }
132
+ */;
129
133
  /**
130
134
  * Renders the component.
131
135
  * @returns {JSX}
132
136
  */
133
- render() {
137
+ _proto.render = function render() {
134
138
  const hasSelection = !!this.selectedItem;
135
139
  const buttonValue = hasSelection ? this.selectedItem.label : '';
136
140
  const buttonLabel = hasSelection ? this.props.label : this.props.placeholder;
@@ -153,18 +157,25 @@ class Picker extends Component {
153
157
  selectedIndex: this.state.selectedIndex,
154
158
  onSelect: this.handleItemSelect
155
159
  };
156
- return /*#__PURE__*/React.createElement("div", {
160
+ return /*#__PURE__*/_jsxs("div", {
157
161
  role: "button",
158
162
  className: `${this.props.className} common__picker`,
159
163
  ref: this.props.forwardedRef,
160
164
  tabIndex: 0,
161
- "aria-haspopup": true
162
- }, /*#__PURE__*/React.createElement(this.props.buttonComponent, buttonProps), /*#__PURE__*/React.createElement(ConnectedReactPortal, {
163
- onClose: () => this.toggleOpenState(false),
164
- isOpened: true
165
- }, /*#__PURE__*/React.createElement(this.props.modalComponent, modalProps, /*#__PURE__*/React.createElement(this.props.listComponent, listProps))));
166
- }
167
- }
165
+ "aria-haspopup": true,
166
+ children: [/*#__PURE__*/React.createElement(this.props.buttonComponent, buttonProps), /*#__PURE__*/_jsx(ConnectedReactPortal, {
167
+ isOpened: true,
168
+ children: /*#__PURE__*/React.createElement(this.props.modalComponent, modalProps, /*#__PURE__*/React.createElement(this.props.listComponent, listProps))
169
+ })]
170
+ });
171
+ };
172
+ return _createClass(Picker, [{
173
+ key: "selectedItem",
174
+ get: function () {
175
+ return normalizeItem(this.props.items[this.state.selectedIndex]);
176
+ }
177
+ }]);
178
+ }(Component);
168
179
  Picker.defaultProps = {
169
180
  buttonComponent: PickerButton,
170
181
  buttonProps: {},
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import { mount } from 'enzyme';
3
3
  import Picker from "./index";
4
4
  import PickerList from "./components/List";
5
+ import { jsx as _jsx } from "react/jsx-runtime";
5
6
  jest.mock('@shopgate/engage/components');
6
7
  jest.mock('@shopgate/engage/core');
7
8
  describe('<Picker />', () => {
@@ -21,7 +22,9 @@ describe('<Picker />', () => {
21
22
  * @param {Object} props The component props.
22
23
  */
23
24
  const renderComponent = props => {
24
- renderedElement = mount(/*#__PURE__*/React.createElement(Picker, props));
25
+ renderedElement = mount(/*#__PURE__*/_jsx(Picker, {
26
+ ...props
27
+ }));
25
28
  renderedInstance = renderedElement.find('Picker').instance();
26
29
  };
27
30
  beforeEach(() => {