24 lines
567 B
TypeScript
24 lines
567 B
TypeScript
import React from "react";
|
|
import { useDraggable, UseDraggableArguments } from "@dnd-kit/core";
|
|
|
|
const Draggable = (props: any) => {
|
|
const { attributes, listeners, setNodeRef, transform } = useDraggable({
|
|
id: `draggable-${props.data.type}`,
|
|
data: props.data,
|
|
});
|
|
|
|
const style = transform
|
|
? {
|
|
transform: `translate3d(${transform.x}px, ${transform.y}px, 0)`,
|
|
}
|
|
: undefined;
|
|
|
|
return (
|
|
<button ref={setNodeRef} style={style} {...listeners} {...attributes}>
|
|
{props.children}
|
|
</button>
|
|
);
|
|
};
|
|
|
|
export default Draggable;
|