diff --git a/src/components/Sortable.js b/src/components/Sortable.js index b0a44b6..128a0e2 100644 --- a/src/components/Sortable.js +++ b/src/components/Sortable.js @@ -14,7 +14,7 @@ function Sortable({ id, children }) { const style = { cursor: "pointer", touchAction: "none", - opacity: isDragging ? 0.5 : undefined, + opacity: isDragging ? 0.25 : undefined, transform: transform && `translate3d(${transform.x}px, ${transform.y}px, 0px)`, zIndex: isDragging ? 100 : 0, diff --git a/src/components/map/MapTiles.js b/src/components/map/MapTiles.js index 1f6ebba..811467f 100644 --- a/src/components/map/MapTiles.js +++ b/src/components/map/MapTiles.js @@ -1,7 +1,8 @@ -import React from "react"; +import React, { useState } from "react"; +import { createPortal } from "react-dom"; import { Flex, Box, Text, IconButton, Close, Grid } from "theme-ui"; import SimpleBar from "simplebar-react"; -import { DndContext } from "@dnd-kit/core"; +import { DndContext, DragOverlay } from "@dnd-kit/core"; import { SortableContext, arrayMove } from "@dnd-kit/sortable"; import RemoveMapIcon from "../../icons/RemoveMapIcon"; @@ -35,6 +36,7 @@ function MapTiles({ }) { const { databaseStatus } = useDatabase(); const layout = useResponsiveLayout(); + const [dragId, setDragId] = useState(); let hasMapState = false; for (let state of selectedMapStates) { @@ -74,7 +76,12 @@ function MapTiles({ const multipleSelected = selectedMaps.length > 1; + function handleDragStart({ active }) { + setDragId(active.id); + } + function handleDragEnd({ active, over }) { + setDragId(); if (active && over && active.id !== over.id) { const oldIndex = groups.indexOf(active.id); const newIndex = groups.indexOf(over.id); @@ -83,7 +90,7 @@ function MapTiles({ } return ( - + )} + {createPortal( + + {dragId && mapToTile(maps.find((maps) => maps.id === dragId))} + , + document.body + )} ); diff --git a/src/components/token/TokenTiles.js b/src/components/token/TokenTiles.js index 5854517..a35ee87 100644 --- a/src/components/token/TokenTiles.js +++ b/src/components/token/TokenTiles.js @@ -1,7 +1,8 @@ -import React from "react"; +import React, { useState } from "react"; +import { createPortal } from "react-dom"; import { Flex, Box, Text, IconButton, Close, Grid } from "theme-ui"; import SimpleBar from "simplebar-react"; -import { DndContext } from "@dnd-kit/core"; +import { DndContext, DragOverlay } from "@dnd-kit/core"; import { SortableContext, arrayMove } from "@dnd-kit/sortable"; import RemoveTokenIcon from "../../icons/RemoveTokenIcon"; @@ -34,6 +35,7 @@ function TokenTiles({ }) { const { databaseStatus } = useDatabase(); const layout = useResponsiveLayout(); + const [dragId, setDragId] = useState(); let hasSelectedDefaultToken = selectedTokens.some( (token) => token.type === "default" @@ -77,7 +79,12 @@ function TokenTiles({ } } + function handleDragStart({ active }) { + setDragId(active.id); + } + function handleDragEnd({ active, over }) { + setDragId(); if (active && over && active.id !== over.id) { const oldIndex = groups.indexOf(active.id); const newIndex = groups.indexOf(over.id); @@ -86,7 +93,7 @@ function TokenTiles({ } return ( - + )} + {createPortal( + + {dragId && tokenToTile(tokens.find((token) => token.id === dragId))} + , + document.body + )} );