forked from MapComplete/MapComplete
More refactoring, stuff kindoff works
This commit is contained in:
parent
62f471df1e
commit
3943100e54
52 changed files with 635 additions and 1010 deletions
|
@ -1,41 +1,33 @@
|
|||
import {UIElement} from "../UIElement";
|
||||
import Translations from "../i18n/Translations";
|
||||
import {UIEventSource} from "../../Logic/UIEventSource";
|
||||
import Combine from "./Combine";
|
||||
import BaseUIElement from "../BaseUIElement";
|
||||
import {VariableUiElement} from "./VariableUIElement";
|
||||
|
||||
export class TabbedComponent extends UIElement {
|
||||
export class TabbedComponent extends Combine {
|
||||
|
||||
private readonly header: UIElement;
|
||||
private content: UIElement[] = [];
|
||||
|
||||
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)));
|
||||
const self = this;
|
||||
const tabs: UIElement[] = []
|
||||
constructor(elements: { header: BaseUIElement | string, content: BaseUIElement | string }[], openedTab: (UIEventSource<number> | number) = 0) {
|
||||
|
||||
const openedTabSrc = typeof (openedTab) === "number" ? new UIEventSource(openedTab) : (openedTab ?? new UIEventSource<number>(0))
|
||||
|
||||
const tabs: BaseUIElement[] = []
|
||||
const contentElements: BaseUIElement[] = [];
|
||||
for (let i = 0; i < elements.length; i++) {
|
||||
let element = elements[i];
|
||||
const header = Translations.W(element.header).onClick(() => self._source.setData(i))
|
||||
const header = Translations.W(element.header).onClick(() => openedTabSrc.setData(i))
|
||||
const content = Translations.W(element.content)
|
||||
this.content.push(content);
|
||||
if (!this.content[i].IsEmpty()) {
|
||||
const tab = header.SetClass("block tab-single-header")
|
||||
tabs.push(tab)
|
||||
}
|
||||
content.SetClass("tab-content")
|
||||
contentElements.push(content);
|
||||
const tab = header.SetClass("block tab-single-header")
|
||||
tabs.push(tab)
|
||||
}
|
||||
|
||||
this.header = new Combine(tabs).SetClass("block tabs-header-bar")
|
||||
const header = new Combine(tabs).SetClass("block tabs-header-bar")
|
||||
const actualContent = new VariableUiElement(
|
||||
openedTabSrc.map(i => contentElements[i])
|
||||
)
|
||||
super([header, actualContent])
|
||||
|
||||
|
||||
}
|
||||
|
||||
InnerRender(): UIElement {
|
||||
|
||||
const content = this.content[this._source.data];
|
||||
return new Combine([
|
||||
this.header,
|
||||
content.SetClass("tab-content"),
|
||||
])
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue