Skip to content

Commit 7f3ce33

Browse files
committed
Prep for minor
1 parent 00db4e3 commit 7f3ce33

File tree

6 files changed

+209
-210
lines changed

6 files changed

+209
-210
lines changed

README.md

+68-16
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ A lightweight, unopinionated and performant toast notification component for mod
1414
[lines](https://github.com/zerodevx/svelte-toast/blob/master/src/stores.js)
1515
[of](https://github.com/zerodevx/svelte-toast/blob/master/src/index.js)
1616
[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
17+
it's only **19kb** minified (**8kb** gzipped) and can be used in Vanilla JS, or as a Svelte
1818
component.
1919

2020
Because a demo helps better than a thousand API docs: https://zerodevx.github.io/svelte-toast/
@@ -34,10 +34,12 @@ The following are exported:
3434

3535
### Svelte
3636

37-
If you're using this in a Svelte app, import the toast container and place it in your app shell.
37+
If you're using this in a Svelte app, import the toast container and place it in your app shell or
38+
root layout.
3839

39-
`App.svelte`:
40+
`+layout.svelte`:
4041

42+
<!-- prettier-ignore -->
4143
```html
4244
<script>
4345
import { SvelteToast } from '@zerodevx/svelte-toast'
@@ -58,7 +60,7 @@ Use anywhere in your app - just import the toast emitter.
5860

5961
```html
6062
<script>
61-
import { toast } from '@zerodevx/svelte-toast'
63+
import { toast } from '@zerodevx/svelte-toast'
6264
</script>
6365

6466
<button on:click={() => toast.push('Hello world!')}>EMIT TOAST</button>
@@ -162,6 +164,16 @@ In general, use CSS variables - the following (self-explanatory) vars are expose
162164
padding: var(--toastMsgPadding, 0.75rem 0.5rem);
163165
}
164166

167+
._toastBtn {
168+
width: var(--toastBtnWidth, 2rem);
169+
height: var(--toastBtnHeight, 100%);
170+
font: var(--toastBtnFont, 1rem sans-serif);
171+
}
172+
173+
._toastBtn::after {
174+
content: var(--toastBtnContent, '');
175+
}
176+
165177
._toastBar {
166178
background: var(--toastBarBackground, rgba(33, 150, 243, 0.75));
167179
top: var(--toastBarTop, auto);
@@ -175,13 +187,14 @@ In general, use CSS variables - the following (self-explanatory) vars are expose
175187

176188
So to apply your custom theme globally, do something like:
177189

190+
<!-- prettier-ignore -->
178191
```html
179192
<style>
180193
:root {
181194
--toastBackground: #abcdef;
182195
--toastColor: #123456;
183196
--toastHeight: 300px;
184-
...;
197+
...
185198
}
186199
</style>
187200
```
@@ -244,18 +257,21 @@ toast.push(`<strong>You won the jackpot!</strong><br>
244257
Click <a href="#" target="_blank">here</a> for details! 😛`)
245258
```
246259

247-
### Custom Fonts
260+
### Custom Fonts and Styles
248261

249-
In a Svelte app, the easiest way to apply custom font styles is to wrap the toast container then
250-
apply styles on the wrapper:
262+
In a Svelte app, the quickest way to apply custom styles is to wrap the toast container then apply
263+
styles on the wrapper:
251264

265+
<!-- prettier-ignore -->
252266
```html
253267
<style>
254268
.wrap {
255269
display: contents;
256270
font-family: Roboto, sans-serif;
257271
font-size: 0.875rem;
258-
...;
272+
/* You can set CSS vars here too */
273+
--toastBackground: pink;
274+
...
259275
}
260276
.wrap :global(strong) {
261277
font-weight: 600;
@@ -267,12 +283,14 @@ apply styles on the wrapper:
267283
</div>
268284
```
269285

270-
In Vanilla JS, simply apply your styles to the `._toastMsg` class:
286+
In Vanilla JS, simply apply your styles to the `._toastContainer` class:
271287

288+
<!-- prettier-ignore -->
272289
```css
273-
._toastMsg {
290+
._toastContainer {
274291
font-family: Roboto, sans-serif;
275-
...;
292+
--toastBackground: yellow;
293+
...
276294
}
277295
```
278296

@@ -284,6 +302,7 @@ In Vanilla JS, simply apply your styles to the `._toastMsg` class:
284302

285303
It's now easy to send toasts to different container targets within your app. For example:
286304

305+
<!-- prettier-ignore -->
287306
```html
288307
<script>
289308
import { SvelteToast, toast } from '@zerodevx/svelte-toast'
@@ -303,7 +322,7 @@ It's now easy to send toasts to different container targets within your app. For
303322
--toastContainerLeft: 2rem;
304323
--toastWidth: 100%;
305324
font-size: 0.875rem;
306-
...;
325+
...
307326
}
308327
</style>
309328

@@ -411,9 +430,42 @@ or implementing CSS-only dark modes.
411430
</style>
412431
```
413432

433+
### New from `v0.8`
434+
435+
#### Auto-pause Toasts when Page Hidden
436+
437+
This feature uses the
438+
[Page Visibility API](https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API) (if it's
439+
supported) to pause/resume a toast whenever the browser tab visibility changes - allowing one to
440+
emit notifications in the background without it being dismissed prematurely. This now happens
441+
automatically and is default behaviour, since notifications should by nature ensure that they're
442+
seen.
443+
444+
#### Customise Dismiss Button
445+
446+
Additional CSS vars are exposed - specifically, `--toastBtnContent` allows the '✕' default character
447+
to be changed. As with CSS `content` keys for pseudo elements, `url()` can be used to load external
448+
or inline icons.
449+
450+
```html
451+
<script>
452+
import { toast, SvelteToast } from '@zerodevx/svelte-toast'
453+
454+
const options = {
455+
theme: {
456+
'--toastBtnContent': `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' ...")`
457+
}
458+
}
459+
</script>
460+
461+
<button on:click={() => toast.push('Ping!')}>PONG</button>
462+
463+
<SvelteToast {options} />
464+
```
465+
414466
## Toast Options
415467

416-
<!-- prettier-ignore-start -->
468+
<!-- prettier-ignore -->
417469
```js
418470
// Default options
419471
const options = {
@@ -428,7 +480,6 @@ const options = {
428480
classes: [] // user-defined classes
429481
}
430482
```
431-
<!-- prettier-ignore-end -->
432483

433484
## Toast Methods
434485

@@ -440,7 +491,8 @@ toast.set(id, { ...options })
440491

441492
## Development
442493

443-
Standard Github [contribution workflow](https://gist.github.com/Chaser324/ce0505fbed06b947d962)
494+
Standard Github
495+
[contribution workflow](https://docs.github.com/en/get-started/quickstart/contributing-to-projects)
444496
applies.
445497

446498
### Tests

docs/build/bundle.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/build/bundle.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/build/global.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)