Project

General

Profile

1 61381 k.triantaf
import {Component, ElementRef, Input, OnInit} from "@angular/core";
2
import {IconsService} from "./icons.service";
3
4
/**
5
 * First add your icon to Icon registry, by adding this to your component Module.
6
 *
7
 * e.g export class ExampleModule {
8
 *  constructor(private iconsService: IconsService) {
9
 *    this.iconsService.registerIcons([arrow_right])
10
 *  }
11
 * }
12
 *
13
 * */
14
@Component({
15
  selector: 'icon',
16
  template: `
17
    <span *ngIf="svg" class="uk-icon" [class.uk-flex]="flex" [ngClass]="customClass" [ngStyle]="style" [innerHTML]="svg | safeHtml"></span>
18
  `
19
})
20
export class IconsComponent implements OnInit{
21
  public svg;
22
  public style;
23
  /**
24
   * True if this icon should have display flex (Optional, Default: false)
25
   * */
26
  @Input()
27
  public flex = false;
28
  /**
29
   *
30
   * Add custom class(es)(Optional)
31
   * */
32
  @Input()
33
  public customClass;
34
  /**
35
   * Color of svg (Optional)
36
   * */
37
  @Input()
38
  public fill;
39
  /**
40
   * Color of svg stroke (Optional)
41
   * */
42
  @Input()
43
  public stroke;
44
  /**
45
   * Size of svg (Default: 1)
46
   * */
47
  @Input()
48
  public ratio = 1;
49
  /**
50
   * Name of icon in registry (Required)
51
   * */
52
  @Input()
53
  set name(iconName: string) {
54
    this.svg = this.iconsService.getIcon(iconName);
55
  }
56
57
  constructor(private iconsService: IconsService,
58
              private elementRef: ElementRef) {}
59
60
  ngOnInit() {
61
    this.style = {
62
      transform: 'scale(' + this.ratio + ')',
63
      fill: this.fill,
64
      stroke: this.stroke
65
    };
66
    //this.elementRef.nativeElement.style = 'line-height: ' + this.ratio*20 + 'px; height: 20px';
67
  }
68
}