Skip to content

Instantly share code, notes, and snippets.

@gruppjo
Last active May 2, 2020 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gruppjo/3e1c33537c1f3613f04fea87dac16a36 to your computer and use it in GitHub Desktop.
Save gruppjo/3e1c33537c1f3613f04fea87dac16a36 to your computer and use it in GitHub Desktop.
ProjectCSSTransition using global hardwired _animations.scss defaults
/* 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