11[ ![ npm (scoped)] ( https://img.shields.io/npm/v/@zerodevx/svelte-toast )] ( https://www.npmjs.com/package/@zerodevx/svelte-toast )
22[ ![ JavaScript Style Guide] ( https://img.shields.io/badge/code_style-standard-brightgreen.svg )] ( https://standardjs.com )
3+ [ ![ Lines of code] ( https://img.shields.io/tokei/lines/github/zerodevx/svelte-toast?label=lines%20of%20code )] ( https://github.com/XAMPPRocky/tokei )
4+ [ ![ Size minified] ( https://img.shields.io/bundlephobia/min/@zerodevx/svelte-toast?label=minified )] ( https://bundlephobia.com/ )
5+ [ ![ Size gzipped] ( https://img.shields.io/bundlephobia/minzip/@zerodevx/svelte-toast?label=gzipped )] ( https://bundlephobia.com/ )
36
47# svelte-toast
58
69> Simple elegant toast notifications.
710
8- A lightweight, unopinionated and performant toast notification component for modern web frontends in very little
9- lines of code. Compiled, it's only ** 15kb** minified (** 6kb** gzipped) and can be used in Vanilla JS, or as a
10- Svelte component.
11+ A lightweight, unopinionated and performant toast notification component for modern web frontends in
12+ [ very] ( https://github.com/zerodevx/svelte-toast/blob/master/src/SvelteToast.svelte )
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 )
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 ) .
17+ Compiled (into UMD), it's only ** 17kb** minified (** 7kb** gzipped) and can be used in Vanilla JS,
18+ as a Svelte component.
1119
1220Because a demo helps better than a thousand API docs: https://zerodevx.github.io/svelte-toast/
1321
@@ -101,7 +109,7 @@ Or if you prefer to go old-school javascript and a CDN:
101109 })
102110
103111 // Now you can `toast` anywhere!
104- toast .push (' Hello world!' );
112+ toast .push (' Hello world!' )
105113 </script >
106114</head >
107115```
@@ -214,14 +222,15 @@ then apply styles on the wrapper:
214222
215223``` html
216224<style >
217- .wrap {
218- font-family : Roboto, sans-serif ;
219- font-size : 0.875rem ;
220- ...
221- }
222- .wrap :global(strong ) {
223- font-weight : 600 ;
224- }
225+ .wrap {
226+ display : contents ;
227+ font-family : Roboto, sans-serif ;
228+ font-size : 0.875rem ;
229+ ...
230+ }
231+ .wrap :global(strong ) {
232+ font-weight : 600 ;
233+ }
225234 </style >
226235
227236<div class =" wrap" >
@@ -238,6 +247,8 @@ In Vanilla JS, simply apply your styles to the `._toastMsg` class:
238247}
239248```
240249
250+ ## Features
251+
241252### New from ` v0.4 `
242253
243254#### Supporting Multiple Toast Containers
@@ -289,43 +300,74 @@ toast.pop(i => i.target !== 'new')
289300toast .pop (0 )
290301```
291302
292- #### Accepts Object as First Param
303+ #### Accepting Object as First Param
293304
294305` push() ` and ` set() ` can also take an object as its first parameter.
295306
296307``` js
297308let id = toast .push (' Yo!' , { duration: 2000 })
298-
299309// is semantically equivalent to
300310id = toast .push ({ msg: ' Yo!' , duration: 2000 })
301311
302312toast .set (id, { msg: ' Waddup!' })
303-
304313// is semantically equivalent to
305314toast .set ({ id, msg: ' Waddup!' })
306315```
307316
308- ## Options
317+ ### New from ` v0.5 `
318+
319+ #### Pausable Toasts
320+
321+ Progress bar tweens can now be paused when the mouse cursor (on desktop) is hovered on the toast item.
322+ This behaviour by default is ** disabled** . To enable, set option ` pausable: true ` :
323+
324+ ``` js
325+ toast .push (' Hover me!' , { pausable: true })
326+ ```
327+
328+ #### Send Svelte Component as a Message
329+
330+ To allow for complex UI or workflows, a Svelte component can be pushed instead of a standard message.
331+ Obviously, this works only if you're consuming ` svelte-toast ` as part of a larger Svelte project.
332+ To do so, push options with ` component ` property defined:
333+
334+ ``` js
335+ import MyCustomSvelteComponent from ' ./MyCustomSvelteComponent.svelte'
336+
337+ toast .push ({
338+ component: {
339+ src: MyCustomSvelteComponent, // set the `src` to the component itself (required)
340+ props: { // optionally pass in `props` as key/value pairs
341+ ...
342+ },
343+ sendIdTo: ' toastId' // optionally forward the toast id to `toastId` prop
344+ },
345+ ... // any other toast options
346+ })
347+ ```
348+
349+ ## Toast Options
309350
310351``` js
311352// Default options
312353const options = {
313- duration: 4000 , // duration of progress bar tween
314- dismissable: true , // allow dismiss with close button
354+ duration: 4000 , // duration of progress bar tween to the `next` value
315355 initial: 1 , // initial progress bar value
316- progress: 0 , // current progress
356+ next: 0 , // next progress value
357+ dismissable: true , // allow dismiss with close button
358+ pausable: false , // allow pause on mouse hover
317359 reversed: false , // insert new toast to bottom of stack
318360 intro: { x: 256 }, // toast intro fly animation settings
319361 theme: {} // css var overrides
320362}
321363```
322364
323- ## Toast API
365+ ## Toast Methods
324366
325367``` js
326- const id = toast .push (message, { options })
327- toast .pop (id)
328- toast .set (id, { options })
368+ const id = toast .push (message, { ... options })
369+ toast .pop (id) // accepts a filter function too
370+ toast .set (id, { ... options })
329371```
330372
331373## Development
0 commit comments