2024-10-02 11:34:47 +09:00

23 lines
522 B
JavaScript

'use client'
import { useState } from 'react'
import Draggable from 'react-draggable'
export default function WithDraggable({ isShow, children }) {
const [position, setPosition] = useState({ x: 0, y: 0 })
const handleOnDrag = (data) => {
setPosition({ x: data.x, y: data.y })
}
return (
<>
{isShow && (
<Draggable position={{ x: position.x, y: position.y }} onDrag={(_, data) => handleOnDrag(data)} handle=".modal-header">
{children}
</Draggable>
)}
</>
)
}