UNPKG

@blueprintjs/core

Version:
80 lines 3.51 kB
/* * Copyright 2015 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. */ import * as tslib_1 from "tslib"; import classNames from "classnames"; import * as React from "react"; import { polyfill } from "react-lifecycles-compat"; import { AbstractPureComponent2, Classes } from "../../common"; import * as Errors from "../../common/errors"; import { DISPLAYNAME_PREFIX } from "../../common/props"; import { Button } from "../button/buttons"; import { H4 } from "../html/html"; import { Icon } from "../icon/icon"; import { Overlay } from "../overlay/overlay"; var Dialog = /** @class */ (function (_super) { tslib_1.__extends(Dialog, _super); function Dialog() { return _super !== null && _super.apply(this, arguments) || this; } Dialog.prototype.render = function () { return (React.createElement(Overlay, tslib_1.__assign({}, this.props, { className: Classes.OVERLAY_SCROLL_CONTAINER, hasBackdrop: true }), React.createElement("div", { className: Classes.DIALOG_CONTAINER }, React.createElement("div", { className: classNames(Classes.DIALOG, this.props.className), style: this.props.style }, this.maybeRenderHeader(), this.props.children)))); }; Dialog.prototype.validateProps = function (props) { if (props.title == null) { if (props.icon != null) { console.warn(Errors.DIALOG_WARN_NO_HEADER_ICON); } if (props.isCloseButtonShown != null) { console.warn(Errors.DIALOG_WARN_NO_HEADER_CLOSE_BUTTON); } } }; Dialog.prototype.maybeRenderCloseButton = function () { // show close button if prop is undefined or null // this gives us a behavior as if the default value were `true` if (this.props.isCloseButtonShown !== false) { return (React.createElement(Button, { "aria-label": "Close", className: Classes.DIALOG_CLOSE_BUTTON, icon: React.createElement(Icon, { icon: "small-cross", iconSize: Icon.SIZE_LARGE }), minimal: true, onClick: this.props.onClose })); } else { return undefined; } }; Dialog.prototype.maybeRenderHeader = function () { var _a = this.props, icon = _a.icon, title = _a.title; if (title == null) { return undefined; } return (React.createElement("div", { className: Classes.DIALOG_HEADER }, React.createElement(Icon, { icon: icon, iconSize: Icon.SIZE_LARGE }), React.createElement(H4, null, title), this.maybeRenderCloseButton())); }; Dialog.defaultProps = { canOutsideClickClose: true, isOpen: false, }; Dialog.displayName = DISPLAYNAME_PREFIX + ".Dialog"; Dialog = tslib_1.__decorate([ polyfill ], Dialog); return Dialog; }(AbstractPureComponent2)); export { Dialog }; //# sourceMappingURL=dialog.js.map