react-confirm-lite 1.2.4 → 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 -269
- package/dist/index.d.ts +38 -9
- package/dist/index.js +130 -49
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/dist/README.md +0 -378
package/README.md
CHANGED
|
@@ -1,149 +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
|
-
## Quick Comparison
|
|
1
|
+
# React Confirm Lite ✨
|
|
21
2
|
|
|
22
|
-
|
|
23
|
-
|---------|-------------------|---------------|---------------------|
|
|
24
|
-
| Built-in styling | ✅ Multiple color schemes | ❌ None | ✅ Toast style |
|
|
25
|
-
| Promise-based | ✅ | ✅ | ✅ |
|
|
26
|
-
| Zero dependencies | ✅ | ✅ | ✅ |
|
|
27
|
-
| Queue system | ✅ | ❌ | ❌ |
|
|
28
|
-
| Automatic CSS | ✅ No separate imports | ❌ | ❌ |
|
|
29
|
-
| 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.**
|
|
30
4
|
|
|
31
|
-
|
|
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
|
-
|
|
12
|
+

|
|
34
13
|
|
|
35
14
|
## 🔗 Live Demo
|
|
36
15
|
|
|
37
16
|
[](https://stackblitz.com/edit/vitejs-vite-bfthlpmw?file=src%2FApp.tsx)
|
|
38
17
|
|
|
39
|
-
##
|
|
18
|
+
## 📦 Installation
|
|
40
19
|
|
|
41
|
-
### Step 1: **Install the package**:
|
|
42
20
|
```bash
|
|
43
21
|
npm install react-confirm-lite
|
|
22
|
+
# or
|
|
23
|
+
yarn add react-confirm-lite
|
|
24
|
+
# or
|
|
25
|
+
pnpm add react-confirm-lite
|
|
44
26
|
```
|
|
45
27
|
|
|
46
|
-
|
|
28
|
+
## 🚀 Quick Start
|
|
29
|
+
|
|
30
|
+
### 1. Add the Container Component
|
|
31
|
+
|
|
32
|
+
Place `<ConfirmContainer />` in your app (usually in root layout):
|
|
33
|
+
|
|
47
34
|
```tsx
|
|
48
|
-
import {
|
|
49
|
-
```
|
|
35
|
+
import { ConfirmContainer } from 'react-confirm-lite';
|
|
50
36
|
|
|
51
|
-
### Step 3: Add ConfirmContainer to your component tree:
|
|
52
|
-
```jsx
|
|
53
37
|
function App() {
|
|
54
38
|
return (
|
|
55
|
-
|
|
56
|
-
<ConfirmContainer />
|
|
39
|
+
<div>
|
|
57
40
|
{/* Your app content */}
|
|
58
|
-
|
|
41
|
+
<ConfirmContainer />
|
|
42
|
+
</div>
|
|
59
43
|
);
|
|
60
44
|
}
|
|
61
45
|
```
|
|
62
46
|
|
|
63
|
-
###
|
|
47
|
+
### 2. Use the Confirm Function
|
|
48
|
+
|
|
49
|
+
Import and use `confirm()` anywhere in your app:
|
|
50
|
+
|
|
64
51
|
```tsx
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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!');
|
|
70
61
|
}
|
|
71
|
-
}
|
|
62
|
+
}
|
|
72
63
|
```
|
|
73
64
|
|
|
74
|
-
|
|
65
|
+
## 🎯 Features
|
|
75
66
|
|
|
67
|
+
### ✅ Simple Promise-based API
|
|
76
68
|
```tsx
|
|
77
|
-
|
|
69
|
+
const result = await confirm('Message here');
|
|
70
|
+
// Returns true for OK, false for Cancel, null for ESC/outside click
|
|
71
|
+
```
|
|
78
72
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
+
```
|
|
87
119
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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');
|
|
94
137
|
}
|
|
95
138
|
```
|
|
96
139
|
|
|
97
|
-
|
|
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
|
+
```
|
|
98
150
|
|
|
99
|
-
###
|
|
151
|
+
### Disable ESC and Backdrop Closing
|
|
100
152
|
```tsx
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
okText: 'Yes, delete',
|
|
107
|
-
colorSchema: 'red',
|
|
108
|
-
isDestructive: true
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
if (isConfirmed) {
|
|
112
|
-
// Delete item
|
|
113
|
-
}
|
|
114
|
-
};
|
|
153
|
+
<ConfirmContainer
|
|
154
|
+
closeOnEscape={false}
|
|
155
|
+
closeOnClickOutside={false}
|
|
156
|
+
/>
|
|
157
|
+
// Now dialog can only be closed with Cancel/OK buttons
|
|
115
158
|
```
|
|
116
159
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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
|
+
});
|
|
121
189
|
```
|
|
122
190
|
|
|
123
|
-
|
|
124
|
-
|
|
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
|
|
125
199
|
<ConfirmContainer
|
|
126
200
|
classes={{
|
|
127
|
-
overlay: "
|
|
128
|
-
wrapper: "
|
|
129
|
-
title: "
|
|
130
|
-
message: "
|
|
131
|
-
button: "
|
|
132
|
-
cancel: "
|
|
133
|
-
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
|
|
134
208
|
}}
|
|
135
209
|
/>
|
|
136
210
|
```
|
|
137
211
|
|
|
138
|
-
|
|
139
|
-
|
|
212
|
+
## 🎭 Custom UI with Render Prop
|
|
213
|
+
|
|
214
|
+
Want complete control over the UI? Use the render prop:
|
|
215
|
+
|
|
216
|
+
```tsx
|
|
140
217
|
<ConfirmContainer animationDuration={500}>
|
|
141
|
-
{({
|
|
142
|
-
|
|
143
|
-
|
|
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
|
+
>
|
|
144
237
|
<h2>{confirm.title}</h2>
|
|
145
238
|
<p>{confirm.message}</p>
|
|
146
|
-
|
|
239
|
+
|
|
240
|
+
<div className="buttons">
|
|
147
241
|
<button onClick={handleCancel}>
|
|
148
242
|
{confirm.cancelText || 'Cancel'}
|
|
149
243
|
</button>
|
|
@@ -157,222 +251,238 @@ const handleCustomConfirm = async () => {
|
|
|
157
251
|
</ConfirmContainer>
|
|
158
252
|
```
|
|
159
253
|
|
|
160
|
-
|
|
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
|
|
161
263
|
|
|
162
|
-
|
|
264
|
+
## 📱 Real-World Examples
|
|
163
265
|
|
|
164
|
-
###
|
|
266
|
+
### Delete Confirmation with ESC Disabled
|
|
165
267
|
```tsx
|
|
166
|
-
|
|
167
|
-
|
|
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
|
+
});
|
|
168
277
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
return (
|
|
175
|
-
<html lang="en">
|
|
176
|
-
<body>
|
|
177
|
-
{children}
|
|
178
|
-
<ConfirmContainer />
|
|
179
|
-
</body>
|
|
180
|
-
</html>
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
```
|
|
184
|
-
```tsx
|
|
185
|
-
// app/page.tsx (server component)
|
|
186
|
-
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
|
+
};
|
|
187
283
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
return (
|
|
192
|
-
<form action={async () => {
|
|
193
|
-
'use server';
|
|
194
|
-
const isConfirmed = await confirm('Are you sure?');
|
|
195
|
-
if (isConfirmed) {
|
|
196
|
-
// Server action
|
|
197
|
-
}
|
|
198
|
-
}}>
|
|
199
|
-
<button>Submit</button>
|
|
200
|
-
</form>
|
|
201
|
-
);
|
|
202
|
-
}
|
|
284
|
+
// In your component
|
|
285
|
+
<ConfirmContainer closeOnEscape={false} closeOnClickOutside={false} />
|
|
203
286
|
```
|
|
204
287
|
|
|
205
|
-
###
|
|
288
|
+
### Form Submission with Backdrop Only
|
|
206
289
|
```tsx
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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
|
+
});
|
|
217
301
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}
|
|
302
|
+
if (result) {
|
|
303
|
+
await submitForm();
|
|
304
|
+
} else if (result === null) {
|
|
305
|
+
// User clicked backdrop
|
|
306
|
+
console.log('Closed by clicking outside');
|
|
307
|
+
}
|
|
308
|
+
};
|
|
225
309
|
```
|
|
226
310
|
|
|
227
|
-
|
|
311
|
+
### Different Behaviors for Different Dialogs
|
|
312
|
+
```tsx
|
|
313
|
+
// Global: ESC and backdrop disabled
|
|
314
|
+
<ConfirmContainer
|
|
315
|
+
closeOnEscape={false}
|
|
316
|
+
closeOnClickOutside={false}
|
|
317
|
+
/>
|
|
228
318
|
|
|
229
|
-
|
|
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
|
+
```
|
|
230
326
|
|
|
231
|
-
|
|
327
|
+
## 🏗️ Container Configuration
|
|
232
328
|
|
|
233
|
-
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
//
|
|
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
|
+
/>
|
|
237
340
|
```
|
|
238
341
|
|
|
239
|
-
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
cancelText: 'Cancel',
|
|
245
|
-
okText: 'Delete',
|
|
246
|
-
colorSchema: 'red',
|
|
247
|
-
isDestructive: true
|
|
248
|
-
});
|
|
249
|
-
```
|
|
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
|
|
250
347
|
|
|
251
|
-
|
|
348
|
+
// Option 2: Force explicit choice
|
|
349
|
+
<ConfirmContainer closeOnEscape={false} closeOnClickOutside={false} />
|
|
350
|
+
// Users can only close via: OK or Cancel buttons
|
|
252
351
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
| `animationDuration` | `number` | `300` | Animation duration in ms |
|
|
257
|
-
| `classes` | `ConfirmClasses` | `{}` | Custom CSS classes |
|
|
258
|
-
| `children` | Render function | - | For complete UI customization |
|
|
259
|
-
|
|
260
|
-
### Types:
|
|
261
|
-
```ts
|
|
262
|
-
type ColorSchema = 'light' | 'dark' | 'blue' | 'red' | 'green' | 'purple';
|
|
263
|
-
|
|
264
|
-
interface ConfirmClasses {
|
|
265
|
-
overlay?: string;
|
|
266
|
-
wrapper?: string;
|
|
267
|
-
title?: string;
|
|
268
|
-
message?: string;
|
|
269
|
-
button?: string;
|
|
270
|
-
cancel?: string;
|
|
271
|
-
ok?: string;
|
|
272
|
-
}
|
|
352
|
+
// Option 3: Backdrop only
|
|
353
|
+
<ConfirmContainer closeOnEscape={false} closeOnClickOutside={true} />
|
|
354
|
+
// Users can close via: OK, Cancel, or backdrop click
|
|
273
355
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
cancelText?: string;
|
|
278
|
-
okText?: string;
|
|
279
|
-
colorSchema?: ColorSchema;
|
|
280
|
-
isDestructive?: boolean;
|
|
281
|
-
}
|
|
356
|
+
// Option 4: ESC only
|
|
357
|
+
<ConfirmContainer closeOnEscape={true} closeOnClickOutside={false} />
|
|
358
|
+
// Users can close via: OK, Cancel, or ESC key
|
|
282
359
|
```
|
|
283
360
|
|
|
284
|
-
##
|
|
361
|
+
## 🎨 Animation Gallery
|
|
285
362
|
|
|
286
|
-
###
|
|
287
|
-
-
|
|
288
|
-
-
|
|
363
|
+
### Slide Animations
|
|
364
|
+
- `slide` - Smooth vertical slide (default)
|
|
365
|
+
- `slideRight` / `slideLeft` - Horizontal slides
|
|
366
|
+
- `slideVertical` - Vertical slide
|
|
367
|
+
- `slideDown` - Slide down
|
|
289
368
|
|
|
290
|
-
###
|
|
291
|
-
-
|
|
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
|
|
292
374
|
|
|
293
|
-
###
|
|
294
|
-
-
|
|
295
|
-
-
|
|
296
|
-
-
|
|
375
|
+
### 3D Animations
|
|
376
|
+
- `flip` - Card flip effect
|
|
377
|
+
- `drop` - 3D drop animation
|
|
378
|
+
- `rotate` / `rotateRight` - Rotation effects
|
|
297
379
|
|
|
298
|
-
###
|
|
299
|
-
-
|
|
300
|
-
-
|
|
380
|
+
### Playful Animations
|
|
381
|
+
- `bounce` / `bounceSmall` - Bounce effects
|
|
382
|
+
- `zoom` / `zoomSmall` - Zoom in/out
|
|
301
383
|
|
|
302
|
-
|
|
303
|
-
- The library is designed to work with Next.js App Router
|
|
304
|
-
- If using in a layout, ensure it's placed after dynamic content
|
|
384
|
+
## 🚨 Troubleshooting
|
|
305
385
|
|
|
306
|
-
|
|
386
|
+
### Dialog not showing?
|
|
387
|
+
- Make sure `<ConfirmContainer />` is mounted
|
|
388
|
+
- Check it's not conditionally rendered
|
|
307
389
|
|
|
308
|
-
###
|
|
309
|
-
|
|
390
|
+
### ESC key not working?
|
|
391
|
+
- Check if `closeOnEscape={true}` (default)
|
|
392
|
+
- Ensure no other event is preventing ESC
|
|
393
|
+
- Try different browsers
|
|
310
394
|
|
|
311
|
-
###
|
|
312
|
-
|
|
395
|
+
### Backdrop click not working?
|
|
396
|
+
- Verify `closeOnClickOutside={true}` (default)
|
|
397
|
+
- Check if any parent element is preventing clicks
|
|
313
398
|
|
|
314
|
-
###
|
|
315
|
-
|
|
399
|
+
### Animation not working?
|
|
400
|
+
- Verify animation name is correct
|
|
401
|
+
- Check browser console for errors
|
|
316
402
|
|
|
317
|
-
###
|
|
318
|
-
|
|
403
|
+
### TypeScript errors?
|
|
404
|
+
- Ensure you have `@types/react` installed
|
|
405
|
+
- Update to latest TypeScript version
|
|
319
406
|
|
|
320
|
-
###
|
|
321
|
-
|
|
407
|
+
### Styling issues?
|
|
408
|
+
- Use `classes` prop to override styles
|
|
409
|
+
- Check CSS specificity
|
|
322
410
|
|
|
323
|
-
|
|
324
|
-
Full TypeScript support with comprehensive type definitions.
|
|
411
|
+
## 📱 Next.js Support
|
|
325
412
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
- **Small bundle size**: ~5KB gzipped (including styles)
|
|
331
|
-
- **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';
|
|
332
417
|
|
|
333
|
-
|
|
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
|
+
```
|
|
334
433
|
|
|
335
|
-
|
|
434
|
+
### Server Components
|
|
435
|
+
```tsx
|
|
436
|
+
// Server actions
|
|
437
|
+
'use server';
|
|
438
|
+
import { confirm } from 'react-confirm-lite';
|
|
336
439
|
|
|
337
|
-
|
|
338
|
-
|
|
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
|
+
```
|
|
339
450
|
|
|
451
|
+
## 🔄 Migration from Other Libraries
|
|
340
452
|
|
|
341
|
-
|
|
453
|
+
### From window.confirm()
|
|
454
|
+
```tsx
|
|
455
|
+
// Old way (always returns true/false)
|
|
456
|
+
if (window.confirm('Delete?')) {
|
|
457
|
+
deleteItem();
|
|
458
|
+
}
|
|
342
459
|
|
|
343
|
-
|
|
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
|
+
```
|
|
344
470
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
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)
|
|
349
477
|
|
|
350
|
-
##
|
|
478
|
+
## 📄 License
|
|
351
479
|
|
|
352
|
-
|
|
353
|
-
- GitHub: [@SaadNasir-git](https://github.com/SaadNasir-git)
|
|
354
|
-
- For support: Open an issue on GitHub
|
|
480
|
+
MIT License - free for personal and commercial use.
|
|
355
481
|
|
|
356
|
-
##
|
|
482
|
+
## 👨💻 Author
|
|
357
483
|
|
|
358
|
-
|
|
484
|
+
**Saad Nasir** - Creator of react-confirm-lite
|
|
359
485
|
|
|
360
486
|
---
|
|
361
487
|
|
|
362
|
-
|
|
363
|
-

|
|
364
|
-

|
|
365
|
-

|
|
366
|
-

|
|
367
|
-

|
|
368
|
-

|
|
369
|
-
|
|
370
|
-
## Support
|
|
371
|
-
|
|
372
|
-
If you find this library helpful, please consider:
|
|
373
|
-
- ⭐ Starring the repository on GitHub
|
|
374
|
-
- 📢 Sharing with your network
|
|
375
|
-
- 🐛 Reporting issues you encounter
|
|
376
|
-
- 💡 Suggesting new features
|
|
377
|
-
|
|
378
|
-
Happy coding! 🚀
|
|
488
|
+
⭐ **Found this useful? Give it a star on GitHub!** ⭐
|