Skip to content

Instantly share code, notes, and snippets.

@hpierre74
Last active August 7, 2018 18:48
Show Gist options
  • Save hpierre74/f53cbc7569cd9a8253f982f2059b1ffa to your computer and use it in GitHub Desktop.
Save hpierre74/f53cbc7569cd9a8253f982f2059b1ffa to your computer and use it in GitHub Desktop.
import React from 'react';
import PropTypes from 'prop-types';
import styled, { keyframes } from 'styled-components';
import { requireAnimation } from 'YOUR_PATH';
const AnimationWrapper = styled.div`
animation: ${({ duration }) => duration}s ${({ animation }) => animation};
`;
const withAnim = Component => {
const withAnimHOC = props => (
<AnimationWrapper
duration={props.duration}
animation={keyframes`${requireAnimation(props.animation)}`}>
<Component {...props} />
</AnimationWrapper>
);
withAnimHOC.defaultProps = {
duration: '1.5',
};
withAnimHOC.propTypes = {
animation: PropTypes.string.isRequired,
duration: PropTypes.string,
};
return withAnimHOC;
};
export default withAnim;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment