react-confirm-alert 2.8.0 → 3.0.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 +7 -4
- package/index.d.ts +7 -5
- package/lib/index.js +36 -17
- package/package.json +5 -5
package/Readme.md
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
# react-confirm-alert
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
### React 18 is supported!!
|
|
4
|
+
|
|
5
|
+
React component confirm dialog. [Live demo](https://ga-mo.github.io/react-confirm-alert/demo/)
|
|
4
6
|
|
|
5
7
|
[](https://badge.fury.io/js/react-confirm-alert)
|
|
6
8
|
|
|
7
|
-
Document for
|
|
9
|
+
Document for
|
|
10
|
+
[v.1.x.x](https://github.com/GA-MO/react-confirm-alert/blob/master/Document-v1.md),
|
|
11
|
+
[v.2.x.x](https://github.com/GA-MO/react-confirm-alert/blob/master/Document-v2.md)
|
|
8
12
|
|
|
9
13
|
## Getting started
|
|
10
14
|
|
|
@@ -30,14 +34,13 @@ const options = {
|
|
|
30
34
|
onClick: () => alert('Click No')
|
|
31
35
|
}
|
|
32
36
|
],
|
|
33
|
-
childrenElement: () => <div />,
|
|
34
|
-
customUI: ({ onClose }) => <div>Custom UI</div>,
|
|
35
37
|
closeOnEscape: true,
|
|
36
38
|
closeOnClickOutside: true,
|
|
37
39
|
keyCodeForClose: [8, 32],
|
|
38
40
|
willUnmount: () => {},
|
|
39
41
|
afterClose: () => {}
|
|
40
42
|
onClickOutside: () => {},
|
|
43
|
+
onKeypress: () => {},
|
|
41
44
|
onKeypressEscape: () => {},
|
|
42
45
|
overlayClassName: "overlay-custom-class-name"
|
|
43
46
|
};
|
package/index.d.ts
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
declare module 'react-confirm-alert' {
|
|
2
2
|
export interface ReactConfirmAlertProps {
|
|
3
|
+
targetId: string
|
|
3
4
|
title?: string
|
|
4
5
|
message?: string
|
|
5
6
|
buttons?: Array<{
|
|
6
7
|
label: string
|
|
7
|
-
onClick: () => void
|
|
8
8
|
className?: string
|
|
9
|
-
}>
|
|
9
|
+
} & HTMLButtonElement>
|
|
10
10
|
childrenElement?: () => React.ReactNode
|
|
11
11
|
customUI?: (customUiOptions: {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
title: string
|
|
13
|
+
message: string
|
|
14
|
+
onClose: () => void
|
|
15
15
|
}) => React.ReactNode
|
|
16
16
|
closeOnClickOutside?: boolean
|
|
17
17
|
closeOnEscape?: boolean
|
|
18
|
+
keyCodeForClose: Array<number>
|
|
18
19
|
willUnmount?: () => void
|
|
19
20
|
onClickOutside?: () => void
|
|
20
21
|
onKeypressEscape?: () => void
|
|
22
|
+
onkeyPress?: () => void
|
|
21
23
|
overlayClassName?: string
|
|
22
24
|
}
|
|
23
25
|
|
package/lib/index.js
CHANGED
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = undefined;
|
|
7
7
|
|
|
8
|
+
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
|
9
|
+
|
|
8
10
|
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
9
11
|
|
|
10
12
|
var _class, _temp2;
|
|
@@ -19,7 +21,7 @@ var _propTypes = require('prop-types');
|
|
|
19
21
|
|
|
20
22
|
var _propTypes2 = _interopRequireDefault(_propTypes);
|
|
21
23
|
|
|
22
|
-
var
|
|
24
|
+
var _client = require('react-dom/client');
|
|
23
25
|
|
|
24
26
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
27
|
|
|
@@ -61,12 +63,13 @@ var ReactConfirmAlert = (_temp2 = _class = function (_Component) {
|
|
|
61
63
|
var afterClose = _this.props.afterClose;
|
|
62
64
|
|
|
63
65
|
removeBodyClass();
|
|
64
|
-
removeElementReconfirm();
|
|
66
|
+
removeElementReconfirm(_this.props);
|
|
65
67
|
removeSVGBlurReconfirm(afterClose);
|
|
66
|
-
}, _this.
|
|
68
|
+
}, _this.keyboard = function (event) {
|
|
67
69
|
var _this$props2 = _this.props,
|
|
68
70
|
closeOnEscape = _this$props2.closeOnEscape,
|
|
69
71
|
onKeypressEscape = _this$props2.onKeypressEscape,
|
|
72
|
+
onkeyPress = _this$props2.onkeyPress,
|
|
70
73
|
keyCodeForClose = _this$props2.keyCodeForClose;
|
|
71
74
|
|
|
72
75
|
var keyCode = event.keyCode;
|
|
@@ -80,10 +83,14 @@ var ReactConfirmAlert = (_temp2 = _class = function (_Component) {
|
|
|
80
83
|
onKeypressEscape(event);
|
|
81
84
|
_this.close();
|
|
82
85
|
}
|
|
86
|
+
|
|
87
|
+
if (onkeyPress) {
|
|
88
|
+
onkeyPress();
|
|
89
|
+
}
|
|
83
90
|
}, _this.componentDidMount = function () {
|
|
84
|
-
document.addEventListener('keydown', _this.
|
|
91
|
+
document.addEventListener('keydown', _this.keyboard, false);
|
|
85
92
|
}, _this.componentWillUnmount = function () {
|
|
86
|
-
document.removeEventListener('keydown', _this.
|
|
93
|
+
document.removeEventListener('keydown', _this.keyboard, false);
|
|
87
94
|
_this.props.willUnmount();
|
|
88
95
|
}, _this.renderCustomUI = function () {
|
|
89
96
|
var _this$props3 = _this.props,
|
|
@@ -145,9 +152,13 @@ var ReactConfirmAlert = (_temp2 = _class = function (_Component) {
|
|
|
145
152
|
buttons.map(function (button, i) {
|
|
146
153
|
return _react2.default.createElement(
|
|
147
154
|
'button',
|
|
148
|
-
|
|
155
|
+
_extends({
|
|
156
|
+
key: i,
|
|
157
|
+
onClick: function onClick() {
|
|
149
158
|
return _this2.handleClickButton(button);
|
|
150
|
-
},
|
|
159
|
+
},
|
|
160
|
+
className: button.className
|
|
161
|
+
}, button),
|
|
151
162
|
button.label
|
|
152
163
|
);
|
|
153
164
|
})
|
|
@@ -172,6 +183,7 @@ var ReactConfirmAlert = (_temp2 = _class = function (_Component) {
|
|
|
172
183
|
afterClose: _propTypes2.default.func,
|
|
173
184
|
onClickOutside: _propTypes2.default.func,
|
|
174
185
|
onKeypressEscape: _propTypes2.default.func,
|
|
186
|
+
onkeyPress: _propTypes2.default.func,
|
|
175
187
|
overlayClassName: _propTypes2.default.string
|
|
176
188
|
}, _class.defaultProps = {
|
|
177
189
|
buttons: [{
|
|
@@ -209,6 +221,9 @@ var ReactConfirmAlert = (_temp2 = _class = function (_Component) {
|
|
|
209
221
|
exports.default = ReactConfirmAlert;
|
|
210
222
|
|
|
211
223
|
|
|
224
|
+
var root = null;
|
|
225
|
+
var targetId = 'react-confirm-alert';
|
|
226
|
+
|
|
212
227
|
function createSVGBlurReconfirm() {
|
|
213
228
|
// If has svg ignore to create the svg
|
|
214
229
|
var svg = document.getElementById('react-confirm-alert-firm-svg');
|
|
@@ -239,25 +254,29 @@ function removeSVGBlurReconfirm(afterClose) {
|
|
|
239
254
|
}
|
|
240
255
|
|
|
241
256
|
function createElementReconfirm(properties) {
|
|
242
|
-
var divTarget = document.getElementById(
|
|
257
|
+
var divTarget = document.getElementById(properties.targetId || targetId);
|
|
258
|
+
|
|
259
|
+
if (properties.targetId && !divTarget) {
|
|
260
|
+
console.error('React Confirm Alert:', 'Can not get element id (#' + properties.targetId + ')');
|
|
261
|
+
}
|
|
262
|
+
|
|
243
263
|
if (divTarget) {
|
|
244
|
-
|
|
245
|
-
|
|
264
|
+
root = (0, _client.createRoot)(divTarget);
|
|
265
|
+
root.render(_react2.default.createElement(ReactConfirmAlert, properties));
|
|
246
266
|
} else {
|
|
247
|
-
// Mount the ReactConfirmAlert component
|
|
248
267
|
document.body.children[0].classList.add('react-confirm-alert-blur');
|
|
249
268
|
divTarget = document.createElement('div');
|
|
250
|
-
divTarget.id =
|
|
269
|
+
divTarget.id = targetId;
|
|
251
270
|
document.body.appendChild(divTarget);
|
|
252
|
-
(0,
|
|
271
|
+
root = (0, _client.createRoot)(divTarget);
|
|
272
|
+
root.render(_react2.default.createElement(ReactConfirmAlert, properties));
|
|
253
273
|
}
|
|
254
274
|
}
|
|
255
275
|
|
|
256
|
-
function removeElementReconfirm() {
|
|
257
|
-
var target = document.getElementById(
|
|
276
|
+
function removeElementReconfirm(properties) {
|
|
277
|
+
var target = document.getElementById(properties.targetId || targetId);
|
|
258
278
|
if (target) {
|
|
259
|
-
|
|
260
|
-
target.parentNode.removeChild(target);
|
|
279
|
+
root.unmount(target);
|
|
261
280
|
}
|
|
262
281
|
}
|
|
263
282
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-confirm-alert",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "react component confirm dialog.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -63,8 +63,8 @@
|
|
|
63
63
|
"eslint-plugin-standard": "^3.0.1",
|
|
64
64
|
"mocha": "^3.5.0",
|
|
65
65
|
"prop-types": "^15.6.2",
|
|
66
|
-
"react": "^
|
|
67
|
-
"react-dom": "^
|
|
66
|
+
"react": "^18.1.0",
|
|
67
|
+
"react-dom": "^18.1.0",
|
|
68
68
|
"react-hot-loader": "^4.3.3",
|
|
69
69
|
"rimraf": "^2.6.1",
|
|
70
70
|
"style-loader": "^0.18.2",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"webpack-dev-server": "^2.7.1"
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
|
76
|
-
"react": ">=
|
|
77
|
-
"react-dom": ">=
|
|
76
|
+
"react": ">=18.0.0",
|
|
77
|
+
"react-dom": ">=10.0.0"
|
|
78
78
|
}
|
|
79
79
|
}
|