import { Component, OnInit, AfterViewInit, Output, EventEmitter, ViewChildren, ElementRef, Renderer, QueryList, ChangeDetectorRef } from '@angular/core'; import {NgSwitch, NgSwitchWhen} from '@angular/common'; import {KeypressEditComponent} from './keypress-edit.component'; @Component({ moduleId: module.id, selector: 'popover', template: `
Layer
Mouse
Macro
Keymap
None
`, styles: [` :host { display: flex; flex-direction: column; min-width: 577px; padding: 0; } .popover-action { padding: 8px 14px; margin: 0; font-size: 14px; background-color: #f7f7f7; border-top: 1px solid #ebebeb; border-radius: 0 0 5px 5px; text-align: right; } .popover-title.menu-tabs { padding: .5rem .5rem 0; display: block; } .popover-title.menu-tabs .nav-tabs { position: relative; top: 1px; } .popover-content { padding: 10px 24px; } `], host: { 'class': 'popover' }, directives: [NgSwitch, NgSwitchWhen, KeypressEditComponent] }) export class PopoverComponent implements OnInit, AfterViewInit { @Output() cancel = new EventEmitter(); @ViewChildren('keypress,layer,mouse,macro,keymap,none') liElementRefs: QueryList; private activeListItemIndex: number; constructor(private renderer: Renderer, private changeDetectorRef: ChangeDetectorRef) { this.activeListItemIndex = -1; } ngOnInit() { } ngAfterViewInit() { this.onListItemClick(0); this.changeDetectorRef.detectChanges(); } onCancelClick(): void { this.cancel.emit(undefined); } onRemapKey(): void { } onListItemClick(index: number): void { let listItems: HTMLLIElement[] = this.liElementRefs.toArray().map(liElementRef => liElementRef.nativeElement); if (this.activeListItemIndex >= 0) { this.renderer.setElementClass(listItems[this.activeListItemIndex], 'active', false); } this.renderer.setElementClass(listItems[index], 'active', true); this.activeListItemIndex = index; } }