Last active
May 2, 2020 14:58
-
-
Save gruppjo/3e1c33537c1f3613f04fea87dac16a36 to your computer and use it in GitHub Desktop.
ProjectCSSTransition using global hardwired _animations.scss defaults
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
/* V1.0 based on Jonathan's Gist */ | |
/* https://gist.github.com/gruppjo/3e1c33537c1f3613f04fea87dac16a36 */ | |
import React from 'react'; | |
import styles from 'styles-imports/shared.scss'; | |
import { CSSTransition } from 'react-transition-group'; | |
/** | |
* ProjectCSSTransition | |
* extends the functionality of react-transition-group's CSSTransition | |
* - it wires the global animationDurationMs from _animations.scss to the transition | |
* - it applies mountOnEnter, unMountOnExit per default | |
* - allows timeout to be numbers in ms (e.g. 100) or numbers as strings (e.g. '100') | |
* @param {*} props | |
*/ | |
const ProjectCSSTransition = (props) => { | |
const { classNames, timeout } = props; | |
return ( | |
<CSSTransition | |
in={props.in} | |
classNames={classNames} | |
timeout={isNaN(timeout) ? Number(styles.animationDurationMs) : Number(timeout)} | |
mountOnEnter | |
unmountOnExit> | |
{props.children} | |
</CSSTransition> | |
); | |
}; | |
export default ProjectCSSTransition; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment