ISSUE-057 - Refactor: Separated out the Wipe functionality from VenetianBlindsTransition so I can re-use it elsewhere as WipeTransition.

This commit is contained in:
Kyle Geib committed 2022-03-03 08:20:19 -05:00
1 parent 49dd08cc13
commit 759e788af4
4 files changed
+89 -42

No files matched your search

@@ -0,0 +1,70 @@
import { animated, easings, useSpring } from "@react-spring/web";
import useMeasure from "react-use-measure";
import { Corner, Degrees, Fraction } from "../../../../types/style";
import { Milliseconds } from "../../../../types/util";
import { wipeCustomDegClip } from "../../../../utils/styling";
type WipeTransitionProps = {
visible: boolean,
delay?: Milliseconds,
angle: Degrees,
duration: Milliseconds,
startingCorner: Corner,
opacityStart?: Fraction,
opacityDuration?: Milliseconds,
opacityDelay?: Milliseconds,
}
export function WipeTransition({
visible,
delay = 0,
angle,
duration,
startingCorner,
opacityStart = 1,
opacityDuration = duration,
opacityDelay = 0,
children,
}: React.PropsWithChildren<WipeTransitionProps>) {
const [childRef, {
height: childHeight,
width: childWidth,
}] = useMeasure();
const { wipe } = useSpring({
wipe: visible ? 1 : 0,
config: {
duration: duration,
easing: easings.easeInOutQuint,
},
delay: 0 + delay,
});
const { opacity } = useSpring({
opacity: visible ? 1 : opacityStart,
config: { duration: opacityDuration },
delay: opacityDelay + delay,
});
return (
<animated.div
style={{
opacity,
clipPath: wipe.to(wipeProgress => {
const coordinates = wipeCustomDegClip(
childWidth,
childHeight,
wipeProgress,
startingCorner,
angle,
);
return `polygon(${coordinates.map(([x, y]) => `${x}px ${y}px`).join(", ")})`;
}),
}}
ref={childRef}
>
{children}
</animated.div>
);
}
@@ -0,0 +1 @@
export * from "./WipeTransition";
@@ -0,0 +1,3 @@
import styled from "styled-components";
export const Foo = styled.div``;