forked from quoid/userscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotification.svelte
More file actions
146 lines (123 loc) · 3.46 KB
/
Copy pathNotification.svelte
File metadata and controls
146 lines (123 loc) · 3.46 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<script>
// inspired by https://github.com/zerodevx/svelte-toast
import {onMount} from "svelte";
import {fade, fly} from "svelte/transition";
import {tweened} from "svelte/motion";
import {linear} from "svelte/easing";
import {notifications} from "../store.js";
import IconButton from "../../shared/Components/IconButton.svelte";
import iconClose from "../../shared/img/icon-close.svg?raw";
import iconError from "../../shared/img/icon-error.svg?raw";
import iconInfo from "../../shared/img/icon-info.svg?raw";
import iconWarn from "../../shared/img/icon-warn.svg?raw";
export let item;
const timeout = 5000;
const progress = tweened(1, {duration: timeout, easing: linear});
const icon = item.type === "error" ? iconError : item.type === "info" ? iconInfo : iconWarn;
let previousProgress;
function pause() {
previousProgress = $progress;
progress.set($progress, {duration: 0});
}
function resume() {
progress.set(0, {duration: timeout * previousProgress});
}
$: if (!$progress) notifications.remove(item.id);
onMount(() => progress.set(0));
</script>
<li
class:error={item.type === "error"}
class:info={item.type === "info"}
class:warn={item.type === "warn"}
in:fly={{y: 24, duration: 150}}
out:fade={{duration: 150}}
on:mouseover={pause}
on:mouseout={resume}
>
<progress value={$progress}></progress>
<div>
<div class="icon">{@html icon}</div>
<span>{item.message}</span>
<IconButton icon={iconClose} on:click/>
</div>
</li>
<style>
li {
background-color: var(--color-black);
border: 1px solid black;
border-radius: var(--border-radius);
box-shadow: var(--box-shadow);
color: var(--text-color-secondary);
font: var(--text-medium);
line-height: 1.25rem;
margin-bottom: 0.5rem;
width: 20rem;
}
progress,
progress::-webkit-progress-bar,
progress::-webkit-progress-value {
border-radius: var(--border-radius) 0 0 0;
}
progress {
appearance: none;
background: transparent;
border: none;
display: block;
filter: brightness(0.8);
height: 0.125rem;
pointer-events: none;
width: 100%;
}
progress::-webkit-progress-bar {
background-color: transparent;
}
progress::-webkit-progress-value {
background-color: var(--color-blue);
}
.error progress::-webkit-progress-value {
background-color: var(--color-red);
}
.warn progress::-webkit-progress-value {
background-color: var(--color-yellow);
}
li > div {
align-items: start;
display: flex;
padding: 0.5rem 1rem;
}
.icon {
align-items: center;
display: flex;
flex-shrink: 0;
height: 1.25rem;
justify-content: center;
width: 1.5rem;
}
.error .icon {
color: var(--color-red);
}
.info .icon {
color: var(--color-blue);
}
.warn .icon {
color: var(--color-yellow);
}
.icon :global(svg) {
fill: currentcolor;
height: auto;
pointer-events: none;
width: 66.7%;
}
li:last-child {
margin-bottom: 0;
}
span {
flex-grow: 1;
margin: 0 1rem 0 0.25rem;
}
li :global(button) {
flex-shrink: 0;
height: 1.25rem;
width: 1rem;
}
</style>