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>
|
2022-01-17 18:46:22 +01:00
|
|
|
<span *ngIf="!svg && iconName" class="material-icons" [ngClass]="customClass + (type?(' ' + type):'')" [ngStyle]="style">{{iconName}}</span>
|
2020-10-13 14:57:04 +02:00
|
|
|
`
|
|
|
|
})
|
2022-01-17 18:46:22 +01:00
|
|
|
export class IconsComponent implements OnInit {
|
2020-10-13 14:57:04 +02:00
|
|
|
public svg;
|
2022-01-17 18:46:22 +01:00
|
|
|
public iconName: string;
|
2020-10-13 14:57:04 +02:00
|
|
|
public style;
|
|
|
|
/**
|
|
|
|
* True if this icon should have display flex (Optional, Default: false)
|
|
|
|
* */
|
|
|
|
@Input()
|
|
|
|
public flex = false;
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Add custom class(es)(Optional)
|
|
|
|
* */
|
|
|
|
@Input()
|
2022-01-17 18:46:22 +01:00
|
|
|
public customClass = '';
|
2020-10-13 14:57:04 +02:00
|
|
|
/**
|
|
|
|
* Color of svg (Optional)
|
|
|
|
* */
|
|
|
|
@Input()
|
|
|
|
public fill;
|
|
|
|
/**
|
|
|
|
* Color of svg stroke (Optional)
|
|
|
|
* */
|
|
|
|
@Input()
|
|
|
|
public stroke;
|
|
|
|
/**
|
2022-01-17 18:46:22 +01:00
|
|
|
* Size of icon (Default: 1)
|
2020-10-13 14:57:04 +02:00
|
|
|
* */
|
|
|
|
@Input()
|
|
|
|
public ratio = 1;
|
2022-01-17 18:46:22 +01:00
|
|
|
/**
|
|
|
|
* In case of Material icon only. Type of icon (Optional)
|
|
|
|
* */
|
|
|
|
@Input()
|
|
|
|
public type: "outlined" | "round" | "sharp" | "two-tone" | null = null;
|
2020-10-13 14:57:04 +02:00
|
|
|
/**
|
|
|
|
* Name of icon in registry (Required)
|
|
|
|
* */
|
|
|
|
@Input()
|
|
|
|
set name(iconName: string) {
|
2022-01-17 18:46:22 +01:00
|
|
|
this.iconName = iconName;
|
2020-10-13 14:57:04 +02:00
|
|
|
this.svg = this.iconsService.getIcon(iconName);
|
|
|
|
}
|
|
|
|
|
2022-01-17 18:46:22 +01:00
|
|
|
constructor(private iconsService: IconsService) {}
|
2020-10-13 14:57:04 +02:00
|
|
|
|
|
|
|
ngOnInit() {
|
2022-01-17 18:46:22 +01:00
|
|
|
if(this.svg) {
|
|
|
|
this.style = {
|
|
|
|
transform: 'scale(' + this.ratio + ')',
|
|
|
|
fill: this.fill,
|
|
|
|
stroke: this.stroke
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
this.style = {
|
|
|
|
"font-size.px": this.ratio*20,
|
|
|
|
fill: this.fill,
|
|
|
|
stroke: this.stroke
|
|
|
|
};
|
|
|
|
}
|
2020-10-13 14:57:04 +02:00
|
|
|
}
|
|
|
|
}
|