PromucFlow_constructor/app/client/src/editorComponents/DraggableComponent.tsx

55 lines
1.4 KiB
TypeScript
Raw Normal View History

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-08-29 11:22:09 +00:00
export interface DraggableProps extends ContainerProps {
connectDragSource: Function;
isDragging?: boolean;
}
2019-09-09 09:08:54 +00:00
class DraggableComponent extends React.Component<DraggableProps, WidgetState> {
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,
}}
>
{this.props.children}
2019-09-09 09:08:54 +00:00
</div>,
);
}
}
const widgetSource = {
2019-09-09 09:08:54 +00:00
beginDrag(props: WidgetProps) {
return {
widgetId: props.widgetId,
2019-09-09 09:08:54 +00:00
widgetType: props.widgetType,
};
},
};
2019-09-09 09:08:54 +00:00
const widgetType = (props: WidgetProps) => {
return props.widgetType;
};
function collect(connect: DragSourceConnector, monitor: DragSourceMonitor) {
return {
connectDragSource: connect.dragSource(),
2019-09-09 09:08:54 +00:00
isDragging: monitor.isDragging(),
};
}
2019-09-09 09:08:54 +00:00
export default DragSource(widgetType, widgetSource, collect)(
DraggableComponent,
);