-
-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathSvelteToast.svelte
52 lines (45 loc) · 1.26 KB
/
SvelteToast.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
<script>
import { fade, fly } from 'svelte/transition'
import { flip } from 'svelte/animate'
import { toast } from './stores.js'
import ToastItem from './ToastItem.svelte'
/** @type {import('./stores.js').SvelteToastOptions} */
export let options = {}
/** @type {(string|'default')} */
export let target = 'default'
/** @type {import('./stores.js').SvelteToastOptions[]} */
let items = []
/** @param {Object<string,string|number>} [theme] */
function getCss(theme) {
return theme ? Object.keys(theme).reduce((a, c) => `${a}${c}:${theme[c]};`, '') : undefined
}
$: toast._init(target, options)
$: items = $toast.filter((i) => i.target === target)
</script>
<ul class="_toastContainer">
{#each items as item (item.id)}
<li
class={item.classes?.join(' ')}
in:fly={item.intro}
out:fade
animate:flip={{ duration: 200 }}
style={getCss(item.theme)}
>
<ToastItem {item} />
</li>
{/each}
</ul>
<style>
._toastContainer {
top: var(--toastContainerTop, 1.5rem);
right: var(--toastContainerRight, 2rem);
bottom: var(--toastContainerBottom, auto);
left: var(--toastContainerLeft, auto);
position: fixed;
margin: 0;
padding: 0;
list-style-type: none;
pointer-events: none;
z-index: var(--toastContainerZIndex, 9999);
}
</style>