| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 1 | import { NodeType, useNodeMessages } from "@/lib/state"; |
| 2 | import { Icon } from "./icon"; |
| 3 | |
| 4 | export type Props = { |
| 5 | id: string; |
| 6 | selected?: boolean; |
| 7 | children: any; |
| 8 | type: NodeType; |
| 9 | }; |
| 10 | |
| 11 | export function NodeRect(p: Props) { |
| 12 | const { id, selected, children } = p; |
| 13 | const messages = useNodeMessages(id); |
| 14 | const hasFatal = messages.some((m) => m.type === "FATAL"); |
| 15 | const hasWarning = messages.some((m) => m.type === "WARNING"); |
| 16 | const classes = ["px-4", "py-2", "rounded-md", "bg-white"]; |
| 17 | if (hasFatal) { |
| 18 | classes.push("border-red-500"); |
| 19 | } else if (hasWarning) { |
| 20 | classes.push("border-yellow-500"); |
| 21 | } else { |
| 22 | classes.push("border-black"); |
| 23 | } |
| 24 | if (selected) { |
| 25 | classes.push("border-2"); |
| 26 | } else { |
| 27 | classes.push("border"); |
| 28 | } |
| 29 | return ( |
| 30 | <div className={classes.join(" ")}> |
| 31 | <div style={{ position: "absolute", top: "5px", left: "5px"}}> |
| 32 | {Icon(p.type)} |
| 33 | </div> |
| 34 | {children} |
| 35 | </div> |
| 36 | ) |
| 37 | |
| 38 | } |