toastify-pro 1.2.0 → 1.4.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,18 +18,19 @@
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
- - 📱 **Flexible Positioning** - 6 different position options
22
- - **Apple-Style Animations** - Smooth AirDrop-inspired entrance and exit effects
21
+ - 🎯 **Interactive Confirmation Dialogs** - Perfect replacement for SweetAlert with dark/light themes
22
+ - 📱 **7 Flexible Positions** - Including center position ideal for confirmations
23
+ - ⚡ **Apple-Style Animations** - Smooth AirDrop-inspired entrance and car-swipe exit effects
23
24
  - 🔧 **Framework Agnostic** - Works with React, Vue, Angular, or vanilla JS
24
25
  - 🎯 **Auto-dismiss** - Configurable timeout with manual close option
25
26
  - 📝 **Description Support** - Optional secondary text for detailed messages
26
27
  - 🌈 **Easy Customization** - Simple API with sensible defaults
27
- - ♿ **Accessible** - Clean HTML structure with proper styling
28
+ - ♿ **Accessible** - Clean HTML structure with proper ARIA support
28
29
  - 🎨 **Custom SVG Icons** - Beautiful vector icons for each toast type
29
- - 🚗 **Car Swipe Exit Animations** - Position-aware exit animations (5 types)
30
- - 📱 **POP UP Entrance** - iOS-inspired entrance animation with rotation
31
- - **Glassmorphism Design** - Modern backdrop blur effects and transparency
32
- - 📊 **Progress Bar Animation** - Visual countdown with shimmer effects
30
+ - **Modern Design** - Glassmorphism effects with backdrop blur
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
 
@@ -65,6 +66,31 @@ toast.light('Light themed message');
65
66
  toast.success('Success!', 'Your changes have been saved successfully.');
66
67
  toast.error('Error occurred!', 'Please check your network connection and try again.');
67
68
  toast.info('New feature!', 'Check out our latest updates in the dashboard.');
69
+
70
+ // 🆕 NEW: Confirmation dialogs
71
+ toast.conf('Delete this item?', (confirmed) => {
72
+ if (confirmed) {
73
+ toast.success('Item deleted successfully!');
74
+ } else {
75
+ toast.info('Delete cancelled');
76
+ }
77
+ });
78
+
79
+ // Confirmation with description
80
+ toast.conf('Are you sure?', 'This action cannot be undone.', (confirmed) => {
81
+ console.log('User confirmed:', confirmed);
82
+ });
83
+
84
+ // Advanced confirmation options
85
+ toast.conf('Save changes?', {
86
+ description: 'Your changes will be permanently saved.',
87
+ confirmText: 'Save',
88
+ cancelText: 'Discard',
89
+ theme: 'light', // 'dark' (default) or 'light'
90
+ position: 'center', // Default for confirmations
91
+ onConfirm: () => console.log('Confirmed!'),
92
+ onCancel: () => console.log('Cancelled!')
93
+ });
68
94
  ```
69
95
 
70
96
  #### With CDN
@@ -77,6 +103,7 @@ toast.info('New feature!', 'Check out our latest updates in the dashboard.');
77
103
  </head>
78
104
  <body>
79
105
  <button onclick="showToast()">Show Toast</button>
106
+ <button onclick="showConfirmation()">Show Confirmation</button>
80
107
 
81
108
  <script>
82
109
  const toast = new ToastifyPro();
@@ -95,6 +122,29 @@ toast.info('New feature!', 'Check out our latest updates in the dashboard.');
95
122
  allowClose: true
96
123
  });
97
124
  }
125
+
126
+ // 🆕 NEW: Confirmation dialogs
127
+ function showConfirmation() {
128
+ toast.conf('Delete this item?', 'This action cannot be undone.', (confirmed) => {
129
+ if (confirmed) {
130
+ toast.success('Item deleted!');
131
+ } else {
132
+ toast.info('Delete cancelled');
133
+ }
134
+ });
135
+ }
136
+
137
+ function showAdvancedConfirmation() {
138
+ toast.conf('Save document?', {
139
+ description: 'All your changes will be saved permanently.',
140
+ confirmText: 'Save Now',
141
+ cancelText: 'Cancel',
142
+ theme: 'light',
143
+ position: 'center'
144
+ }, (confirmed) => {
145
+ console.log('User decision:', confirmed);
146
+ });
147
+ }
98
148
  </script>
99
149
  </body>
100
150
  </html>
@@ -120,6 +170,7 @@ const toast = new ToastifyPro({
120
170
  - `bottom-left` - Bottom left corner
121
171
  - `bottom-right` - Bottom right corner
122
172
  - `bottom-center` - Bottom center (default)
173
+ - `center` - Perfect center of screen (ideal for confirmations)
123
174
 
124
175
  ### Methods
125
176
 
@@ -185,6 +236,135 @@ toast.light('Settings updated', { timeout: 2000 });
185
236
  toast.light('Light Mode', 'Switched to clean light theme.'); // With description
186
237
  ```
187
238
 
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.
241
+
242
+ **Features:**
243
+ - 🎯 **Center positioning** (default) for maximum attention
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
247
+ - 📱 **Responsive** design for mobile devices
248
+ - ⚡ **No auto-dismiss** - requires user interaction
249
+
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 |
262
+
263
+ ```javascript
264
+ // Simple confirmation
265
+ toast.conf('Delete this item?', (confirmed) => {
266
+ if (confirmed) toast.success('Deleted!');
267
+ });
268
+
269
+ // With description
270
+ toast.conf('Are you sure?', 'This action cannot be undone.', (confirmed) => {
271
+ console.log('User confirmed:', confirmed);
272
+ });
273
+
274
+ // With options
275
+ toast.conf('Save changes?', {
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();
283
+ });
284
+ ```
285
+
286
+ #### ⏳ Loading States
287
+ Handle async operations with built-in loading spinner:
288
+
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!
366
+ ```
367
+
188
368
  ### 🆕 Enhanced Features
189
369
 
190
370
  #### Custom SVG Icons
@@ -305,6 +485,34 @@ function App() {
305
485
  toast?.info('New Feature!', 'Check out our latest React integration updates.');
306
486
  };
307
487
 
488
+ // 🆕 NEW: Confirmation dialog examples
489
+ const handleDelete = () => {
490
+ toast?.conf('Delete item?', 'This action cannot be undone.', (confirmed) => {
491
+ if (confirmed) {
492
+ // Perform deletion logic
493
+ console.log('Deleting item...');
494
+ toast?.success('Item deleted successfully!');
495
+ } else {
496
+ toast?.info('Delete cancelled');
497
+ }
498
+ });
499
+ };
500
+
501
+ const handleLogout = () => {
502
+ toast?.conf('Sign out?', {
503
+ description: 'You will need to sign in again to access your account.',
504
+ confirmText: 'Sign Out',
505
+ cancelText: 'Stay Signed In',
506
+ theme: 'dark',
507
+ position: 'center'
508
+ }, (confirmed) => {
509
+ if (confirmed) {
510
+ // Logout logic
511
+ window.location.href = '/login';
512
+ }
513
+ });
514
+ };
515
+
308
516
  const handleIconDemo = () => {
309
517
  // Showcase different icons with descriptions
310
518
  toast?.success('✓ Success Icon', 'Beautiful checkmark with green theme');
@@ -319,6 +527,8 @@ function App() {
319
527
  <button onClick={handleError}>Show Error</button>
320
528
  <button onClick={handleWithDescription}>Show with Description</button>
321
529
  <button onClick={handleIconDemo}>Demo All Icons</button>
530
+ <button onClick={handleDelete}>Delete with Confirmation</button>
531
+ <button onClick={handleLogout}>Logout Confirmation</button>
322
532
  </div>
323
533
  );
324
534
  }
@@ -333,6 +543,8 @@ export default App;
333
543
  <button @click="showSuccess">Show Success</button>
334
544
  <button @click="showError">Show Error</button>
335
545
  <button @click="showCustom">Show Custom</button>
546
+ <button @click="showConfirmation">Show Confirmation</button>
547
+ <button @click="showDeleteConfirmation">Delete Item</button>
336
548
  </div>
337
549
  </template>
338
550
 
@@ -364,6 +576,38 @@ export default {
364
576
  timeout: 6000,
365
577
  allowClose: true
366
578
  });
579
+ },
580
+ // 🆕 NEW: Confirmation methods
581
+ showConfirmation() {
582
+ this.toast.conf('Save changes?', (confirmed) => {
583
+ if (confirmed) {
584
+ this.saveData();
585
+ } else {
586
+ this.toast.info('Changes not saved');
587
+ }
588
+ });
589
+ },
590
+ showDeleteConfirmation() {
591
+ this.toast.conf('Delete this item?', {
592
+ description: 'This action cannot be undone and will remove all associated data.',
593
+ confirmText: 'Delete',
594
+ cancelText: 'Keep',
595
+ theme: 'dark',
596
+ position: 'center'
597
+ }, (confirmed) => {
598
+ if (confirmed) {
599
+ this.deleteItem();
600
+ this.toast.success('Item deleted successfully!');
601
+ }
602
+ });
603
+ },
604
+ saveData() {
605
+ // Save logic here
606
+ this.toast.success('Data saved successfully!');
607
+ },
608
+ deleteItem() {
609
+ // Delete logic here
610
+ console.log('Item deleted');
367
611
  }
368
612
  }
369
613
  };
@@ -381,6 +625,8 @@ import ToastifyPro from 'toastify-pro';
381
625
  <button (click)="showSuccess()">Show Success</button>
382
626
  <button (click)="showError()">Show Error</button>
383
627
  <button (click)="showInfo()">Show Info</button>
628
+ <button (click)="showConfirmation()">Show Confirmation</button>
629
+ <button (click)="showLogoutConfirmation()">Logout</button>
384
630
  `
385
631
  })
386
632
  export class ToastExampleComponent implements OnInit {
@@ -407,6 +653,41 @@ export class ToastExampleComponent implements OnInit {
407
653
  timeout: 5000
408
654
  });
409
655
  }
656
+
657
+ // 🆕 NEW: Confirmation methods
658
+ showConfirmation() {
659
+ this.toast.conf('Save document?', 'All changes will be saved permanently.', (confirmed: boolean) => {
660
+ if (confirmed) {
661
+ this.saveDocument();
662
+ } else {
663
+ this.toast.info('Save cancelled');
664
+ }
665
+ });
666
+ }
667
+
668
+ showLogoutConfirmation() {
669
+ this.toast.conf('Sign out?', {
670
+ description: 'You will be logged out of your account.',
671
+ confirmText: 'Sign Out',
672
+ cancelText: 'Cancel',
673
+ theme: 'light',
674
+ position: 'center'
675
+ }, (confirmed: boolean) => {
676
+ if (confirmed) {
677
+ this.logout();
678
+ }
679
+ });
680
+ }
681
+
682
+ private saveDocument() {
683
+ // Save logic
684
+ this.toast.success('Document saved successfully!');
685
+ }
686
+
687
+ private logout() {
688
+ // Logout logic
689
+ this.toast.success('Logged out successfully!');
690
+ }
410
691
  }
411
692
  ```
412
693
 
@@ -419,30 +700,71 @@ const toast = new ToastifyPro({
419
700
  allowClose: true
420
701
  });
421
702
 
422
- // Form submission example
703
+ // Form submission example with confirmation
423
704
  document.getElementById('submitForm').addEventListener('click', async function() {
424
- try {
425
- // Simulate API call
426
- const response = await fetch('/api/submit', { method: 'POST' });
427
-
428
- if (response.ok) {
429
- toast.success('Form submitted successfully!', 'Your data has been processed and saved.');
430
- } else {
431
- toast.error('Failed to submit form', 'Please check your inputs and try again.');
705
+ toast.conf('Submit form?', 'Your data will be sent to the server.', async (confirmed) => {
706
+ if (confirmed) {
707
+ try {
708
+ // Simulate API call
709
+ const response = await fetch('/api/submit', { method: 'POST' });
710
+
711
+ if (response.ok) {
712
+ toast.success('Form submitted successfully!', 'Your data has been processed and saved.');
713
+ } else {
714
+ toast.error('Failed to submit form', 'Please check your inputs and try again.');
715
+ }
716
+ } catch (error) {
717
+ toast.error('Network error occurred', 'Check your connection and retry.');
718
+ }
432
719
  }
433
- } catch (error) {
434
- toast.error('Network error occurred', 'Check your connection and retry.');
435
- }
720
+ });
436
721
  });
437
722
 
438
- // File upload with progress
723
+ // Delete confirmation example
724
+ function deleteItem(itemId) {
725
+ toast.conf('Delete this item?', {
726
+ description: 'This action cannot be undone and will permanently remove all associated data.',
727
+ confirmText: 'Delete',
728
+ cancelText: 'Keep',
729
+ theme: 'dark',
730
+ position: 'center'
731
+ }, (confirmed) => {
732
+ if (confirmed) {
733
+ // Perform deletion
734
+ console.log('Deleting item:', itemId);
735
+ toast.success('Item deleted!', 'The item has been permanently removed.');
736
+ } else {
737
+ toast.info('Delete cancelled', 'Your item is safe.');
738
+ }
739
+ });
740
+ }
741
+
742
+ // File upload with confirmation and progress
439
743
  function handleFileUpload() {
440
- toast.info('Uploading...', 'Please wait while we process your file.');
441
-
442
- // Simulate upload completion
443
- setTimeout(() => {
444
- toast.success('Upload complete!', 'Your file has been uploaded successfully.');
445
- }, 3000);
744
+ toast.conf('Upload file?', 'The file will be uploaded to your account.', (confirmed) => {
745
+ if (confirmed) {
746
+ toast.info('Uploading...', 'Please wait while we process your file.');
747
+
748
+ // Simulate upload completion
749
+ setTimeout(() => {
750
+ toast.success('Upload complete!', 'Your file has been uploaded successfully.');
751
+ }, 3000);
752
+ }
753
+ });
754
+ }
755
+
756
+ // Logout confirmation
757
+ function logout() {
758
+ toast.conf('Sign out?', {
759
+ description: 'You will need to sign in again to access your account.',
760
+ confirmText: 'Sign Out',
761
+ cancelText: 'Stay Signed In',
762
+ theme: 'light'
763
+ }, (confirmed) => {
764
+ if (confirmed) {
765
+ window.location.href = '/login';
766
+ }
767
+ });
446
768
  }
447
769
 
448
770
  // Multiple toast types with descriptions
@@ -455,7 +777,7 @@ function showAllTypes() {
455
777
  setTimeout(() => toast.light('Light Mode', 'Clean light notification'), 2500);
456
778
  }
457
779
 
458
- // Showcase new enhanced features
780
+ // Showcase new enhanced features including confirmations
459
781
  function demoEnhancedFeatures() {
460
782
  // SVG Icons demo
461
783
  toast.success('✓ Beautiful Icons', 'Each type has its own vector icon that scales perfectly');
@@ -474,24 +796,61 @@ function demoEnhancedFeatures() {
474
796
  setTimeout(() => {
475
797
  toast.dark('✨ Glassmorphism', 'Modern backdrop blur with translucent design');
476
798
  }, 3000);
799
+
800
+ // 🆕 Confirmation dialog demo
801
+ setTimeout(() => {
802
+ toast.conf('Try confirmation?', 'Experience the new interactive dialog feature.', (confirmed) => {
803
+ if (confirmed) {
804
+ toast.success('🎉 Confirmation works!', 'You can now create interactive dialogs easily.');
805
+ } else {
806
+ toast.info('No problem!', 'Confirmation dialogs are optional.');
807
+ }
808
+ });
809
+ }, 4000);
810
+ }
811
+
812
+ // Advanced confirmation examples
813
+ function advancedConfirmationExamples() {
814
+ // Settings reset confirmation
815
+ toast.conf('Reset all settings?', {
816
+ description: 'This will restore all settings to their default values.',
817
+ confirmText: 'Reset',
818
+ cancelText: 'Cancel',
819
+ theme: 'dark',
820
+ position: 'center'
821
+ }, (confirmed) => {
822
+ if (confirmed) {
823
+ // Reset settings logic
824
+ toast.success('Settings reset!', 'All settings have been restored to defaults.');
825
+ }
826
+ });
477
827
  }
478
828
 
479
829
  // Advanced usage with all new features
480
830
  function advancedExample() {
481
- // Progress indication with description
482
- toast.info('Processing...', {
483
- description: 'Please wait while we upload your file to the server',
484
- timeout: 0, // No auto-dismiss
485
- allowClose: true
831
+ // Progress indication with confirmation first
832
+ toast.conf('Start processing?', {
833
+ description: 'This will upload your file to the server and may take a few minutes.',
834
+ confirmText: 'Start',
835
+ cancelText: 'Later',
836
+ theme: 'light'
837
+ }, (confirmed) => {
838
+ if (confirmed) {
839
+ toast.info('Processing...', {
840
+ description: 'Please wait while we upload your file to the server',
841
+ timeout: 0, // No auto-dismiss
842
+ allowClose: true
843
+ });
844
+
845
+ // Simulate progress completion
846
+ setTimeout(() => {
847
+ toast.success('Upload Complete!', {
848
+ description: 'Your file has been uploaded successfully with all metadata',
849
+ timeout: 5000
850
+ });
851
+ }, 3000);
852
+ }
486
853
  });
487
-
488
- // Simulate progress completion
489
- setTimeout(() => {
490
- toast.success('Upload Complete!', {
491
- description: 'Your file has been uploaded successfully with all metadata',
492
- timeout: 5000
493
- });
494
- }, 3000);
495
854
  }
496
855
  ```
497
856