# contextmenu

> ContextMenu is a context menu build on React (16.8+) hooks. ContextMenu provides a quick and easy way to create instant context menus without having to build jsx. This component supports submenus, custom component menu items, and edge detection.

Latest version **1.0.2** (published 2019-04-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install contextmenu
pnpm add contextmenu
yarn add contextmenu
bun add contextmenu
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2019-04-16 |
| First published | 2017-02-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 24.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | tetranoir |
| Keywords | react, js, context, menu, hooks |

## Links

- npm: https://www.npmjs.com/package/contextmenu
- Repository: https://github.com/tetranoir/contextmenu
- Homepage: https://github.com/tetranoir/contextmenu#readme
- Issues: https://github.com/tetranoir/contextmenu/issues
- npm.io page: https://npm.io/package/contextmenu

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.2 (latest) — 2019-04-16
- 1.0.1 — 2019-04-16
- 1.0.0 — 2019-04-16
- 0.1.2 — 2017-02-13
- 0.1.1 — 2017-02-13
- 0.0.6 — 2017-02-13
- 0.0.5 — 2017-02-12
- 0.0.4 — 2017-02-12
- 0.0.3 — 2017-02-12
- 0.0.1 — 2017-02-12

## README

# ContextMenu
ContextMenu is a context menu build on React (16.8+) hooks. ContextMenu provides a quick and easy way to create instant context menus without having to build jsx. This component supports submenus, custom component menu items, and edge detection.

## Installation
Using npm:
```shell
$ npm i contextmenu
```

## How To Use
Import:
```jsx
import useContextMenu from 'contextmenu';
import 'contextmenu/ContextMenu.css';
```

Build out your menu:
```jsx
const menuConfig = {
  'Say open': () => console.log('open'),
  'Disabled': null,
  'JSX line': <hr></hr>,
  'JSX': <div style={{height: 40, border: '1px solid green'}}>yes</div>,
  'Line': '---',
  'Submenu': {
    'Say wololol': () => console.log('wololol'),
    'Go deeper': {
      'Onceptioniningiong': () => console.log('inceptioniningiong'),
    },
    'Submenu 2': {
      'electric': console.log,
      'boogaloo': () => console.log('boogaloo'), 
    },
  },
};
```

Render your menu in your component:
```jsx
  const [contextMenu, useCM] = useContextMenu({ submenuSymbol: 'O' });
  return <div onContextMenu={useCM(menuConfig)}>{...}{contextMenu}</div>
```

## API
ContextMenu is built off hooks, which means you must render it within React functional components.

### useContextMenu(props)
 - `props` is optional
 - `props` shape:
```
{
  submenuSymbol: jsx; // which means jsx component or string or null
  depth: number;
  // more to be added later
}
```

### contextMenu
 - Returned from `useContextmenu()` which contains the `React.portal` to be rendered (onto `document.body`)
 - Must be in your render function, anywhere.

### useCM(menuConfig)
 - `menuConfig` is a **JSON** that determines what the rendered context menu looks like.
 - menuConfig shape:
```
{
  [menu option name] :
    | [option callback]
    | [menuConfig]
    | [jsx]
    | "-----"
    | null
}
```
 - **[menu option name]** is used in conjection with **[option callback]** to create an option that does something
 - **[menu option name]** is used in conjection with another `menuConfig` to create a submenu
 - **[menu option name]** is used with `null` when the item is disabled
 - **[jsx]** shows custom renderings inside menu options (**[menu option name]** is unused here)
 - **"---"** is a shortcut to display a separation line between menu items (**[menu option name]** is unused)

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