File tree Expand file tree Collapse file tree 2 files changed +29
-10
lines changed Expand file tree Collapse file tree 2 files changed +29
-10
lines changed Original file line number Diff line number Diff line change @@ -17,12 +17,17 @@ let unlisten
17
17
18
18
const progress = tweened (item .initial , { duration: item .duration , easing: linear })
19
19
20
- function close () {
20
+ function close (details ) {
21
+ item .details = details
21
22
toast .pop (item .id )
22
23
}
23
24
24
25
function autoclose () {
25
- if ($progress === 1 || $progress === 0 ) close ()
26
+ if ($progress === 1 || $progress === 0 )
27
+ close ({
28
+ autoClose: true ,
29
+ originalEvent: null
30
+ })
26
31
}
27
32
28
33
function pause () {
@@ -77,7 +82,7 @@ onMount(listen)
77
82
onDestroy (() => {
78
83
if (check (item .onpop , ' function' )) {
79
84
// @ts-ignore
80
- item .onpop (item .id )
85
+ item .onpop (item .id , item . details )
81
86
}
82
87
unlisten && unlisten ()
83
88
})
@@ -104,9 +109,13 @@ onDestroy(() => {
104
109
class =" _toastBtn pe"
105
110
role =" button"
106
111
tabindex =" 0"
107
- on:click ={close }
112
+ on:click ={(ev ) =>
113
+ close ({
114
+ autoClose: false ,
115
+ originalEvent: ev
116
+ })}
108
117
on:keydown ={(e ) => {
109
- if (e instanceof KeyboardEvent && [' Enter' , ' ' ].includes (e .key )) close ()
118
+ if (e instanceof KeyboardEvent && [' Enter' , ' ' ].includes (e .key )) close (e )
110
119
}}
111
120
/>
112
121
{/if }
Original file line number Diff line number Diff line change @@ -298,16 +298,26 @@ toast.pop(0)`,
298
298
{
299
299
name: ' RUN CALLBACK ON TOAST REMOVAL' ,
300
300
code: ` toast.push('Wait for it...', {
301
- onpop: () => {
302
- toast.push('onpop() callback has been executed.', { target: 'new' })
303
- }
304
- })` ,
301
+ onpop: (id, details) => {
302
+ toast.push('onpop() callback has been executed.', { target: 'new' })
303
+ if (details.autoClose) {
304
+ console.log('closed automatically')
305
+ } else {
306
+ console.log('closed by user', details.originalEvent)
307
+ }
308
+ }
309
+ })` ,
305
310
run : () =>
306
311
toast .push (' Wait for it...' , {
307
- onpop : () => {
312
+ onpop : (id , details ) => {
308
313
toast .push (` <strong><tt>onpop()</tt></strong> callback has been executed.` , {
309
314
target: ' new'
310
315
})
316
+ if (details .autoClose ) {
317
+ console .log (' closed automatically' )
318
+ } else {
319
+ console .log (' closed by user' , details .originalEvent )
320
+ }
311
321
}
312
322
})
313
323
},
You can’t perform that action at this time.
0 commit comments