UNPKG

4.51 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright 2015 Palantir Technologies, Inc. All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17Object.defineProperty(exports, "__esModule", { value: true });
18exports.Alert = void 0;
19var tslib_1 = require("tslib");
20var classnames_1 = tslib_1.__importDefault(require("classnames"));
21var React = tslib_1.__importStar(require("react"));
22var common_1 = require("../../common");
23var errors_1 = require("../../common/errors");
24var buttons_1 = require("../button/buttons");
25var dialog_1 = require("../dialog/dialog");
26var icon_1 = require("../icon/icon");
27/**
28 * Alert component.
29 *
30 * @see https://blueprintjs.com/docs/#core/components/alert
31 */
32var Alert = /** @class */ (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));
78exports.Alert = Alert;
79//# sourceMappingURL=alert.js.map
\No newline at end of file