mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-11-09 14:03:33 +09:00
cursor=grabbing while dragging
This commit is contained in:
1 parent
cce2b23f59
commit
a2cd70d7ca
3 files changed
+30
-2
No files matched your search
@@ -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 (
|
||||
<Box
|
||||
css={{
|
||||
|
||||
@@ -3,4 +3,5 @@ export * from "./use-drop";
|
||||
export * from "./use-auto-scroll";
|
||||
export * from "./placement-indicator";
|
||||
export * from "./use-hold";
|
||||
export * from "./use-drag-cursor";
|
||||
export { type Rect, type Point, type Placement } from "./geometry-utils";
|
||||
@@ -0,0 +1,24 @@
|
||||
import { useEffect } from "react";
|
||||
|
||||
export const useDragCursor = (isDragging: boolean, cursor = "grabbing") => {
|
||||
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]);
|
||||
};
|
||||
Reference in new issue
Block a user