2020-07-29 15:05:19 +02:00
|
|
|
import {UIElement} from "../UIElement";
|
|
|
|
import Translations from "../i18n/Translations";
|
2020-08-17 17:23:15 +02:00
|
|
|
import {UIEventSource} from "../../Logic/UIEventSource";
|
2020-07-29 15:05:19 +02:00
|
|
|
|
|
|
|
export class TabbedComponent extends UIElement {
|
|
|
|
|
|
|
|
private headers: UIElement[] = [];
|
|
|
|
private content: UIElement[] = [];
|
|
|
|
|
2020-09-02 11:37:34 +02:00
|
|
|
constructor(elements: { header: UIElement | string, content: UIElement | string }[], openedTab: (UIEventSource<number> | number) = 0) {
|
|
|
|
super(typeof (openedTab) === "number" ? new UIEventSource(openedTab) : (openedTab ?? new UIEventSource<number>(0)));
|
2020-07-29 15:05:19 +02:00
|
|
|
const self = this;
|
|
|
|
for (let i = 0; i < elements.length; i++) {
|
|
|
|
let element = elements[i];
|
|
|
|
this.headers.push(Translations.W(element.header).onClick(() => self._source.setData(i)));
|
|
|
|
this.content.push(Translations.W(element.content));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
InnerRender(): string {
|
|
|
|
let headerBar = "";
|
|
|
|
for (let i = 0; i < this.headers.length; i++) {
|
|
|
|
let header = this.headers[i];
|
|
|
|
|
2020-07-31 04:58:58 +02:00
|
|
|
if (!this.content[i].IsEmpty()) {
|
|
|
|
headerBar += `<div class=\'tab-single-header ${i == this._source.data ? 'tab-active' : 'tab-non-active'}\'>` +
|
|
|
|
header.Render() + "</div>"
|
|
|
|
}
|
2020-07-29 15:05:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
headerBar = "<div class='tabs-header-bar'>" + headerBar + "</div>"
|
|
|
|
|
2020-08-27 18:44:16 +02:00
|
|
|
const content = this.content[this._source.data];
|
2020-08-31 02:59:47 +02:00
|
|
|
return headerBar + "<div class='tab-content'>" + (content?.Render() ?? "") + "</div>";
|
2020-08-27 18:44:16 +02:00
|
|
|
}
|
2020-07-29 15:05:19 +02:00
|
|
|
|
2020-08-27 18:44:16 +02:00
|
|
|
protected InnerUpdate(htmlElement: HTMLElement) {
|
2020-08-31 02:59:47 +02:00
|
|
|
|
2020-08-27 18:44:16 +02:00
|
|
|
super.InnerUpdate(htmlElement);
|
|
|
|
this.content[this._source.data].Update();
|
2020-07-29 15:05:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|