@apitable/react-contexify
v5.0.7
Published
Add contextmenu to your react component with ease
Downloads
377
Readme
@apitable/react-contexify
Installation
Using yarn
$ yarn add @apitable/react-contexify
Using npm
$ npm install --save @apitable/react-contexify
The gist
import React from 'react';
import { Menu, Item, Separator, Submenu, MenuProvider } from '@apitable/react-contexify';
import '@apitable/react-contexify/dist/ReactContexify.css';
const MENU_ID = 'blahblah';
function App() {
const { show } = useContextMenu({
id: MENU_ID,
});
function handleContextMenu(event){
event.preventDefault();
show({
event,
props: {
key: 'value'
}
})
}
const handleItemClick = ({ event, props }) => console.log(event,props);
return (
<div>
<p onContextMenu={handleContextMenu}>lorem ipsum blabladhasi blaghs blah</p>
<Menu id={MENU_ID}>
<Item onClick={handleItemClick}>Item 1</Item>
<Item onClick={handleItemClick}>Item 2</Item>
<Separator />
<Item disabled>Disabled</Item>
<Separator />
<Submenu label="Foobar">
<Item onClick={handleItemClick}>Sub Item 1</Item>
<Item onClick={handleItemClick}>Sub Item 2</Item>
</Submenu>
</Menu>
</div>
);
}
License
React Contexify is licensed under MIT.