blob: 297f3661a55b9200f15a9e826d8b1e613b0fe25e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
import React, {useEffect} from "react";
import {ActiveDrag} from "./Body.tsx";
import CreateFolderIcon from "../assets/create_folder.svg?react"
function DropTarget(props: {children: React.ReactNode, className: string, onDrop: () => void}) {
let [drop, setDrop] = React.useState(false);
let [activeDrag, _] = React.useContext(ActiveDrag);
useEffect(() => {
setDrop(false);
}, [activeDrag]);
function handleDragOver(e: React.DragEvent<HTMLDivElement>) {
e.preventDefault()
setDrop(true)
}
function handleDragLeave(e: React.DragEvent<HTMLDivElement>) {
setDrop(false)
}
function handleDrop(e: React.DragEvent<HTMLDivElement>) {
e.preventDefault();
props.onDrop();
}
return (
<div className={props.className} style={drop ? undefined : {opacity: 0}}
onDragOver={handleDragOver} onDragLeave={handleDragLeave} onDrop={handleDrop}>
{props.children}
</div>
);
}
function DropTargets(props: { onDropLeft: () => void, onDropRight: () => void, onDropCenter: () => void }) {
return (
<div className={"drop-targets"}>
<DropTarget className={"left"} onDrop={props.onDropLeft}>
<div/>
</DropTarget>
<DropTarget className={"right"} onDrop={props.onDropRight}>
<div/>
</DropTarget>
<DropTarget className={"center"} onDrop={props.onDropCenter}>
<CreateFolderIcon/>
</DropTarget>
</div>
);
}
export default DropTargets;
|