-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathloader.component.ts
58 lines (46 loc) · 1.12 KB
/
loader.component.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
import { Component, Input, ElementRef, ViewChild, Renderer } from '@angular/core'
@Component({
selector: "lsu-loader",
template: `
<div #loaderDiv class="ui dimmer" [ngClass]="{'active': active}">
<div class="ui {{loaderSize}} text loader">{{ loaderText }}</div>
</div>
`
})
export class LoaderComponent {
@ViewChild("loaderDiv")
loaderDiv: ElementRef;
_active: boolean;
@Input()
public set active(val: boolean) {
this._active = val;
this.toggleLoader();
}
public get active(): boolean {
return this._active;
}
@Input()
public loaderText: string
@Input()
public loaderSize: string
parentEle: any
constructor(
private _renderer: Renderer) {
}
ngAfterViewInit() {
if (!this.parentEle) {
this.parentEle = this.loaderDiv.nativeElement.parentElement.parentElement;
}
}
show() {
this.active = true;
}
hide() {
this.active = false;
}
toggleLoader() {
if (!this.parentEle) return;
this._renderer.setElementClass(this.parentEle, 'ui', this.active);
this._renderer.setElementClass(this.parentEle, 'segment', this.active);
}
}