Skip to content

Instantly share code, notes, and snippets.

@andrit
Last active December 18, 2018 04:07
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 andrit/d20ce56ec23b270d007a0c44acadc29c to your computer and use it in GitHub Desktop.
Save andrit/d20ce56ec23b270d007a0c44acadc29c to your computer and use it in GitHub Desktop.
import React from 'react';
import Transition from 'react-transition-group/Transition';

//build config file to then expose interface controls on cms and grant ability to edit all animations from one dashboard
const duration = 400;
const duration2 = 800;

const defaultStyle = {
  transition: `opacity ${duration2}ms ease-in-out, right ${duration}ms ease-in-out`,
  opacity: 0,
  top: 0,
  right: 1000,
  position: 'relative'
}

const transitionStyles = {
  entering: { opacity: 0, right: 1000 },
  entered:  { opacity: 1, right: 0 },
};

export const TransitionAnimation = (Module) => {

    return class AnimateHOC extends React.Component {
        state = {in:false}

        componentDidMount() {
            this.setState({ in: true })
        }
        // componentWillUnmount(){
        //     clearTimeout();
        // }
        
        render(){
            return(
                <Transition 
                    in={this.state.in} 
                    timeout={{
                        enter: duration,
                        exit: duration,
                       }}
                    unmountOnExit >
                    {(state) => (
                    <div style={{
                        ...defaultStyle,
                        ...transitionStyles[state]
                    }}>
                        <Module {...this.props} />
                    </div>
                    )}
                </Transition>
            )
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment