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

@luminela/contextmenu

v2.1.1

Published

A simple contextmenu component for Angular v9+.

Downloads

8

Readme

yui-contextmenu

A simple context menu component for Angular 9+.

Documentation is work in progress.

WARNING

  • This component is written with Angular 9, so it will not work with earlier versions of Angular
  • Internet Explorer is not supported.
  • No RTL support.
  • Partial keyboard support.
  • This is a simple component I implemented for my personal project, so I cannot guarantee you with frequent updates/bug fixes.
  • If you are looking for better/more professional solutions, please check out other open-source projects such as ngx-contextmenu or ngx-rightclick.

Installation

  • Install the following packages:
npm i @angular/cdk @luminela/popup @luminela/contextmenu
  • Add the following line to your global stylesheet file (styles.scss)
@import "~@angular/cdk/overlay-prebuilt.css";
  • Import ContextmenuModule in your app.module.ts file (or another module where you need it.)

Usage

Basic Usage

<yui-contextmenu [target]="targetElement" [trigger]="'contextmenu'">
    <yui-menu-item text="Export Data">
        <yui-menu-item text="Export as XML"></yui-menu-item>
        <yui-menu-item text="Export as JSON"></yui-menu-item>
        <yui-menu-item text="Export as CSV"></yui-menu-item>
    </yui-menu-item>
    <yui-menu-item [divider]="true"></yui-menu-item>
    <yui-menu-item text="Close" (menuSelect)="close()"></yui-menu-item>
</yui-contextmenu>

<button #targetElement>Context Menu Button</button>

yui-contextmenu accepts the following inputs.

target   : The target element that the context menu will be attached to.
trigger  : You can set it to 'contextmenu' or 'click' to set the trigger event. Default is set to 'contextmenu'.
menuClass: You can pass a string of css classes to help you style the menu.
theme    : You can pass 'light' or 'dark' to set the theme.
  • Inside yui-contextmenu tag, you can define multiple yui-menu-item components.
  • Inside yui-menu-item tag, you can define multiple yui-menu-item components for a submenu.
  • If, for example, you passed 'export-menu' as menuClass input, you can then use the following code to help you style the menu.
yui-contextmenu-content.export-menu {
    /* Your style rules */
}

yui-menu-item accepts the following inputs and outputs.

disabled: boolean                    // Disable a menu item.
divider: boolean                     // Set a menu item as divider. When set to true, all other options are ignored.
event: MouseEvent                    // Set the triggering event. Only used when the target changes dynamically.
icon: string;                        // Icon class for menu item. For example, you can pass a font icon class such as 'fa fa-plus'. Ignored when iconTemplate option is set.
iconTemplate: TemplateRef<any>;      // Pass a template reference to show as menu item icon.
image: string;                       // Image url for menu item icon. Ignored when iconTemplate option is set.
menuSelect: EventEmitter<IMenuItem>; // Called when a menu item is selected. 
text: string;                        // Menu item text. Ignored when textTemplate option is set.
textTemplate: TemplateRef<any>;      // Pass a template reference to show as menu item text.
toggleable: boolean;                 // Pass true if you want to make the menu item toggleable.
toggled: boolean;                    // Set toggle status of menu item. This is a two-way binding. [(toggled)]
visible: boolean;                    // Set false to hide a menu item.

Dynamic HTML Targets

If you want to change the target dynamically, you need to take a few extra steps.

  • Create the following public instance fields.
public menuEvent: MouseEvent;
public menuTarget: HTMLElement;
  • Create the yui-contextmenu component. For example;
<yui-contextmenu [target]="menuTarget" [trigger]="menuEvent?.type" [event]="menuEvent">
    <yui-menu-item text="Menu Item I"></yui-menu-item>
    <yui-menu-item text="Menu Item II"></yui-menu-item>
</yui-contextmenu>
  • Create a method that will set the values of menuTarget and menuEvent
public createMenu(event: MouseEvent): void {
    this.menuEvent = event;
    this.menuTarget = (event.target as HTMLElement);
}
  • Finally, call this createMenu method from a suitable context.
<div (contextmenu)="createMenu($event)"></div>
<p (contextmenu)="createMenu($event)"></p>
<button (click)="createMenu($event)"></button>

Known Issues

menuClass input does not work properly.

License

MIT