export class Icons { private icons: Array constructor() { this.icons = [ { name: 'cross', svg: ` ` }, { name: 'check_circle', svg: ` ` }, { name: 'exclamation_circle', svg: ` ` }, { name: 'triangular_error', svg: ` ` }, { name: 'info_circle', svg: ` ` } ] } getIcon(name: string, size?: number) { var icon = this.icons.find((icon) => 'name' in icon ? icon.name == name : false); if (icon) { let svg = ('svg' in icon ? icon.svg : '') as string; let svgElement = this.htmlStringToElement(svg); if (size) { svgElement.setAttribute('height', size + 'px'); svgElement.setAttribute('width', size + 'px'); } return svgElement; } return false; } htmlStringToElement(html: string): HTMLElement { const template = document.createElement('template'); template.innerHTML = html.trim(); return template.content.firstElementChild as HTMLElement; } }