aboutsummaryrefslogtreecommitdiffstats
path: root/src/angular/popup-menu/popup-menu-item.component.ts
blob: fb5a71d1d2aeb1b3c5e8cc6c4297913a5a7778d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { Component, Input, Output, EventEmitter, OnChanges, SimpleChanges } from '@angular/core';
import { PopupMenuListComponent } from "./popup-menu-list.component";

@Component({
    selector: 'popup-menu-item',
    template:
        `<li [ngClass]="[className || '', type || '', type == 'separator'? '': 'sdc-menu-item']" (click)="performAction($event)">
    <ng-content *ngIf="type != 'separator'"></ng-content>
</li>`
})
export class PopupMenuItemComponent {
    @Input() public className: string;
    @Input() public type: undefined|'disabled'|'selected'|'separator';
    @Output() public action: EventEmitter<any> = new EventEmitter<any>();

    public parentMenu: PopupMenuListComponent;
    public index: number = 0;

    public performAction(evt) {
        evt.stopPropagation();

        if (['disabled', 'separator'].indexOf(this.type) !== -1) {
            return;
        }

        if (this.parentMenu instanceof PopupMenuListComponent) {
            this.parentMenu.open = false;
        }

        if (this.action) {
            this.action.emit();
        }
    }
}