@@ -40,7 +40,7 @@ const options = {
4040
4141Use anywhere in your app - just import the toast emitter.
4242
43- ` MyComponent.svelte `
43+ ` MyComponent.svelte ` :
4444
4545``` html
4646<script >
@@ -52,7 +52,7 @@ import { toast } from '@zerodevx/svelte-toast'
5252
5353### Vanilla JS
5454
55- For any other applications with a bundler, something like this should work.
55+ For any other application with a bundler, something like this should work:
5656
5757``` js
5858import { SvelteToast , toast } from ' @zerodevx/svelte-toast'
@@ -80,10 +80,10 @@ Or if you prefer to go old-school javascript and a CDN:
8080 ...
8181 <script >
8282 function registerToast () {
83- window .toastApp = new window. SvelteToastUMD.SvelteToast ({
83+ window .toastApp = new SvelteToastUMD.SvelteToast ({
8484 target: document .body
8585 });
86- window .toast = window . SvelteToastUMD .toast ;
86+ window .toast = SvelteToastUMD .toast ;
8787
8888 // Now you can `toast` anywhere!
8989 toast .push (' Hello world!' );
@@ -93,29 +93,31 @@ Or if you prefer to go old-school javascript and a CDN:
9393</head >
9494```
9595
96-
9796## Theming
9897
99- In general, use CSS variables - the following are exposed:
98+ In general, use CSS variables - the following (self-explanatory) vars are exposed:
10099
101100``` css
102- ToastContainer {
101+ ._toastContainer {
103102 top : var (--toastContainerTop , 1.5rem );
104103 right : var (--toastContainerRight , 2rem );
105104 bottom : var (--toastContainerBottom , auto );
106105 left : var (--toastContainerLeft , auto );
107106}
108107
109- ToastItem {
108+ ._toastItem {
110109 width : var (--toastWidth , 16rem );
111110 height : var (--toastHeight , 3.5rem );
112111 margin : var (--toastMargin , 0 0 0.5rem 0 );
113112 background : var (--toastBackground , rgba (66 ,66 ,66 ,0.9 ));
114113 color : var (--toastColor , #FFF );
115- font : var (--toastFont );
116114}
117115
118- ToastProgressBar {
116+ ._toastMsg {
117+ padding : var (--toastMsgPadding , 0.75rem 0.5rem );
118+ }
119+
120+ ._toastProgressBar {
119121 background : var (--toastProgressBackground , rgba (33 ,150 ,243 ,0.75 ));
120122}
121123```
@@ -147,19 +149,51 @@ toast.push('Yo!', {
147149
148150where ` theme ` is an object containing one or more CSS var key/value pairs.
149151
152+ ### Rich HTML
153+
154+ Toast messages can be in rich HTML too - for example:
155+
156+ ``` js
157+ // Definitely not spam
158+ toast .push (' <strong>You won the jackpot!</strong><br>Click <a href="#" target="_blank">here</a> for details! 😛' )
159+ ```
160+
161+ ### Custom Fonts
162+
163+ Apply custom font CSS on toast messages by setting styles globally on the ` ._toastMsg ` class:
164+
165+ ``` html
166+ <style >
167+ /* In Svelte app, use the `:global` modifier */
168+ :global(._toastMsg ) {
169+ font-family : Roboto, sans-serif ;
170+ font-size : 0.875rem ;
171+ font-weight : 300 ;
172+ line-height : 1.125 ;
173+ }
174+ :global(._toastMsg > strong ) {
175+ font-weight : 600 ;
176+ }
177+
178+ /* For any others, just apply globally */
179+ ._toastMsg {
180+ ...
181+ }
182+ </style >
183+ ```
184+
150185## Options
151186
152187``` js
153188// Default options
154- const defaults = {
189+ const options = {
155190 duration: 4000 , // duration of progress bar tween
156191 dismissable: true , // allow dismiss with close button
157192 initial: 1 , // initial progress bar value
158193 progress: 0 , // current progress
159194 reversed: false , // insert new toast to bottom of stack
160195 intro: { x: 256 }, // toast intro fly animation settings
161- theme: {}, // css var overrides
162- title: null // insert a title for the toast (optional)
196+ theme: {} // css var overrides
163197}
164198```
165199
@@ -168,7 +202,7 @@ const defaults = {
168202``` js
169203const id = toast .push (message, { options })
170204toast .pop (id)
171- toast .set (id, { object })
205+ toast .set (id, { options })
172206```
173207
174208## License
0 commit comments