Farmbot-Web-App/frontend/draggable/drop_area.tsx

44 lines
1.1 KiB
TypeScript
Raw Permalink Normal View History

2017-06-29 12:54:02 -06:00
import { DropAreaProps, DropAreaState } from "./interfaces";
import * as React from "react";
import { STEP_DATATRANSFER_IDENTIFER } from "./actions";
export class DropArea extends React.Component<DropAreaProps, DropAreaState> {
2017-07-06 16:58:44 -06:00
state: DropAreaState = { isHovered: false };
2017-06-29 12:54:02 -06:00
2017-08-02 11:59:16 -06:00
dragOver = (e: React.DragEvent<HTMLElement>) => {
e.preventDefault();
}
2017-07-06 16:58:44 -06:00
drop = (e: React.DragEvent<HTMLElement>) => {
e.preventDefault();
2017-08-28 05:49:13 -06:00
const key = e.dataTransfer.getData(STEP_DATATRANSFER_IDENTIFER);
const fn = this.props.callback;
if (fn) {
fn(key);
}
2017-06-29 12:54:02 -06:00
this.toggle();
}
2017-08-02 11:59:16 -06:00
toggle = () => {
this.setState({ isHovered: !this.state.isHovered });
};
2017-06-29 12:54:02 -06:00
render() {
2017-08-28 05:49:13 -06:00
const isVisible = this.props.isLocked || this.state.isHovered;
2019-04-09 19:45:59 -06:00
const visible = isVisible ? "visible" : "";
2017-07-06 16:58:44 -06:00
return <div
2019-04-09 19:45:59 -06:00
className={`drag-drop-area ${visible}`}
2017-07-06 16:58:44 -06:00
onDragLeave={this.toggle}
onDragEnter={(e) => {
e.preventDefault();
this.toggle();
}}
2017-07-19 10:41:26 -06:00
onDragOver={this.dragOver}
onDrop={this.drop}
2019-09-23 12:56:35 -06:00
style={{ minHeight: "2rem" }}>
2017-07-19 10:41:26 -06:00
{this.props.children}
2017-06-29 12:54:02 -06:00
</div>;
}
}