I have this simple Todo List,
I need to add animate.css library animations when adding and removing. I'm really new to react. I have read the documentation, but it's really hard to understand,
This is a question asking for help with coding.
http://jsfiddle.net/johnthethird/NXCyC/7/
/** @jsx React.DOM */
var TodoList = React.createClass({
propTypes: {items: React.PropTypes.array},
render: function() {
var createItem = function(itemText) {
return <li>{itemText}</li>;
};
return <ul>{this.props.items.map(createItem)}</ul>;
}
});
var TodoApp = React.createClass({
getInitialState: function() {
return {items: [], text: ''};
},
onChange: function(e) {
this.setState({text: e.target.value});
},
handleSubmit: function(e) {
e.preventDefault();
var nextItems = this.state.items.concat([this.state.text]);
var nextText = '';
this.setState({items: nextItems, text: nextText});
},
render: function() {
return (
<div>
<h3>TODO</h3>
<TodoList items={this.state.items} />
<form onSubmit={this.handleSubmit}>
<input onChange={this.onChange} value={this.state.text} />
<button>{'Add #' + (this.state.items.length + 1)}</button>
</form>
</div>
);
}
});
React.renderComponent(<TodoApp />, document.body);
See https://facebook.github.io/react/docs/animation.html
You can use
ReactTransitionGroup
and use the callbacks to setup the animate.css classes on the child nodes.Note that you can't use directly
ReactCSSTransitionGroup
because of the class name convention it has: you have to control the animation class names in order to follow React convention. I mean.transitionName-enter-active
is whatReactCSSTransitionGroup
puts on the node to animate, while you would need something like.animate zoomIn
.Edit
According to this commit / issue I see you can now customize all of the
ReactCSSTransitionGroup
classnames.Look at the proptypes:
I think it is available only for React 0.14.0 (still in beta)
Unfurtunatly according to my tests, this is not enough to support easily Animate.CSS out of the box.
With the new version, one should be able to write:
http://jsfiddle.net/ghmpo42k/6/
Unfurtunatly this does not work yet because of an unhandled case that does not allow to set multiple classes at the same time. Will mention that on the React issue so that it is supported in the future.
In the meantine, you can simply copy the ReactCSSTransitionGroup and solve the bug yourself :)