@blueprintjs/core
Version:
Core styles & components
64 lines • 4.41 kB
JavaScript
/*
* Copyright 2025 Palantir Technologies, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Alert = void 0;
var tslib_1 = require("tslib");
var classnames_1 = tslib_1.__importDefault(require("classnames"));
var React = tslib_1.__importStar(require("react"));
var common_1 = require("../../common");
var errors_1 = require("../../common/errors");
var useValidateProps_1 = require("../../hooks/useValidateProps");
var buttons_1 = require("../button/buttons");
var dialog_1 = require("../dialog/dialog");
var icon_1 = require("../icon/icon");
/**
* Alert component.
*
* @see https://blueprintjs.com/docs/#core/components/alert
*/
var Alert = function (props) {
var cancelButtonText = props.cancelButtonText, _a = props.canEscapeKeyCancel, canEscapeKeyCancel = _a === void 0 ? false : _a, _b = props.canOutsideClickCancel, canOutsideClickCancel = _b === void 0 ? false : _b, children = props.children, className = props.className, _c = props.confirmButtonText, confirmButtonText = _c === void 0 ? "OK" : _c, icon = props.icon, intent = props.intent, _d = props.isOpen, isOpen = _d === void 0 ? false : _d, _e = props.loading, loading = _e === void 0 ? false : _e, onCancel = props.onCancel, onClose = props.onClose, onConfirm = props.onConfirm, overlayProps = tslib_1.__rest(props, ["cancelButtonText", "canEscapeKeyCancel", "canOutsideClickCancel", "children", "className", "confirmButtonText", "icon", "intent", "isOpen", "loading", "onCancel", "onClose", "onConfirm"]);
(0, useValidateProps_1.useValidateProps)(function () {
if (onClose == null && (cancelButtonText == null) !== (onCancel == null)) {
console.warn(errors_1.ALERT_WARN_CANCEL_PROPS);
}
var hasCancelHandler = onCancel != null || onClose != null;
if (canEscapeKeyCancel && !hasCancelHandler) {
console.warn(errors_1.ALERT_WARN_CANCEL_ESCAPE_KEY);
}
if (canOutsideClickCancel && !hasCancelHandler) {
console.warn(errors_1.ALERT_WARN_CANCEL_OUTSIDE_CLICK);
}
}, [canEscapeKeyCancel, canOutsideClickCancel, cancelButtonText, onCancel, onClose]);
var internalHandleCallbacks = React.useCallback(function (confirmed, event) {
var _a;
(_a = (confirmed ? onConfirm : onCancel)) === null || _a === void 0 ? void 0 : _a(event);
onClose === null || onClose === void 0 ? void 0 : onClose(confirmed, event);
}, [onCancel, onClose, onConfirm]);
var handleCancel = React.useCallback(function (event) { return internalHandleCallbacks(false, event); }, [internalHandleCallbacks]);
var handleConfirm = React.useCallback(function (event) { return internalHandleCallbacks(true, event); }, [internalHandleCallbacks]);
return (React.createElement(dialog_1.Dialog, tslib_1.__assign({}, overlayProps, { role: "alertdialog", className: (0, classnames_1.default)(common_1.Classes.ALERT, className), canEscapeKeyClose: canEscapeKeyCancel, canOutsideClickClose: canOutsideClickCancel, isOpen: isOpen, onClose: handleCancel }),
React.createElement("div", { className: common_1.Classes.ALERT_BODY },
React.createElement(icon_1.Icon, { icon: icon, size: 40, intent: intent }),
React.createElement("div", { className: common_1.Classes.ALERT_CONTENTS }, children)),
React.createElement("div", { className: common_1.Classes.ALERT_FOOTER },
React.createElement(buttons_1.Button, { loading: loading, intent: intent, text: confirmButtonText, onClick: handleConfirm }),
cancelButtonText && React.createElement(buttons_1.Button, { text: cancelButtonText, disabled: loading, onClick: handleCancel }))));
};
exports.Alert = Alert;
exports.Alert.displayName = "".concat(common_1.DISPLAYNAME_PREFIX, ".Alert");
//# sourceMappingURL=alert.js.map
;