UNPKG

2.24 kBJavaScriptView Raw
1import * as React from 'react';
2import PropTypes from 'prop-types';
3import clsx from 'clsx';
4/**
5 * @ignore - internal component.
6 */
7
8import { jsx as _jsx } from "react/jsx-runtime";
9
10function Ripple(props) {
11 const {
12 className,
13 classes,
14 pulsate = false,
15 rippleX,
16 rippleY,
17 rippleSize,
18 in: inProp,
19 onExited,
20 timeout
21 } = props;
22 const [leaving, setLeaving] = React.useState(false);
23 const rippleClassName = clsx(className, classes.ripple, classes.rippleVisible, pulsate && classes.ripplePulsate);
24 const rippleStyles = {
25 width: rippleSize,
26 height: rippleSize,
27 top: -(rippleSize / 2) + rippleY,
28 left: -(rippleSize / 2) + rippleX
29 };
30 const childClassName = clsx(classes.child, leaving && classes.childLeaving, pulsate && classes.childPulsate);
31
32 if (!inProp && !leaving) {
33 setLeaving(true);
34 }
35
36 React.useEffect(() => {
37 if (!inProp && onExited != null) {
38 // react-transition-group#onExited
39 const timeoutId = setTimeout(onExited, timeout);
40 return () => {
41 clearTimeout(timeoutId);
42 };
43 }
44
45 return undefined;
46 }, [onExited, inProp, timeout]);
47 return /*#__PURE__*/_jsx("span", {
48 className: rippleClassName,
49 style: rippleStyles,
50 children: /*#__PURE__*/_jsx("span", {
51 className: childClassName
52 })
53 });
54}
55
56process.env.NODE_ENV !== "production" ? Ripple.propTypes = {
57 /**
58 * Override or extend the styles applied to the component.
59 * See [CSS API](#css) below for more details.
60 */
61 classes: PropTypes.object.isRequired,
62 className: PropTypes.string,
63
64 /**
65 * @ignore - injected from TransitionGroup
66 */
67 in: PropTypes.bool,
68
69 /**
70 * @ignore - injected from TransitionGroup
71 */
72 onExited: PropTypes.func,
73
74 /**
75 * If `true`, the ripple pulsates, typically indicating the keyboard focus state of an element.
76 */
77 pulsate: PropTypes.bool,
78
79 /**
80 * Diameter of the ripple.
81 */
82 rippleSize: PropTypes.number,
83
84 /**
85 * Horizontal position of the ripple center.
86 */
87 rippleX: PropTypes.number,
88
89 /**
90 * Vertical position of the ripple center.
91 */
92 rippleY: PropTypes.number,
93
94 /**
95 * exit delay
96 */
97 timeout: PropTypes.number.isRequired
98} : void 0;
99export default Ripple;
\No newline at end of file