Files
PyUIBuilder/src/components/utils/draggable.js

27 lines
693 B
JavaScript
Raw Normal View History

2024-08-04 22:47:43 +05:30
import React from "react"
import {useDraggable} from "@dnd-kit/core"
2024-09-11 19:06:04 +05:30
import { CSS } from "@dnd-kit/utilities"
2024-08-04 22:47:43 +05:30
function Draggable(props) {
const {attributes, listeners, setNodeRef, transform} = useDraggable({
2024-09-11 19:06:04 +05:30
id: props.id,
data: {title: props.children}
2024-08-04 22:47:43 +05:30
})
const style = transform ? {
2024-09-11 19:06:04 +05:30
transform: CSS.Translate.toString(transform),
2024-08-04 22:47:43 +05:30
} : undefined
return (
2024-09-11 19:06:04 +05:30
<button className={`tw-bg-transparent tw-outline-none tw-border-none ${props.className}`}
ref={setNodeRef}
style={style}
{...listeners}
{...attributes}>
2024-08-04 22:47:43 +05:30
{props.children}
</button>
)
}
export default Draggable