@shopgate/pwa-ui-shared 7.30.0-alpha.12 → 7.30.0-alpha.13

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.
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useRef, useMemo } from 'react';
1
+ import React, { memo, useRef, useMemo } from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { Transition } from 'react-transition-group';
4
4
  import { themeConfig } from '@shopgate/pwa-common/helpers/config';
@@ -27,68 +27,62 @@ function RippleAnimation({
27
27
  y
28
28
  }) {
29
29
  const nodeRef = useRef(null);
30
-
31
- // Trigger the animation immediately
32
- const inProp = true;
33
30
  const baseStyle = useMemo(() => ({
34
- position: 'absolute',
35
31
  backgroundColor: color,
36
32
  height: size,
37
33
  width: size,
38
34
  left: x,
39
35
  top: y,
40
- borderRadius: '50%',
41
- transform: 'translate3d(-50%, -50%, 0) scale3d(0, 0, 1)',
42
36
  opacity: 0.25,
37
+ transform: 'translate3d(-50%, -50%, 0) scale3d(0, 0, 1)',
43
38
  transition: `opacity ${duration}ms cubic-bezier(0.25, 0.1, 0.25, 1), transform ${duration}ms cubic-bezier(0.25, 0.1, 0.25, 1)`,
44
- pointerEvents: 'none'
45
- }), [color, duration, size, x, y]);
46
- const transitionStyles = useMemo(() => ({
47
- entering: {
48
- transform: 'translate3d(-50%, -50%, 0) scale3d(1, 1, 1)',
49
- opacity: 0
50
- },
51
- entered: {
52
- transform: 'translate3d(-50%, -50%, 0) scale3d(1, 1, 1)',
53
- opacity: 0
54
- },
55
- exiting: {},
56
- exited: {},
57
- unmounted: {}
39
+ willChange: 'transform, opacity'
40
+ }), [color, size, x, y, duration]);
41
+ const activeStyle = useMemo(() => ({
42
+ transform: 'translate3d(-50%, -50%, 0) scale3d(1, 1, 1)',
43
+ opacity: 0
58
44
  }), []);
59
45
 
60
- // Run callback when transition ends
61
- useEffect(() => {
62
- const el = nodeRef.current;
63
- if (!el) return undefined;
64
-
65
- /**
66
- * Handles the transition end event and calls onComplete for relevant properties.
67
- * @param {TransitionEvent} e - The transition event object
68
- */
69
- const handleEnd = e => {
70
- // Only handle transform or opacity transitions
71
- if (e.propertyName === 'transform' || e.propertyName === 'opacity') {
72
- onComplete();
73
- }
74
- };
75
- el.addEventListener('transitionend', handleEnd);
76
- return () => el.removeEventListener('transitionend', handleEnd);
77
- }, [onComplete]);
46
+ /**
47
+ * Resolves ripple animation styles for a given transition state.
48
+ *
49
+ * @param {string} state React Transition state.
50
+ * @returns {React.CSSProperties} Computed inline styles.
51
+ */
52
+ const getStyleForState = state => {
53
+ // Transition states: 'entering', 'entered', 'exiting', 'exited'
54
+ if (state === 'entering' || state === 'entered') {
55
+ return {
56
+ ...baseStyle,
57
+ ...activeStyle
58
+ };
59
+ }
60
+ return baseStyle;
61
+ };
78
62
  return /*#__PURE__*/_jsx(Transition, {
79
- in: inProp,
80
- timeout: duration,
63
+ in: true,
64
+ timeout: {
65
+ appear: duration,
66
+ enter: duration,
67
+ exit: 0
68
+ },
81
69
  appear: true,
82
70
  mountOnEnter: true,
83
71
  unmountOnExit: true,
84
72
  nodeRef: nodeRef,
73
+ onEnter: () => {
74
+ // Force layout/reflow so Safari & Chrome reliably apply the transition
75
+ // before switching to the "entering" styles.
76
+ if (nodeRef.current) {
77
+ // eslint-disable-next-line no-unused-expressions
78
+ nodeRef.current.offsetHeight;
79
+ }
80
+ },
81
+ onEntered: onComplete,
85
82
  children: state => /*#__PURE__*/_jsx("div", {
86
83
  ref: nodeRef,
87
84
  className: style.ripple,
88
- style: {
89
- ...baseStyle,
90
- ...transitionStyles[state]
91
- }
85
+ style: getStyleForState(state)
92
86
  })
93
87
  });
94
88
  }
@@ -100,4 +94,4 @@ RippleAnimation.defaultProps = {
100
94
  x: 0,
101
95
  y: 0
102
96
  };
103
- export default /*#__PURE__*/React.memo(RippleAnimation);
97
+ export default /*#__PURE__*/memo(RippleAnimation);
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@shopgate/pwa-ui-shared",
3
- "version": "7.30.0-alpha.12",
3
+ "version": "7.30.0-alpha.13",
4
4
  "description": "Shopgate's shared UI components.",
5
5
  "main": "index.js",
6
6
  "license": "Apache-2.0",
7
7
  "dependencies": {
8
- "@shopgate/pwa-ui-ios": "7.30.0-alpha.12",
9
- "@shopgate/pwa-ui-material": "7.30.0-alpha.12"
8
+ "@shopgate/pwa-ui-ios": "7.30.0-alpha.13",
9
+ "@shopgate/pwa-ui-material": "7.30.0-alpha.13"
10
10
  },
11
11
  "devDependencies": {
12
- "@shopgate/pwa-common": "7.30.0-alpha.12",
13
- "@shopgate/pwa-common-commerce": "7.30.0-alpha.12",
12
+ "@shopgate/pwa-common": "7.30.0-alpha.13",
13
+ "@shopgate/pwa-common-commerce": "7.30.0-alpha.13",
14
14
  "classnames": "2.5.1",
15
15
  "react": "^17.0.2"
16
16
  },