UNPKG

3.75 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 { H5 } from "../html/html";
25import { Icon, IconSize } from "../icon/icon";
26import { Overlay } from "../overlay/overlay";
27var Dialog = /** @class */ (function (_super) {
28 __extends(Dialog, _super);
29 function Dialog(props) {
30 var _this = _super.call(this, props) || this;
31 var id = uniqueId("bp-dialog");
32 _this.titleId = "title-".concat(id);
33 return _this;
34 }
35 Dialog.prototype.render = function () {
36 return (React.createElement(Overlay, __assign({}, this.props, { className: Classes.OVERLAY_SCROLL_CONTAINER, hasBackdrop: true }),
37 React.createElement("div", { className: Classes.DIALOG_CONTAINER },
38 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 },
39 this.maybeRenderHeader(),
40 this.props.children))));
41 };
42 Dialog.prototype.validateProps = function (props) {
43 if (props.title == null) {
44 if (props.icon != null) {
45 console.warn(Errors.DIALOG_WARN_NO_HEADER_ICON);
46 }
47 if (props.isCloseButtonShown != null) {
48 console.warn(Errors.DIALOG_WARN_NO_HEADER_CLOSE_BUTTON);
49 }
50 }
51 };
52 Dialog.prototype.maybeRenderCloseButton = function () {
53 // show close button if prop is undefined or null
54 // this gives us a behavior as if the default value were `true`
55 if (this.props.isCloseButtonShown !== false) {
56 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 }));
57 }
58 else {
59 return undefined;
60 }
61 };
62 Dialog.prototype.maybeRenderHeader = function () {
63 var _a = this.props, icon = _a.icon, title = _a.title;
64 if (title == null) {
65 return undefined;
66 }
67 return (React.createElement("div", { className: Classes.DIALOG_HEADER },
68 React.createElement(Icon, { icon: icon, size: IconSize.STANDARD, "aria-hidden": true, tabIndex: -1 }),
69 React.createElement(H5, { id: this.titleId }, title),
70 this.maybeRenderCloseButton()));
71 };
72 Dialog.defaultProps = {
73 canOutsideClickClose: true,
74 isOpen: false,
75 };
76 Dialog.displayName = "".concat(DISPLAYNAME_PREFIX, ".Dialog");
77 return Dialog;
78}(AbstractPureComponent2));
79export { Dialog };
80//# sourceMappingURL=dialog.js.map
\No newline at end of file