UNPKG

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