# react-contexify

> Add contextmenu to your react component with ease

Latest version **6.0.0** (published 2022-11-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-contexify
pnpm add react-contexify
yarn add react-contexify
bun add react-contexify
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 6.0.0 |
| Published | 2022-11-13 |
| First published | 2016-06-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 146.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1224 |
| Author | Fadi Khadra |
| Maintainers | sniphpet |
| Keywords | react, context menu, react-component, menu, react-contextmenu, react-contexify, popup |

## Links

- npm: https://www.npmjs.com/package/react-contexify
- Repository: https://github.com/fkhadra/react-contexify
- Homepage: https://github.com/fkhadra/react-contexify#readme
- Issues: https://github.com/fkhadra/react-contexify/issues
- npm.io page: https://npm.io/package/react-contexify

## Dependencies (1)

- [clsx](https://npm.io/package/clsx.md) ^1.2.1

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 6.0.0 (latest) — 2022-11-13
- 6.0.0-rc.3 (next) — 2022-11-13
- 6.0.0-doc-1 (doc-build-1) — 2022-11-12
- 5.0.1-1 (@alpha-1) — 2022-11-11
- 5.0.0-beta.12 (beta) — 2020-11-15
- 6.0.0-rc.2 — 2022-11-13
- 6.0.0-rc.1 — 2022-11-13
- 5.0.0 — 2020-11-30
- 5.0.0-beta.11 — 2020-11-15
- 5.0.0-beta.10 — 2020-11-13
- 5.0.0-beta.9 — 2020-11-13
- 5.0.0-beta.8 — 2020-11-13
- 5.0.0-beta.7 — 2020-11-13
- 5.0.0-beta.6 — 2020-11-13
- 5.0.0-beta.5 — 2020-11-11
- … 37 more at https://npm.io/package/react-contexify/versions

## README

<img width="645" alt="screenshot 2018-10-31 at 13 32 57" src="https://user-images.githubusercontent.com/5574267/47815610-1806fa00-dd51-11e8-981b-2f680244ae29.png">

![React-contexify CI](https://github.com/fkhadra/react-contexify/workflows/React-contexify%20CI/badge.svg) [![npm](https://img.shields.io/npm/dm/react-contexify.svg)]() [![npm](https://img.shields.io/npm/v/react-contexify.svg)]() [![license](https://img.shields.io/github/license/fkhadra/react-contexify.svg?maxAge=2592000)]()

<div style="text-align:center">

![contexify](https://user-images.githubusercontent.com/5574267/100552409-500dfd80-3287-11eb-96ee-fc1d17ef50b8.gif)

</div>

## Features

- Easy to set up for real, you can make it work in less than 10sec!
- Super easy to customize thanks to css variables 💅
- Custom position
- Sub menu support
- Does not go offscreen
- Dark mode 🌒
- Keyboard navigation + keyboard shortcut!
- Built-in animations
- Easy to test!
- Written in Typescript 💪
- Tiny! (3k gzipped)

Check the documentation for more!


## Documentation

Go [here](https://fkhadra.github.io/react-contexify). 

## Installation

Using yarn

```sh
$ yarn add react-contexify
```

Using npm

```sh
$ npm install --save react-contexify
```

## The gist

```js
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>
  );
}
```

## Contribute

Any idea and suggestions are welcome. Please have a look at the contributing guide.

## License

React Contexify is licensed under MIT.

---
_Source: https://npm.io/package/react-contexify · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
