Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
66 lines (63 sloc)
1.93 KB
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
import React , { Component } from 'react' | |
import delay from 'delay' | |
import { Spring , Trail , Keyframes , animated , config } from 'react-spring' | |
class TransitionGrid extends Component { | |
async componentDidUpdate ( prevProps , prevState ) { | |
if ( ! prevProps . visible && this . props . visible ) { | |
this . container ( Spring , { | |
from : { x : - 100 , opacity : } , | |
to : { x : , opacity : 1 } , | |
config : config . slow | |
} ) | |
await delay ( 500 ) | |
await this . content ( Trail , { | |
from : { y : - 120 , opacity : } , | |
to : { y : , opacity : 1 } | |
} ) | |
} else if ( prevProps . visible && ! this . props . visible ) { | |
this . content ( Trail , { to : { y : - 120 , opacity : } } ) | |
await delay ( 500 ) | |
await this . container ( Spring , { | |
to : { x : - 100 , opacity : } , | |
config : config . slow | |
} ) | |
} | |
} | |
render ( ) { | |
const { items , removeItem } = this . props | |
return ( | |
< Keyframes native script = { next => ( this . container = next ) } > | |
{ ( { x , opacity } ) => ( | |
< animated . ul | |
className = "grid animated-grid" | |
style = { { | |
transform : x . interpolate ( x => `translate3d( ${ x } %,0,0)` ) , | |
opacity | |
} } | |
> | |
< Keyframes | |
native | |
keys = { items } | |
script = { next => ( this . content = next ) } | |
> | |
{ items . map ( item => ( { y , ... props } ) => ( | |
< animated . li | |
onClick = { ( ) => removeItem ( item ) } | |
className = "card" | |
style = { { | |
transform : y . interpolate ( y => `translate3d(0, ${ y } %,0)` ) , | |
... props | |
} } | |
> | |
< div className = "close-card" > ✕ < / div > | |
< div > { item } < / div > | |
< / animated . li > | |
) ) } | |
< / Keyframes > | |
< / animated . ul > | |
) } | |
< / Keyframes > | |
) | |
} | |
} | |
export default props => < TransitionGrid { ... props } / > |