1
1
<script >
2
- import { tick } from ' svelte'
2
+ /* eslint no-useless-escape: "off" */
3
+ /* global PUBLIC_VERSION */
4
+
3
5
import { SvelteToast , toast } from ' $lib'
6
+ import { tick } from ' svelte'
7
+ import { browser , dev } from ' $app/environment'
4
8
import DummyComponent from ' ./Dummy.svelte'
5
9
import camelCase from ' camelcase'
6
10
import Prism from ' prismjs'
7
11
8
- // @ts-ignore
12
+ // Hoist to `window` for debug
13
+ if (browser) window .toast = toast
14
+
9
15
const version = PUBLIC_VERSION
10
16
11
17
let selected
@@ -19,9 +25,7 @@ const buttons = [
19
25
{
20
26
name: ' DEFAULT' ,
21
27
code: ` toast.push('Hello world!')` ,
22
- run : () => {
23
- toast .push (' Hello world!' )
24
- }
28
+ run : () => toast .push (' Hello world!' )
25
29
},
26
30
{
27
31
name: ' COLORED TOAST' ,
@@ -32,25 +36,23 @@ const buttons = [
32
36
'--toastBarBackground': '#2F855A'
33
37
}
34
38
})` ,
35
- run : () => {
39
+ run : () =>
36
40
toast .push (' Success!' , {
37
41
theme: {
38
42
' --toastColor' : ' mintcream' ,
39
43
' --toastBackground' : ' rgba(72,187,120,0.9)' ,
40
44
' --toastBarBackground' : ' #2F855A'
41
45
}
42
46
})
43
- }
44
47
},
45
48
{
46
49
name: ' RICH HTML' ,
47
50
code: ` toast.push(\` <strong>You won the jackpot!</strong><br>
48
51
Click <a href="#" target="_blank">here</a> for details! 😛\` )` ,
49
- run : () => {
52
+ run : () =>
50
53
toast .push (
51
54
' <strong>You won the jackpot!</strong><br>Click <a href="#" target="_blank">here</a> for details! 😛'
52
55
)
53
- }
54
56
},
55
57
{
56
58
name: ' HIDE PROGRESS BAR' ,
@@ -59,30 +61,20 @@ const buttons = [
59
61
'--toastBarHeight': 0
60
62
}
61
63
})` ,
62
- run : () => {
63
- toast .push (' Hide the progress bar' , {
64
- theme: {
65
- ' --toastBarHeight' : 0
66
- }
67
- })
68
- }
64
+ run : () => toast .push (' Hide the progress bar' , { theme: { ' --toastBarHeight' : 0 } })
69
65
},
70
66
{
71
67
name: ' LONG DURATION' ,
72
68
code: ` toast.push('Watching the paint dry...', { duration: 20000 })` ,
73
- run : () => {
74
- toast .push (' Watching the paint dry...' , { duration: 20000 })
75
- }
69
+ run : () => toast .push (' Watching the paint dry...' , { duration: 20000 })
76
70
},
77
71
{
78
72
name: ' NO EXPIRY' ,
79
73
code: ` toast.push('Tap button to dismiss', {
80
74
// Effectively disables autoclose when \` initial\` ==\` next\`
81
75
initial: 0
82
76
})` ,
83
- run : () => {
84
- toast .push (' Tap button to dismiss' , { initial: 0 })
85
- }
77
+ run : () => toast .push (' Tap button to dismiss' , { initial: 0 })
86
78
},
87
79
{
88
80
name: ' NON-DISMISSABLE' ,
@@ -91,9 +83,7 @@ const buttons = [
91
83
initial: 0,
92
84
dismissable: false
93
85
})` ,
94
- run : () => {
95
- toast .push (' Where the close btn?!?' , { initial: 0 , dismissable: false })
96
- }
86
+ run : () => toast .push (' Where the close btn?!?' , { initial: 0 , dismissable: false })
97
87
},
98
88
{
99
89
name: ' REMOVE LAST TOAST' ,
@@ -103,9 +93,7 @@ toast.pop()
103
93
// Or remove a particular one
104
94
const id = toast.push('Yo!')
105
95
toast.pop(id)` ,
106
- run : () => {
107
- toast .pop ()
108
- }
96
+ run : () => toast .pop ()
109
97
},
110
98
{
111
99
name: ' FLIP PROGRESS BAR' ,
@@ -115,13 +103,12 @@ toast.pop(id)`,
115
103
next: 1,
116
104
duration: 6000
117
105
})` ,
118
- run : () => {
106
+ run : () =>
119
107
toast .push (' Progress bar is flipped' , {
120
108
initial: 0 ,
121
109
next: 1 ,
122
110
duration: 6000
123
111
})
124
- }
125
112
},
126
113
{
127
114
name: ' USE AS LOADING INDICATOR' ,
@@ -244,9 +231,8 @@ toast.set(id, { next: 1 })`,
244
231
}
245
232
}
246
233
</style>` ,
247
- run : () => {
234
+ run : () =>
248
235
toast .push (' <strong>NEW:</strong> Multiple toast container support!' , { target: ' new' })
249
- }
250
236
},
251
237
{
252
238
name: ' REMOVE ALL TOASTS FROM CONTAINER' ,
@@ -255,9 +241,7 @@ toast.pop(i => i.target !== 'new')
255
241
256
242
// Or remove ALL active toasts from ALL containers
257
243
toast.pop(0)` ,
258
- run : () => {
259
- toast .pop ((i ) => i .target !== ' new' )
260
- }
244
+ run : () => toast .pop ((i ) => i .target !== ' new' )
261
245
},
262
246
{
263
247
name: ' SEND COMPONENT AS A MESSAGE' ,
@@ -309,9 +293,7 @@ toast.pop(0)`,
309
293
{
310
294
name: ' PAUSE ON MOUSE HOVER' ,
311
295
code: ` toast.push('Hover me!', { pausable: true })` ,
312
- run : () => {
313
- toast .push (' Hover me!' , { pausable: true })
314
- }
296
+ run : () => toast .push (' Hover me!' , { pausable: true })
315
297
},
316
298
{
317
299
name: ' RUN CALLBACK ON TOAST REMOVAL' ,
@@ -320,15 +302,14 @@ toast.pop(0)`,
320
302
toast.push('onpop() callback has been executed.', { target: 'new' })
321
303
}
322
304
})` ,
323
- run : () => {
305
+ run : () =>
324
306
toast .push (' Wait for it...' , {
325
307
onpop : () => {
326
308
toast .push (` <strong><tt>onpop()</tt></strong> callback has been executed.` , {
327
309
target: ' new'
328
310
})
329
311
}
330
312
})
331
- }
332
313
},
333
314
{
334
315
name: ' STYLE WITH USER-DEFINED CLASSES' ,
@@ -363,7 +344,7 @@ toast.pop(0)`,
363
344
'--toastBtnContent': \` url("data:image/svg+xml,...")\`
364
345
}
365
346
}` ,
366
- run : () => {
347
+ run : () =>
367
348
toast .push (' Say cheese!' , {
368
349
theme: {
369
350
// @ts-ignore
@@ -372,15 +353,14 @@ toast.pop(0)`,
372
353
: `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24px' height='24px' fill='%23F1CB30' viewBox='0 0 512 512' xml:space='preserve'%3E%3Cpath d='M256,0C114.842,0,0,114.842,0,256s114.842,256,256,256s256-114.842,256-256S397.158,0,256,0z'/%3E%3Cg%3E%3Cpath style='fill:%2357575C;' d='M355.297,175.321c-8.161,0-16.167,3.305-21.938,9.092c-5.773,5.772-9.092,13.762-9.092,21.938 c0,8.163,3.32,16.168,9.092,21.94c5.772,5.772,13.777,9.09,21.938,9.09c8.161,0,16.167-3.32,21.938-9.09 c5.773-5.772,9.092-13.777,9.092-21.94c0-8.176-3.32-16.167-9.092-21.938C371.464,178.626,363.472,175.321,355.297,175.321z'/%3E%3Cpath style='fill:%2357575C;' d='M178.641,228.291c5.773-5.772,9.092-13.762,9.092-21.94c0-8.176-3.32-16.167-9.092-21.938 c-5.772-5.787-13.777-9.092-21.938-9.092c-8.161,0-16.167,3.305-21.938,9.092c-5.772,5.772-9.092,13.762-9.092,21.938 c0,8.176,3.32,16.168,9.092,21.94c5.772,5.786,13.777,9.09,21.938,9.09C164.864,237.382,172.87,234.077,178.641,228.291z'/%3E%3C/g%3E%3Cpath style='fill:%23DF6246;' d='M356.49,326.085c-3.603-8.696-12.088-14.367-21.501-14.367H256h-78.991 c-9.413,0-17.898,5.671-21.501,14.367c-3.601,8.696-1.61,18.708,5.046,25.363c25.495,25.493,59.392,39.534,95.446,39.534 s69.952-14.041,95.446-39.534C358.102,344.792,360.093,334.78,356.49,326.085z'/%3E%3Cpath style='fill:%23E69629;' d='M160.552,351.448c-6.656-6.654-8.647-16.665-5.046-25.363c3.603-8.696,12.088-14.367,21.501-14.367 H256V0C114.842,0,0,114.842,0,256s114.842,256,256,256V390.982C219.946,390.982,186.048,376.941,160.552,351.448z M125.673,206.352 c0-8.176,3.32-16.167,9.092-21.938c5.772-5.787,13.777-9.092,21.938-9.092c8.161,0,16.167,3.305,21.938,9.092 c5.773,5.772,9.092,13.762,9.092,21.938c0,8.176-3.32,16.168-9.092,21.94c-5.772,5.786-13.777,9.09-21.938,9.09 c-8.161,0-16.167-3.305-21.938-9.09C128.993,222.52,125.673,214.528,125.673,206.352z'/%3E%3Cpath style='fill:%23DD512A;' d='M177.009,311.718c-9.413,0-17.898,5.671-21.501,14.367c-3.601,8.696-1.61,18.708,5.046,25.363 c25.495,25.493,59.39,39.534,95.445,39.534v-79.264H177.009z'/%3E%3C/svg%3E")`
373
354
}
374
355
})
375
- }
376
356
}
377
357
]
378
358
379
359
function clicked (btn ) {
380
360
selected = btn .name
381
361
code = btn .code
382
362
btn .run ()
383
- window .gtag (' event' , ' toast' , { event_label: btn .name })
363
+ if (browser && ! dev) window .gtag (' event' , ' toast' , { event_label: btn .name })
384
364
}
385
365
386
366
$: formatted = Prism .highlight (code, Prism .languages .javascript , ' javascript' )
@@ -405,10 +385,10 @@ $: formatted = Prism.highlight(code, Prism.languages.javascript, 'javascript')
405
385
rel= " noreferrer" > GITHUB v{version}< / a
406
386
>
407
387
< / div>
408
- < p class = " text-center mb-6" >
409
- Simple elegant toast notifications for modern web frontends in very little lines of code.< br / >
410
- Because a demo helps better than a thousand API docs, so here it is.< br / >
411
- Use in Vanilla JS ( 8kb gzipped) or as a Svelte component.
388
+ < p class = " max-w-2xl mx-auto text-center mb-6" >
389
+ Simple elegant toast notifications for modern web frontends in very little lines of code.
390
+ Because a demo helps better than a thousand API docs, so here it is . Use in Vanilla JS ( 8kb
391
+ gzipped) or as a Svelte component.
412
392
< / p>
413
393
< div class = " mockup-code h-80 mb-4 text-sm overflow-auto" >
414
394
< pre>< code class = " language-javascript" > {@html formatted}< / code>< / pre>
0 commit comments