UNPKG

@blueprintjs/core

Version:
55 lines 2.91 kB
/* * Copyright 2015 Palantir Technologies, Inc. All rights reserved. * * Licensed under the terms of the LICENSE file distributed with this project. */ import classNames from "classnames"; import * as React from "react"; import { AbstractPureComponent, Classes, DISPLAYNAME_PREFIX } from "../../common"; import { ALERT_WARN_CANCEL_ESCAPE_KEY, ALERT_WARN_CANCEL_OUTSIDE_CLICK, ALERT_WARN_CANCEL_PROPS, } from "../../common/errors"; import { safeInvoke } from "../../common/utils"; import { Button } from "../button/buttons"; import { Dialog } from "../dialog/dialog"; import { Icon } from "../icon/icon"; export class Alert extends AbstractPureComponent { constructor() { super(...arguments); this.handleCancel = (evt) => this.internalHandleCallbacks(false, evt); this.handleConfirm = (evt) => this.internalHandleCallbacks(true, evt); } render() { const { canEscapeKeyCancel, canOutsideClickCancel, children, className, icon, intent, cancelButtonText, confirmButtonText, onClose, ...overlayProps } = this.props; return (React.createElement(Dialog, Object.assign({}, overlayProps, { className: classNames(Classes.ALERT, className), canEscapeKeyClose: canEscapeKeyCancel, canOutsideClickClose: canOutsideClickCancel, onClose: this.handleCancel, portalContainer: this.props.portalContainer }), React.createElement("div", { className: Classes.ALERT_BODY }, React.createElement(Icon, { icon: icon, iconSize: 40, intent: intent }), React.createElement("div", { className: Classes.ALERT_CONTENTS }, children)), React.createElement("div", { className: Classes.ALERT_FOOTER }, React.createElement(Button, { intent: intent, text: confirmButtonText, onClick: this.handleConfirm }), cancelButtonText && React.createElement(Button, { text: cancelButtonText, onClick: this.handleCancel })))); } validateProps(props) { if (props.onClose == null && (props.cancelButtonText == null) !== (props.onCancel == null)) { console.warn(ALERT_WARN_CANCEL_PROPS); } const hasCancelHandler = props.onCancel != null || props.onClose != null; if (props.canEscapeKeyCancel && !hasCancelHandler) { console.warn(ALERT_WARN_CANCEL_ESCAPE_KEY); } if (props.canOutsideClickCancel && !hasCancelHandler) { console.warn(ALERT_WARN_CANCEL_OUTSIDE_CLICK); } } internalHandleCallbacks(confirmed, evt) { const { onCancel, onClose, onConfirm } = this.props; safeInvoke(confirmed ? onConfirm : onCancel, evt); safeInvoke(onClose, confirmed, evt); } } Alert.defaultProps = { canEscapeKeyCancel: false, canOutsideClickCancel: false, confirmButtonText: "OK", isOpen: false, }; Alert.displayName = `${DISPLAYNAME_PREFIX}.Alert`; //# sourceMappingURL=alert.js.map