vetra-toast 1.0.0 → 1.0.1

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.
Files changed (2) hide show
  1. package/README.md +298 -17
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,14 +1,54 @@
1
- # vetra-toast
1
+ <div align="center">
2
2
 
3
- Premium glassmorphism toast notification library for modern React and Next.js applications.
3
+ # Vetra Toast
4
4
 
5
- ## Install
5
+ **Premium glassmorphism toast notifications for modern React and Next.js applications.**
6
+
7
+ [![npm version](https://img.shields.io/npm/v/vetra-toast?color=38bdf8&style=flat-square)](https://www.npmjs.com/package/vetra-toast)
8
+ [![npm downloads](https://img.shields.io/npm/dm/vetra-toast?color=818cf8&style=flat-square)](https://www.npmjs.com/package/vetra-toast)
9
+ [![TypeScript](https://img.shields.io/badge/TypeScript-First-3178c6?style=flat-square&logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
10
+ [![Zero Dependencies](https://img.shields.io/badge/dependencies-0-34d399?style=flat-square)](https://www.npmjs.com/package/vetra-toast)
11
+ [![License: MIT](https://img.shields.io/badge/license-MIT-a78bfa?style=flat-square)](https://github.com/immobarok/vetra-toast/blob/main/LICENSE)
12
+
13
+ [Installation](#installation) • [Quick Start](#quick-start) • [API Reference](#api-reference) • [Customization](#customization) • [Next.js Setup](#nextjs-app-router) • [Accessibility](#accessibility)
14
+
15
+ </div>
16
+
17
+ ---
18
+
19
+ ## Why Vetra Toast?
20
+
21
+ - **Signature Frosted Glass UI** — Layered `backdrop-filter` blur, prismatic top specular edge, semantic corner aura, and four glass presets (`subtle`, `frosted`, `crystal`, `solid`).
22
+ - **Bespoke Animated SVG Icons** — Hand-crafted micro-animations per variant (spring-drawn success check with sparkles, dual-stroke error shield with micro-shake, warning prism, orbital info glint, and dual-ring gyroscope loader).
23
+ - **Zero Runtime Dependencies** — No mandatory Tailwind CSS or animation libraries. Tree-shakeable ESM + CJS with standalone `vetra-toast/styles.css`.
24
+ - **Framework-Agnostic Core** — Predictable external store (`useSyncExternalStore`) with FIFO queue promotion, reference-counted multi-reason pause/resume (`hover`, `focus`, `document-hidden`, `swipe`), and duplicate prevention.
25
+ - **Next.js App Router & SSR Safe** — Ships `"use client"` on the React entry, defers portal mounting until client hydration, and keeps browser APIs out of module initialization.
26
+ - **Accessibility First** — Semantic `role="alert"` / `role="status"`, `aria-live`, `Alt+T` focus hotkey, `Escape` dismissal, `prefers-reduced-motion`, and `prefers-reduced-transparency` fallbacks.
27
+ - **Rich Sensory Feedback** — Optional subtle synthesized Web Audio chimes and mobile haptic vibration (`navigator.vibrate`), zero audio asset downloads.
28
+
29
+ ---
30
+
31
+ ## Installation
32
+
33
+ ```bash
34
+ pnpm add vetra-toast
35
+ ```
6
36
 
7
37
  ```bash
8
38
  npm install vetra-toast
9
39
  ```
10
40
 
11
- ## Usage
41
+ ```bash
42
+ yarn add vetra-toast
43
+ ```
44
+
45
+ > **Peer dependencies**: `react >= 18` and `react-dom >= 18` (built and tested with React 19.3+).
46
+
47
+ ---
48
+
49
+ ## Quick Start
50
+
51
+ Import the stylesheet once in your app entry, mount `<Toaster />` near the root, and call `toast` from anywhere:
12
52
 
13
53
  ```tsx
14
54
  import { Toaster, toast } from "vetra-toast";
@@ -17,24 +57,265 @@ import "vetra-toast/styles.css";
17
57
  export function App() {
18
58
  return (
19
59
  <>
20
- <Toaster position="top-right" theme="dark" duration={4000} visibleToasts={4} />
21
- <button onClick={() => toast.success("Profile updated!")}>Notify</button>
60
+ <Toaster position="top-right" theme="dark" />
61
+
62
+ <button onClick={() => toast.success("Profile updated!")}>
63
+ Save Profile
64
+ </button>
22
65
  </>
23
66
  );
24
67
  }
25
68
  ```
26
69
 
27
- ## Features
70
+ ---
71
+
72
+ ## Next.js App Router
73
+
74
+ Mount `<Toaster />` directly inside your Server Component root layout (`app/layout.tsx`) with zero hydration warnings:
75
+
76
+ ```tsx
77
+ // app/layout.tsx
78
+ import type { ReactNode } from "react";
79
+ import { Toaster } from "vetra-toast";
80
+ import "vetra-toast/styles.css";
81
+
82
+ export default function RootLayout({ children }: { children: ReactNode }) {
83
+ return (
84
+ <html lang="en">
85
+ <body>
86
+ {children}
87
+ <Toaster position="top-right" theme="system" />
88
+ </body>
89
+ </html>
90
+ );
91
+ }
92
+ ```
93
+
94
+ Then trigger toasts from any Client Component (`"use client"`):
95
+
96
+ ```tsx
97
+ "use client";
98
+
99
+ import { toast } from "vetra-toast";
100
+
101
+ export function SaveButton() {
102
+ return (
103
+ <button onClick={() => toast.success("Saved to cloud!")}>
104
+ Save Changes
105
+ </button>
106
+ );
107
+ }
108
+ ```
109
+
110
+ ---
111
+
112
+ ## API Reference
113
+
114
+ ### Variants
115
+
116
+ ```ts
117
+ toast("Default notification");
118
+ toast.success("Profile updated!", { description: "Your preferences are synced." });
119
+ toast.error("Something went wrong!", { description: "Please check your connection." });
120
+ toast.warning("Session expiring!", { description: "Sign in again within 2 minutes." });
121
+ toast.info("New update available!");
122
+ toast.loading("Uploading artifact...");
123
+ ```
124
+
125
+ ### Promise Notifications
126
+
127
+ Automatically transitions a single toast from `loading` → `success` or `error`. Rejections are handled internally so fire-and-forget usage never triggers unhandled promise rejections; call `.unwrap()` when you want the original promise result:
128
+
129
+ ```ts
130
+ const req = toast.promise(uploadFile(), {
131
+ loading: "Uploading...",
132
+ success: (file) => `Uploaded ${file.name}!`,
133
+ error: (err) => `Upload failed: ${err.message}`,
134
+ });
135
+
136
+ // Optional: await resolved data or catch rejection
137
+ // const file = await req.unwrap();
138
+ ```
139
+
140
+ ### Update, Dismiss & Dismiss All
141
+
142
+ ```ts
143
+ const id = toast.loading("Deploying to production...");
144
+
145
+ toast.update(id, {
146
+ variant: "success",
147
+ title: "Deployment live!",
148
+ description: "All health checks passed.",
149
+ });
150
+
151
+ toast.dismiss(id);
152
+ toast.dismissAll();
153
+ ```
154
+
155
+ ### Action Buttons, Custom Icons & Custom JSX
156
+
157
+ ```tsx
158
+ toast.warning("File moved to trash", {
159
+ description: "Restore it within 30 days.",
160
+ action: {
161
+ label: "Undo",
162
+ onClick: () => restoreFile(),
163
+ },
164
+ cancel: {
165
+ label: "Dismiss",
166
+ onClick: () => {},
167
+ },
168
+ });
169
+
170
+ toast.custom(({ dismiss }) => (
171
+ <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", gap: 12 }}>
172
+ <strong>Custom Glass Widget</strong>
173
+ <button type="button" onClick={dismiss}>Close</button>
174
+ </div>
175
+ ));
176
+ ```
177
+
178
+ ### Duplicate Prevention
179
+
180
+ ```ts
181
+ // Global: <Toaster preventDuplicates />
182
+ // Or per-toast:
183
+ toast.info("Connection restored", {
184
+ dedupe: true,
185
+ dedupeKey: "network-status",
186
+ });
187
+ ```
188
+
189
+ Repeated triggers increment a sleek `×2`, `×3` counter badge and reset the auto-dismiss timer instead of flooding the screen.
190
+
191
+ ---
192
+
193
+ ## `<Toaster />` Props
194
+
195
+ | Prop | Type | Default | Description |
196
+ | :--- | :--- | :--- | :--- |
197
+ | `position` | `"top-left" \| "top-center" \| "top-right" \| "bottom-left" \| "bottom-center" \| "bottom-right"` | `"top-right"` | Viewport anchor (auto-centered on mobile `<= 640px`) |
198
+ | `theme` | `"dark" \| "light" \| "system"` | `"dark"` | Glassmorphism theme mode |
199
+ | `glass` | `"subtle" \| "frosted" \| "crystal" \| "solid"` | `"frosted"` | Glass blur & surface intensity preset |
200
+ | `radius` | `"sm" \| "md" \| "lg" \| "pill"` | `"md"` | Corner radius preset |
201
+ | `size` | `"compact" \| "default" \| "comfortable"` | `"default"` | Spacing & typography density |
202
+ | `animation` | `"spring" \| "slide" \| "fade" \| "zoom" \| "bounce" \| "none"` | `"bounce"` | Entrance & exit animation style |
203
+ | `iconAnimation` | `"default" \| "subtle" \| "none" \| boolean` | `"default"` | Control animated SVG icon motion |
204
+ | `ambientGlow` | `boolean` | `true` | Semantic corner aura glow behind the icon |
205
+ | `richColors` | `boolean` | `false` | Apply subtle semantic tint to glass surface & border |
206
+ | `duration` | `number` | `4000` | Default auto-dismiss duration in ms (`Infinity` disables) |
207
+ | `visibleToasts` | `number` | `4` | Max visible toasts; overflow queues in FIFO order |
208
+ | `expand` | `boolean` | `false` | Stacked depth mode by default (fans open on hover/focus) |
209
+ | `showProgress` | `boolean` | `false` | Synchronized countdown progress bar |
210
+ | `progressPosition` | `"bottom" \| "top"` | `"bottom"` | Progress bar edge placement |
211
+ | `progressHeight` | `number` | `3` | Progress bar height in px |
212
+ | `closeButton` | `boolean` | `true` | Render accessible dismiss button |
213
+ | `closeButtonPosition` | `"top-right" \| "top-left" \| "floating"` | `"floating"` | Close button placement |
214
+ | `showCloseOnHover` | `boolean` | `true` | Reveal close button on hover or keyboard focus |
215
+ | `pauseOnHover` | `boolean` | `true` | Pause auto-dismiss timer while hovered |
216
+ | `pauseOnFocus` | `boolean` | `true` | Pause auto-dismiss timer while focused |
217
+ | `swipeToDismiss` | `boolean` | `true` | Enable pointer/touch swipe dismissal |
218
+ | `swipeDirections` | `Array<"left" \| "right" \| "up" \| "down">` | Position-based | Override allowed swipe directions |
219
+ | `preventDuplicates` | `boolean` | `false` | Deduplicate matching active toasts globally |
220
+ | `hotkey` | `string[]` | `["altKey", "KeyT"]` | Global keyboard shortcut to focus notifications |
221
+ | `sound` | `boolean` | `true` | Subtle synthesized Web Audio chime |
222
+ | `haptic` | `boolean` | `true` | Mobile `navigator.vibrate` haptic pulse |
223
+ | `onToastShow` | `(toast: ToastRecord) => void` | — | Callback fired when a toast becomes visible |
224
+ | `themeTokens` | `VetraThemeTokens` | — | Inline CSS custom property overrides |
225
+ | `icons` | `ToastIcons` | — | Global custom icons (`success`, `error`, `warning`, `info`, `loading`, `close`) |
226
+ | `classNames` | `ToastClassNames` | — | Granular slot class names (`toast`, `title`, `description`, `icon`, `actionButton`, `closeButton`, `progress`, etc.) |
227
+ | `toastOptions` | `ToastDefaultOptions` | — | Global & per-variant default options |
228
+ | `gap` / `offset` | `number` / `number \| string` | `12` / `20` | Stack gap and viewport offset |
229
+ | `portalContainer` | `HTMLElement \| null` | `document.body` | Custom React Portal mount target |
230
+
231
+ ---
232
+
233
+ ## Customization
234
+
235
+ ### Inline Theme Tokens & Per-Variant Defaults
236
+
237
+ ```tsx
238
+ <Toaster
239
+ theme="dark"
240
+ glass="crystal"
241
+ radius="lg"
242
+ animation="spring"
243
+ showProgress
244
+ progressPosition="top"
245
+ themeTokens={{
246
+ blur: 28,
247
+ width: 400,
248
+ success: "#10b981",
249
+ error: "#f43f5e",
250
+ }}
251
+ toastOptions={{
252
+ success: { duration: 2500 },
253
+ error: { duration: 6000 },
254
+ }}
255
+ />
256
+ ```
257
+
258
+ ### CSS Custom Properties
259
+
260
+ Override any `--vt-*` variable directly in CSS:
261
+
262
+ ```css
263
+ :root {
264
+ --vt-blur: 24px;
265
+ --vt-saturate: 195%;
266
+ --vt-radius: 18px;
267
+ --vt-width: 390px;
268
+ --vt-success: #34d399;
269
+ --vt-error: #fb7185;
270
+ --vt-warning: #fbbf24;
271
+ --vt-info: #38bdf8;
272
+ --vt-loading: #a78bfa;
273
+ }
274
+ ```
275
+
276
+ ### Granular Slot Styling (`classNames`)
277
+
278
+ Style any internal element with Tailwind CSS or CSS Modules:
279
+
280
+ ```tsx
281
+ <Toaster
282
+ classNames={{
283
+ toast: "shadow-2xl",
284
+ title: "tracking-tight",
285
+ description: "text-xs opacity-80",
286
+ actionButton: "rounded-full",
287
+ closeButton: "hover:scale-110",
288
+ }}
289
+ />
290
+ ```
291
+
292
+ ---
293
+
294
+ ## Framework-Agnostic Core (`vetra-toast/core`)
295
+
296
+ Import the notification store and timer engine without pulling React into non-UI modules:
297
+
298
+ ```ts
299
+ import { createToastStore, createToastApi, defaultToastStore } from "vetra-toast/core";
300
+
301
+ const store = createToastStore({ visibleToasts: 3, defaultDuration: 3500 });
302
+ const api = createToastApi(store);
303
+ api.success("Triggered outside React");
304
+ ```
305
+
306
+ ---
307
+
308
+ ## Accessibility
309
+
310
+ - **Semantic Live Regions**: `error` and `warning` use `role="alert"` (`aria-live="assertive"`); `success`, `info`, and `loading` use `role="status"` (`aria-live="polite"`).
311
+ - **Keyboard Control**: Press `Alt+T` to focus active notifications, `Tab` through actions/close buttons with high-visibility focus rings, or press `Escape` to dismiss.
312
+ - **Tab Visibility Awareness**: Timers pause automatically when the browser tab goes hidden (`document.visibilitychange`) and resume when returning.
313
+ - **OS Preferences**: Automatic `@media (prefers-reduced-transparency: reduce)` solid surface fallback and `@media (prefers-reduced-motion: reduce)` gentle fade transitions.
314
+
315
+ ---
28
316
 
29
- - Frosted glassmorphism UI with dark, light, and system themes
30
- - `success`, `error`, `warning`, `info`, `loading`, `promise`, `custom`, `update`, `dismiss`, `dismissAll`
31
- - 6 positions + responsive mobile layout
32
- - Synchronized progress bar, pause on hover, pause on focus, pause on background tab, swipe-to-dismiss
33
- - Stacking + FIFO queue management + duplicate prevention
34
- - Accessible (`role="alert"` / `role="status"`, `Escape` dismiss, reduced motion & reduced transparency)
35
- - SSR-safe & Next.js App Router compatible (`"use client"` included)
36
- - Zero runtime dependencies
317
+ ## Author & License
37
318
 
38
- ## License
319
+ Created by **[Mobarok](https://www.mobarok.me)** ([GitHub @immobarok](https://github.com/immobarok)).
39
320
 
40
- MIT
321
+ Licensed under the [MIT License](https://github.com/immobarok/vetra-toast/blob/main/LICENSE).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vetra-toast",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Premium glassmorphism toast notification library for modern React and Next.js applications.",
5
5
  "keywords": [
6
6
  "react",