Files
goTorrent/goTorrentWebUI/node_modules/material-ui/ButtonBase/Ripple.js.flow

102 lines
2.1 KiB
Plaintext

import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import Transition from 'react-transition-group/Transition';
/**
* @ignore - internal component.
*/
class Ripple extends React.Component {
state = {
rippleVisible: false,
rippleLeaving: false,
};
handleEnter = () => {
this.setState({
rippleVisible: true,
});
};
handleExit = () => {
this.setState({
rippleLeaving: true,
});
};
render() {
const {
classes,
className: classNameProp,
pulsate,
rippleX,
rippleY,
rippleSize,
...other
} = this.props;
const { rippleVisible, rippleLeaving } = this.state;
const className = classNames(
classes.wrapper,
{
[classes.wrapperLeaving]: rippleLeaving,
[classes.wrapperPulsating]: pulsate,
},
classNameProp,
);
const rippleClassName = classNames(classes.ripple, {
[classes.rippleVisible]: rippleVisible,
[classes.rippleFast]: pulsate,
});
const rippleStyles = {
width: rippleSize,
height: rippleSize,
top: -(rippleSize / 2) + rippleY,
left: -(rippleSize / 2) + rippleX,
};
return (
<Transition onEnter={this.handleEnter} onExit={this.handleExit} {...other}>
<span className={className}>
<span className={rippleClassName} style={rippleStyles} />
</span>
</Transition>
);
}
}
Ripple.propTypes = {
/**
* Useful to extend the style applied to components.
*/
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,
};
Ripple.defaultProps = {
pulsate: false,
};
export default Ripple;