@@ -40,7 +40,7 @@ const options = {
40
40
41
41
Use anywhere in your app - just import the toast emitter.
42
42
43
- ` MyComponent.svelte `
43
+ ` MyComponent.svelte ` :
44
44
45
45
``` html
46
46
<script >
@@ -52,7 +52,7 @@ import { toast } from '@zerodevx/svelte-toast'
52
52
53
53
### Vanilla JS
54
54
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:
56
56
57
57
``` js
58
58
import { SvelteToast , toast } from ' @zerodevx/svelte-toast'
@@ -80,10 +80,10 @@ Or if you prefer to go old-school javascript and a CDN:
80
80
...
81
81
<script >
82
82
function registerToast () {
83
- window .toastApp = new window. SvelteToastUMD.SvelteToast ({
83
+ window .toastApp = new SvelteToastUMD.SvelteToast ({
84
84
target: document .body
85
85
});
86
- window .toast = window . SvelteToastUMD .toast ;
86
+ window .toast = SvelteToastUMD .toast ;
87
87
88
88
// Now you can `toast` anywhere!
89
89
toast .push (' Hello world!' );
@@ -93,29 +93,31 @@ Or if you prefer to go old-school javascript and a CDN:
93
93
</head >
94
94
```
95
95
96
-
97
96
## Theming
98
97
99
- In general, use CSS variables - the following are exposed:
98
+ In general, use CSS variables - the following (self-explanatory) vars are exposed:
100
99
101
100
``` css
102
- ToastContainer {
101
+ ._toastContainer {
103
102
top : var (--toastContainerTop , 1.5rem );
104
103
right : var (--toastContainerRight , 2rem );
105
104
bottom : var (--toastContainerBottom , auto );
106
105
left : var (--toastContainerLeft , auto );
107
106
}
108
107
109
- ToastItem {
108
+ ._toastItem {
110
109
width : var (--toastWidth , 16rem );
111
110
height : var (--toastHeight , 3.5rem );
112
111
margin : var (--toastMargin , 0 0 0.5rem 0 );
113
112
background : var (--toastBackground , rgba (66 ,66 ,66 ,0.9 ));
114
113
color : var (--toastColor , #FFF );
115
- font : var (--toastFont );
116
114
}
117
115
118
- ToastProgressBar {
116
+ ._toastMsg {
117
+ padding : var (--toastMsgPadding , 0.75rem 0.5rem );
118
+ }
119
+
120
+ ._toastProgressBar {
119
121
background : var (--toastProgressBackground , rgba (33 ,150 ,243 ,0.75 ));
120
122
}
121
123
```
@@ -147,19 +149,51 @@ toast.push('Yo!', {
147
149
148
150
where ` theme ` is an object containing one or more CSS var key/value pairs.
149
151
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
+
150
185
## Options
151
186
152
187
``` js
153
188
// Default options
154
- const defaults = {
189
+ const options = {
155
190
duration: 4000 , // duration of progress bar tween
156
191
dismissable: true , // allow dismiss with close button
157
192
initial: 1 , // initial progress bar value
158
193
progress: 0 , // current progress
159
194
reversed: false , // insert new toast to bottom of stack
160
195
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
163
197
}
164
198
```
165
199
@@ -168,7 +202,7 @@ const defaults = {
168
202
``` js
169
203
const id = toast .push (message, { options })
170
204
toast .pop (id)
171
- toast .set (id, { object })
205
+ toast .set (id, { options })
172
206
```
173
207
174
208
## License
0 commit comments