2024-08-08 23:32:46 +00:00
|
|
|
<script lang="ts">
|
2025-05-07 22:04:35 +00:00
|
|
|
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">
|
2024-10-11 00:09:01 +00:00
|
|
|
{#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"}>
|
2025-08-19 21:03:04 +00:00
|
|
|
<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}
|
2025-05-07 22:04:35 +00:00
|
|
|
</p>
|
2025-02-04 01:21:46 +00:00
|
|
|
<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>
|
2024-10-11 00:09:01 +00:00
|
|
|
{/key}
|
|
|
|
|
</div>
|
2024-08-08 23:32:46 +00:00
|
|
|
{/if}
|