forked from MapComplete/MapComplete
Refactoring: move all code files into a src directory
This commit is contained in:
parent
de99f56ca8
commit
e75d2789d2
389 changed files with 0 additions and 12 deletions
52
src/UI/Base/List.ts
Normal file
52
src/UI/Base/List.ts
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
import { Utils } from "../../Utils"
|
||||
import BaseUIElement from "../BaseUIElement"
|
||||
import Translations from "../i18n/Translations"
|
||||
|
||||
export default class List extends BaseUIElement {
|
||||
private readonly uiElements: BaseUIElement[]
|
||||
private readonly _ordered: boolean
|
||||
|
||||
constructor(uiElements: (string | BaseUIElement)[], ordered = false) {
|
||||
super()
|
||||
this._ordered = ordered
|
||||
this.uiElements = Utils.NoNull(uiElements).map((s) => Translations.W(s))
|
||||
}
|
||||
|
||||
AsMarkdown(): string {
|
||||
if (this._ordered) {
|
||||
return (
|
||||
"\n\n" +
|
||||
this.uiElements
|
||||
.map((el, i) => " " + i + ". " + el.AsMarkdown().replace(/\n/g, " \n"))
|
||||
.join("\n") +
|
||||
"\n"
|
||||
)
|
||||
} else {
|
||||
return (
|
||||
"\n\n" +
|
||||
this.uiElements
|
||||
.map((el) => " - " + el.AsMarkdown().replace(/\n/g, " \n"))
|
||||
.join("\n") +
|
||||
"\n"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
protected InnerConstructElement(): HTMLElement {
|
||||
const el = document.createElement(this._ordered ? "ol" : "ul")
|
||||
|
||||
for (const subEl of this.uiElements) {
|
||||
if (subEl === undefined || subEl === null) {
|
||||
continue
|
||||
}
|
||||
const subHtml = subEl.ConstructElement()
|
||||
if (subHtml !== undefined) {
|
||||
const item = document.createElement("li")
|
||||
item.appendChild(subHtml)
|
||||
el.appendChild(item)
|
||||
}
|
||||
}
|
||||
|
||||
return el
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue