mapcomplete/UI/UIElement.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

34 lines
917 B
TypeScript
Raw Normal View History

2021-06-10 01:36:20 +02:00
import BaseUIElement from "./BaseUIElement";
2020-06-24 00:35:19 +02:00
export abstract class UIElement extends BaseUIElement {
2020-09-02 11:37:34 +02:00
2020-06-24 00:35:19 +02:00
/**
2021-06-10 01:36:20 +02:00
* Should be overridden for specific HTML functionality
*/
2021-06-10 01:36:20 +02:00
protected InnerConstructElement(): HTMLElement {
// Uses the old fashioned way to construct an element using 'InnerRender'
const innerRender = this.InnerRender();
if (innerRender === undefined || innerRender === "") {
return undefined;
}
const el = document.createElement("span")
if (typeof innerRender === "string") {
el.innerHTML = innerRender
} else {
const subElement = innerRender.ConstructElement();
if (subElement === undefined) {
return undefined;
}
2021-06-10 01:36:20 +02:00
el.appendChild(subElement)
}
2021-06-10 01:36:20 +02:00
return el;
}
2021-06-10 01:36:20 +02:00
protected abstract InnerRender(): string | BaseUIElement;
2020-07-20 15:54:50 +02:00
}
2020-06-24 00:35:19 +02:00
2020-07-29 15:05:19 +02:00