Giter Site home page Giter Site logo

react-procedural-context-menu's Introduction

React Procedural Context Menu

demo

codesandbox

ctxmenudemo

Install the package:

npm i react-context-menu

Or

yarn add react-context-menu

How to use, the easy way:

Step 1: Making a Menu

  • A menu is an array of small menu entries.

  • A menu entry looks like this, { text: "Label for the entry" }

  • You can choose to do something, when it's clicked { text: "Label1", onClick: () => console.log('Label1 was Clicked') }

  • Like this you can make a simple menu, [ { text: "Label1", onClick: () => console.log('Label1 was Clicked') }, { text: "Label2", onClick: () => console.log('Label2 was Clicked') } ]

  • A menu item can also have it's own submenu, { text: "Label for the entry", sub: [...another menu...] }

  • Instead of plaintext you can also use a react component { component: <>Github <img src="https://github.com/Heaust-ops" /></> }

Step 2: Using the premade wrapper

  • Import the wrapper div, this defines the region for context menu action import ContextMenuWrapperDiv from "./ContextMenu/ContextMenuWrapperDiv";

  • Make a menu collection, menuCollection = { hotkeys: { shifta: someMenu }, contextMenu: someOtherMenu }

  • Use the wrapper div and pass it the menu collection <ContextMenuWrapperDiv menus={menuCollection}> {...content...} </ContextMenuWrapperDiv>

  • It behaves like a normal div and you can use all of a normal div's props

  • Moreover it takes in 2 additional props, itemStyle and wrapperStyle

  • itemStyle can be used to style the items in the context menu

  • wrapperStyle can be used to style the wrapper of the context menu itself

How to use, for powerusers:

  • Import the ContextMenu Component import { ContextMenu } from "react-procedural-context-menu";

  • Unlike the wrapper div this takes in a single menu, <ContextMenu contextMenuItems={someMenu} >

  • This component is just the menu with no activation logic

  • You have to implement the logic of when and where to render it yourself

  • It still has itemStyle and wrapperStyle for the same reasons

  • Tip: You can use wrapperStyle to position it

react-procedural-context-menu's People

Contributors

heaust-ops avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.