vetra-toast 1.0.0 → 1.0.2

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