UNPKG

@carbon/react

Version:

React components for the Carbon Design System

94 lines (90 loc) 3.2 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. */ import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js'; import PropTypes from 'prop-types'; import React, { forwardRef } from 'react'; import cx from 'classnames'; import Link from '../Link/Link.js'; import { OverflowMenuHorizontal } from '@carbon/icons-react'; import { usePrefix } from '../../internal/usePrefix.js'; import '../Text/index.js'; import { Text } from '../Text/Text.js'; const frFn = forwardRef; const BreadcrumbItem = frFn((props, ref) => { const { 'aria-current': ariaCurrent, children, className: customClassName = '', href, isCurrentPage, ...rest } = props; const prefix = 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 = children; if (child.type && child.type.displayName !== undefined && child.type.displayName.includes('OverflowMenu')) { const horizontalOverflowIcon = /*#__PURE__*/React.createElement(OverflowMenuHorizontal, { className: `${prefix}--overflow-menu__icon` }); return /*#__PURE__*/React.createElement("li", _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", _extends({ className: className, ref: ref }, rest), href ? /*#__PURE__*/React.createElement(Link, { href: href, "aria-current": ariaCurrent || isCurrentPage }, children) : /*#__PURE__*/React.createElement(Text, { "aria-current": ariaCurrent || isCurrentPage, className: `${prefix}--link` }, children)); } return /*#__PURE__*/React.createElement("li", _extends({ className: className, ref: ref }, rest), /*#__PURE__*/React.cloneElement(child, { 'aria-current': ariaCurrent, className: cx(`${prefix}--link`, child.props.className) })); }); 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 }; export { BreadcrumbItem as default };