1.2.0 • Published 5 years ago

@langleyfoxall/react-dynamic-context-menu v1.2.0

Weekly downloads
1
License
LGPL-3.0
Repository
github
Last release
5 years ago

React Dynamic Context Menu

React Dynamic Context menu provides an easy way to add right click functionality to React components.

Props

NameTypeUsage
menuItemsArray of ObjectsThe items that appear on the menu when the context menu is shown
dataObjectThe data passed in as the first argument to the onClick function.
ignoreClickEvents (optional)Single or Array of refsRefs of elements that won't close the menu when clicked.

Basic usage

To use the DynamicContextMenu wrap the element you want to be clickable.

const menu = [
	{
		label: 'Save'
		onClick: this.handleSave
	},
	{
		label: 'Delete'
		onClick: this.handleDelete
		className: 'danger'
	}
]

...

<DynamicContextMenu
	menuItems={menu}
	data={rowData}
>
	<p>Right click this row!</p>
</DynamicContextMenu>

Data

Whatever is passed into as the data prop will be used as the first argument when the onClick function is called.

Menu Items

[
	{
		label: 'Save'
		onClick: this.handleSave
	},
	{
		label: 'Delete'
		onClick: this.handleDelete
		className: 'danger'
	}
]

As you can see menu items can have 3 properties. They are:

NameDescription
LabelThe text are appears on the menu item
onClickThe callback that is called when the menu item is clicked. The first argument of the method is the data passed in to the data on the DynamicContextMenu.
className (optional)The class name of the menu item div.
onContextMenu (optional)A valid function ran after the menu has opened.