Path: blob/1.0-develop/resources/scripts/components/elements/Fade.tsx
7461 views
import React from 'react';1import tw from 'twin.macro';2import styled from 'styled-components/macro';3import CSSTransition, { CSSTransitionProps } from 'react-transition-group/CSSTransition';45interface Props extends Omit<CSSTransitionProps, 'timeout' | 'classNames'> {6timeout: number;7}89const Container = styled.div<{ timeout: number }>`10.fade-enter,11.fade-exit,12.fade-appear {13will-change: opacity;14}1516.fade-enter,17.fade-appear {18${tw`opacity-0`};1920&.fade-enter-active,21&.fade-appear-active {22${tw`opacity-100 transition-opacity ease-in`};23transition-duration: ${(props) => props.timeout}ms;24}25}2627.fade-exit {28${tw`opacity-100`};2930&.fade-exit-active {31${tw`opacity-0 transition-opacity ease-in`};32transition-duration: ${(props) => props.timeout}ms;33}34}35`;3637const Fade: React.FC<Props> = ({ timeout, children, ...props }) => (38<Container timeout={timeout}>39<CSSTransition timeout={timeout} classNames={'fade'} {...props}>40{children}41</CSSTransition>42</Container>43);44Fade.displayName = 'Fade';4546export default Fade;474849