summaryrefslogtreecommitdiffstats
path: root/src/angular/popup-menu/popup-menu-list.component.ts
diff options
context:
space:
mode:
authorMichael Lando <ml636r@att.com>2018-05-21 20:19:48 +0000
committerGerrit Code Review <gerrit@onap.org>2018-05-21 20:19:48 +0000
commit05b37297177e8a342668c15e5d6f738b51f7aedd (patch)
treee236c96df52a13f935292db8aa73e84d0c41ad8a /src/angular/popup-menu/popup-menu-list.component.ts
parent884dfb789593d2a3cc319047ab1f0215778aec9f (diff)
parent1994c98063c27a41797dec01f2ca9fcbe33ceab0 (diff)
Merge "init commit onap ui"2.0.0-ONAPbeijing2.0.0-ONAP
Diffstat (limited to 'src/angular/popup-menu/popup-menu-list.component.ts')
-rw-r--r--src/angular/popup-menu/popup-menu-list.component.ts65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/angular/popup-menu/popup-menu-list.component.ts b/src/angular/popup-menu/popup-menu-list.component.ts
new file mode 100644
index 0000000..6a20423
--- /dev/null
+++ b/src/angular/popup-menu/popup-menu-list.component.ts
@@ -0,0 +1,65 @@
+import { Component, Input, Output, ContentChildren, SimpleChanges, QueryList, EventEmitter, OnChanges, AfterContentInit } from '@angular/core';
+import { PopupMenuItemComponent } from "./popup-menu-item.component";
+
+export interface IPoint {
+ x: number;
+ y: number;
+}
+
+@Component({
+ selector: 'popup-menu-list',
+ template:
+ `<ul
+ class="sdc-menu-list"
+ *ngIf="open"
+ [ngClass]="[className || '', relative? 'relative': '']"
+ [ngStyle]="{'left': position.x + 'px', 'top': position.y + 'px'}"
+ (click)="$event.stopPropagation()">
+ <ng-content></ng-content>
+ </ul>`
+})
+export class PopupMenuListComponent implements AfterContentInit {
+ @Input()
+ public get open(): boolean {
+ return this._open;
+ }
+ public set open(isOpen: boolean) {
+ isOpen = isOpen !== undefined ? isOpen : false;
+ if (this._open !== isOpen) {
+ this._open = isOpen;
+ this.openChange.emit(this._open);
+ }
+ }
+ @Input()
+ public get position(): IPoint {
+ return this._position;
+ }
+ public set position(position: IPoint) {
+ position = position !== undefined ? position : {x: 0, y: 0};
+ if (this._position.x !== position.x || this._position.y !== position.y) {
+ this._position = position;
+ this.positionChange.emit(this._position);
+ }
+ }
+ @Input() public className: string;
+ @Input() public relative: boolean = false;
+ @Output() public openChange: EventEmitter<boolean> = new EventEmitter<boolean>();
+ @Output() public positionChange: EventEmitter<IPoint> = new EventEmitter<IPoint>();
+
+ @ContentChildren(PopupMenuItemComponent) private menuItems: QueryList<PopupMenuItemComponent>;
+
+ private _open: boolean = false;
+ private _position: IPoint = {x: 0, y: 0};
+
+ public ngAfterContentInit() {
+ this._updateMenuItemsList(this.menuItems);
+ this.menuItems.changes.subscribe(this._updateMenuItemsList);
+ }
+
+ private _updateMenuItemsList(menuItemsList: QueryList<PopupMenuItemComponent>) {
+ menuItemsList.forEach((c, idx) => {
+ c.parentMenu = this;
+ c.index = idx;
+ });
+ }
+}