toastify-pro 1.3.0 → 1.5.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
@@ -10,7 +10,7 @@
10
10
  [![License](https://img.shields.io/npm/l/toastify-pro.svg)](https://github.com/abhipotter/toastify-pro/blob/main/LICENSE)
11
11
  [![Bundle Size](https://img.shields.io/bundlephobia/minzip/toastify-pro)](https://bundlephobia.com/package/toastify-pro)
12
12
 
13
- [Demo](https://abhipotter.github.io/toastify-pro) • [Documentation](https://github.com/abhipotter/toastify-pro/wiki) • [Examples](https://github.com/abhipotter/toastify-pro/tree/main/examples)
13
+ [Demo](https://abhipotter.github.io/toastify-pro/demo) • [Documentation](https://github.com/abhipotter/toastify-pro/wiki) • [Examples](https://github.com/abhipotter/toastify-pro/tree/main/examples)
14
14
 
15
15
  </div>
16
16
 
@@ -18,8 +18,8 @@
18
18
 
19
19
  - 🚀 **Lightweight** - Minimal bundle size with zero dependencies
20
20
  - 🎨 **6 Built-in Themes** - Success, Error, Info, Warning, Dark, and Light themes
21
- - 🎯 **Interactive Confirmation Dialogs** - Perfect replacement for SweetAlert with dark/light themes only
22
- - 📱 **7 Flexible Positions** - Including new center position ideal for confirmations
21
+ - 🎯 **Interactive Confirmation Dialogs** - Perfect replacement for SweetAlert with dark/light themes
22
+ - 📱 **7 Flexible Positions** - Including center position ideal for confirmations
23
23
  - ⚡ **Apple-Style Animations** - Smooth AirDrop-inspired entrance and car-swipe exit effects
24
24
  - 🔧 **Framework Agnostic** - Works with React, Vue, Angular, or vanilla JS
25
25
  - 🎯 **Auto-dismiss** - Configurable timeout with manual close option
@@ -28,8 +28,9 @@
28
28
  - ♿ **Accessible** - Clean HTML structure with proper ARIA support
29
29
  - 🎨 **Custom SVG Icons** - Beautiful vector icons for each toast type
30
30
  - ✨ **Modern Design** - Glassmorphism effects with backdrop blur
31
- - **Perfect Callback Handling** - No double execution, conflict-free patterns
32
- - **Close Button** - Interactive close buttons for confirmation dialogs
31
+ - 🔒 **Single Instance** - Only one confirmation at a time with shake animation
32
+ - **Loading States** - Built-in loading spinner for async operations
33
+ - 🎨 **Custom Gradients** - primaryColor & secondaryColor for gradient backgrounds
33
34
 
34
35
  ## 🚀 Quick Start
35
36
 
@@ -235,76 +236,133 @@ toast.light('Settings updated', { timeout: 2000 });
235
236
  toast.light('Light Mode', 'Switched to clean light theme.'); // With description
236
237
  ```
237
238
 
238
- #### 🆕 `toast.conf(message, descriptionOrCallback, callback)`
239
- Display an interactive confirmation dialog with confirm/cancel buttons.
239
+ #### 🆕 `toast.conf(message, descriptionOrCallback, callback)` or `toast.confirm(message, descriptionOrCallback, callback)`
240
+ Display an interactive confirmation dialog with confirm/cancel buttons. Both methods work identically.
240
241
 
241
242
  **Features:**
242
243
  - 🎯 **Center positioning** (default) for maximum attention
243
- - ✖️ **Close button** in top-right corner (acts as cancel)
244
- - 🎨 **Simple theming** - Dark (default) or Light themes only
244
+ - 🔒 **Single instance** - Only one confirmation at a time with shake animation
245
+ - **Loading states** - Built-in spinner for async operations
246
+ - 🎨 **Custom gradients** - primaryColor & secondaryColor support
245
247
  - 📱 **Responsive** design for mobile devices
246
248
  - ⚡ **No auto-dismiss** - requires user interaction
247
249
 
248
- **Theme Options:**
249
- - `theme: 'dark'` (default) - Dark theme with elegant styling
250
- - `theme: 'light'` or `theme: 'white'` - Clean light theme with dark text
250
+ **Options:**
251
+ | Option | Type | Default | Description |
252
+ |--------|------|---------|-------------|
253
+ | `description` | string | - | Secondary text below the message |
254
+ | `confirmText` | string | `'Confirm'` | Custom confirm button text |
255
+ | `cancelText` | string | `'Cancel'` | Custom cancel button text |
256
+ | `theme` | string | `'dark'` | Theme: `'dark'` or `'light'` |
257
+ | `position` | string | `'center'` | Any valid position |
258
+ | `primaryColor` | string | - | Primary gradient color (hex) |
259
+ | `secondaryColor` | string | - | Secondary gradient color (hex) |
260
+ | `onConfirm` | function | - | Callback when confirmed |
261
+ | `onCancel` | function | - | Callback when cancelled |
251
262
 
252
263
  ```javascript
253
- // Simple confirmation with callback
264
+ // Simple confirmation
254
265
  toast.conf('Delete this item?', (confirmed) => {
255
- if (confirmed) {
256
- console.log('User confirmed');
257
- } else {
258
- console.log('User cancelled');
259
- }
266
+ if (confirmed) toast.success('Deleted!');
260
267
  });
261
268
 
262
- // Confirmation with description
269
+ // With description
263
270
  toast.conf('Are you sure?', 'This action cannot be undone.', (confirmed) => {
264
- handleUserChoice(confirmed);
271
+ console.log('User confirmed:', confirmed);
265
272
  });
266
273
 
267
- // Advanced confirmation with full options
274
+ // With options
268
275
  toast.conf('Save changes?', {
269
- description: 'Your changes will be permanently saved to the server.',
270
- confirmText: 'Save Now', // Custom confirm button text
271
- cancelText: 'Discard', // Custom cancel button text
272
- theme: 'light', // Theme: 'dark' (default) or 'light'
273
- position: 'center', // Position (defaults to 'center' for confirmations)
274
- onConfirm: () => saveData(), // Alternative callback approach
275
- onCancel: () => discardChanges()
276
+ description: 'Your changes will be saved permanently.',
277
+ confirmText: 'Save',
278
+ cancelText: 'Discard',
279
+ theme: 'light',
280
+ position: 'center'
281
+ }, (confirmed) => {
282
+ if (confirmed) submitForm();
276
283
  });
284
+ ```
277
285
 
278
- // Real-world example: Delete confirmation
279
- function deleteItem(itemId) {
280
- toast.conf('Delete item?',
281
- 'This will permanently remove the item from your account.',
282
- (confirmed) => {
283
- if (confirmed) {
284
- // Perform deletion
285
- deleteFromServer(itemId);
286
- toast.success('Item deleted successfully!');
287
- } else {
288
- toast.info('Delete cancelled');
289
- }
290
- }
291
- );
292
- }
286
+ #### Loading States
287
+ Handle async operations with built-in loading spinner:
293
288
 
294
- // Form save confirmation
295
- function handleFormSubmit() {
296
- toast.conf('Save changes?', {
297
- description: 'Your form data will be submitted and cannot be edited later.',
298
- confirmText: 'Submit',
299
- cancelText: 'Keep Editing',
300
- theme: 'dark', // Default theme, can be 'light'
301
- position: 'center'
302
- }, (confirmed) => {
303
- if (confirmed) {
304
- submitForm();
305
- }
306
- });
307
- }
289
+ ```javascript
290
+ // Manual loading control
291
+ toast.conf('Process data?', {
292
+ confirmText: 'Process'
293
+ }, (confirmed, { setLoading, close }) => {
294
+ if (confirmed) {
295
+ setLoading(true); // Show spinner, disable buttons
296
+
297
+ fetch('/api/process')
298
+ .then(() => {
299
+ setLoading(false);
300
+ close();
301
+ toast.success('Done!');
302
+ })
303
+ .catch(() => {
304
+ setLoading(false);
305
+ close();
306
+ toast.error('Failed!');
307
+ });
308
+ }
309
+ });
310
+
311
+ // Async/await (auto-loading for promises)
312
+ toast.conf('Fetch data?', {
313
+ confirmText: 'Fetch',
314
+ onConfirm: async () => {
315
+ await fetch('/api/data'); // Auto shows loading
316
+ toast.success('Data fetched!');
317
+ }
318
+ });
319
+
320
+ // With custom colors
321
+ toast.conf('Upload file?', {
322
+ primaryColor: '#f59e0b',
323
+ secondaryColor: '#d97706',
324
+ onConfirm: async ({ setLoading, close }) => {
325
+ setLoading(true);
326
+ await uploadFile();
327
+ close();
328
+ toast.success('Uploaded!');
329
+ }
330
+ });
331
+ ```
332
+
333
+ #### 🎨 Custom Gradient Colors
334
+ Create beautiful gradient backgrounds:
335
+
336
+ ```javascript
337
+ // Orange gradient
338
+ toast.conf('Custom styled!', {
339
+ primaryColor: '#f97316',
340
+ secondaryColor: '#ea580c',
341
+ confirmText: 'Nice!'
342
+ });
343
+
344
+ // Purple gradient
345
+ toast.conf('Purple theme', {
346
+ primaryColor: '#8b5cf6',
347
+ secondaryColor: '#6366f1'
348
+ });
349
+
350
+ // Text color auto-adjusts based on background brightness
351
+ toast.conf('Light background', {
352
+ primaryColor: '#fef3c7', // Light color
353
+ secondaryColor: '#fde68a' // Dark text will be used
354
+ });
355
+ ```
356
+
357
+ #### 🔒 Single Instance (Shake Effect)
358
+ Only one confirmation dialog can be open at a time. Attempting to open another will shake the existing one:
359
+
360
+ ```javascript
361
+ // First call - shows confirmation
362
+ toast.conf('First dialog');
363
+
364
+ // Second call - shakes existing dialog instead of opening new one
365
+ toast.conf('Second dialog'); // Shakes first dialog!
308
366
  ```
309
367
 
310
368
  ### 🆕 Enhanced Features