2020-07-04 16:46:26 +00:00
|
|
|
import React from 'react';
|
|
|
|
import tw from 'twin.macro';
|
|
|
|
import styled from 'styled-components/macro';
|
|
|
|
import CSSTransition, { CSSTransitionProps } from 'react-transition-group/CSSTransition';
|
|
|
|
|
|
|
|
interface Props extends Omit<CSSTransitionProps, 'timeout' | 'classNames'> {
|
|
|
|
timeout: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Container = styled.div<{ timeout: number }>`
|
2022-06-26 19:13:52 +00:00
|
|
|
.fade-enter,
|
|
|
|
.fade-exit,
|
|
|
|
.fade-appear {
|
2020-07-04 16:46:26 +00:00
|
|
|
will-change: opacity;
|
|
|
|
}
|
2022-06-26 19:13:52 +00:00
|
|
|
|
|
|
|
.fade-enter,
|
|
|
|
.fade-appear {
|
2020-07-04 16:46:26 +00:00
|
|
|
${tw`opacity-0`};
|
2022-06-26 19:13:52 +00:00
|
|
|
|
|
|
|
&.fade-enter-active,
|
|
|
|
&.fade-appear-active {
|
2020-07-04 16:46:26 +00:00
|
|
|
${tw`opacity-100 transition-opacity ease-in`};
|
2022-06-26 19:13:52 +00:00
|
|
|
transition-duration: ${(props) => props.timeout}ms;
|
2020-07-04 16:46:26 +00:00
|
|
|
}
|
|
|
|
}
|
2022-06-26 19:13:52 +00:00
|
|
|
|
2020-07-04 16:46:26 +00:00
|
|
|
.fade-exit {
|
|
|
|
${tw`opacity-100`};
|
2022-06-26 19:13:52 +00:00
|
|
|
|
2020-07-04 16:46:26 +00:00
|
|
|
&.fade-exit-active {
|
|
|
|
${tw`opacity-0 transition-opacity ease-in`};
|
2022-06-26 19:13:52 +00:00
|
|
|
transition-duration: ${(props) => props.timeout}ms;
|
2020-07-04 16:46:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const Fade: React.FC<Props> = ({ timeout, children, ...props }) => (
|
|
|
|
<Container timeout={timeout}>
|
|
|
|
<CSSTransition timeout={timeout} classNames={'fade'} {...props}>
|
|
|
|
{children}
|
|
|
|
</CSSTransition>
|
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
Fade.displayName = 'Fade';
|
|
|
|
|
|
|
|
export default Fade;
|