flotilla/src/app/components/Toast.svelte

39 lines
1.2 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"
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/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">
{@html renderAsHtml(parse({content: $toast.message}))}
2025-07-30 22:54:10 +00:00
{#if $toast.action}
<Button class="cursor-pointer underline" onclick={onActionClick}>
{$toast.action.message}
</Button>
{/if}
</p>
<Button class="flex items-center opacity-75" onclick={() => popToast($toast.id)}>
2024-11-18 23:58:40 +00:00
<Icon icon="close-circle" />
</Button>
2024-08-08 23:32:46 +00:00
</div>
{/key}
</div>
2024-08-08 23:32:46 +00:00
{/if}