11
11
A lightweight, unopinionated and performant toast notification component for modern web frontends in
12
12
[ very] ( https://github.com/zerodevx/svelte-toast/blob/master/src/SvelteToast.svelte )
13
13
[ little] ( https://github.com/zerodevx/svelte-toast/blob/master/src/ToastItem.svelte )
14
- [ lines] ( https://github.com/zerodevx/svelte-toast/blob/master/src/store .js )
14
+ [ lines] ( https://github.com/zerodevx/svelte-toast/blob/master/src/stores .js )
15
15
[ of] ( https://github.com/zerodevx/svelte-toast/blob/master/src/index.js )
16
- [ code] ( https://github.com/zerodevx/svelte-toast/blob/master/src/index.d.ts ) . Compiled (into UMD), it's only ** 18kb**
17
- minified (** 7kb** gzipped) and can be used in Vanilla JS, or as a Svelte component.
16
+ [ code] ( https://github.com/zerodevx/svelte-toast/blob/master/src/index.d.ts ) . Compiled (into UMD),
17
+ it's only ** 18kb** minified (** 7kb** gzipped) and can be used in Vanilla JS, or as a Svelte
18
+ component.
18
19
19
20
Because a demo helps better than a thousand API docs: https://zerodevx.github.io/svelte-toast/
20
21
@@ -147,7 +148,11 @@ In general, use CSS variables - the following (self-explanatory) vars are expose
147
148
padding : var (--toastPadding , 0 );
148
149
background : var (--toastBackground , rgba (66 , 66 , 66 , 0.9 ));
149
150
color : var (--toastColor , #fff );
150
- box-shadow : var (--toastBoxShadow , 0 4px 6px -1px rgba (0 , 0 , 0 , 0.1 ), 0 2px 4px -1px rgba (0 , 0 , 0 , 0.06 ));
151
+ box-shadow : var (
152
+ --toastBoxShadow ,
153
+ 0 4px 6px -1px rgba (0 , 0 , 0 , 0.1 ),
154
+ 0 2px 4px -1px rgba (0 , 0 , 0 , 0.06 )
155
+ );
151
156
border : var (--toastBorder , none );
152
157
border-radius : var (--toastBorderRadius , 0.125rem );
153
158
}
@@ -180,7 +185,8 @@ So to apply your custom theme globally, do something like:
180
185
</style >
181
186
```
182
187
183
- To apply CSS overrides to a particular Toast Item (on a per-toast basis), emit the toast with options:
188
+ To apply CSS overrides to a particular Toast Item (on a per-toast basis), emit the toast with
189
+ options:
184
190
185
191
``` js
186
192
toast .push (' Yo!' , {
@@ -196,8 +202,9 @@ where `theme` is an object containing one or more CSS var key/value pairs.
196
202
197
203
### Create Your Own Toast Actions
198
204
199
- For convenient composing, the recommended way is to create your own common toast actions by stubbing them out. For
200
- example:
205
+ For convenient composing, you can either push toasts with
206
+ [ user-defined classes] ( #styling-with-user-defined-classes ) (from ` v0.7 ` ), or create your own common
207
+ toast actions by stubbing them out. For example:
201
208
202
209
` my-theme.js `
203
210
@@ -238,8 +245,8 @@ toast.push(`<strong>You won the jackpot!</strong><br>
238
245
239
246
### Custom Fonts
240
247
241
- In a Svelte app, the easiest way to apply custom font styles is to wrap the toast container then apply styles on the
242
- wrapper:
248
+ In a Svelte app, the easiest way to apply custom font styles is to wrap the toast container then
249
+ apply styles on the wrapper:
243
250
244
251
``` html
245
252
<style >
@@ -339,17 +346,17 @@ toast.set({ id, msg: 'Waddup!' })
339
346
340
347
#### Pausable Toasts
341
348
342
- Progress bar tweens can now be paused when the mouse cursor (on desktop) is hovered over the toast item. This behaviour
343
- is ** disabled** by default. To enable, set option ` pausable: true ` .
349
+ Progress bar tweens can now be paused when the mouse cursor (on desktop) is hovered over the toast
350
+ item. This behaviour is ** disabled** by default. To enable, set option ` pausable: true ` .
344
351
345
352
``` js
346
353
toast .push (' Hover me!' , { pausable: true })
347
354
```
348
355
349
356
#### Send Svelte Component as a Message
350
357
351
- To support complex UIs or workflows, a Svelte component can be pushed instead of a standard message if you're using this
352
- in a Svelte project. To do so, push options with ` component ` defined:
358
+ To support complex UIs or workflows, a Svelte component can be pushed instead of a standard message
359
+ if you're using this in a Svelte project. To do so, push options with ` component ` defined:
353
360
354
361
``` js
355
362
import MyCustomSvelteComponent from ' ./MyCustomSvelteComponent.svelte'
@@ -368,7 +375,8 @@ toast.push({
368
375
369
376
#### ` onpop() ` Callback Function
370
377
371
- A callback function can be run when a toast is closed. To do so, pass the function to the ` onpop ` toast option:
378
+ A callback function can be run when a toast is closed. To do so, pass the function to the ` onpop `
379
+ toast option:
372
380
373
381
``` js
374
382
toast .push (' Hello world' , {
@@ -379,6 +387,29 @@ toast.push('Hello world', {
379
387
})
380
388
```
381
389
390
+ ### New from ` v0.7 `
391
+
392
+ #### Styling with User-Defined Classes
393
+
394
+ Custom class names can now be passed into each toast item. Very useful for composing toast actions,
395
+ or implementing CSS-only dark modes.
396
+
397
+ ``` html
398
+ <script >
399
+ toast .push (' Foo' , { classes: [' info' ] }) // background green
400
+ toast .push (' Bar' , { classes: [' warn' ] }) // background red
401
+ </script >
402
+ <SvelteToast options ={{ classes: [ ' log' ] }} />
403
+ <style >
404
+ :global(.log.info ) {
405
+ --toastBackground : green ;
406
+ }
407
+ :global(.log.warn ) {
408
+ --toastBackground : red ;
409
+ }
410
+ </style >
411
+ ```
412
+
382
413
## Toast Options
383
414
384
415
<!-- prettier-ignore-start -->
@@ -392,7 +423,8 @@ const options = {
392
423
dismissable: true , // allow dismiss with close button
393
424
reversed: false , // insert new toast to bottom of stack
394
425
intro: { x: 256 }, // toast intro fly animation settings
395
- theme: {} // css var overrides
426
+ theme: {}, // css var overrides
427
+ classes: [] // user-defined classes
396
428
}
397
429
```
398
430
<!-- prettier-ignore-end -->
@@ -407,7 +439,8 @@ toast.set(id, { ...options })
407
439
408
440
## Development
409
441
410
- Standard Github [ contribution workflow] ( https://gist.github.com/Chaser324/ce0505fbed06b947d962 ) applies.
442
+ Standard Github [ contribution workflow] ( https://gist.github.com/Chaser324/ce0505fbed06b947d962 )
443
+ applies.
411
444
412
445
### Tests
413
446
0 commit comments