UNPKG

@carbon/react

Version:

React components for the Carbon Design System

99 lines (93 loc) 3.48 kB
/** * Copyright IBM Corp. 2016, 2023 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js'); var PropTypes = require('prop-types'); var React = require('react'); var cx = require('classnames'); var Link = require('../Link/Link.js'); var iconsReact = require('@carbon/icons-react'); var usePrefix = require('../../internal/usePrefix.js'); var Text = require('../Text/Text.js'); require('../Text/TextDirection.js'); const frFn = React.forwardRef; const BreadcrumbItem = frFn((props, ref) => { const { 'aria-current': ariaCurrent, children, className: customClassName = '', href, isCurrentPage, ...rest } = props; const prefix = usePrefix.usePrefix(); const className = cx({ [`${prefix}--breadcrumb-item`]: true, // We set the current class only if `isCurrentPage` is passed in and we do // not have an `aria-current="page"` set for the breadcrumb item [`${prefix}--breadcrumb-item--current`]: isCurrentPage && ariaCurrent !== 'page', [customClassName]: !!customClassName }); const child = /*#__PURE__*/React.isValidElement(children) ? children : null; const childType = child?.type; if (child && typeof child.type !== 'string' && childType?.displayName?.includes('OverflowMenu')) { const horizontalOverflowIcon = /*#__PURE__*/React.createElement(iconsReact.OverflowMenuHorizontal, { className: `${prefix}--overflow-menu__icon` }); return /*#__PURE__*/React.createElement("li", _rollupPluginBabelHelpers.extends({ className: className }, rest), /*#__PURE__*/React.cloneElement(child, { menuOptionsClass: `${prefix}--breadcrumb-menu-options`, menuOffset: { top: 10, left: 59 }, renderIcon: () => horizontalOverflowIcon })); } if (typeof children === 'string') { return /*#__PURE__*/React.createElement("li", _rollupPluginBabelHelpers.extends({ className: className, ref: ref }, rest), href ? /*#__PURE__*/React.createElement(Link.default, { href: href, "aria-current": ariaCurrent || isCurrentPage }, children) : /*#__PURE__*/React.createElement(Text.Text, { "aria-current": ariaCurrent || isCurrentPage, className: `${prefix}--link` }, children)); } return /*#__PURE__*/React.createElement("li", _rollupPluginBabelHelpers.extends({ className: className, ref: ref }, rest), child ? /*#__PURE__*/React.cloneElement(child, { 'aria-current': ariaCurrent, className: cx(`${prefix}--link`, child.props.className) }) : children); }); BreadcrumbItem.displayName = 'BreadcrumbItem'; BreadcrumbItem.propTypes = { 'aria-current': PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf(['false', 'true', 'page', 'step', 'location', 'date', 'time'])]), /** * Pass in content that will be inside of the BreadcrumbItem */ children: PropTypes.node, /** * Specify an optional className to be applied to the container node */ className: PropTypes.string, /** * Optional string representing the link location for the BreadcrumbItem */ href: PropTypes.string, /** * Provide if this breadcrumb item represents the current page */ isCurrentPage: PropTypes.bool }; exports.default = BreadcrumbItem;