MapComplete/UI/Base/Button.ts

26 lines
766 B
TypeScript
Raw Normal View History

2020-07-25 18:00:08 +02:00
import Translations from "../i18n/Translations";
2021-06-12 02:58:32 +02:00
import BaseUIElement from "../BaseUIElement";
2020-06-29 03:12:44 +02:00
2021-06-15 00:55:12 +02:00
export class Button extends BaseUIElement {
2021-06-12 02:58:32 +02:00
private _text: BaseUIElement;
2020-06-29 03:12:44 +02:00
2022-08-22 19:16:37 +02:00
constructor(text: string | BaseUIElement, onclick: (() => void | Promise<void>)) {
2021-06-15 00:55:12 +02:00
super();
2020-07-25 18:00:08 +02:00
this._text = Translations.W(text);
2022-08-22 19:16:37 +02:00
this.onClick(onclick)
2020-06-29 03:12:44 +02:00
}
2021-06-15 00:55:12 +02:00
protected InnerConstructElement(): HTMLElement {
const el = this._text.ConstructElement();
if (el === undefined) {
2021-06-15 00:55:12 +02:00
return undefined;
2020-06-29 03:12:44 +02:00
}
2021-06-15 00:55:12 +02:00
const form = document.createElement("form")
const button = document.createElement("button")
button.type = "button"
button.appendChild(el)
form.appendChild(button)
return form;
2020-06-29 03:12:44 +02:00
}
}