flotilla/src/app/components/Toast.svelte

45 lines
1.5 KiB
Svelte
Raw Normal View History

2024-08-08 23:32:46 +00:00
<script lang="ts">
import {parse, renderAsHtml} from "@welshman/content"
2024-08-08 23:32:46 +00:00
import {fly} from "@lib/transition"
2025-09-10 22:26:39 +00:00
import CloseCircle from "@assets/icons/close-circle.svg?dataurl"
2024-11-18 23:58:40 +00:00
import Icon from "@lib/components/Icon.svelte"
import Button from "@lib/components/Button.svelte"
import {toast, popToast} from "@app/util/toast"
2025-07-30 22:54:10 +00:00
const onActionClick = () => {
$toast!.action!.onclick()
popToast($toast!.id)
}
2024-08-08 23:32:46 +00:00
</script>
{#if $toast}
2024-08-23 20:33:36 +00:00
{@const theme = $toast.theme || "info"}
2025-05-08 18:05:27 +00:00
<div transition:fly class="bottom-sai right-sai toast z-toast">
{#key $toast.id}
2024-08-16 17:50:38 +00:00
<div
role="alert"
2024-11-27 00:39:49 +00:00
class="alert flex justify-center whitespace-normal text-left"
2024-10-15 18:48:11 +00:00
class:bg-base-100={theme === "info"}
class:text-base-content={theme === "info"}
2024-08-23 20:33:36 +00:00
class:alert-error={theme === "error"}>
<p class:welshman-content-error={theme === "error"}>
{#if $toast.message}
{@html renderAsHtml(parse({content: $toast.message}))}
{#if $toast.action}
<Button class="cursor-pointer underline" onclick={onActionClick}>
{$toast.action.message}
</Button>
{/if}
{:else if $toast.children}
{@const {component: Component, props} = $toast?.children || {}}
<Component toast={$toast} {...props} />
2025-07-30 22:54:10 +00:00
{/if}
</p>
<Button class="flex items-center opacity-75" onclick={() => popToast($toast.id)}>
2025-09-10 22:26:39 +00:00
<Icon icon={CloseCircle} />
2024-11-18 23:58:40 +00:00
</Button>
2024-08-08 23:32:46 +00:00
</div>
{/key}
</div>
2024-08-08 23:32:46 +00:00
{/if}