Nfinished / react-tiny-contextmenu

A super tiny, fully typed, zero dependency context menu.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

react-tiny-contextmenu

A super tiny, fully typed, zero dependency context menu.

npm version npm license npm bundle size Code Climate coverage

usage gif

API:

target : React.refObject<HtmlElement>
A React ref to attach the context menu to.


items : React.ComponentWithoutRef<'span'>[]
A list of objects representing the context menu's options. Accepts all props that a span would.


children : React.ReactNode
Instead of passing in a list of items, roll your own content. Takes priority over items.


className : string
ClassNames to be applied to the context menu's container element.


itemClassName : string
ClassNames to be applied to each item element. Applied before any classNames provided per-item.


Usage:

import { ContextMenu } from 'react-tiny-contextmenu'

const contextMenuContainerRef = React.useRef(null)
const items = [
  {
    children: 'One Button',
  },
  {
    children: (
      <div>
        <button>two</button>
        <button>button</button>
      </div>
    ),
  },
  {
    children: 'Red Button',
    className: 'red-button'
  },
  {
    children: 'Blue Button',
    style: { background: 'blue' }
  },
]

...

<span ref={contextMenuContainerRef}>right click me!</span>
<ContextMenu target={contextMenuContainerRef} items={items} />

About

A super tiny, fully typed, zero dependency context menu.

License:MIT License


Languages

Language:TypeScript 81.7%Language:JavaScript 8.6%Language:CSS 5.2%Language:HTML 4.5%