react-confirm-lite 1.5.5 โ†’ 1.5.7

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
@@ -11,13 +11,6 @@
11
11
 
12
12
  ![Sample Image](https://camo.githubusercontent.com/af08928ac7006e57dc2a28f01b1fbc7214ea742379365f364f37bb204a93906b/68747470733a2f2f7265732e636c6f7564696e6172792e636f6d2f646863716e35626d712f696d6167652f75706c6f61642f76313736363737383630322f53637265656e6361737466726f6d323032352d31322d323730302d34322d31342d657a6769662e636f6d2d6f7074696d697a655f6f64316874322e676966)
13
13
 
14
- ## What's new?
15
- Just optimized, but now you will have to give an id to api and ConfirmContainer only if you're using multiple containers on the same page and want to show the specfic container when a specific api is called otherwise it will show the first rendered component. But one more thing if don't want to give the id and want to show the closest to the button then you can pass an argument to the api like this.
16
- ```ts
17
- confirm('Are you sure?',true)
18
- ```
19
- then it will show the closest otherwise will show the first rendered.
20
-
21
14
  ## ๐Ÿ”— Live Demo
22
15
 
23
16
  [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/edit/vitejs-vite-bfthlpmw?file=src%2FApp.tsx)
@@ -76,646 +69,9 @@ One more thing that if you want to show the closest container to button to which
76
69
  ```ts
77
70
  confirm('Are you sure?', true)
78
71
  ```
79
- or if you want that everytime it show the closest without passing true in api then you can do like this in root directory
72
+ or if you want that everytime it show the closest without passing true in api then you can do like this in root component
80
73
  ```ts
81
74
  import { showClosest } from 'react-confirm-lite'
82
75
  showClosest()
83
76
  ```
84
-
85
- ## ๐ŸŽฏ Features
86
-
87
- ### โœ… Simple Promise-based API
88
- ```tsx
89
- const result = await confirm('Message here');
90
- // Returns true for OK, false for Cancel, null for ESC/outside click
91
- ```
92
-
93
- ### โœ… 18 Built-in Animations
94
- Choose from various animations:
95
- - `slide` (default) - Smooth slide up/down
96
- - `fadeScale` - Fade with scale effect
97
- - `bounce` - Playful bounce animation
98
- - `flip` - 3D flip effect
99
- - `zoom` - Zoom in/out
100
- - `rotate` - Rotate animation
101
- - `fadeUp` / `fadeDown` - Directional fade
102
- - `drop` - 3D drop effect
103
- - `slideRight` / `slideLeft` - Horizontal slides
104
- - `slideVertical` - Vertical slide
105
- - `slideDown` - Slide down
106
- - `rotateRight` - Rotate from right
107
- - `zoomSmall` / `bounceSmall` - Subtle animations
108
- - `fadeBlur` / `fadeShrink` - Creative effects
109
-
110
- ### โœ… 6 Color Schemes
111
- Pre-built color themes:
112
- - `dark` (default) - Dark theme
113
- - `light` - Light theme
114
- - `blue` - Blue theme
115
- - `red` - Perfect for destructive actions
116
- - `green` - Success actions
117
- - `purple` - Premium/feature actions
118
-
119
- ### โœ… Interactive Controls
120
- - `closeOnEscape` (default: true) - Press ESC to close
121
- - `closeOnClickOutside` (default: true) - Click backdrop to close
122
- - Returns `null` when closed via ESC or backdrop click
123
-
124
- ### โœ… Customizable Options
125
- Control every aspect:
126
- - Custom OK/Cancel button text
127
- - Separate animation durations for enter/exit
128
- - Override colors per dialog
129
- - Custom CSS classes for all elements
130
-
131
- ### โœ… Queue System
132
- Multiple confirm requests automatically queue and show one at a time:
133
- ```tsx
134
- // These will show sequentially
135
- await confirm('First?');
136
- await confirm('Second?');
137
- await confirm('Third?');
138
- ```
139
-
140
- ### โœ… Zero Configuration
141
- No CSS imports needed. Styles are automatically injected.
142
-
143
- ## ๐ŸŽจ Usage Examples
144
-
145
- ### Basic Usage
146
- ```tsx
147
- const result = await confirm('Delete this item?');
148
- if (result) {
149
- // User clicked OK
150
- deleteItem();
151
- } else if (result === false) {
152
- // User clicked Cancel
153
- console.log('Cancelled');
154
- } else if (result === null) {
155
- // User pressed ESC or clicked outside
156
- console.log('Closed via ESC/backdrop');
157
- }
158
- ```
159
-
160
- ### Custom Dialog Options
161
- ```tsx
162
- const result = await confirm({
163
- title: 'Delete Account',
164
- message: 'This will permanently delete your account and all data.',
165
- okText: 'Delete Forever',
166
- cancelText: 'Cancel',
167
- colorSchema: 'red'
168
- });
169
- ```
170
-
171
- ### Disable ESC and Backdrop Closing
172
- ```tsx
173
- <ConfirmContainer
174
- closeOnEscape={false}
175
- closeOnClickOutside={false}
176
- />
177
- // Now dialog can only be closed with Cancel/OK buttons
178
- ```
179
-
180
- ## ๐Ÿ”ง API Reference
181
-
182
- ### Confirm Container Props
183
-
184
- | Prop | Type | Default | Description |
185
- |------|------|---------|-------------|
186
- |`id`|`string`| `random` | To show a specific container with a specific confirm() app |
187
- | `animation` | `AnimationType` | `'slide'` | Animation type (18 options) |
188
- | `animationDuration` | `number` | `300` | Base animation duration (ms) |
189
- | `animationDurationIn` | `number` | - | Enter animation duration |
190
- | `animationDurationOut` | `number` | - | Exit animation duration |
191
- | `defaultColorSchema` | `ColorSchema` | `'dark'` | Default color scheme |
192
- | `closeOnEscape` | `boolean` | `true` | Close with ESC key |
193
- | `closeOnClickOutside` | `boolean` | `true` | Close on backdrop click |
194
- | `classes` | `ConfirmClasses` | `{}` | Custom CSS classes |
195
- <!-- | `closest` | `boolean` | `false` | If you want to show the closest container when api is called then do this true but it may be slow.| -->
196
-
197
- ### Confirm Function
198
-
199
- ```tsx
200
- // String input (simple)
201
- await confirm('Simple message');
202
-
203
- // Object input (full options)
204
- await confirm({
205
- title: 'Custom Title', // Optional
206
- message: 'Required message', // Required
207
- okText: 'Proceed', // Optional
208
- cancelText: 'Go Back', // Optional
209
- colorSchema: 'blue', // Optional
210
- });
211
- ```
212
-
213
- **Return values:**
214
- - `true` - User clicked OK
215
- - `false` - User clicked Cancel
216
- - `null` - User pressed ESC or clicked outside (if enabled)
217
-
218
- ### Custom Styling with CSS Classes
219
-
220
- ```tsx
221
- <ConfirmContainer
222
- classes={{
223
- overlay: "my-overlay-class", // Background overlay
224
- wrapper: "my-modal-class", // Modal container
225
- title: "my-title-class", // Title text
226
- message: "my-message-class", // Message text
227
- button: "my-button-class", // Both buttons
228
- cancel: "my-cancel-class", // Cancel button only
229
- ok: "my-ok-class", // OK button only
230
- }}
231
- />
232
- ```
233
-
234
- ## ๐ŸŽญ Custom UI with Render Prop
235
-
236
- Want complete control over the UI? Use the render prop:
237
-
238
- ```tsx
239
- <ConfirmContainer animationDuration={500}>
240
- {({
241
- isVisible,
242
- confirm,
243
- handleCancel,
244
- handleOk,
245
- containerRef,
246
- animationClass,
247
- animationStyle
248
- }) => (
249
- <div className={`modal-overlay ${isVisible ? 'show' : 'hide'}`}>
250
- {/* Your custom backdrop */}
251
- <div className="backdrop" onClick={handleCancel} />
252
-
253
- {/* Your custom modal */}
254
- <div
255
- ref={containerRef}
256
- className={`custom-modal ${animationClass}`}
257
- style={animationStyle}
258
- >
259
- <h2>{confirm.title}</h2>
260
- <p>{confirm.message}</p>
261
-
262
- <div className="buttons">
263
- <button onClick={handleCancel}>
264
- {confirm.cancelText || 'Cancel'}
265
- </button>
266
- <button onClick={handleOk}>
267
- {confirm.okText || 'OK'}
268
- </button>
269
- </div>
270
- </div>
271
- </div>
272
- )}
273
- </ConfirmContainer>
274
- ```
275
-
276
- **Available render props:**
277
- - `isVisible`: Boolean indicating if dialog should be visible
278
- - `confirm`: The current confirm options object
279
- - `handleCancel`: Function to cancel the dialog (returns false)
280
- - `handleOk`: Function to confirm the dialog (returns true)
281
- - `containerRef`: React ref for the modal container
282
- - `colorSchema`: Current color scheme
283
- - `animationClass`: CSS class for current animation
284
- - `animationStyle`: Style object with animation duration
285
- - `lockScroll`: Boolean, If will be true then scroll will be locked when dialog will show.
286
-
287
- ## ๐Ÿ“ฑ Real-World Examples
288
-
289
- ### Delete Confirmation with ESC Disabled
290
- ```tsx
291
- const handleDelete = async () => {
292
- // Force user to make explicit choice
293
- const result = await confirm({
294
- title: 'Delete Item',
295
- message: 'This action cannot be undone. Are you sure?',
296
- okText: 'Delete',
297
- cancelText: 'Keep',
298
- colorSchema: 'red'
299
- });
300
-
301
- // Result can only be true or false (no null since ESC/backdrop disabled)
302
- if (result) {
303
- await deleteItem();
304
- }
305
- };
306
-
307
- // In your component
308
- <ConfirmContainer closeOnEscape={false} closeOnClickOutside={false} />
309
- ```
310
-
311
- ### Form Submission with Backdrop Only
312
- ```tsx
313
- // Allow closing by clicking backdrop but not ESC
314
- <ConfirmContainer closeOnEscape={false} closeOnClickOutside={true} />
315
-
316
- const handleSubmit = async () => {
317
- const result = await confirm({
318
- title: 'Submit Form',
319
- message: 'Ready to submit this form?',
320
- okText: 'Submit',
321
- cancelText: 'Review',
322
- colorSchema: 'green'
323
- });
324
-
325
- if (result) {
326
- await submitForm();
327
- } else if (result === null) {
328
- // User clicked backdrop
329
- console.log('Closed by clicking outside');
330
- }
331
- };
332
- ```
333
-
334
- ### Different Behaviors for Different Dialogs
335
- ```tsx
336
- // Global: ESC and backdrop disabled
337
- <ConfirmContainer
338
- closeOnEscape={false}
339
- closeOnClickOutside={false}
340
- />
341
-
342
- // Some dialogs can override via custom UI
343
- const handleFlexibleDialog = async () => {
344
- // Create custom UI that allows ESC/backdrop
345
- const result = await confirm('Flexible dialog?');
346
- // result can be true, false, or null
347
- };
348
- ```
349
-
350
- ## ๐Ÿ—๏ธ Container Configuration
351
-
352
- ### Global Settings
353
- ```tsx
354
- <ConfirmContainer
355
- defaultColorSchema="light" // Light theme by default
356
- animation="zoom" // Zoom animation for all dialogs
357
- animationDuration={400} // 400ms animations
358
- closeOnEscape={true} // Allow ESC to close
359
- closeOnClickOutside={true} // Allow backdrop click to close
360
- animationDurationIn={350} // Enter: 350ms
361
- animationDurationOut={250} // Exit: 250ms
362
- lockScroll={false} // true by default
363
- />
364
- ```
365
-
366
- ### Different Close Behaviors
367
- ```tsx
368
- // Option 1: Fully closable (default)
369
- <ConfirmContainer closeOnEscape={true} closeOnClickOutside={true} />
370
- // Users can close via: OK, Cancel, ESC, or backdrop click
371
-
372
- // Option 2: Force explicit choice
373
- <ConfirmContainer closeOnEscape={false} closeOnClickOutside={false} />
374
- // Users can only close via: OK or Cancel buttons
375
-
376
- // Option 3: Backdrop only
377
- <ConfirmContainer closeOnEscape={false} closeOnClickOutside={true} />
378
- // Users can close via: OK, Cancel, or backdrop click
379
-
380
- // Option 4: ESC only
381
- <ConfirmContainer closeOnEscape={true} closeOnClickOutside={false} />
382
- // Users can close via: OK, Cancel, or ESC key
383
- ```
384
- If user will close dialog box by clicking outside or by pressing escape then it will return `null`
385
-
386
- ## ๐ŸŽจ Animation Gallery
387
-
388
- ### Slide Animations
389
- - `slide` - Smooth vertical slide (default)
390
- - `slideRight` / `slideLeft` - Horizontal slides
391
- - `slideVertical` - Vertical slide
392
- - `slideDown` - Slide down
393
-
394
- ### Fade Animations
395
- - `fadeScale` - Fade with scaling
396
- - `fadeUp` / `fadeDown` - Directional fades
397
- - `fadeBlur` - Fade with blur effect
398
- - `fadeShrink` - Fade with shrink effect
399
-
400
- ### 3D Animations
401
- - `flip` - Card flip effect
402
- - `drop` - 3D drop animation
403
- - `rotate` / `rotateRight` - Rotation effects
404
-
405
- ### Playful Animations
406
- - `bounce` / `bounceSmall` - Bounce effects
407
- - `zoom` / `zoomSmall` - Zoom in/out
408
-
409
- ## ๐Ÿšจ Troubleshooting
410
-
411
- ### Multiple dialogs are showing?
412
- - Make sure you are on version `>=1.4`
413
- - Make sure you didn't pass same id to different `<ConfirmContainer />`
414
-
415
- ### Dialog not showing?
416
- - Make sure `<ConfirmContainer />` is mounted
417
- - Check it's not conditionally rendered
418
-
419
- ### ESC key not working?
420
- - Check if `closeOnEscape={true}` (default)
421
- - Ensure no other event is preventing ESC
422
- - Try different browsers
423
-
424
- ### Backdrop click not working?
425
- - Verify `closeOnClickOutside={true}` (default)
426
- - Check if any parent element is preventing clicks
427
-
428
- ### Animation not working?
429
- - Verify animation name is correct
430
- - Check browser console for errors
431
-
432
- ### TypeScript errors?
433
- - Ensure you have `@types/react` installed
434
- - Update to latest TypeScript version
435
-
436
- ### Styling issues?
437
- - Use `classes` prop to override styles
438
- - Check CSS specificity
439
-
440
- You can also use it in TanStack with react easily
441
-
442
-
443
- ## ๐Ÿ“ฑ Next.js Support
444
-
445
- ### App Router (Next.js 15+)
446
- ```tsx
447
- // app/layout.tsx
448
- import { ConfirmContainer } from 'react-confirm-lite';
449
-
450
- export default function RootLayout({
451
- children,
452
- }: {
453
- children: React.ReactNode;
454
- }) {
455
- return (
456
- <html lang="en">
457
- <body>
458
- {children}
459
- <ConfirmContainer />
460
- </body>
461
- </html>
462
- );
463
- }
464
- ```
465
-
466
- ### Server Components
467
- ```tsx
468
- // Server actions
469
- 'use server';
470
- import { confirm } from 'react-confirm-lite';
471
-
472
- export async function serverAction() {
473
- const result = await confirm('Confirm from server?');
474
- if (result) {
475
- // Perform action
476
- } else if (result === null) {
477
- // User pressed ESC or clicked outside
478
- console.log('Action cancelled');
479
- }
480
- }
481
- ```
482
-
483
- ## ๐Ÿ”„ Migration from Other Libraries
484
-
485
- ### From window.confirm()
486
- ```tsx
487
- // Old way (always returns true/false)
488
- if (window.confirm('Delete?')) {
489
- deleteItem();
490
- }
491
-
492
- // New way (returns true/false/null)
493
- const result = await confirm('Delete?');
494
- if (result === true) {
495
- await deleteItem();
496
- } else if (result === false) {
497
- console.log('User clicked Cancel');
498
- } else if (result === null) {
499
- console.log('User pressed ESC');
500
- }
501
- ```
502
-
503
- ### From Other Confirm Libraries
504
- - No CSS imports needed
505
- - Automatic queue system
506
- - Built-in animations
507
- - Zero configuration
508
- - Three return states (true/false/null)
509
-
510
- # Contributing to react-confirm-lite
511
-
512
- Thanks for your interest in contributing. This project is intentionally lightweight, so the contribution workflow is kept simple and explicit. Please read this fully before starting.
513
-
514
- ---
515
-
516
- ## ๐Ÿ“ฆ Project Structure
517
-
518
- ```
519
- react-confirm-lite/
520
- โ”œโ”€ src/ # Library source code
521
- โ”œโ”€ dist/ # Built output (generated)
522
- โ”œโ”€ example/ # Local playground app (Vite + React)
523
- โ”œโ”€ CONTRIBUTING.md
524
- โ”œโ”€ README.md
525
- โ”œโ”€ package.json
526
- โ”œโ”€ tsup.config.ts
527
- ```
528
-
529
- * **src/** โ†’ where you make changes
530
- * **dist/** โ†’ auto-generated by tsup (do not edit manually)
531
- * **example/** โ†’ used to test changes locally
532
-
533
- ---
534
-
535
- ## ๐Ÿงฐ Prerequisites
536
-
537
- * Node.js >= 18
538
- * npm >= 9
539
- * Basic familiarity with React + TypeScript
540
-
541
- ---
542
-
543
- ## ๐Ÿš€ Local Development Setup
544
-
545
- ### 1. Clone the repository
546
-
547
- ```bash
548
- git clone https://github.com/SaadNasir-git/react-confirm-lite.git
549
- cd react-confirm-lite
550
- ```
551
-
552
- ### 2. Install dependencies (root)
553
-
554
- ```bash
555
- npm install
556
- ```
557
-
558
- ---
559
-
560
- ## ๐Ÿ” Development Workflow (IMPORTANT)
561
-
562
- This project uses **tsup watch mode** for live rebuilding.
563
-
564
- ### Terminal 1 โ€” Run library in watch mode
565
-
566
- From the project root:
567
-
568
- ```bash
569
- npm run build:watch
570
- ```
571
-
572
- This will:
573
-
574
- * Watch `src/` for changes
575
- * Automatically rebuild `dist/`
576
- * Re-run post-build steps when files change
577
-
578
- โš ๏ธ Leave this terminal running.
579
-
580
- ---
581
-
582
- ### Terminal 2 โ€” Run example app
583
-
584
- ```bash
585
- cd example
586
- npm install
587
- npm run dev
588
- ```
589
-
590
- Open the provided local URL in your browser.
591
-
592
- ---
593
-
594
- ## ๐Ÿงช How to Test Your Changes
595
-
596
- 1. Modify files inside `src/`
597
- 2. tsup automatically rebuilds the library
598
- 3. Refresh the browser running the example app
599
- 4. Verify behavior visually and via console logs
600
-
601
- You **do not** need to:
602
-
603
- * run `npm pack`
604
- * reinstall the package
605
- * publish to npm
606
-
607
- This setup mirrors real-world library development.
608
-
609
- ---
610
-
611
- ## ๐Ÿง  What to Change (and What Not to)
612
-
613
- ### โœ… You can change
614
-
615
- * Logic in `src/`
616
- * Types in `types.ts`
617
- * Styles / animations
618
- * README documentation
619
-
620
- ### โŒ Do not change
621
-
622
- * `dist/` files manually
623
- * Version number (maintainer handles releases)
624
- * Build configuration unless discussed
625
-
626
- ---
627
-
628
- ## ๐Ÿงน Code Style
629
-
630
- * Use TypeScript types explicitly
631
- * Avoid unnecessary abstractions
632
- * Prefer clarity over cleverness
633
- * Keep bundle size in mind
634
-
635
- ---
636
-
637
- ## ๐Ÿž Reporting Bugs
638
-
639
- When opening an issue, include:
640
-
641
- * What you expected
642
- * What actually happened
643
- * Steps to reproduce
644
- * Browser and React version
645
-
646
- ---
647
-
648
- ## ๐Ÿ’ก Feature Requests
649
-
650
- Feature requests are welcome, but keep in mind:
651
-
652
- * This library aims to stay minimal
653
- * Features should not add heavy dependencies
654
- * API simplicity is a priority
655
-
656
- ---
657
-
658
- ## ๐Ÿ›  Development & Contributing
659
-
660
- If you want to contribute or modify the library locally, use the built-in example app and watch mode.
661
-
662
- ### Local Development Setup
663
-
664
- ```bash
665
- git clone https://github.com/SaadNasir-git/react-confirm-lite.git
666
- cd react-confirm-lite
667
- npm install
668
- ```
669
-
670
- ### Run Library in Watch Mode
671
-
672
- In the project root:
673
-
674
- ```bash
675
- npm run build:watch
676
- ```
677
-
678
- This watches the `src/` directory and automatically rebuilds `dist/` on every change.
679
-
680
- ### Run Example App
681
-
682
- In a second terminal:
683
-
684
- ```bash
685
- cd example
686
- npm install
687
- npm run dev
688
- ```
689
-
690
- Open the local URL shown by Vite. Any change you make in `src/` will be reflected after a browser refresh.
691
-
692
- ### Notes
693
-
694
- * Do **not** edit files inside `dist/` manually
695
- * You do **not** need to run `npm pack` or reinstall the package
696
- * Versioning and releases are handled by the maintainer
697
-
698
- For more details, see **CONTRIBUTING.md**.
699
-
700
- ---
701
-
702
- ## ๐Ÿ“„ License
703
-
704
- By contributing, you agree that your contributions will be licensed under the MIT License.
705
-
706
- ---
707
-
708
- Thanks for contributing to **react-confirm-lite** ๐Ÿ™Œ
709
-
710
-
711
- ## ๐Ÿ“„ License
712
-
713
- MIT License - free for personal and commercial use.
714
-
715
- ## ๐Ÿ‘จโ€๐Ÿ’ป Author
716
-
717
- **Saad Nasir** - Creator of react-confirm-lite
718
-
719
- ---
720
-
721
- โญ **Found this useful? Give it a star on GitHub!** โญ
77
+ For more info checkout [website](https://react-confirm-lite.github.io).
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import React, { CSSProperties, ReactNode } from 'react';
3
3
 
4
4
  type ColorSchema = 'light' | 'dark' | 'blue' | 'red' | 'green' | 'purple';
5
- type AnimationType = 'slide' | 'fadeScale' | 'bounce' | 'flip' | 'zoom' | 'rotate' | 'fadeUp' | 'drop' | 'slideRight' | 'slideLeft' | 'fadeDown' | 'slideDown' | 'rotateRight' | 'zoomSmall' | 'bounceSmall' | 'fadeBlur' | 'fadeShrink';
5
+ type AnimationType = 'slide' | 'fadeScale' | 'bounce' | 'flip' | 'zoom' | 'rotate' | 'fadeUp' | 'drop' | 'slideRight' | 'slideLeft' | 'fadeDown' | 'rotateRight' | 'zoomSmall' | 'bounceSmall' | 'fadeBlur' | 'fadeShrink';
6
6
  type ConfirmClasses = {
7
7
  overlay?: string;
8
8
  wrapper?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-confirm-lite",
3
- "version": "1.5.5",
3
+ "version": "1.5.7",
4
4
  "description": "A lightweight, promise-based confirm dialog for React, designed to be as easy to use as react-toastify, while remaining fully customizable.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -19,7 +19,7 @@
19
19
  "type": "git",
20
20
  "url": "https://github.com/SaadNasir-git/react-confirm-lite.git"
21
21
  },
22
- "homepage": "https://github.com/SaadNasir-git/react-confirm-lite#readme",
22
+ "homepage": "https://react-confirm-lite.github.io",
23
23
  "scripts": {
24
24
  "build": "tsup && cp LICENSE dist/",
25
25
  "build:watch": "tsup --watch",