UNPKG

4.82 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright 2018 Palantir Technologies, Inc. All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17Object.defineProperty(exports, "__esModule", { value: true });
18exports.Drawer = exports.DrawerSize = void 0;
19var tslib_1 = require("tslib");
20var classnames_1 = tslib_1.__importDefault(require("classnames"));
21var React = tslib_1.__importStar(require("react"));
22var common_1 = require("../../common");
23var Errors = tslib_1.__importStar(require("../../common/errors"));
24var position_1 = require("../../common/position");
25var props_1 = require("../../common/props");
26var buttons_1 = require("../button/buttons");
27var html_1 = require("../html/html");
28var icon_1 = require("../icon/icon");
29var overlay_1 = require("../overlay/overlay");
30var DrawerSize;
31(function (DrawerSize) {
32 DrawerSize["SMALL"] = "360px";
33 DrawerSize["STANDARD"] = "50%";
34 DrawerSize["LARGE"] = "90%";
35})(DrawerSize = exports.DrawerSize || (exports.DrawerSize = {}));
36/**
37 * Drawer component.
38 *
39 * @see https://blueprintjs.com/docs/#core/components/drawer
40 */
41var Drawer = /** @class */ (function (_super) {
42 tslib_1.__extends(Drawer, _super);
43 function Drawer() {
44 return _super !== null && _super.apply(this, arguments) || this;
45 }
46 Drawer.prototype.render = function () {
47 var _a, _b;
48 var _c;
49 var _d = this.props, size = _d.size, style = _d.style, position = _d.position;
50 var realPosition = (0, position_1.getPositionIgnoreAngles)(position);
51 var classes = (0, classnames_1.default)(common_1.Classes.DRAWER, (_a = {},
52 _a[(_c = common_1.Classes.positionClass(realPosition)) !== null && _c !== void 0 ? _c : ""] = true,
53 _a), this.props.className);
54 var styleProp = size == null
55 ? style
56 : tslib_1.__assign(tslib_1.__assign({}, style), (_b = {}, _b[(0, position_1.isPositionHorizontal)(realPosition) ? "height" : "width"] = size, _b));
57 return (React.createElement(overlay_1.Overlay, tslib_1.__assign({}, this.props, { className: common_1.Classes.OVERLAY_CONTAINER }),
58 React.createElement("div", { className: classes, style: styleProp },
59 this.maybeRenderHeader(),
60 this.props.children)));
61 };
62 Drawer.prototype.validateProps = function (props) {
63 if (props.title == null) {
64 if (props.icon != null) {
65 console.warn(Errors.DIALOG_WARN_NO_HEADER_ICON);
66 }
67 if (props.isCloseButtonShown != null) {
68 console.warn(Errors.DIALOG_WARN_NO_HEADER_CLOSE_BUTTON);
69 }
70 }
71 if (props.position != null) {
72 if (props.position !== (0, position_1.getPositionIgnoreAngles)(props.position)) {
73 console.warn(Errors.DRAWER_ANGLE_POSITIONS_ARE_CASTED);
74 }
75 }
76 };
77 Drawer.prototype.maybeRenderCloseButton = function () {
78 // `isCloseButtonShown` can't be defaulted through default props because of props validation
79 // so this check actually defaults it to true (fails only if directly set to false)
80 if (this.props.isCloseButtonShown !== false) {
81 return (React.createElement(buttons_1.Button, { "aria-label": "Close", className: common_1.Classes.DIALOG_CLOSE_BUTTON, icon: React.createElement(icon_1.Icon, { icon: "small-cross", size: icon_1.IconSize.LARGE }), minimal: true, onClick: this.props.onClose }));
82 }
83 else {
84 return null;
85 }
86 };
87 Drawer.prototype.maybeRenderHeader = function () {
88 var _a = this.props, icon = _a.icon, title = _a.title;
89 if (title == null) {
90 return null;
91 }
92 return (React.createElement("div", { className: common_1.Classes.DRAWER_HEADER },
93 React.createElement(icon_1.Icon, { icon: icon, size: icon_1.IconSize.LARGE }),
94 React.createElement(html_1.H4, null, title),
95 this.maybeRenderCloseButton()));
96 };
97 Drawer.displayName = "".concat(props_1.DISPLAYNAME_PREFIX, ".Drawer");
98 Drawer.defaultProps = {
99 canOutsideClickClose: true,
100 isOpen: false,
101 position: "right",
102 style: {},
103 };
104 return Drawer;
105}(common_1.AbstractPureComponent2));
106exports.Drawer = Drawer;
107//# sourceMappingURL=drawer.js.map
\No newline at end of file