ISSUE-045 - Venetian Blinds - After some trial and error I've got a performant and sensible wipe solution using a clip-path mask.
Figuring this out of great because these kinds of clip paths are used in other places as well so this is good practice to start with.
This commit is contained in:
1 parent
38aeedea65
commit
c07d364584
3 files changed
+105
-11
No files matched your search
+51
-10
@@ -1,17 +1,58 @@
|
||||
import { useState } from "react";
|
||||
import { useSpring, animated } from "@react-spring/web";
|
||||
import useMeasure from "react-use-measure";
|
||||
|
||||
import { VenetianBlindsFilter } from "./styles";
|
||||
import { wipe45DegClip } from "../../../../utils/styling";
|
||||
|
||||
type VenetianBlindsTransitionProps = {
|
||||
color: string,
|
||||
};
|
||||
export const VenetianBlindsTransition = (
|
||||
{ color, children }: React.PropsWithChildren<VenetianBlindsTransitionProps>,
|
||||
) => (
|
||||
<VenetianBlindsFilter
|
||||
deg={-45}
|
||||
transparentWidth={3}
|
||||
opaqueWidth={5}
|
||||
opaqueColor={color}
|
||||
>
|
||||
{children}
|
||||
</VenetianBlindsFilter>
|
||||
);
|
||||
) => {
|
||||
const [childRef, {
|
||||
height: childHeight,
|
||||
width: childWidth,
|
||||
}] = useMeasure();
|
||||
const deg = -45;
|
||||
|
||||
const [state, toggle] = useState(true);
|
||||
|
||||
const { x } = useSpring({
|
||||
from: { x: 0 },
|
||||
x: state ? 1 : 0,
|
||||
config: { duration: 300 },
|
||||
});
|
||||
|
||||
return (
|
||||
<div onClick={() => {
|
||||
console.log(!state);
|
||||
toggle(!state);
|
||||
}}>
|
||||
<animated.div
|
||||
style={{
|
||||
clipPath: x.to(x => {
|
||||
const [a1, a2, b1, b2, c1, c2] = wipe45DegClip(
|
||||
childWidth,
|
||||
childHeight,
|
||||
x,
|
||||
"bottomRight",
|
||||
);
|
||||
return `polygon(${a1}px ${a2}px, ${b1}px ${b2}px, ${c1}px ${c2}px)`;
|
||||
}),
|
||||
}}
|
||||
>
|
||||
<VenetianBlindsFilter
|
||||
deg={deg}
|
||||
transparentWidth={3}
|
||||
opaqueWidth={5}
|
||||
opaqueColor={color}
|
||||
ref={childRef}
|
||||
>
|
||||
{children}
|
||||
</VenetianBlindsFilter>
|
||||
</animated.div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user