ReactTransitionGroup + ReactGSAPEnhancer for transitions in anything GSAP supports.
npm install react-addons-gsap-transition-groupReact Addons: GSAP Transition Group
===================================
Use GSAP animations for transitions which work in any browser both GSAP and React support. Uses React GSAP Enhancer to add GSAP support to React Components, and extends ReactTransitionGroup to create an element which adds GSAP powered transitions which even work in IE8.
Usage
-----
```
tweenEnter={ tweenEnterFactory :function }
tweenLeave={ tweenLeaveFactory :function }
transitionAppear={ shouldAppear :boolean }
transitionEnter={ shouldEnter :boolean }
transitionLeave={ shouldLeave :boolean }
>
Functions more or less like ReactCSSTransitionGroup, although rather than transitionName, the three properties are used to specify the transitions.
- The Tween Props
- These should be set to functions which take an arguments object that has the properties target and options and return a TweenLite, TweenMax, TimelineLite, or TimelineMax instance. See the _Example_ section for a simple case of a use of TweenMax.fromTo.utils.target.find
- Note: If you need to target a specific element within, use and other such element finding/filtering functions. See React GSAP Enhancer's documents for more details on this.tweenAppear: function({ target, options }): (TweenLite|TweenMax|TimelineLite|TimelineMax)
- _optional_tweenEnter: function({ target, options }): (TweenLite|TweenMax|TimelineLite|TimelineMax)
- tweenLeave: function({ target, options }): (TweenLite|TweenMax|TimelineLite|TimelineMax)
- tweenAppear: boolean = false
- The Transition Props
- These specify whether a transition should be played at a given life cycle point, in much the same way the same props work in ReactCSSTransitionGroup.
- determines whether or not tweenAppear is called.tweenEnter: boolean = true
- determines whether or not tweenEnter is called.tweenLeave: boolean = true
- determines whether or not tweenLeave is called.
Example
-------
> Note: This example is written in ES6, sorta.
`js
let React = require( 'react' );
let ReactGSAPTransitionGroup = require( 'react-addons-gsap-transition-group' );
let TweenMax = require( 'gsap' );
//////// Transition factories
// See react-gsap-enhancer (https://github.com/azazdeaz/react-gsap-enhancer) for how these functions should be structured.
function transitionEnter({ target, options }) {
return TweenMax.fromTo( target, 0.3, {
x: '+=50',
opacity: 0
}, {
x: '-=50',
opacity: 1
});
}
function transitionLeave({ target, options }) {
return TweenMax.fromTo( target, 0.3, {
x: '+=0',
opacity: 1
}, {
x: '-=50',
opacity: 0
});
}
//////// A grouping component
const TransitioningList = React.createClass({
render() {
return (
// Note: Don't need tweenAppear unless you set transitionAppear="true".
tweenLeave={ transitionLeave }
>
{ this.renderItems() }
);
},
renderItems() {
return this.props.items.map( item => (
handleRemoveItem( itemId ) {
this.props.onRemoveItem( itemId );
}
});
`
`js
function transitionEnter( utils ) {
return TweenMax.fromTo( utils.target, 0.3, {
x: '+=50',
opacity: 0
}, {
x: '-=50',
opacity: 1
});
}
function transitionLeave( utils ) {
return TweenMax.fromTo( utils.target, 0.3, {
x: '+=0',
opacity: 1
}, {
x: '-=50',
opacity: 0
});
}
`
Considerations when targeting legacy browsers
---------------------------------------------
- You should add core-js to ensure things such as Map, Array#map`, and other sundry ES5 things.
- If targeting ES3 environments (mostly IE8), you should at least add a transform to make property name access ES3 safe, such as es3ify if using Browserify.