UNPKG

@carbon/react

Version:

React components for the Carbon Design System

59 lines (57 loc) 2.06 kB
/** * Copyright IBM Corp. 2016, 2026 * * 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 { usePrefix } from "../../internal/usePrefix.js"; import { deprecate } from "../../prop-types/deprecate.js"; import Link, { LinkPropTypes } from "./Link.js"; import classNames from "classnames"; import { forwardRef } from "react"; import PropTypes from "prop-types"; import { jsx } from "react/jsx-runtime"; //#region src/components/UIShell/HeaderMenuItem.tsx /** * Copyright IBM Corp. 2016, 2025 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ const HeaderMenuItem = forwardRef(function HeaderMenuItem({ className, isActive, isCurrentPage, "aria-current": ariaCurrent, children, role, tabIndex, ...rest }, ref) { const prefix = usePrefix(); const resolvedTabIndex = tabIndex ?? 0; if (isCurrentPage) isActive = isCurrentPage; const hasCurrentClass = isActive && ariaCurrent !== "page"; const linkClassName = classNames({ [`${prefix}--header__menu-item`]: true, [`${prefix}--header__menu-item--current`]: hasCurrentClass }); return /* @__PURE__ */ jsx("li", { className, role, children: /* @__PURE__ */ jsx(Link, { ...rest, "aria-current": hasCurrentClass ? true : ariaCurrent, className: linkClassName, ref, tabIndex: resolvedTabIndex, children: /* @__PURE__ */ jsx("span", { className: `${prefix}--text-truncate--end`, children }) }) }); }); HeaderMenuItem.displayName = "HeaderMenuItem"; HeaderMenuItem.propTypes = { ...LinkPropTypes, children: PropTypes.node.isRequired, className: PropTypes.string, isActive: PropTypes.bool, isCurrentPage: deprecate(PropTypes.bool, "The `isCurrentPage` prop for `HeaderMenuItem` has been deprecated. Please use `isActive` instead. This will be removed in the next major release."), role: PropTypes.string, tabIndex: PropTypes.number }; //#endregion export { HeaderMenuItem as default };