22 lines
462 B
TypeScript
22 lines
462 B
TypeScript
export class WeatherIconElement extends HTMLElement {
|
|
static iconsPath = "./icons";
|
|
static observedAttributes = ["icon"];
|
|
|
|
constructor() {
|
|
super();
|
|
const icon = this.getAttribute("icon");
|
|
if (icon) {
|
|
this.icon = icon;
|
|
}
|
|
}
|
|
|
|
set icon(value: string) {
|
|
const src = `${WeatherIconElement.iconsPath}/wi-${value}.svg`;
|
|
fetch(src)
|
|
.then((response) => response.text())
|
|
.then((data) => (this.innerHTML = data));
|
|
}
|
|
}
|
|
|
|
|