@@ -6,9 +6,16 @@ import { toast } from './stores.js'
6
6
export let item
7
7
8
8
const progress = tweened (item .initial , { duration: item .duration , easing: linear })
9
+ const close = () => {
10
+ const { id , onpop } = item
11
+ toast .pop (id)
12
+ if (typeof onpop === ' function' ) {
13
+ onpop (id)
14
+ }
15
+ }
9
16
const autoclose = () => {
10
17
if ($progress === 1 || $progress === 0 ) {
11
- toast . pop ( item . id )
18
+ close ( )
12
19
}
13
20
}
14
21
let next = item .initial
@@ -31,8 +38,9 @@ const pause = () => {
31
38
32
39
const resume = () => {
33
40
if (paused) {
34
- const remaining = item .duration - item .duration * (($progress - prev) / (next - prev))
35
- progress .set (next, { duration: remaining }).then (autoclose)
41
+ const d = item .duration
42
+ const duration = d - d * (($progress - prev) / (next - prev))
43
+ progress .set (next, { duration }).then (autoclose)
36
44
paused = false
37
45
}
38
46
}
@@ -60,11 +68,7 @@ $: if (typeof item.progress !== 'undefined') {
60
68
padding : var (--toastPadding , 0 );
61
69
background : var (--toastBackground , rgba (66 , 66 , 66 , 0.9 ));
62
70
color : var (--toastColor , #fff );
63
- box-shadow : var (
64
- --toastBoxShadow ,
65
- 0 4px 6px -1px rgba (0 , 0 , 0 , 0.1 ),
66
- 0 2px 4px -1px rgba (0 , 0 , 0 , 0.06 )
67
- );
71
+ box-shadow : var (--toastBoxShadow , 0 4px 6px -1px rgba (0 , 0 , 0 , 0.1 ), 0 2px 4px -1px rgba (0 , 0 , 0 , 0.06 ));
68
72
border : var (--toastBorder , none );
69
73
border-radius : var (--toastBorderRadius , 0.125rem );
70
74
position : relative ;
@@ -112,7 +116,7 @@ $: if (typeof item.progress !== 'undefined') {
112
116
._toastBar ::-webkit-progress-bar {
113
117
background : transparent ;
114
118
}
115
- /* `--toastProgressBackground` has been renamed to `--toastBarBackground`; override included for backward compatibility */
119
+ /* `--toastProgressBackground` renamed to `--toastBarBackground`; override included for backward compatibility */
116
120
._toastBar ::-webkit-progress-value {
117
121
background : var (--toastProgressBackground , var (--toastBarBackground , rgba (33 , 150 , 243 , 0.75 )));
118
122
}
@@ -130,9 +134,7 @@ $: if (typeof item.progress !== 'undefined') {
130
134
{/if }
131
135
</div >
132
136
{#if item .dismissable }
133
- <div class ="_toastBtn pe" role ="button" tabindex ="-1" on:click ={() => toast .pop (item .id )}>
134
- ✕
135
- </div >
137
+ <div class ="_toastBtn pe" role ="button" tabindex ="-1" on:click ={close }>✕</div >
136
138
{/if }
137
139
<progress class ="_toastBar" value ={$progress } />
138
140
</div >
0 commit comments