Skip to content

Commit 149803e

Browse files
author
Chris Johnson
committed
fix(transform components): Refactor FadeTransform and allow entering and exiting for finer control
FadeTransform needs different configurations than FadeInOut for each status. Spitting into its own code for now, needs possible refactor
1 parent ce2c8f9 commit 149803e

File tree

2 files changed

+54
-19
lines changed

2 files changed

+54
-19
lines changed

src/animations/FadeTransform/index.jsx

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,57 @@
11
import React from 'react';
22
import { node, string } from 'prop-types';
3+
import { Transition } from 'react-transition-group';
34
import {
45
defaultAnimationProps,
56
getInlineStyles,
67
getTimeoutValue,
78
} from 'utilities';
89

9-
import FadeInOut from '../FadeInOut';
10-
import TweenTransform from '../TweenTransform';
10+
const statusStyles = {
11+
entered: {
12+
opacity: 1,
13+
},
14+
entering: {
15+
opacity: 1,
16+
},
17+
exited: {
18+
opacity: 0,
19+
},
20+
exiting: {
21+
opacity: 0,
22+
},
23+
};
24+
25+
const FadeTransform = ({
26+
children,
27+
enter,
28+
exit,
29+
exiting,
30+
entering,
31+
...props
32+
}) => {
33+
const pos = {
34+
entering: entering || enter,
35+
entered: enter,
36+
exiting: exiting || exit,
37+
exited: exit,
38+
};
1139

12-
const FadeTransform = ({ children, ...props }) => {
1340
return (
14-
<TweenTransform
15-
timeout={getTimeoutValue(props)}
16-
{...props}
17-
style={getInlineStyles(props)}
18-
>
19-
<FadeInOut
20-
timeout={getTimeoutValue(props)}
21-
{...props}
22-
style={getInlineStyles(props)}
23-
>
24-
{children}
25-
</FadeInOut>
26-
</TweenTransform>
41+
<Transition timeout={getTimeoutValue(props)} {...props}>
42+
{status => (
43+
<div
44+
style={{
45+
...getInlineStyles(props),
46+
...statusStyles[status],
47+
transform: pos[status],
48+
transitionProperty: 'transform, opacity',
49+
}}
50+
>
51+
{children}
52+
</div>
53+
)}
54+
</Transition>
2755
);
2856
};
2957

src/animations/TweenTransform/index.jsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,18 @@ import {
88
getTimeoutValue,
99
} from 'utilities';
1010

11-
const TweenTransform = ({ children, enter, exit, ...props }) => {
11+
const TweenTransform = ({
12+
children,
13+
enter,
14+
exit,
15+
entering,
16+
exiting,
17+
...props
18+
}) => {
1219
const pos = {
13-
entering: enter,
20+
entering: entering || enter,
1421
entered: enter,
15-
exiting: exit,
22+
exiting: exiting || exit,
1623
exited: exit,
1724
};
1825

0 commit comments

Comments
 (0)