From ac83dd4a08bdbab6df270d6dae8d9e2d6d619342 Mon Sep 17 00:00:00 2001
From: Sam Nystrom <sam@samnystrom.dev>
Date: Wed, 6 Mar 2024 20:52:45 +0000
Subject: init

---
 src/AddNodeMenu.tsx | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
 create mode 100644 src/AddNodeMenu.tsx

(limited to 'src/AddNodeMenu.tsx')

diff --git a/src/AddNodeMenu.tsx b/src/AddNodeMenu.tsx
new file mode 100644
index 0000000..197f56d
--- /dev/null
+++ b/src/AddNodeMenu.tsx
@@ -0,0 +1,21 @@
+import { useId } from 'preact/hooks';
+import { NodeInfo } from './node.tsx';
+
+export interface AddNodeMenuProps {
+	nodes: Record<string, NodeInfo>;
+	onClick?: (NodeInfo) => void;
+}
+
+export const AddNodeMenu = ({ nodes, onClick = _ => {} }: AddNodeMenuProps) => {
+	const id = useId();
+	return (
+		<>
+			<menu id={id} popover>
+				{Object.entries(nodes).map(([name, node]) => (
+					<li><button onClick={() => onClick(node)}>{name}</button></li>
+				))}
+			</menu>
+			<button popoverTarget={id}>Add</button>
+		</>
+	);
+};
\ No newline at end of file
-- 
cgit v1.2.3

