@blueprintjs/core
Version:
Core styles & components
81 lines • 4.48 kB
JavaScript
/*
* Copyright 2022 Palantir Technologies, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Breadcrumbs = void 0;
const tslib_1 = require("tslib");
const classnames_1 = tslib_1.__importDefault(require("classnames"));
const React = tslib_1.__importStar(require("react"));
const common_1 = require("../../common");
const menu_1 = require("../menu/menu");
const menuItem_1 = require("../menu/menuItem");
const overflowList_1 = require("../overflow-list/overflowList");
const popover_1 = require("../popover/popover");
const breadcrumb_1 = require("./breadcrumb");
/**
* Breadcrumbs component.
*
* @see https://blueprintjs.com/docs/#core/components/breadcrumbs
*/
class Breadcrumbs extends common_1.AbstractPureComponent {
constructor() {
super(...arguments);
this.renderOverflow = (items) => {
const { collapseFrom, overflowButtonProps, popoverProps } = this.props;
let orderedItems = items;
if (collapseFrom === common_1.Boundary.START) {
// If we're collapsing from the start, the menu should be read from the bottom to the
// top, continuing with the breadcrumbs to the right. Since this means the first
// breadcrumb in the props must be the last in the menu, we need to reverse the overlow
// order.
orderedItems = items.slice().reverse();
}
return (React.createElement("li", null,
React.createElement(popover_1.Popover, { placement: collapseFrom === common_1.Boundary.END ? "bottom-end" : "bottom-start", disabled: orderedItems.length === 0, content: React.createElement(menu_1.Menu, null, orderedItems.map(this.renderOverflowBreadcrumb)), ...popoverProps },
React.createElement("span", { "aria-label": "collapsed breadcrumbs", role: "button", tabIndex: 0, ...overflowButtonProps, className: (0, classnames_1.default)(common_1.Classes.BREADCRUMBS_COLLAPSED, overflowButtonProps === null || overflowButtonProps === void 0 ? void 0 : overflowButtonProps.className) }))));
};
this.renderOverflowBreadcrumb = (props, index) => {
const isClickable = props.href != null || props.onClick != null;
const htmlProps = (0, common_1.removeNonHTMLProps)(props);
return React.createElement(menuItem_1.MenuItem, { disabled: !isClickable, ...htmlProps, text: props.text, key: index });
};
this.renderBreadcrumbWrapper = (props, index) => {
const isCurrent = this.props.items[this.props.items.length - 1] === props;
return React.createElement("li", { key: index }, this.renderBreadcrumb(props, isCurrent));
};
}
render() {
const { className, collapseFrom, items, minVisibleItems, overflowListProps = {} } = this.props;
return (React.createElement(overflowList_1.OverflowList, { collapseFrom: collapseFrom, minVisibleItems: minVisibleItems, tagName: "ol", ...overflowListProps, className: (0, classnames_1.default)(common_1.Classes.BREADCRUMBS, overflowListProps.className, className), items: items, overflowRenderer: this.renderOverflow, visibleItemRenderer: this.renderBreadcrumbWrapper }));
}
renderBreadcrumb(props, isCurrent) {
if (isCurrent && this.props.currentBreadcrumbRenderer != null) {
return this.props.currentBreadcrumbRenderer(props);
}
else if (this.props.breadcrumbRenderer != null) {
return this.props.breadcrumbRenderer(props);
}
else {
// allow user to override 'current' prop
return React.createElement(breadcrumb_1.Breadcrumb, { current: isCurrent, ...props });
}
}
}
exports.Breadcrumbs = Breadcrumbs;
Breadcrumbs.defaultProps = {
collapseFrom: common_1.Boundary.START,
};
//# sourceMappingURL=breadcrumbs.js.map
;