feather-toast-vue 2.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,543 +1,660 @@
1
- # feather-toast-vue
2
-
3
- Lightweight, accessible toast notifications for Vue 3 with spring-based animations, promise support, swipe-to-dismiss, and a minimal footprint.
4
-
5
- ---
6
-
7
- ## Table of Contents
8
-
9
- 1. [Installation](#installation)
10
- 2. [Setup](#setup)
11
- 3. [Quick Start](#quick-start)
12
- 4. [Variants](#variants)
13
- 5. [Positioning](#positioning)
14
- 6. [Stack Limit](#stack-limit)
15
- 7. [Global Configuration](#global-configuration)
16
- 8. [toast.undo](#toastundo)
17
- 9. [toast.step](#toapststep)
18
- 10. [toast.progress](#toastprogress)
19
- 11. [toast.copy](#toastcopy)
20
- 12. [toast.promise](#toastpromise)
21
- 13. [toast.custom](#toastcustom)
22
- 14. [toast.network](#toastnetwork)
23
- 15. [TypeScript API Reference](#typescript-api-reference)
24
- 16. [CSS Theming](#css-custom-properties-theming)
25
-
26
- ---
27
-
28
- ## Installation
29
-
30
- ```bash
31
- npm install feather-toast-vue
32
- # or
33
- yarn add feather-toast-vue
34
- # or
35
- pnpm add feather-toast-vue
36
- ```
37
-
38
- ---
39
-
40
- ## Setup
41
-
42
- ### Vue 3 (Vite / Webpack)
43
-
44
- Register the plugin once in your application entry file.
45
-
46
- **`src/main.ts`**
47
- ```ts
48
- import { createApp } from 'vue'
49
- import App from './App.vue'
50
- import { CreateFeatherToast } from 'feather-toast-vue'
51
-
52
- const app = createApp(App)
53
- app.use(CreateFeatherToast)
54
- app.mount('#app')
55
- ```
56
-
57
- The plugin automatically mounts `<ToastContainer />` and injects the `toast` instance via `provide/inject`.
58
-
59
- ---
60
-
61
- ### Nuxt 3
62
-
63
- Create a client-only plugin file. Toast relies on browser APIs and must run exclusively on the client.
64
-
65
- **`plugins/toast.client.ts`**
66
- ```ts
67
- import { defineNuxtPlugin } from '#app'
68
- import { CreateFeatherToast } from 'feather-toast-vue'
69
-
70
- export default defineNuxtPlugin((nuxtApp) => {
71
- nuxtApp.vueApp.use(CreateFeatherToast)
72
- })
73
- ```
74
-
75
- > The `.client.ts` suffix ensures Nuxt only loads this plugin in the browser, never on the server.
76
-
77
- ---
78
-
79
- ## Quick Start
80
-
81
- Call `useFeatherToast()` inside any Vue component's `<script setup>` to access the `toast` object.
82
-
83
- ```vue
84
- <script setup lang="ts">
85
- import { useFeatherToast } from 'feather-toast-vue'
86
-
87
- const { toast } = useFeatherToast()
88
-
89
- function save() {
90
- toast.success('Changes saved successfully!')
91
- }
92
- </script>
93
-
94
- <template>
95
- <button @click="save">Save</button>
96
- </template>
97
- ```
98
-
99
- ---
100
-
101
- ## Variants
102
-
103
- ```ts
104
- const { toast } = useFeatherToast()
105
-
106
- toast('New notification') // default
107
- toast.success('Profile updated!')
108
- toast.error('Request failed.')
109
- toast.warning('Storage running low.')
110
- toast.info('Version 2.4 available.')
111
- toast.loading('Uploading files...')
112
- toast.destructive('3 records deleted permanently.')
113
- toast.neutral('Session token refreshed.')
114
-
115
- // Full options object
116
- toast.success({
117
- title: 'Payment successful',
118
- description: 'Your invoice has been paid.',
119
- duration: 6000,
120
- position: 'top-right',
121
- })
122
- ```
123
-
124
- | Variant | Duration | Dismissible | Notes |
125
- |---------------|-------------|-------------|------------------------------------|
126
- | `default` | 5 000 ms | Yes | Neutral notification |
127
- | `success` | 5 000 ms | Yes | Positive confirmation |
128
- | `error` | 5 000 ms | Yes | Failure or exception |
129
- | `warning` | 5 000 ms | Yes | Caution / low-priority issue |
130
- | `info` | 5 000 ms | Yes | Informational message |
131
- | `loading` | Persistent | No | Spinner; use with `toast.promise` |
132
- | `destructive` | 5 000 ms | Yes | High-severity irreversible action |
133
- | `offline` | Persistent | No | Network connectivity lost |
134
- | `update` | 8 000 ms | Yes | App or version update available |
135
- | `neutral` | 3 000 ms | Yes | Passive ambient notification |
136
-
137
- ---
138
-
139
- ## Positioning
140
-
141
- ```ts
142
- toast.success({
143
- title: 'Saved',
144
- position: 'top-right',
145
- // 'top-right' | 'top-left' | 'top-center'
146
- // 'bottom-right' | 'bottom-left' | 'bottom-center'
147
- })
148
- ```
149
-
150
- ---
151
-
152
- ## Stack Limit
153
-
154
- When the number of visible toasts at a given position exceeds the configured maximum, the oldest toast is smoothly dismissed.
155
-
156
- ```ts
157
- toast.config({ max: 3 }) // Allow at most 3 simultaneous toasts
158
- toast.config({ max: 0 }) // Unlimited
159
- ```
160
-
161
- ---
162
-
163
- ## Global Configuration
164
-
165
- Configure defaults once � typically in your root component.
166
-
167
- ```ts
168
- import { useFeatherToast } from 'feather-toast-vue'
169
-
170
- const { toast } = useFeatherToast()
171
-
172
- toast.config({
173
- max: 3, // Max visible toasts per position (0 = unlimited)
174
- duration: 4000, // Default auto-dismiss timeout in milliseconds
175
- position: 'bottom-right', // Default spawn position
176
- })
177
-
178
- const config = toast.getConfig()
179
- // => { max: 3, duration: 4000, position: 'bottom-right' }
180
- ```
181
-
182
- ---
183
-
184
- ## toast.undo
185
-
186
- Renders a toast with a live countdown bar and an **Undo** action button. Use this for destructive operations where the user needs a grace period to revert.
187
-
188
- ```ts
189
- const { toast } = useFeatherToast()
190
-
191
- function deleteFile(fileId: string) {
192
- toast.undo('File "invoice-2026.pdf" deleted', {
193
- description: 'Click Undo within 5 seconds to restore the file.',
194
- duration: 5000,
195
- undoLabel: 'Undo Delete',
196
- onUndo: async () => {
197
- await restoreFile(fileId)
198
- toast.success('File restored to Documents.')
199
- },
200
- onDismiss: () => {
201
- // Called only if countdown expired without clicking Undo
202
- permanentlyDelete(fileId)
203
- },
204
- })
205
- }
206
- ```
207
-
208
- ### UndoToastOptions
209
-
210
- | Property | Type | Default | Description |
211
- |---------------|-------------------------------|----------|----------------------------------------------------|
212
- | `title` | `string` | � | Primary text of the toast. |
213
- | `description` | `string` | � | Secondary explanation line. |
214
- | `duration` | `number` | `5000` | Countdown timer in milliseconds. |
215
- | `undoLabel` | `string` | `'Undo'` | Label for the revert button. |
216
- | `onUndo` | `() => void \| Promise<void>` | � | Called when the user clicks Undo. |
217
- | `onDismiss` | `() => void` | � | Called if the countdown expires without undo. |
218
- | `position` | `ToastPosition` | Global | Overrides the global default position. |
219
-
220
- ---
221
-
222
- ## toast.step
223
-
224
- Renders a single persistent loading toast and transitions it through sequential steps in-place � no flicker, no new cards. Ideal for multi-stage operations (deployments, imports, migrations).
225
-
226
- ```ts
227
- const { toast } = useFeatherToast()
228
-
229
- async function runMigration() {
230
- const workflow = toast.step({
231
- title: 'Step 1/3: Validating schema...',
232
- description: 'Checking data integrity.',
233
- })
234
-
235
- await validateSchema()
236
- workflow.next({
237
- title: 'Step 2/3: Deploying database migration...',
238
- description: 'Applying schema patches to PostgreSQL.',
239
- })
240
-
241
- try {
242
- await deployMigration()
243
- workflow.done({
244
- title: 'Step 3/3: Migration complete!',
245
- description: 'Database updated with zero downtime.',
246
- })
247
- } catch (err) {
248
- workflow.fail({
249
- title: 'Migration failed',
250
- description: err.message,
251
- })
252
- }
253
- }
254
- ```
255
-
256
- ### StepToastController
257
-
258
- | Method | Signature | Description |
259
- |--------|-----------------------------------------|-------------------------------------------------|
260
- | `next` | `(opts: Partial<ToastOptions>) => void` | Updates the toast in-place; keeps loading state.|
261
- | `done` | `(opts?: Partial<ToastOptions>) => void`| Switches the toast to success variant. |
262
- | `fail` | `(opts?: Partial<ToastOptions>) => void`| Switches the toast to error variant. |
263
-
264
- ---
265
-
266
- ## toast.progress
267
-
268
- Spawns a loading toast with an explicit progress bar you control programmatically. Use for uploads, downloads, or any task with measurable progress.
269
-
270
- ```ts
271
- const { toast } = useFeatherToast()
272
-
273
- async function uploadFile(file: File) {
274
- const progressToast = toast.progress({
275
- title: 'Uploading file...',
276
- description: '0% completed',
277
- })
278
-
279
- xhr.addEventListener('progress', (e) => {
280
- const pct = Math.round((e.loaded / e.total) * 100)
281
- progressToast.setProgress(pct, { description: `${pct}% completed` })
282
- })
283
-
284
- await uploadPromise
285
-
286
- progressToast.done({
287
- title: 'Upload complete!',
288
- description: `${file.name} saved to storage.`,
289
- })
290
- }
291
- ```
292
-
293
- ### ProgressToastController
294
-
295
- | Method | Signature | Description |
296
- |---------------|-------------------------------------------------------|-----------------------------------------------|
297
- | `setProgress` | `(pct: number, opts?: Partial<ToastOptions>) => void` | Updates the bar (0�100) and toast text. |
298
- | `done` | `(opts?: Partial<ToastOptions>) => void` | Completes the task; switches to success. |
299
- | `fail` | `(opts?: Partial<ToastOptions>) => void` | Marks the task failed; switches to error. |
300
-
301
- ---
302
-
303
- ## toast.copy
304
-
305
- Copies text to the system clipboard and automatically shows a confirmation toast.
306
-
307
- ```ts
308
- const { toast } = useFeatherToast()
309
-
310
- async function copyLink() {
311
- await toast.copy('https://your-app.dev/share/xyz', {
312
- title: 'Link copied!',
313
- description: 'Share link has been copied to your clipboard.',
314
- })
315
- }
316
- ```
317
-
318
- On success: shows a `success` toast.
319
- On failure: shows an `error` toast with the browser error message.
320
-
321
- ---
322
-
323
- ## toast.promise
324
-
325
- Tracks an existing promise and automatically transitions loading ? success / error.
326
-
327
- ```ts
328
- const { toast } = useFeatherToast()
329
-
330
- async function createProject(data: ProjectPayload) {
331
- const request = fetch('/api/projects', {
332
- method: 'POST',
333
- body: JSON.stringify(data),
334
- })
335
-
336
- await toast.promise(request, {
337
- loading: {
338
- title: 'Creating project...',
339
- description: 'Setting up your workspace.',
340
- },
341
- success: () => ({
342
- title: 'Project created!',
343
- description: 'Your workspace is ready.',
344
- }),
345
- error: (err) => ({
346
- title: 'Failed to create project',
347
- description: err instanceof Error ? err.message : 'An unknown error occurred.',
348
- }),
349
- })
350
- }
351
- ```
352
-
353
- > `toast.promise` re-throws the rejection after showing the error toast. Wrap calls in `try/catch` or `.catch()` to handle the error downstream.
354
-
355
- ### ToastPromiseOptions
356
-
357
- | Property | Type | Description |
358
- |-----------|---------------------------------------------------|------------------------------------------------|
359
- | `loading` | `ToastOptions` | Shown while the promise is pending. |
360
- | `success` | `ToastOptions \| ((data: T) => ToastOptions)` | Shown on fulfillment. |
361
- | `error` | `ToastOptions \| ((err: unknown) => ToastOptions)`| Shown on rejection. |
362
-
363
- ---
364
-
365
- ## toast.custom
366
-
367
- Render any Vue component, render function, or `h()` VNode directly inside a toast.
368
-
369
- ```ts
370
- import { h } from 'vue'
371
- import { useFeatherToast } from 'feather-toast-vue'
372
-
373
- const { toast } = useFeatherToast()
374
-
375
- function showInvite(user: { name: string; initials: string }) {
376
- toast.custom({
377
- render: () =>
378
- h('div', { style: 'display:flex;align-items:center;gap:12px;' }, [
379
- h('div', {
380
- style: 'width:32px;height:32px;border-radius:50%;background:#6366f1;color:#fff;display:flex;align-items:center;justify-content:center;font-size:12px;font-weight:600;',
381
- }, user.initials),
382
- h('div', [
383
- h('p', { style: 'font-size:13px;font-weight:500;margin:0;' }, `${user.name} invited you`),
384
- h('p', { style: 'font-size:11px;opacity:0.65;margin:3px 0 0;' }, 'to collaborate on Project Alpha'),
385
- ]),
386
- ]),
387
- duration: 6000,
388
- })
389
- }
390
- ```
391
-
392
- You can also pass a single-file component directly:
393
-
394
- ```ts
395
- import InviteCard from '@/components/InviteCard.vue'
396
-
397
- toast.custom({
398
- render: () => h(InviteCard, { user }),
399
- duration: 6000,
400
- })
401
- ```
402
-
403
- ---
404
-
405
- ## toast.network
406
-
407
- `toast.network()` automatically monitors the browser's `online` and `offline` events. It:
408
-
409
- - Shows a **persistent, non-dismissible offline toast** the instant the device loses internet.
410
- - Dismisses it and shows a **success toast** when the connection is restored.
411
- - Detects if the device is **already offline at registration time** and shows the toast immediately.
412
-
413
- Returns a `NetworkToastController` with a `stop()` method to clean up listeners.
414
-
415
- ### Recommended: App-Level Registration
416
-
417
- Register once in your root `App.vue` to monitor connectivity for the entire application.
418
-
419
- ```vue
420
- <!-- App.vue -->
421
- <script setup lang="ts">
422
- import { onMounted, onUnmounted } from 'vue'
423
- import { useFeatherToast } from 'feather-toast-vue'
424
- import type { NetworkToastController } from 'feather-toast-vue'
425
-
426
- const { toast } = useFeatherToast()
427
- let networkMonitor: NetworkToastController | null = null
428
-
429
- onMounted(() => {
430
- networkMonitor = toast.network()
431
- })
432
-
433
- onUnmounted(() => {
434
- networkMonitor?.stop()
435
- })
436
- </script>
437
- ```
438
-
439
- ### Custom Messages
440
-
441
- ```ts
442
- const monitor = toast.network({
443
- offline: {
444
- title: 'No internet connection',
445
- description: 'Please check your Wi-Fi or mobile data.',
446
- position: 'top-center',
447
- },
448
- online: {
449
- title: 'Connection restored',
450
- description: 'You are back online.',
451
- position: 'top-center',
452
- },
453
- })
454
-
455
- // Stop monitoring when no longer needed
456
- monitor.stop()
457
- ```
458
-
459
- ### NetworkToastOptions
460
-
461
- | Option | Type | Default | Description |
462
- |-----------|-------------------------|----------|------------------------------------------------------|
463
- | `offline` | `Partial<ToastOptions>` | Built-in | Toast shown when internet connection is lost. |
464
- | `online` | `Partial<ToastOptions>` | Built-in | Toast shown when internet connection is restored. |
465
-
466
- ### NetworkToastController
467
-
468
- | Method | Signature | Description |
469
- |--------|--------------|-----------------------------------------------------------------|
470
- | `stop` | `() => void` | Removes event listeners and dismisses the offline toast if present. |
471
-
472
- ---
473
-
474
- ## TypeScript API Reference
475
-
476
- All types are exported directly from the package:
477
-
478
- ```ts
479
- import type {
480
- Toast,
481
- ToastOptions,
482
- ToastAction,
483
- ToastVariant,
484
- ToastPosition,
485
- ToastConfig,
486
- ToastPromiseOptions,
487
- UndoToastOptions,
488
- StepToastController,
489
- ProgressToastController,
490
- NetworkToastOptions,
491
- NetworkToastController,
492
- ToastComponent,
493
- } from 'feather-toast-vue'
494
- ```
495
-
496
- ### ToastOptions
497
-
498
- | Property | Type | Default | Description |
499
- |---------------|-----------------------------------------|------------------|------------------------------------------------|
500
- | `title` | `string` | � | Primary text of the toast. |
501
- | `description` | `string` | `undefined` | Secondary line below the title. |
502
- | `variant` | `ToastVariant` | `'default'` | Controls the icon and accent color. |
503
- | `position` | `ToastPosition` | `'bottom-right'` | One of six supported positions. |
504
- | `duration` | `number` | `5000` | Auto-dismiss delay in milliseconds. |
505
- | `dismissible` | `boolean` | `true` | Whether the user can close the toast manually. |
506
- | `progress` | `number` (0�100) | `undefined` | Explicit progress bar percentage. |
507
- | `showProgress`| `boolean` | `false` | Renders an animated countdown bar. |
508
- | `action` | `{ label: string; onClick: () => void }`| `undefined` | Inline action button. |
509
- | `onDismiss` | `() => void` | `undefined` | Called when the toast is dismissed. |
510
-
511
- ### ToastConfig
512
-
513
- | Property | Type | Default | Description |
514
- |------------|-----------------|------------------|--------------------------------------------------|
515
- | `max` | `number` | `5` | Max visible toasts per position (0 = unlimited). |
516
- | `duration` | `number` | `5000` | Default auto-dismiss timeout in milliseconds. |
517
- | `position` | `ToastPosition` | `'bottom-right'` | Default spawn position. |
518
-
519
- ---
520
-
521
- ## CSS Custom Properties (Theming)
522
-
523
- ```css
524
- :root {
525
- --toast-bg: #18181b;
526
- --toast-border: rgba(255, 255, 255, 0.08);
527
- --toast-text: #fafafa;
528
- --toast-text-muted: #a1a1aa;
529
- --toast-success: #22c55e;
530
- --toast-error: #ef4444;
531
- --toast-warning: #f59e0b;
532
- --toast-info: #3b82f6;
533
- --toast-radius: 8px;
534
- --toast-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
535
- --toast-z-index: 9999;
536
- }
537
- ```
538
-
539
- ---
540
-
541
- ## License
542
-
1
+ # feather-toast-vue
2
+
3
+ Lightweight, accessible toast notifications for Vue 3 with spring-based animations, promise support, swipe-to-dismiss, and a minimal footprint.
4
+
5
+ ---
6
+
7
+ ## Table of Contents
8
+
9
+ 1. [Installation](#installation)
10
+ 2. [Setup](#setup)
11
+ 3. [Quick Start](#quick-start)
12
+ 4. [Variants](#variants)
13
+ 5. [Positioning](#positioning)
14
+ 6. [Stack Limit](#stack-limit)
15
+ 7. [Global Configuration](#global-configuration)
16
+ 8. [toast.undo](#toastundo)
17
+ 9. [toast.step](#toapststep)
18
+ 10. [toast.progress](#toastprogress)
19
+ 11. [toast.copy](#toastcopy)
20
+ 12. [toast.promise](#toastpromise)
21
+ 13. [toast.custom](#toastcustom)
22
+ 14. [toast.network](#toastnetwork)
23
+ 15. [TypeScript API Reference](#typescript-api-reference)
24
+ 16. [CSS Theming](#css-custom-properties-theming)
25
+
26
+ ---
27
+
28
+ ## Installation
29
+
30
+ ```bash
31
+ npm install feather-toast-vue
32
+ # or
33
+ yarn add feather-toast-vue
34
+ # or
35
+ pnpm add feather-toast-vue
36
+ ```
37
+
38
+ ---
39
+
40
+ ## Setup
41
+
42
+ ### Vue 3 (Vite / Webpack)
43
+
44
+ Register the plugin once in your application entry file.
45
+
46
+ **`src/main.ts`**
47
+ ```ts
48
+ import { createApp } from 'vue'
49
+ import App from './App.vue'
50
+ import { CreateFeatherToast } from 'feather-toast-vue'
51
+
52
+ const app = createApp(App)
53
+ app.use(CreateFeatherToast)
54
+ app.mount('#app')
55
+ ```
56
+
57
+ The plugin automatically mounts `<ToastContainer />`, injects its stylesheet, and provides the `toast` instance via `provide/inject`. No CSS import needed.
58
+
59
+ Need to load the CSS yourself (strict CSP, SSR critical CSS)? Turn injection off and import the file:
60
+
61
+ ```ts
62
+ import 'feather-toast-vue/style.css'
63
+ app.use(CreateFeatherToast, { injectStyles: false })
64
+ ```
65
+
66
+ ---
67
+
68
+ ### Nuxt 3
69
+
70
+ Create a client-only plugin file. Toast relies on browser APIs and must run exclusively on the client.
71
+
72
+ **`plugins/toast.client.ts`**
73
+ ```ts
74
+ import { defineNuxtPlugin } from '#app'
75
+ import { CreateFeatherToast } from 'feather-toast-vue'
76
+
77
+ export default defineNuxtPlugin((nuxtApp) => {
78
+ nuxtApp.vueApp.use(CreateFeatherToast)
79
+ })
80
+ ```
81
+
82
+ > The `.client.ts` suffix ensures Nuxt only loads this plugin in the browser, never on the server.
83
+
84
+ ---
85
+
86
+ ## Quick Start
87
+
88
+ Call `useFeatherToast()` inside any Vue component's `<script setup>` to access the `toast` object.
89
+
90
+ ```vue
91
+ <script setup lang="ts">
92
+ import { useFeatherToast } from 'feather-toast-vue'
93
+
94
+ const { toast } = useFeatherToast()
95
+
96
+ function save() {
97
+ toast.success('Changes saved successfully!')
98
+ }
99
+ </script>
100
+
101
+ <template>
102
+ <button @click="save">Save</button>
103
+ </template>
104
+ ```
105
+
106
+ ---
107
+
108
+ ## Variants
109
+
110
+ ```ts
111
+ const { toast } = useFeatherToast()
112
+
113
+ toast('New notification') // default
114
+ toast.success('Profile updated!')
115
+ toast.error('Request failed.')
116
+ toast.warning('Storage running low.')
117
+ toast.info('Version 2.4 available.')
118
+ toast.loading('Uploading files...')
119
+
120
+ // Pass anything thrown straight in  the message is extracted
121
+ try { await save() } catch (err) { toast.error(err) }
122
+
123
+ // Full options object
124
+ toast.success({
125
+ title: 'Payment successful',
126
+ description: 'Your invoice has been paid.',
127
+ duration: 6000,
128
+ position: 'top-right',
129
+ })
130
+ ```
131
+
132
+ | Variant | Duration | Dismissible | Notes |
133
+ |---------------|-------------|-------------|------------------------------------|
134
+ | `default` | 5 000 ms | Yes | Neutral notification |
135
+ | `success` | 5 000 ms | Yes | Positive confirmation |
136
+ | `error` | 5 000 ms | Yes | Failure or exception |
137
+ | `warning` | 5 000 ms | Yes | Caution / low-priority issue |
138
+ | `info` | 5 000 ms | Yes | Informational message |
139
+ | `loading` | Persistent | No | Spinner; use with `toast.promise` |
140
+ | `offline` | Persistent | No | Network connectivity lost |
141
+ | `update` | 8 000 ms | Yes | App or version update available |
142
+
143
+ ---
144
+
145
+ ## Positioning
146
+
147
+ ```ts
148
+ toast.success({
149
+ title: 'Saved',
150
+ position: 'top-right',
151
+ // 'top-right' | 'top-left' | 'top-center'
152
+ // 'bottom-right' | 'bottom-left' | 'bottom-center'
153
+ })
154
+ ```
155
+
156
+ ---
157
+
158
+ ## Stack Limit
159
+
160
+ When the number of visible toasts at a given position exceeds the configured maximum, the oldest toast is smoothly dismissed.
161
+
162
+ ```ts
163
+ toast.config({ max: 3 }) // Allow at most 3 simultaneous toasts
164
+ toast.config({ max: 0 }) // Unlimited
165
+ ```
166
+
167
+ ---
168
+
169
+ ## Global Configuration
170
+
171
+ Configure defaults once � typically in your root component.
172
+
173
+ ```ts
174
+ import { useFeatherToast } from 'feather-toast-vue'
175
+
176
+ const { toast } = useFeatherToast()
177
+
178
+ toast.config({
179
+ max: 3, // Max visible toasts per position (0 = unlimited)
180
+ duration: 4000, // Default auto-dismiss timeout in milliseconds
181
+ position: 'bottom-right', // Default spawn position
182
+ visibleToasts: 3, // Toasts shown in the collapsed stack
183
+ expand: false, // true = always expanded instead of the Sonner-style stack
184
+ richColors: false, // Tinted backgrounds for success/error/warning/info/update
185
+ theme: 'light', // 'light' | 'dark' | 'system'
186
+ })
187
+
188
+ const config = toast.getConfig()
189
+ // => { max: 3, duration: 4000, position: 'bottom-right' }
190
+ ```
191
+
192
+ ---
193
+
194
+ ## Stacking & Gestures
195
+
196
+ Toasts stack like shadcn/Sonner: newer toasts sit in front and older ones peek out behind.
197
+
198
+ - **Desktop:** hover the stack to expand it. All timers pause while it is expanded.
199
+ - **Touch:** tap the stack to expand it, and tap outside to collapse it.
200
+ - **Swipe** left or right to dismiss. A quick flick also works.
201
+ - Timers also pause while the browser tab is hidden.
202
+ - All motion is `transform`/`opacity` only, and `prefers-reduced-motion` falls back to a plain fade.
203
+
204
+ ### Deduplicate with `id`
205
+
206
+ Passing an `id` that is already on screen updates that toast in place instead of stacking a duplicate:
207
+
208
+ ```ts
209
+ toast.success({ id: 'autosave', title: 'Draft saved' })
210
+ ```
211
+
212
+ ---
213
+
214
+ ## Reactive toasts
215
+
216
+ `title`, `description` and `progress` accept a `ref`, a `computed` or a getter. The toast updates when the value changes, with no update calls needed:
217
+
218
+ ```ts
219
+ const pct = ref(0)
220
+ toast.loading({
221
+ title: computed(() => `Uploading& ${pct.value}%`),
222
+ progress: pct,
223
+ })
224
+ ```
225
+
226
+ ---
227
+
228
+ ## toast.flash
229
+
230
+ Works like `toast()`, but survives a full page load. If the page reloads or navigates away while the toast is visible, it shows again on the next page. Use it after login redirects, OAuth round-trips and classic form posts. On SPA navigation it just stays on screen.
231
+
232
+ ```ts
233
+ toast.flash.success('Signed in') // also .error / .warning / .info, or toast.flash({ ... })
234
+ window.location.href = '/dashboard'
235
+ ```
236
+
237
+ Only the title, description, variant, position and duration are carried over (as plain JSON in `sessionStorage`). Buttons and custom components are not.
238
+
239
+ ---
240
+
241
+ ## Testing
242
+
243
+ The store can be read without rendering anything, so tests don't need a DOM or `<ToastContainer />`. The helpers work with Vitest, Jest or any runner that catches thrown errors.
244
+
245
+ ```ts
246
+ import { expectToast, expectNoToasts, getToasts, clickToastAction, resetToasts } from 'feather-toast-vue'
247
+
248
+ beforeEach(() => resetToasts()) // toasts, config and pending flashes
249
+
250
+ it('confirms before deleting', async () => {
251
+ const done = store.deleteFiles() // calls toast.confirm(...)
252
+ await clickToastAction({ title: /Delete/ }) // or (matcher, 'cancel')
253
+ await done
254
+ expectToast({ variant: 'success', title: 'Files deleted' })
255
+ })
256
+ ```
257
+
258
+ A failing `expectToast` lists every active toast, so you can see what showed up instead. `getToasts()` returns plain snapshots (refs resolved) that are safe for `toEqual`.
259
+
260
+ ---
261
+
262
+ ## Duplicate grouping
263
+
264
+ Firing the same plain toast (same variant, title, description and position) while it's still visible doesn't stack a copy. The visible toast gets a **�N** badge and its timer restarts. That keeps error storms and repeated clicks readable. Turn it off with `toast.config({ group: false })`.
265
+
266
+ ---
267
+
268
+ ## toast.retry
269
+
270
+ Runs an async task behind a loading toast. If it throws, the toast becomes an error with a **Retry** button that re-runs the task in the same toast. The returned promise resolves with the task's result, or rejects when the user dismisses the error or `maxRetries` runs out.
271
+
272
+ ```ts
273
+ const users = await toast.retry(() => api.get('/users'), {
274
+ loading: 'Loading users...',
275
+ success: (res) => `Loaded ${res.data.length} users`,
276
+ // error: (err) => ({ title: 'Could not load users', description: String(err) }), // default: the error's message
277
+ maxRetries: 3,
278
+ })
279
+ ```
280
+
281
+ ---
282
+
283
+ ## toast.confirm
284
+
285
+ Inline confirmation that resolves to `true` or `false`. Cancel, close, swipe and timeout all resolve `false`.
286
+
287
+ ```ts
288
+ const ok = await toast.confirm('Delete 3 files?', {
289
+ description: 'This cannot be undone.',
290
+ confirmLabel: 'Delete', // default "Confirm"
291
+ cancelLabel: 'Keep', // default "Cancel"
292
+ duration: 10000, // optional auto-cancel, shows a countdown bar
293
+ })
294
+ if (ok) await deleteFiles()
295
+ ```
296
+
297
+ Any toast can also take a secondary `cancel: { label, onClick }` button next to `action`.
298
+
299
+ ---
300
+
301
+ ## toast.undo
302
+
303
+ Renders a toast with a live countdown bar and an **Undo** action button. Use this for destructive operations where the user needs a grace period to revert.
304
+
305
+ ```ts
306
+ const { toast } = useFeatherToast()
307
+
308
+ function deleteFile(fileId: string) {
309
+ toast.undo('File "invoice-2026.pdf" deleted', {
310
+ description: 'Click Undo within 5 seconds to restore the file.',
311
+ duration: 5000,
312
+ undoLabel: 'Undo Delete',
313
+ onUndo: async () => {
314
+ await restoreFile(fileId)
315
+ toast.success('File restored to Documents.')
316
+ },
317
+ onDismiss: () => {
318
+ // Called only if countdown expired without clicking Undo
319
+ permanentlyDelete(fileId)
320
+ },
321
+ })
322
+ }
323
+ ```
324
+
325
+ ### UndoToastOptions
326
+
327
+ | Property | Type | Default | Description |
328
+ |---------------|-------------------------------|----------|----------------------------------------------------|
329
+ | `title` | `string` | � | Primary text of the toast. |
330
+ | `description` | `string` | � | Secondary explanation line. |
331
+ | `duration` | `number` | `5000` | Countdown timer in milliseconds. |
332
+ | `undoLabel` | `string` | `'Undo'` | Label for the revert button. |
333
+ | `onUndo` | `() => void \| Promise<void>` | � | Called when the user clicks Undo. |
334
+ | `onDismiss` | `() => void` | � | Called if the countdown expires without undo. |
335
+ | `position` | `ToastPosition` | Global | Overrides the global default position. |
336
+
337
+ ---
338
+
339
+ ## toast.step
340
+
341
+ Renders a single persistent loading toast and transitions it through sequential steps in-place � no flicker, no new cards. Ideal for multi-stage operations (deployments, imports, migrations).
342
+
343
+ ```ts
344
+ const { toast } = useFeatherToast()
345
+
346
+ async function runMigration() {
347
+ const workflow = toast.step({
348
+ title: 'Step 1/3: Validating schema...',
349
+ description: 'Checking data integrity.',
350
+ })
351
+
352
+ await validateSchema()
353
+ workflow.next({
354
+ title: 'Step 2/3: Deploying database migration...',
355
+ description: 'Applying schema patches to PostgreSQL.',
356
+ })
357
+
358
+ try {
359
+ await deployMigration()
360
+ workflow.done({
361
+ title: 'Step 3/3: Migration complete!',
362
+ description: 'Database updated with zero downtime.',
363
+ })
364
+ } catch (err) {
365
+ workflow.fail({
366
+ title: 'Migration failed',
367
+ description: err.message,
368
+ })
369
+ }
370
+ }
371
+ ```
372
+
373
+ ### StepToastController
374
+
375
+ | Method | Signature | Description |
376
+ |--------|-----------------------------------------|-------------------------------------------------|
377
+ | `next` | `(opts: Partial<ToastOptions>) => void` | Updates the toast in-place; keeps loading state.|
378
+ | `done` | `(opts?: Partial<ToastOptions>) => void`| Switches the toast to success variant. |
379
+ | `fail` | `(opts?: Partial<ToastOptions>) => void`| Switches the toast to error variant. |
380
+
381
+ ---
382
+
383
+ ## toast.progress
384
+
385
+ Spawns a loading toast with an explicit progress bar you control programmatically. Use for uploads, downloads, or any task with measurable progress.
386
+
387
+ ```ts
388
+ const { toast } = useFeatherToast()
389
+
390
+ async function uploadFile(file: File) {
391
+ const progressToast = toast.progress({
392
+ title: 'Uploading file...',
393
+ description: '0% completed',
394
+ })
395
+
396
+ xhr.addEventListener('progress', (e) => {
397
+ const pct = Math.round((e.loaded / e.total) * 100)
398
+ progressToast.setProgress(pct, { description: `${pct}% completed` })
399
+ })
400
+
401
+ await uploadPromise
402
+
403
+ progressToast.done({
404
+ title: 'Upload complete!',
405
+ description: `${file.name} saved to storage.`,
406
+ })
407
+ }
408
+ ```
409
+
410
+ ### ProgressToastController
411
+
412
+ | Method | Signature | Description |
413
+ |---------------|-------------------------------------------------------|-----------------------------------------------|
414
+ | `setProgress` | `(pct: number, opts?: Partial<ToastOptions>) => void` | Updates the bar (0�100) and toast text. |
415
+ | `done` | `(opts?: Partial<ToastOptions>) => void` | Completes the task; switches to success. |
416
+ | `fail` | `(opts?: Partial<ToastOptions>) => void` | Marks the task failed; switches to error. |
417
+
418
+ ---
419
+
420
+ ## toast.copy
421
+
422
+ Copies text to the system clipboard and automatically shows a confirmation toast.
423
+
424
+ ```ts
425
+ const { toast } = useFeatherToast()
426
+
427
+ async function copyLink() {
428
+ await toast.copy('https://your-app.dev/share/xyz', {
429
+ title: 'Link copied!',
430
+ description: 'Share link has been copied to your clipboard.',
431
+ })
432
+ }
433
+ ```
434
+
435
+ On success: shows a `success` toast.
436
+ On failure: shows an `error` toast with the browser error message.
437
+
438
+ ---
439
+
440
+ ## toast.promise
441
+
442
+ Tracks an existing promise and automatically transitions loading ? success / error.
443
+
444
+ ```ts
445
+ const { toast } = useFeatherToast()
446
+
447
+ async function createProject(data: ProjectPayload) {
448
+ const request = fetch('/api/projects', {
449
+ method: 'POST',
450
+ body: JSON.stringify(data),
451
+ })
452
+
453
+ await toast.promise(request, {
454
+ loading: {
455
+ title: 'Creating project...',
456
+ description: 'Setting up your workspace.',
457
+ },
458
+ success: () => ({
459
+ title: 'Project created!',
460
+ description: 'Your workspace is ready.',
461
+ }),
462
+ error: (err) => ({
463
+ title: 'Failed to create project',
464
+ description: err instanceof Error ? err.message : 'An unknown error occurred.',
465
+ }),
466
+ })
467
+ }
468
+ ```
469
+
470
+ > `toast.promise` re-throws the rejection after showing the error toast. Wrap calls in `try/catch` or `.catch()` to handle the error downstream.
471
+
472
+ ### ToastPromiseOptions
473
+
474
+ | Property | Type | Description |
475
+ |-----------|---------------------------------------------------|------------------------------------------------|
476
+ | `loading` | `ToastOptions` | Shown while the promise is pending. |
477
+ | `success` | `ToastOptions \| ((data: T) => ToastOptions)` | Shown on fulfillment. |
478
+ | `error` | `ToastOptions \| ((err: unknown) => ToastOptions)`| Shown on rejection. |
479
+
480
+ ---
481
+
482
+ ## toast.custom
483
+
484
+ Render any Vue component, render function, or `h()` VNode directly inside a toast.
485
+
486
+ ```ts
487
+ import { h } from 'vue'
488
+ import { useFeatherToast } from 'feather-toast-vue'
489
+
490
+ const { toast } = useFeatherToast()
491
+
492
+ function showInvite(user: { name: string; initials: string }) {
493
+ toast.custom({
494
+ render: () =>
495
+ h('div', { style: 'display:flex;align-items:center;gap:12px;' }, [
496
+ h('div', {
497
+ style: 'width:32px;height:32px;border-radius:50%;background:#6366f1;color:#fff;display:flex;align-items:center;justify-content:center;font-size:12px;font-weight:600;',
498
+ }, user.initials),
499
+ h('div', [
500
+ h('p', { style: 'font-size:13px;font-weight:500;margin:0;' }, `${user.name} invited you`),
501
+ h('p', { style: 'font-size:11px;opacity:0.65;margin:3px 0 0;' }, 'to collaborate on Project Alpha'),
502
+ ]),
503
+ ]),
504
+ duration: 6000,
505
+ })
506
+ }
507
+ ```
508
+
509
+ You can also pass a single-file component directly:
510
+
511
+ ```ts
512
+ import InviteCard from '@/components/InviteCard.vue'
513
+
514
+ toast.custom({
515
+ render: () => h(InviteCard, { user }),
516
+ duration: 6000,
517
+ })
518
+ ```
519
+
520
+ ---
521
+
522
+ ## toast.network
523
+
524
+ `toast.network()` automatically monitors the browser's `online` and `offline` events. It:
525
+
526
+ - Shows a **persistent, non-dismissible offline toast** the instant the device loses internet.
527
+ - Dismisses it and shows a **success toast** when the connection is restored.
528
+ - Detects if the device is **already offline at registration time** and shows the toast immediately.
529
+
530
+ Returns a `NetworkToastController` with a `stop()` method to clean up listeners.
531
+
532
+ ### Recommended: App-Level Registration
533
+
534
+ Register once in your root `App.vue` to monitor connectivity for the entire application.
535
+
536
+ ```vue
537
+ <!-- App.vue -->
538
+ <script setup lang="ts">
539
+ import { onMounted, onUnmounted } from 'vue'
540
+ import { useFeatherToast } from 'feather-toast-vue'
541
+ import type { NetworkToastController } from 'feather-toast-vue'
542
+
543
+ const { toast } = useFeatherToast()
544
+ let networkMonitor: NetworkToastController | null = null
545
+
546
+ onMounted(() => {
547
+ networkMonitor = toast.network()
548
+ })
549
+
550
+ onUnmounted(() => {
551
+ networkMonitor?.stop()
552
+ })
553
+ </script>
554
+ ```
555
+
556
+ ### Custom Messages
557
+
558
+ ```ts
559
+ const monitor = toast.network({
560
+ offline: {
561
+ title: 'No internet connection',
562
+ description: 'Please check your Wi-Fi or mobile data.',
563
+ position: 'top-center',
564
+ },
565
+ online: {
566
+ title: 'Connection restored',
567
+ description: 'You are back online.',
568
+ position: 'top-center',
569
+ },
570
+ })
571
+
572
+ // Stop monitoring when no longer needed
573
+ monitor.stop()
574
+ ```
575
+
576
+ ### NetworkToastOptions
577
+
578
+ | Option | Type | Default | Description |
579
+ |-----------|-------------------------|----------|------------------------------------------------------|
580
+ | `offline` | `Partial<ToastOptions>` | Built-in | Toast shown when internet connection is lost. |
581
+ | `online` | `Partial<ToastOptions>` | Built-in | Toast shown when internet connection is restored. |
582
+
583
+ ### NetworkToastController
584
+
585
+ | Method | Signature | Description |
586
+ |--------|--------------|-----------------------------------------------------------------|
587
+ | `stop` | `() => void` | Removes event listeners and dismisses the offline toast if present. |
588
+
589
+ ---
590
+
591
+ ## TypeScript API Reference
592
+
593
+ All types are exported directly from the package:
594
+
595
+ ```ts
596
+ import type {
597
+ Toast,
598
+ ToastOptions,
599
+ ToastAction,
600
+ ToastVariant,
601
+ ToastPosition,
602
+ ToastConfig,
603
+ ToastPromiseOptions,
604
+ UndoToastOptions,
605
+ StepToastController,
606
+ ProgressToastController,
607
+ NetworkToastOptions,
608
+ NetworkToastController,
609
+ ToastComponent,
610
+ } from 'feather-toast-vue'
611
+ ```
612
+
613
+ ### ToastOptions
614
+
615
+ | Property | Type | Default | Description |
616
+ |---------------|-----------------------------------------|------------------|------------------------------------------------|
617
+ | `title` | `string` | � | Primary text of the toast. |
618
+ | `description` | `string` | `undefined` | Secondary line below the title. |
619
+ | `variant` | `ToastVariant` | `'default'` | Controls the icon and accent color. |
620
+ | `position` | `ToastPosition` | `'bottom-right'` | One of six supported positions. |
621
+ | `duration` | `number` | `5000` | Auto-dismiss delay in milliseconds. |
622
+ | `dismissible` | `boolean` | `true` | Whether the user can close the toast manually. |
623
+ | `progress` | `number` (0�100) | `undefined` | Explicit progress bar percentage. |
624
+ | `showProgress`| `boolean` | `false` | Renders an animated countdown bar. |
625
+ | `action` | `{ label: string; onClick: () => void }`| `undefined` | Inline action button. |
626
+ | `onDismiss` | `() => void` | `undefined` | Called when the toast is dismissed. |
627
+
628
+ ### ToastConfig
629
+
630
+ | Property | Type | Default | Description |
631
+ |------------|-----------------|------------------|--------------------------------------------------|
632
+ | `max` | `number` | `5` | Max visible toasts per position (0 = unlimited). |
633
+ | `duration` | `number` | `5000` | Default auto-dismiss timeout in milliseconds. |
634
+ | `position` | `ToastPosition` | `'bottom-right'` | Default spawn position. |
635
+
636
+ ---
637
+
638
+ ## CSS Custom Properties (Theming)
639
+
640
+ ```css
641
+ :root {
642
+ --toast-bg: #18181b;
643
+ --toast-border: rgba(255, 255, 255, 0.08);
644
+ --toast-text: #fafafa;
645
+ --toast-text-muted: #a1a1aa;
646
+ --toast-success: #22c55e;
647
+ --toast-error: #ef4444;
648
+ --toast-warning: #f59e0b;
649
+ --toast-info: #3b82f6;
650
+ --toast-radius: 8px;
651
+ --toast-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
652
+ --toast-z-index: 9999;
653
+ }
654
+ ```
655
+
656
+ ---
657
+
658
+ ## License
659
+
543
660
  MIT (c) zin-ix