UNPKG

4.6 kBJavaScriptView Raw
1/*
2 * Copyright 2018 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, __decorate, __extends } from "tslib";
17import classNames from "classnames";
18import * as React from "react";
19import { polyfill } from "react-lifecycles-compat";
20import { AbstractPureComponent2, Boundary, Classes, Position, removeNonHTMLProps } from "../../common";
21import { Menu } from "../menu/menu";
22import { MenuItem } from "../menu/menuItem";
23import { OverflowList } from "../overflow-list/overflowList";
24import { Popover } from "../popover/popover";
25import { Breadcrumb } from "./breadcrumb";
26var Breadcrumbs = /** @class */ (function (_super) {
27 __extends(Breadcrumbs, _super);
28 function Breadcrumbs() {
29 var _this = _super !== null && _super.apply(this, arguments) || this;
30 _this.renderOverflow = function (items) {
31 var collapseFrom = _this.props.collapseFrom;
32 var position = collapseFrom === Boundary.END ? Position.BOTTOM_RIGHT : Position.BOTTOM_LEFT;
33 var orderedItems = items;
34 if (collapseFrom === Boundary.START) {
35 // If we're collapsing from the start, the menu should be read from the bottom to the
36 // top, continuing with the breadcrumbs to the right. Since this means the first
37 // breadcrumb in the props must be the last in the menu, we need to reverse the overlow
38 // order.
39 orderedItems = items.slice().reverse();
40 }
41 /* eslint-disable deprecation/deprecation */
42 return (React.createElement("li", null,
43 React.createElement(Popover, __assign({ position: position, disabled: orderedItems.length === 0, content: React.createElement(Menu, null, orderedItems.map(_this.renderOverflowBreadcrumb)) }, _this.props.popoverProps),
44 React.createElement("span", { className: Classes.BREADCRUMBS_COLLAPSED }))));
45 /* eslint-enable deprecation/deprecation */
46 };
47 _this.renderOverflowBreadcrumb = function (props, index) {
48 var isClickable = props.href != null || props.onClick != null;
49 var htmlProps = removeNonHTMLProps(props);
50 return React.createElement(MenuItem, __assign({ disabled: !isClickable }, htmlProps, { text: props.text, key: index }));
51 };
52 _this.renderBreadcrumbWrapper = function (props, index) {
53 var isCurrent = _this.props.items[_this.props.items.length - 1] === props;
54 return React.createElement("li", { key: index }, _this.renderBreadcrumb(props, isCurrent));
55 };
56 return _this;
57 }
58 Breadcrumbs.prototype.render = function () {
59 var _a = this.props, className = _a.className, collapseFrom = _a.collapseFrom, items = _a.items, minVisibleItems = _a.minVisibleItems, _b = _a.overflowListProps, overflowListProps = _b === void 0 ? {} : _b;
60 return (React.createElement(OverflowList, __assign({ collapseFrom: collapseFrom, minVisibleItems: minVisibleItems, tagName: "ul" }, overflowListProps, { className: classNames(Classes.BREADCRUMBS, overflowListProps.className, className), items: items, overflowRenderer: this.renderOverflow, visibleItemRenderer: this.renderBreadcrumbWrapper })));
61 };
62 Breadcrumbs.prototype.renderBreadcrumb = function (props, isCurrent) {
63 if (isCurrent && this.props.currentBreadcrumbRenderer != null) {
64 return this.props.currentBreadcrumbRenderer(props);
65 }
66 else if (this.props.breadcrumbRenderer != null) {
67 return this.props.breadcrumbRenderer(props);
68 }
69 else {
70 // allow user to override 'current' prop
71 return React.createElement(Breadcrumb, __assign({ current: isCurrent }, props));
72 }
73 };
74 Breadcrumbs.defaultProps = {
75 collapseFrom: Boundary.START,
76 };
77 Breadcrumbs = __decorate([
78 polyfill
79 ], Breadcrumbs);
80 return Breadcrumbs;
81}(AbstractPureComponent2));
82export { Breadcrumbs };
83//# sourceMappingURL=breadcrumbs.js.map
\No newline at end of file