ISSUE-045 - Venetian Blinds - Wipe, blinds closing, and blinds color all working.
This commit is contained in:
1 parent
3ce590d794
commit
78073b1eb2
5 files changed
+103
-29
No files matched your search
+45
-12
@@ -2,21 +2,32 @@ import { useState } from "react";
|
||||
import { useSpring, animated } from "@react-spring/web";
|
||||
import useMeasure from "react-use-measure";
|
||||
|
||||
import { VenetianBlindsFilter } from "./styles";
|
||||
import { AnimatedVenetianBlindsFilter, VenetianBlindsFilter } from "./styles";
|
||||
import { wipeCustomDegClip } from "../../../../utils/styling";
|
||||
import { Corner } from "../../../../types/style";
|
||||
import { Corner, Degrees, Px } from "../../../../types/style";
|
||||
import { Milliseconds } from "../../../../types/util";
|
||||
|
||||
type VenetianBlindsTransitionProps = {
|
||||
blindsColor: string,
|
||||
blindsAngle: number,
|
||||
wipeAngle: number,
|
||||
wipeDuration: number,
|
||||
blindsColorFadeDuration: Milliseconds,
|
||||
blindsColorFadeDelay?: Milliseconds,
|
||||
blindsAngle: Degrees,
|
||||
blindsOpenDuration: Milliseconds,
|
||||
blindsOpenDelay?: Milliseconds,
|
||||
blindsSize: { opaque: Px, transparent: Px },
|
||||
wipeAngle: Degrees,
|
||||
wipeDuration: Milliseconds,
|
||||
wipeStartingCorner: Corner,
|
||||
};
|
||||
export const VenetianBlindsTransition = (
|
||||
{
|
||||
blindsColor,
|
||||
blindsColorFadeDuration,
|
||||
blindsColorFadeDelay = 0,
|
||||
blindsAngle,
|
||||
blindsOpenDuration,
|
||||
blindsOpenDelay = 0,
|
||||
blindsSize,
|
||||
wipeAngle,
|
||||
wipeDuration,
|
||||
wipeStartingCorner,
|
||||
@@ -31,11 +42,16 @@ export const VenetianBlindsTransition = (
|
||||
const [state, toggle] = useState(true);
|
||||
|
||||
const { wipe } = useSpring({
|
||||
from: { wipe: 0 },
|
||||
wipe: state ? 1 : 0,
|
||||
config: { duration: wipeDuration },
|
||||
});
|
||||
|
||||
const blindsSpring = useSpring({
|
||||
opacity: state ? 1 : 0,
|
||||
config: { duration: blindsOpenDuration },
|
||||
delay: blindsOpenDelay,
|
||||
});
|
||||
|
||||
return (
|
||||
<div onClick={() => toggle(!state)}>
|
||||
<animated.div
|
||||
@@ -51,13 +67,30 @@ export const VenetianBlindsTransition = (
|
||||
return `polygon(${a1}px ${a2}px, ${b1}px ${b2}px, ${c1}px ${c2}px)`;
|
||||
}),
|
||||
}}
|
||||
>
|
||||
<VenetianBlindsFilter
|
||||
deg={blindsAngle}
|
||||
transparentWidth={3}
|
||||
opaqueWidth={5}
|
||||
opaqueColor={blindsColor}
|
||||
ref={childRef}
|
||||
>
|
||||
<AnimatedVenetianBlindsFilter
|
||||
style={blindsSpring}
|
||||
blindsAngle={blindsAngle}
|
||||
transparentWidth={blindsSize.transparent}
|
||||
opaqueWidth={blindsSize.opaque}
|
||||
blindsColor={blindsColor}
|
||||
blindsColorFadeDuration={blindsColorFadeDuration}
|
||||
blindsColorFadeDelay={blindsColorFadeDelay}
|
||||
blindsClosed={!!state}
|
||||
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}
|
||||
blindsClosed={!!state}
|
||||
mirror={false}
|
||||
>
|
||||
{children}
|
||||
</VenetianBlindsFilter>
|
||||
|
||||
@@ -1,23 +1,43 @@
|
||||
import { animated } from "@react-spring/web";
|
||||
import styled from "styled-components";
|
||||
import { Px } from "../../../../types/style";
|
||||
|
||||
import { Degrees, Px } from "../../../../types/style";
|
||||
import { Milliseconds } from "../../../../types/util";
|
||||
|
||||
type VenetianBlindsFilterProps = {
|
||||
deg: number,
|
||||
blindsAngle: Degrees,
|
||||
transparentWidth: Px,
|
||||
opaqueWidth: Px,
|
||||
opaqueColor: string,
|
||||
blindsColor: string,
|
||||
blindsColorFadeDuration: Milliseconds,
|
||||
blindsColorFadeDelay?: Milliseconds,
|
||||
blindsClosed: boolean,
|
||||
mirror?: boolean,
|
||||
};
|
||||
export const VenetianBlindsFilter = styled.div<VenetianBlindsFilterProps>`
|
||||
position: ${({ mirror }) => mirror ? "absolute" : null};
|
||||
|
||||
--A: ${({ mirror }) => mirror ? "transparent" : "black"};
|
||||
--B: ${({ mirror }) => mirror ? "black" : "transparent"};
|
||||
|
||||
mask-image: repeating-linear-gradient(
|
||||
${({ deg }) => deg}deg,
|
||||
black,
|
||||
black ${({ opaqueWidth }) => opaqueWidth}px,
|
||||
transparent ${({ opaqueWidth }) => opaqueWidth}px,
|
||||
transparent ${({ transparentWidth, opaqueWidth }) => transparentWidth + opaqueWidth}px
|
||||
${({ blindsAngle }) => blindsAngle}deg,
|
||||
var(--A),
|
||||
var(--A) ${({ opaqueWidth }) => opaqueWidth}px,
|
||||
var(--B) ${({ opaqueWidth }) => opaqueWidth}px,
|
||||
var(--B) ${({ transparentWidth, opaqueWidth }) => transparentWidth + opaqueWidth}px
|
||||
);
|
||||
|
||||
> * {
|
||||
box-shadow: inset 0 0 0 99999px ${({ opaqueColor }) => opaqueColor};
|
||||
box-shadow: inset 0 0 0 99999px ${({ blindsColor, blindsClosed }) =>
|
||||
`${blindsColor}${blindsClosed ? "00" : "cc"}`};
|
||||
transition: box-shadow
|
||||
${({ blindsColorFadeDuration }) => blindsColorFadeDuration}ms
|
||||
cubic-bezier(0.88, 0.18, 0.96, 0.75)
|
||||
${({ blindsColorFadeDelay = 0 }) => blindsColorFadeDelay}ms;
|
||||
}
|
||||
`;
|
||||
VenetianBlindsFilter.displayName = "VenetianBlindsFilter";
|
||||
|
||||
export const AnimatedVenetianBlindsFilter = animated(VenetianBlindsFilter);
|
||||
AnimatedVenetianBlindsFilter.displayName = "AnimatedVenetianBlindsFilter";
|
||||
+15
-7
@@ -16,23 +16,31 @@ export function VenetianBlindsWorkspace() {
|
||||
<BasicBlock width={450} height={450} color={bgColor} >
|
||||
{prototypeState?.venetianTransition?.mode === "driverPortrait" ? (
|
||||
<VenetianBlindsTransition
|
||||
blindsColor={theme.colors.teams.mercedes + "b5"}
|
||||
blindsColor={theme.colors.teams.redBull}
|
||||
blindsColorFadeDuration={600}
|
||||
blindsColorFadeDelay={300}
|
||||
blindsAngle={-45}
|
||||
blindsOpenDuration={600}
|
||||
blindsOpenDelay={600}
|
||||
blindsSize={{ transparent: 2, opaque: 5 }}
|
||||
wipeAngle={45}
|
||||
wipeDuration={500}
|
||||
wipeDuration={600}
|
||||
wipeStartingCorner="topLeft"
|
||||
>
|
||||
<DriverPortrait
|
||||
driverId="hamilton"
|
||||
height={150}
|
||||
driverId="verstappen"
|
||||
height={250}
|
||||
/>
|
||||
</VenetianBlindsTransition>
|
||||
) : (
|
||||
<VenetianBlindsTransition
|
||||
blindsColor="#f60d0db5"
|
||||
blindsColor="#f60d0d"
|
||||
blindsColorFadeDuration={400}
|
||||
blindsAngle={-45}
|
||||
wipeAngle={35}
|
||||
wipeDuration={350}
|
||||
blindsOpenDuration={120}
|
||||
blindsSize={{ transparent: 3, opaque: 6 }}
|
||||
wipeAngle={40}
|
||||
wipeDuration={200}
|
||||
wipeStartingCorner="bottomRight"
|
||||
>
|
||||
<PositionFlag size={122} number={1} />
|
||||
|
||||
Vendored
+5
@@ -13,6 +13,11 @@ export type Percent = number;
|
||||
*/
|
||||
export type Fraction = number;
|
||||
|
||||
/**
|
||||
* Type to remind you that we're dealing with degrees (0-360, etc).
|
||||
*/
|
||||
export type Degrees = number;
|
||||
|
||||
/**
|
||||
* Object to cleanly define relative/absolute placement for a styled component.
|
||||
*/
|
||||
|
||||
Vendored
+9
-1
@@ -1,3 +1,11 @@
|
||||
export type Optional<TEntity> = TEntity | null;
|
||||
export type Optional<T> = T | null;
|
||||
|
||||
/**
|
||||
* Type to remind you that we're dealing with milliseconds.
|
||||
*/
|
||||
export type Milliseconds = number;
|
||||
|
||||
/**
|
||||
* Type to remind you that we're dealing with seconds.
|
||||
*/
|
||||
export type Seconds = number;
|
||||
Reference in new issue
Block a user