Skip to content

Commit

Permalink
chore(icon): update lifecycle hook to allow icon change
Browse files Browse the repository at this point in the history
  • Loading branch information
tonghauhive committed Dec 20, 2024
1 parent 0e0c516 commit 4f4fa83
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/components/Icon/sgds-icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@ export class SgdsIcon extends SgdsElement {
@state()
private _svgContent: string | null = null;

async firstUpdated() {
if (this.name) {
async updated(changedProperties: Map<string, any>) {
if (changedProperties.has("name")) {
await this.loadSvg(this.name);
}
}

updated() {
this.style.display = this._svgContent ? "flex" : "none";
this.style.display = this._svgContent ? "" : "none";
}

async loadSvg(name: string): Promise<void> {
Expand All @@ -46,10 +43,10 @@ export class SgdsIcon extends SgdsElement {
if (svg) {
this._svgContent = svg;
} else {
throw new Error("icon `name` is undefined");
throw new Error("Icon `name` is undefined");
}
} catch (error) {
console.error(`Error loading SVG: ${name}`, error);
console.error(`Unable to load icon: ${name}.`, error);
}
}
}
Expand Down

0 comments on commit 4f4fa83

Please sign in to comment.