ISSUE-057 - Refactor: Separated out the Wipe functionality from VenetianBlindsTransition so I can re-use it elsewhere as WipeTransition.
This commit is contained in:
1 parent
49dd08cc13
commit
759e788af4
4 files changed
+89
-42
No files matched your search
+15
-42
@@ -1,10 +1,9 @@
|
|||||||
import { useSpring, animated, easings } from "@react-spring/web";
|
import { useSpring } from "@react-spring/web";
|
||||||
import useMeasure from "react-use-measure";
|
|
||||||
|
|
||||||
import { AnimatedVenetianBlindsFilter, VenetianBlindsFilter } from "./styles";
|
import { AnimatedVenetianBlindsFilter, VenetianBlindsFilter } from "./styles";
|
||||||
import { wipeCustomDegClip } from "../../../../utils/styling";
|
|
||||||
import { Corner, Degrees, Fraction, Px } from "../../../../types/style";
|
import { Corner, Degrees, Fraction, Px } from "../../../../types/style";
|
||||||
import { Milliseconds } from "../../../../types/util";
|
import { Milliseconds } from "../../../../types/util";
|
||||||
|
import { WipeTransition } from "../WipeTransition";
|
||||||
|
|
||||||
type VenetianBlindsTransitionProps = {
|
type VenetianBlindsTransitionProps = {
|
||||||
visible: boolean,
|
visible: boolean,
|
||||||
@@ -24,7 +23,7 @@ type VenetianBlindsTransitionProps = {
|
|||||||
opacityDelay?: Milliseconds,
|
opacityDelay?: Milliseconds,
|
||||||
spanBlinkDuration?: Milliseconds,
|
spanBlinkDuration?: Milliseconds,
|
||||||
};
|
};
|
||||||
export const VenetianBlindsTransition = (
|
export function VenetianBlindsTransition(
|
||||||
{
|
{
|
||||||
visible,
|
visible,
|
||||||
delay = 0,
|
delay = 0,
|
||||||
@@ -44,27 +43,7 @@ export const VenetianBlindsTransition = (
|
|||||||
spanBlinkDuration,
|
spanBlinkDuration,
|
||||||
children,
|
children,
|
||||||
}: React.PropsWithChildren<VenetianBlindsTransitionProps>,
|
}: React.PropsWithChildren<VenetianBlindsTransitionProps>,
|
||||||
) => {
|
) {
|
||||||
const [childRef, {
|
|
||||||
height: childHeight,
|
|
||||||
width: childWidth,
|
|
||||||
}] = useMeasure();
|
|
||||||
|
|
||||||
const { wipe } = useSpring({
|
|
||||||
wipe: visible ? 1 : 0,
|
|
||||||
config: {
|
|
||||||
duration: wipeDuration,
|
|
||||||
easing: easings.easeInOutQuint,
|
|
||||||
},
|
|
||||||
delay: 0 + delay,
|
|
||||||
});
|
|
||||||
|
|
||||||
const { opacity } = useSpring({
|
|
||||||
opacity: visible ? 1 : opacityStart,
|
|
||||||
config: { duration: opacityDuration },
|
|
||||||
delay: opacityDelay + delay,
|
|
||||||
});
|
|
||||||
|
|
||||||
const blindsSpring = useSpring({
|
const blindsSpring = useSpring({
|
||||||
opacity: visible ? 1 : 0,
|
opacity: visible ? 1 : 0,
|
||||||
config: { duration: blindsOpenDuration },
|
config: { duration: blindsOpenDuration },
|
||||||
@@ -72,21 +51,15 @@ export const VenetianBlindsTransition = (
|
|||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<animated.div
|
<WipeTransition
|
||||||
style={{
|
visible={visible}
|
||||||
opacity,
|
delay={delay}
|
||||||
clipPath: wipe.to(wipeProgress => {
|
angle={wipeAngle}
|
||||||
const coordinates = wipeCustomDegClip(
|
duration={wipeDuration}
|
||||||
childWidth,
|
startingCorner={wipeStartingCorner}
|
||||||
childHeight,
|
opacityStart={opacityStart}
|
||||||
wipeProgress,
|
opacityDuration={opacityDuration}
|
||||||
wipeStartingCorner,
|
opacityDelay={opacityDelay}
|
||||||
wipeAngle,
|
|
||||||
);
|
|
||||||
return `polygon(${coordinates.map(([x, y]) => `${x}px ${y}px`).join(", ")})`;
|
|
||||||
}),
|
|
||||||
}}
|
|
||||||
ref={childRef}
|
|
||||||
>
|
>
|
||||||
<AnimatedVenetianBlindsFilter
|
<AnimatedVenetianBlindsFilter
|
||||||
style={blindsSpring}
|
style={blindsSpring}
|
||||||
@@ -117,6 +90,6 @@ export const VenetianBlindsTransition = (
|
|||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</VenetianBlindsFilter>
|
</VenetianBlindsFilter>
|
||||||
</animated.div>
|
</WipeTransition>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
@@ -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``;
|
||||||
Reference in new issue
Block a user