-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBaseNotification.svelte
69 lines (63 loc) · 2.02 KB
/
BaseNotification.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<script lang="ts">
import {
Icon,
CheckCircle,
ExclamationCircle,
ExclamationTriangle,
InformationCircle,
XMark
} from "svelte-hero-icons";
import toast_, { type Renderable, type Toast } from "svelte-hot-french-toast";
import { clickOutside } from "..";
const {
...allProps
}: {
toast: Toast;
status: "success" | "info" | "loading" | "error" | "warning";
Content: Renderable;
} = $props();
const { toast, status, Content } = $derived(allProps);
const { position, visible, icon, id } = $derived(toast);
</script>
<div
use:clickOutside={() => toast_.dismiss(id)}
role="status"
class="notification-{status} relative flex max-w-sm transform-gpu flex-row items-start justify-between space-x-2 rounded-xl bg-base-200 p-4 shadow-center shadow-accent transition-all duration-500 ease-in-out {position!.substring(
0,
3
) == 'top'
? `hover:translate-y-1 ${visible ? 'top-0' : '-top-96'}`
: `hover:-translate-y-1 ${visible ? 'bottom-0' : '-bottom-96'}`}"
>
<div class="self-center leading-[0]">
{#if icon}
<Icon src={icon} class="h-6 w-6" />
{:else if status === "success"}
<Icon src={CheckCircle} class="w-7 text-success" />
{:else if status === "loading"}
<span class="loading loading-spinner w-6"></span>
{:else if status === "error"}
<Icon src={ExclamationCircle} class="w-7 text-error" />
{:else if status === "info"}
<Icon src={InformationCircle} class="w-7 text-info" />
{:else if status === "warning"}
<Icon src={ExclamationTriangle} class="w-7 text-warning" />
{/if}
</div>
<div class="overflow-x-hidden whitespace-pre-line break-words" class:mt-1={icon}>
{#if typeof Content === "string"}
{Content}
{:else}
{#key Content}
<Content {...allProps} />
{/key}
{/if}
</div>
<button class="cursor-pointer text-lg" class:mt-1={icon}>
<Icon
src={XMark}
class="notification-close w-6 cursor-pointer"
onclick={() => toast_.remove(id)}
/>
</button>
</div>