react-confirm 0.1.21 → 0.2.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 +2 -2
- package/package.json +8 -12
- package/src/confirmable.js +23 -30
- package/src/createConfirmation.js +5 -5
- package/lib/confirmable.js +0 -82
- package/lib/createConfirmation.js +0 -60
- package/lib/index.js +0 -19
package/README.md
CHANGED
|
@@ -34,13 +34,13 @@ import PropTypes from 'prop-types';
|
|
|
34
34
|
import { confirmable } from 'react-confirm';
|
|
35
35
|
import Dialog from 'any-dialog-library'; // your choice.
|
|
36
36
|
|
|
37
|
-
const YourDialog = ({show, proceed, confirmation, options}) =>
|
|
37
|
+
const YourDialog = ({show, proceed, confirmation, options}) => (
|
|
38
38
|
<Dialog onHide={() => proceed(false)} show={show}>
|
|
39
39
|
{confirmation}
|
|
40
40
|
<button onClick={() => proceed(false)}>CANCEL</button>
|
|
41
41
|
<button onClick={() => proceed(true)}>OK</button>
|
|
42
42
|
</Dialog>
|
|
43
|
-
|
|
43
|
+
)
|
|
44
44
|
|
|
45
45
|
YourDialog.propTypes = {
|
|
46
46
|
show: PropTypes.bool, // from confirmable. indicates if the dialog is shown or not.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-confirm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Small library which makes your Dialog component callable",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -29,19 +29,15 @@
|
|
|
29
29
|
"author": "",
|
|
30
30
|
"license": "MIT",
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"react-dom": "
|
|
33
|
-
"react": "
|
|
32
|
+
"react-dom": "18.x",
|
|
33
|
+
"react": "18.x"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"babel
|
|
37
|
-
"babel
|
|
38
|
-
"babel-
|
|
39
|
-
"babel
|
|
40
|
-
"
|
|
41
|
-
"babel-preset-stage-0": "^6.3.13",
|
|
42
|
-
"dependency-check": "^3.2.1",
|
|
43
|
-
"rimraf": "^2.5.1",
|
|
44
|
-
"webpack": "^1.15.0"
|
|
36
|
+
"@babel/cli": "^7.17.6",
|
|
37
|
+
"@babel/core": "^7.17.9",
|
|
38
|
+
"@babel/preset-env": "^7.16.11",
|
|
39
|
+
"@babel/preset-react": "^7.16.7",
|
|
40
|
+
"rimraf": "^3.0.2"
|
|
45
41
|
},
|
|
46
42
|
"dependencies": {}
|
|
47
43
|
}
|
package/src/confirmable.js
CHANGED
|
@@ -1,38 +1,31 @@
|
|
|
1
|
-
import React from 'react'
|
|
1
|
+
import React, {useState} from 'react';
|
|
2
2
|
|
|
3
|
-
const confirmable = (Component) =>
|
|
3
|
+
const confirmable = (Component) => ({dispose, reject, resolve, ...other}) => {
|
|
4
|
+
const [show, setShow] = useState(true);
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
this.state = {
|
|
9
|
-
show: true,
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
dismiss() {
|
|
13
|
-
this.setState({
|
|
14
|
-
show: false,
|
|
15
|
-
}, () => {
|
|
16
|
-
this.props.dispose();
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
cancel(value) {
|
|
20
|
-
this.setState({
|
|
21
|
-
show: false,
|
|
22
|
-
}, () => {
|
|
23
|
-
this.props.reject(value);
|
|
24
|
-
});
|
|
6
|
+
const dismiss = () => {
|
|
7
|
+
setShow(false);
|
|
8
|
+
dispose()
|
|
25
9
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
this.props.resolve(value);
|
|
31
|
-
});
|
|
10
|
+
|
|
11
|
+
const cancel = (value) => {
|
|
12
|
+
setShow(false)
|
|
13
|
+
reject(value);
|
|
32
14
|
}
|
|
33
|
-
|
|
34
|
-
|
|
15
|
+
|
|
16
|
+
const proceed = (value) => {
|
|
17
|
+
setShow(false)
|
|
18
|
+
resolve(value)
|
|
35
19
|
}
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<Component
|
|
23
|
+
cancel={cancel}
|
|
24
|
+
dismiss={dismiss}
|
|
25
|
+
proceed={proceed}
|
|
26
|
+
show={show}
|
|
27
|
+
{...other} />
|
|
28
|
+
);
|
|
36
29
|
}
|
|
37
30
|
|
|
38
31
|
export default confirmable;
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import { createRoot } from 'react-dom/client';
|
|
3
3
|
|
|
4
4
|
const createConfirmation = (Component, unmountDelay = 1000, mountingNode) => {
|
|
5
5
|
return (props) => {
|
|
6
6
|
const wrapper = (mountingNode || document.body).appendChild(document.createElement('div'));
|
|
7
|
+
const root = createRoot(wrapper);
|
|
7
8
|
|
|
8
9
|
const promise = new Promise((resolve, reject) => {
|
|
9
10
|
try {
|
|
10
|
-
|
|
11
|
+
root.render(
|
|
11
12
|
<Component
|
|
12
13
|
reject={reject}
|
|
13
14
|
resolve={resolve}
|
|
14
15
|
dispose={dispose}
|
|
15
16
|
{...props}
|
|
16
|
-
|
|
17
|
-
wrapper
|
|
17
|
+
/>
|
|
18
18
|
);
|
|
19
19
|
} catch (e) {
|
|
20
20
|
console.error(e);
|
|
@@ -24,7 +24,7 @@ const createConfirmation = (Component, unmountDelay = 1000, mountingNode) => {
|
|
|
24
24
|
|
|
25
25
|
function dispose() {
|
|
26
26
|
setTimeout(() => {
|
|
27
|
-
|
|
27
|
+
root.unmount();
|
|
28
28
|
setTimeout(() => {
|
|
29
29
|
if (document.body.contains(wrapper)) {
|
|
30
30
|
document.body.removeChild(wrapper)
|
package/lib/confirmable.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
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; };
|
|
8
|
-
|
|
9
|
-
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; }; }();
|
|
10
|
-
|
|
11
|
-
var _react = require('react');
|
|
12
|
-
|
|
13
|
-
var _react2 = _interopRequireDefault(_react);
|
|
14
|
-
|
|
15
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
-
|
|
17
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
18
|
-
|
|
19
|
-
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
|
20
|
-
|
|
21
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
|
22
|
-
|
|
23
|
-
var confirmable = function confirmable(Component) {
|
|
24
|
-
return function (_React$Component) {
|
|
25
|
-
_inherits(_class, _React$Component);
|
|
26
|
-
|
|
27
|
-
function _class(props) {
|
|
28
|
-
_classCallCheck(this, _class);
|
|
29
|
-
|
|
30
|
-
var _this = _possibleConstructorReturn(this, (_class.__proto__ || Object.getPrototypeOf(_class)).call(this, props));
|
|
31
|
-
|
|
32
|
-
_this.state = {
|
|
33
|
-
show: true
|
|
34
|
-
};
|
|
35
|
-
return _this;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
_createClass(_class, [{
|
|
39
|
-
key: 'dismiss',
|
|
40
|
-
value: function dismiss() {
|
|
41
|
-
var _this2 = this;
|
|
42
|
-
|
|
43
|
-
this.setState({
|
|
44
|
-
show: false
|
|
45
|
-
}, function () {
|
|
46
|
-
_this2.props.dispose();
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
}, {
|
|
50
|
-
key: 'cancel',
|
|
51
|
-
value: function cancel(value) {
|
|
52
|
-
var _this3 = this;
|
|
53
|
-
|
|
54
|
-
this.setState({
|
|
55
|
-
show: false
|
|
56
|
-
}, function () {
|
|
57
|
-
_this3.props.reject(value);
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}, {
|
|
61
|
-
key: 'proceed',
|
|
62
|
-
value: function proceed(value) {
|
|
63
|
-
var _this4 = this;
|
|
64
|
-
|
|
65
|
-
this.setState({
|
|
66
|
-
show: false
|
|
67
|
-
}, function () {
|
|
68
|
-
_this4.props.resolve(value);
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
}, {
|
|
72
|
-
key: 'render',
|
|
73
|
-
value: function render() {
|
|
74
|
-
return _react2.default.createElement(Component, _extends({ proceed: this.proceed.bind(this), cancel: this.cancel.bind(this), dismiss: this.dismiss.bind(this), show: this.state.show }, this.props));
|
|
75
|
-
}
|
|
76
|
-
}]);
|
|
77
|
-
|
|
78
|
-
return _class;
|
|
79
|
-
}(_react2.default.Component);
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
exports.default = confirmable;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
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; };
|
|
8
|
-
|
|
9
|
-
var _react = require('react');
|
|
10
|
-
|
|
11
|
-
var _react2 = _interopRequireDefault(_react);
|
|
12
|
-
|
|
13
|
-
var _reactDom = require('react-dom');
|
|
14
|
-
|
|
15
|
-
var _reactDom2 = _interopRequireDefault(_reactDom);
|
|
16
|
-
|
|
17
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
-
|
|
19
|
-
var createConfirmation = function createConfirmation(Component) {
|
|
20
|
-
var unmountDelay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1000;
|
|
21
|
-
var mountingNode = arguments[2];
|
|
22
|
-
|
|
23
|
-
return function (props) {
|
|
24
|
-
var wrapper = (mountingNode || document.body).appendChild(document.createElement('div'));
|
|
25
|
-
|
|
26
|
-
var promise = new Promise(function (resolve, reject) {
|
|
27
|
-
try {
|
|
28
|
-
_reactDom2.default.render(_react2.default.createElement(Component, _extends({
|
|
29
|
-
reject: reject,
|
|
30
|
-
resolve: resolve,
|
|
31
|
-
dispose: dispose
|
|
32
|
-
}, props)), wrapper);
|
|
33
|
-
} catch (e) {
|
|
34
|
-
console.error(e);
|
|
35
|
-
throw e;
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
function dispose() {
|
|
40
|
-
setTimeout(function () {
|
|
41
|
-
_reactDom2.default.unmountComponentAtNode(wrapper);
|
|
42
|
-
setTimeout(function () {
|
|
43
|
-
if (document.body.contains(wrapper)) {
|
|
44
|
-
document.body.removeChild(wrapper);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
}, unmountDelay);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return promise.then(function (result) {
|
|
51
|
-
dispose();
|
|
52
|
-
return result;
|
|
53
|
-
}, function (result) {
|
|
54
|
-
dispose();
|
|
55
|
-
return Promise.reject(result);
|
|
56
|
-
});
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
exports.default = createConfirmation;
|
package/lib/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createConfirmation = exports.confirmable = undefined;
|
|
7
|
-
|
|
8
|
-
var _confirmable = require('./confirmable');
|
|
9
|
-
|
|
10
|
-
var _confirmable2 = _interopRequireDefault(_confirmable);
|
|
11
|
-
|
|
12
|
-
var _createConfirmation = require('./createConfirmation');
|
|
13
|
-
|
|
14
|
-
var _createConfirmation2 = _interopRequireDefault(_createConfirmation);
|
|
15
|
-
|
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
18
|
-
exports.confirmable = _confirmable2.default;
|
|
19
|
-
exports.createConfirmation = _createConfirmation2.default;
|