ISSUE-017 - Basic drag functionality added.
I cannot combine it with transition handling any top/left transitions.
This commit is contained in:
1 parent
1ba5e99532
commit
9541306894
4 files changed
+36
-8
No files matched your search
@@ -27,6 +27,7 @@
|
||||
"@types/react-dom": "^17.0.9",
|
||||
"@types/react-redux": "^7.1.21",
|
||||
"@types/styled-components": "^5.1.18",
|
||||
"@use-gesture/react": "^10.2.4",
|
||||
"d3": "^7.2.1",
|
||||
"history": "5",
|
||||
"react": "^17.0.2",
|
||||
|
||||
@@ -1,23 +1,31 @@
|
||||
import { useSelector } from "react-redux";
|
||||
import { useSelector, useDispatch } from "react-redux";
|
||||
import { useTransition, animated } from "@react-spring/web";
|
||||
import { useDrag } from "@use-gesture/react";
|
||||
|
||||
import { overlayToolSelector } from "../../../features/overlayTool/overlayToolSelector";
|
||||
import { setPosition } from "../../../features/overlayTool/overlayToolSlice";
|
||||
|
||||
import { OverlayItemContainer } from "./styles";
|
||||
|
||||
export function OverlayDisplay() {
|
||||
const { currentOverlayItem, visible } = useSelector(overlayToolSelector);
|
||||
const dispatch = useDispatch();
|
||||
const bindOverlayItem = useDrag((state) => {
|
||||
dispatch(setPosition({
|
||||
x: state.args[0].xPos + state.delta[0],
|
||||
y: state.args[0].yPos + state.delta[1],
|
||||
}));
|
||||
});
|
||||
|
||||
const xPos = currentOverlayItem?.position.x ?? 0;
|
||||
const yPos = currentOverlayItem?.position.y ?? 0;
|
||||
const transition = useTransition(visible, {
|
||||
from: { left: xPos, top: yPos + 50, opacity: 0 },
|
||||
from: { top: 50, opacity: 0 },
|
||||
enter: {
|
||||
left: xPos,
|
||||
top: yPos,
|
||||
top: 0,
|
||||
opacity: currentOverlayItem?.opacity ?? 1,
|
||||
},
|
||||
leave: { left: xPos, top: yPos + 50, opacity: 0 },
|
||||
leave: { top: 50, opacity: 0 },
|
||||
});
|
||||
|
||||
if (currentOverlayItem == null) {
|
||||
@@ -30,7 +38,14 @@ export function OverlayDisplay() {
|
||||
transition((style, visible) =>
|
||||
visible ? (
|
||||
<animated.div
|
||||
style={{ ...style, position: "absolute" }}
|
||||
{...bindOverlayItem({ xPos, yPos })}
|
||||
style={{
|
||||
...style,
|
||||
left: xPos,
|
||||
// top: style.top.get() + yPos, // This doesn't work.
|
||||
top: yPos,
|
||||
position: "absolute",
|
||||
}}
|
||||
>
|
||||
<OverlayItemContainer position={position} visible={visible}>
|
||||
{id}
|
||||
|
||||
@@ -11,8 +11,8 @@ export const OverlayItemContainer = styled.div.attrs<OverlayItemContainerProps>(
|
||||
visible,
|
||||
}) => ({
|
||||
style: {
|
||||
top: y,
|
||||
left: x,
|
||||
// top: y,
|
||||
// left: x,
|
||||
display: visible ? undefined : "none",
|
||||
},
|
||||
}))<OverlayItemContainerProps>`
|
||||
|
||||
@@ -2284,6 +2284,18 @@
|
||||
"@typescript-eslint/types" "5.7.0"
|
||||
eslint-visitor-keys "^3.0.0"
|
||||
|
||||
"@use-gesture/core@10.2.4":
|
||||
version "10.2.4"
|
||||
resolved "https://registry.yarnpkg.com/@use-gesture/core/-/core-10.2.4.tgz#139370223174b0589bd4b4f8ac7c0beb6ba64ba2"
|
||||
integrity sha512-fk1LjCBj43BKb8NE05qkdtPOR0ngA7PwgvEqfFap/h+s7QHi+JTv4/mtDQ4wI9zzem+Ry5EKrHS/cVdBehI4wA==
|
||||
|
||||
"@use-gesture/react@^10.2.4":
|
||||
version "10.2.4"
|
||||
resolved "https://registry.yarnpkg.com/@use-gesture/react/-/react-10.2.4.tgz#b333e91b00670785ee32e8f4f1530ac6b8894bbc"
|
||||
integrity sha512-CbqyRj+qNbRBOGmS8OWtaOa29fxEr7bKTYHvPuMQ1wsgQDh2/DqQxbp7cFxAg6WZ8oZjppDj/EkWnw22WpIIWQ==
|
||||
dependencies:
|
||||
"@use-gesture/core" "10.2.4"
|
||||
|
||||
"@webassemblyjs/ast@1.11.1":
|
||||
version "1.11.1"
|
||||
resolved "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.11.1.tgz"
|
||||
|
||||
Reference in new issue
Block a user