23 lines
522 B
JavaScript
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>
|
|
)}
|
|
</>
|
|
)
|
|
}
|