UNPKG

3.87 kBJavaScriptView Raw
1/*
2 * Copyright 2015 Palantir Technologies, Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import { __assign, __extends } from "tslib";
17import classNames from "classnames";
18import * as React from "react";
19import { AbstractPureComponent2, Classes } from "../../common";
20import * as Errors from "../../common/errors";
21import { DISPLAYNAME_PREFIX } from "../../common/props";
22import { uniqueId } from "../../common/utils";
23import { Button } from "../button/buttons";
24import { H6 } from "../html/html";
25import { Icon, IconSize } from "../icon/icon";
26import { Overlay } from "../overlay/overlay";
27/**
28 * Dialog component.
29 *
30 * @see https://blueprintjs.com/docs/#core/components/dialog
31 */
32var Dialog = /** @class */ (function (_super) {
33 __extends(Dialog, _super);
34 function Dialog(props) {
35 var _this = _super.call(this, props) || this;
36 var id = uniqueId("bp-dialog");
37 _this.titleId = "title-".concat(id);
38 return _this;
39 }
40 Dialog.prototype.render = function () {
41 return (React.createElement(Overlay, __assign({}, this.props, { className: Classes.OVERLAY_SCROLL_CONTAINER, hasBackdrop: true }),
42 React.createElement("div", { className: Classes.DIALOG_CONTAINER, ref: this.props.containerRef },
43 React.createElement("div", { className: classNames(Classes.DIALOG, this.props.className), role: "dialog", "aria-labelledby": this.props["aria-labelledby"] || (this.props.title ? this.titleId : undefined), "aria-describedby": this.props["aria-describedby"], style: this.props.style },
44 this.maybeRenderHeader(),
45 this.props.children))));
46 };
47 Dialog.prototype.validateProps = function (props) {
48 if (props.title == null) {
49 if (props.icon != null) {
50 console.warn(Errors.DIALOG_WARN_NO_HEADER_ICON);
51 }
52 if (props.isCloseButtonShown != null) {
53 console.warn(Errors.DIALOG_WARN_NO_HEADER_CLOSE_BUTTON);
54 }
55 }
56 };
57 Dialog.prototype.maybeRenderCloseButton = function () {
58 // show close button if prop is undefined or null
59 // this gives us a behavior as if the default value were `true`
60 if (this.props.isCloseButtonShown !== false) {
61 return (React.createElement(Button, { "aria-label": "Close", className: Classes.DIALOG_CLOSE_BUTTON, icon: React.createElement(Icon, { icon: "cross", size: IconSize.STANDARD }), minimal: true, onClick: this.props.onClose }));
62 }
63 else {
64 return undefined;
65 }
66 };
67 Dialog.prototype.maybeRenderHeader = function () {
68 var _a = this.props, icon = _a.icon, title = _a.title;
69 if (title == null) {
70 return undefined;
71 }
72 return (React.createElement("div", { className: Classes.DIALOG_HEADER },
73 React.createElement(Icon, { icon: icon, size: IconSize.STANDARD, "aria-hidden": true, tabIndex: -1 }),
74 React.createElement(H6, { id: this.titleId }, title),
75 this.maybeRenderCloseButton()));
76 };
77 Dialog.defaultProps = {
78 canOutsideClickClose: true,
79 isOpen: false,
80 };
81 Dialog.displayName = "".concat(DISPLAYNAME_PREFIX, ".Dialog");
82 return Dialog;
83}(AbstractPureComponent2));
84export { Dialog };
85//# sourceMappingURL=dialog.js.map
\No newline at end of file