react-confirm-alert 2.6.2 → 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 CHANGED
@@ -1,10 +1,14 @@
1
1
  # react-confirm-alert
2
2
 
3
- react component confirm dialog. [Live demo](https://ga-mo.github.io/react-confirm-alert/demo/)
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
  [![npm version](https://badge.fury.io/js/react-confirm-alert.svg)](https://badge.fury.io/js/react-confirm-alert)
6
8
 
7
- Document for v.1.x.x [see](https://github.com/GA-MO/react-confirm-alert/blob/master/Document-v1.md)
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,15 @@ 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: () => {},
40
- onKeypressEscape: () => {}
43
+ onKeypress: () => {},
44
+ onKeypressEscape: () => {},
45
+ overlayClassName: "overlay-custom-class-name"
41
46
  };
42
47
 
43
48
  confirmAlert(options);
package/index.d.ts CHANGED
@@ -1,23 +1,26 @@
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
- title: string
13
- message: string
14
- onClose: () => void
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
23
+ overlayClassName?: string
21
24
  }
22
25
 
23
26
  export function confirmAlert(options: ReactConfirmAlertProps): void
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 _reactDom = require('react-dom');
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.keyboardClose = function (event) {
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;
74
+
75
+ var keyCode = event.keyCode;
76
+ var isKeyCodeEscape = keyCode === 27;
70
77
 
71
- var isKeyCodeEscape = event.keyCode === 27;
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.keyboardClose, false);
91
+ document.addEventListener('keydown', _this.keyboard, false);
79
92
  }, _this.componentWillUnmount = function () {
80
- document.removeEventListener('keydown', _this.keyboardClose, false);
93
+ document.removeEventListener('keydown', _this.keyboard, false);
81
94
  _this.props.willUnmount();
82
95
  }, _this.renderCustomUI = function () {
83
96
  var _this$props3 = _this.props,
@@ -107,13 +120,14 @@ var ReactConfirmAlert = (_temp2 = _class = function (_Component) {
107
120
  message = _props.message,
108
121
  buttons = _props.buttons,
109
122
  childrenElement = _props.childrenElement,
110
- customUI = _props.customUI;
123
+ customUI = _props.customUI,
124
+ overlayClassName = _props.overlayClassName;
111
125
 
112
126
 
113
127
  return _react2.default.createElement(
114
128
  'div',
115
129
  {
116
- className: 'react-confirm-alert-overlay',
130
+ className: 'react-confirm-alert-overlay ' + overlayClassName,
117
131
  ref: function ref(dom) {
118
132
  return _this2.overlay = dom;
119
133
  },
@@ -138,9 +152,13 @@ var ReactConfirmAlert = (_temp2 = _class = function (_Component) {
138
152
  buttons.map(function (button, i) {
139
153
  return _react2.default.createElement(
140
154
  'button',
141
- { key: i, onClick: function onClick() {
155
+ _extends({
156
+ key: i,
157
+ onClick: function onClick() {
142
158
  return _this2.handleClickButton(button);
143
- }, className: button.className },
159
+ },
160
+ className: button.className
161
+ }, button),
144
162
  button.label
145
163
  );
146
164
  })
@@ -160,10 +178,13 @@ var ReactConfirmAlert = (_temp2 = _class = function (_Component) {
160
178
  customUI: _propTypes2.default.func,
161
179
  closeOnClickOutside: _propTypes2.default.bool,
162
180
  closeOnEscape: _propTypes2.default.bool,
181
+ keyCodeForClose: _propTypes2.default.arrayOf(_propTypes2.default.number),
163
182
  willUnmount: _propTypes2.default.func,
164
183
  afterClose: _propTypes2.default.func,
165
184
  onClickOutside: _propTypes2.default.func,
166
- onKeypressEscape: _propTypes2.default.func
185
+ onKeypressEscape: _propTypes2.default.func,
186
+ onkeyPress: _propTypes2.default.func,
187
+ overlayClassName: _propTypes2.default.string
167
188
  }, _class.defaultProps = {
168
189
  buttons: [{
169
190
  label: 'Cancel',
@@ -183,6 +204,7 @@ var ReactConfirmAlert = (_temp2 = _class = function (_Component) {
183
204
  },
184
205
  closeOnClickOutside: true,
185
206
  closeOnEscape: true,
207
+ keyCodeForClose: [],
186
208
  willUnmount: function willUnmount() {
187
209
  return null;
188
210
  },
@@ -199,6 +221,9 @@ var ReactConfirmAlert = (_temp2 = _class = function (_Component) {
199
221
  exports.default = ReactConfirmAlert;
200
222
 
201
223
 
224
+ var root = null;
225
+ var targetId = 'react-confirm-alert';
226
+
202
227
  function createSVGBlurReconfirm() {
203
228
  // If has svg ignore to create the svg
204
229
  var svg = document.getElementById('react-confirm-alert-firm-svg');
@@ -221,31 +246,37 @@ function createSVGBlurReconfirm() {
221
246
 
222
247
  function removeSVGBlurReconfirm(afterClose) {
223
248
  var svg = document.getElementById('react-confirm-alert-firm-svg');
224
- svg.parentNode.removeChild(svg);
249
+ if (svg) {
250
+ svg.parentNode.removeChild(svg);
251
+ }
225
252
  document.body.children[0].classList.remove('react-confirm-alert-blur');
226
253
  afterClose();
227
254
  }
228
255
 
229
256
  function createElementReconfirm(properties) {
230
- var divTarget = document.getElementById('react-confirm-alert');
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
+
231
263
  if (divTarget) {
232
- // Rerender - the mounted ReactConfirmAlert
233
- (0, _reactDom.render)(_react2.default.createElement(ReactConfirmAlert, properties), divTarget);
264
+ root = (0, _client.createRoot)(divTarget);
265
+ root.render(_react2.default.createElement(ReactConfirmAlert, properties));
234
266
  } else {
235
- // Mount the ReactConfirmAlert component
236
267
  document.body.children[0].classList.add('react-confirm-alert-blur');
237
268
  divTarget = document.createElement('div');
238
- divTarget.id = 'react-confirm-alert';
269
+ divTarget.id = targetId;
239
270
  document.body.appendChild(divTarget);
240
- (0, _reactDom.render)(_react2.default.createElement(ReactConfirmAlert, properties), divTarget);
271
+ root = (0, _client.createRoot)(divTarget);
272
+ root.render(_react2.default.createElement(ReactConfirmAlert, properties));
241
273
  }
242
274
  }
243
275
 
244
- function removeElementReconfirm() {
245
- var target = document.getElementById('react-confirm-alert');
276
+ function removeElementReconfirm(properties) {
277
+ var target = document.getElementById(properties.targetId || targetId);
246
278
  if (target) {
247
- (0, _reactDom.unmountComponentAtNode)(target);
248
- target.parentNode.removeChild(target);
279
+ root.unmount(target);
249
280
  }
250
281
  }
251
282
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-confirm-alert",
3
- "version": "2.6.2",
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": "^16.4.1",
67
- "react-dom": "^16.4.1",
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": ">=16.0.0",
77
- "react-dom": ">=16.0.0"
76
+ "react": ">=18.0.0",
77
+ "react-dom": ">=10.0.0"
78
78
  }
79
79
  }