Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save acro5piano/422e8eb7a41e2330a07492c1f6179dec to your computer and use it in GitHub Desktop.
Save acro5piano/422e8eb7a41e2330a07492c1f6179dec to your computer and use it in GitHub Desktop.
import { useState } from 'react'
export const Draggable: React.FC<{}> = ({ children }) => {
const [position, setPosition] = useState({ x: 0, y: 0 })
return (
<div
className="cursor-move"
draggable
style={{ transform: `translate(${position.x}px, ${position.y}px)` }}
onDrag={(e) => {
console.log(e)
setPosition({
x: position.x + e.nativeEvent.offsetX / 10,
y: position.y + e.nativeEvent.offsetY / 10,
})
}}
>
{children}
</div>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment