2019-09-09 09:08:54 +00:00
|
|
|
import * as React from "react";
|
2019-09-17 10:09:00 +00:00
|
|
|
import { WidgetProps } from "../widgets/BaseWidget";
|
|
|
|
|
import { useDrag, DragPreviewImage, DragSourceMonitor } from "react-dnd";
|
|
|
|
|
import blankImage from "../assets/images/blank.png";
|
2019-09-09 09:08:54 +00:00
|
|
|
import { ContainerProps } from "./ContainerComponent";
|
2019-04-02 16:12:08 +00:00
|
|
|
|
2019-09-17 10:09:00 +00:00
|
|
|
type DraggableComponentProps = WidgetProps & ContainerProps;
|
2019-04-02 16:12:08 +00:00
|
|
|
|
2019-09-17 10:09:00 +00:00
|
|
|
const DraggableComponent = (props: DraggableComponentProps) => {
|
2019-09-17 15:09:55 +00:00
|
|
|
const [, drag, preview] = useDrag({
|
2019-09-17 10:09:00 +00:00
|
|
|
item: props,
|
|
|
|
|
collect: (monitor: DragSourceMonitor) => ({
|
|
|
|
|
isDragging: monitor.isDragging(),
|
|
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
return (
|
|
|
|
|
<React.Fragment>
|
|
|
|
|
<DragPreviewImage connect={preview} src={blankImage} />
|
2019-04-02 16:12:08 +00:00
|
|
|
<div
|
2019-09-17 15:09:55 +00:00
|
|
|
ref={drag}
|
2019-04-02 16:12:08 +00:00
|
|
|
style={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
flexDirection: "column",
|
2019-09-17 10:09:00 +00:00
|
|
|
left: props.style
|
|
|
|
|
? props.style.xPosition + props.style.xPositionUnit
|
2019-04-02 16:12:08 +00:00
|
|
|
: 0,
|
2019-09-17 10:09:00 +00:00
|
|
|
top: props.style
|
|
|
|
|
? props.style.yPosition + props.style.yPositionUnit
|
2019-09-09 09:08:54 +00:00
|
|
|
: 0,
|
2019-04-02 16:12:08 +00:00
|
|
|
}}
|
|
|
|
|
>
|
2019-09-17 10:09:00 +00:00
|
|
|
{props.children}
|
|
|
|
|
</div>
|
|
|
|
|
</React.Fragment>
|
|
|
|
|
);
|
2019-09-09 09:08:54 +00:00
|
|
|
};
|
2019-04-02 16:12:08 +00:00
|
|
|
|
2019-09-17 10:09:00 +00:00
|
|
|
export default DraggableComponent;
|