-
-
Save myndzi/7809b2c5aa2421f30679 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var items = this.state.items.map(item => { | |
var data = item.value; | |
return ( | |
<Fadeable key={data.id} | |
onComplete={() => Actions.remove(data.id)} | |
transition="opacity 0.5s ease-in" | |
style={{opacity: 0, color: 'red'}}> | |
<li> | |
State: {item.state}, ID: {data.id}, Tag: {data.tag} | |
<a onClick={Fadeable}>delete</a> | |
</li> | |
</Fadeable> | |
); | |
}); |
This file contains hidden or 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
'use strict'; | |
var React = require('react/addons'); | |
var bindMethods = require('utils/bind-methods'); | |
class Fadeable extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { }; | |
this.el = null; | |
bindMethods(this, ['onTransitionEnd', 'transition', 'wrap']); | |
} | |
onTransitionEnd() { | |
this.props.onComplete(); | |
} | |
componentDidMount() { | |
this.el = React.findDOMNode(this); | |
this.el.addEventListener('transitionend', this.onTransitionEnd); | |
} | |
componentWillUnmount() { | |
this.el.removeEventListener('transitionend', this.onTransitionEnd); | |
} | |
transition() { | |
this.setState(Object.assign({ | |
transition: this.props.transition | |
}, this.props.style)); | |
} | |
wrap(child, cb) { | |
if (child && !child._isReactElement) { return child; } | |
var obj = { }, doWrap = false; | |
Object.keys(child.props) | |
.forEach(function (key) { | |
if (child.props[key] === Fadeable) { | |
obj[key] = this.transition; | |
} | |
}, this); | |
if (child.props.children) { | |
obj.children = React.Children.map(child.props.children, this.wrap); | |
} | |
if (!Object.keys(obj).length) { return child; } | |
return React.addons.cloneWithProps(child, obj); | |
} | |
render() { | |
return React.addons.cloneWithProps( | |
this.wrap(this.props.children), { | |
style: this.state | |
} | |
); | |
} | |
} | |
module.exports = Fadeable; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment