New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

vanilla-context-menu-point

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vanilla-context-menu-point

Easily create context menus using vanilla JavaScript and integrate them in any web application

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
378
decreased by-20.08%
Maintainers
1
Weekly downloads
 
Created
Source

Vanilla Context Menu

issues forks stars license version

vanilla-context-menu - easily create context-menus using Vanilla JavaScript and integrate them in any web application

Installation

Browser CDN

<script src="https://unpkg.com/vanilla-context-menu@1.0.0/dist/vanilla-context-menu.js"></script>

Where @1.0.0 is the version that you want to use.

Then anywhere in your JavaScript code you can access the library with window.VanillaContextMenu or simply VanillaContextMenu.

Via NPM

npm i vanilla-context-menu

Then anywhere in your code.

import VanillaContextMenu from 'vanilla-context-menu';

How to use it

new VanillaContextMenu({
  scope: document.querySelector('main'),
  menuItems: [
    {
      label: 'Copy',
      callback: () => {
        // ? your code here
      },
    },
    'hr',
    {
      label: 'Paste',
      callback: pasteFunction,
    },
  ],
});

Configuration options

VanillaContextMenu(configurableOptions: ConfigurableOptions):VanillaContextMenu

ConfigurableOptions

OptionRequiredTypeDefaultDescription
scopeyesHTMLElementundefinedThe HTML element on which you want to bind the contextmenu event listener.
menuItemsyesMenuItem[]undefinedMenu items to be built.
customClassnostringundefinedA custom CSS class that can be added to the context menu
customThemeClassnostringundefinedA custom CSS class that can be added to the context menu theme. A value for this property will exclude the theme option.
preventCloseOnClicknobooleanfalseIf this variable is true, then the context menu will not close when its elements are clicked.
transitionDurationnonumber200Duration of the context menu transition. Set this value to 0 if you want to disable the animation.
themeno'black' | 'white'blackBy default, the library provides two themes for the context menu: black and white. You can use this option to choose the one you want to use.

MenuItem

type MenuItem = MenuOption | 'hr';

MenuOption

OptionRequiredTypeDefaultDescription
labelyesstringundefinedMenu option label.
callbackyes() => anyundefinedCallback to be executed.
preventCloseOnClicknobooleanfalseIf this variable is true, then the context menu will not close when this menu option is clicked. A value set for this option, either true or false will override the global one.

API (2)

The following methods and properties are available through the class instance.

const myContextMenu = new VanillaContextMenu(...)

(1)

off(): void

This method will remove all event listeners that have been registered for the context-menu.

! It should be called when you want to deactivate the context menu or when the container item has been removed from the DOM.

(2)

updateOptions(configurableOptions: Partial<ConfigurableOptions>): void

Examples

Define your own theme

.context-menu-orange-theme {
  background: #d35400;

  hr {
    background-color: #eee;
  }

  // ? text color for each item
  & > *:not(hr) {
    color: #eee;

    &:hover {
      background: #e67e22;
    }
  }
}

Define your own CSS class for styling

.custom-context-menu-cls {
  width: 150px;
  font-family: 'Roboto', sans-serif; /* DEFAULT -- font-family: 'Open Sans', sans-serif; */
}
const myContextMenu = new window.VanillaContextMenu({
  scope: ...,
  menuItems: [...],
  customThemeClass: 'context-menu-orange-theme',
  customClass: 'custom-context-menu-cls',
});

You can check the demo file for more examples from demo/index.html.

Contributing

Pull requests and stars are always welcome. Please check the guidelines.

Stay in touch

Discussions page

License

This project is licensed under the MIT License

Keywords

FAQs

Package last updated on 21 Dec 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc