Skip to content

ChristophHu/ngx-contextmenu

Repository files navigation

Ngx-contextmenu

Demo

image

Description

This repository contains an Angular 20 demo that showcases the ngx-contextmenu library. ngx-contextmenu provides a flexible and customizable context menu component for Angular applications. With this library, you can easily add right-click context menus to your web applications, enhancing user interaction and experience. It’s easy to customize—sizes, colors, and behavior—to match your application’s design.

Frameworks and Languages

Static Badge Static Badge Static Badge

Installation

To run this project, you need to have Node.js installed on your machine. Clone the repository and run the following commands:

npm install @christophhu/ngx-contextmenu

Usage

Import the DatatableComponent in the app.ts.

import { NgxContextmenu } from '@christophhu/ngx-contextmenu';

@NgModule({
    imports: [
        NgxContextmenu,
        ...
    ]
...
})
export class App {
  public items: ContextItem[] = [
    { id: '1', label: 'Back', icon: 'dot', shortcut: ["Shift", "L"], disabled: true, action: ContextActionEnum.DELETE },
    { id: '2', label: 'Forward', icon: 'dots', shortcut: ["Shift", "O"], action: ContextActionEnum.EDIT },
    { id: '3', label: 'Teilen', divider: true, items: [
      { id: '31', label: 'Facebook', icon: 'brand-facebook', shortcut: ["Shift", "D"], action: ContextActionEnum.EDIT },
      { id: '32', label: 'Instagram', icon: 'brand-instagram', shortcut: ["Shift", "I"], action: ContextActionEnum.EDIT }
    ]},
    { id: '4', label: 'Forward', class: ContextItemClassEnum.DANGER, icon: 'dots', shortcut: ["Shift", "A"], action: '5' }
  ]

  returnContextAction(event: ContextActionReturn) {
    switch (event.action) {
      case ContextDefaultActions.OPEN.toString():
        console.log('is open', event.id)
        break
      case ContextActionEnum.DELETE:
        console.log('delete row', event.id)
        break
      case ContextActionEnum.EDIT:
        console.log('edit row', event.id)
        break
      default:
        console.log('default contextaction', event.id)
    }
  }
}

Then, you can use the <ngx-contextmenu> component in your HTML templates as shown below:

<ngx-contextmenu [items]="items" (action)="returnContextAction($event)" [element]="{ id: '1234', code: 'test'}"></ngx-contextmenu>

Styles

You can customize the styles of the context menu by overriding the default CSS classes. Here’s an example of how to change the background color and text color of the context menu:

ngx-shortcut 
    .shortcut
        gap: 0px
        justify-content: flex-end

        .shortcut-text
            @apply bg-transparent text-borderline h-full p-0 min-w-full

License

This project is licensed under the MIT License.

The MIT License (MIT) Copyright © 2025

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published