/* Copyright © 2016-2019 Lidor Systems. All rights reserved. This file is part of the "IntegralUI Web" Library. The contents of this file are subject to the IntegralUI Web License, and may not be used except in compliance with the License. A copy of the License should have been installed in the product's root installation directory or it can be found at http://www.lidorsystems.com/products/web/studio/license-agreement.aspx. This SOFTWARE is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. Any infringement will be prosecuted under applicable laws. */ import { Component, ViewContainerRef, ViewChild, ViewChildren, ViewEncapsulation } from '@angular/core'; import { IntegralUIContextMenu } from '../../integralui/directives/integralui.contextmenu'; @Component({ selector: '', template: `

ContextMenu / Templates

{{item.text}}
{{item.value}}
{{item.text}}
Right click to open the context menu

This example shows how to create menu items with custom content in ContextMenu directive.

For this purpose, you can use templates and based on menu item, add different HTML elements or other Angular components. In this case, the ContextMenu has two custom menu items:

To simplify the example, when edit button is clicked, a popup message will appear stating the button that is clicked.

When you need to change a value while keeping the menu open, you need to set the autoClose field in menu settings to false. This makes sure the menu stays open during operation. If the menu item label is clicked, the menu will also close. For example, click on +/- buttons to change the font size, when finished, just click on the 'Font Size' label.

For more information check out the source code of this sample (contextmenu/contextmenu-templates.ts) file.

`, encapsulation: ViewEncapsulation.None }) export class ContextMenuTemplateSample { @ViewChild('application', {read: ViewContainerRef, static: false}) applicationRef: ViewContainerRef; public menuSettings: any = { appRef: null, items: [] } public fontWeight: string = 'bold'; public fontStyle: string = 'normal'; public fontSize: number = 18; public textDecoration: string = 'none'; constructor(){} ngAfterViewInit(){ this.menuSettings = { appRef: this.applicationRef, autoClose: false, items: [ { id: 1, text: "Bold", icon: 'cmnu-tpl-icons-medium check-mark', checked: true }, { id: 2, text: "Italic", icon: 'cmnu-tpl-icons-medium empty' }, { id: 3, text: "Strikethrough", icon: 'cmnu-tpl-icons-medium empty' }, { id: 4, type: "separator" }, { id: 5, text: "Font Size", value: 18, buttons: [ { icon: 'cmnu-tpl-icons-medium cmnu-tpl-font-decrease' }, { icon: 'cmnu-tpl-icons-medium cmnu-tpl-font-increase' } ] }, { id: 6, type: "separator" }, { id: 7, text: "Edit", buttons: [ { text: 'Cut' }, { text: 'Copy' }, { text: 'Paste' } ] }, { id: 8, type: "separator" }, { id: 9, text: "Exit" } ] } } menuItemClick(e: any){ if (e.item){ if (e.item.id < 5) e.item.checked = e.item.checked != undefined ? !e.item.checked : true; else e.item.checked = true; switch (e.item.id){ case 1: this.fontWeight = e.item.checked != false ? 'bold' : 'normal'; break; case 2: this.fontStyle = e.item.checked != false ? 'italic' : 'normal'; break; case 3: this.textDecoration = e.item.checked != false ? 'line-through' : 'none'; break; } if (e.item.id < 4) e.item.icon = e.item.checked != false ? 'cmnu-tpl-icons-medium check-mark' : 'cmnu-tpl-icons-medium empty'; } } onFontDecrease(e: any, item: any){ if (e.which == 1){ item.value--; this.fontSize = item.value; } e.stopPropagation(); } onFontIncrease(e: any, item: any){ if (e.which == 1){ item.value++; this.fontSize = item.value; } e.stopPropagation(); } onEditButtonClicked(e: any, index: number){ switch (index){ case 0: alert("Cut button clicked!"); break; case 1: alert("Copy button clicked!"); break; case 2: alert("Paste button clicked!"); break; } e.stopPropagation(); } }