2020-10-31 16:44:19 +01:00
|
|
|
import {Component, ElementRef, Input, OnInit} from "@angular/core";
|
2020-10-13 14:57:04 +02:00
|
|
|
import {IconsService} from "./icons.service";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* First add your icon to Icon registry, by adding this to your component Module.
|
|
|
|
*
|
|
|
|
* e.g export class ExampleModule {
|
|
|
|
* constructor(private iconsService: IconsService) {
|
|
|
|
* this.iconsService.registerIcons([arrow_right])
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* */
|
|
|
|
@Component({
|
|
|
|
selector: 'icon',
|
|
|
|
template: `
|
2020-10-19 17:05:16 +02:00
|
|
|
<span *ngIf="svg" class="uk-icon" [class.uk-flex]="flex" [ngClass]="customClass" [ngStyle]="style" [innerHTML]="svg | safeHtml"></span>
|
2020-10-13 14:57:04 +02:00
|
|
|
`
|
|
|
|
})
|
|
|
|
export class IconsComponent implements OnInit{
|
|
|
|
public svg;
|
|
|
|
public style;
|
|
|
|
/**
|
|
|
|
* True if this icon should have display flex (Optional, Default: false)
|
|
|
|
* */
|
|
|
|
@Input()
|
|
|
|
public flex = false;
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Add custom class(es)(Optional)
|
|
|
|
* */
|
|
|
|
@Input()
|
|
|
|
public customClass;
|
|
|
|
/**
|
|
|
|
* Color of svg (Optional)
|
|
|
|
* */
|
|
|
|
@Input()
|
|
|
|
public fill;
|
|
|
|
/**
|
|
|
|
* Color of svg stroke (Optional)
|
|
|
|
* */
|
|
|
|
@Input()
|
|
|
|
public stroke;
|
|
|
|
/**
|
|
|
|
* Size of svg (Default: 1)
|
|
|
|
* */
|
|
|
|
@Input()
|
|
|
|
public ratio = 1;
|
|
|
|
/**
|
|
|
|
* Name of icon in registry (Required)
|
|
|
|
* */
|
|
|
|
@Input()
|
|
|
|
set name(iconName: string) {
|
|
|
|
this.svg = this.iconsService.getIcon(iconName);
|
|
|
|
}
|
|
|
|
|
2020-10-31 16:44:19 +01:00
|
|
|
constructor(private iconsService: IconsService,
|
|
|
|
private elementRef: ElementRef) {}
|
2020-10-13 14:57:04 +02:00
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.style = {
|
|
|
|
transform: 'scale(' + this.ratio + ')',
|
|
|
|
fill: this.fill,
|
|
|
|
stroke: this.stroke
|
|
|
|
};
|
2020-10-31 16:44:19 +01:00
|
|
|
this.elementRef.nativeElement.style = 'line-height: 20px;';
|
2020-10-13 14:57:04 +02:00
|
|
|
}
|
|
|
|
}
|