1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | import { __assign, __extends } from "tslib";
|
17 | import classNames from "classnames";
|
18 | import * as React from "react";
|
19 | import { AbstractPureComponent2, Classes } from "../../common";
|
20 | import * as Errors from "../../common/errors";
|
21 | import { getPositionIgnoreAngles, isPositionHorizontal } from "../../common/position";
|
22 | import { DISPLAYNAME_PREFIX } from "../../common/props";
|
23 | import { Button } from "../button/buttons";
|
24 | import { H4 } from "../html/html";
|
25 | import { Icon, IconSize } from "../icon/icon";
|
26 | import { Overlay } from "../overlay/overlay";
|
27 | export var DrawerSize;
|
28 | (function (DrawerSize) {
|
29 | DrawerSize["SMALL"] = "360px";
|
30 | DrawerSize["STANDARD"] = "50%";
|
31 | DrawerSize["LARGE"] = "90%";
|
32 | })(DrawerSize || (DrawerSize = {}));
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | var Drawer = (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 |
|
76 |
|
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));
|
103 | export { Drawer };
|
104 |
|
\ | No newline at end of file |