Skip to content

Commit

Permalink
feat(anims): added reversed Fade animation
Browse files Browse the repository at this point in the history
  • Loading branch information
morellodev committed Jul 29, 2020
1 parent ee077b2 commit 33af712
Show file tree
Hide file tree
Showing 17 changed files with 306 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/animations/fading_entrances/fadeInTopLeft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const fadeInTopLeft = keyframes`
opacity: 0;
transform: translate3d(-100%, -100%, 0);
}
to {
opacity: 1;
transform: translate3d(0, 0, 0);
Expand Down
1 change: 1 addition & 0 deletions src/animations/fading_entrances/fadeInTopRight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const fadeInTopRight = keyframes`
opacity: 0;
transform: translate3d(100%, -100%, 0);
}
to {
opacity: 1;
transform: translate3d(0, 0, 0);
Expand Down
16 changes: 16 additions & 0 deletions src/animations/fading_exits/fadeOut.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { keyframes } from "@emotion/core";

/**
* @see {@link https://github.com/animate-css/animate.css/blob/master/source/fading_exits/fadeOut.css}
*/
const fadeOut = keyframes`
from {
opacity: 1;
}
to {
opacity: 0;
}
`;

export default fadeOut;
18 changes: 18 additions & 0 deletions src/animations/fading_exits/fadeOutBottomLeft.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { keyframes } from "@emotion/core";

/**
* @see {@link https://github.com/animate-css/animate.css/blob/master/source/fading_exits/fadeOutBottomLeft.css}
*/
const fadeOutBottomLeft = keyframes`
from {
opacity: 1;
transform: translate3d(0, 0, 0);
}
to {
opacity: 0;
transform: translate3d(-100%, 100%, 0);
}
`;

export default fadeOutBottomLeft;
18 changes: 18 additions & 0 deletions src/animations/fading_exits/fadeOutBottomRight.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { keyframes } from "@emotion/core";

/**
* @see {@link https://github.com/animate-css/animate.css/blob/master/source/fading_exits/fadeOutBottomRight.css}
*/
const fadeOutBottomRight = keyframes`
from {
opacity: 1;
transform: translate3d(0, 0, 0);
}
to {
opacity: 0;
transform: translate3d(100%, 100%, 0);
}
`;

export default fadeOutBottomRight;
17 changes: 17 additions & 0 deletions src/animations/fading_exits/fadeOutDown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { keyframes } from "@emotion/core";

/**
* @see {@link https://github.com/animate-css/animate.css/blob/master/source/fading_exits/fadeOutDown.css}
*/
const fadeOutDown = keyframes`
from {
opacity: 1;
}
to {
opacity: 0;
transform: translate3d(0, 100%, 0);
}
`;

export default fadeOutDown;
17 changes: 17 additions & 0 deletions src/animations/fading_exits/fadeOutDownBig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { keyframes } from "@emotion/core";

/**
* @see {@link https://github.com/animate-css/animate.css/blob/master/source/fading_exits/fadeOutDownBig.css}
*/
const fadeOutDownBig = keyframes`
from {
opacity: 1;
}
to {
opacity: 0;
transform: translate3d(0, 2000px, 0);
}
`;

export default fadeOutDownBig;
17 changes: 17 additions & 0 deletions src/animations/fading_exits/fadeOutLeft.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { keyframes } from "@emotion/core";

/**
* @see {@link https://github.com/animate-css/animate.css/blob/master/source/fading_exits/fadeOutLeft.css}
*/
const fadeOutLeft = keyframes`
from {
opacity: 1;
}
to {
opacity: 0;
transform: translate3d(-100%, 0, 0);
}
`;

export default fadeOutLeft;
17 changes: 17 additions & 0 deletions src/animations/fading_exits/fadeOutLeftBig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { keyframes } from "@emotion/core";

/**
* @see {@link https://github.com/animate-css/animate.css/blob/master/source/fading_exits/fadeOutLeftBig.css}
*/
const fadeOutLeftBig = keyframes`
from {
opacity: 1;
}
to {
opacity: 0;
transform: translate3d(-2000px, 0, 0);
}
`;

export default fadeOutLeftBig;
17 changes: 17 additions & 0 deletions src/animations/fading_exits/fadeOutRight.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { keyframes } from "@emotion/core";

/**
* @see {@link https://github.com/animate-css/animate.css/blob/master/source/fading_exits/fadeOutRight.css}
*/
const fadeOutRight = keyframes`
from {
opacity: 1;
}
to {
opacity: 0;
transform: translate3d(100%, 0, 0);
}
`;

export default fadeOutRight;
17 changes: 17 additions & 0 deletions src/animations/fading_exits/fadeOutRightBig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { keyframes } from "@emotion/core";

/**
* @see {@link https://github.com/animate-css/animate.css/blob/master/source/fading_exits/fadeOutRightBig.css}
*/
const fadeOutRightBig = keyframes`
from {
opacity: 1;
}
to {
opacity: 0;
transform: translate3d(2000px, 0, 0);
}
`;

export default fadeOutRightBig;
18 changes: 18 additions & 0 deletions src/animations/fading_exits/fadeOutTopLeft.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { keyframes } from "@emotion/core";

/**
* @see {@link https://github.com/animate-css/animate.css/blob/master/source/fading_exits/fadeOutTopLeft.css}
*/
const fadeOutTopLeft = keyframes`
from {
opacity: 1;
transform: translate3d(0, 0, 0);
}
to {
opacity: 0;
transform: translate3d(-100%, -100%, 0);
}
`;

export default fadeOutTopLeft;
18 changes: 18 additions & 0 deletions src/animations/fading_exits/fadeOutTopRight.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { keyframes } from "@emotion/core";

/**
* @see {@link https://github.com/animate-css/animate.css/blob/master/source/fading_exits/fadeOutTopRight.css}
*/
const fadeOutTopRight = keyframes`
from {
opacity: 1;
transform: translate3d(0, 0, 0);
}
to {
opacity: 0;
transform: translate3d(100%, -100%, 0);
}
`;

export default fadeOutTopRight;
17 changes: 17 additions & 0 deletions src/animations/fading_exits/fadeOutUp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { keyframes } from "@emotion/core";

/**
* @see {@link https://github.com/animate-css/animate.css/blob/master/source/fading_exits/fadeOutUp.css}
*/
const fadeOutUp = keyframes`
from {
opacity: 1;
}
to {
opacity: 0;
transform: translate3d(0, -100%, 0);
}
`;

export default fadeOutUp;
17 changes: 17 additions & 0 deletions src/animations/fading_exits/fadeOutUpBig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { keyframes } from "@emotion/core";

/**
* @see {@link https://github.com/animate-css/animate.css/blob/master/source/fading_exits/fadeOutUpBig.css}
*/
const fadeOutUpBig = keyframes`
from {
opacity: 1;
}
to {
opacity: 0;
transform: translate3d(0, -2000px, 0);
}
`;

export default fadeOutUpBig;
13 changes: 13 additions & 0 deletions src/animations/fading_exits/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export { default as fadeOut } from "./fadeOut";
export { default as fadeOutBottomLeft } from "./fadeOutBottomLeft";
export { default as fadeOutBottomRight } from "./fadeOutBottomRight";
export { default as fadeOutDown } from "./fadeOutDown";
export { default as fadeOutDownBig } from "./fadeOutDownBig";
export { default as fadeOutLeft } from "./fadeOutLeft";
export { default as fadeOutLeftBig } from "./fadeOutLeftBig";
export { default as fadeOutRight } from "./fadeOutRight";
export { default as fadeOutRightBig } from "./fadeOutRightBig";
export { default as fadeOutTopLeft } from "./fadeOutTopLeft";
export { default as fadeOutTopRight } from "./fadeOutTopRight";
export { default as fadeOutUp } from "./fadeOutUp";
export { default as fadeOutUpBig } from "./fadeOutUpBig";
79 changes: 67 additions & 12 deletions src/components/Fade.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ import {
fadeInUp,
fadeInUpBig
} from "../animations/fading_entrances";
import {
fadeOut,
fadeOutBottomLeft,
fadeOutBottomRight,
fadeOutDown,
fadeOutDownBig,
fadeOutLeft,
fadeOutLeftBig,
fadeOutRight,
fadeOutRightBig,
fadeOutTopLeft,
fadeOutTopRight,
fadeOutUp,
fadeOutUpBig
} from "../animations/fading_exits";

type FadeDirection =
| "bottom-left"
Expand All @@ -39,33 +54,73 @@ interface FadeProps extends Omit<RevealProps, "animation"> {
* @default undefined
*/
direction?: FadeDirection;
/**
* Specifies if the animation should make element(s) disappear.
* @default false
*/
reverse?: boolean;
}

function getFadeKeyframes(big: boolean, direction?: FadeDirection) {
function getFadeKeyframes(
big: boolean,
reverse: boolean,
direction?: FadeDirection
) {
switch (direction) {
case "bottom-left":
return fadeInBottomLeft;
return reverse ? fadeOutBottomLeft : fadeInBottomLeft;
case "bottom-right":
return fadeInBottomRight;
return reverse ? fadeOutBottomRight : fadeInBottomRight;
case "down":
return big ? fadeInDownBig : fadeInDown;
return big
? reverse
? fadeOutDownBig
: fadeInDownBig
: reverse
? fadeOutDown
: fadeInDown;
case "left":
return big ? fadeInLeftBig : fadeInLeft;
return big
? reverse
? fadeOutLeftBig
: fadeInLeftBig
: reverse
? fadeOutLeft
: fadeInLeft;
case "right":
return big ? fadeInRightBig : fadeInRight;
return big
? reverse
? fadeOutRightBig
: fadeInRightBig
: reverse
? fadeOutRight
: fadeInRight;
case "top-left":
return fadeInTopLeft;
return reverse ? fadeOutTopLeft : fadeInTopLeft;
case "top-right":
return fadeInTopRight;
return reverse ? fadeOutTopRight : fadeInTopRight;
case "up":
return big ? fadeInUpBig : fadeInUp;
return big
? reverse
? fadeOutUpBig
: fadeInUpBig
: reverse
? fadeOutUp
: fadeInUp;
default:
return fadeIn;
return reverse ? fadeOut : fadeIn;
}
}

const Fade: React.FC<FadeProps> = ({ big = false, direction, ...rest }) => {
return <Reveal animation={getFadeKeyframes(big, direction)} {...rest} />;
const Fade: React.FC<FadeProps> = ({
big = false,
direction,
reverse = false,
...rest
}) => {
return (
<Reveal animation={getFadeKeyframes(big, reverse, direction)} {...rest} />
);
};

export default Fade;

0 comments on commit 33af712

Please sign in to comment.