ISSUE-045 - Venetian Blinds - Improvements to prototype state management by using partial state updates, which are pretty useful.
More props for <VenentianBlindsTransition>.
This commit is contained in:
1 parent
14e4c0569d
commit
3ce590d794
6 files changed
+90
-60
No files matched your search
+15
-13
@@ -1,5 +1,5 @@
|
||||
import { useState } from "react";
|
||||
import { useSpring, animated, config } from "@react-spring/web";
|
||||
import { useSpring, animated } from "@react-spring/web";
|
||||
import useMeasure from "react-use-measure";
|
||||
|
||||
import { VenetianBlindsFilter } from "./styles";
|
||||
@@ -8,15 +8,17 @@ import { Corner } from "../../../../types/style";
|
||||
|
||||
type VenetianBlindsTransitionProps = {
|
||||
blindsColor: string,
|
||||
degrees: number,
|
||||
duration: number,
|
||||
blindsAngle: number,
|
||||
wipeAngle: number,
|
||||
wipeDuration: number,
|
||||
wipeStartingCorner: Corner,
|
||||
};
|
||||
export const VenetianBlindsTransition = (
|
||||
{
|
||||
blindsColor,
|
||||
degrees,
|
||||
duration,
|
||||
blindsAngle,
|
||||
wipeAngle,
|
||||
wipeDuration,
|
||||
wipeStartingCorner,
|
||||
children,
|
||||
}: React.PropsWithChildren<VenetianBlindsTransitionProps>,
|
||||
@@ -28,30 +30,30 @@ export const VenetianBlindsTransition = (
|
||||
|
||||
const [state, toggle] = useState(true);
|
||||
|
||||
const { x } = useSpring({
|
||||
from: { x: 0 },
|
||||
x: state ? 1 : 0,
|
||||
config: { duration },
|
||||
const { wipe } = useSpring({
|
||||
from: { wipe: 0 },
|
||||
wipe: state ? 1 : 0,
|
||||
config: { duration: wipeDuration },
|
||||
});
|
||||
|
||||
return (
|
||||
<div onClick={() => toggle(!state)}>
|
||||
<animated.div
|
||||
style={{
|
||||
clipPath: x.to(x => {
|
||||
clipPath: wipe.to(wipeProgress => {
|
||||
const [a1, a2, b1, b2, c1, c2] = wipeCustomDegClip(
|
||||
childWidth,
|
||||
childHeight,
|
||||
x,
|
||||
wipeProgress,
|
||||
wipeStartingCorner,
|
||||
degrees,
|
||||
wipeAngle,
|
||||
);
|
||||
return `polygon(${a1}px ${a2}px, ${b1}px ${b2}px, ${c1}px ${c2}px)`;
|
||||
}),
|
||||
}}
|
||||
>
|
||||
<VenetianBlindsFilter
|
||||
deg={-45}
|
||||
deg={blindsAngle}
|
||||
transparentWidth={3}
|
||||
opaqueWidth={5}
|
||||
opaqueColor={blindsColor}
|
||||
|
||||
+6
-4
@@ -17,8 +17,9 @@ export function VenetianBlindsWorkspace() {
|
||||
{prototypeState?.venetianTransition?.mode === "driverPortrait" ? (
|
||||
<VenetianBlindsTransition
|
||||
blindsColor={theme.colors.teams.mercedes + "b5"}
|
||||
degrees={35}
|
||||
duration={500}
|
||||
blindsAngle={-45}
|
||||
wipeAngle={45}
|
||||
wipeDuration={500}
|
||||
wipeStartingCorner="topLeft"
|
||||
>
|
||||
<DriverPortrait
|
||||
@@ -29,8 +30,9 @@ export function VenetianBlindsWorkspace() {
|
||||
) : (
|
||||
<VenetianBlindsTransition
|
||||
blindsColor="#f60d0db5"
|
||||
degrees={45}
|
||||
duration={350}
|
||||
blindsAngle={-45}
|
||||
wipeAngle={35}
|
||||
wipeDuration={350}
|
||||
wipeStartingCorner="bottomRight"
|
||||
>
|
||||
<PositionFlag size={122} number={1} />
|
||||
|
||||
+6
-26
@@ -1,9 +1,8 @@
|
||||
import { PadBox } from "@bedrock-layout/padbox";
|
||||
import { Split } from "@bedrock-layout/split";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { workspaceSelector } from "../../../../features/workspace/workspaceSelector";
|
||||
import { useDispatch } from "react-redux";
|
||||
|
||||
import { setPrototypeState } from "../../../../features/workspace/workspaceSlice";
|
||||
import { updateAngledFlagCountry, updateAngledFlagTeam } from "../../../../features/workspace/workspaceSlice";
|
||||
import { FlagMode, TeamId } from "../../../../types/state";
|
||||
|
||||
import { SlotSelector } from "../../../Common/Inputs/SlotSelector";
|
||||
@@ -17,41 +16,22 @@ const teams: Array<TeamId> = [
|
||||
"mclaren", "mercedes", "redBull", "williams",
|
||||
];
|
||||
|
||||
const DEFAULT_COUNTRY = "GBR";
|
||||
const DEFAULT_TEAM: TeamId = "alfaRomeo";
|
||||
|
||||
type AngledFlagPrototypeControlsProps = {
|
||||
flagMode: FlagMode,
|
||||
};
|
||||
export function AngledFlagPrototypeControls({ flagMode }: AngledFlagPrototypeControlsProps) {
|
||||
const dispatch = useDispatch();
|
||||
const { prototypeState } = useSelector(workspaceSelector);
|
||||
const flagList = flagMode === "country" ? countries : flagMode === "team" ? teams : [];
|
||||
|
||||
const onChange = (flag: "flagA" | "flagB") => (index: number) => {
|
||||
if (flagMode === "country") {
|
||||
dispatch(setPrototypeState({
|
||||
angledFlagCountry: {
|
||||
flagA: flag === "flagA"
|
||||
? countries[index]
|
||||
: prototypeState?.angledFlagCountry?.flagA ?? DEFAULT_COUNTRY,
|
||||
flagB: flag === "flagB"
|
||||
? countries[index]
|
||||
: prototypeState?.angledFlagCountry?.flagB ?? DEFAULT_COUNTRY,
|
||||
},
|
||||
dispatch(updateAngledFlagCountry({
|
||||
[flag]: countries[index],
|
||||
}));
|
||||
} else if (flagMode === "team") {
|
||||
dispatch(setPrototypeState({
|
||||
angledFlagTeam: {
|
||||
flagA: flag === "flagA"
|
||||
? teams[index]
|
||||
: prototypeState?.angledFlagTeam?.flagA ?? DEFAULT_TEAM,
|
||||
flagB: flag === "flagB"
|
||||
? teams[index]
|
||||
: prototypeState?.angledFlagTeam?.flagB ?? DEFAULT_TEAM,
|
||||
},
|
||||
dispatch(updateAngledFlagTeam({
|
||||
[flag]: teams[index],
|
||||
}));
|
||||
|
||||
}
|
||||
};
|
||||
return (
|
||||
|
||||
+7
-12
@@ -1,8 +1,9 @@
|
||||
import { InlineCluster } from "@bedrock-layout/inline-cluster";
|
||||
import { PadBox } from "@bedrock-layout/padbox";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
|
||||
import { workspaceSelector } from "../../../../features/workspace/workspaceSelector";
|
||||
import { setPrototypeState } from "../../../../features/workspace/workspaceSlice";
|
||||
import { updateVenetianTransition } from "../../../../features/workspace/workspaceSlice";
|
||||
import { VenetianTransitionWorkspaceMode } from "../../../../types/state";
|
||||
|
||||
import { SlotSelector } from "../../../Common/Inputs/SlotSelector";
|
||||
@@ -18,20 +19,14 @@ export function VenetianBlindsPrototypeControls() {
|
||||
const { prototypeState } = useSelector(workspaceSelector);
|
||||
|
||||
const onChange = (index: number) => {
|
||||
dispatch(setPrototypeState({
|
||||
venetianTransition: {
|
||||
mode: modes[index],
|
||||
showBG: prototypeState?.venetianTransition?.showBG ?? false,
|
||||
},
|
||||
dispatch(updateVenetianTransition({
|
||||
mode: modes[index],
|
||||
}));
|
||||
};
|
||||
|
||||
const onToggle = (value: boolean) => {
|
||||
dispatch(setPrototypeState({
|
||||
venetianTransition: {
|
||||
mode: prototypeState?.venetianTransition?.mode ?? "positionFlag",
|
||||
showBG: value,
|
||||
},
|
||||
dispatch(updateVenetianTransition({
|
||||
showBG: value,
|
||||
}));
|
||||
};
|
||||
|
||||
@@ -44,7 +39,7 @@ export function VenetianBlindsPrototypeControls() {
|
||||
slotWidth="200px"
|
||||
/>
|
||||
<Toggle
|
||||
toggled={prototypeState?.venetianTransition?.showBG ?? false}
|
||||
toggled={prototypeState?.venetianTransition?.showBG ?? true}
|
||||
onToggle={onToggle}
|
||||
label="Show BG"
|
||||
/>
|
||||
|
||||
@@ -9,7 +9,7 @@ const initialState: RootState["workspace"] = {
|
||||
overlayIds: [],
|
||||
previewWindowDimensions: { width: 0, height: 0 },
|
||||
},
|
||||
prototypeState: null,
|
||||
prototypeState: {},
|
||||
};
|
||||
|
||||
export type UpdateWorkspaceAction = {
|
||||
@@ -31,8 +31,54 @@ export const workspaceSlice = createSlice({
|
||||
state.workspaceId = action.payload.workspaceId;
|
||||
state.workspaceProperties = action.payload.workspaceProperties;
|
||||
},
|
||||
setPrototypeState: (state, action: PayloadAction<PrototypeState>) => {
|
||||
state.prototypeState = action.payload;
|
||||
|
||||
// Prototype States
|
||||
updateAngledFlagCountry: (
|
||||
state,
|
||||
action: PayloadAction<Partial<PrototypeState["angledFlagCountry"]>>,
|
||||
) => {
|
||||
if (state.prototypeState.angledFlagCountry == null) {
|
||||
state.prototypeState.angledFlagCountry = {
|
||||
flagA: "GBR",
|
||||
flagB: "GBR",
|
||||
};
|
||||
}
|
||||
state.prototypeState.angledFlagCountry = Object.assign(
|
||||
state.prototypeState.angledFlagCountry,
|
||||
action.payload,
|
||||
);
|
||||
},
|
||||
updateAngledFlagTeam: (
|
||||
state,
|
||||
action: PayloadAction<Partial<PrototypeState["angledFlagTeam"]>>,
|
||||
) => {
|
||||
if (state.prototypeState.angledFlagTeam == null) {
|
||||
state.prototypeState.angledFlagTeam = {
|
||||
flagA: "alfaRomeo",
|
||||
flagB: "alfaRomeo",
|
||||
};
|
||||
}
|
||||
state.prototypeState.angledFlagTeam = Object.assign(
|
||||
state.prototypeState.angledFlagTeam,
|
||||
action.payload,
|
||||
);
|
||||
},
|
||||
updateVenetianTransition: (
|
||||
state,
|
||||
action: PayloadAction<Partial<PrototypeState["venetianTransition"]>>,
|
||||
) => {
|
||||
if (state.prototypeState.venetianTransition == null) {
|
||||
state.prototypeState.venetianTransition = {
|
||||
mode: "positionFlag",
|
||||
showBG: true,
|
||||
timing: 500,
|
||||
startingCorner: "topLeft",
|
||||
};
|
||||
}
|
||||
state.prototypeState.venetianTransition = Object.assign(
|
||||
state.prototypeState?.venetianTransition,
|
||||
action.payload,
|
||||
);
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -41,6 +87,8 @@ export const {
|
||||
setWorkspaceId,
|
||||
setAnimatedBG,
|
||||
updateWorkspace,
|
||||
setPrototypeState,
|
||||
updateAngledFlagCountry,
|
||||
updateAngledFlagTeam,
|
||||
updateVenetianTransition,
|
||||
} = workspaceSlice.actions;
|
||||
export default workspaceSlice.reducer;
|
||||
Vendored
+4
-1
@@ -1,4 +1,5 @@
|
||||
import { Milliseconds, Optional } from "./util";
|
||||
import { Corner } from "./style";
|
||||
|
||||
export interface RootState {
|
||||
pageDimensions: PageDimensions;
|
||||
@@ -22,7 +23,7 @@ export interface Workspace {
|
||||
workspaceId: WorkspaceId;
|
||||
animatedBG: boolean;
|
||||
workspaceProperties: WorkspaceProperties;
|
||||
prototypeState: Optional<PrototypeState>;
|
||||
prototypeState: PrototypeState;
|
||||
}
|
||||
|
||||
export type WorkspaceId = string;
|
||||
@@ -43,6 +44,8 @@ export interface PrototypeState {
|
||||
venetianTransition?: {
|
||||
mode: VenetianTransitionWorkspaceMode;
|
||||
showBG: boolean;
|
||||
timing: number,
|
||||
startingCorner: Corner,
|
||||
};
|
||||
}
|
||||
export type VenetianTransitionWorkspaceMode = "positionFlag" | "driverPortrait";
|
||||
|
||||
Reference in new issue
Block a user