@shopgate/pwa-common 7.30.3 → 7.31.0-alpha.1

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 (112) hide show
  1. package/App.js +0 -2
  2. package/actions/app/handleLink.js +1 -0
  3. package/collections/AuthRoutes.js +1 -0
  4. package/collections/PersistedReducers.js +1 -0
  5. package/collections/media-providers/Vimeo.js +1 -1
  6. package/collections/media-providers/style.js +1 -1
  7. package/components/Backdrop/index.js +18 -3
  8. package/components/Button/index.js +40 -52
  9. package/components/Checkbox/index.js +1 -1
  10. package/components/Drawer/index.js +118 -132
  11. package/components/Drawer/spec.js +4 -2
  12. package/components/Dropdown/index.js +52 -68
  13. package/components/Grid/components/Item/index.js +37 -40
  14. package/components/Grid/index.js +36 -34
  15. package/components/HtmlSanitizer/index.js +60 -7
  16. package/components/I18n/components/FormatNumber/spec.js +1 -0
  17. package/components/Icon/index.d.ts +36 -0
  18. package/components/Icon/index.d.ts.map +1 -0
  19. package/components/Icon/index.js +39 -28
  20. package/components/Image/Image.js +27 -6
  21. package/components/Image/ImageInner.js +32 -25
  22. package/components/InfiniteContainer/index.js +5 -7
  23. package/components/InfiniteContainer/spec.js +13 -17
  24. package/components/Link/index.js +75 -84
  25. package/components/List/components/Item/index.js +19 -10
  26. package/components/List/spec.js +1 -3
  27. package/components/Loading/index.d.ts +6 -0
  28. package/components/Loading/index.d.ts.map +1 -0
  29. package/components/Modal/index.js +41 -7
  30. package/components/Picker/index.js +18 -194
  31. package/components/Portal/index.d.ts +50 -0
  32. package/components/Portal/index.d.ts.map +1 -0
  33. package/components/ProductCharacteristics/index.js +14 -276
  34. package/components/RangeSlider/index.js +15 -258
  35. package/components/Select/components/Item/index.js +18 -7
  36. package/components/Select/index.js +108 -144
  37. package/components/Select/spec.js +49 -16
  38. package/components/SelectBox/components/Item/index.js +49 -51
  39. package/components/SelectBox/index.js +140 -160
  40. package/components/SurroundPortals/index.d.ts +24 -0
  41. package/components/SurroundPortals/index.d.ts.map +1 -0
  42. package/components/SurroundPortals/index.js +3 -13
  43. package/components/Swiper/components/SwiperItem/index.js +13 -4
  44. package/components/Swiper/components/SwiperItem/spec.js +3 -2
  45. package/components/Swiper/index.js +80 -12
  46. package/components/Widgets/components/Widget/index.js +54 -56
  47. package/components/Widgets/components/Widget/spec.js +12 -8
  48. package/components/Widgets/components/WidgetGrid/index.js +39 -53
  49. package/components/Widgets/components/WidgetGrid/spec.js +12 -8
  50. package/constants/Configuration.js +2 -1
  51. package/constants/Portals.d.ts +101 -0
  52. package/constants/Portals.d.ts.map +1 -0
  53. package/helpers/config/index.d.ts +94 -0
  54. package/helpers/config/index.d.ts.map +1 -0
  55. package/helpers/config/mock.d.ts +23 -0
  56. package/helpers/config/mock.d.ts.map +1 -0
  57. package/helpers/config/theme.d.ts +7 -0
  58. package/helpers/config/theme.d.ts.map +1 -0
  59. package/helpers/data/index.d.ts +35 -0
  60. package/helpers/data/index.d.ts.map +1 -0
  61. package/helpers/data/index.js +1 -0
  62. package/helpers/html/handleDOM.js +1 -0
  63. package/helpers/portals/portalCollection.d.ts +30 -0
  64. package/helpers/portals/portalCollection.d.ts.map +1 -0
  65. package/helpers/style/index.js +1 -0
  66. package/helpers/validation/index.d.ts +10 -0
  67. package/helpers/validation/index.d.ts.map +1 -0
  68. package/package.json +4 -3
  69. package/selectors/client.js +1 -0
  70. package/styles/reset/form.js +46 -51
  71. package/styles/reset/media.js +21 -19
  72. package/styles/reset/root.js +28 -26
  73. package/styles/reset/table.js +9 -7
  74. package/styles/reset/typography.js +24 -22
  75. package/subscriptions/error.js +1 -0
  76. package/subscriptions/helpers/handleLinks.js +1 -0
  77. package/subscriptions/router.js +1 -0
  78. package/tsconfig.build.json +16 -0
  79. package/tsconfig.json +3 -0
  80. package/components/Backdrop/style.js +0 -11
  81. package/components/Button/style.js +0 -6
  82. package/components/Drawer/style.js +0 -37
  83. package/components/Dropdown/style.js +0 -4
  84. package/components/Grid/components/Item/style.js +0 -23
  85. package/components/Grid/style.js +0 -14
  86. package/components/Icon/style.js +0 -6
  87. package/components/Image/style.js +0 -32
  88. package/components/Link/style.js +0 -10
  89. package/components/List/components/Item/style.js +0 -16
  90. package/components/Modal/style.js +0 -36
  91. package/components/Picker/components/Button/index.js +0 -42
  92. package/components/Picker/components/Button/style.js +0 -19
  93. package/components/Picker/components/List/index.js +0 -38
  94. package/components/Picker/components/List/style.js +0 -17
  95. package/components/Picker/components/Modal/index.js +0 -76
  96. package/components/Picker/components/Modal/style.js +0 -78
  97. package/components/Picker/spec.js +0 -88
  98. package/components/ProductCharacteristics/connector.js +0 -41
  99. package/components/ProductCharacteristics/context.js +0 -2
  100. package/components/ProductCharacteristics/helpers/index.js +0 -162
  101. package/components/RangeSlider/components/Handle/index.js +0 -34
  102. package/components/RangeSlider/components/Handle/style.js +0 -14
  103. package/components/RangeSlider/helper.js +0 -85
  104. package/components/RangeSlider/style.js +0 -14
  105. package/components/Select/components/Item/style.js +0 -4
  106. package/components/Select/style.js +0 -17
  107. package/components/SelectBox/components/Item/style.js +0 -7
  108. package/components/SelectBox/style.js +0 -18
  109. package/components/Swiper/components/SwiperItem/styles.js +0 -5
  110. package/components/Swiper/styles.js +0 -76
  111. package/components/Widgets/components/Widget/style.js +0 -27
  112. package/components/Widgets/components/WidgetGrid/style.js +0 -8
@@ -1,176 +1,156 @@
1
- import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
2
- import React, { Component } from 'react';
1
+ import React, { useState, useEffect, useRef, useCallback, memo } from 'react';
3
2
  import PropTypes from 'prop-types';
4
- import classNames from 'classnames';
5
3
  import find from 'lodash/find';
4
+ import { makeStyles } from '@shopgate/engage/styles';
6
5
  import Dropdown from "../Dropdown";
7
6
  import I18n from "../I18n";
8
7
  import SelectBoxItem from "./components/Item";
9
- import styles from "./style";
8
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
9
+ const useStyles = makeStyles()(() => ({
10
+ overlay: {
11
+ position: 'fixed',
12
+ top: 0,
13
+ left: 0,
14
+ width: '100%',
15
+ height: '100%',
16
+ overflow: 'auto',
17
+ zIndex: 1,
18
+ outline: 0
19
+ }
20
+ }));
10
21
 
11
22
  /**
12
23
  * The select box component.
24
+ * @param {Object} props Props.
25
+ * @returns {JSX.Element}
13
26
  */
14
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
15
- let SelectBox = /*#__PURE__*/function (_Component) {
16
- /**
17
- * Initializes the component.
18
- * @param {Object} props The components props.
19
- */
20
- function SelectBox(props) {
21
- var _this;
22
- _this = _Component.call(this, props) || this;
23
- /**
24
- * Handles any interaction the user does outside of the component.
25
- * In this case the select gets closed.
26
- * @param {Object} event The event object.
27
- */
28
- _this.handleInteractionOutside = event => {
29
- _this.setState({
30
- isOpen: false
31
- });
32
- event.preventDefault();
33
- event.stopPropagation();
34
- };
35
- /**
36
- * Sets the open state to true
37
- */
38
- _this.handleOpenList = () => {
39
- if (_this.state.isOpen) {
40
- return;
41
- }
42
- _this.setState({
43
- isOpen: true
44
- });
45
- if (_this.firstItemRef) {
46
- _this.firstItemRef.focus();
47
- }
48
- };
49
- /**
50
- * Sets the new active selection.
51
- * @param {string} value Value of the selected item.
52
- */
53
- _this.handleSelectionUpdate = value => {
54
- const selection = find(_this.props.items, {
55
- value
56
- });
57
- _this.setState({
58
- selected: selection,
59
- isOpen: false
60
- });
27
+ const SelectBox = ({
28
+ icon: Icon,
29
+ item: Item,
30
+ items,
31
+ className,
32
+ classNames: classNamesProp,
33
+ defaultText,
34
+ duration,
35
+ handleSelectionUpdate,
36
+ initialValue,
37
+ testId
38
+ }) => {
39
+ const {
40
+ classes,
41
+ cx
42
+ } = useStyles();
43
+ const [isOpen, setIsOpen] = useState(false);
44
+ const [selected, setSelected] = useState(() => find(items, {
45
+ value: initialValue
46
+ }));
47
+ const controlRef = useRef(null);
48
+ const firstItemRef = useRef(null);
49
+ useEffect(() => {
50
+ setSelected(find(items, {
51
+ value: initialValue
52
+ }));
53
+ }, [initialValue, items]);
54
+ const handleInteractionOutside = useCallback(event => {
55
+ setIsOpen(false);
56
+ event.preventDefault();
57
+ event.stopPropagation();
58
+ }, []);
59
+ const handleOpenList = useCallback(() => {
60
+ if (isOpen) {
61
+ return;
62
+ }
63
+ setIsOpen(true);
64
+ if (firstItemRef.current) {
65
+ firstItemRef.current.focus();
66
+ }
67
+ }, [isOpen]);
68
+ const handleSelectionUpdateInner = useCallback(value => {
69
+ const selection = find(items, {
70
+ value
71
+ });
72
+ setSelected(selection);
73
+ setIsOpen(false);
74
+ setTimeout(() => {
75
+ handleSelectionUpdate(selection.value);
76
+ }, duration);
77
+ if (controlRef.current) {
78
+ controlRef.current.focus();
79
+ }
80
+ }, [duration, handleSelectionUpdate, items]);
61
81
 
62
- // Delay the callback to make sure actions are fired after animations are done.
63
- setTimeout(() => {
64
- _this.props.handleSelectionUpdate(selection.value);
65
- }, _this.props.duration);
66
- if (_this.controlRef) {
67
- _this.controlRef.focus();
68
- }
69
- };
70
- /** @param {HTMLElement} ref The element */
71
- _this.setControlRef = ref => {
72
- _this.controlRef = ref;
73
- };
74
- /** @param {HTMLElement} ref The element */
75
- _this.setFirstItemRef = ref => {
76
- _this.firstItemRef = ref;
77
- };
78
- _this.state = {
79
- isOpen: false,
80
- selected: find(props.items, {
81
- value: props.initialValue
82
- })
83
- };
84
- return _this;
85
- }
82
+ // eslint-disable-next-line require-jsdoc
83
+ const setControlRef = ref => {
84
+ controlRef.current = ref;
85
+ };
86
86
 
87
- /**
88
- * Reset selected when changing the initial value.
89
- * @param {Object} nextProps The next props the component will receive.
90
- */
91
- _inheritsLoose(SelectBox, _Component);
92
- var _proto = SelectBox.prototype;
93
- _proto.UNSAFE_componentWillReceiveProps = function UNSAFE_componentWillReceiveProps(nextProps) {
94
- if (this.props.initialValue !== nextProps.initialValue) {
95
- this.setState({
96
- selected: find(nextProps.items, {
97
- value: nextProps.initialValue
98
- })
99
- });
100
- }
87
+ // eslint-disable-next-line require-jsdoc
88
+ const setFirstItemRef = ref => {
89
+ firstItemRef.current = ref;
101
90
  };
102
- /**
103
- * Renders the component
104
- * @returns {JSX}
105
- */
106
- _proto.render = function render() {
107
- const Icon = this.props.icon;
108
- const {
109
- icon,
110
- iconOpen = null,
111
- selection,
112
- button,
113
- dropdown,
114
- selectItem,
115
- selectItemSelected
116
- } = this.props.classNames;
117
- const buttonLabel = this.state.selected ? this.state.selected.label : this.props.defaultText;
118
- const iconClasses = classNames(icon, {
119
- [iconOpen]: this.state.isOpen && iconOpen !== null
120
- });
121
- return /*#__PURE__*/_jsxs("div", {
122
- className: `${this.props.className} common__select-box`,
123
- "data-test-id": this.props.testId,
124
- children: [/*#__PURE__*/_jsxs("button", {
125
- className: button,
126
- onClick: this.handleOpenList,
127
- "data-test-id": buttonLabel,
128
- type: "button",
129
- "aria-haspopup": true,
130
- "aria-expanded": this.state.isOpen ? true : null,
131
- "aria-controls": buttonLabel,
132
- ref: this.setControlRef,
133
- children: [/*#__PURE__*/_jsx("span", {
134
- className: selection,
135
- children: /*#__PURE__*/_jsx(I18n.Text, {
136
- string: buttonLabel
137
- })
138
- }), /*#__PURE__*/_jsx("div", {
139
- className: iconClasses,
140
- children: /*#__PURE__*/_jsx(Icon, {})
141
- })]
142
- }), /*#__PURE__*/_jsx(Dropdown, {
143
- className: dropdown,
144
- isOpen: this.state.isOpen,
145
- duration: this.props.duration,
146
- children: /*#__PURE__*/_jsx("ul", {
147
- role: "menu",
148
- id: buttonLabel,
149
- tabIndex: "-1",
150
- children: this.props.items.map(item => /*#__PURE__*/_jsx(SelectBoxItem, {
151
- classNames: {
152
- selectItem,
153
- selectItemSelected
154
- },
155
- wrapper: this.props.item,
156
- value: item.value,
157
- label: item.label,
158
- handleSelectionUpdate: this.handleSelectionUpdate,
159
- isSelected: buttonLabel === item.label,
160
- forwardedRef: buttonLabel === item.label ? this.setFirstItemRef : null
161
- }, item.value))
91
+ const {
92
+ icon: iconClass,
93
+ iconOpen = null,
94
+ selection,
95
+ button,
96
+ dropdown,
97
+ selectItem,
98
+ selectItemSelected
99
+ } = classNamesProp;
100
+ const buttonLabel = selected ? selected.label : defaultText;
101
+ return /*#__PURE__*/_jsxs("div", {
102
+ className: cx(className, 'common__select-box'),
103
+ "data-test-id": testId,
104
+ children: [/*#__PURE__*/_jsxs("button", {
105
+ className: button,
106
+ onClick: handleOpenList,
107
+ "data-test-id": buttonLabel,
108
+ type: "button",
109
+ "aria-haspopup": true,
110
+ "aria-expanded": isOpen ? true : null,
111
+ "aria-controls": buttonLabel,
112
+ ref: setControlRef,
113
+ children: [/*#__PURE__*/_jsx("span", {
114
+ className: selection,
115
+ children: /*#__PURE__*/_jsx(I18n.Text, {
116
+ string: buttonLabel
162
117
  })
163
- }), this.state.isOpen && /*#__PURE__*/_jsx("button", {
164
- className: styles.overlay,
165
- onClick: this.handleInteractionOutside,
166
- onTouchMove: this.handleInteractionOutside,
167
- type: "button",
168
- "aria-hidden": true
118
+ }), /*#__PURE__*/_jsx("div", {
119
+ className: cx(iconClass, {
120
+ [iconOpen]: isOpen && iconOpen !== null
121
+ }),
122
+ children: /*#__PURE__*/_jsx(Icon, {})
169
123
  })]
170
- });
171
- };
172
- return SelectBox;
173
- }(Component);
124
+ }), /*#__PURE__*/_jsx(Dropdown, {
125
+ className: dropdown,
126
+ isOpen: isOpen,
127
+ duration: duration,
128
+ children: /*#__PURE__*/_jsx("ul", {
129
+ role: "menu",
130
+ id: buttonLabel,
131
+ tabIndex: "-1",
132
+ children: items.map(item => /*#__PURE__*/_jsx(SelectBoxItem, {
133
+ classNames: {
134
+ selectItem,
135
+ selectItemSelected
136
+ },
137
+ wrapper: Item,
138
+ value: item.value,
139
+ label: item.label,
140
+ handleSelectionUpdate: handleSelectionUpdateInner,
141
+ isSelected: buttonLabel === item.label,
142
+ forwardedRef: buttonLabel === item.label ? setFirstItemRef : null
143
+ }, item.value))
144
+ })
145
+ }), isOpen && /*#__PURE__*/_jsx("button", {
146
+ className: classes.overlay,
147
+ onClick: handleInteractionOutside,
148
+ onTouchMove: handleInteractionOutside,
149
+ type: "button",
150
+ "aria-hidden": true
151
+ })]
152
+ });
153
+ };
174
154
  SelectBox.defaultProps = {
175
155
  className: '',
176
156
  classNames: {},
@@ -180,4 +160,4 @@ SelectBox.defaultProps = {
180
160
  initialValue: null,
181
161
  testId: null
182
162
  };
183
- export default SelectBox;
163
+ export default /*#__PURE__*/memo(SelectBox);
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+ export interface SurroundPortalsProps {
3
+ /**
4
+ * The name of the main portal.
5
+ * The additional portals will be named `${portalName}.before` and `${portalName}.after`.
6
+ */
7
+ portalName: string;
8
+ /**
9
+ * Optional props to be passed to all three portals.
10
+ */
11
+ portalProps?: Record<string, unknown>;
12
+ children?: React.ReactNode;
13
+ }
14
+ /**
15
+ * The SurroundPortals component renders three Portal components. The main portal is wrapped around
16
+ * its children, the two additional portals are rendered before and after the main portal.
17
+ * The names of the additional portals are automatically created from the name of the main portal
18
+ * with a ".before" and ".after" suffix.
19
+ *
20
+ * @returns The SurroundPortals component.
21
+ */
22
+ declare const SurroundPortals: ({ portalName, portalProps, children, }: SurroundPortalsProps) => import("react/jsx-runtime").JSX.Element;
23
+ export default SurroundPortals;
24
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../components/SurroundPortals/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED;;;;;;;GAOG;AACH,QAAA,MAAM,eAAe,GAAI,wCAItB,oBAAoB,4CAQtB,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -1,21 +1,15 @@
1
1
  import React from 'react';
2
- import PropTypes from 'prop-types';
3
2
  import Portal from "../Portal";
4
3
  import { AFTER, BEFORE } from "../../constants/Portals";
5
-
4
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
6
5
  /**
7
- * The SurroundPortals component renders three Portal component. The main portal is wrapped around
6
+ * The SurroundPortals component renders three Portal components. The main portal is wrapped around
8
7
  * its children, the two additional portals are rendered before and after the main portal.
9
8
  * The names of the additional portals are automatically created from the name of the main portal
10
9
  * with a ".before" and ".after" suffix.
11
10
  *
12
- * @param {Object} props The component props
13
- * @param {string} props.portalName Name for the main portal
14
- * @param {Object} props.portalProps Props that are assigned to the portals
15
- * @param {React.ReactNode} props.children Component children
16
- * @returns {JSX.Element}
11
+ * @returns The SurroundPortals component.
17
12
  */
18
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
19
13
  const SurroundPortals = ({
20
14
  portalName,
21
15
  portalProps,
@@ -33,8 +27,4 @@ const SurroundPortals = ({
33
27
  props: portalProps
34
28
  })]
35
29
  });
36
- SurroundPortals.defaultProps = {
37
- children: null,
38
- portalProps: null
39
- };
40
30
  export default SurroundPortals;
@@ -1,8 +1,14 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import classNames from 'classnames';
4
3
  import { SwiperSlide } from 'swiper/react';
5
- import { item } from "./styles";
4
+ import { makeStyles } from '@shopgate/engage/styles';
5
+ import { jsx as _jsx } from "react/jsx-runtime";
6
+ const useStyles = makeStyles()(() => ({
7
+ item: {
8
+ position: 'relative',
9
+ height: '100%'
10
+ }
11
+ }));
6
12
 
7
13
  /**
8
14
  * @typedef {import('swiper/react').SwiperSlideProps} SwiperSlideProps
@@ -13,15 +19,18 @@ import { item } from "./styles";
13
19
  * @param {SwiperSlideProps} props The component props.
14
20
  * @returns {React.Node}
15
21
  */
16
- import { jsx as _jsx } from "react/jsx-runtime";
17
22
  function SwiperItem({
18
23
  children,
19
24
  className,
20
25
  ...slideProps
21
26
  }) {
27
+ const {
28
+ classes,
29
+ cx
30
+ } = useStyles();
22
31
  return /*#__PURE__*/_jsx(SwiperSlide, {
23
32
  ...slideProps,
24
- className: classNames(item, className),
33
+ className: cx(classes.item, className),
25
34
  "data-test-id": "Slider",
26
35
  children: children
27
36
  });
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import { shallow } from 'enzyme';
3
+ import { CLASS_PREFIX } from '@shopgate/engage/styles/tss';
3
4
  import SwiperItem from '.';
4
5
  import { jsx as _jsx } from "react/jsx-runtime";
5
6
  jest.mock('react', () => ({
@@ -12,7 +13,7 @@ describe('<SwiperItem />', () => {
12
13
  children: /*#__PURE__*/_jsx("div", {})
13
14
  }));
14
15
  expect(wrapper).toMatchSnapshot();
15
- expect(wrapper.html()).toEqual('<div class="swiper-slide css-10a4qrv" data-test-id="Slider"><div></div></div>');
16
+ expect(wrapper.html()).toMatch(new RegExp(`^<div class="swiper-slide ${CLASS_PREFIX}-[^"]+" data-test-id="Slider"><div></div></div>$`));
16
17
  });
17
18
  it('should add custom className', () => {
18
19
  const wrapper = shallow(/*#__PURE__*/_jsx(SwiperItem, {
@@ -20,6 +21,6 @@ describe('<SwiperItem />', () => {
20
21
  children: /*#__PURE__*/_jsx("div", {})
21
22
  }));
22
23
  expect(wrapper).toMatchSnapshot();
23
- expect(wrapper.html()).toEqual('<div class="swiper-slide css-10a4qrv test" data-test-id="Slider"><div></div></div>');
24
+ expect(wrapper.html()).toMatch(new RegExp(`^<div class="swiper-slide ${CLASS_PREFIX}-[^"]+ test" data-test-id="Slider"><div></div></div>$`));
24
25
  });
25
26
  });
@@ -1,6 +1,5 @@
1
1
  import React, { useMemo, useCallback, useEffect, useRef, useState } from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import cls from 'classnames';
4
3
  import { A11y, Autoplay, FreeMode, Navigation, Pagination, Zoom } from 'swiper/modules';
5
4
  import { Swiper as OriginalSwiper } from 'swiper/react';
6
5
  import 'swiper/css';
@@ -9,8 +8,74 @@ import 'swiper/css/pagination';
9
8
  import 'swiper/css/navigation';
10
9
  import 'swiper/css/zoom';
11
10
  import { useReduceMotion } from '@shopgate/engage/a11y/hooks';
11
+ import { makeStyles } from '@shopgate/engage/styles';
12
+ import { themeColors } from '@shopgate/pwa-common/helpers/config';
12
13
  import SwiperItem from "./components/SwiperItem";
13
- import { container, innerContainer, zoomFix, buttonNext, buttonPrev } from "./styles";
14
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
15
+ const useStyles = makeStyles()(() => ({
16
+ container: {
17
+ position: 'relative',
18
+ maxHeight: '100%'
19
+ },
20
+ innerContainer: {
21
+ overflow: 'hidden',
22
+ '--swiper-navigation-color': themeColors.gray,
23
+ '& .swiper-wrapper': {
24
+ alignItems: 'stretch'
25
+ },
26
+ '& .swiper-slide': {
27
+ height: 'auto'
28
+ },
29
+ '& .swiper-pagination': {
30
+ '& .swiper-pagination-bullet': {
31
+ background: themeColors.gray,
32
+ opacity: '.5',
33
+ margin: '0 4px',
34
+ transition: 'opacity 300ms cubic-bezier(0.25, 0.1, 0.25, 1)',
35
+ border: `1px solid ${themeColors.dark}`
36
+ },
37
+ '& .swiper-pagination-bullet-active.swiper-pagination-bullet-active-main': {
38
+ opacity: 1
39
+ }
40
+ },
41
+ '& .swiper-pagination-fraction': {
42
+ top: 'var(--swiper-pagination-fraction-top-offset, 4px)',
43
+ left: 'auto',
44
+ right: 0,
45
+ bottom: 'auto',
46
+ fontSize: 12,
47
+ background: themeColors.background,
48
+ borderRadius: '50px',
49
+ width: 'fit-content',
50
+ padding: '4px 8px',
51
+ margin: '4px 16px',
52
+ transition: 'opacity 300ms cubic-bezier(0.25, 0.1, 0.25, 1)'
53
+ },
54
+ '& .swiper-pagination-progressbar': {
55
+ background: themeColors.shade7,
56
+ '& .swiper-pagination-progressbar-fill': {
57
+ background: themeColors.dark
58
+ }
59
+ }
60
+ },
61
+ zoomFix: {
62
+ '& .swiper-slide': {
63
+ overflow: 'hidden'
64
+ }
65
+ },
66
+ buttonNext: {
67
+ backgroundImage: "url(\"data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20viewBox%3D'0%200%2027%2044'%3E%3Cpath%20d%3D'M27%2C22L27%2C22L5%2C44l-2.1-2.1L22.8%2C22L2.9%2C2.1L5%2C0L27%2C22L27%2C22z'%20fill%3D'%23808080'%2F%3E%3C%2Fsvg%3E\") !important",
68
+ '&:after': {
69
+ color: 'transparent'
70
+ }
71
+ },
72
+ buttonPrev: {
73
+ backgroundImage: "url(\"data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20viewBox%3D'0%200%2027%2044'%3E%3Cpath%20d%3D'M0%2C22L22%2C0l2.1%2C2.1L4.2%2C22l19.9%2C19.9L22%2C44L0%2C22L0%2C22L0%2C22z'%20fill%3D'%23808080'%2F%3E%3C%2Fsvg%3E\") !important",
74
+ '&:after': {
75
+ color: 'transparent'
76
+ }
77
+ }
78
+ }));
14
79
 
15
80
  /**
16
81
  * @typedef {import('swiper/react').SwiperProps} SwiperCmpProps
@@ -25,7 +90,6 @@ import { container, innerContainer, zoomFix, buttonNext, buttonPrev } from "./st
25
90
  * @param {SwiperClass} swiper Swiper instance
26
91
  * @param {boolean} loop Whether the loop mode should be enabled or not.
27
92
  */
28
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
29
93
  const handleLoopPropUpdate = (swiper, loop) => {
30
94
  const realIndex = swiper?.realIndex || 0;
31
95
 
@@ -67,6 +131,10 @@ const Swiper = ({
67
131
  paginationType: paginationTypeProp,
68
132
  ...swiperProps
69
133
  }) => {
134
+ const {
135
+ classes,
136
+ cx
137
+ } = useStyles();
70
138
  const useFraction = maxIndicators && maxIndicators < children.length;
71
139
  const paginationType = useFraction ? 'fraction' : 'bullets';
72
140
  const showPagination = indicators && children.length > 1;
@@ -81,15 +149,15 @@ const Swiper = ({
81
149
  if (hasControls) {
82
150
  nav = {
83
151
  // Important to use dot notation (swiper uses it as selector internally)
84
- nextEl: `.swiper-button-next.${buttonNext}`,
85
- prevEl: `.swiper-button-prev.${buttonPrev}`
152
+ nextEl: `.swiper-button-next.${classes.buttonNext}`,
153
+ prevEl: `.swiper-button-prev.${classes.buttonPrev}`
86
154
  };
87
155
  }
88
156
  if (typeof controls === 'object') {
89
157
  nav = controls;
90
158
  }
91
159
  return nav;
92
- }, [controls, hasControls]);
160
+ }, [controls, hasControls, classes.buttonNext, classes.buttonPrev]);
93
161
  const handleSlideChange = useCallback(swiper => {
94
162
  if (typeof onSlideChange === 'function') {
95
163
  onSlideChange(swiper.realIndex, swiper);
@@ -101,8 +169,8 @@ const Swiper = ({
101
169
  */
102
170
  const internalProps = useMemo(() => ({
103
171
  modules: [A11y, Autoplay, FreeMode, Navigation, Pagination, Zoom].concat(Array.isArray(additionalModules) ? additionalModules : []),
104
- className: cls(innerContainer, classNames.container, {
105
- [zoomFix]: swiperProps?.zoom
172
+ className: cx(classes.innerContainer, classNames.container, {
173
+ [classes.zoomFix]: swiperProps?.zoom
106
174
  }),
107
175
  autoplay: autoPlay ? {
108
176
  delay: interval
@@ -122,7 +190,7 @@ const Swiper = ({
122
190
  allowSlidePrev: !disabled,
123
191
  allowSlideNext: !disabled,
124
192
  onSlideChange: handleSlideChange
125
- }), [additionalModules, classNames.container, classNames.bulletClass, classNames.bulletActiveClass, swiperProps, autoPlay, interval, navigation, showPagination, paginationTypeProp, paginationType, indicators, children.length, disabled, handleSlideChange]);
193
+ }), [additionalModules, classNames.container, classNames.bulletClass, classNames.bulletActiveClass, classes.innerContainer, classes.zoomFix, swiperProps, autoPlay, interval, navigation, showPagination, paginationTypeProp, paginationType, indicators, children.length, disabled, handleSlideChange, cx]);
126
194
  useEffect(() => {
127
195
  if (!internalProps.autoplay && !swiperProps.autoplay) {
128
196
  if (swiperRef.current?.swiper?.autoplay) {
@@ -187,7 +255,7 @@ const Swiper = ({
187
255
  }
188
256
  }, [delay, loopProp, onBreakpoint]);
189
257
  return /*#__PURE__*/_jsx("div", {
190
- className: cls(container, className, 'common__swiper'),
258
+ className: cx(classes.container, className, 'common__swiper'),
191
259
  "aria-hidden": ariaHidden,
192
260
  children: /*#__PURE__*/_jsxs(OriginalSwiper, {
193
261
  "aria-live": "off",
@@ -201,9 +269,9 @@ const Swiper = ({
201
269
  ref: swiperRef,
202
270
  children: [children, hasControls && /*#__PURE__*/_jsxs(_Fragment, {
203
271
  children: [/*#__PURE__*/_jsx("div", {
204
- className: `swiper-button-next ${buttonNext}`
272
+ className: cx('swiper-button-next', classes.buttonNext)
205
273
  }), /*#__PURE__*/_jsx("div", {
206
- className: `swiper-button-prev ${buttonPrev}`
274
+ className: cx('swiper-button-prev', classes.buttonPrev)
207
275
  })]
208
276
  })]
209
277
  })