mapcomplete/UI/Base/Combine.ts

36 lines
1,000 B
TypeScript
Raw Normal View History

2020-07-21 01:37:48 +02:00
import {UIElement} from "../UIElement";
2020-09-12 23:15:17 +02:00
import {FixedUiElement} from "./FixedUiElement";
import {Utils} from "../../Utils";
2020-07-21 01:37:48 +02:00
export default class Combine extends UIElement {
2020-09-12 23:15:17 +02:00
private readonly uiElements: UIElement[];
2020-07-21 01:37:48 +02:00
2020-09-12 23:15:17 +02:00
constructor(uiElements: (string | UIElement)[]) {
super();
this.uiElements = Utils.NoNull(uiElements)
.map(el => {
if (typeof el === "string") {
return new FixedUiElement(el);
}
return el;
});
2020-07-21 01:37:48 +02:00
}
InnerRender(): string {
return this.uiElements.map(ui => {
if(ui === undefined || ui === null){
return "";
}
if(ui.Render === undefined){
console.error("Not a UI-element", ui);
return "";
}
2021-01-21 23:39:31 +01:00
let rendered = ui.Render();
if(ui.IsEmpty()){
return "";
}
return rendered;
}).join("");
2020-07-21 01:37:48 +02:00
}
2020-07-21 01:37:48 +02:00
}