CSSTransition component for adding classes to an element while it is transitioning
$ npm install vdux-css-transition
Use this component to apply classes to your nodes when they are being added/removed from the DOM. It works like this:
function render () {
return (
<CSSTransition timeout={500}>
<Tooltip />
</CSSTransition>
)
}
Each child of <CSSTransition/>
will have the following classes added to it:
enter
- Immediately on creationenter-active
- On the next tick after theenter
class is addedleave
- When the component begins leavingleave-active
- On th enext tick after theleave
class is added
timeout
- (Object|Number). If you specify a number, it'll be used as both theenter
andleave
timeout lengths in milliseconds. You may alternatively passn an object withenter
andleave
keys to specify them independently.
Fade example (using jss-simple for css)
import css from 'jss-simple'
function render () {
return (
<CSSTransition timeout={150}>
<div class={fade}>I am fading in</div>
</CSSTransition>
)
}
const {fade} = css({
fade: {
'&.enter': {
opacity: 0,
'&.enter-active': {
transition: 'opacity .15s linear',
opacity: 1
},
},
'&.leave': {
opacity: 1,
'&.leave-active': {
opacity: 0,
transition: 'opacity .15s linear'
}
}
}
})
MIT