UNPKG

3.82 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, __decorate, __extends } from "tslib";
17import classNames from "classnames";
18import * as React from "react";
19import { polyfill } from "react-lifecycles-compat";
20import { AbstractPureComponent2, Classes } from "../../common";
21import * as Errors from "../../common/errors";
22import { DISPLAYNAME_PREFIX } from "../../common/props";
23import { uniqueId } from "../../common/utils";
24import { Button } from "../button/buttons";
25import { H4 } from "../html/html";
26import { Icon, IconSize } from "../icon/icon";
27import { Overlay } from "../overlay/overlay";
28var Dialog = /** @class */ (function (_super) {
29 __extends(Dialog, _super);
30 function Dialog(props) {
31 var _this = _super.call(this, props) || this;
32 var id = uniqueId("bp-dialog");
33 _this.titleId = "title-" + id;
34 return _this;
35 }
36 Dialog.prototype.render = function () {
37 return (React.createElement(Overlay, __assign({}, this.props, { className: Classes.OVERLAY_SCROLL_CONTAINER, hasBackdrop: true }),
38 React.createElement("div", { className: Classes.DIALOG_CONTAINER },
39 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 },
40 this.maybeRenderHeader(),
41 this.props.children))));
42 };
43 Dialog.prototype.validateProps = function (props) {
44 if (props.title == null) {
45 if (props.icon != null) {
46 console.warn(Errors.DIALOG_WARN_NO_HEADER_ICON);
47 }
48 if (props.isCloseButtonShown != null) {
49 console.warn(Errors.DIALOG_WARN_NO_HEADER_CLOSE_BUTTON);
50 }
51 }
52 };
53 Dialog.prototype.maybeRenderCloseButton = function () {
54 // show close button if prop is undefined or null
55 // this gives us a behavior as if the default value were `true`
56 if (this.props.isCloseButtonShown !== false) {
57 return (React.createElement(Button, { "aria-label": "Close", className: Classes.DIALOG_CLOSE_BUTTON, icon: React.createElement(Icon, { icon: "small-cross", size: IconSize.LARGE }), minimal: true, onClick: this.props.onClose }));
58 }
59 else {
60 return undefined;
61 }
62 };
63 Dialog.prototype.maybeRenderHeader = function () {
64 var _a = this.props, icon = _a.icon, title = _a.title;
65 if (title == null) {
66 return undefined;
67 }
68 return (React.createElement("div", { className: Classes.DIALOG_HEADER },
69 React.createElement(Icon, { icon: icon, size: IconSize.LARGE }),
70 React.createElement(H4, { id: this.titleId }, title),
71 this.maybeRenderCloseButton()));
72 };
73 Dialog.defaultProps = {
74 canOutsideClickClose: true,
75 isOpen: false,
76 };
77 Dialog.displayName = DISPLAYNAME_PREFIX + ".Dialog";
78 Dialog = __decorate([
79 polyfill
80 ], Dialog);
81 return Dialog;
82}(AbstractPureComponent2));
83export { Dialog };
84//# sourceMappingURL=dialog.js.map
\No newline at end of file