diff options
Diffstat (limited to 'src/AddNodeMenu.tsx')
| -rw-r--r-- | src/AddNodeMenu.tsx | 21 |
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 |
