Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/resources/scripts/components/elements/Fade.tsx
7461 views
1
import React from 'react';
2
import tw from 'twin.macro';
3
import styled from 'styled-components/macro';
4
import CSSTransition, { CSSTransitionProps } from 'react-transition-group/CSSTransition';
5
6
interface Props extends Omit<CSSTransitionProps, 'timeout' | 'classNames'> {
7
timeout: number;
8
}
9
10
const Container = styled.div<{ timeout: number }>`
11
.fade-enter,
12
.fade-exit,
13
.fade-appear {
14
will-change: opacity;
15
}
16
17
.fade-enter,
18
.fade-appear {
19
${tw`opacity-0`};
20
21
&.fade-enter-active,
22
&.fade-appear-active {
23
${tw`opacity-100 transition-opacity ease-in`};
24
transition-duration: ${(props) => props.timeout}ms;
25
}
26
}
27
28
.fade-exit {
29
${tw`opacity-100`};
30
31
&.fade-exit-active {
32
${tw`opacity-0 transition-opacity ease-in`};
33
transition-duration: ${(props) => props.timeout}ms;
34
}
35
}
36
`;
37
38
const Fade: React.FC<Props> = ({ timeout, children, ...props }) => (
39
<Container timeout={timeout}>
40
<CSSTransition timeout={timeout} classNames={'fade'} {...props}>
41
{children}
42
</CSSTransition>
43
</Container>
44
);
45
Fade.displayName = 'Fade';
46
47
export default Fade;
48
49