-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
/
Copy pathfocus-ripple.jsx
89 lines (71 loc) · 2.2 KB
/
focus-ripple.jsx
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
81
82
83
84
85
86
87
88
89
var React = require('react');
var StylePropable = require('../mixins/style-propable');
var Transitions = require('../styles/transitions');
var Colors = require('../styles/colors');
var pulsateDuration = 750;
var FocusRipple = React.createClass({
mixins: [StylePropable],
propTypes: {
color: React.PropTypes.string,
opacity: React.PropTypes.number,
show: React.PropTypes.bool,
innerStyle: React.PropTypes.object
},
getDefaultProps: function() {
return {
color: Colors.darkBlack
};
},
componentDidMount: function() {
this._setRippleSize();
this._pulsate();
},
render: function() {
var outerStyles = this.mergeAndPrefix({
height: '100%',
width: '100%',
position: 'absolute',
top: 0,
left: 0,
transition: Transitions.easeOut(),
transform: this.props.show ? 'scale(1)' : 'scale(0)',
opacity: this.props.show ? 1 : 0
}, this.props.style);
var innerStyles = this.mergeAndPrefix({
position: 'absolute',
height: '100%',
width: '100%',
borderRadius: '50%',
opacity: this.props.opacity ? this.props.opacity : 0.16,
backgroundColor: this.props.color,
transition: Transitions.easeOut(pulsateDuration + 'ms', null, null, Transitions.easeInOutFunction)
}, this.props.innerStyle);
return (
<div style={outerStyles}>
<div ref="innerCircle" style={innerStyles} />
</div>
);
},
_pulsate: function() {
if (!this.isMounted()) return;
var startScale = 'scale(0.75)';
var endScale = 'scale(0.85)';
var innerCircle = React.findDOMNode(this.refs.innerCircle);
var currentScale = innerCircle.style.transform;
var nextScale;
currentScale = currentScale || startScale;
nextScale = currentScale === startScale ?
endScale : startScale;
innerCircle.style.transform = nextScale;
setTimeout(this._pulsate, pulsateDuration);
},
_setRippleSize: function() {
var el = React.findDOMNode(this);
var height = el.offsetHeight;
var width = el.offsetWidth;
var size = Math.max(height, width);
el.style.height = size + 'px';
el.style.top = (size / 2 * -1) + (height / 2) + 'px';
}
});
module.exports = FocusRipple;