-
Notifications
You must be signed in to change notification settings - Fork 150
/
layers.component.ts
54 lines (48 loc) · 1.39 KB
/
layers.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
import { DOCUMENT } from '@angular/common';
import {
Component,
ElementRef,
HostBinding,
inject,
Input,
OnChanges,
OnInit,
Renderer2,
SimpleChanges,
} from '@angular/core';
import { SizeProp } from '@fortawesome/fontawesome-svg-core';
import { FaConfig } from '../config';
import { ensureCss } from '../shared/utils/css';
/**
* Fontawesome layers.
*/
@Component({
selector: 'fa-layers',
standalone: true,
template: `<ng-content></ng-content>`,
})
export class FaLayersComponent implements OnInit, OnChanges {
@Input() size?: SizeProp;
@Input() @HostBinding('class.fa-fw') fixedWidth?: boolean;
private document = inject(DOCUMENT);
constructor(
private renderer: Renderer2,
private elementRef: ElementRef,
private config: FaConfig,
) {}
ngOnInit() {
this.renderer.addClass(this.elementRef.nativeElement, 'fa-layers');
ensureCss(this.document, this.config);
this.fixedWidth = typeof this.fixedWidth === 'boolean' ? this.fixedWidth : this.config.fixedWidth;
}
ngOnChanges(changes: SimpleChanges) {
if ('size' in changes) {
if (changes.size.currentValue != null) {
this.renderer.addClass(this.elementRef.nativeElement, `fa-${changes.size.currentValue}`);
}
if (changes.size.previousValue != null) {
this.renderer.removeClass(this.elementRef.nativeElement, `fa-${changes.size.previousValue}`);
}
}
}
}