Skip to content

Latest commit

 

History

History
45 lines (35 loc) · 864 Bytes

styled-components.md

File metadata and controls

45 lines (35 loc) · 864 Bytes

Styled Components

Styled Components with CSSTransition

import React from 'react';
import styled from 'styled-components';
import { CSSTransition } from 'react-transition-group';

const CSSTransitionFactory = (Transition, transitionName) => {
  return ({ children, ...props }) => {
    return (
      <Transition
        classNames={transitionName}
        {...props}
        timeout={props.timeout || 0}
      >
        {children}
      </Transition>
    )
  }
};

const FadeCSSTransition = styled(CSSTransition)`
  transition: opacity ${({ duration }) => duration || 1000}ms;

  &.fade-enter {
    opacity: 0.01;
  }

  &.fade-enter-active {
    opacity: 1;
  }
`;

export const Fade = CSSTransitionFactory(FadeCSSTransition, 'fade');
<Fade key={tweet.messageId} duration={1000} timeout={0}>
  <Component />
</Fade>