react-confirm-alert 3.0.6 → 3.1.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 +56 -89
- package/dist/index.esm.js +1058 -0
- package/dist/package.json +1 -0
- package/index.d.ts +2 -31
- package/lib/index.js +1071 -295
- package/package.json +35 -40
- package/src/react-confirm-alert.css +64 -54
- package/typings/Dialog.d.ts +27 -0
- package/typings/DialogFrame.d.ts +28 -0
- package/typings/DialogHost.d.ts +17 -0
- package/typings/DialogStack.d.ts +5 -0
- package/typings/api.d.ts +21 -0
- package/typings/classNames.d.ts +16 -0
- package/typings/compat.d.ts +48 -0
- package/typings/fallbackRoot.d.ts +4 -0
- package/typings/index.d.ts +9 -0
- package/typings/lifecycle.d.ts +7 -0
- package/typings/page.d.ts +2 -0
- package/typings/store.d.ts +59 -0
- package/typings/types.d.ts +138 -0
package/Readme.md
CHANGED
|
@@ -1,108 +1,75 @@
|
|
|
1
1
|
# react-confirm-alert
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
### For React <= 17.x.x use version 2.x.x
|
|
5
|
-
|
|
6
|
-
React component confirm dialog. [Live demo](https://ga-mo.github.io/react-confirm-alert/demo/)
|
|
3
|
+
Confirm, alert and prompt dialogs for React 18 and 19. `await confirm()`, a native modal, focus that moves in and back, and the v3 `confirmAlert` unchanged.
|
|
7
4
|
|
|
8
5
|
[](https://badge.fury.io/js/react-confirm-alert)
|
|
9
6
|
|
|
10
|
-
|
|
11
|
-
[v.1.x.x](https://github.com/GA-MO/react-confirm-alert/blob/master/Document-v1.md),
|
|
12
|
-
[v.2.x.x](https://github.com/GA-MO/react-confirm-alert/blob/master/Document-v2.md)
|
|
13
|
-
|
|
14
|
-
## Getting started
|
|
7
|
+
[Docs](https://ga-mo.github.io/react-confirm-alert/docs/) · [Playground](https://ga-mo.github.io/react-confirm-alert/playground/) · [Migrate from v3](https://ga-mo.github.io/react-confirm-alert/docs/migrate-from-v3/)
|
|
15
8
|
|
|
16
|
-
|
|
9
|
+
## Install
|
|
17
10
|
|
|
11
|
+
```bash
|
|
12
|
+
npm install react-confirm-alert
|
|
18
13
|
```
|
|
19
|
-
|
|
14
|
+
|
|
15
|
+
## Ask a question
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { confirm } from 'react-confirm-alert'
|
|
19
|
+
import 'react-confirm-alert/src/react-confirm-alert.css'
|
|
20
|
+
|
|
21
|
+
if (await confirm({ title: 'Delete file?', message: 'This cannot be undone.', tone: 'danger' })) {
|
|
22
|
+
remove(file)
|
|
23
|
+
}
|
|
20
24
|
```
|
|
21
25
|
|
|
22
|
-
|
|
26
|
+
`confirm()` resolves `true` or `false`. `alert()` and `prompt()` work the same way, and `<DialogHost />` placed inside your providers lets dialogs read their context.
|
|
27
|
+
|
|
28
|
+
## v3 code keeps working
|
|
23
29
|
|
|
24
30
|
```jsx
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
31
|
+
import { confirmAlert } from 'react-confirm-alert'
|
|
32
|
+
import 'react-confirm-alert/src/react-confirm-alert.css'
|
|
33
|
+
|
|
34
|
+
confirmAlert({
|
|
35
|
+
title: 'Confirm to submit',
|
|
36
|
+
message: 'Are you sure to do this.',
|
|
28
37
|
buttons: [
|
|
29
|
-
{
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
{
|
|
34
|
-
label: 'No',
|
|
35
|
-
onClick: () => alert('Click No')
|
|
36
|
-
}
|
|
37
|
-
],
|
|
38
|
-
closeOnEscape: true,
|
|
39
|
-
closeOnClickOutside: true,
|
|
40
|
-
keyCodeForClose: [8, 32],
|
|
41
|
-
willUnmount: () => {},
|
|
42
|
-
afterClose: () => {},
|
|
43
|
-
onClickOutside: () => {},
|
|
44
|
-
onKeypress: () => {},
|
|
45
|
-
onKeypressEscape: () => {},
|
|
46
|
-
overlayClassName: "overlay-custom-class-name"
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
confirmAlert(options);
|
|
38
|
+
{ label: 'Yes', onClick: () => alert('Click Yes') },
|
|
39
|
+
{ label: 'No', onClick: () => alert('Click No') }
|
|
40
|
+
]
|
|
41
|
+
})
|
|
50
42
|
```
|
|
51
43
|
|
|
52
|
-
|
|
44
|
+
Same options, DOM, class names and CSS path as v3.
|
|
53
45
|
|
|
54
|
-
|
|
55
|
-
import { confirmAlert } from 'react-confirm-alert'; // Import
|
|
56
|
-
import 'react-confirm-alert/src/react-confirm-alert.css'; // Import css
|
|
57
|
-
|
|
58
|
-
class App extends React.Component {
|
|
59
|
-
submit = () => {
|
|
60
|
-
confirmAlert({
|
|
61
|
-
title: 'Confirm to submit',
|
|
62
|
-
message: 'Are you sure to do this.',
|
|
63
|
-
buttons: [
|
|
64
|
-
{
|
|
65
|
-
label: 'Yes',
|
|
66
|
-
onClick: () => alert('Click Yes')
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
label: 'No',
|
|
70
|
-
onClick: () => alert('Click No')
|
|
71
|
-
}
|
|
72
|
-
]
|
|
73
|
-
});
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
render() {
|
|
77
|
-
return (
|
|
78
|
-
<div className='container'>
|
|
79
|
-
<button onClick={this.submit}>Confirm dialog</button>
|
|
80
|
-
</div>
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
```
|
|
46
|
+
## Tailwind CSS
|
|
85
47
|
|
|
86
|
-
|
|
48
|
+
```css
|
|
49
|
+
@import 'tailwindcss';
|
|
50
|
+
@import 'react-confirm-alert/src/react-confirm-alert.css' layer(components);
|
|
51
|
+
```
|
|
87
52
|
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
customUI: ({ onClose }) => {
|
|
91
|
-
return (
|
|
92
|
-
<div className='custom-ui'>
|
|
93
|
-
<h1>Are you sure?</h1>
|
|
94
|
-
<p>You want to delete this file?</p>
|
|
95
|
-
<button onClick={onClose}>No</button>
|
|
96
|
-
<button
|
|
97
|
-
onClick={() => {
|
|
98
|
-
this.handleClickDelete();
|
|
99
|
-
onClose();
|
|
100
|
-
}}
|
|
101
|
-
>
|
|
102
|
-
Yes, Delete it!
|
|
103
|
-
</button>
|
|
104
|
-
</div>
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
});
|
|
53
|
+
```tsx
|
|
54
|
+
confirm({ title: 'Publish?', classNames: { button: 'rounded-full bg-red-500' } })
|
|
108
55
|
```
|
|
56
|
+
|
|
57
|
+
Importing the CSS into `layer(components)` lets Tailwind utilities win without `!important`. Or pass `unstyled: true` and style every slot yourself.
|
|
58
|
+
|
|
59
|
+
## Size
|
|
60
|
+
|
|
61
|
+
| Import | gzip |
|
|
62
|
+
|---|---|
|
|
63
|
+
| `import { confirmAlert }` | 3,571 B |
|
|
64
|
+
| `import { confirm }` | 3,851 B |
|
|
65
|
+
| CSS | 1,095 B |
|
|
66
|
+
|
|
67
|
+
Measured on 2026-10-23 with size-limit 14.3.0 (`npx size-limit`, config in `.size-limit.json`): the ESM build bundled and minified with React and React DOM excluded, then gzipped. v3.0.6 measured the same way is 2,396 B, including `prop-types`. The extra bytes are the native modal, focus handling, stacked and queued dialogs, and dialogs that render inside your providers.
|
|
68
|
+
|
|
69
|
+
## Older versions
|
|
70
|
+
|
|
71
|
+
Docs for [v1](https://github.com/GA-MO/react-confirm-alert/blob/master/Document-v1.md) and [v2](https://github.com/GA-MO/react-confirm-alert/blob/master/Document-v2.md). For React 17 or older, use version 2.
|
|
72
|
+
|
|
73
|
+
## License
|
|
74
|
+
|
|
75
|
+
MIT
|