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