npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ember-context-menu

v0.5.2

Published

Ember addon for right-click-menu

Downloads

330

Readme

ember-context-menu

npm version Build Status Ember Observer Score Code Climate

An ember-cli addon to add any right-click-menu to your components. Try it here

Compatibility

  • Ember.js v3.8 or above
  • Ember CLI v2.13 or above
  • Node.js v8 or above

Installation

In your application's directory:

$ ember install ember-context-menu

In your application.hbs add the following:

{{context-menu}}

WARNING: You need to add this to make the context-menu work, and should add it just once in your application.

Usage

Using the mixin

This mixin is designed to add a context-menu to any component. Add it to your component like this:

import Component from '@ember/component';
import contextMenuMixin from 'ember-context-menu';

export default Component.extend(contextMenuMixin, {
  // your component properties
  
  _contextMenu(e) {
    // do anything before triggering the context-menu
  }
});

Context items

Your component needs at least an array of contextItems, which should have a label and an action.

import Component from '@ember/component';

export default Component.extend(contextMenuMixin, {
  contextItems: [
    {
      label: 'do something',
      action(selection, details, event) { /* do something */ }
    }
  ]
});

Label icons

:no_entry_sign: (Temporary removed from 0.2.0, back in 0.3.2)

You can optionally set an icon to show in front of the label. Just give the name of the icon.

  contextItems: [
    {
      label: 'do something',
      icon: 'search',
      action() { /* do something */ }
    }
  ]

The icons that you can use are the one from font-awesome. See http://fontawesome.io/icons/ for the icons to use. Special thanks to the ember-font-awesome addon.

Sub actions

You can add as many sub-actions as you like, but keep in mind it could blow out of your screen ;-)

  contextItems: [
    {
      label: 'multiple actions',
      subActions: [
        {
          label: 'sub action 1',
          action() { /* do something */ }
        }
      ]
    }
  ]

Selection

This context-menu can even be used in case you have to pass an item to your action. You should add it as the contextSelection. This could be one or multiple items.

  contextItems: [
    {
      label: 'do something',
      action(selection) { /* do something with the selection */ }
    }
  ],
  
  contextSelection: { foo: 'bar' }

When it's an array of multiple items, the context-menu will show the amount of items you pass to the action.

Details

If you want to pass some more details to your action, you can set is as the contextDetails. It will be passed to the action as the second argument.

  contextItems: [
    {
      label: 'do something',
      action(selection, details) { /* do something */ }
    }
  ],
  
  contextDetails: { foo: 'bar' }

Disabled actions

When your item has no action and no sub-actions, it will be disabled by default. Also you could disable it by yourself to add the disabled property. This could be either a boolean or a function which gets the selection.

  contextItems: [
    {
      label: 'foo',
      disabled: true
      action() { /* do nothing */ }
    },
    {
      label: 'bar',
      disabled(selection) {
        /* return disabled depending on selection */
      },
      action() { /* do something */ }
    }
  ]

Custom styling

The addon has some predefined styling to just get a quick start. You are able to change the styling of the complete menu by overwriting the styling for the following classes:

  • context-menu
  • context-menu--sub
  • context-menu__item
  • context-menu__item--disabled
  • context-menu__item--parent
  • context-menu__item__label

(Set up by the BEM convention)

Example screenshot Example screenshot with multiple selection

Testing

Test helpers are provided to make it easier to trigger the context menu to open.

import { triggerContextMenu } from 'ember-context-menu/test-support';

triggerContextMenu('.my-class-selector');

Special thanks to @Fabriquartz (Fabriquartz.com)

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.