openaire-library/utils/icons/icons.service.ts

22 lines
580 B
TypeScript

import {Injectable} from "@angular/core";
import {Icon} from "./icons";
@Injectable({
providedIn: 'root'
})
export class IconsService {
private registry = new Map<string, string>();
public registerIcons(icons: any[]): void {
icons.forEach((icon: Icon) => this.registry.set(icon.name, icon.data));
}
public getIcon(iconName: string): string | undefined {
if (!this.registry.has(iconName)) {
console.warn(`We could not find Icon with the name ${iconName}, did you add it to the Icon registry?`);
}
return this.registry.get(iconName);
}
}