import type { JSX } from "solid-js"; import { splitProps } from "solid-js"; import { useNavigationMenuContext, useNavigationMenuItemContext } from "./navigation-menu-context"; import type { NavigationMenuTriggerProps } from "./navigation-menu.props"; /** * Button that opens the associated NavigationMenu.Content on click or hover. * Manages hover-intent via the root context's scheduleOpen/cancelAndClose. */ export function NavigationMenuTrigger(props: NavigationMenuTriggerProps): JSX.Element { const [local, rest] = splitProps(props, [ "children", "onClick", "onPointerEnter", "onPointerLeave", ]); const ctx = useNavigationMenuContext(); const itemCtx = useNavigationMenuItemContext(); const handleClick: JSX.EventHandler = (e) => { if (typeof local.onClick === "function") local.onClick(e); const next = ctx.value() === itemCtx.value ? "" : itemCtx.value; ctx.setValue(next); }; const handlePointerEnter: JSX.EventHandler = (e) => { if (typeof local.onPointerEnter === "function") local.onPointerEnter(e); ctx.scheduleOpen(itemCtx.value); }; const handlePointerLeave: JSX.EventHandler = (e) => { if (typeof local.onPointerLeave === "function") local.onPointerLeave(e); ctx.cancelAndClose(); }; return ( ); }