Coder Social home page Coder Social logo

vivek-yarra / ngx-rightclick Goto Github PK

View Code? Open in Web Editor NEW

This project forked from scttcper/ngx-rightclick

0.0 0.0 0.0 2.16 MB

Context Menu Service for Angular

Home Page: https://ngx-rightclick.vercel.app

License: MIT License

JavaScript 3.34% TypeScript 84.27% HTML 5.07% SCSS 7.32%

ngx-rightclick's Introduction

ngx-rightclick

npm CircleCI

Context Menu Service for Angular

Demo: https://ngx-rightclick.vercel.app

Install

if you don't already have @angular/cdk that needs to be installed too

npm install @ctrl/ngx-rightclick

Dependencies

Latest version available for each version of Angular

ngx-rightclick Angular
3.0.1 9.x
4.0.0 10 < 15
15.0.0 >= 15.*

Use

Import and Add to NgModule

import { ContextMenuModule } from '@ctrl/ngx-rightclick';

Add context menu directive to element and pass the menu component to be shown. Important the menu component must also be added as to entryComponents in your NgModule. See here

// show.component.ts
@Component({
  template: `
    <div [contextMenuTrigger]="menu" (menuAction)="handleMenuAction($event)">Right Click</div>
  `,
})
export class ShowComponent {
  // menu component imported and assigned locally
  menu = SimpleMenuComponent;
}
// my-menu.component.ts
import { Component } from '@angular/core';

import { MenuComponent, ContextMenuService, MenuPackage } from '@ctrl/ngx-rightclick';

@Component({
  selector: 'simple-menu',
  // add your menu html
  template: `<a (click)="handleClick()">Download</a>`,
})
export class SimpleMenuComponent extends MenuComponent {
  // this module does not have animations, set lazy false
  lazy = false;

  constructor(public menuPackage: MenuPackage, public contextMenuService: ContextMenuService) {
    super(menuPackage, contextMenuService);
    // grab any required menu context passed via menuContext input
    console.log(menuPackage.context);
  }

  handleClick() {
    // IMPORTANT! tell the menu to close, anything passed in here is given to (menuAction)
    this.contextMenuService.closeAll();
  }
}

Last step add css somewhere in your global styles

.cdk-overlay-container {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
.ngx-contextmenu.cdk-overlay-pane {
  position: absolute;
  pointer-events: auto;
  box-sizing: border-box;
}

// not required but can help with mobile right click
.target {
  user-select: none;
}

[Inputs]

name type description
contextMenuTrigger / contextSubmenuTrigger component the menu or submenu to be shown
menuContext any passed to the menu component via MenuPackage
holdToDisplay number default: 1000 ms pressing down on mobile to show menu

(Ouput)

name type description
menuAction any whatever is passed to ContextMenuService.closeAll
menuClose void triggered whenever a menu or submenu is closed

Submenu

Use the contextSubmenuTrigger directive as you would the contextMenuTrigger inside your menu.

Other Options

ngx-contextmenu
Find the Angular Component of your dreams on angular.parts

License

MIT

ngx-rightclick's People

Contributors

renovate-bot avatar scttcper avatar renovate[bot] avatar 1-0-1 avatar msarsha 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.