forked from mui/material-ui
/
Ripple.js
80 lines (71 loc) · 1.81 KB
/
Ripple.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { Transition } from 'react-transition-group';
/**
* @ignore - internal component.
*/
function Ripple(props) {
const { classes, className, pulsate = false, rippleX, rippleY, rippleSize, ...other } = props;
const [visible, setVisible] = React.useState(false);
const [leaving, setLeaving] = React.useState(false);
const handleEnter = () => {
setVisible(true);
};
const handleExit = () => {
setLeaving(true);
};
const rippleClassName = clsx(
classes.ripple,
{
[classes.rippleVisible]: visible,
[classes.ripplePulsate]: pulsate,
},
className,
);
const rippleStyles = {
width: rippleSize,
height: rippleSize,
top: -(rippleSize / 2) + rippleY,
left: -(rippleSize / 2) + rippleX,
};
const childClassName = clsx(classes.child, {
[classes.childLeaving]: leaving,
[classes.childPulsate]: pulsate,
});
return (
<Transition onEnter={handleEnter} onExit={handleExit} {...other}>
<span className={rippleClassName} style={rippleStyles}>
<span className={childClassName} />
</span>
</Transition>
);
}
Ripple.propTypes = {
/**
* Override or extend the styles applied to the component.
* See [CSS API](#css) below for more details.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string,
/**
* If `true`, the ripple pulsates, typically indicating the keyboard focus state of an element.
*/
pulsate: PropTypes.bool,
/**
* Diameter of the ripple.
*/
rippleSize: PropTypes.number,
/**
* Horizontal position of the ripple center.
*/
rippleX: PropTypes.number,
/**
* Vertical position of the ripple center.
*/
rippleY: PropTypes.number,
};
export default Ripple;