1.1.3 • Published 5 years ago

ng2-right-click-menu v1.1.3

Weekly downloads
569
License
MIT
Repository
github
Last release
5 years ago

ng2-right-click-menu

Right click context menu for Angular 2+

DEMO https://msarsha.github.io/ng2-right-click-menu/

Dependencies

@angular/cdk

@angular/cdk/overlay-prebuilt.css

Setup

npm install --save ng2-right-click-menu @angular/cdk

import ShContextMenuModule

import {ShContextMenuModule} from 'ng2-right-click-menu'

@NgModule({
  //...
  imports: [ShContextMenuModule]
  //...
})

import css file in your styles.css:

  @import "~@angular/cdk/overlay-prebuilt.css";

Usage

Defining a Basic Menu Template

The menu template is built using the sh-context-menu component as the menu wrapper, and nested ng-template with the shContextMenuItem directive for every menu item:

The shContextMenuItem directive provide a template variable (let-data) that gives you access to the data object attached to the menu.

<sh-context-menu #menu>
  <ng-template shContextMenuItem let-data (click)="onClick($event)">
    <div>
      Menu Item - {{data.label}}
    </div>
  </ng-template>
</sh-context-menu>

Attaching Menu To An Element

Attaching works by using the shAttachMenu directive and providing the #menu (from the above example) template variable:

The object provided to the [shMenuData] input will be available as a template variable inside ng-templates with shContextMenuItem

<div [shAttachMenu]="menu" [shMenuData]="data">Right Click Me</div>

Sub Menus

Sub menu is attached to the shContextMenuItem directive using the [subMenu] input.

The [subMenu] input is provided with a sh-context-menu's template variable (just like attaching a menu to an element).

<sh-context-menu #menu>
  <ng-template shContextMenuItem let-data [subMenu]="#nestedMenu">
    <div>
      Menu Item - {{data.label}}
    </div>
  </ng-template>
  <sh-context-menu #nestedMenu>
    <ng-template shContextMenuItem let-data>
      <div>
        Menu Item - {{data.label}}
      </div>
    </ng-template>
  </sh-context-menu>
</sh-context-menu>

API

sh-context-menu (component)

NameTypeDefaultDescription
thisanynullthe this context for input callbacks (visible) - typically the menu's host component

shContextMenuItem (directive)

NameTypeDefaultDescription
subMenuShContextMenuComponentnullsub menu
dividerbooleanfalserender a divider
closeOnClickbooleantrueshould the menu close on click
visible(event: ShContextMenuClickEvent) => booleannullfunction to determine if a item is visible
(click)(event: ShContextMenuClickEvent) => voidnullclick handler

shAttachMenu (directive)

NameTypeDefaultDescription
shAttachMenuShContextMenuComponentnullthe menu that will be attached to the element
shMenuTriggersstring[]nulllist of event names that will trigger the menu
shMenuDataanynullthe data object that will be injected to the menu item's template

Setting up development env

npm start to run the demo application

develop the library under /lib

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.0.16

6 years ago

0.0.15

6 years ago

0.0.14

7 years ago

0.0.13

7 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago