JSPM

usecontextmenu-react

1.0.3
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q15098F
  • License MIT

Contextmenu hook in React

Package Exports

  • usecontextmenu-react

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (usecontextmenu-react) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

usecontextmenu-react

Contextmenu hook in React

NPM Package

Install

Using npm

npm install --save usecontextmenu-react

Usage

import {ContextMenu, ContextMenuItem, useContextMenu} from 'usecontextmenu-react';

Example

See example folder

import React, {useRef} from "react";
import {ContextMenu, ContextMenuItem, useContextMenu} from 'usecontextmenu-react';

const Example = () => {
    const {menuProps, onContextMenu, visibleOnPosition} = useContextMenu();

    const blockStyle = {
        height: '200px',
        backgroundColor: 'tomato',
    }
    
    return (
        <div>
            <div onContextMenu={onContextMenu} style={blockStyle}/>

            <ContextMenu {...menuProps}>
                <ContextMenuItem>Lorem ipsum dolor</ContextMenuItem>
                <ContextMenuItem disabled>Disabled</ContextMenuItem>
                <ContextMenuItem onClick={() => console.log('Click!')}>onClick</ContextMenuItem>
                <ContextMenuItem>Lorem ipsum dolor sit</ContextMenuItem>
            </ContextMenu>
        </div>
    );
}

API

useContextMenu({onShow, onHide})

onShow: () => void - Called when the menu is visible

onHide: () => void - Called when the menu is hidden

This hook returns an object containing the following properties:

onContextMenu - The event that triggered the context menu

menuProps - Context menu props

visibleOnPosition({x: number, y: number}) - Display the context menu on custom position. You can provide x and y coordinates

License

MIT © n0mver