about summary refs log tree commit diff
path: root/assets/src/components/Toasts.svelte
blob: f909831106fbeb144a49e747671e6d22563d5119 (plain)
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
70
71
72
73
74
75
76
77
<script lang="ts">
    import { dismissToast, toasts, ToastType } from "../state/toast";
    import { scale } from "svelte/transition";
    import CloseIcon from "./icons/CloseIcon.svelte";
    import FlashIcon from "./icons/FlashIcon.svelte";
    import LightbulbIcon from "./icons/LightbulbIcon.svelte";

    function trim(str: string) {
        return str.slice(0, 100) + (str.length > 100 ? "..." : "");
    }
</script>

<div class="toasts">
    {#each $toasts as toast (toast.id)}
        <ul class="toast" in:scale out:scale>
            <div class="button" on:click={() => dismissToast(toast)}>
                <CloseIcon color="white" />
            </div>

            <li>
                {#if toast.type === ToastType.INFO}
                    <LightbulbIcon color="white" />
                {:else}
                    <FlashIcon color="white" />
                {/if}
            </li>

            {#if toast.title}
                <li class="title">{toast.title}</li>
            {/if}

            <li class="message">{trim(toast.message)}</li>
        </ul>
    {/each}
</div>

<style>
    .toasts {
        position: fixed;
        bottom: 0;
        display: flex;
        align-items: center;
        width: 100%;
        z-index: 1;
        flex-direction: column-reverse;
    }

    .toast {
        width: 300px;
        background-color: black;
        border: solid 1px #626262;
        padding: 17px 20px;
        font-size: 12px;
        line-height: 1.5rem;
        position: relative;
    }

    .title {
        font-size: 16px;
    }

    .message {
        color: #626262;
        font-size: 12px;
        line-height: 1.2rem;
        word-wrap: anywhere;
    }

    ul {
        list-style-type: none;
    }

    .button {
        position: absolute;
        right: 20px;
    }
</style>