1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.PanelStack = void 0;
|
19 | var tslib_1 = require("tslib");
|
20 | var classnames_1 = tslib_1.__importDefault(require("classnames"));
|
21 | var React = tslib_1.__importStar(require("react"));
|
22 | var react_transition_group_1 = require("react-transition-group");
|
23 | var common_1 = require("../../common");
|
24 | var Errors = tslib_1.__importStar(require("../../common/errors"));
|
25 | var panelView_1 = require("./panelView");
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | var PanelStack = (function (_super) {
|
33 | tslib_1.__extends(PanelStack, _super);
|
34 | function PanelStack() {
|
35 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
36 | _this.state = {
|
37 | direction: "push",
|
38 | stack: _this.props.stack != null
|
39 | ? _this.props.stack.slice().reverse()
|
40 | : _this.props.initialPanel !== undefined
|
41 | ? [_this.props.initialPanel]
|
42 | : [],
|
43 | };
|
44 | _this.renderPanel = function (panel, index) {
|
45 | var _a = _this.props, renderActivePanelOnly = _a.renderActivePanelOnly, _b = _a.showPanelHeader, showPanelHeader = _b === void 0 ? true : _b;
|
46 | var stack = _this.state.stack;
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 | var layer = stack.length - index;
|
54 | var key = renderActivePanelOnly ? stack.length : layer;
|
55 | return (React.createElement(react_transition_group_1.CSSTransition, { classNames: common_1.Classes.PANEL_STACK, key: key, timeout: 400 },
|
56 | React.createElement(panelView_1.PanelView, { onClose: _this.handlePanelClose, onOpen: _this.handlePanelOpen, panel: panel, previousPanel: stack[index + 1], showHeader: showPanelHeader })));
|
57 | };
|
58 | _this.handlePanelClose = function (panel) {
|
59 | var _a, _b;
|
60 | var stack = _this.state.stack;
|
61 |
|
62 | if (stack[0] !== panel || stack.length <= 1) {
|
63 | return;
|
64 | }
|
65 | (_b = (_a = _this.props).onClose) === null || _b === void 0 ? void 0 : _b.call(_a, panel);
|
66 | if (_this.props.stack == null) {
|
67 | _this.setState(function (state) { return ({
|
68 | direction: "pop",
|
69 | stack: state.stack.slice(1),
|
70 | }); });
|
71 | }
|
72 | };
|
73 | _this.handlePanelOpen = function (panel) {
|
74 | var _a, _b;
|
75 | (_b = (_a = _this.props).onOpen) === null || _b === void 0 ? void 0 : _b.call(_a, panel);
|
76 | if (_this.props.stack == null) {
|
77 | _this.setState(function (state) { return ({
|
78 | direction: "push",
|
79 | stack: tslib_1.__spreadArray([panel], state.stack, true),
|
80 | }); });
|
81 | }
|
82 | };
|
83 | return _this;
|
84 | }
|
85 | PanelStack.prototype.componentDidUpdate = function (prevProps, prevState) {
|
86 | _super.prototype.componentDidUpdate.call(this, prevProps, prevState);
|
87 |
|
88 | if (this.props.stack !== prevProps.stack && prevProps.stack != null) {
|
89 | this.setState({ stack: this.props.stack.slice().reverse() });
|
90 | }
|
91 |
|
92 | var stackLength = this.props.stack != null ? this.props.stack.length : 0;
|
93 | var prevStackLength = prevProps.stack != null ? prevProps.stack.length : 0;
|
94 | if (stackLength !== prevStackLength && prevProps.stack != null) {
|
95 | this.setState({
|
96 | direction: prevProps.stack.length - this.props.stack.length < 0 ? "push" : "pop",
|
97 | });
|
98 | }
|
99 | };
|
100 | PanelStack.prototype.render = function () {
|
101 | var classes = (0, classnames_1.default)(common_1.Classes.PANEL_STACK, "".concat(common_1.Classes.PANEL_STACK, "-").concat(this.state.direction), this.props.className);
|
102 | return (React.createElement(react_transition_group_1.TransitionGroup, { className: classes, component: "div" }, this.renderPanels()));
|
103 | };
|
104 | PanelStack.prototype.validateProps = function (props) {
|
105 | if ((props.initialPanel == null && props.stack == null) ||
|
106 | (props.initialPanel != null && props.stack != null)) {
|
107 | console.error(Errors.PANEL_STACK_INITIAL_PANEL_STACK_MUTEX);
|
108 | }
|
109 | if (props.stack != null && props.stack.length === 0) {
|
110 | console.error(Errors.PANEL_STACK_REQUIRES_PANEL);
|
111 | }
|
112 | };
|
113 | PanelStack.prototype.renderPanels = function () {
|
114 | var _a = this.props.renderActivePanelOnly, renderActivePanelOnly = _a === void 0 ? true : _a;
|
115 | var stack = this.state.stack;
|
116 | if (stack.length === 0) {
|
117 | return null;
|
118 | }
|
119 | var panelsToRender = renderActivePanelOnly ? [stack[0]] : stack;
|
120 | var panelViews = panelsToRender.map(this.renderPanel).reverse();
|
121 | return panelViews;
|
122 | };
|
123 | return PanelStack;
|
124 | }(common_1.AbstractPureComponent2));
|
125 | exports.PanelStack = PanelStack;
|
126 |
|
\ | No newline at end of file |