-
Notifications
You must be signed in to change notification settings - Fork 2
/
fab-menu.ts
64 lines (46 loc) · 1.55 KB
/
fab-menu.ts
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { Component, Output, Input, ViewChild, EventEmitter, ViewChildren, QueryList, Renderer } from '@angular/core';
import { FabContainer } from 'ionic-angular';
export class FabMenuItem {
constructor(
public id: string,
public icon: string,
public label: string) { }
}
@Component({
selector: 'custom-fab-menu',
templateUrl: 'custom-fab-menu.html'
})
export class CustomFabMenu {
@ViewChild('fab') fab: FabContainer;
@ViewChild('container') container: any;
@ViewChildren('label') labels: QueryList<any>;
@Input("fabIcon") fabIcon: string;
@Input("items") items: Array<FabMenuItem> = [];
@Output("onItemSelected") anOutput = new EventEmitter<FabMenuItem>();
public showMenuItem: boolean = false;
constructor(private renderer: Renderer) { }
public ngOnInit() {
this.showMenuItem = false;
}
public ngOnChanges() {
this.showMenuItem = false;
}
public hideMenuFab() {
this.fab.close();
this.showMenuItems();
}
public showMenuItems() {
this.showMenuItem = this.fab._listsActive;
this.renderer.setElementClass(this.container.nativeElement, "show", this.showMenuItem);
let i = 1;
var localLabel = this.showMenuItem ? this.labels.toArray().reverse() : this.labels.toArray();
localLabel.forEach(elem => {
setTimeout(() => this.renderer.setElementClass(elem.nativeElement, "show", this.showMenuItem), i * 50)
i++;
})
}
public action(item: FabMenuItem) {
this.hideMenuFab();
this.anOutput.emit(item);
}
}