Skip to content

Commit 281f95d

Browse files
committed
Document v0.7
1 parent e38df22 commit 281f95d

File tree

1 file changed

+49
-16
lines changed

1 file changed

+49
-16
lines changed

README.md

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
A lightweight, unopinionated and performant toast notification component for modern web frontends in
1212
[very](https://github.com/zerodevx/svelte-toast/blob/master/src/SvelteToast.svelte)
1313
[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)
1515
[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.
1819

1920
Because a demo helps better than a thousand API docs: https://zerodevx.github.io/svelte-toast/
2021

@@ -147,7 +148,11 @@ In general, use CSS variables - the following (self-explanatory) vars are expose
147148
padding: var(--toastPadding, 0);
148149
background: var(--toastBackground, rgba(66, 66, 66, 0.9));
149150
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+
);
151156
border: var(--toastBorder, none);
152157
border-radius: var(--toastBorderRadius, 0.125rem);
153158
}
@@ -180,7 +185,8 @@ So to apply your custom theme globally, do something like:
180185
</style>
181186
```
182187

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:
184190

185191
```js
186192
toast.push('Yo!', {
@@ -196,8 +202,9 @@ where `theme` is an object containing one or more CSS var key/value pairs.
196202

197203
### Create Your Own Toast Actions
198204

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:
201208

202209
`my-theme.js`
203210

@@ -238,8 +245,8 @@ toast.push(`<strong>You won the jackpot!</strong><br>
238245

239246
### Custom Fonts
240247

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:
243250

244251
```html
245252
<style>
@@ -339,17 +346,17 @@ toast.set({ id, msg: 'Waddup!' })
339346

340347
#### Pausable Toasts
341348

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`.
344351

345352
```js
346353
toast.push('Hover me!', { pausable: true })
347354
```
348355

349356
#### Send Svelte Component as a Message
350357

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:
353360

354361
```js
355362
import MyCustomSvelteComponent from './MyCustomSvelteComponent.svelte'
@@ -368,7 +375,8 @@ toast.push({
368375

369376
#### `onpop()` Callback Function
370377

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:
372380

373381
```js
374382
toast.push('Hello world', {
@@ -379,6 +387,29 @@ toast.push('Hello world', {
379387
})
380388
```
381389

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+
382413
## Toast Options
383414

384415
<!-- prettier-ignore-start -->
@@ -392,7 +423,8 @@ const options = {
392423
dismissable: true, // allow dismiss with close button
393424
reversed: false, // insert new toast to bottom of stack
394425
intro: { x: 256 }, // toast intro fly animation settings
395-
theme: {} // css var overrides
426+
theme: {}, // css var overrides
427+
classes: [] // user-defined classes
396428
}
397429
```
398430
<!-- prettier-ignore-end -->
@@ -407,7 +439,8 @@ toast.set(id, { ...options })
407439

408440
## Development
409441

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.
411444

412445
### Tests
413446

0 commit comments

Comments
 (0)