@supunlakmal/hooks
Version:
A collection of reusable React hooks
22 lines (21 loc) • 767 B
TypeScript
import { RefObject } from 'react';
interface ContextMenuState {
isOpen: boolean;
position: {
x: number;
y: number;
};
}
interface UseContextMenuResult extends ContextMenuState {
open: (event: MouseEvent) => void;
close: () => void;
}
/**
* Custom hook to manage the state for a custom context menu.
* Listens for contextmenu events on the target element and provides menu state (position, visibility).
*
* @param {RefObject<HTMLElement | null>} targetRef - Ref attached to the element that triggers the context menu.
* @returns {UseContextMenuResult} An object containing menu state and control functions.
*/
export declare const useContextMenu: (targetRef: RefObject<HTMLElement | null>) => UseContextMenuResult;
export {};