From a2cd70d7ca59de5007dd7628f0b3fb1e38dbb66e Mon Sep 17 00:00:00 2001 From: Roman Pominov Date: Mon, 15 Aug 2022 09:43:56 +0300 Subject: [PATCH] cursor=grabbing while dragging --- .../app/designer/shared/tree/tree.tsx | 7 ++++-- .../src/components/primitives/dnd/index.ts | 1 + .../primitives/dnd/use-drag-cursor.ts | 24 +++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 packages/design-system/src/components/primitives/dnd/use-drag-cursor.ts diff --git a/apps/designer/app/designer/shared/tree/tree.tsx b/apps/designer/app/designer/shared/tree/tree.tsx index 722792c76c..427299ccaf 100644 --- a/apps/designer/app/designer/shared/tree/tree.tsx +++ b/apps/designer/app/designer/shared/tree/tree.tsx @@ -7,12 +7,13 @@ import { import { type DropTarget, type Rect, + type Placement, useDrag, useDrop, useHold, - Box, useAutoScroll, - Placement, + useDragCursor, + Box, } from "@webstudio-is/design-system"; import { findInstanceById, @@ -358,6 +359,8 @@ export const Tree = ({ const autoScrollHandlers = useAutoScroll(); + useDragCursor(dragItem !== undefined); + return ( { + useEffect(() => { + // possible + if (document.body === null) { + return; + } + + if (isDragging) { + const originalValue = document.body.style.getPropertyValue("cursor"); + const originalPriority = + document.body.style.getPropertyPriority("cursor"); + document.body.style.setProperty("cursor", cursor, "important"); + return () => { + document.body.style.setProperty( + "cursor", + originalValue, + originalPriority + ); + }; + } + }, [isDragging, cursor]); +};