import {usePopup} from "../usePopup"; import {ListPanel} from "../ListPanel"; import {ListOption} from "../ListOption"; import {iMouseEvent} from "@peryl/react-compose"; import {getFunctionValue} from "@peryl/utils/getFunctionValue"; export const useContextmenuOptions = () => { const { $popup } = usePopup(); const open = ({ x, y ,options}: { x: number, y: number, options: iContextmenuOption[]}) => { const pop = $popup.absolute({ x, y, noArrow: true, noPadding: true, type: 'contextmenu-option', placement: 'bottom-start', trigger: 'contextmenu', render: () => ( {options.map((option, index) => ( { const flag = await option.handler(e); if (flag != false) {pop.hide();} }}> {getFunctionValue(option.label)} ))} ) }); }; return { open }; }; export interface iContextmenuOption { label: string | (() => any); handler: (e: iMouseEvent) => void | boolean | Promise, }