drawDB/src/components/rect.jsx

122 lines
3.1 KiB
React
Raw Normal View History

2023-09-19 20:47:11 +08:00
import { React, useState } from "react";
import Node from "./node";
2023-09-19 20:47:10 +08:00
import { Button } from "@arco-design/web-react";
2023-09-19 20:47:06 +08:00
const Rect = (props) => {
2023-09-19 20:47:11 +08:00
const [isHovered, setIsHovered] = useState(false);
const [node, setNode] = useState(Node.NONE);
2023-09-19 20:47:06 +08:00
return (
<g>
2023-09-19 20:47:10 +08:00
<foreignObject
2023-09-19 20:47:06 +08:00
key={props.id}
x={props.x}
y={props.y}
width={props.width}
height={props.height}
2023-09-19 20:47:11 +08:00
style={{ cursor: "move" }}
2023-09-19 20:47:06 +08:00
onMouseDown={props.onMouseDown}
2023-09-19 20:47:11 +08:00
onMouseEnter={() => {
setIsHovered(true);
2023-09-19 20:47:13 +08:00
props.setOnRect(true);
2023-09-19 20:47:11 +08:00
}}
onMouseLeave={() => {
setIsHovered(false);
2023-09-19 20:47:13 +08:00
props.setOnRect(false);
2023-09-19 20:47:11 +08:00
}}
2023-09-19 20:47:10 +08:00
>
2023-09-19 20:47:11 +08:00
<div
xmlns="http://www.w3.org/1999/xhtml"
className={`${isHovered ? "bg-red-500" : "bg-blue"} p-3`}
>
2023-09-19 20:47:10 +08:00
<div className="text-white">{props.label}</div>
2023-09-19 20:47:08 +08:00
<form onSubmit={(e) => e.preventDefault()}>
<input type="text" className="w-full" />
</form>
2023-09-19 20:47:10 +08:00
<Button type="secondary" onClick={(e) => console.log("sup")}>
sup
</Button>
</div>
2023-09-19 20:47:08 +08:00
</foreignObject>
2023-09-19 20:47:11 +08:00
<circle
id="TOP"
cx={props.x + props.width / 2}
cy={props.y}
r={5}
onClick={(e) => {
setNode(Node.TOP);
props.setLinks([
...props.links,
{
rect: props.id,
node: Node.TOP,
x: props.x + props.width / 2,
y: props.y,
},
]);
}}
style={{ fill: node === Node.TOP ? "green" : "black" }}
/>
<circle
id="LEFT"
cx={props.x}
cy={props.y + props.height / 2}
r={5}
onClick={(e) => {
setNode(Node.LEFT);
props.setLinks([
...props.links,
{
2023-09-19 20:47:11 +08:00
rect: props.id,
2023-09-19 20:47:11 +08:00
node: Node.LEFT,
x: props.x,
y: props.y + props.height / 2,
},
]);
}}
style={{ fill: node === Node.LEFT ? "green" : "black" }}
/>
<circle
id="RIGHT"
cx={props.x + props.width}
cy={props.y + props.height / 2}
r={5}
onClick={(e) => {
setNode(Node.RIGHT);
props.setLinks([
...props.links,
{
rect: props.id,
node: Node.RIGHT,
x: props.x + props.width,
y: props.y + props.height / 2,
},
]);
}}
style={{ fill: node === Node.RIGHT ? "green" : "black" }}
/>
<circle
id="BOTTOM"
cx={props.x + props.width / 2}
cy={props.y + props.height}
r={5}
onClick={(e) => {
setNode(Node.BOTTOM);
props.setLinks([
...props.links,
{
rect: props.id,
node: Node.BOTTOM,
x: props.x + props.width / 2,
y: props.y + props.height,
},
]);
}}
style={{ fill: node === Node.BOTTOM ? "green" : "black" }}
/>
2023-09-19 20:47:06 +08:00
</g>
);
};
export default Rect;