summaryrefslogtreecommitdiff
path: root/src/AddNodeMenu.tsx
diff options
context:
space:
mode:
authorSam Nystrom <sam@samnystrom.dev>2024-03-06 20:52:45 +0000
committerSam Nystrom <15555332-SamNystrom1@users.noreply.replit.com>2024-03-06 20:52:45 +0000
commitac83dd4a08bdbab6df270d6dae8d9e2d6d619342 (patch)
treed928f552d7fb89a96b757b00899d4dbc0639cacd /src/AddNodeMenu.tsx
init
Diffstat (limited to 'src/AddNodeMenu.tsx')
-rw-r--r--src/AddNodeMenu.tsx21
1 files changed, 21 insertions, 0 deletions
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