2020-07-29 16:46:45 +02:00
|
|
|
import Translations from "../i18n/Translations";
|
|
|
|
import Combine from "./Combine";
|
2021-06-10 01:36:20 +02:00
|
|
|
import BaseUIElement from "../BaseUIElement";
|
|
|
|
import Link from "./Link";
|
|
|
|
import Img from "./Img";
|
|
|
|
import {UIEventSource} from "../../Logic/UIEventSource";
|
2021-06-12 02:58:32 +02:00
|
|
|
import {UIElement} from "../UIElement";
|
2020-07-29 16:46:45 +02:00
|
|
|
|
|
|
|
|
2021-06-12 02:58:32 +02:00
|
|
|
export class SubtleButton extends UIElement {
|
2021-12-21 19:09:24 +01:00
|
|
|
private readonly imageUrl: string | BaseUIElement;
|
|
|
|
private readonly message: string | BaseUIElement;
|
|
|
|
private readonly linkTo: { url: string | UIEventSource<string>; newTab?: boolean };
|
2020-07-29 16:46:45 +02:00
|
|
|
|
2021-05-30 00:17:31 +02:00
|
|
|
|
2021-06-12 02:58:32 +02:00
|
|
|
constructor(imageUrl: string | BaseUIElement, message: string | BaseUIElement, linkTo: { url: string | UIEventSource<string>, newTab?: boolean } = undefined) {
|
|
|
|
super();
|
2021-12-21 19:09:24 +01:00
|
|
|
this.imageUrl = imageUrl;
|
|
|
|
this.message = message;
|
|
|
|
this.linkTo = linkTo;
|
2021-05-30 00:17:31 +02:00
|
|
|
}
|
|
|
|
|
2021-12-21 19:09:24 +01:00
|
|
|
protected InnerRender(): string | BaseUIElement {
|
2022-02-01 04:14:54 +01:00
|
|
|
const classes = "block flex p-3 my-2 bg-subtle rounded-lg hover:shadow-xl hover:bg-unsubtle transition-colors transition-shadow link-no-underline";
|
2021-12-21 19:09:24 +01:00
|
|
|
const message = Translations.W(this.message);
|
2021-01-18 19:36:19 +01:00
|
|
|
let img;
|
2021-12-21 19:09:24 +01:00
|
|
|
if ((this.imageUrl ?? "") === "") {
|
2021-06-10 01:36:20 +02:00
|
|
|
img = undefined;
|
2021-12-21 19:09:24 +01:00
|
|
|
} else if (typeof (this.imageUrl) === "string") {
|
|
|
|
img = new Img(this.imageUrl)
|
2020-09-15 02:29:31 +02:00
|
|
|
} else {
|
2021-12-21 19:09:24 +01:00
|
|
|
img = this.imageUrl;
|
2020-09-15 02:29:31 +02:00
|
|
|
}
|
2021-06-18 01:25:13 +02:00
|
|
|
img?.SetClass("block flex items-center justify-center h-11 w-11 flex-shrink0 mr-4")
|
2021-05-30 00:17:31 +02:00
|
|
|
const image = new Combine([img])
|
2021-01-25 03:12:09 +01:00
|
|
|
.SetClass("flex-shrink-0");
|
2021-06-12 02:58:32 +02:00
|
|
|
|
2021-12-21 19:09:24 +01:00
|
|
|
if (this.linkTo == undefined) {
|
|
|
|
this.SetClass(classes)
|
2021-06-12 02:58:32 +02:00
|
|
|
return new Combine([
|
2021-05-30 00:17:31 +02:00
|
|
|
image,
|
2021-06-18 01:25:13 +02:00
|
|
|
message?.SetClass("block overflow-ellipsis"),
|
2021-06-16 21:23:03 +02:00
|
|
|
]).SetClass("flex group w-full");
|
2020-07-29 19:02:36 +02:00
|
|
|
}
|
2021-05-30 00:17:31 +02:00
|
|
|
|
2021-06-12 02:58:32 +02:00
|
|
|
|
|
|
|
return new Link(
|
|
|
|
new Combine([
|
|
|
|
image,
|
2021-06-18 01:25:13 +02:00
|
|
|
message?.SetClass("block overflow-ellipsis")
|
2021-06-16 21:23:03 +02:00
|
|
|
]).SetClass("flex group w-full"),
|
2021-12-21 19:09:24 +01:00
|
|
|
this.linkTo.url,
|
|
|
|
this.linkTo.newTab ?? false
|
|
|
|
).SetClass(classes)
|
2021-06-12 02:58:32 +02:00
|
|
|
|
2020-07-29 16:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|