react-confirm-lite 1.2.5 → 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
@@ -1,151 +1,247 @@
1
- # react-confirm-lite
2
-
3
- **A lightweight, promise-based confirm dialog for React with built-in styling**
4
-
5
- ✨ **Features:**
6
- - Promise-based API like window.confirm
7
- - Built-in styling with multiple color schemes
8
- - Zero dependencies
9
- - Fully customizable
10
- - TypeScript support
11
- - Queue system for multiple dialogs
12
- - Works with Next.js App Router (no 'use client' needed)
13
- - Automatic CSS injection (no separate imports needed)
14
- ---
15
-
16
- ## Recommendations
17
- - Always use the latest version for bug fixes and improvements
18
- - If you face any issues, please report them on [GitHub](https://github.com/SaadNasir-git/react-confirm-lite/issues)
19
-
20
- ![react-confirm-lite sample](https://res.cloudinary.com/dhcqn5bmq/image/upload/v1766778602/Screencastfrom2025-12-2700-42-14-ezgif.com-optimize_od1ht2.gif)
21
-
22
- ## Quick Comparison
1
+ # React Confirm Lite ✨
23
2
 
24
- | Feature | react-confirm-lite | react-confirm | react-confirm-toast |
25
- |---------|-------------------|---------------|---------------------|
26
- | Built-in styling | ✅ Multiple color schemes | ❌ None | ✅ Toast style |
27
- | Promise-based | ✅ | ✅ | ✅ |
28
- | Zero dependencies | ✅ | ✅ | ✅ |
29
- | Queue system | ✅ | ❌ | ❌ |
30
- | Automatic CSS | ✅ No separate imports | ❌ | ❌ |
31
- | Next.js App Router | ✅ Works out of the box | ❌ Needs 'use client' | ✅ |
3
+ **A lightweight, promise-based confirm dialog for React, designed to be as easy to use as react-toastify, while remaining fully customizable.**
32
4
 
33
- ## Why Choose react-confirm-lite?
5
+ [![npm version](https://img.shields.io/npm/v/react-confirm-lite)](https://www.npmjs.com/package/react-confirm-lite)
6
+ [![bundle size](https://img.shields.io/bundlephobia/minzip/react-confirm-lite)](https://bundlephobia.com/package/react-confirm-lite)
7
+ [![npm downloads](https://img.shields.io/npm/dm/react-confirm-lite)](https://www.npmjs.com/package/react-confirm-lite)
8
+ [![license](https://img.shields.io/npm/l/react-confirm-lite)](https://github.com/SaadNasir-git/react-confirm-lite/blob/main/LICENSE)
9
+ [![typescript](https://img.shields.io/badge/types-TypeScript-blue)](https://www.typescriptlang.org/)
10
+ [![react](https://img.shields.io/badge/react-%3E%3D18-blue)](https://reactjs.org/)
34
11
 
35
- If you want a **simple, lightweight** confirm dialog that **just works** without any configuration, `react-confirm-lite` is perfect. No separate CSS imports, no 'use client' directives needed in Next.js App Router, and fully customizable when you need it.
12
+ ![Sample Image](https://camo.githubusercontent.com/af08928ac7006e57dc2a28f01b1fbc7214ea742379365f364f37bb204a93906b/68747470733a2f2f7265732e636c6f7564696e6172792e636f6d2f646863716e35626d712f696d6167652f75706c6f61642f76313736363737383630322f53637265656e6361737466726f6d323032352d31322d323730302d34322d31342d657a6769662e636f6d2d6f7074696d697a655f6f64316874322e676966)
36
13
 
37
14
  ## 🔗 Live Demo
38
15
 
39
16
  [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/edit/vitejs-vite-bfthlpmw?file=src%2FApp.tsx)
40
17
 
41
- ## Getting Started
18
+ ## 📦 Installation
42
19
 
43
- ### Step 1: **Install the package**:
44
20
  ```bash
45
21
  npm install react-confirm-lite
22
+ # or
23
+ yarn add react-confirm-lite
24
+ # or
25
+ pnpm add react-confirm-lite
46
26
  ```
47
27
 
48
- ### Step 2: Import in your component:
28
+ ## 🚀 Quick Start
29
+
30
+ ### Complete Example
31
+
32
+ Place `<ConfirmContainer />` in your app (usually in root layout) and use it with `confirm`
33
+
49
34
  ```tsx
50
- import { confirm, ConfirmContainer } from 'react-confirm-lite';
51
- ```
35
+ import { ConfirmContainer, confirm } from 'react-confirm-lite';
52
36
 
53
- ### Step 3: Add ConfirmContainer to your component tree:
54
- ```jsx
55
37
  function App() {
38
+ async function handleAction() {
39
+ const result = await confirm('Are you sure?');
40
+
41
+ if (result) {
42
+ console.log('User confirmed!');
43
+ } else {
44
+ console.log('User cancelled!');
45
+ }
46
+ }
56
47
  return (
57
- <>
58
- <ConfirmContainer />
48
+ <div>
59
49
  {/* Your app content */}
60
- </>
50
+ <ConfirmContainer />
51
+ </div>
61
52
  );
62
53
  }
63
54
  ```
64
55
 
65
- ### Step 4: Use the confirm function:
66
- ```tsx
67
- const handleAction = async () => {
68
- const isConfirmed = await confirm('Are you sure?');
69
- if (isConfirmed) {
70
- // Perform action
71
- console.log('Confirmed!');
72
- }
73
- };
56
+ ### Important
57
+ By default it shows the closest container to button to which you clicked to show the confirmation dialog but you are a programmer and you will try thing and sometimes you may use it in useEffect hook then in this case it will show the first rendered confirm container.
58
+
59
+ If you want to show a specific container by confirm api no matters where it is then you can pass the id like this
60
+ ```jsx
61
+ // In confirm Api
62
+ confirm({id:'1' , message:'Are you sure?'})
63
+ // And in confirm Container
64
+ <ConfirmContainer id='1'/>
74
65
  ```
66
+ And make sure that not to pass same id to different `<ConfirmContainer />` In this way It will show both of these containers
75
67
 
76
- ### Complete Example:
68
+ ## 🎯 Features
77
69
 
70
+ ### ✅ Simple Promise-based API
78
71
  ```tsx
79
- import { confirm, ConfirmContainer } from 'react-confirm-lite';
72
+ const result = await confirm('Message here');
73
+ // Returns true for OK, false for Cancel, null for ESC/outside click
74
+ ```
80
75
 
81
- function App() {
82
- const handleDelete = async () => {
83
- const isConfirmed = await confirm('Are you sure you want to delete this item?');
84
- if (isConfirmed) {
85
- // Delete logic here
86
- console.log('Item deleted');
87
- }
88
- };
76
+ ### 18 Built-in Animations
77
+ Choose from various animations:
78
+ - `slide` (default) - Smooth slide up/down
79
+ - `fadeScale` - Fade with scale effect
80
+ - `bounce` - Playful bounce animation
81
+ - `flip` - 3D flip effect
82
+ - `zoom` - Zoom in/out
83
+ - `rotate` - Rotate animation
84
+ - `fadeUp` / `fadeDown` - Directional fade
85
+ - `drop` - 3D drop effect
86
+ - `slideRight` / `slideLeft` - Horizontal slides
87
+ - `slideVertical` - Vertical slide
88
+ - `slideDown` - Slide down
89
+ - `rotateRight` - Rotate from right
90
+ - `zoomSmall` / `bounceSmall` - Subtle animations
91
+ - `fadeBlur` / `fadeShrink` - Creative effects
92
+
93
+ ### ✅ 6 Color Schemes
94
+ Pre-built color themes:
95
+ - `dark` (default) - Dark theme
96
+ - `light` - Light theme
97
+ - `blue` - Blue theme
98
+ - `red` - Perfect for destructive actions
99
+ - `green` - Success actions
100
+ - `purple` - Premium/feature actions
101
+
102
+ ### ✅ Interactive Controls
103
+ - `closeOnEscape` (default: true) - Press ESC to close
104
+ - `closeOnClickOutside` (default: true) - Click backdrop to close
105
+ - Returns `null` when closed via ESC or backdrop click
106
+
107
+ ### ✅ Customizable Options
108
+ Control every aspect:
109
+ - Custom OK/Cancel button text
110
+ - Separate animation durations for enter/exit
111
+ - Override colors per dialog
112
+ - Custom CSS classes for all elements
113
+
114
+ ### ✅ Queue System
115
+ Multiple confirm requests automatically queue and show one at a time:
116
+ ```tsx
117
+ // These will show sequentially
118
+ await confirm('First?');
119
+ await confirm('Second?');
120
+ await confirm('Third?');
121
+ ```
89
122
 
90
- return (
91
- <div>
92
- <button onClick={handleDelete}>Delete Item</button>
93
- <ConfirmContainer />
94
- </div>
95
- );
123
+ ### ✅ Zero Configuration
124
+ No CSS imports needed. Styles are automatically injected.
125
+
126
+ ## 🎨 Usage Examples
127
+
128
+ ### Basic Usage
129
+ ```tsx
130
+ const result = await confirm('Delete this item?');
131
+ if (result) {
132
+ // User clicked OK
133
+ deleteItem();
134
+ } else if (result === false) {
135
+ // User clicked Cancel
136
+ console.log('Cancelled');
137
+ } else if (result === null) {
138
+ // User pressed ESC or clicked outside
139
+ console.log('Closed via ESC/backdrop');
96
140
  }
97
141
  ```
98
142
 
99
- ## Advanced Usage
143
+ ### Custom Dialog Options
144
+ ```tsx
145
+ const result = await confirm({
146
+ title: 'Delete Account',
147
+ message: 'This will permanently delete your account and all data.',
148
+ okText: 'Delete Forever',
149
+ cancelText: 'Cancel',
150
+ colorSchema: 'red'
151
+ });
152
+ ```
100
153
 
101
- ### Custom Options:
154
+ ### Disable ESC and Backdrop Closing
102
155
  ```tsx
103
- const handleCustomConfirm = async () => {
104
- const isConfirmed = await confirm({
105
- title: "Delete Item",
106
- message: "This action cannot be undone. Are you sure?",
107
- cancelText: 'No, keep it',
108
- okText: 'Yes, delete',
109
- colorSchema: 'red',
110
- isDestructive: true
111
- });
112
-
113
- if (isConfirmed) {
114
- // Delete item
115
- }
116
- };
156
+ <ConfirmContainer
157
+ closeOnEscape={false}
158
+ closeOnClickOutside={false}
159
+ />
160
+ // Now dialog can only be closed with Cancel/OK buttons
117
161
  ```
118
162
 
119
- ### Custom Color Scheme:
120
- ```jsx
121
- <ConfirmContainer defaultColorSchema="light" />
122
- // Available options: 'light', 'dark', 'blue', 'red', 'green', 'purple'
163
+ ## 🔧 API Reference
164
+
165
+ ### Confirm Container Props
166
+
167
+ | Prop | Type | Default | Description |
168
+ |------|------|---------|-------------|
169
+ |`id`|`string`| `random` | To show a specific container with a specific confirm() app |
170
+ | `animation` | `AnimationType` | `'slide'` | Animation type (18 options) |
171
+ | `animationDuration` | `number` | `300` | Base animation duration (ms) |
172
+ | `animationDurationIn` | `number` | - | Enter animation duration |
173
+ | `animationDurationOut` | `number` | - | Exit animation duration |
174
+ | `defaultColorSchema` | `ColorSchema` | `'dark'` | Default color scheme |
175
+ | `closeOnEscape` | `boolean` | `true` | Close with ESC key |
176
+ | `closeOnClickOutside` | `boolean` | `true` | Close on backdrop click |
177
+ | `classes` | `ConfirmClasses` | `{}` | Custom CSS classes |
178
+
179
+ ### Confirm Function
180
+
181
+ ```tsx
182
+ // String input (simple)
183
+ await confirm('Simple message');
184
+
185
+ // Object input (full options)
186
+ await confirm({
187
+ title: 'Custom Title', // Optional
188
+ message: 'Required message', // Required
189
+ okText: 'Proceed', // Optional
190
+ cancelText: 'Go Back', // Optional
191
+ colorSchema: 'blue', // Optional
192
+ });
123
193
  ```
124
194
 
125
- ### Custom Styling:
126
- ```jsx
195
+ **Return values:**
196
+ - `true` - User clicked OK
197
+ - `false` - User clicked Cancel
198
+ - `null` - User pressed ESC or clicked outside (if enabled)
199
+
200
+ ### Custom Styling with CSS Classes
201
+
202
+ ```tsx
127
203
  <ConfirmContainer
128
204
  classes={{
129
- overlay: "bg-black/50",
130
- wrapper: "rounded-xl shadow-2xl",
131
- title: "text-2xl font-bold",
132
- message: "text-gray-600",
133
- button: "px-6 py-3 rounded-lg font-medium",
134
- cancel: "border border-gray-300 hover:bg-gray-50",
135
- ok: "bg-blue-600 hover:bg-blue-700 text-white"
205
+ overlay: "my-overlay-class", // Background overlay
206
+ wrapper: "my-modal-class", // Modal container
207
+ title: "my-title-class", // Title text
208
+ message: "my-message-class", // Message text
209
+ button: "my-button-class", // Both buttons
210
+ cancel: "my-cancel-class", // Cancel button only
211
+ ok: "my-ok-class", // OK button only
136
212
  }}
137
213
  />
138
214
  ```
139
215
 
140
- ### Fully Custom UI with Render Prop:
141
- ```jsx
216
+ ## 🎭 Custom UI with Render Prop
217
+
218
+ Want complete control over the UI? Use the render prop:
219
+
220
+ ```tsx
142
221
  <ConfirmContainer animationDuration={500}>
143
- {({ isVisible, confirm, handleCancel, handleOk }) => (
144
- <div className={`modal ${isVisible ? 'show' : 'hide'}`}>
145
- <div className="modal-content">
222
+ {({
223
+ isVisible,
224
+ confirm,
225
+ handleCancel,
226
+ handleOk,
227
+ containerRef,
228
+ animationClass,
229
+ animationStyle
230
+ }) => (
231
+ <div className={`modal-overlay ${isVisible ? 'show' : 'hide'}`}>
232
+ {/* Your custom backdrop */}
233
+ <div className="backdrop" onClick={handleCancel} />
234
+
235
+ {/* Your custom modal */}
236
+ <div
237
+ ref={containerRef}
238
+ className={`custom-modal ${animationClass}`}
239
+ style={animationStyle}
240
+ >
146
241
  <h2>{confirm.title}</h2>
147
242
  <p>{confirm.message}</p>
148
- <div className="modal-actions">
243
+
244
+ <div className="buttons">
149
245
  <button onClick={handleCancel}>
150
246
  {confirm.cancelText || 'Cancel'}
151
247
  </button>
@@ -159,11 +255,173 @@ const handleCustomConfirm = async () => {
159
255
  </ConfirmContainer>
160
256
  ```
161
257
 
162
- ## Next.js App Router Support
258
+ **Available render props:**
259
+ - `isVisible`: Boolean indicating if dialog should be visible
260
+ - `confirm`: The current confirm options object
261
+ - `handleCancel`: Function to cancel the dialog (returns false)
262
+ - `handleOk`: Function to confirm the dialog (returns true)
263
+ - `containerRef`: React ref for the modal container
264
+ - `colorSchema`: Current color scheme
265
+ - `animationClass`: CSS class for current animation
266
+ - `animationStyle`: Style object with animation duration
267
+
268
+ ## 📱 Real-World Examples
269
+
270
+ ### Delete Confirmation with ESC Disabled
271
+ ```tsx
272
+ const handleDelete = async () => {
273
+ // Force user to make explicit choice
274
+ const result = await confirm({
275
+ title: 'Delete Item',
276
+ message: 'This action cannot be undone. Are you sure?',
277
+ okText: 'Delete',
278
+ cancelText: 'Keep',
279
+ colorSchema: 'red'
280
+ });
281
+
282
+ // Result can only be true or false (no null since ESC/backdrop disabled)
283
+ if (result) {
284
+ await deleteItem();
285
+ }
286
+ };
287
+
288
+ // In your component
289
+ <ConfirmContainer closeOnEscape={false} closeOnClickOutside={false} />
290
+ ```
291
+
292
+ ### Form Submission with Backdrop Only
293
+ ```tsx
294
+ // Allow closing by clicking backdrop but not ESC
295
+ <ConfirmContainer closeOnEscape={false} closeOnClickOutside={true} />
296
+
297
+ const handleSubmit = async () => {
298
+ const result = await confirm({
299
+ title: 'Submit Form',
300
+ message: 'Ready to submit this form?',
301
+ okText: 'Submit',
302
+ cancelText: 'Review',
303
+ colorSchema: 'green'
304
+ });
305
+
306
+ if (result) {
307
+ await submitForm();
308
+ } else if (result === null) {
309
+ // User clicked backdrop
310
+ console.log('Closed by clicking outside');
311
+ }
312
+ };
313
+ ```
314
+
315
+ ### Different Behaviors for Different Dialogs
316
+ ```tsx
317
+ // Global: ESC and backdrop disabled
318
+ <ConfirmContainer
319
+ closeOnEscape={false}
320
+ closeOnClickOutside={false}
321
+ />
322
+
323
+ // Some dialogs can override via custom UI
324
+ const handleFlexibleDialog = async () => {
325
+ // Create custom UI that allows ESC/backdrop
326
+ const result = await confirm('Flexible dialog?');
327
+ // result can be true, false, or null
328
+ };
329
+ ```
330
+
331
+ ## 🏗️ Container Configuration
163
332
 
164
- Works automatically! No 'use client' directive needed for the library. The library handles everything internally.
333
+ ### Global Settings
334
+ ```tsx
335
+ <ConfirmContainer
336
+ defaultColorSchema="light" // Light theme by default
337
+ animation="zoom" // Zoom animation for all dialogs
338
+ animationDuration={400} // 400ms animations
339
+ closeOnEscape={true} // Allow ESC to close
340
+ closeOnClickOutside={true} // Allow backdrop click to close
341
+ animationDurationIn={350} // Enter: 350ms
342
+ animationDurationOut={250} // Exit: 250ms
343
+ />
344
+ ```
165
345
 
166
- ### Server Components Example:
346
+ ### Different Close Behaviors
347
+ ```tsx
348
+ // Option 1: Fully closable (default)
349
+ <ConfirmContainer closeOnEscape={true} closeOnClickOutside={true} />
350
+ // Users can close via: OK, Cancel, ESC, or backdrop click
351
+
352
+ // Option 2: Force explicit choice
353
+ <ConfirmContainer closeOnEscape={false} closeOnClickOutside={false} />
354
+ // Users can only close via: OK or Cancel buttons
355
+
356
+ // Option 3: Backdrop only
357
+ <ConfirmContainer closeOnEscape={false} closeOnClickOutside={true} />
358
+ // Users can close via: OK, Cancel, or backdrop click
359
+
360
+ // Option 4: ESC only
361
+ <ConfirmContainer closeOnEscape={true} closeOnClickOutside={false} />
362
+ // Users can close via: OK, Cancel, or ESC key
363
+ ```
364
+
365
+ ## 🎨 Animation Gallery
366
+
367
+ ### Slide Animations
368
+ - `slide` - Smooth vertical slide (default)
369
+ - `slideRight` / `slideLeft` - Horizontal slides
370
+ - `slideVertical` - Vertical slide
371
+ - `slideDown` - Slide down
372
+
373
+ ### Fade Animations
374
+ - `fadeScale` - Fade with scaling
375
+ - `fadeUp` / `fadeDown` - Directional fades
376
+ - `fadeBlur` - Fade with blur effect
377
+ - `fadeShrink` - Fade with shrink effect
378
+
379
+ ### 3D Animations
380
+ - `flip` - Card flip effect
381
+ - `drop` - 3D drop animation
382
+ - `rotate` / `rotateRight` - Rotation effects
383
+
384
+ ### Playful Animations
385
+ - `bounce` / `bounceSmall` - Bounce effects
386
+ - `zoom` / `zoomSmall` - Zoom in/out
387
+
388
+ ## 🚨 Troubleshooting
389
+
390
+ ### Multiple dialogs are showing?
391
+ - Make sure you are on version `>=1.4`
392
+ - Make sure you didn't pass same id to different `<ConfirmContainer />`
393
+
394
+ ### Dialog not showing?
395
+ - Make sure `<ConfirmContainer />` is mounted
396
+ - Check it's not conditionally rendered
397
+
398
+ ### ESC key not working?
399
+ - Check if `closeOnEscape={true}` (default)
400
+ - Ensure no other event is preventing ESC
401
+ - Try different browsers
402
+
403
+ ### Backdrop click not working?
404
+ - Verify `closeOnClickOutside={true}` (default)
405
+ - Check if any parent element is preventing clicks
406
+
407
+ ### Animation not working?
408
+ - Verify animation name is correct
409
+ - Check browser console for errors
410
+
411
+ ### TypeScript errors?
412
+ - Ensure you have `@types/react` installed
413
+ - Update to latest TypeScript version
414
+
415
+ ### Styling issues?
416
+ - Use `classes` prop to override styles
417
+ - Check CSS specificity
418
+
419
+ You can also use it in TanStack with react easily
420
+
421
+
422
+ ## 📱 Next.js Support
423
+
424
+ ### App Router (Next.js 15+)
167
425
  ```tsx
168
426
  // app/layout.tsx
169
427
  import { ConfirmContainer } from 'react-confirm-lite';
@@ -183,198 +441,260 @@ export default function RootLayout({
183
441
  );
184
442
  }
185
443
  ```
444
+
445
+ ### Server Components
186
446
  ```tsx
187
- // app/page.tsx (server component)
447
+ // Server actions
448
+ 'use server';
188
449
  import { confirm } from 'react-confirm-lite';
189
450
 
190
- export default async function Page() {
191
- // Server-side logic here
192
-
193
- return (
194
- <form action={async () => {
195
- 'use server';
196
- const isConfirmed = await confirm('Are you sure?');
197
- if (isConfirmed) {
198
- // Server action
199
- }
200
- }}>
201
- <button>Submit</button>
202
- </form>
203
- );
451
+ export async function serverAction() {
452
+ const result = await confirm('Confirm from server?');
453
+ if (result) {
454
+ // Perform action
455
+ } else if (result === null) {
456
+ // User pressed ESC or clicked outside
457
+ console.log('Action cancelled');
458
+ }
204
459
  }
205
460
  ```
206
461
 
207
- ### Client Component Example:
208
- ```tsx
209
- 'use client';
210
- import { confirm, ConfirmContainer } from 'react-confirm-lite';
462
+ ## 🔄 Migration from Other Libraries
211
463
 
212
- export default function ClientComponent() {
213
- const handleClick = async () => {
214
- const result = await confirm('Confirm action?');
215
- if (result) {
216
- // Handle confirmation
217
- }
218
- };
464
+ ### From window.confirm()
465
+ ```tsx
466
+ // Old way (always returns true/false)
467
+ if (window.confirm('Delete?')) {
468
+ deleteItem();
469
+ }
219
470
 
220
- return (
221
- <div>
222
- <button onClick={handleClick}>Click me</button>
223
- <ConfirmContainer />
224
- </div>
225
- );
471
+ // New way (returns true/false/null)
472
+ const result = await confirm('Delete?');
473
+ if (result === true) {
474
+ await deleteItem();
475
+ } else if (result === false) {
476
+ console.log('User clicked Cancel');
477
+ } else if (result === null) {
478
+ console.log('User pressed ESC');
226
479
  }
227
480
  ```
228
481
 
229
- ## API Reference
482
+ ### From Other Confirm Libraries
483
+ - No CSS imports needed
484
+ - Automatic queue system
485
+ - Built-in animations
486
+ - Zero configuration
487
+ - Three return states (true/false/null)
230
488
 
231
- ### `confirm(message: string | ConfirmOptions): Promise<boolean>`
489
+ # Contributing to react-confirm-lite
232
490
 
233
- Displays a confirmation dialog. Returns a promise that resolves to `true` if confirmed, `false` if cancelled.
491
+ 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.
492
+
493
+ ---
494
+
495
+ ## 📦 Project Structure
234
496
 
235
- **String usage:**
236
- ```ts
237
- await confirm('Simple message');
238
- // Equivalent to: { title: 'Confirm', message: 'Simple message' }
497
+ ```
498
+ react-confirm-lite/
499
+ ├─ src/ # Library source code
500
+ ├─ dist/ # Built output (generated)
501
+ ├─ example/ # Local playground app (Vite + React)
502
+ ├─ CONTRIBUTING.md
503
+ ├─ README.md
504
+ ├─ package.json
505
+ ├─ tsup.config.ts
239
506
  ```
240
507
 
241
- **Object usage:**
242
- ```ts
243
- await confirm({
244
- title: 'Warning',
245
- message: 'This action cannot be undone',
246
- cancelText: 'Cancel',
247
- okText: 'Delete',
248
- colorSchema: 'red',
249
- isDestructive: true
250
- });
508
+ * **src/** → where you make changes
509
+ * **dist/** → auto-generated by tsup (do not edit manually)
510
+ * **example/** → used to test changes locally
511
+
512
+ ---
513
+
514
+ ## 🧰 Prerequisites
515
+
516
+ * Node.js >= 18
517
+ * npm >= 9
518
+ * Basic familiarity with React + TypeScript
519
+
520
+ ---
521
+
522
+ ## 🚀 Local Development Setup
523
+
524
+ ### 1. Clone the repository
525
+
526
+ ```bash
527
+ git clone https://github.com/SaadNasir-git/react-confirm-lite.git
528
+ cd react-confirm-lite
251
529
  ```
252
530
 
253
- ### `ConfirmContainer` Props:
531
+ ### 2. Install dependencies (root)
254
532
 
255
- | Prop | Type | Default | Description |
256
- |------|------|---------|-------------|
257
- | `defaultColorSchema` | `ColorSchema` | `'dark'` | Default color scheme |
258
- | `animationDuration` | `number` | `300` | Animation duration in ms |
259
- | `classes` | `ConfirmClasses` | `{}` | Custom CSS classes |
260
- | `children` | Render function | - | For complete UI customization |
261
-
262
- ### Types:
263
- ```ts
264
- type ColorSchema = 'light' | 'dark' | 'blue' | 'red' | 'green' | 'purple';
265
-
266
- interface ConfirmClasses {
267
- overlay?: string;
268
- wrapper?: string;
269
- title?: string;
270
- message?: string;
271
- button?: string;
272
- cancel?: string;
273
- ok?: string;
274
- }
533
+ ```bash
534
+ npm install
535
+ ```
275
536
 
276
- interface ConfirmOptions {
277
- title?: string;
278
- message: string;
279
- cancelText?: string;
280
- okText?: string;
281
- colorSchema?: ColorSchema;
282
- isDestructive?: boolean;
283
- }
537
+ ---
538
+
539
+ ## 🔁 Development Workflow (IMPORTANT)
540
+
541
+ This project uses **tsup watch mode** for live rebuilding.
542
+
543
+ ### Terminal 1 — Run library in watch mode
544
+
545
+ From the project root:
546
+
547
+ ```bash
548
+ npm run build:watch
284
549
  ```
285
550
 
286
- ## Troubleshooting
551
+ This will:
287
552
 
288
- ### Dialog not appearing?
289
- - Make sure `<ConfirmContainer />` is rendered in your component tree
290
- - Check that you're not conditionally rendering it in a way that unmounts it
553
+ * Watch `src/` for changes
554
+ * Automatically rebuild `dist/`
555
+ * Re-run post-build steps when files change
556
+
557
+ ⚠️ Leave this terminal running.
558
+
559
+ ---
560
+
561
+ ### Terminal 2 — Run example app
562
+
563
+ ```bash
564
+ cd example
565
+ npm install
566
+ npm run dev
567
+ ```
291
568
 
292
- ### Multiple dialogs overlapping?
293
- - The library has a built-in queue system that handles multiple confirm requests sequentially
569
+ Open the provided local URL in your browser.
294
570
 
295
- ### ❌ Styling not working?
296
- - If using custom classes, ensure they have proper CSS specificity
297
- - Try using `!important` flag for custom styles if needed
298
- - Make sure you're on the latest version
571
+ ---
299
572
 
300
- ### Animation issues with custom UI?
301
- - When using the `children` render prop, use the `isVisible` prop for animations
302
- - Set appropriate `animationDuration` to match your CSS transitions
573
+ ## 🧪 How to Test Your Changes
303
574
 
304
- ### Next.js hydration errors?
305
- - The library is designed to work with Next.js App Router
306
- - If using in a layout, ensure it's placed after dynamic content
575
+ 1. Modify files inside `src/`
576
+ 2. tsup automatically rebuilds the library
577
+ 3. Refresh the browser running the example app
578
+ 4. Verify behavior visually and via console logs
307
579
 
308
- ## Features in Detail
580
+ You **do not** need to:
309
581
 
310
- ### 🎨 Multiple Color Schemes
311
- Six built-in color schemes: light, dark, blue, red, green, purple. Set globally or per confirm dialog.
582
+ * run `npm pack`
583
+ * reinstall the package
584
+ * publish to npm
312
585
 
313
- ### 🔄 Queue System
314
- Multiple confirm requests are queued and shown one at a time, preventing overlapping dialogs.
586
+ This setup mirrors real-world library development.
315
587
 
316
- ### 🎯 Zero Configuration
317
- Works out of the box with default styling. No CSS imports needed.
588
+ ---
318
589
 
319
- ### 🔧 Fully Customizable
320
- From simple class overrides to complete UI replacement with render props.
590
+ ## 🧠 What to Change (and What Not to)
321
591
 
322
- ### 📱 Responsive Design
323
- Built-in responsive styling that works on all screen sizes.
592
+ ### You can change
324
593
 
325
- ### 🔒 Type Safety
326
- Full TypeScript support with comprehensive type definitions.
594
+ * Logic in `src/`
595
+ * Types in `types.ts`
596
+ * Styles / animations
597
+ * README documentation
327
598
 
328
- ## Performance
599
+ ### ❌ Do not change
329
600
 
330
- - **Zero dependencies**: Only React as a peer dependency
331
- - **Tree-shakeable**: Only imports what you use
332
- - **Small bundle size**: ~5KB gzipped (including styles)
333
- - **Optimized renders**: Minimal re-renders with React.memo
601
+ * `dist/` files manually
602
+ * Version number (maintainer handles releases)
603
+ * Build configuration unless discussed
334
604
 
335
- ## Migration from Older Versions
605
+ ---
336
606
 
337
- If you're upgrading from version <1.3.0:
607
+ ## 🧹 Code Style
338
608
 
339
- 1. **'use client' not needed**: The library handles this internally
340
- 2. **Simpler API**: Same functions, better internals
609
+ * Use TypeScript types explicitly
610
+ * Avoid unnecessary abstractions
611
+ * Prefer clarity over cleverness
612
+ * Keep bundle size in mind
341
613
 
614
+ ---
342
615
 
343
- ## Contributing
616
+ ## 🐞 Reporting Bugs
344
617
 
345
- Contributions are welcome! Please:
618
+ When opening an issue, include:
346
619
 
347
- 1. Fork the repository
348
- 2. Create a feature branch
349
- 3. Add tests for your changes
350
- 4. Submit a pull request
620
+ * What you expected
621
+ * What actually happened
622
+ * Steps to reproduce
623
+ * Browser and React version
351
624
 
352
- ## Author
625
+ ---
353
626
 
354
- **Saad Nasir** - Full Stack Developer
355
- - GitHub: [@SaadNasir-git](https://github.com/SaadNasir-git)
356
- - For support: Open an issue on GitHub
627
+ ## 💡 Feature Requests
357
628
 
358
- ## License
629
+ Feature requests are welcome, but keep in mind:
359
630
 
360
- MIT © Saad Nasir
631
+ * This library aims to stay minimal
632
+ * Features should not add heavy dependencies
633
+ * API simplicity is a priority
361
634
 
362
635
  ---
363
636
 
364
- ![npm version](https://img.shields.io/npm/v/react-confirm-lite)
365
- ![bundle size](https://img.shields.io/bundlephobia/minzip/react-confirm-lite)
366
- ![npm downloads](https://img.shields.io/npm/dm/react-confirm-lite)
367
- ![license](https://img.shields.io/npm/l/react-confirm-lite)
368
- ![typescript](https://img.shields.io/badge/types-TypeScript-blue)
369
- ![react](https://img.shields.io/badge/react-%3E%3D18-blue)
370
- ![next.js](https://img.shields.io/badge/next.js-15+-black)
637
+ ## 🛠 Development & Contributing
638
+
639
+ If you want to contribute or modify the library locally, use the built-in example app and watch mode.
371
640
 
372
- ## Support
641
+ ### Local Development Setup
373
642
 
374
- If you find this library helpful, please consider:
375
- - Starring the repository on GitHub
376
- - 📢 Sharing with your network
377
- - 🐛 Reporting issues you encounter
378
- - 💡 Suggesting new features
643
+ ```bash
644
+ git clone https://github.com/SaadNasir-git/react-confirm-lite.git
645
+ cd react-confirm-lite
646
+ npm install
647
+ ```
648
+
649
+ ### Run Library in Watch Mode
650
+
651
+ In the project root:
652
+
653
+ ```bash
654
+ npm run build:watch
655
+ ```
656
+
657
+ This watches the `src/` directory and automatically rebuilds `dist/` on every change.
658
+
659
+ ### Run Example App
660
+
661
+ In a second terminal:
662
+
663
+ ```bash
664
+ cd example
665
+ npm install
666
+ npm run dev
667
+ ```
668
+
669
+ Open the local URL shown by Vite. Any change you make in `src/` will be reflected after a browser refresh.
670
+
671
+ ### Notes
672
+
673
+ * Do **not** edit files inside `dist/` manually
674
+ * You do **not** need to run `npm pack` or reinstall the package
675
+ * Versioning and releases are handled by the maintainer
676
+
677
+ For more details, see **CONTRIBUTING.md**.
678
+
679
+ ---
680
+
681
+ ## 📄 License
682
+
683
+ By contributing, you agree that your contributions will be licensed under the MIT License.
684
+
685
+ ---
686
+
687
+ Thanks for contributing to **react-confirm-lite** 🙌
688
+
689
+
690
+ ## 📄 License
691
+
692
+ MIT License - free for personal and commercial use.
693
+
694
+ ## 👨‍💻 Author
695
+
696
+ **Saad Nasir** - Creator of react-confirm-lite
697
+
698
+ ---
379
699
 
380
- Happy coding! 🚀
700
+ **Found this useful? Give it a star on GitHub!** ⭐