UNPKG

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