import { observer } from 'mobx-react-lite'; import { useEffect, useRef } from 'react'; import { state } from '../state'; import './MenuView.scss'; import type { MenuNode } from '../state/menuState'; export const MenuNodeView = observer(function ({ node }: { node: MenuNode }) { const forceOpen = state.menu.nodeContainsSelected(node); const ref = useRef(null); useEffect(() => { if (forceOpen && ref.current) ref.current.open = true; }, [forceOpen]); const classNames = []; if (node.selected?.()) classNames.push('selected'); if (node.className !== undefined) classNames.push(node.className); return (
node.onClick?.()} >
{node.title}
{node.actions &&
{node.actions.map((action) =>
{ e.stopPropagation(); e.preventDefault(); action.onClick(); }} > {action.content}
)}
}
{node.children?.map((child) => )}
); }); export const MenuView = observer(function () { return ( ); });