ISSUE-045 - Venetian Blinds - Moved visibility state outside of the Transition component and into the workspace.
This commit is contained in:
1 parent
b1b3b62d3a
commit
9518f934ae
2 files changed
+55
-53
No files matched your search
+48
-51
@@ -1,4 +1,3 @@
|
||||
import { useState } from "react";
|
||||
import { useSpring, animated } from "@react-spring/web";
|
||||
import useMeasure from "react-use-measure";
|
||||
|
||||
@@ -8,6 +7,7 @@ import { Corner, Degrees, Fraction, Px } from "../../../../types/style";
|
||||
import { Milliseconds } from "../../../../types/util";
|
||||
|
||||
type VenetianBlindsTransitionProps = {
|
||||
visible: boolean,
|
||||
blindsColor: string,
|
||||
blindsColorFadeDuration: Milliseconds,
|
||||
blindsColorFadeDelay?: Milliseconds,
|
||||
@@ -25,6 +25,7 @@ type VenetianBlindsTransitionProps = {
|
||||
};
|
||||
export const VenetianBlindsTransition = (
|
||||
{
|
||||
visible,
|
||||
blindsColor,
|
||||
blindsColorFadeDuration,
|
||||
blindsColorFadeDelay = 0,
|
||||
@@ -47,71 +48,67 @@ export const VenetianBlindsTransition = (
|
||||
width: childWidth,
|
||||
}] = useMeasure();
|
||||
|
||||
const [state, toggle] = useState(true);
|
||||
|
||||
const { wipe } = useSpring({
|
||||
wipe: state ? 1 : 0,
|
||||
wipe: visible ? 1 : 0,
|
||||
config: { duration: wipeDuration },
|
||||
});
|
||||
|
||||
const { opacity } = useSpring({
|
||||
opacity: state ? 1 : opacityStart,
|
||||
opacity: visible ? 1 : opacityStart,
|
||||
config: { duration: opacityDuration },
|
||||
delay: opacityDelay,
|
||||
});
|
||||
|
||||
const blindsSpring = useSpring({
|
||||
opacity: state ? 1 : 0,
|
||||
opacity: visible ? 1 : 0,
|
||||
config: { duration: blindsOpenDuration },
|
||||
delay: blindsOpenDelay,
|
||||
});
|
||||
|
||||
return (
|
||||
<div onClick={() => toggle(!state)}>
|
||||
<animated.div
|
||||
style={{
|
||||
opacity,
|
||||
clipPath: wipe.to(wipeProgress => {
|
||||
const [a1, a2, b1, b2, c1, c2] = wipeCustomDegClip(
|
||||
childWidth,
|
||||
childHeight,
|
||||
wipeProgress,
|
||||
wipeStartingCorner,
|
||||
wipeAngle,
|
||||
);
|
||||
return `polygon(${a1}px ${a2}px, ${b1}px ${b2}px, ${c1}px ${c2}px)`;
|
||||
}),
|
||||
}}
|
||||
ref={childRef}
|
||||
<animated.div
|
||||
style={{
|
||||
opacity,
|
||||
clipPath: wipe.to(wipeProgress => {
|
||||
const [a1, a2, b1, b2, c1, c2] = wipeCustomDegClip(
|
||||
childWidth,
|
||||
childHeight,
|
||||
wipeProgress,
|
||||
wipeStartingCorner,
|
||||
wipeAngle,
|
||||
);
|
||||
return `polygon(${a1}px ${a2}px, ${b1}px ${b2}px, ${c1}px ${c2}px)`;
|
||||
}),
|
||||
}}
|
||||
ref={childRef}
|
||||
>
|
||||
<AnimatedVenetianBlindsFilter
|
||||
style={blindsSpring}
|
||||
blindsAngle={blindsAngle}
|
||||
transparentWidth={blindsSize.transparent}
|
||||
opaqueWidth={blindsSize.opaque}
|
||||
blindsColor={blindsColor}
|
||||
blindsColorFadeDuration={blindsColorFadeDuration}
|
||||
blindsColorFadeDelay={blindsColorFadeDelay}
|
||||
blindsClosing={visible}
|
||||
spanBlinkDuration={spanBlinkDuration}
|
||||
mirror={true} // Mirror version provides the opposite blinds.
|
||||
>
|
||||
<AnimatedVenetianBlindsFilter
|
||||
style={blindsSpring}
|
||||
blindsAngle={blindsAngle}
|
||||
transparentWidth={blindsSize.transparent}
|
||||
opaqueWidth={blindsSize.opaque}
|
||||
blindsColor={blindsColor}
|
||||
blindsColorFadeDuration={blindsColorFadeDuration}
|
||||
blindsColorFadeDelay={blindsColorFadeDelay}
|
||||
blindsClosing={!!state}
|
||||
spanBlinkDuration={spanBlinkDuration}
|
||||
mirror={true} // Mirror version provides the opposite blinds.
|
||||
>
|
||||
{children}
|
||||
</AnimatedVenetianBlindsFilter>
|
||||
<VenetianBlindsFilter
|
||||
blindsAngle={blindsAngle}
|
||||
transparentWidth={blindsSize.transparent}
|
||||
opaqueWidth={blindsSize.opaque}
|
||||
blindsColor={blindsColor}
|
||||
blindsColorFadeDuration={blindsColorFadeDuration}
|
||||
blindsColorFadeDelay={blindsColorFadeDelay}
|
||||
blindsClosing={!!state}
|
||||
spanBlinkDuration={spanBlinkDuration}
|
||||
mirror={false}
|
||||
>
|
||||
{children}
|
||||
</VenetianBlindsFilter>
|
||||
</animated.div>
|
||||
</div>
|
||||
{children}
|
||||
</AnimatedVenetianBlindsFilter>
|
||||
<VenetianBlindsFilter
|
||||
blindsAngle={blindsAngle}
|
||||
transparentWidth={blindsSize.transparent}
|
||||
opaqueWidth={blindsSize.opaque}
|
||||
blindsColor={blindsColor}
|
||||
blindsColorFadeDuration={blindsColorFadeDuration}
|
||||
blindsColorFadeDelay={blindsColorFadeDelay}
|
||||
blindsClosing={visible}
|
||||
spanBlinkDuration={spanBlinkDuration}
|
||||
mirror={false}
|
||||
>
|
||||
{children}
|
||||
</VenetianBlindsFilter>
|
||||
</animated.div>
|
||||
);
|
||||
};
|
||||
+7
-2
@@ -1,6 +1,7 @@
|
||||
import { useState } from "react";
|
||||
import { useSelector } from "react-redux";
|
||||
import { workspaceSelector } from "../../../../features/workspace/workspaceSelector";
|
||||
|
||||
import { workspaceSelector } from "../../../../features/workspace/workspaceSelector";
|
||||
import { theme } from "../../../../shared/theme";
|
||||
import { BasicBlock } from "../styles";
|
||||
|
||||
@@ -14,10 +15,13 @@ export function VenetianBlindsWorkspace() {
|
||||
const bgColor = prototypeState?.venetianTransition?.showBG ?? true
|
||||
? "black" : "transparent";
|
||||
|
||||
const [visible, setVisible] = useState(true);
|
||||
|
||||
return (
|
||||
<BasicBlock width={450} height={450} color={bgColor} >
|
||||
<BasicBlock width={450} height={450} color={bgColor} onClick={() => setVisible(!visible)} >
|
||||
{prototypeState?.venetianTransition?.mode === "driverPortrait" ? (
|
||||
<VenetianBlindsTransition
|
||||
visible={visible}
|
||||
blindsColor={theme.colors.teams.redBull}
|
||||
blindsColorFadeDuration={600}
|
||||
blindsColorFadeDelay={300}
|
||||
@@ -36,6 +40,7 @@ export function VenetianBlindsWorkspace() {
|
||||
</VenetianBlindsTransition>
|
||||
) : (
|
||||
<VenetianBlindsTransition
|
||||
visible={visible}
|
||||
blindsColor="#f60d0d"
|
||||
blindsColorFadeDuration={300}
|
||||
blindsColorFadeDelay={200}
|
||||
|
||||
Reference in new issue
Block a user