All files / src/lib/wvr-icon wvr-icon.component.ts

90% Statements 9/10
100% Branches 0/0
66.67% Functions 2/3
87.5% Lines 7/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                                1x                       4x       4x 4x       4x 4x 4x            
import { HttpClient } from '@angular/common/http';
import { ChangeDetectionStrategy, Component, HostBinding, Injector, Input, OnInit } from '@angular/core';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { WvrBaseComponent } from '../shared/wvr-base.component';
 
/**
 * A reference to an Icon currently available in the configured assets.
 */
@Component({
  selector: 'wvr-icon-component',
  templateUrl: './wvr-icon.component.html',
  styleUrls: ['./wvr-icon.component.scss'],
  changeDetection: ChangeDetectionStrategy.Default
})
export class WvrIconComponent extends WvrBaseComponent implements OnInit {
 
  /** An attribute input describing the icon set to which this icon belongs. */
  @Input() set: string;
 
  /** An attribute input describing the icon name of this icon. */
  @Input() name: string;
 
  /** An attribute input bound to the css variable `--wvr-icon-color`.  */
  @HostBinding('style.--wvr-icon-color') @Input() color: string;
 
  /** An attribute input bound to the css variable `--wvr-icon-size`.  */
  @HostBinding('style.--wvr-icon-size') @Input() size = '24px';
 
  iconSvg: Observable<SafeHtml>;
 
  constructor(injector: Injector, private readonly http: HttpClient, protected readonly sanitizer: DomSanitizer) {
    super(injector);
  }
 
  ngOnInit(): void {
    super.ngOnInit();
    const iconSvgUrl = `${this.appConfig.assetsUrl}/icons/${this.set}/${this.name}.svg`;
    this.iconSvg = this.http.get(iconSvgUrl, {
      responseType: 'text'
    }).pipe(map((svg: string) => this.sanitizer.bypassSecurityTrustHtml(svg)));
  }
 
}