UNPKG

2.83 kBJavaScriptView Raw
1/*
2 * Copyright 2021 Palantir Technologies, Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import { __assign } from "tslib";
17import * as React from "react";
18import { Classes, DISPLAYNAME_PREFIX } from "../../common";
19import { Button } from "../button/buttons";
20import { Text } from "../text/text";
21// eslint-disable-next-line @typescript-eslint/ban-types
22export var PanelView2 = function (props) {
23 var handleClose = React.useCallback(function () { return props.onClose(props.panel); }, [props.onClose, props.panel]);
24 var maybeBackButton = props.previousPanel === undefined ? null : (React.createElement(Button, { "aria-label": "Back", className: Classes.PANEL_STACK_HEADER_BACK, icon: "chevron-left", minimal: true, onClick: handleClose, small: true, text: props.previousPanel.title, title: props.previousPanel.htmlTitle }));
25 // `props.panel.renderPanel` is simply a function that returns a JSX.Element. It may be an FC which
26 // uses hooks. In order to avoid React errors due to inconsistent hook calls, we must encapsulate
27 // those hooks with their own lifecycle through a very simple wrapper component.
28 var PanelWrapper = React.useMemo(function () { return function () {
29 // N.B. A type cast is required because of error TS2345, where technically `panel.props` could be
30 // instantiated with a type unrelated to our generic constraint `T` here. We know
31 // we're sending the right values here though, and it makes the consumer API for this
32 // component type safe, so it's ok to do this...
33 return props.panel.renderPanel(__assign({ closePanel: handleClose, openPanel: props.onOpen }, props.panel.props));
34 }; }, [props.panel, props.onOpen]);
35 return (React.createElement("div", { className: Classes.PANEL_STACK2_VIEW },
36 props.showHeader && (React.createElement("div", { className: Classes.PANEL_STACK2_HEADER },
37 React.createElement("span", null, maybeBackButton),
38 React.createElement(Text, { className: Classes.HEADING, ellipsize: true, title: props.panel.htmlTitle }, props.panel.title),
39 React.createElement("span", null))),
40 React.createElement(PanelWrapper, null)));
41};
42PanelView2.displayName = DISPLAYNAME_PREFIX + ".PanelView2";
43//# sourceMappingURL=panelView2.js.map
\No newline at end of file