Gem 一覧へ戻る
fkhadra/react-contexify(新しいタブで開きます)
主要言語: TypeScript
👌 Add a context menu to your react app with ease
- star 数
- 1,226
- watcher 数
- 7
- fork 数
- 133
- issue 数
- 49
- 最終更新
- 2024/11/25
主要言語: TypeScript
👌 Add a context menu to your react app with ease
Check the documentation for more!
Go here.
Using yarn
$ yarn add react-contexify
Using npm
$ npm install --save react-contexify
import { Menu, Item, Separator, Submenu, useContextMenu } from 'react-contexify'; import 'react-contexify/ReactContexify.css'; const MENU_ID = 'blahblah'; function App() { const { show } = useContextMenu({ id: MENU_ID, }); function handleContextMenu(event){ show({ event, props: { key: 'value' } }) } // I'm using a single event handler for all items // but you don't have too :) const handleItemClick = ({ id, event, props }) => { switch (id) { case "copy": console.log(event, props) break; case "cut"; console.log(event, props); break; //etc... } } return ( <div> <p onContextMenu={handleContextMenu}>lorem ipsum blabladhasi blaghs blah</p> <Menu id={MENU_ID}> <Item id="copy" onClick={handleItemClick}>Copy</Item> <Item id="cut" onClick={handleItemClick}>Cut</Item> <Separator /> <Item disabled>Disabled</Item> <Separator /> <Submenu label="Foobar"> <Item id="reload" onClick={handleItemClick}>Reload</Item> <Item id="something" onClick={handleItemClick}>Do something else</Item> </Submenu> </Menu> </div> ); }
Any idea and suggestions are welcome. Please have a look at the contributing guide.
React Contexify is licensed under MIT.