Skip to content

Commit

Permalink
make animation as shared component
Browse files Browse the repository at this point in the history
Signed-off-by: huongg <[email protected]>
  • Loading branch information
Huongg committed Jul 7, 2022
1 parent 565e9a8 commit 8d4661d
Showing 1 changed file with 19 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,43 @@ import { Transition } from 'react-transition-group';
const directions = {
leftToRight: {
entering: {
opacity: 0.5,
transform: 'translateX(50%)',
visibility: 'visible',
},
entered: {
opacity: 1,
transform: 'translateX(50%)',
visibility: 'visible',
},
exiting: {
transform: 'translateX(-50%)',
opacity: 0.5,
visibility: 'hidden',
},
exited: {
transform: 'translateX(-50%)',
opacity: 0,
visibility: 'hidden',
},
},
rightToLeft: {
entering: {
opacity: 0.5,
transform: 'translateX(-50%)',
visibility: 'visible',
},
entered: {
opacity: 1,
transform: 'translateX(-50%)',
visibility: 'visible',
},
exiting: {
transform: 'translateX(50%)',
opacity: 0.5,
visibility: 'hidden',
},
exited: {
transform: 'translateX(50%)',
opacity: 0,
visibility: 'hidden',
},
},
};

export const SlideFromLeftToRight = ({ state, duration, children }) => {
export const Animation = ({ children, direction, duration, state }) => {
const defaultStyle = {
transition: `transform ${duration}ms ease-in-out`,
};
Expand All @@ -59,7 +51,7 @@ export const SlideFromLeftToRight = ({ state, duration, children }) => {
<div
style={{
...defaultStyle,
...directions['leftToRight'][state],
...directions[direction][state],
}}
>
{children}
Expand All @@ -69,23 +61,24 @@ export const SlideFromLeftToRight = ({ state, duration, children }) => {
);
};

export const SlideFromRightToLeft = ({ state, duration, children }) => {
const defaultStyle = {
transition: `transform ${duration}ms ease-in-out`,
};
export const SlideFromLeftToRight = ({ state, duration, children }) => {
return (
<Animation
children={children}
direction="leftToRight"
duration={duration}
state={state}
/>
);
};

export const SlideFromRightToLeft = ({ state, duration, children }) => {
return (
<Transition in={state} timeout={duration}>
{(state) => (
<div
style={{
...defaultStyle,
...directions['rightToLeft'][state],
}}
>
{children}
</div>
)}
</Transition>
<Animation
children={children}
direction="rightToLeft"
duration={duration}
state={state}
/>
);
};

0 comments on commit 8d4661d

Please sign in to comment.