mapcomplete/UI/Base/SubtleButton.ts

54 lines
1.6 KiB
TypeScript
Raw Normal View History

import {UIElement} from "../UIElement";
import Translations from "../i18n/Translations";
import Combine from "./Combine";
2020-09-15 02:29:31 +02:00
import {FixedUiElement} from "./FixedUiElement";
export class SubtleButton extends UIElement{
2020-09-15 02:29:31 +02:00
private readonly image: UIElement;
2020-09-02 11:37:34 +02:00
private readonly message: UIElement;
private readonly linkTo: { url: string, newTab?: boolean } = undefined;
2020-09-15 02:29:31 +02:00
constructor(imageUrl: string | UIElement, message: string | UIElement, linkTo: { url: string, newTab?: boolean } = undefined) {
super(undefined);
2020-07-29 19:02:36 +02:00
this.linkTo = linkTo;
this.message = Translations.W(message);
2020-09-15 02:29:31 +02:00
if(this.message !== null){
this.message.dumbMode = false;
}
if ((imageUrl ?? "") === "") {
this.image = new FixedUiElement("");
} else if (typeof (imageUrl) === "string") {
this.image = new FixedUiElement(`<img src="${imageUrl}">`);
} else {
this.image = imageUrl;
}
}
InnerRender(): string {
2020-09-02 11:37:34 +02:00
if(this.message !== null && this.message.IsEmpty()){
2020-09-15 02:29:31 +02:00
// Message == null: special case to force empty text
return "";
}
2020-07-29 19:02:36 +02:00
if(this.linkTo != undefined){
return new Combine([
`<a class="subtle-button" href="${this.linkTo.url}" ${this.linkTo.newTab ? 'target="_blank"' : ""}>`,
2020-09-15 02:29:31 +02:00
this.image,
this.message,
2020-07-29 19:02:36 +02:00
'</a>'
]).Render();
}
return new Combine([
'<span class="subtle-button">',
2020-09-15 02:29:31 +02:00
this.image,
this.message,
'</span>'
]).Render();
}
}