UNPKG

3.05 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright 2021 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.PanelView2 = void 0;
19var tslib_1 = require("tslib");
20var React = tslib_1.__importStar(require("react"));
21var common_1 = require("../../common");
22var buttons_1 = require("../button/buttons");
23var text_1 = require("../text/text");
24// eslint-disable-next-line @typescript-eslint/ban-types
25var PanelView2 = function (props) {
26 var handleClose = React.useCallback(function () { return props.onClose(props.panel); }, [props.onClose, props.panel]);
27 var maybeBackButton = props.previousPanel === undefined ? null : (React.createElement(buttons_1.Button, { "aria-label": "Back", className: common_1.Classes.PANEL_STACK_HEADER_BACK, icon: "chevron-left", minimal: true, onClick: handleClose, small: true, text: props.previousPanel.title, title: props.previousPanel.htmlTitle }));
28 // `props.panel.renderPanel` is simply a function that returns a JSX.Element. It may be an FC which
29 // uses hooks. In order to avoid React errors due to inconsistent hook calls, we must encapsulate
30 // those hooks with their own lifecycle through a very simple wrapper component.
31 var PanelWrapper = React.useMemo(function () { return function () {
32 // N.B. A type cast is required because of error TS2345, where technically `panel.props` could be
33 // instantiated with a type unrelated to our generic constraint `T` here. We know
34 // we're sending the right values here though, and it makes the consumer API for this
35 // component type safe, so it's ok to do this...
36 return props.panel.renderPanel(tslib_1.__assign({ closePanel: handleClose, openPanel: props.onOpen }, props.panel.props));
37 }; }, [props.panel, props.onOpen]);
38 return (React.createElement("div", { className: common_1.Classes.PANEL_STACK2_VIEW },
39 props.showHeader && (React.createElement("div", { className: common_1.Classes.PANEL_STACK2_HEADER },
40 React.createElement("span", null, maybeBackButton),
41 React.createElement(text_1.Text, { className: common_1.Classes.HEADING, ellipsize: true, title: props.panel.htmlTitle }, props.panel.title),
42 React.createElement("span", null))),
43 React.createElement(PanelWrapper, null)));
44};
45exports.PanelView2 = PanelView2;
46exports.PanelView2.displayName = "".concat(common_1.DISPLAYNAME_PREFIX, ".PanelView2");
47//# sourceMappingURL=panelView2.js.map
\No newline at end of file