UNPKG

4.48 kBJavaScriptView Raw
1/*
2 * Copyright 2018 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 { getPositionIgnoreAngles, isPositionHorizontal } from "../../common/position";
22import { DISPLAYNAME_PREFIX } from "../../common/props";
23import { Button } from "../button/buttons";
24import { H4 } from "../html/html";
25import { Icon, IconSize } from "../icon/icon";
26import { Overlay } from "../overlay/overlay";
27export var DrawerSize;
28(function (DrawerSize) {
29 DrawerSize["SMALL"] = "360px";
30 DrawerSize["STANDARD"] = "50%";
31 DrawerSize["LARGE"] = "90%";
32})(DrawerSize || (DrawerSize = {}));
33/**
34 * Drawer component.
35 *
36 * @see https://blueprintjs.com/docs/#core/components/drawer
37 */
38var Drawer = /** @class */ (function (_super) {
39 __extends(Drawer, _super);
40 function Drawer() {
41 return _super !== null && _super.apply(this, arguments) || this;
42 }
43 Drawer.prototype.render = function () {
44 var _a, _b;
45 var _c;
46 var _d = this.props, size = _d.size, style = _d.style, position = _d.position;
47 var realPosition = getPositionIgnoreAngles(position);
48 var classes = classNames(Classes.DRAWER, (_a = {},
49 _a[(_c = Classes.positionClass(realPosition)) !== null && _c !== void 0 ? _c : ""] = true,
50 _a), this.props.className);
51 var styleProp = size == null
52 ? style
53 : __assign(__assign({}, style), (_b = {}, _b[isPositionHorizontal(realPosition) ? "height" : "width"] = size, _b));
54 return (React.createElement(Overlay, __assign({}, this.props, { className: Classes.OVERLAY_CONTAINER }),
55 React.createElement("div", { className: classes, style: styleProp },
56 this.maybeRenderHeader(),
57 this.props.children)));
58 };
59 Drawer.prototype.validateProps = function (props) {
60 if (props.title == null) {
61 if (props.icon != null) {
62 console.warn(Errors.DIALOG_WARN_NO_HEADER_ICON);
63 }
64 if (props.isCloseButtonShown != null) {
65 console.warn(Errors.DIALOG_WARN_NO_HEADER_CLOSE_BUTTON);
66 }
67 }
68 if (props.position != null) {
69 if (props.position !== getPositionIgnoreAngles(props.position)) {
70 console.warn(Errors.DRAWER_ANGLE_POSITIONS_ARE_CASTED);
71 }
72 }
73 };
74 Drawer.prototype.maybeRenderCloseButton = function () {
75 // `isCloseButtonShown` can't be defaulted through default props because of props validation
76 // so this check actually defaults it to true (fails only if directly set to false)
77 if (this.props.isCloseButtonShown !== false) {
78 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 }));
79 }
80 else {
81 return null;
82 }
83 };
84 Drawer.prototype.maybeRenderHeader = function () {
85 var _a = this.props, icon = _a.icon, title = _a.title;
86 if (title == null) {
87 return null;
88 }
89 return (React.createElement("div", { className: Classes.DRAWER_HEADER },
90 React.createElement(Icon, { icon: icon, size: IconSize.LARGE }),
91 React.createElement(H4, null, title),
92 this.maybeRenderCloseButton()));
93 };
94 Drawer.displayName = "".concat(DISPLAYNAME_PREFIX, ".Drawer");
95 Drawer.defaultProps = {
96 canOutsideClickClose: true,
97 isOpen: false,
98 position: "right",
99 style: {},
100 };
101 return Drawer;
102}(AbstractPureComponent2));
103export { Drawer };
104//# sourceMappingURL=drawer.js.map
\No newline at end of file