From 9f4e564a743967e78abd768f5af5b52b2c853cb4 Mon Sep 17 00:00:00 2001 From: Kyle Geib Date: Mon, 7 Mar 2022 11:50:05 -0500 Subject: [PATCH] ISSUE-058 - New opening/closing transition props feature added. Last name wiping added. Now we can define separate opening and closing transition settings as well as common (both ways) transition props. This is all pretty cool. Timing for open/close animations and transitions are looking better and more mature. --- .../TimingTower/TimingTowerRow.tsx | 101 ++++++++++++------ .../TimingBoard/TimingTower/styles.ts | 97 +++++++++-------- .../TimingTowerPrototypeControls.tsx | 1 - src/types/style.d.ts | 11 ++ src/utils/styling.ts | 32 +++++- 5 files changed, 162 insertions(+), 80 deletions(-) diff --git a/src/components/BroadcastGraphics/TimingBoard/TimingTower/TimingTowerRow.tsx b/src/components/BroadcastGraphics/TimingBoard/TimingTower/TimingTowerRow.tsx index d6fd89b..63b29be 100644 --- a/src/components/BroadcastGraphics/TimingBoard/TimingTower/TimingTowerRow.tsx +++ b/src/components/BroadcastGraphics/TimingBoard/TimingTower/TimingTowerRow.tsx @@ -35,6 +35,7 @@ import { RowLeftHalfPosFlagChangeContainer, AnimatedRowLeftHalfOutline, DriverNameContainer, + DriverNameWipe, } from "./styles"; import useMeasure from "react-use-measure"; @@ -42,6 +43,7 @@ const WIPE_DELAY: Milliseconds = 3500; const WIPE_DURATION: Milliseconds = 400; const TRAVEL_DURATION: Milliseconds = 750; const FULL_WIDTH_DURATION: Milliseconds = 750; +const FULL_WIDTH_CLOSE_DELAY: Milliseconds = 333; interface TimingTowerRowProps { car: Car; @@ -172,7 +174,8 @@ export function TimingTowerRow({ BGTimingTowerDisplayMode.FullLeft, ) ? 5 : 0 } - transitionProps={[{ + open={displayMode === BGTimingTowerDisplayMode.FullLeft} + transitionOpeningProps={[{ property: "width", duration: FULL_WIDTH_DURATION * DDM, }, { @@ -182,7 +185,19 @@ export function TimingTowerRow({ property: "border-bottom-right-radius", duration: TRAVEL_DURATION * DDM, }]} - wide={displayMode === BGTimingTowerDisplayMode.FullLeft} + transitionClosingProps={[{ + property: "width", + duration: FULL_WIDTH_DURATION * DDM, + delay: FULL_WIDTH_CLOSE_DELAY * DDM, + }, { + property: "border-top-right-radius", + duration: TRAVEL_DURATION * DDM, + delay: FULL_WIDTH_CLOSE_DELAY * DDM, + }, { + property: "border-bottom-right-radius", + duration: TRAVEL_DURATION * DDM, + delay: FULL_WIDTH_CLOSE_DELAY * DDM, + }]} ref={leftHalfRef} > @@ -220,34 +235,47 @@ export function TimingTowerRow({ )} - - + + {car.driver.initials} - - + {car.driver.lastName} - + @@ -292,25 +320,36 @@ export function TimingTowerRow({ BGTimingTowerSplitsMode.Interval, ) ? 5 : 0 } - collapsed={displayMode !== BGTimingTowerDisplayMode.LeftAndRight} + open={displayMode === BGTimingTowerDisplayMode.LeftAndRight} transitionProps={[{ - property: "width", - duration: FULL_WIDTH_DURATION * DDM, - }, { property: "border-top-right-radius", duration: TRAVEL_DURATION * DDM, }, { property: "border-bottom-right-radius", duration: TRAVEL_DURATION * DDM, }]} + transitionClosingProps={[{ + property: "width", + duration: FULL_WIDTH_DURATION * DDM, + }]} + transitionOpeningProps={[{ + property: "width", + duration: FULL_WIDTH_DURATION * DDM, + delay: FULL_WIDTH_CLOSE_DELAY * DDM, + }]} hugRight={hugRight} > ` border-bottom-right-radius: ${({ roundedCornerBottom = 0 }) => roundedCornerBottom}px; `; -type RowLeftHalfProps = TransitionProps & { - wide: boolean, -}; -export const RowLeftHalf = styled(Rounded)` +export const RowLeftHalf = styled(Rounded)` position: absolute; left: 0; top: 0; z-index: 1; overflow-x: clip; - width: ${({ theme: { design: { timingTower } }, wide }) => - (wide ? timingTower.rowRightHalfWidthPx : 0) + timingTower.rowLeftHalfWidthPx}px; + width: ${({ theme: { design: { timingTower } }, open }) => + (open ? timingTower.rowRightHalfWidthPx : 0) + timingTower.rowLeftHalfWidthPx}px; height: ${p => p.theme.design.timingTower.rowHeightPx}px; background-color: #000000e5; - ${({ transitionProps }) => commonTransition(transitionProps)} + ${({ open, transitionOpeningProps, transitionClosingProps, transitionProps }) => + commonDirectionalTransition(open, transitionOpeningProps, transitionClosingProps, transitionProps)} `; RowLeftHalf.displayName = "RowLeftHalf"; -type AnimatedRowLeftHalfOutlineProps = OpenProps & TransitionProps & { +type AnimatedRowLeftHalfOutlineProps = DirectionalTransitionProps & { startThickness: Px, endThickness: Px, startColor: string, endColor: string, }; -export const AnimatedRowLeftHalfOutline = animated(styled(Rounded) ` +export const AnimatedRowLeftHalfOutline = animated(styled(Rounded)` position: absolute; top: 0; left: 0; @@ -106,7 +101,8 @@ export const AnimatedRowLeftHalfOutline = animated(styled(Rounded) -startThickness}px; - ${({ transitionProps }) => commonTransition(transitionProps)} + ${({ open, transitionOpeningProps, transitionClosingProps, transitionProps }) => + commonDirectionalTransition(open, transitionOpeningProps, transitionClosingProps, transitionProps)} `); AnimatedRowLeftHalfOutline.displayName = "AnimatedRowLeftHalfOutline"; @@ -118,7 +114,6 @@ export const RowLeftHalfLayout = styled.div` display: flex; padding-left: 3px; - /* align-items: center; */ justify-content: flex-start; `; RowLeftHalfLayout.displayName = "RowLeftHalfLayout"; @@ -158,27 +153,29 @@ export const RowLeftHalfGemContainer = styled.div` `; RowLeftHalfGemContainer.displayName = "RowLeftHalfGemContainer"; -type RowRightHalfProps = TransitionProps & { - collapsed: boolean, +type RowRightHalfProps = DirectionalTransitionProps & { hugRight: boolean, }; export const RowRightHalf = styled(Rounded)` position: absolute; ${({ hugRight }) => hugRight - ? css`right: 0;` : css` - left: ${p => p.theme.design.timingTower.rowLeftHalfWidthPx}px; - `} + ? css` + right: 0; + ` : css` + left: ${p => p.theme.design.timingTower.rowLeftHalfWidthPx}px; + `} top: 0; - width: ${({ theme: { design: { timingTower } }, collapsed }) => - collapsed ? 0 : timingTower.rowRightHalfWidthPx}px; + width: ${({ theme: { design: { timingTower } }, open }) => + open ? timingTower.rowRightHalfWidthPx : 0}px; height: ${p => p.theme.design.timingTower.rowHeightPx}px; overflow-x: clip; background-color: #0000007e; - ${({ transitionProps }) => commonTransition(transitionProps)} + ${({ open, transitionOpeningProps, transitionClosingProps, transitionProps }) => + commonDirectionalTransition(open, transitionOpeningProps, transitionClosingProps, transitionProps)} `; RowRightHalf.displayName = "RowRightHalf"; @@ -194,37 +191,46 @@ export const RowRightHalfLayout = styled.div` `; RowRightHalfLayout.displayName = "RowRightHalfLayout"; -type DriverNameProps = { - visible: boolean, -}; -export const DriverName = styled.span` +export const DriverNameContainer = styled.div` + position: relative; + margin-left: ${p => p.theme.design.timingTower.nameLeftMargin}px; +`; +DriverNameContainer.displayName = "DriverNameContainer"; + +export const DriverName = styled.span` position: absolute; top: 0; left: 0; - opacity: ${({ visible }) => visible ? 1 : 0}; - color: white; font-family: ${p => p.theme.fonts.f1Bold}; font-size: 20px; text-transform: uppercase; + + opacity: ${({ open }) => open ? 1 : 0}; + ${({ open, transitionOpeningProps, transitionClosingProps, transitionProps }) => + commonDirectionalTransition(open, transitionOpeningProps, transitionClosingProps, transitionProps)} `; DriverName.displayName = "DriverName"; -export const DriverNameContainer = styled.div` - position: relative; - margin-left: ${p => p.theme.design.timingTower.nameLeftMargin}px; +export const DriverNameWipe = styled.div` + /* background: #deadbe; */ - > span { - ${({ transitionProps }) => commonTransition(transitionProps)} - } + width: ${({ open }) => open ? 800 : 200}px; + height: ${p => p.theme.design.timingTower.rowHeightPx}px; + + mask-image: linear-gradient(to right, black 0, black 20%, transparent 30%); + mask-repeat: no-repeat; + + opacity: ${({ open }) => open ? 1 : 0}; + ${({ open, transitionOpeningProps, transitionClosingProps, transitionProps }) => + commonDirectionalTransition(open, transitionOpeningProps, transitionClosingProps, transitionProps)} `; -DriverNameContainer.displayName = "DriverNameContainer"; +DriverNameWipe.displayName = "DriverNameWipe"; -type TimeDiffProps = TransitionProps & { +type TimeDiffProps = DirectionalTransitionProps & { xScale: Fraction, yScale: Fraction, - visible: boolean, }; export const TimeDiff = styled.span` color: white; @@ -237,8 +243,9 @@ export const TimeDiff = styled.span` transform-origin: top right; transform: scale(${({ xScale, yScale }) => `${xScale}, ${yScale}`}); - opacity: ${({ visible }) => visible ? 1 : 0}; - ${({ transitionProps }) => commonTransition(transitionProps)} + opacity: ${({ open }) => open ? 1 : 0}; + ${({ open, transitionOpeningProps, transitionClosingProps, transitionProps }) => + commonDirectionalTransition(open, transitionOpeningProps, transitionClosingProps, transitionProps)} `; TimeDiff.displayName = "TimeDiff"; diff --git a/src/components/Workspaces/PrototypingControls/TimingTowerPrototype/TimingTowerPrototypeControls.tsx b/src/components/Workspaces/PrototypingControls/TimingTowerPrototype/TimingTowerPrototypeControls.tsx index 3a88707..bbc74f7 100644 --- a/src/components/Workspaces/PrototypingControls/TimingTowerPrototype/TimingTowerPrototypeControls.tsx +++ b/src/components/Workspaces/PrototypingControls/TimingTowerPrototype/TimingTowerPrototypeControls.tsx @@ -10,7 +10,6 @@ import { setTimingTowerDisplayMode, setTimingTowerSplitsMode } from "../../../.. import { eventSelector } from "../../../../features/event/eventSelector"; import { increaseDistance, refreshRunningOrder, setCarStatus } from "../../../../features/event/eventSlice"; import { BGTimingTowerDisplayMode, BGTimingTowerSplitsMode, CarStatus } from "../../../../types/state"; -import { SlotSelector } from "../../../Common/Inputs/SlotSelector"; import { GridSelection } from "../GridSelection"; import { ClickSpan } from "./styles"; diff --git a/src/types/style.d.ts b/src/types/style.d.ts index 64e22dd..e9b3e97 100644 --- a/src/types/style.d.ts +++ b/src/types/style.d.ts @@ -40,3 +40,14 @@ export interface TransitionArgs { timing?: string delay?: Milliseconds, } + +export type OpenProps = { + open: boolean, +}; +export type TransitionProps = OpenProps & { + transitionProps?: TransitionArgs[], +}; +export type DirectionalTransitionProps = TransitionProps & { + transitionOpeningProps?: TransitionArgs[], + transitionClosingProps?: TransitionArgs[], +} diff --git a/src/utils/styling.ts b/src/utils/styling.ts index 4d3c3e1..34ecfa1 100644 --- a/src/utils/styling.ts +++ b/src/utils/styling.ts @@ -69,16 +69,42 @@ export function wipeCustomDegClip( * @param propsArray * @returns */ -export function commonTransition(propsArray: TransitionArgs[]) { +export function commonTransition(propsArray: TransitionArgs[] = []) { + if (propsArray.length === 0){ + return ""; + } + return ( "transition: " + propsArray.map(p => ` - ${p?.property ?? "all"} ${p?.duration ?? 1000}ms ${p?.timing ?? ""} ${p?.delay ?? 0}ms - `).join(", ") + ${p?.property ?? "all"} ${p?.duration ?? 1000}ms ${p?.timing ?? ""} ${p?.delay ?? 0}ms`, + ).join(", ") + ";" ); } +/** + * An extension and evolution of commonTransition() provides a way to define + * transition configurations that can be differentiated by which direction + * (opening or closing) that they're going and can even support additional + * "shared" properties that are common in either direction. + * @param open the (often visible) state of the element + * @param openingPropsArray what transition props to use when "open" (opening) + * @param closingPropsArray what transition props to use when "closed" (closing) + * @param sharedPropsArray what transition props to use in either direction + * @returns + */ +export function commonDirectionalTransition( + open: boolean, + openingPropsArray: TransitionArgs[] = [], + closingPropsArray: TransitionArgs[] = [], + sharedPropsArray: TransitionArgs[] = [], +) { + return open + ? commonTransition(openingPropsArray.concat(sharedPropsArray)) + : commonTransition(closingPropsArray.concat(sharedPropsArray)); +} + /** * Provides the x, y coordinates of a six point polygon for use in a clip-path * mask. By taking a fraction to indicate the progress through the animation it