react-confirm-lite 1.2.5 → 1.3.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 +379 -271
- package/dist/index.d.ts +38 -9
- package/dist/index.js +130 -49
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,151 +1,243 @@
|
|
|
1
|
-
#
|
|
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
|
-

|
|
1
|
+
# React Confirm Lite ✨
|
|
21
2
|
|
|
22
|
-
|
|
3
|
+
**A lightweight, promise-based confirm dialog for React, designed to be as easy to use as react-toastify, while remaining fully customizable.**
|
|
23
4
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
| Automatic CSS | ✅ No separate imports | ❌ | ❌ |
|
|
31
|
-
| Next.js App Router | ✅ Works out of the box | ❌ Needs 'use client' | ✅ |
|
|
5
|
+
[](https://www.npmjs.com/package/react-confirm-lite)
|
|
6
|
+
[](https://bundlephobia.com/package/react-confirm-lite)
|
|
7
|
+
[](https://www.npmjs.com/package/react-confirm-lite)
|
|
8
|
+
[](https://github.com/SaadNasir-git/react-confirm-lite/blob/main/LICENSE)
|
|
9
|
+
[](https://www.typescriptlang.org/)
|
|
10
|
+
[](https://reactjs.org/)
|
|
32
11
|
|
|
33
|
-
|
|
34
|
-
|
|
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
|
+

|
|
36
13
|
|
|
37
14
|
## 🔗 Live Demo
|
|
38
15
|
|
|
39
16
|
[](https://stackblitz.com/edit/vitejs-vite-bfthlpmw?file=src%2FApp.tsx)
|
|
40
17
|
|
|
41
|
-
##
|
|
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
|
-
|
|
28
|
+
## 🚀 Quick Start
|
|
29
|
+
|
|
30
|
+
### 1. Add the Container Component
|
|
31
|
+
|
|
32
|
+
Place `<ConfirmContainer />` in your app (usually in root layout):
|
|
33
|
+
|
|
49
34
|
```tsx
|
|
50
|
-
import {
|
|
51
|
-
```
|
|
35
|
+
import { ConfirmContainer } from 'react-confirm-lite';
|
|
52
36
|
|
|
53
|
-
### Step 3: Add ConfirmContainer to your component tree:
|
|
54
|
-
```jsx
|
|
55
37
|
function App() {
|
|
56
38
|
return (
|
|
57
|
-
|
|
58
|
-
<ConfirmContainer />
|
|
39
|
+
<div>
|
|
59
40
|
{/* Your app content */}
|
|
60
|
-
|
|
41
|
+
<ConfirmContainer />
|
|
42
|
+
</div>
|
|
61
43
|
);
|
|
62
44
|
}
|
|
63
45
|
```
|
|
64
46
|
|
|
65
|
-
###
|
|
47
|
+
### 2. Use the Confirm Function
|
|
48
|
+
|
|
49
|
+
Import and use `confirm()` anywhere in your app:
|
|
50
|
+
|
|
66
51
|
```tsx
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
52
|
+
import { confirm } from 'react-confirm-lite';
|
|
53
|
+
|
|
54
|
+
async function handleAction() {
|
|
55
|
+
const result = await confirm('Are you sure?');
|
|
56
|
+
|
|
57
|
+
if (result) {
|
|
58
|
+
console.log('User confirmed!');
|
|
59
|
+
} else {
|
|
60
|
+
console.log('User cancelled!');
|
|
72
61
|
}
|
|
73
|
-
}
|
|
62
|
+
}
|
|
74
63
|
```
|
|
75
64
|
|
|
76
|
-
|
|
65
|
+
## 🎯 Features
|
|
77
66
|
|
|
67
|
+
### ✅ Simple Promise-based API
|
|
78
68
|
```tsx
|
|
79
|
-
|
|
69
|
+
const result = await confirm('Message here');
|
|
70
|
+
// Returns true for OK, false for Cancel, null for ESC/outside click
|
|
71
|
+
```
|
|
80
72
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
73
|
+
### ✅ 18 Built-in Animations
|
|
74
|
+
Choose from various animations:
|
|
75
|
+
- `slide` (default) - Smooth slide up/down
|
|
76
|
+
- `fadeScale` - Fade with scale effect
|
|
77
|
+
- `bounce` - Playful bounce animation
|
|
78
|
+
- `flip` - 3D flip effect
|
|
79
|
+
- `zoom` - Zoom in/out
|
|
80
|
+
- `rotate` - Rotate animation
|
|
81
|
+
- `fadeUp` / `fadeDown` - Directional fade
|
|
82
|
+
- `drop` - 3D drop effect
|
|
83
|
+
- `slideRight` / `slideLeft` - Horizontal slides
|
|
84
|
+
- `slideVertical` - Vertical slide
|
|
85
|
+
- `slideDown` - Slide down
|
|
86
|
+
- `rotateRight` - Rotate from right
|
|
87
|
+
- `zoomSmall` / `bounceSmall` - Subtle animations
|
|
88
|
+
- `fadeBlur` / `fadeShrink` - Creative effects
|
|
89
|
+
|
|
90
|
+
### ✅ 6 Color Schemes
|
|
91
|
+
Pre-built color themes:
|
|
92
|
+
- `dark` (default) - Dark theme
|
|
93
|
+
- `light` - Light theme
|
|
94
|
+
- `blue` - Blue theme
|
|
95
|
+
- `red` - Perfect for destructive actions
|
|
96
|
+
- `green` - Success actions
|
|
97
|
+
- `purple` - Premium/feature actions
|
|
98
|
+
|
|
99
|
+
### ✅ Interactive Controls
|
|
100
|
+
- `closeOnEscape` (default: true) - Press ESC to close
|
|
101
|
+
- `closeOnClickOutside` (default: true) - Click backdrop to close
|
|
102
|
+
- Returns `null` when closed via ESC or backdrop click
|
|
103
|
+
|
|
104
|
+
### ✅ Customizable Options
|
|
105
|
+
Control every aspect:
|
|
106
|
+
- Custom OK/Cancel button text
|
|
107
|
+
- Separate animation durations for enter/exit
|
|
108
|
+
- Override colors per dialog
|
|
109
|
+
- Custom CSS classes for all elements
|
|
110
|
+
|
|
111
|
+
### ✅ Queue System
|
|
112
|
+
Multiple confirm requests automatically queue and show one at a time:
|
|
113
|
+
```tsx
|
|
114
|
+
// These will show sequentially
|
|
115
|
+
await confirm('First?');
|
|
116
|
+
await confirm('Second?');
|
|
117
|
+
await confirm('Third?');
|
|
118
|
+
```
|
|
89
119
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
120
|
+
### ✅ Zero Configuration
|
|
121
|
+
No CSS imports needed. Styles are automatically injected.
|
|
122
|
+
|
|
123
|
+
## 🎨 Usage Examples
|
|
124
|
+
|
|
125
|
+
### Basic Usage
|
|
126
|
+
```tsx
|
|
127
|
+
const result = await confirm('Delete this item?');
|
|
128
|
+
if (result) {
|
|
129
|
+
// User clicked OK
|
|
130
|
+
deleteItem();
|
|
131
|
+
} else if (result === false) {
|
|
132
|
+
// User clicked Cancel
|
|
133
|
+
console.log('Cancelled');
|
|
134
|
+
} else if (result === null) {
|
|
135
|
+
// User pressed ESC or clicked outside
|
|
136
|
+
console.log('Closed via ESC/backdrop');
|
|
96
137
|
}
|
|
97
138
|
```
|
|
98
139
|
|
|
99
|
-
|
|
140
|
+
### Custom Dialog Options
|
|
141
|
+
```tsx
|
|
142
|
+
const result = await confirm({
|
|
143
|
+
title: 'Delete Account',
|
|
144
|
+
message: 'This will permanently delete your account and all data.',
|
|
145
|
+
okText: 'Delete Forever',
|
|
146
|
+
cancelText: 'Cancel',
|
|
147
|
+
colorSchema: 'red'
|
|
148
|
+
});
|
|
149
|
+
```
|
|
100
150
|
|
|
101
|
-
###
|
|
151
|
+
### Disable ESC and Backdrop Closing
|
|
102
152
|
```tsx
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
okText: 'Yes, delete',
|
|
109
|
-
colorSchema: 'red',
|
|
110
|
-
isDestructive: true
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
if (isConfirmed) {
|
|
114
|
-
// Delete item
|
|
115
|
-
}
|
|
116
|
-
};
|
|
153
|
+
<ConfirmContainer
|
|
154
|
+
closeOnEscape={false}
|
|
155
|
+
closeOnClickOutside={false}
|
|
156
|
+
/>
|
|
157
|
+
// Now dialog can only be closed with Cancel/OK buttons
|
|
117
158
|
```
|
|
118
159
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
160
|
+
## 🔧 API Reference
|
|
161
|
+
|
|
162
|
+
### Confirm Container Props
|
|
163
|
+
|
|
164
|
+
| Prop | Type | Default | Description |
|
|
165
|
+
|------|------|---------|-------------|
|
|
166
|
+
| `animation` | `AnimationType` | `'slide'` | Animation type (18 options) |
|
|
167
|
+
| `animationDuration` | `number` | `300` | Base animation duration (ms) |
|
|
168
|
+
| `animationDurationIn` | `number` | - | Enter animation duration |
|
|
169
|
+
| `animationDurationOut` | `number` | - | Exit animation duration |
|
|
170
|
+
| `defaultColorSchema` | `ColorSchema` | `'dark'` | Default color scheme |
|
|
171
|
+
| `closeOnEscape` | `boolean` | `true` | Close with ESC key |
|
|
172
|
+
| `closeOnClickOutside` | `boolean` | `true` | Close on backdrop click |
|
|
173
|
+
| `classes` | `ConfirmClasses` | `{}` | Custom CSS classes |
|
|
174
|
+
|
|
175
|
+
### Confirm Function
|
|
176
|
+
|
|
177
|
+
```tsx
|
|
178
|
+
// String input (simple)
|
|
179
|
+
await confirm('Simple message');
|
|
180
|
+
|
|
181
|
+
// Object input (full options)
|
|
182
|
+
await confirm({
|
|
183
|
+
title: 'Custom Title', // Optional
|
|
184
|
+
message: 'Required message', // Required
|
|
185
|
+
okText: 'Proceed', // Optional
|
|
186
|
+
cancelText: 'Go Back', // Optional
|
|
187
|
+
colorSchema: 'blue', // Optional
|
|
188
|
+
});
|
|
123
189
|
```
|
|
124
190
|
|
|
125
|
-
|
|
126
|
-
|
|
191
|
+
**Return values:**
|
|
192
|
+
- `true` - User clicked OK
|
|
193
|
+
- `false` - User clicked Cancel
|
|
194
|
+
- `null` - User pressed ESC or clicked outside (if enabled)
|
|
195
|
+
|
|
196
|
+
### Custom Styling with CSS Classes
|
|
197
|
+
|
|
198
|
+
```tsx
|
|
127
199
|
<ConfirmContainer
|
|
128
200
|
classes={{
|
|
129
|
-
overlay: "
|
|
130
|
-
wrapper: "
|
|
131
|
-
title: "
|
|
132
|
-
message: "
|
|
133
|
-
button: "
|
|
134
|
-
cancel: "
|
|
135
|
-
ok: "
|
|
201
|
+
overlay: "my-overlay-class", // Background overlay
|
|
202
|
+
wrapper: "my-modal-class", // Modal container
|
|
203
|
+
title: "my-title-class", // Title text
|
|
204
|
+
message: "my-message-class", // Message text
|
|
205
|
+
button: "my-button-class", // Both buttons
|
|
206
|
+
cancel: "my-cancel-class", // Cancel button only
|
|
207
|
+
ok: "my-ok-class", // OK button only
|
|
136
208
|
}}
|
|
137
209
|
/>
|
|
138
210
|
```
|
|
139
211
|
|
|
140
|
-
|
|
141
|
-
|
|
212
|
+
## 🎭 Custom UI with Render Prop
|
|
213
|
+
|
|
214
|
+
Want complete control over the UI? Use the render prop:
|
|
215
|
+
|
|
216
|
+
```tsx
|
|
142
217
|
<ConfirmContainer animationDuration={500}>
|
|
143
|
-
{({
|
|
144
|
-
|
|
145
|
-
|
|
218
|
+
{({
|
|
219
|
+
isVisible,
|
|
220
|
+
confirm,
|
|
221
|
+
handleCancel,
|
|
222
|
+
handleOk,
|
|
223
|
+
containerRef,
|
|
224
|
+
animationClass,
|
|
225
|
+
animationStyle
|
|
226
|
+
}) => (
|
|
227
|
+
<div className={`modal-overlay ${isVisible ? 'show' : 'hide'}`}>
|
|
228
|
+
{/* Your custom backdrop */}
|
|
229
|
+
<div className="backdrop" onClick={handleCancel} />
|
|
230
|
+
|
|
231
|
+
{/* Your custom modal */}
|
|
232
|
+
<div
|
|
233
|
+
ref={containerRef}
|
|
234
|
+
className={`custom-modal ${animationClass}`}
|
|
235
|
+
style={animationStyle}
|
|
236
|
+
>
|
|
146
237
|
<h2>{confirm.title}</h2>
|
|
147
238
|
<p>{confirm.message}</p>
|
|
148
|
-
|
|
239
|
+
|
|
240
|
+
<div className="buttons">
|
|
149
241
|
<button onClick={handleCancel}>
|
|
150
242
|
{confirm.cancelText || 'Cancel'}
|
|
151
243
|
</button>
|
|
@@ -159,222 +251,238 @@ const handleCustomConfirm = async () => {
|
|
|
159
251
|
</ConfirmContainer>
|
|
160
252
|
```
|
|
161
253
|
|
|
162
|
-
|
|
254
|
+
**Available render props:**
|
|
255
|
+
- `isVisible`: Boolean indicating if dialog should be visible
|
|
256
|
+
- `confirm`: The current confirm options object
|
|
257
|
+
- `handleCancel`: Function to cancel the dialog (returns false)
|
|
258
|
+
- `handleOk`: Function to confirm the dialog (returns true)
|
|
259
|
+
- `containerRef`: React ref for the modal container
|
|
260
|
+
- `colorSchema`: Current color scheme
|
|
261
|
+
- `animationClass`: CSS class for current animation
|
|
262
|
+
- `animationStyle`: Style object with animation duration
|
|
163
263
|
|
|
164
|
-
|
|
264
|
+
## 📱 Real-World Examples
|
|
165
265
|
|
|
166
|
-
###
|
|
266
|
+
### Delete Confirmation with ESC Disabled
|
|
167
267
|
```tsx
|
|
168
|
-
|
|
169
|
-
|
|
268
|
+
const handleDelete = async () => {
|
|
269
|
+
// Force user to make explicit choice
|
|
270
|
+
const result = await confirm({
|
|
271
|
+
title: 'Delete Item',
|
|
272
|
+
message: 'This action cannot be undone. Are you sure?',
|
|
273
|
+
okText: 'Delete',
|
|
274
|
+
cancelText: 'Keep',
|
|
275
|
+
colorSchema: 'red'
|
|
276
|
+
});
|
|
170
277
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
return (
|
|
177
|
-
<html lang="en">
|
|
178
|
-
<body>
|
|
179
|
-
{children}
|
|
180
|
-
<ConfirmContainer />
|
|
181
|
-
</body>
|
|
182
|
-
</html>
|
|
183
|
-
);
|
|
184
|
-
}
|
|
185
|
-
```
|
|
186
|
-
```tsx
|
|
187
|
-
// app/page.tsx (server component)
|
|
188
|
-
import { confirm } from 'react-confirm-lite';
|
|
278
|
+
// Result can only be true or false (no null since ESC/backdrop disabled)
|
|
279
|
+
if (result) {
|
|
280
|
+
await deleteItem();
|
|
281
|
+
}
|
|
282
|
+
};
|
|
189
283
|
|
|
190
|
-
|
|
191
|
-
|
|
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
|
-
);
|
|
204
|
-
}
|
|
284
|
+
// In your component
|
|
285
|
+
<ConfirmContainer closeOnEscape={false} closeOnClickOutside={false} />
|
|
205
286
|
```
|
|
206
287
|
|
|
207
|
-
###
|
|
288
|
+
### Form Submission with Backdrop Only
|
|
208
289
|
```tsx
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
290
|
+
// Allow closing by clicking backdrop but not ESC
|
|
291
|
+
<ConfirmContainer closeOnEscape={false} closeOnClickOutside={true} />
|
|
292
|
+
|
|
293
|
+
const handleSubmit = async () => {
|
|
294
|
+
const result = await confirm({
|
|
295
|
+
title: 'Submit Form',
|
|
296
|
+
message: 'Ready to submit this form?',
|
|
297
|
+
okText: 'Submit',
|
|
298
|
+
cancelText: 'Review',
|
|
299
|
+
colorSchema: 'green'
|
|
300
|
+
});
|
|
219
301
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
}
|
|
302
|
+
if (result) {
|
|
303
|
+
await submitForm();
|
|
304
|
+
} else if (result === null) {
|
|
305
|
+
// User clicked backdrop
|
|
306
|
+
console.log('Closed by clicking outside');
|
|
307
|
+
}
|
|
308
|
+
};
|
|
227
309
|
```
|
|
228
310
|
|
|
229
|
-
|
|
311
|
+
### Different Behaviors for Different Dialogs
|
|
312
|
+
```tsx
|
|
313
|
+
// Global: ESC and backdrop disabled
|
|
314
|
+
<ConfirmContainer
|
|
315
|
+
closeOnEscape={false}
|
|
316
|
+
closeOnClickOutside={false}
|
|
317
|
+
/>
|
|
230
318
|
|
|
231
|
-
|
|
319
|
+
// Some dialogs can override via custom UI
|
|
320
|
+
const handleFlexibleDialog = async () => {
|
|
321
|
+
// Create custom UI that allows ESC/backdrop
|
|
322
|
+
const result = await confirm('Flexible dialog?');
|
|
323
|
+
// result can be true, false, or null
|
|
324
|
+
};
|
|
325
|
+
```
|
|
232
326
|
|
|
233
|
-
|
|
327
|
+
## 🏗️ Container Configuration
|
|
234
328
|
|
|
235
|
-
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
//
|
|
329
|
+
### Global Settings
|
|
330
|
+
```tsx
|
|
331
|
+
<ConfirmContainer
|
|
332
|
+
defaultColorSchema="light" // Light theme by default
|
|
333
|
+
animation="zoom" // Zoom animation for all dialogs
|
|
334
|
+
animationDuration={400} // 400ms animations
|
|
335
|
+
closeOnEscape={true} // Allow ESC to close
|
|
336
|
+
closeOnClickOutside={true} // Allow backdrop click to close
|
|
337
|
+
animationDurationIn={350} // Enter: 350ms
|
|
338
|
+
animationDurationOut={250} // Exit: 250ms
|
|
339
|
+
/>
|
|
239
340
|
```
|
|
240
341
|
|
|
241
|
-
|
|
242
|
-
```
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
cancelText: 'Cancel',
|
|
247
|
-
okText: 'Delete',
|
|
248
|
-
colorSchema: 'red',
|
|
249
|
-
isDestructive: true
|
|
250
|
-
});
|
|
251
|
-
```
|
|
342
|
+
### Different Close Behaviors
|
|
343
|
+
```tsx
|
|
344
|
+
// Option 1: Fully closable (default)
|
|
345
|
+
<ConfirmContainer closeOnEscape={true} closeOnClickOutside={true} />
|
|
346
|
+
// Users can close via: OK, Cancel, ESC, or backdrop click
|
|
252
347
|
|
|
253
|
-
|
|
348
|
+
// Option 2: Force explicit choice
|
|
349
|
+
<ConfirmContainer closeOnEscape={false} closeOnClickOutside={false} />
|
|
350
|
+
// Users can only close via: OK or Cancel buttons
|
|
254
351
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
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
|
-
}
|
|
352
|
+
// Option 3: Backdrop only
|
|
353
|
+
<ConfirmContainer closeOnEscape={false} closeOnClickOutside={true} />
|
|
354
|
+
// Users can close via: OK, Cancel, or backdrop click
|
|
275
355
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
cancelText?: string;
|
|
280
|
-
okText?: string;
|
|
281
|
-
colorSchema?: ColorSchema;
|
|
282
|
-
isDestructive?: boolean;
|
|
283
|
-
}
|
|
356
|
+
// Option 4: ESC only
|
|
357
|
+
<ConfirmContainer closeOnEscape={true} closeOnClickOutside={false} />
|
|
358
|
+
// Users can close via: OK, Cancel, or ESC key
|
|
284
359
|
```
|
|
285
360
|
|
|
286
|
-
##
|
|
361
|
+
## 🎨 Animation Gallery
|
|
287
362
|
|
|
288
|
-
###
|
|
289
|
-
-
|
|
290
|
-
-
|
|
363
|
+
### Slide Animations
|
|
364
|
+
- `slide` - Smooth vertical slide (default)
|
|
365
|
+
- `slideRight` / `slideLeft` - Horizontal slides
|
|
366
|
+
- `slideVertical` - Vertical slide
|
|
367
|
+
- `slideDown` - Slide down
|
|
291
368
|
|
|
292
|
-
###
|
|
293
|
-
-
|
|
369
|
+
### Fade Animations
|
|
370
|
+
- `fadeScale` - Fade with scaling
|
|
371
|
+
- `fadeUp` / `fadeDown` - Directional fades
|
|
372
|
+
- `fadeBlur` - Fade with blur effect
|
|
373
|
+
- `fadeShrink` - Fade with shrink effect
|
|
294
374
|
|
|
295
|
-
###
|
|
296
|
-
-
|
|
297
|
-
-
|
|
298
|
-
-
|
|
375
|
+
### 3D Animations
|
|
376
|
+
- `flip` - Card flip effect
|
|
377
|
+
- `drop` - 3D drop animation
|
|
378
|
+
- `rotate` / `rotateRight` - Rotation effects
|
|
299
379
|
|
|
300
|
-
###
|
|
301
|
-
-
|
|
302
|
-
-
|
|
380
|
+
### Playful Animations
|
|
381
|
+
- `bounce` / `bounceSmall` - Bounce effects
|
|
382
|
+
- `zoom` / `zoomSmall` - Zoom in/out
|
|
303
383
|
|
|
304
|
-
|
|
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
|
|
384
|
+
## 🚨 Troubleshooting
|
|
307
385
|
|
|
308
|
-
|
|
386
|
+
### Dialog not showing?
|
|
387
|
+
- Make sure `<ConfirmContainer />` is mounted
|
|
388
|
+
- Check it's not conditionally rendered
|
|
309
389
|
|
|
310
|
-
###
|
|
311
|
-
|
|
390
|
+
### ESC key not working?
|
|
391
|
+
- Check if `closeOnEscape={true}` (default)
|
|
392
|
+
- Ensure no other event is preventing ESC
|
|
393
|
+
- Try different browsers
|
|
312
394
|
|
|
313
|
-
###
|
|
314
|
-
|
|
395
|
+
### Backdrop click not working?
|
|
396
|
+
- Verify `closeOnClickOutside={true}` (default)
|
|
397
|
+
- Check if any parent element is preventing clicks
|
|
315
398
|
|
|
316
|
-
###
|
|
317
|
-
|
|
399
|
+
### Animation not working?
|
|
400
|
+
- Verify animation name is correct
|
|
401
|
+
- Check browser console for errors
|
|
318
402
|
|
|
319
|
-
###
|
|
320
|
-
|
|
403
|
+
### TypeScript errors?
|
|
404
|
+
- Ensure you have `@types/react` installed
|
|
405
|
+
- Update to latest TypeScript version
|
|
321
406
|
|
|
322
|
-
###
|
|
323
|
-
|
|
407
|
+
### Styling issues?
|
|
408
|
+
- Use `classes` prop to override styles
|
|
409
|
+
- Check CSS specificity
|
|
324
410
|
|
|
325
|
-
|
|
326
|
-
Full TypeScript support with comprehensive type definitions.
|
|
411
|
+
## 📱 Next.js Support
|
|
327
412
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
- **Small bundle size**: ~5KB gzipped (including styles)
|
|
333
|
-
- **Optimized renders**: Minimal re-renders with React.memo
|
|
413
|
+
### App Router (Next.js 15+)
|
|
414
|
+
```tsx
|
|
415
|
+
// app/layout.tsx
|
|
416
|
+
import { ConfirmContainer } from 'react-confirm-lite';
|
|
334
417
|
|
|
335
|
-
|
|
418
|
+
export default function RootLayout({
|
|
419
|
+
children,
|
|
420
|
+
}: {
|
|
421
|
+
children: React.ReactNode;
|
|
422
|
+
}) {
|
|
423
|
+
return (
|
|
424
|
+
<html lang="en">
|
|
425
|
+
<body>
|
|
426
|
+
{children}
|
|
427
|
+
<ConfirmContainer />
|
|
428
|
+
</body>
|
|
429
|
+
</html>
|
|
430
|
+
);
|
|
431
|
+
}
|
|
432
|
+
```
|
|
336
433
|
|
|
337
|
-
|
|
434
|
+
### Server Components
|
|
435
|
+
```tsx
|
|
436
|
+
// Server actions
|
|
437
|
+
'use server';
|
|
438
|
+
import { confirm } from 'react-confirm-lite';
|
|
338
439
|
|
|
339
|
-
|
|
340
|
-
|
|
440
|
+
export async function serverAction() {
|
|
441
|
+
const result = await confirm('Confirm from server?');
|
|
442
|
+
if (result) {
|
|
443
|
+
// Perform action
|
|
444
|
+
} else if (result === null) {
|
|
445
|
+
// User pressed ESC or clicked outside
|
|
446
|
+
console.log('Action cancelled');
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
```
|
|
341
450
|
|
|
451
|
+
## 🔄 Migration from Other Libraries
|
|
342
452
|
|
|
343
|
-
|
|
453
|
+
### From window.confirm()
|
|
454
|
+
```tsx
|
|
455
|
+
// Old way (always returns true/false)
|
|
456
|
+
if (window.confirm('Delete?')) {
|
|
457
|
+
deleteItem();
|
|
458
|
+
}
|
|
344
459
|
|
|
345
|
-
|
|
460
|
+
// New way (returns true/false/null)
|
|
461
|
+
const result = await confirm('Delete?');
|
|
462
|
+
if (result === true) {
|
|
463
|
+
await deleteItem();
|
|
464
|
+
} else if (result === false) {
|
|
465
|
+
console.log('User clicked Cancel');
|
|
466
|
+
} else if (result === null) {
|
|
467
|
+
console.log('User pressed ESC');
|
|
468
|
+
}
|
|
469
|
+
```
|
|
346
470
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
471
|
+
### From Other Confirm Libraries
|
|
472
|
+
- No CSS imports needed
|
|
473
|
+
- Automatic queue system
|
|
474
|
+
- Built-in animations
|
|
475
|
+
- Zero configuration
|
|
476
|
+
- Three return states (true/false/null)
|
|
351
477
|
|
|
352
|
-
##
|
|
478
|
+
## 📄 License
|
|
353
479
|
|
|
354
|
-
|
|
355
|
-
- GitHub: [@SaadNasir-git](https://github.com/SaadNasir-git)
|
|
356
|
-
- For support: Open an issue on GitHub
|
|
480
|
+
MIT License - free for personal and commercial use.
|
|
357
481
|
|
|
358
|
-
##
|
|
482
|
+
## 👨💻 Author
|
|
359
483
|
|
|
360
|
-
|
|
484
|
+
**Saad Nasir** - Creator of react-confirm-lite
|
|
361
485
|
|
|
362
486
|
---
|
|
363
487
|
|
|
364
|
-
|
|
365
|
-

|
|
366
|
-

|
|
367
|
-

|
|
368
|
-

|
|
369
|
-

|
|
370
|
-

|
|
371
|
-
|
|
372
|
-
## Support
|
|
373
|
-
|
|
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
|
|
379
|
-
|
|
380
|
-
Happy coding! 🚀
|
|
488
|
+
⭐ **Found this useful? Give it a star on GitHub!** ⭐
|