react-confirm-alert 2.7.0 → 3.0.1
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 +8 -4
- package/index.d.ts +7 -5
- package/lib/index.js +47 -19
- 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,13 +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,
|
|
39
|
+
keyCodeForClose: [8, 32],
|
|
37
40
|
willUnmount: () => {},
|
|
38
41
|
afterClose: () => {}
|
|
39
42
|
onClickOutside: () => {},
|
|
43
|
+
onKeypress: () => {},
|
|
40
44
|
onKeypressEscape: () => {},
|
|
41
45
|
overlayClassName: "overlay-custom-class-name"
|
|
42
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,23 +63,34 @@ 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
|
-
onKeypressEscape = _this$props2.onKeypressEscape
|
|
71
|
+
onKeypressEscape = _this$props2.onKeypressEscape,
|
|
72
|
+
onkeyPress = _this$props2.onkeyPress,
|
|
73
|
+
keyCodeForClose = _this$props2.keyCodeForClose;
|
|
70
74
|
|
|
71
|
-
var
|
|
75
|
+
var keyCode = event.keyCode;
|
|
76
|
+
var isKeyCodeEscape = keyCode === 27;
|
|
77
|
+
|
|
78
|
+
if (keyCodeForClose.includes(keyCode)) {
|
|
79
|
+
_this.close();
|
|
80
|
+
}
|
|
72
81
|
|
|
73
82
|
if (closeOnEscape && isKeyCodeEscape) {
|
|
74
83
|
onKeypressEscape(event);
|
|
75
84
|
_this.close();
|
|
76
85
|
}
|
|
86
|
+
|
|
87
|
+
if (onkeyPress) {
|
|
88
|
+
onkeyPress();
|
|
89
|
+
}
|
|
77
90
|
}, _this.componentDidMount = function () {
|
|
78
|
-
document.addEventListener('keydown', _this.
|
|
91
|
+
document.addEventListener('keydown', _this.keyboard, false);
|
|
79
92
|
}, _this.componentWillUnmount = function () {
|
|
80
|
-
document.removeEventListener('keydown', _this.
|
|
93
|
+
document.removeEventListener('keydown', _this.keyboard, false);
|
|
81
94
|
_this.props.willUnmount();
|
|
82
95
|
}, _this.renderCustomUI = function () {
|
|
83
96
|
var _this$props3 = _this.props,
|
|
@@ -139,9 +152,14 @@ var ReactConfirmAlert = (_temp2 = _class = function (_Component) {
|
|
|
139
152
|
buttons.map(function (button, i) {
|
|
140
153
|
return _react2.default.createElement(
|
|
141
154
|
'button',
|
|
142
|
-
|
|
155
|
+
_extends({
|
|
156
|
+
key: i,
|
|
157
|
+
className: button.className
|
|
158
|
+
}, button, {
|
|
159
|
+
onClick: function onClick(e) {
|
|
143
160
|
return _this2.handleClickButton(button);
|
|
144
|
-
}
|
|
161
|
+
}
|
|
162
|
+
}),
|
|
145
163
|
button.label
|
|
146
164
|
);
|
|
147
165
|
})
|
|
@@ -161,10 +179,12 @@ var ReactConfirmAlert = (_temp2 = _class = function (_Component) {
|
|
|
161
179
|
customUI: _propTypes2.default.func,
|
|
162
180
|
closeOnClickOutside: _propTypes2.default.bool,
|
|
163
181
|
closeOnEscape: _propTypes2.default.bool,
|
|
182
|
+
keyCodeForClose: _propTypes2.default.arrayOf(_propTypes2.default.number),
|
|
164
183
|
willUnmount: _propTypes2.default.func,
|
|
165
184
|
afterClose: _propTypes2.default.func,
|
|
166
185
|
onClickOutside: _propTypes2.default.func,
|
|
167
186
|
onKeypressEscape: _propTypes2.default.func,
|
|
187
|
+
onkeyPress: _propTypes2.default.func,
|
|
168
188
|
overlayClassName: _propTypes2.default.string
|
|
169
189
|
}, _class.defaultProps = {
|
|
170
190
|
buttons: [{
|
|
@@ -185,6 +205,7 @@ var ReactConfirmAlert = (_temp2 = _class = function (_Component) {
|
|
|
185
205
|
},
|
|
186
206
|
closeOnClickOutside: true,
|
|
187
207
|
closeOnEscape: true,
|
|
208
|
+
keyCodeForClose: [],
|
|
188
209
|
willUnmount: function willUnmount() {
|
|
189
210
|
return null;
|
|
190
211
|
},
|
|
@@ -201,6 +222,9 @@ var ReactConfirmAlert = (_temp2 = _class = function (_Component) {
|
|
|
201
222
|
exports.default = ReactConfirmAlert;
|
|
202
223
|
|
|
203
224
|
|
|
225
|
+
var root = null;
|
|
226
|
+
var targetId = 'react-confirm-alert';
|
|
227
|
+
|
|
204
228
|
function createSVGBlurReconfirm() {
|
|
205
229
|
// If has svg ignore to create the svg
|
|
206
230
|
var svg = document.getElementById('react-confirm-alert-firm-svg');
|
|
@@ -231,25 +255,29 @@ function removeSVGBlurReconfirm(afterClose) {
|
|
|
231
255
|
}
|
|
232
256
|
|
|
233
257
|
function createElementReconfirm(properties) {
|
|
234
|
-
var divTarget = document.getElementById(
|
|
258
|
+
var divTarget = document.getElementById(properties.targetId || targetId);
|
|
259
|
+
|
|
260
|
+
if (properties.targetId && !divTarget) {
|
|
261
|
+
console.error('React Confirm Alert:', 'Can not get element id (#' + properties.targetId + ')');
|
|
262
|
+
}
|
|
263
|
+
|
|
235
264
|
if (divTarget) {
|
|
236
|
-
|
|
237
|
-
|
|
265
|
+
root = (0, _client.createRoot)(divTarget);
|
|
266
|
+
root.render(_react2.default.createElement(ReactConfirmAlert, properties));
|
|
238
267
|
} else {
|
|
239
|
-
// Mount the ReactConfirmAlert component
|
|
240
268
|
document.body.children[0].classList.add('react-confirm-alert-blur');
|
|
241
269
|
divTarget = document.createElement('div');
|
|
242
|
-
divTarget.id =
|
|
270
|
+
divTarget.id = targetId;
|
|
243
271
|
document.body.appendChild(divTarget);
|
|
244
|
-
(0,
|
|
272
|
+
root = (0, _client.createRoot)(divTarget);
|
|
273
|
+
root.render(_react2.default.createElement(ReactConfirmAlert, properties));
|
|
245
274
|
}
|
|
246
275
|
}
|
|
247
276
|
|
|
248
|
-
function removeElementReconfirm() {
|
|
249
|
-
var target = document.getElementById(
|
|
277
|
+
function removeElementReconfirm(properties) {
|
|
278
|
+
var target = document.getElementById(properties.targetId || targetId);
|
|
250
279
|
if (target) {
|
|
251
|
-
|
|
252
|
-
target.parentNode.removeChild(target);
|
|
280
|
+
root.unmount(target);
|
|
253
281
|
}
|
|
254
282
|
}
|
|
255
283
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-confirm-alert",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
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
|
}
|