react-confirm-lite 1.2.4 → 1.2.5
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 +2 -0
- package/package.json +5 -5
- package/dist/README.md +0 -378
package/README.md
CHANGED
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
- Always use the latest version for bug fixes and improvements
|
|
18
18
|
- If you face any issues, please report them on [GitHub](https://github.com/SaadNasir-git/react-confirm-lite/issues)
|
|
19
19
|
|
|
20
|
+

|
|
21
|
+
|
|
20
22
|
## Quick Comparison
|
|
21
23
|
|
|
22
24
|
| Feature | react-confirm-lite | react-confirm | react-confirm-toast |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-confirm-lite",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5",
|
|
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",
|
|
@@ -13,8 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"files": [
|
|
15
15
|
"dist",
|
|
16
|
-
"LICENSE"
|
|
17
|
-
"README.md"
|
|
16
|
+
"LICENSE"
|
|
18
17
|
],
|
|
19
18
|
"repository": {
|
|
20
19
|
"type": "git",
|
|
@@ -22,7 +21,7 @@
|
|
|
22
21
|
},
|
|
23
22
|
"homepage": "https://github.com/SaadNasir-git/react-confirm-lite#readme",
|
|
24
23
|
"scripts": {
|
|
25
|
-
"build": "tsup && cp
|
|
24
|
+
"build": "tsup && cp LICENSE dist/",
|
|
26
25
|
"clean": "rm -rf dist",
|
|
27
26
|
"postbuild": "echo \"'use client';\" | cat - dist/index.js > temp && mv temp dist/index.js",
|
|
28
27
|
"prepack": "npm run clean && npm run build"
|
|
@@ -38,5 +37,6 @@
|
|
|
38
37
|
"typescript": "^5.9.3"
|
|
39
38
|
},
|
|
40
39
|
"license": "MIT",
|
|
41
|
-
"author": "Saad Nasir"
|
|
40
|
+
"author": "Saad Nasir",
|
|
41
|
+
"keywords": ["react-confirm" , "react-confirm-lite" , "react confirm lite" , "react confirm" , "confirm"]
|
|
42
42
|
}
|
package/dist/README.md
DELETED
|
@@ -1,378 +0,0 @@
|
|
|
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
|
-
## Quick Comparison
|
|
21
|
-
|
|
22
|
-
| Feature | react-confirm-lite | react-confirm | react-confirm-toast |
|
|
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' | ✅ |
|
|
30
|
-
|
|
31
|
-
## Why Choose react-confirm-lite?
|
|
32
|
-
|
|
33
|
-
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.
|
|
34
|
-
|
|
35
|
-
## 🔗 Live Demo
|
|
36
|
-
|
|
37
|
-
[](https://stackblitz.com/edit/vitejs-vite-bfthlpmw?file=src%2FApp.tsx)
|
|
38
|
-
|
|
39
|
-
## Getting Started
|
|
40
|
-
|
|
41
|
-
### Step 1: **Install the package**:
|
|
42
|
-
```bash
|
|
43
|
-
npm install react-confirm-lite
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
### Step 2: Import in your component:
|
|
47
|
-
```tsx
|
|
48
|
-
import { confirm, ConfirmContainer } from 'react-confirm-lite';
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
### Step 3: Add ConfirmContainer to your component tree:
|
|
52
|
-
```jsx
|
|
53
|
-
function App() {
|
|
54
|
-
return (
|
|
55
|
-
<>
|
|
56
|
-
<ConfirmContainer />
|
|
57
|
-
{/* Your app content */}
|
|
58
|
-
</>
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
### Step 4: Use the confirm function:
|
|
64
|
-
```tsx
|
|
65
|
-
const handleAction = async () => {
|
|
66
|
-
const isConfirmed = await confirm('Are you sure?');
|
|
67
|
-
if (isConfirmed) {
|
|
68
|
-
// Perform action
|
|
69
|
-
console.log('Confirmed!');
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
### Complete Example:
|
|
75
|
-
|
|
76
|
-
```tsx
|
|
77
|
-
import { confirm, ConfirmContainer } from 'react-confirm-lite';
|
|
78
|
-
|
|
79
|
-
function App() {
|
|
80
|
-
const handleDelete = async () => {
|
|
81
|
-
const isConfirmed = await confirm('Are you sure you want to delete this item?');
|
|
82
|
-
if (isConfirmed) {
|
|
83
|
-
// Delete logic here
|
|
84
|
-
console.log('Item deleted');
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
return (
|
|
89
|
-
<div>
|
|
90
|
-
<button onClick={handleDelete}>Delete Item</button>
|
|
91
|
-
<ConfirmContainer />
|
|
92
|
-
</div>
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
## Advanced Usage
|
|
98
|
-
|
|
99
|
-
### Custom Options:
|
|
100
|
-
```tsx
|
|
101
|
-
const handleCustomConfirm = async () => {
|
|
102
|
-
const isConfirmed = await confirm({
|
|
103
|
-
title: "Delete Item",
|
|
104
|
-
message: "This action cannot be undone. Are you sure?",
|
|
105
|
-
cancelText: 'No, keep it',
|
|
106
|
-
okText: 'Yes, delete',
|
|
107
|
-
colorSchema: 'red',
|
|
108
|
-
isDestructive: true
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
if (isConfirmed) {
|
|
112
|
-
// Delete item
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
### Custom Color Scheme:
|
|
118
|
-
```jsx
|
|
119
|
-
<ConfirmContainer defaultColorSchema="light" />
|
|
120
|
-
// Available options: 'light', 'dark', 'blue', 'red', 'green', 'purple'
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
### Custom Styling:
|
|
124
|
-
```jsx
|
|
125
|
-
<ConfirmContainer
|
|
126
|
-
classes={{
|
|
127
|
-
overlay: "bg-black/50",
|
|
128
|
-
wrapper: "rounded-xl shadow-2xl",
|
|
129
|
-
title: "text-2xl font-bold",
|
|
130
|
-
message: "text-gray-600",
|
|
131
|
-
button: "px-6 py-3 rounded-lg font-medium",
|
|
132
|
-
cancel: "border border-gray-300 hover:bg-gray-50",
|
|
133
|
-
ok: "bg-blue-600 hover:bg-blue-700 text-white"
|
|
134
|
-
}}
|
|
135
|
-
/>
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
### Fully Custom UI with Render Prop:
|
|
139
|
-
```jsx
|
|
140
|
-
<ConfirmContainer animationDuration={500}>
|
|
141
|
-
{({ isVisible, confirm, handleCancel, handleOk }) => (
|
|
142
|
-
<div className={`modal ${isVisible ? 'show' : 'hide'}`}>
|
|
143
|
-
<div className="modal-content">
|
|
144
|
-
<h2>{confirm.title}</h2>
|
|
145
|
-
<p>{confirm.message}</p>
|
|
146
|
-
<div className="modal-actions">
|
|
147
|
-
<button onClick={handleCancel}>
|
|
148
|
-
{confirm.cancelText || 'Cancel'}
|
|
149
|
-
</button>
|
|
150
|
-
<button onClick={handleOk}>
|
|
151
|
-
{confirm.okText || 'OK'}
|
|
152
|
-
</button>
|
|
153
|
-
</div>
|
|
154
|
-
</div>
|
|
155
|
-
</div>
|
|
156
|
-
)}
|
|
157
|
-
</ConfirmContainer>
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
## Next.js App Router Support
|
|
161
|
-
|
|
162
|
-
Works automatically! No 'use client' directive needed for the library. The library handles everything internally.
|
|
163
|
-
|
|
164
|
-
### Server Components Example:
|
|
165
|
-
```tsx
|
|
166
|
-
// app/layout.tsx
|
|
167
|
-
import { ConfirmContainer } from 'react-confirm-lite';
|
|
168
|
-
|
|
169
|
-
export default function RootLayout({
|
|
170
|
-
children,
|
|
171
|
-
}: {
|
|
172
|
-
children: React.ReactNode;
|
|
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';
|
|
187
|
-
|
|
188
|
-
export default async function Page() {
|
|
189
|
-
// Server-side logic here
|
|
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
|
-
}
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
### Client Component Example:
|
|
206
|
-
```tsx
|
|
207
|
-
'use client';
|
|
208
|
-
import { confirm, ConfirmContainer } from 'react-confirm-lite';
|
|
209
|
-
|
|
210
|
-
export default function ClientComponent() {
|
|
211
|
-
const handleClick = async () => {
|
|
212
|
-
const result = await confirm('Confirm action?');
|
|
213
|
-
if (result) {
|
|
214
|
-
// Handle confirmation
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
return (
|
|
219
|
-
<div>
|
|
220
|
-
<button onClick={handleClick}>Click me</button>
|
|
221
|
-
<ConfirmContainer />
|
|
222
|
-
</div>
|
|
223
|
-
);
|
|
224
|
-
}
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
## API Reference
|
|
228
|
-
|
|
229
|
-
### `confirm(message: string | ConfirmOptions): Promise<boolean>`
|
|
230
|
-
|
|
231
|
-
Displays a confirmation dialog. Returns a promise that resolves to `true` if confirmed, `false` if cancelled.
|
|
232
|
-
|
|
233
|
-
**String usage:**
|
|
234
|
-
```ts
|
|
235
|
-
await confirm('Simple message');
|
|
236
|
-
// Equivalent to: { title: 'Confirm', message: 'Simple message' }
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
**Object usage:**
|
|
240
|
-
```ts
|
|
241
|
-
await confirm({
|
|
242
|
-
title: 'Warning',
|
|
243
|
-
message: 'This action cannot be undone',
|
|
244
|
-
cancelText: 'Cancel',
|
|
245
|
-
okText: 'Delete',
|
|
246
|
-
colorSchema: 'red',
|
|
247
|
-
isDestructive: true
|
|
248
|
-
});
|
|
249
|
-
```
|
|
250
|
-
|
|
251
|
-
### `ConfirmContainer` Props:
|
|
252
|
-
|
|
253
|
-
| Prop | Type | Default | Description |
|
|
254
|
-
|------|------|---------|-------------|
|
|
255
|
-
| `defaultColorSchema` | `ColorSchema` | `'dark'` | Default color scheme |
|
|
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
|
-
}
|
|
273
|
-
|
|
274
|
-
interface ConfirmOptions {
|
|
275
|
-
title?: string;
|
|
276
|
-
message: string;
|
|
277
|
-
cancelText?: string;
|
|
278
|
-
okText?: string;
|
|
279
|
-
colorSchema?: ColorSchema;
|
|
280
|
-
isDestructive?: boolean;
|
|
281
|
-
}
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
## Troubleshooting
|
|
285
|
-
|
|
286
|
-
### ❌ Dialog not appearing?
|
|
287
|
-
- Make sure `<ConfirmContainer />` is rendered in your component tree
|
|
288
|
-
- Check that you're not conditionally rendering it in a way that unmounts it
|
|
289
|
-
|
|
290
|
-
### ❌ Multiple dialogs overlapping?
|
|
291
|
-
- The library has a built-in queue system that handles multiple confirm requests sequentially
|
|
292
|
-
|
|
293
|
-
### ❌ Styling not working?
|
|
294
|
-
- If using custom classes, ensure they have proper CSS specificity
|
|
295
|
-
- Try using `!important` flag for custom styles if needed
|
|
296
|
-
- Make sure you're on the latest version
|
|
297
|
-
|
|
298
|
-
### ❌ Animation issues with custom UI?
|
|
299
|
-
- When using the `children` render prop, use the `isVisible` prop for animations
|
|
300
|
-
- Set appropriate `animationDuration` to match your CSS transitions
|
|
301
|
-
|
|
302
|
-
### ❌ Next.js hydration errors?
|
|
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
|
|
305
|
-
|
|
306
|
-
## Features in Detail
|
|
307
|
-
|
|
308
|
-
### 🎨 Multiple Color Schemes
|
|
309
|
-
Six built-in color schemes: light, dark, blue, red, green, purple. Set globally or per confirm dialog.
|
|
310
|
-
|
|
311
|
-
### 🔄 Queue System
|
|
312
|
-
Multiple confirm requests are queued and shown one at a time, preventing overlapping dialogs.
|
|
313
|
-
|
|
314
|
-
### 🎯 Zero Configuration
|
|
315
|
-
Works out of the box with default styling. No CSS imports needed.
|
|
316
|
-
|
|
317
|
-
### 🔧 Fully Customizable
|
|
318
|
-
From simple class overrides to complete UI replacement with render props.
|
|
319
|
-
|
|
320
|
-
### 📱 Responsive Design
|
|
321
|
-
Built-in responsive styling that works on all screen sizes.
|
|
322
|
-
|
|
323
|
-
### 🔒 Type Safety
|
|
324
|
-
Full TypeScript support with comprehensive type definitions.
|
|
325
|
-
|
|
326
|
-
## Performance
|
|
327
|
-
|
|
328
|
-
- **Zero dependencies**: Only React as a peer dependency
|
|
329
|
-
- **Tree-shakeable**: Only imports what you use
|
|
330
|
-
- **Small bundle size**: ~5KB gzipped (including styles)
|
|
331
|
-
- **Optimized renders**: Minimal re-renders with React.memo
|
|
332
|
-
|
|
333
|
-
## Migration from Older Versions
|
|
334
|
-
|
|
335
|
-
If you're upgrading from version <1.3.0:
|
|
336
|
-
|
|
337
|
-
1. **'use client' not needed**: The library handles this internally
|
|
338
|
-
2. **Simpler API**: Same functions, better internals
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
## Contributing
|
|
342
|
-
|
|
343
|
-
Contributions are welcome! Please:
|
|
344
|
-
|
|
345
|
-
1. Fork the repository
|
|
346
|
-
2. Create a feature branch
|
|
347
|
-
3. Add tests for your changes
|
|
348
|
-
4. Submit a pull request
|
|
349
|
-
|
|
350
|
-
## Author
|
|
351
|
-
|
|
352
|
-
**Saad Nasir** - Full Stack Developer
|
|
353
|
-
- GitHub: [@SaadNasir-git](https://github.com/SaadNasir-git)
|
|
354
|
-
- For support: Open an issue on GitHub
|
|
355
|
-
|
|
356
|
-
## License
|
|
357
|
-
|
|
358
|
-
MIT © Saad Nasir
|
|
359
|
-
|
|
360
|
-
---
|
|
361
|
-
|
|
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! 🚀
|