2023-01-17 18:31:51 +01:00
|
|
|
<script lang="ts">
|
|
|
|
import { onMount } from "svelte"
|
|
|
|
import { Store } from "../../Logic/UIEventSource"
|
|
|
|
import BaseUIElement from "../BaseUIElement"
|
|
|
|
import Img from "./Img"
|
|
|
|
import Translations from "../i18n/Translations"
|
|
|
|
|
2023-02-03 22:28:11 +01:00
|
|
|
export let imageUrl: string | BaseUIElement = undefined
|
|
|
|
export let message: string | BaseUIElement = undefined
|
2023-02-03 16:11:46 +01:00
|
|
|
export let options: {
|
|
|
|
url?: string | Store<string>
|
|
|
|
newTab?: boolean
|
|
|
|
imgSize?: string
|
|
|
|
extraClasses?: string
|
2023-02-03 22:28:11 +01:00
|
|
|
} = {}
|
2023-01-17 18:31:51 +01:00
|
|
|
|
|
|
|
let href = typeof options?.url == "string" ? options.url : ""
|
|
|
|
|
2023-02-03 16:11:46 +01:00
|
|
|
let imgElem: HTMLElement
|
|
|
|
let msgElem: HTMLElement
|
|
|
|
|
2023-01-17 18:31:51 +01:00
|
|
|
onMount(() => {
|
|
|
|
if (typeof options?.url != "string" && options?.url != undefined) {
|
|
|
|
options.url.addCallbackAndRun((data) => {
|
|
|
|
href = data
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-02-03 16:11:46 +01:00
|
|
|
// Image
|
2023-02-03 22:28:11 +01:00
|
|
|
if (imgElem && imageUrl) {
|
2023-02-03 16:11:46 +01:00
|
|
|
let img: BaseUIElement
|
|
|
|
|
|
|
|
const imgClasses = "block justify-center flex-none mr-4 " + (options?.imgSize ?? "h-11 w-11")
|
|
|
|
if ((imageUrl ?? "") === "") {
|
|
|
|
img = undefined
|
|
|
|
} else if (typeof imageUrl === "string") {
|
|
|
|
img = new Img(imageUrl)?.SetClass(imgClasses)
|
|
|
|
} else {
|
|
|
|
img = imageUrl?.SetClass(imgClasses)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (img) imgElem.replaceWith(img.ConstructElement())
|
2023-01-17 18:31:51 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 16:11:46 +01:00
|
|
|
// Message
|
2023-02-03 22:28:11 +01:00
|
|
|
if (msgElem && message) {
|
2023-02-03 16:11:46 +01:00
|
|
|
let msg = Translations.W(message)?.SetClass("block text-ellipsis no-images flex-shrink")
|
|
|
|
msgElem.replaceWith(msg.ConstructElement())
|
|
|
|
}
|
2023-01-17 18:31:51 +01:00
|
|
|
})
|
|
|
|
</script>
|
|
|
|
|
2023-02-03 16:11:46 +01:00
|
|
|
<svelte:element
|
|
|
|
this={options?.url == undefined ? "span" : "a"}
|
2023-02-09 00:10:59 +01:00
|
|
|
class={(options.extraClasses??"") + ' hover:shadow-xl transition-[color,background-color,box-shadow] hover:bg-unsubtle'}
|
2023-02-03 16:11:46 +01:00
|
|
|
target={options?.newTab ? "_blank" : ""}
|
|
|
|
{href}
|
|
|
|
>
|
|
|
|
<slot name="image">
|
2023-02-09 00:10:59 +01:00
|
|
|
{#if imgElem}
|
|
|
|
<template bind:this={imgElem} />
|
|
|
|
{/if}
|
2023-02-03 16:11:46 +01:00
|
|
|
</slot>
|
|
|
|
<slot name="message">
|
|
|
|
<template bind:this={msgElem} />
|
|
|
|
</slot>
|
|
|
|
</svelte:element>
|
2023-01-17 18:31:51 +01:00
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
span,
|
|
|
|
a {
|
2023-02-09 00:10:59 +01:00
|
|
|
@apply flex p-3 my-2 rounded-lg ;
|
2023-02-03 16:11:46 +01:00
|
|
|
@apply items-center w-full no-underline;
|
2023-02-09 00:10:59 +01:00
|
|
|
@apply bg-subtle text-black;
|
2023-02-03 16:11:46 +01:00
|
|
|
|
|
|
|
:global(img) {
|
|
|
|
@apply block justify-center flex-none mr-4 h-11 w-11;
|
|
|
|
}
|
2023-02-03 22:28:11 +01:00
|
|
|
|
|
|
|
:global(span) {
|
|
|
|
@apply block text-ellipsis flex-shrink;
|
|
|
|
}
|
2023-01-17 18:31:51 +01:00
|
|
|
}
|
|
|
|
</style>
|