2019-09-09 09:08:54 +00:00
|
|
|
import * as React from "react";
|
|
|
|
|
import { WidgetProps, WidgetState } from "../widgets/BaseWidget";
|
|
|
|
|
import { DragSource, DragSourceConnector, DragSourceMonitor } from "react-dnd";
|
|
|
|
|
import { ContainerProps } from "./ContainerComponent";
|
2019-04-02 16:12:08 +00:00
|
|
|
|
2019-08-29 11:22:09 +00:00
|
|
|
export interface DraggableProps extends ContainerProps {
|
|
|
|
|
connectDragSource: Function;
|
|
|
|
|
isDragging?: boolean;
|
2019-04-02 16:12:08 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-09 09:08:54 +00:00
|
|
|
class DraggableComponent extends React.Component<DraggableProps, WidgetState> {
|
2019-04-02 16:12:08 +00:00
|
|
|
render() {
|
|
|
|
|
return this.props.connectDragSource(
|
|
|
|
|
<div
|
|
|
|
|
style={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
flexDirection: "column",
|
|
|
|
|
left: this.props.style
|
|
|
|
|
? this.props.style.xPosition + this.props.style.xPositionUnit
|
|
|
|
|
: 0,
|
|
|
|
|
top: this.props.style
|
|
|
|
|
? this.props.style.yPosition + this.props.style.yPositionUnit
|
2019-09-09 09:08:54 +00:00
|
|
|
: 0,
|
2019-04-02 16:12:08 +00:00
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{this.props.children}
|
2019-09-09 09:08:54 +00:00
|
|
|
</div>,
|
|
|
|
|
);
|
2019-04-02 16:12:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const widgetSource = {
|
2019-09-09 09:08:54 +00:00
|
|
|
beginDrag(props: WidgetProps) {
|
2019-04-02 16:12:08 +00:00
|
|
|
return {
|
|
|
|
|
widgetId: props.widgetId,
|
2019-09-09 09:08:54 +00:00
|
|
|
widgetType: props.widgetType,
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
};
|
2019-04-02 16:12:08 +00:00
|
|
|
|
2019-09-09 09:08:54 +00:00
|
|
|
const widgetType = (props: WidgetProps) => {
|
|
|
|
|
return props.widgetType;
|
|
|
|
|
};
|
2019-04-02 16:12:08 +00:00
|
|
|
|
|
|
|
|
function collect(connect: DragSourceConnector, monitor: DragSourceMonitor) {
|
|
|
|
|
return {
|
|
|
|
|
connectDragSource: connect.dragSource(),
|
2019-09-09 09:08:54 +00:00
|
|
|
isDragging: monitor.isDragging(),
|
|
|
|
|
};
|
2019-04-02 16:12:08 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-09 09:08:54 +00:00
|
|
|
export default DragSource(widgetType, widgetSource, collect)(
|
|
|
|
|
DraggableComponent,
|
|
|
|
|
);
|