Files
notebrook-notes/frontend/src/ui/image.ts
2024-09-03 14:50:33 +02:00

33 lines
916 B
TypeScript

import { UINode } from "./node";
export class Image extends UINode {
private imgElement: HTMLImageElement;
public constructor(title: string, src: string, altText: string = "") {
super(title);
this.imgElement = document.createElement("img");
this.imgElement.src = src;
this.imgElement.alt = altText;
this.element.appendChild(this.imgElement);
this.element.setAttribute("aria-label", title);
}
public getElement(): HTMLElement {
return this.imgElement;
}
public setText(text: string) {
this.title = text;
this.element.setAttribute("aria-label", text);
return this;
}
public setSource(src: string) {
this.imgElement.src = src;
return this;
}
public setAltText(altText: string) {
this.imgElement.alt = altText;
return this;
}
}