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) => {
|
|
|
|
|
const [{ isDragging }, drag, preview] = useDrag({
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
// class DraggableComponent extends React.Component<DraggableProps, WidgetState> {
|
|
|
|
|
// render() {
|
|
|
|
|
// return props.connectDragSource(
|
|
|
|
|
// ,
|
|
|
|
|
// );
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// const widgetSource = {
|
|
|
|
|
// beginDrag(props: WidgetProps) {
|
|
|
|
|
// return {
|
|
|
|
|
// widgetId: props.widgetId,
|
|
|
|
|
// widgetType: props.type,
|
|
|
|
|
// };
|
|
|
|
|
// },
|
|
|
|
|
// };
|
|
|
|
|
|
2019-09-09 09:08:54 +00:00
|
|
|
const widgetType = (props: WidgetProps) => {
|
2019-09-17 10:09:00 +00:00
|
|
|
return props.type;
|
2019-09-09 09:08:54 +00:00
|
|
|
};
|
2019-04-02 16:12:08 +00:00
|
|
|
|
2019-09-17 10:09:00 +00:00
|
|
|
// function collect(connect: DragSourceConnector, monitor: DragSourceMonitor) {
|
|
|
|
|
// return {
|
|
|
|
|
// connectDragSource: connect.dragSource(),
|
|
|
|
|
// isDragging: monitor.isDragging(),
|
|
|
|
|
// };
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// export default DragSource(widgetType, widgetSource, collect)(
|
|
|
|
|
// DraggableComponent,
|
|
|
|
|
// );
|
2019-04-02 16:12:08 +00:00
|
|
|
|
2019-09-17 10:09:00 +00:00
|
|
|
export default DraggableComponent;
|