From a6a5eb775164ceef883b8874a88058c7ea9935e3 Mon Sep 17 00:00:00 2001 From: Kyle Geib Date: Wed, 12 Jan 2022 14:52:38 -0500 Subject: [PATCH] ISSUE-017 - Figured out how to allow for Transition and Dragging on the same element. The secret? Don't! Use another throw-away div and put it around the draggable div. Also adopted animated.div into the Styled-Component. Really cool how it just works. --- .../OverlayDisplay/OverlayDisplay.tsx | 25 +++++++++---------- .../OverlayTool/OverlayDisplay/styles.ts | 25 +++++++++++++++++-- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/components/OverlayTool/OverlayDisplay/OverlayDisplay.tsx b/src/components/OverlayTool/OverlayDisplay/OverlayDisplay.tsx index aa0c38a..cf1ccfb 100644 --- a/src/components/OverlayTool/OverlayDisplay/OverlayDisplay.tsx +++ b/src/components/OverlayTool/OverlayDisplay/OverlayDisplay.tsx @@ -5,7 +5,7 @@ import { useDrag } from "@use-gesture/react"; import { overlayToolSelector } from "../../../features/overlayTool/overlayToolSelector"; import { setPosition } from "../../../features/overlayTool/overlayToolSlice"; -import { OverlayItemContainer } from "./styles"; +import { AnimatedOverlayItemContainer } from "./styles"; export function OverlayDisplay() { const { currentOverlayItem, visible } = useSelector(overlayToolSelector); @@ -37,21 +37,20 @@ export function OverlayDisplay() { return ( transition((style, visible) => visible ? ( - - + + {id}
(x:{position.x}px, y:{position.y}px) -
+
) : null, ) diff --git a/src/components/OverlayTool/OverlayDisplay/styles.ts b/src/components/OverlayTool/OverlayDisplay/styles.ts index de78e35..50e9c68 100644 --- a/src/components/OverlayTool/OverlayDisplay/styles.ts +++ b/src/components/OverlayTool/OverlayDisplay/styles.ts @@ -1,3 +1,4 @@ +import { animated } from "@react-spring/web"; import styled from "styled-components"; import { OverlayPosition } from "../../../types/state"; @@ -11,8 +12,8 @@ export const OverlayItemContainer = styled.div.attrs( visible, }) => ({ style: { - // top: y, - // left: x, + top: y, + left: x, display: visible ? undefined : "none", }, }))` @@ -24,3 +25,23 @@ export const OverlayItemContainer = styled.div.attrs( `; OverlayItemContainer.displayName = "OverlayItemContainer"; +type AnimatedOverlayItemContainerProps = { + visible: boolean, +} +export const AnimatedOverlayItemContainer = styled(animated.div).attrs(({ + visible, +}) => ({ + style: { + display: visible ? undefined : "none", + }, +}))` + position: absolute; + z-index: 1; + + /* Temporary. Overlay will be transparent and based on an image. */ + width: 150px; + height: 150px; + background-color: white; + box-shadow: 0px 7px 11px 1px black; +`; +