1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.Alert = void 0;
|
19 | var tslib_1 = require("tslib");
|
20 | var classnames_1 = tslib_1.__importDefault(require("classnames"));
|
21 | var React = tslib_1.__importStar(require("react"));
|
22 | var common_1 = require("../../common");
|
23 | var errors_1 = require("../../common/errors");
|
24 | var buttons_1 = require("../button/buttons");
|
25 | var dialog_1 = require("../dialog/dialog");
|
26 | var icon_1 = require("../icon/icon");
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | var Alert = (function (_super) {
|
33 | tslib_1.__extends(Alert, _super);
|
34 | function Alert() {
|
35 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
36 | _this.handleCancel = function (evt) { return _this.internalHandleCallbacks(false, evt); };
|
37 | _this.handleConfirm = function (evt) { return _this.internalHandleCallbacks(true, evt); };
|
38 | return _this;
|
39 | }
|
40 | Alert.prototype.render = function () {
|
41 | var _a = this.props, canEscapeKeyCancel = _a.canEscapeKeyCancel, canOutsideClickCancel = _a.canOutsideClickCancel, children = _a.children, className = _a.className, icon = _a.icon, intent = _a.intent, loading = _a.loading, cancelButtonText = _a.cancelButtonText, confirmButtonText = _a.confirmButtonText, onClose = _a.onClose, overlayProps = tslib_1.__rest(_a, ["canEscapeKeyCancel", "canOutsideClickCancel", "children", "className", "icon", "intent", "loading", "cancelButtonText", "confirmButtonText", "onClose"]);
|
42 | return (React.createElement(dialog_1.Dialog, tslib_1.__assign({}, overlayProps, { className: (0, classnames_1.default)(common_1.Classes.ALERT, className), canEscapeKeyClose: canEscapeKeyCancel, canOutsideClickClose: canOutsideClickCancel, onClose: this.handleCancel, portalContainer: this.props.portalContainer }),
|
43 | React.createElement("div", { className: common_1.Classes.ALERT_BODY },
|
44 | React.createElement(icon_1.Icon, { icon: icon, size: 40, intent: intent }),
|
45 | React.createElement("div", { className: common_1.Classes.ALERT_CONTENTS }, children)),
|
46 | React.createElement("div", { className: common_1.Classes.ALERT_FOOTER },
|
47 | React.createElement(buttons_1.Button, { loading: loading, intent: intent, text: confirmButtonText, onClick: this.handleConfirm }),
|
48 | cancelButtonText && (React.createElement(buttons_1.Button, { text: cancelButtonText, disabled: loading, onClick: this.handleCancel })))));
|
49 | };
|
50 | Alert.prototype.validateProps = function (props) {
|
51 | if (props.onClose == null && (props.cancelButtonText == null) !== (props.onCancel == null)) {
|
52 | console.warn(errors_1.ALERT_WARN_CANCEL_PROPS);
|
53 | }
|
54 | var hasCancelHandler = props.onCancel != null || props.onClose != null;
|
55 | if (props.canEscapeKeyCancel && !hasCancelHandler) {
|
56 | console.warn(errors_1.ALERT_WARN_CANCEL_ESCAPE_KEY);
|
57 | }
|
58 | if (props.canOutsideClickCancel && !hasCancelHandler) {
|
59 | console.warn(errors_1.ALERT_WARN_CANCEL_OUTSIDE_CLICK);
|
60 | }
|
61 | };
|
62 | Alert.prototype.internalHandleCallbacks = function (confirmed, evt) {
|
63 | var _a;
|
64 | var _b = this.props, onCancel = _b.onCancel, onClose = _b.onClose, onConfirm = _b.onConfirm;
|
65 | (_a = (confirmed ? onConfirm : onCancel)) === null || _a === void 0 ? void 0 : _a(evt);
|
66 | onClose === null || onClose === void 0 ? void 0 : onClose(confirmed, evt);
|
67 | };
|
68 | Alert.defaultProps = {
|
69 | canEscapeKeyCancel: false,
|
70 | canOutsideClickCancel: false,
|
71 | confirmButtonText: "OK",
|
72 | isOpen: false,
|
73 | loading: false,
|
74 | };
|
75 | Alert.displayName = "".concat(common_1.DISPLAYNAME_PREFIX, ".Alert");
|
76 | return Alert;
|
77 | }(common_1.AbstractPureComponent2));
|
78 | exports.Alert = Alert;
|
79 |
|
\ | No newline at end of file |