@shopgate/pwa-ui-shared 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 (326) hide show
  1. package/ActionButton/index.js +66 -67
  2. package/AddToCartButton/index.js +217 -185
  3. package/Availability/index.js +24 -6
  4. package/Button/index.js +105 -82
  5. package/Button/spec.js +3 -4
  6. package/Card/index.js +26 -7
  7. package/CardList/components/Item/index.js +15 -3
  8. package/CartTotalLine/components/Amount/index.js +13 -4
  9. package/CartTotalLine/components/Hint/index.js +13 -4
  10. package/CartTotalLine/components/Label/index.js +23 -10
  11. package/CartTotalLine/index.js +41 -7
  12. package/Checkbox/index.js +41 -17
  13. package/Chip/index.js +82 -7
  14. package/ContextMenu/components/Item/index.js +38 -20
  15. package/ContextMenu/components/Position/index.js +38 -56
  16. package/ContextMenu/index.js +64 -28
  17. package/Dialog/components/BasicDialog/index.js +1 -0
  18. package/Dialog/components/HtmlContentDialog/spec.js +39 -0
  19. package/Dialog/components/PipelineErrorDialog/index.js +108 -157
  20. package/Dialog/components/PipelineErrorDialog/spec.js +12 -18
  21. package/Dialog/components/TextMessageDialog/index.js +1 -1
  22. package/Dialog/components/VariantSelectModal/index.js +1 -1
  23. package/Dialog/index.js +1 -1
  24. package/DiscountBadge/index.js +48 -15
  25. package/FavoritesButton/index.js +95 -100
  26. package/FavoritesButton/spec.js +5 -2
  27. package/Form/Builder/classes/ActionListener/index.js +1 -0
  28. package/Form/Checkbox/index.js +64 -56
  29. package/Form/InfoField/index.js +18 -6
  30. package/Form/Password/index.js +39 -52
  31. package/Form/RadioGroup/components/Item/index.js +72 -56
  32. package/Form/RadioGroup/index.js +79 -90
  33. package/Form/Select/index.js +108 -130
  34. package/Form/SelectContextChoices/index.js +30 -8
  35. package/Form/TextField/index.js +106 -82
  36. package/Form/TextField/spec.js +4 -3
  37. package/FormElement/components/ErrorText/index.js +32 -14
  38. package/FormElement/components/Label/index.js +56 -6
  39. package/FormElement/components/Placeholder/index.js +44 -11
  40. package/FormElement/components/Underline/index.js +63 -12
  41. package/FormElement/index.js +62 -85
  42. package/Glow/index.js +73 -83
  43. package/IndicatorCircle/index.js +73 -17
  44. package/IndicatorCircle/spec.js +2 -5
  45. package/LoadingIndicator/index.js +34 -12
  46. package/Manufacturer/index.js +21 -10
  47. package/MessageBar/index.js +12 -38
  48. package/NoResults/components/Icon/index.js +30 -14
  49. package/NoResults/index.js +35 -7
  50. package/Placeholder/index.js +34 -23
  51. package/PlaceholderLabel/index.js +17 -3
  52. package/Price/index.js +34 -21
  53. package/PriceInfo/index.js +23 -9
  54. package/PriceStriked/index.js +67 -77
  55. package/ProgressBar/index.js +112 -77
  56. package/RadioButton/index.js +29 -11
  57. package/RatingStars/index.js +122 -137
  58. package/Ripple/components/RippleAnimation/index.js +13 -3
  59. package/Ripple/index.js +158 -212
  60. package/RippleButton/index.js +63 -60
  61. package/RippleButton/spec.js +15 -9
  62. package/ScannerOverlay/components/CameraOverlay/index.js +54 -10
  63. package/ScannerOverlay/components/ScannerBar/components/FlashlightButton/index.js +53 -27
  64. package/ScannerOverlay/components/ScannerBar/index.js +50 -26
  65. package/Sheet/components/Header/components/SearchBar/index.js +54 -10
  66. package/Sheet/components/Header/index.js +96 -76
  67. package/Sheet/index.js +295 -157
  68. package/Sheet/spec.js +8 -6
  69. package/TaxDisclaimer/index.js +17 -4
  70. package/TaxDisclaimer/spec.js +16 -5
  71. package/TextField/components/ErrorText/index.js +35 -14
  72. package/TextField/components/FormElement/index.js +29 -4
  73. package/TextField/components/Hint/index.js +39 -10
  74. package/TextField/components/Label/index.js +43 -6
  75. package/TextField/components/Underline/index.js +64 -13
  76. package/TextField/index.js +157 -171
  77. package/TextField/spec.js +5 -3
  78. package/icons/AccountBoxIcon.d.ts +7 -0
  79. package/icons/AccountBoxIcon.d.ts.map +1 -0
  80. package/icons/AccountBoxIcon.js +1 -4
  81. package/icons/AddMoreIcon.d.ts +7 -0
  82. package/icons/AddMoreIcon.d.ts.map +1 -0
  83. package/icons/AddMoreIcon.js +0 -3
  84. package/icons/ArrowDropIcon.d.ts +7 -0
  85. package/icons/ArrowDropIcon.d.ts.map +1 -0
  86. package/icons/ArrowDropIcon.js +0 -3
  87. package/icons/ArrowIcon.d.ts +10 -0
  88. package/icons/ArrowIcon.d.ts.map +1 -0
  89. package/icons/ArrowIcon.js +2 -11
  90. package/icons/BarcodeScannerIcon.d.ts +7 -0
  91. package/icons/BarcodeScannerIcon.d.ts.map +1 -0
  92. package/icons/BarcodeScannerIcon.js +0 -3
  93. package/icons/BoxIcon.d.ts +7 -0
  94. package/icons/BoxIcon.d.ts.map +1 -0
  95. package/icons/BoxIcon.js +0 -3
  96. package/icons/BrowseIcon.d.ts +7 -0
  97. package/icons/BrowseIcon.d.ts.map +1 -0
  98. package/icons/BrowseIcon.js +1 -3
  99. package/icons/BurgerIcon.d.ts +7 -0
  100. package/icons/BurgerIcon.d.ts.map +1 -0
  101. package/icons/BurgerIcon.js +0 -3
  102. package/icons/CalendarIcon.d.ts +7 -0
  103. package/icons/CalendarIcon.d.ts.map +1 -0
  104. package/icons/CalendarIcon.js +0 -2
  105. package/icons/CartCouponIcon.d.ts +7 -0
  106. package/icons/CartCouponIcon.d.ts.map +1 -0
  107. package/icons/CartCouponIcon.js +0 -2
  108. package/icons/CartIcon.d.ts +7 -0
  109. package/icons/CartIcon.d.ts.map +1 -0
  110. package/icons/CartIcon.js +0 -2
  111. package/icons/CartPlusIcon.d.ts +7 -0
  112. package/icons/CartPlusIcon.d.ts.map +1 -0
  113. package/icons/CartPlusIcon.js +0 -2
  114. package/icons/CheckIcon.d.ts +7 -0
  115. package/icons/CheckIcon.d.ts.map +1 -0
  116. package/icons/CheckIcon.js +0 -2
  117. package/icons/CheckedIcon.d.ts +7 -0
  118. package/icons/CheckedIcon.d.ts.map +1 -0
  119. package/icons/CheckedIcon.js +0 -3
  120. package/icons/ChevronIcon.d.ts +7 -0
  121. package/icons/ChevronIcon.d.ts.map +1 -0
  122. package/icons/ChevronIcon.js +0 -2
  123. package/icons/CreditCardIcon.d.ts +7 -0
  124. package/icons/CreditCardIcon.d.ts.map +1 -0
  125. package/icons/CreditCardIcon.js +0 -2
  126. package/icons/CrossIcon.d.ts +7 -0
  127. package/icons/CrossIcon.d.ts.map +1 -0
  128. package/icons/CrossIcon.js +0 -2
  129. package/icons/DescriptionIcon.d.ts +7 -0
  130. package/icons/DescriptionIcon.d.ts.map +1 -0
  131. package/icons/DescriptionIcon.js +0 -2
  132. package/icons/FilterIcon.d.ts +7 -0
  133. package/icons/FilterIcon.d.ts.map +1 -0
  134. package/icons/FilterIcon.js +0 -2
  135. package/icons/FlashDisabledIcon.d.ts +7 -0
  136. package/icons/FlashDisabledIcon.d.ts.map +1 -0
  137. package/icons/FlashDisabledIcon.js +0 -2
  138. package/icons/FlashEnabledIcon.d.ts +7 -0
  139. package/icons/FlashEnabledIcon.d.ts.map +1 -0
  140. package/icons/FlashEnabledIcon.js +0 -2
  141. package/icons/GridIcon.d.ts +7 -0
  142. package/icons/GridIcon.d.ts.map +1 -0
  143. package/icons/GridIcon.js +1 -3
  144. package/icons/HeartIcon.d.ts +7 -0
  145. package/icons/HeartIcon.d.ts.map +1 -0
  146. package/icons/HeartIcon.js +0 -2
  147. package/icons/HeartOutlineIcon.d.ts +7 -0
  148. package/icons/HeartOutlineIcon.d.ts.map +1 -0
  149. package/icons/HeartOutlineIcon.js +1 -3
  150. package/icons/HeartPlusIcon.d.ts +7 -0
  151. package/icons/HeartPlusIcon.d.ts.map +1 -0
  152. package/icons/HeartPlusIcon.js +1 -3
  153. package/icons/HeartPlusOutlineIcon.d.ts +7 -0
  154. package/icons/HeartPlusOutlineIcon.d.ts.map +1 -0
  155. package/icons/HeartPlusOutlineIcon.js +1 -3
  156. package/icons/HomeIcon.d.ts +7 -0
  157. package/icons/HomeIcon.d.ts.map +1 -0
  158. package/icons/HomeIcon.js +0 -2
  159. package/icons/InfoIcon.d.ts +7 -0
  160. package/icons/InfoIcon.d.ts.map +1 -0
  161. package/icons/InfoIcon.js +0 -2
  162. package/icons/InfoOutlineIcon.d.ts +7 -0
  163. package/icons/InfoOutlineIcon.d.ts.map +1 -0
  164. package/icons/InfoOutlineIcon.js +0 -2
  165. package/icons/ListIcon.d.ts +7 -0
  166. package/icons/ListIcon.d.ts.map +1 -0
  167. package/icons/ListIcon.js +0 -2
  168. package/icons/LocalShippingIcon.d.ts +7 -0
  169. package/icons/LocalShippingIcon.d.ts.map +1 -0
  170. package/icons/LocalShippingIcon.js +0 -2
  171. package/icons/LocationIcon.d.ts +7 -0
  172. package/icons/LocationIcon.d.ts.map +1 -0
  173. package/icons/LocationIcon.js +1 -4
  174. package/icons/LocatorIcon.d.ts +7 -0
  175. package/icons/LocatorIcon.d.ts.map +1 -0
  176. package/icons/LocatorIcon.js +1 -3
  177. package/icons/LockIcon.d.ts +9 -0
  178. package/icons/LockIcon.d.ts.map +1 -0
  179. package/icons/LockIcon.js +1 -2
  180. package/icons/LogoutIcon.d.ts +7 -0
  181. package/icons/LogoutIcon.d.ts.map +1 -0
  182. package/icons/LogoutIcon.js +0 -2
  183. package/icons/MagnifierIcon.d.ts +7 -0
  184. package/icons/MagnifierIcon.d.ts.map +1 -0
  185. package/icons/MagnifierIcon.js +0 -2
  186. package/icons/MapMarkerIcon.d.ts +7 -0
  187. package/icons/MapMarkerIcon.d.ts.map +1 -0
  188. package/icons/MapMarkerIcon.js +1 -3
  189. package/icons/MoreIcon.d.ts +7 -0
  190. package/icons/MoreIcon.d.ts.map +1 -0
  191. package/icons/MoreIcon.js +1 -3
  192. package/icons/MoreVertIcon.d.ts +7 -0
  193. package/icons/MoreVertIcon.d.ts.map +1 -0
  194. package/icons/MoreVertIcon.js +1 -3
  195. package/icons/NotificationIcon.d.ts +7 -0
  196. package/icons/NotificationIcon.d.ts.map +1 -0
  197. package/icons/NotificationIcon.js +1 -3
  198. package/icons/PersonIcon.d.ts +9 -0
  199. package/icons/PersonIcon.d.ts.map +1 -0
  200. package/icons/PersonIcon.js +0 -3
  201. package/icons/PhoneIcon.d.ts +7 -0
  202. package/icons/PhoneIcon.d.ts.map +1 -0
  203. package/icons/PhoneIcon.js +1 -4
  204. package/icons/PlaceholderIcon.d.ts +7 -0
  205. package/icons/PlaceholderIcon.d.ts.map +1 -0
  206. package/icons/PlaceholderIcon.js +0 -2
  207. package/icons/RadioCheckedIcon.d.ts +10 -0
  208. package/icons/RadioCheckedIcon.d.ts.map +1 -0
  209. package/icons/RadioCheckedIcon.js +0 -2
  210. package/icons/RadioUncheckedIcon.d.ts +10 -0
  211. package/icons/RadioUncheckedIcon.d.ts.map +1 -0
  212. package/icons/RadioUncheckedIcon.js +0 -2
  213. package/icons/SecurityIcon.d.ts +7 -0
  214. package/icons/SecurityIcon.d.ts.map +1 -0
  215. package/icons/SecurityIcon.js +0 -2
  216. package/icons/ShippingMethodIcon.d.ts +7 -0
  217. package/icons/ShippingMethodIcon.d.ts.map +1 -0
  218. package/icons/ShippingMethodIcon.js +0 -2
  219. package/icons/ShoppingCartIcon.d.ts +7 -0
  220. package/icons/ShoppingCartIcon.d.ts.map +1 -0
  221. package/icons/ShoppingCartIcon.js +0 -2
  222. package/icons/SortIcon.d.ts +7 -0
  223. package/icons/SortIcon.d.ts.map +1 -0
  224. package/icons/SortIcon.js +0 -2
  225. package/icons/StarHalfIcon.d.ts +7 -0
  226. package/icons/StarHalfIcon.d.ts.map +1 -0
  227. package/icons/StarHalfIcon.js +0 -9
  228. package/icons/StarIcon.d.ts +7 -0
  229. package/icons/StarIcon.d.ts.map +1 -0
  230. package/icons/StarIcon.js +0 -9
  231. package/icons/StarOutlineIcon.d.ts +7 -0
  232. package/icons/StarOutlineIcon.d.ts.map +1 -0
  233. package/icons/StarOutlineIcon.js +0 -2
  234. package/icons/StopIcon.d.ts +7 -0
  235. package/icons/StopIcon.d.ts.map +1 -0
  236. package/icons/StopIcon.js +0 -2
  237. package/icons/TickIcon.d.ts +7 -0
  238. package/icons/TickIcon.d.ts.map +1 -0
  239. package/icons/TickIcon.js +0 -2
  240. package/icons/TimeIcon.d.ts +7 -0
  241. package/icons/TimeIcon.d.ts.map +1 -0
  242. package/icons/TimeIcon.js +0 -2
  243. package/icons/TrashIcon.d.ts +7 -0
  244. package/icons/TrashIcon.d.ts.map +1 -0
  245. package/icons/TrashIcon.js +0 -3
  246. package/icons/TrashOutlineIcon.d.ts +8 -0
  247. package/icons/TrashOutlineIcon.d.ts.map +1 -0
  248. package/icons/TrashOutlineIcon.js +0 -2
  249. package/icons/UncheckedIcon.d.ts +7 -0
  250. package/icons/UncheckedIcon.d.ts.map +1 -0
  251. package/icons/UncheckedIcon.js +0 -2
  252. package/icons/ViewListIcon.d.ts +7 -0
  253. package/icons/ViewListIcon.d.ts.map +1 -0
  254. package/icons/ViewListIcon.js +0 -2
  255. package/icons/VisibilityIcon.d.ts +8 -0
  256. package/icons/VisibilityIcon.d.ts.map +1 -0
  257. package/icons/VisibilityIcon.js +2 -4
  258. package/icons/VisibilityOffIcon.d.ts +8 -0
  259. package/icons/VisibilityOffIcon.d.ts.map +1 -0
  260. package/icons/VisibilityOffIcon.js +2 -4
  261. package/icons/WarningIcon.d.ts +7 -0
  262. package/icons/WarningIcon.d.ts.map +1 -0
  263. package/icons/WarningIcon.js +1 -3
  264. package/package.json +5 -5
  265. package/tsconfig.build.json +16 -0
  266. package/tsconfig.json +3 -0
  267. package/ActionButton/style.js +0 -22
  268. package/AddToCartButton/style.js +0 -148
  269. package/Availability/style.js +0 -19
  270. package/Button/style.js +0 -155
  271. package/Card/style.js +0 -11
  272. package/CardList/components/Item/style.js +0 -7
  273. package/CartTotalLine/components/Amount/style.js +0 -8
  274. package/CartTotalLine/components/Hint/style.js +0 -12
  275. package/CartTotalLine/components/Label/style.js +0 -17
  276. package/CartTotalLine/style.js +0 -31
  277. package/Checkbox/style.js +0 -18
  278. package/Chip/style.js +0 -78
  279. package/ContextMenu/components/Item/style.js +0 -34
  280. package/ContextMenu/components/Position/style.js +0 -11
  281. package/ContextMenu/style.js +0 -45
  282. package/DiscountBadge/style.js +0 -36
  283. package/FavoritesButton/style.js +0 -26
  284. package/Form/Checkbox/style.js +0 -25
  285. package/Form/InfoField/style.js +0 -11
  286. package/Form/Password/style.js +0 -11
  287. package/Form/RadioGroup/components/Item/style.js +0 -32
  288. package/Form/RadioGroup/style.js +0 -20
  289. package/Form/Select/style.js +0 -27
  290. package/Form/SelectContextChoices/style.js +0 -23
  291. package/Form/TextField/style.js +0 -70
  292. package/FormElement/components/ErrorText/style.js +0 -13
  293. package/FormElement/components/Label/style.js +0 -89
  294. package/FormElement/components/Placeholder/style.js +0 -56
  295. package/FormElement/components/Underline/style.js +0 -60
  296. package/FormElement/style.js +0 -14
  297. package/Glow/style.js +0 -18
  298. package/IndicatorCircle/style.js +0 -65
  299. package/LoadingIndicator/style.js +0 -20
  300. package/Manufacturer/style.js +0 -5
  301. package/MessageBar/spec.js +0 -80
  302. package/MessageBar/style.js +0 -38
  303. package/NoResults/components/Icon/style.js +0 -17
  304. package/NoResults/style.js +0 -31
  305. package/Placeholder/style.js +0 -11
  306. package/PlaceholderLabel/style.js +0 -12
  307. package/Price/style.js +0 -22
  308. package/PriceInfo/style.js +0 -5
  309. package/PriceStriked/style.js +0 -36
  310. package/ProgressBar/style.js +0 -85
  311. package/RadioButton/style.js +0 -21
  312. package/RatingStars/style.js +0 -53
  313. package/Ripple/style.js +0 -18
  314. package/ScannerOverlay/components/CameraOverlay/style.js +0 -40
  315. package/ScannerOverlay/components/ScannerBar/components/FlashlightButton/style.js +0 -28
  316. package/ScannerOverlay/components/ScannerBar/style.js +0 -20
  317. package/Sheet/components/Header/components/SearchBar/style.js +0 -47
  318. package/Sheet/components/Header/style.js +0 -50
  319. package/Sheet/style.js +0 -143
  320. package/TaxDisclaimer/style.js +0 -9
  321. package/TextField/components/ErrorText/style.js +0 -27
  322. package/TextField/components/FormElement/style.js +0 -34
  323. package/TextField/components/Hint/style.js +0 -46
  324. package/TextField/components/Label/style.js +0 -80
  325. package/TextField/components/Underline/style.js +0 -60
  326. package/TextField/style.js +0 -35
package/Ripple/index.js CHANGED
@@ -1,240 +1,186 @@
1
- import _createClass from "@babel/runtime/helpers/createClass";
2
- import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
3
- import React, { PureComponent } from 'react';
1
+ import React, { useState, useRef, useCallback, useLayoutEffect } from 'react';
4
2
  import PropTypes from 'prop-types';
5
- import { findDOMNode } from 'react-dom';
6
3
  import clamp from 'lodash/clamp';
7
4
  import { shift } from '@shopgate/pwa-common/helpers/data';
8
5
  import { getOffset } from '@shopgate/pwa-common/helpers/dom';
9
6
  import { themeConfig } from '@shopgate/pwa-common/helpers/config';
7
+ import { makeStyles } from '@shopgate/engage/styles';
10
8
  import RippleAnimation from "./components/RippleAnimation";
11
- import style from "./style";
9
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
10
+ const useStyles = makeStyles()({
11
+ container: {
12
+ position: 'absolute',
13
+ zIndex: 0,
14
+ top: 0,
15
+ left: 0,
16
+ width: '100%',
17
+ height: '100%'
18
+ }
19
+ });
12
20
 
13
21
  /**
14
22
  * The ripple component.
23
+ * @param {Object} props Props.
24
+ * @returns {JSX.Element}
15
25
  */
16
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
17
- let Ripple = /*#__PURE__*/function (_PureComponent) {
18
- /**
19
- * Constructor.
20
- * @param {Object} props The component props.
21
- */
22
- function Ripple(props) {
23
- var _this;
24
- _this = _PureComponent.call(this, props) || this;
25
- /**
26
- * Triggers adding of a new ripple on touch start event.
27
- * @param {Object} event The even object.
28
- */
29
- _this.handleClick = event => {
30
- if (_this.props.disabled) {
31
- return;
32
- }
33
- _this.addRipple(event, true);
34
- _this.props.onClick();
26
+ const Ripple = ({
27
+ children,
28
+ className,
29
+ color,
30
+ disabled,
31
+ fill,
32
+ onClick,
33
+ onComplete,
34
+ overflow,
35
+ size
36
+ }) => {
37
+ const {
38
+ classes,
39
+ cx
40
+ } = useStyles();
41
+ const [{
42
+ ripples,
43
+ hasRipples
44
+ }, setRippleState] = useState({
45
+ ripples: [],
46
+ nextKey: 0,
47
+ hasRipples: false
48
+ });
49
+ const durationRef = useRef(500);
50
+ const ignoreNextMouseDownRef = useRef(false);
51
+ const mountedRef = useRef(false);
52
+ const offsetRef = useRef(null);
53
+ const positionRef = useRef({
54
+ x: 0,
55
+ y: 0
56
+ });
57
+ const rootRef = useRef(null);
58
+ const [containerStyle, setContainerStyle] = useState(null);
59
+ const getRippleSize = useCallback(() => {
60
+ const rootNode = rootRef.current;
61
+ if (!rootNode) {
62
+ return 0;
63
+ }
64
+ if (size) {
65
+ return fill ? size * 2 : size;
66
+ }
67
+ if (fill) {
68
+ return Math.sqrt(rootNode.offsetWidth ** 2 + rootNode.offsetHeight ** 2) * 2;
69
+ }
70
+ return Math.min(rootNode.offsetWidth, rootNode.offsetHeight);
71
+ }, [fill, size]);
72
+ useLayoutEffect(() => {
73
+ const rootNode = rootRef.current;
74
+ if (!rootNode) {
75
+ return undefined;
76
+ }
77
+ mountedRef.current = true;
78
+ positionRef.current = {
79
+ x: rootNode.offsetWidth / 2,
80
+ y: rootNode.offsetHeight / 2
35
81
  };
36
- /**
37
- * Will be triggered from the ripple animation component, when the
38
- * ripple animation is over. It removes the ripple from the queue again.
39
- */
40
- _this.removeRipple = () => {
41
- if (!_this.mounted) {
42
- return;
82
+ const rippleSize = (() => {
83
+ if (size) {
84
+ return fill ? size * 2 : size;
43
85
  }
44
- _this.setState(prevState => {
45
- const ripples = shift(prevState.ripples);
46
- _this.props.onComplete();
47
- return {
48
- ripples,
49
- hasRipples: !!ripples.length
50
- };
51
- });
52
- };
53
- _this.state = {
54
- ripples: [],
55
- nextKey: 0,
56
- hasRipples: false
57
- };
58
- _this.duration = 500;
59
- _this.ignoreNextMouseDown = false;
60
- _this.mounted = false;
61
- _this.offset = null;
62
- _this.position = null;
63
- _this.rootNode = null;
64
- _this.style = null;
65
- return _this;
66
- }
67
-
68
- /**
69
- * Sets the `mounted` flag to true.
70
- */
71
- _inheritsLoose(Ripple, _PureComponent);
72
- var _proto = Ripple.prototype;
73
- _proto.componentDidMount = function componentDidMount() {
74
- const {
75
- fill
76
- } = this.props;
77
-
78
- // Reference to Ripple container (for now and later).
79
- this.rootNode = findDOMNode(this); // eslint-disable-line react/no-find-dom-node
80
-
81
- // Initially set the position values to be in the middle of the element.
82
- // If the Ripple's starting point has to follow the user's touch
83
- // Location then this is checked later.
84
- this.position = {
85
- x: this.rootNode.offsetWidth / 2,
86
- y: this.rootNode.offsetHeight / 2
87
- };
88
-
89
- // Determine the duration based on the size of the ripple.
90
- this.duration = clamp(Math.round(Math.log(this.rippleSize) * 100 - (fill ? -75 : 50)), 0, 10000);
91
-
92
- // Set the `mounted` flag to true.
93
- this.mounted = true;
94
-
95
- // If the Ripple is not allowed to overflow then apply some styles to the parent container.
96
- this.style = !this.props.overflow ? {
86
+ if (fill) {
87
+ return Math.sqrt(rootNode.offsetWidth ** 2 + rootNode.offsetHeight ** 2) * 2;
88
+ }
89
+ return Math.min(rootNode.offsetWidth, rootNode.offsetHeight);
90
+ })();
91
+ durationRef.current = clamp(Math.round(Math.log(rippleSize) * 100 - (fill ? -75 : 50)), 0, 10000);
92
+ setContainerStyle(!overflow ? {
97
93
  overflow: 'hidden',
98
94
  position: 'relative'
99
- } : null;
100
- }
101
-
102
- /**
103
- * Sets the `mounted` flag to false
104
- */;
105
- _proto.componentWillUnmount = function componentWillUnmount() {
106
- this.mounted = false;
107
- }
108
-
109
- /**
110
- * Calculate the size of the ripple.
111
- * @returns {number}
112
- */;
113
- /**
114
- * Calculates the ripple position from the event.
115
- * @param {Object} event The event object.
116
- * @returns {Object} An object containing x and y values for the ripple.
117
- */
118
- _proto.getRipplePosition = function getRipplePosition(event) {
119
- // If the Ripple is to fill the element then we should set the
120
- // Starting position to be where the user clicked within that element.
121
- if (this.props.fill) {
122
- // Determine if event is a touch event.
95
+ } : null);
96
+ return () => {
97
+ mountedRef.current = false;
98
+ };
99
+ }, [fill, overflow, size]);
100
+ const getRipplePosition = useCallback(event => {
101
+ if (fill) {
123
102
  const isTouchEvent = event.touches && event.touches.length;
124
-
125
- // Find the center points of the event.
126
103
  const pageX = isTouchEvent ? event.touches[0].pageX : event.pageX;
127
104
  const pageY = isTouchEvent ? event.touches[0].pageY : event.pageY;
128
-
129
- // The pointer location is relative to the element offset.
130
- this.position.x = pageX - this.offset.left;
131
- this.position.y = pageY - this.offset.top;
105
+ positionRef.current = {
106
+ x: pageX - offsetRef.current.left,
107
+ y: pageY - offsetRef.current.top
108
+ };
132
109
  }
133
- return this.position;
134
- };
135
- /**
136
- * Adds a new Ripple to the queue.
137
- * @param {Object} event The event object.
138
- * @param {boolean} isTouchGenerated Whether the action was triggered by a touch or click.
139
- */
140
- _proto.addRipple = function addRipple(event, isTouchGenerated) {
141
- // If the adding of the Ripple was already triggered
142
- // By a touch start event, no further action will be done.
143
- if (this.ignoreNextMouseDown && !isTouchGenerated) {
144
- this.ignoreNextMouseDown = false;
110
+ return positionRef.current;
111
+ }, [fill]);
112
+ const removeRipple = useCallback(() => {
113
+ if (!mountedRef.current) {
145
114
  return;
146
115
  }
147
-
148
- // Get the position of the element and store it.
149
- this.offset = getOffset(this.rootNode);
150
-
151
- // Receive the x and y position for the new Ripple.
116
+ setRippleState(prev => {
117
+ const nextRipples = shift(prev.ripples);
118
+ onComplete();
119
+ return {
120
+ ripples: nextRipples,
121
+ nextKey: prev.nextKey,
122
+ hasRipples: !!nextRipples.length
123
+ };
124
+ });
125
+ }, [onComplete]);
126
+ const addRipple = useCallback((event, isTouchGenerated) => {
127
+ if (ignoreNextMouseDownRef.current && !isTouchGenerated) {
128
+ ignoreNextMouseDownRef.current = false;
129
+ return;
130
+ }
131
+ const rootNode = rootRef.current;
132
+ if (!rootNode) {
133
+ return;
134
+ }
135
+ offsetRef.current = getOffset(rootNode);
152
136
  const {
153
137
  x,
154
138
  y
155
- } = this.getRipplePosition(event);
156
- const {
157
- ripples
158
- } = this.state;
159
-
160
- // Append the new ripple to the ripples array.
161
- ripples.push(/*#__PURE__*/_jsx(RippleAnimation, {
162
- color: this.props.color,
163
- duration: this.duration,
164
- fill: this.props.fill,
165
- onComplete: this.removeRipple,
166
- size: this.rippleSize,
167
- x: x,
168
- y: y
169
- }, this.state.nextKey));
170
- this.ignoreNextMouseDown = isTouchGenerated;
171
-
172
- // Update the state.
173
- this.setState(({
174
- nextKey
175
- }) => ({
176
- ripples,
177
- nextKey: nextKey + 1,
178
- hasRipples: true
179
- }));
180
- }
181
-
182
- /**
183
- * Renders all the ripples in the queue.
184
- * @returns {JSX|null}
185
- */;
186
- _proto.renderRipples = function renderRipples() {
187
- // It only needs to render, if there is at least one ripple in the queue.
188
- if (!this.state.hasRipples) {
189
- return null;
190
- }
191
- return /*#__PURE__*/_jsx("div", {
192
- className: style.container,
193
- children: this.state.ripples
194
- });
195
- }
196
-
197
- /**
198
- * Renders the final ripple component including it's contents.
199
- * @returns {JSX}
200
- */;
201
- _proto.render = function render() {
202
- /* eslint-disable jsx-a11y/click-events-have-key-events,
203
- jsx-a11y/no-static-element-interactions */
204
- return /*#__PURE__*/_jsxs("div", {
205
- className: `ui-shared__ripple ${this.props.className}`,
206
- "data-test-id": "Ripple",
207
- onClick: this.handleClick,
208
- style: this.style,
209
- children: [this.renderRipples(), this.props.children]
139
+ } = getRipplePosition(event);
140
+ const rippleSize = getRippleSize();
141
+ setRippleState(prev => {
142
+ const nextRipples = [].concat(prev.ripples);
143
+ nextRipples.push(/*#__PURE__*/_jsx(RippleAnimation, {
144
+ color: color,
145
+ duration: durationRef.current,
146
+ fill: fill,
147
+ onComplete: removeRipple,
148
+ size: rippleSize,
149
+ x: x,
150
+ y: y
151
+ }, prev.nextKey));
152
+ return {
153
+ ripples: nextRipples,
154
+ nextKey: prev.nextKey + 1,
155
+ hasRipples: true
156
+ };
210
157
  });
211
- /* eslint-enable jsx-a11y/click-events-have-key-events,
212
- jsx-a11y/no-static-element-interactions */
213
- };
214
- return _createClass(Ripple, [{
215
- key: "rippleSize",
216
- get: function () {
217
- if (this.props.size) {
218
- if (this.props.fill) {
219
- return this.props.size * 2;
220
- }
221
- return this.props.size;
222
- }
223
-
224
- /**
225
- * We want the Ripple to fill the element. We set the diameter of the Ripple
226
- * to double the distance of the opposing corners of the node. That way the Ripple
227
- * will reach the furthest away corner if you click at a corner.
228
- */
229
- if (this.props.fill) {
230
- return Math.sqrt(this.rootNode.offsetWidth ** 2 + this.rootNode.offsetHeight ** 2) * 2;
231
- }
232
-
233
- // Otherwise we set the size to be the smaller of the element's height and width.
234
- return Math.min(this.rootNode.offsetWidth, this.rootNode.offsetHeight);
158
+ ignoreNextMouseDownRef.current = isTouchGenerated;
159
+ }, [color, fill, getRipplePosition, getRippleSize, removeRipple]);
160
+ const handleClick = useCallback(event => {
161
+ if (disabled) {
162
+ return;
235
163
  }
236
- }]);
237
- }(PureComponent);
164
+ addRipple(event, true);
165
+ onClick();
166
+ }, [addRipple, disabled, onClick]);
167
+
168
+ /* eslint-disable jsx-a11y/click-events-have-key-events,
169
+ jsx-a11y/no-static-element-interactions */
170
+ return /*#__PURE__*/_jsxs("div", {
171
+ ref: rootRef,
172
+ className: cx('ui-shared__ripple', className),
173
+ "data-test-id": "Ripple",
174
+ onClick: handleClick,
175
+ style: containerStyle,
176
+ children: [hasRipples ? /*#__PURE__*/_jsx("div", {
177
+ className: classes.container,
178
+ children: ripples
179
+ }) : null, children]
180
+ });
181
+ /* eslint-enable jsx-a11y/click-events-have-key-events,
182
+ jsx-a11y/no-static-element-interactions */
183
+ };
238
184
  Ripple.defaultProps = {
239
185
  className: '',
240
186
  color: themeConfig.colors.dark,
@@ -1,75 +1,78 @@
1
- import _createClass from "@babel/runtime/helpers/createClass";
2
- import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
3
- import React, { Component } from 'react';
1
+ import React from 'react';
4
2
  import PropTypes from 'prop-types';
3
+ import BaseButton from '@shopgate/pwa-common/components/Button';
4
+ import { makeStyles, cx } from '@shopgate/engage/styles';
5
5
  import Ripple from "../Ripple";
6
6
  import Button from "../Button";
7
- import style from "../Button/style";
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
+ const useStyles = makeStyles()(theme => ({
9
+ contentWrapper: {
10
+ padding: theme.spacing(0, 2, 0)
11
+ }
12
+ }));
8
13
 
9
14
  /**
10
15
  * The ripple button component is a special derivation of the basic button component
11
16
  * that adds a ripple effect when clicked.
17
+ * @param {Object} props Props.
18
+ * @returns {JSX.Element}
12
19
  */
13
- import { jsx as _jsx } from "react/jsx-runtime";
14
- let RippleButton = /*#__PURE__*/function (_Component) {
15
- function RippleButton() {
16
- return _Component.apply(this, arguments) || this;
17
- }
18
- _inheritsLoose(RippleButton, _Component);
19
- var _proto = RippleButton.prototype;
20
- /**
21
- * Renders the component.
22
- * @returns {JSX}
23
- */
24
- _proto.render = function render() {
25
- if (this.props.disabled) {
26
- // Don't show the ripple effect when the button is disabled.
27
- return /*#__PURE__*/_jsx(Button, {
28
- ...this.buttonProps,
29
- wrapContent: true,
30
- children: this.props.children
31
- });
32
- }
33
- const rippleProps = {
34
- className: `${style.contentWrapper} ${this.props.rippleClassName}`,
35
- fill: true,
36
- size: this.props.rippleSize,
37
- overflow: true
38
- };
20
+ const RippleButton = ({
21
+ children,
22
+ className,
23
+ disabled,
24
+ flat,
25
+ onClick,
26
+ rippleClassName,
27
+ rippleSize,
28
+ testId,
29
+ type,
30
+ 'aria-label': ariaLabel,
31
+ 'aria-haspopup': ariaHaspopup
32
+ }) => {
33
+ const {
34
+ classes
35
+ } = useStyles();
36
+ const buttonProps = {
37
+ className: `${className} ui-shared__ripple-button`,
38
+ disabled,
39
+ onClick,
40
+ flat,
41
+ type,
42
+ wrapContent: false,
43
+ 'aria-label': ariaLabel,
44
+ 'aria-haspopup': ariaHaspopup
45
+ };
46
+ if (disabled) {
39
47
  return /*#__PURE__*/_jsx(Button, {
40
- ...this.buttonProps,
41
- testId: this.props.testId,
42
- children: /*#__PURE__*/_jsx(Ripple, {
43
- ...rippleProps,
44
- children: this.props.children
45
- })
48
+ ...buttonProps,
49
+ wrapContent: true,
50
+ children: children
46
51
  });
52
+ }
53
+ const rippleProps = {
54
+ className: cx(classes.contentWrapper, rippleClassName),
55
+ fill: true,
56
+ size: rippleSize,
57
+ overflow: true
47
58
  };
48
- return _createClass(RippleButton, [{
49
- key: "buttonProps",
50
- get:
51
- /**
52
- * Getter for the calculated button props.
53
- * @returns {Object}
54
- */
55
- function () {
56
- return {
57
- className: `${this.props.className} ui-shared__ripple-button`,
58
- disabled: this.props.disabled,
59
- onClick: this.props.onClick,
60
- flat: this.props.flat,
61
- type: this.props.type,
62
- wrapContent: false,
63
- 'aria-label': this.props['aria-label'],
64
- 'aria-haspopup': this.props['aria-haspopup']
65
- };
66
- }
67
- }]);
68
- }(Component);
59
+ return /*#__PURE__*/_jsx(Button, {
60
+ ...buttonProps,
61
+ testId: testId,
62
+ children: /*#__PURE__*/_jsx(Ripple, {
63
+ ...rippleProps,
64
+ children: children
65
+ })
66
+ });
67
+ };
69
68
  RippleButton.defaultProps = {
70
- ...Button.defaultProps,
69
+ ...BaseButton.defaultProps,
70
+ className: '',
71
+ flat: false,
72
+ type: 'primary',
73
+ wrapContent: true,
74
+ testId: 'Button',
71
75
  rippleClassName: '',
72
- rippleSize: null,
73
- testId: 'Button'
76
+ rippleSize: null
74
77
  };
75
78
  export default RippleButton;
@@ -1,25 +1,27 @@
1
1
  import trim from 'lodash/trim';
2
2
  import React from 'react';
3
- import { shallow, mount } from 'enzyme';
4
- import Button from '@shopgate/pwa-common/components/Button';
3
+ import { mount } from 'enzyme';
4
+ import BaseButton from '@shopgate/pwa-common/components/Button';
5
5
  import Ripple from "../Ripple";
6
- import styles from "../Button/style";
7
6
  import RippleButton from "./index";
8
7
  import { jsx as _jsx } from "react/jsx-runtime";
9
8
  describe('<RippleButton />', () => {
10
9
  it('should render as a regular ripple button effect if type is omitted', () => {
11
- const wrapper = shallow(/*#__PURE__*/_jsx(RippleButton, {
10
+ const wrapper = mount(/*#__PURE__*/_jsx(RippleButton, {
12
11
  children: "Press me"
13
12
  }));
14
13
  expect(wrapper).toMatchSnapshot();
15
- expect(wrapper.find(Ripple).render().text()).toEqual('Press me');
14
+ expect(wrapper.find(Ripple).text()).toEqual('Press me');
16
15
  });
17
16
  it('should render as a regular ripple button if type is explicitly defined', () => {
18
17
  const wrapper = mount(/*#__PURE__*/_jsx(RippleButton, {
19
18
  type: "regular",
20
19
  children: "Press me"
21
20
  }));
22
- expect(trim(wrapper.find(Button).props().className)).toEqual(`ui-shared__button ${styles.regular(false).button} ui-shared__ripple-button`);
21
+ const base = wrapper.find(BaseButton);
22
+ expect(base.exists()).toBe(true);
23
+ expect(trim(base.props().className)).toMatch(/^ui-shared__button /);
24
+ expect(trim(base.props().className)).toContain('ui-shared__ripple-button');
23
25
  expect(wrapper.find(Ripple).render().text()).toEqual('Press me');
24
26
  expect(wrapper).toMatchSnapshot();
25
27
  });
@@ -28,7 +30,9 @@ describe('<RippleButton />', () => {
28
30
  type: "primary",
29
31
  children: "Press me"
30
32
  }));
31
- expect(trim(wrapper.find(Button).props().className)).toEqual(`ui-shared__button ${styles.primary(false).button} ui-shared__ripple-button`);
33
+ const base = wrapper.find(BaseButton);
34
+ expect(trim(base.props().className)).toMatch(/^ui-shared__button /);
35
+ expect(trim(base.props().className)).toContain('ui-shared__ripple-button');
32
36
  expect(wrapper.find(Ripple).render().text()).toEqual('Press me');
33
37
  expect(wrapper).toMatchSnapshot();
34
38
  });
@@ -37,7 +41,9 @@ describe('<RippleButton />', () => {
37
41
  type: "secondary",
38
42
  children: "Press me"
39
43
  }));
40
- expect(trim(wrapper.find(Button).props().className)).toEqual(`ui-shared__button ${styles.secondary(false).button} ui-shared__ripple-button`);
44
+ const base = wrapper.find(BaseButton);
45
+ expect(trim(base.props().className)).toMatch(/^ui-shared__button /);
46
+ expect(trim(base.props().className)).toContain('ui-shared__ripple-button');
41
47
  expect(wrapper.find(Ripple).render().text()).toEqual('Press me');
42
48
  expect(wrapper).toMatchSnapshot();
43
49
  });
@@ -46,7 +52,7 @@ describe('<RippleButton />', () => {
46
52
  disabled: true,
47
53
  children: "Press me"
48
54
  }));
49
- expect(wrapper.find(Button).props().disabled).toBe(true);
55
+ expect(wrapper.find(BaseButton).props().disabled).toBe(true);
50
56
  expect(wrapper).toMatchSnapshot();
51
57
  });
52
58
  });
@@ -1,17 +1,61 @@
1
1
  import React from 'react';
2
2
  import SurroundPortals from '@shopgate/pwa-common/components/SurroundPortals';
3
3
  import { SCANNER_CAMERA } from '@shopgate/pwa-common-commerce/scanner/constants/Portals';
4
- import styles from "./style";
4
+ import { themeColors } from '@shopgate/pwa-common/helpers/config';
5
+ import { makeStyles } from '@shopgate/engage/styles';
6
+ import { jsx as _jsx } from "react/jsx-runtime";
7
+ const edgeHeight = 45;
8
+ const edgeWidth = 35;
9
+ const edgeBorderWidth = 3;
10
+ const useStyles = makeStyles()(theme => ({
11
+ root: {
12
+ height: '90%',
13
+ width: '100%',
14
+ ':before,:after,>:before,>:after': {
15
+ display: 'block',
16
+ content: '""',
17
+ width: edgeWidth,
18
+ height: edgeHeight,
19
+ position: 'absolute',
20
+ borderStyle: 'solid',
21
+ borderColor: themeColors.light
22
+ },
23
+ ':before': {
24
+ top: theme.spacing(8),
25
+ left: theme.spacing(4),
26
+ borderWidth: `${edgeBorderWidth}px 0 0 ${edgeBorderWidth}px`
27
+ },
28
+ ':after': {
29
+ top: theme.spacing(8),
30
+ right: theme.spacing(4),
31
+ borderWidth: `${edgeBorderWidth}px ${edgeBorderWidth}px 0 0`
32
+ },
33
+ '>:before': {
34
+ bottom: theme.spacing(8),
35
+ left: theme.spacing(4),
36
+ borderWidth: `0 0 ${edgeBorderWidth}px ${edgeBorderWidth}px`
37
+ },
38
+ '>:after': {
39
+ bottom: theme.spacing(8),
40
+ right: theme.spacing(4),
41
+ borderWidth: `0 ${edgeBorderWidth}px ${edgeBorderWidth}px 0`
42
+ }
43
+ }
44
+ }));
5
45
 
6
46
  /**
7
- * @returns {JSX}
47
+ * @returns {JSX.Element}
8
48
  */
9
- import { jsx as _jsx } from "react/jsx-runtime";
10
- const CameraOverlay = () => /*#__PURE__*/_jsx(SurroundPortals, {
11
- portalName: SCANNER_CAMERA,
12
- children: /*#__PURE__*/_jsx("div", {
13
- className: styles,
14
- children: /*#__PURE__*/_jsx("div", {})
15
- })
16
- });
49
+ const CameraOverlay = () => {
50
+ const {
51
+ classes
52
+ } = useStyles();
53
+ return /*#__PURE__*/_jsx(SurroundPortals, {
54
+ portalName: SCANNER_CAMERA,
55
+ children: /*#__PURE__*/_jsx("div", {
56
+ className: classes.root,
57
+ children: /*#__PURE__*/_jsx("div", {})
58
+ })
59
+ });
60
+ };
17
61
  export default CameraOverlay;