2015-09-18 20:21:54 +03:00
|
|
|
/* global React */
|
|
|
|
|
|
|
|
import { addons } from 'react/addons';
|
2015-10-02 18:39:26 +03:00
|
|
|
import CSSModules from 'react-css-modules';
|
|
|
|
import style from './style.scss';
|
2015-09-18 20:21:54 +03:00
|
|
|
|
2015-10-02 18:39:26 +03:00
|
|
|
const Ripple = React.createClass({
|
2015-09-18 20:21:54 +03:00
|
|
|
mixins: [addons.PureRenderMixin],
|
|
|
|
|
|
|
|
displayName: 'Ripple',
|
|
|
|
|
|
|
|
propTypes: {
|
|
|
|
className: React.PropTypes.string,
|
|
|
|
loading: React.PropTypes.bool
|
|
|
|
},
|
|
|
|
|
|
|
|
getDefaultProps () {
|
|
|
|
return {
|
|
|
|
className: '',
|
|
|
|
loading: false
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
getInitialState () {
|
|
|
|
return {
|
|
|
|
active: false,
|
|
|
|
restarting: false,
|
|
|
|
top: null,
|
|
|
|
left: null,
|
|
|
|
width: null
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
start ({ pageX, pageY }) {
|
2015-10-02 18:39:26 +03:00
|
|
|
document.addEventListener('mouseup', this.end);
|
2015-09-18 20:21:54 +03:00
|
|
|
const {top, left, width} = this._getDescriptor(pageX, pageY);
|
|
|
|
this.setState({active: false, restarting: true, width: 0}, () => {
|
|
|
|
this.refs.ripple.getDOMNode().offsetWidth; //eslint-disable-line no-unused-expressions
|
|
|
|
this.setState({active: true, restarting: false, top: top, left: left, width: width});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
end () {
|
2015-10-02 18:39:26 +03:00
|
|
|
document.removeEventListener('mouseup', this.end);
|
2015-09-18 20:21:54 +03:00
|
|
|
this.setState({active: false});
|
|
|
|
},
|
|
|
|
|
|
|
|
_getDescriptor (pageX, pageY) {
|
|
|
|
let { left, top, width } = this.getDOMNode().getBoundingClientRect();
|
|
|
|
return {
|
|
|
|
left: pageX - left,
|
|
|
|
top: pageY - top,
|
|
|
|
width: width * 2.5
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
render () {
|
|
|
|
let { left, top, width } = this.state;
|
2015-10-02 18:39:26 +03:00
|
|
|
let className = this.props.className;
|
|
|
|
let styleName = this.props.loading ? 'loading' : 'normal';
|
|
|
|
if (this.state.active) className += ` ${style.active}`;
|
|
|
|
if (this.state.restarting) className += ` ${style.restarting}`;
|
2015-09-18 20:21:54 +03:00
|
|
|
|
|
|
|
return (
|
2015-10-02 18:39:26 +03:00
|
|
|
<span styleName='wrapper'>
|
2015-09-18 20:21:54 +03:00
|
|
|
<span
|
|
|
|
ref="ripple"
|
2015-10-02 18:39:26 +03:00
|
|
|
data-toolbox='ripple'
|
2015-09-18 20:21:54 +03:00
|
|
|
className={className}
|
2015-10-02 18:39:26 +03:00
|
|
|
styleName={styleName}
|
2015-09-18 20:21:54 +03:00
|
|
|
style={{left: left, top: top, width: width, height: width}}>
|
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2015-10-02 18:39:26 +03:00
|
|
|
|
|
|
|
export default CSSModules(Ripple, style);
|