Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite ripple in ES6 and update its dependencies
- Loading branch information
1 parent
736fce8
commit 44cab7f
Showing
6 changed files
with
121 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* global React */ | ||
|
||
import { addons } from 'react/addons'; | ||
import style from './style'; | ||
|
||
export default React.createClass({ | ||
mixins: [addons.PureRenderMixin], | ||
|
||
displayName: 'Ripple', | ||
|
||
propTypes: { | ||
auto: React.PropTypes.bool, | ||
className: React.PropTypes.string, | ||
loading: React.PropTypes.bool | ||
}, | ||
|
||
getDefaultProps () { | ||
return { | ||
auto: true, | ||
className: '', | ||
loading: false | ||
}; | ||
}, | ||
|
||
getInitialState () { | ||
return { | ||
active: false, | ||
restarting: false, | ||
top: null, | ||
left: null, | ||
width: null | ||
}; | ||
}, | ||
|
||
start ({ pageX, pageY }) { | ||
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 () { | ||
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; | ||
let className = `${style.ripple} ${this.props.className}`; | ||
if (this.state.active) className += ' active'; | ||
if (this.state.restarting) className += ' restarting'; | ||
if (this.props.loading) className += ' loading'; | ||
|
||
return ( | ||
<span | ||
className={style.root} | ||
onMouseDown={this.props.auto ? this.start : null} | ||
onMouseUp={this.end}> | ||
|
||
<span | ||
ref="ripple" | ||
className={className} | ||
style={{left: left, top: top, width: width, height: width}}> | ||
</span> | ||
</span> | ||
); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,47 @@ | ||
@import '../constants' | ||
|
||
FINAL_OPACITY = .4 | ||
|
||
:local(.root) | ||
position : absolute | ||
background-color : alpha(WHITE, 0.65) | ||
transform translateX(-50%) translateY(-50%) | ||
top : 0 | ||
left : 0 | ||
right : 0 | ||
bottom : 0 | ||
|
||
:local(.ripple) | ||
position : absolute | ||
background-color : currentColor | ||
transform : translateX(-50%) translateY(-50%) | ||
border-radius : 50% | ||
width : SIZE = (4 * UNIT) | ||
height : SIZE | ||
pointer-events : none | ||
opacity : 0 | ||
// -- Classes | ||
&.active, &.loading | ||
animation-name ripple | ||
animation-timing-function ANIMATION_EASE | ||
animation-duration (2 * ANIMATION_DURATION) | ||
&.active | ||
animation-iteration-count 1 | ||
width : 0 | ||
height : 0 | ||
opacity : FINAL_OPACITY | ||
transition-duration : 1.4 * ANIMATION_DURATION | ||
transition-property : height, width | ||
|
||
&:not(.active).restarting | ||
transition-property : none | ||
|
||
&:not(.active) | ||
opacity : 0 | ||
transition-property : opacity, height, width | ||
|
||
&.loading | ||
animation-name : ripple | ||
animation-iteration-count : infinite | ||
animation-timing-function : ANIMATION_EASE | ||
animation-duration : (2 * ANIMATION_DURATION) | ||
height : (4 * UNIT) | ||
width : (4 * UNIT) | ||
left : 50% | ||
opacity : 0 | ||
top : 50% | ||
animation-iteration-count infinite | ||
|
||
@keyframes ripple | ||
0% | ||
width : 0 | ||
height : 0 | ||
opacity : 1 | ||
opacity : FINAL_OPACITY | ||
100% | ||
opacity : 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters