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
|
import { Component, Input, ViewContainerRef, Inject, OnInit, OnDestroy, Output, EventEmitter } from "@angular/core";
import { template } from "./loader.component.html";
import { LoaderService } from "./loader.service";
export enum LoaderSize {
large = 'large',
medium = 'medium',
small = 'small',
}
@Component({
selector: "sdc-loader",
template: template
})
export class LoaderComponent implements OnInit, OnDestroy {
@Input() active: number;
@Input() size?: LoaderSize; // small || medium || large
@Input() global?: boolean; // If is relative is set to true, loader will appear over parent element. Otherwise, will be fixed over the entire page.
@Input() name?: string;
@Output() activeChange: EventEmitter<number> = new EventEmitter<number>();
constructor(private loaderService: LoaderService) {
this.active = 0;
this.size = LoaderSize.large;
this.global = false;
}
public ngOnInit(): void {
if (this.name !== undefined) {
this.loaderService.register(this.name, this);
}
}
public ngOnDestroy(): void {
if (this.name !== undefined) {
this.loaderService.unregister(this.name);
}
}
public activate() {
this.active++;
this.activeChange.emit(this.active);
}
public deactivate() {
if (this.active > 0) {
this.active--;
this.activeChange.emit(this.active);
}
}
}
|