UNPKG

@carbon/react

Version:

React components for the Carbon Design System

62 lines (60 loc) 2.25 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 Link, { LinkPropTypes } from "./Link.js"; import { SideNavContext } from "./SideNavContext.js"; import SideNavIcon from "./SideNavIcon.js"; import SideNavItem from "./SideNavItem.js"; import SideNavLinkText from "./SideNavLinkText.js"; import classNames from "classnames"; import { forwardRef, useContext } from "react"; import PropTypes from "prop-types"; import { jsx, jsxs } from "react/jsx-runtime"; //#region src/components/UIShell/SideNavLink.tsx /** * 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. */ const SideNavLink = forwardRef((props, ref) => { const { children, className: customClassName, renderIcon: IconElement, isActive, isSideNavExpanded, large = false, tabIndex, ...rest } = props; const { isRail, isSideNavExpanded: contextIsSideNavExpanded } = useContext(SideNavContext); const currentIsSideNavExpanded = isSideNavExpanded ?? contextIsSideNavExpanded; const prefix = usePrefix(); const className = classNames({ [`${prefix}--side-nav__link`]: true, [`${prefix}--side-nav__link--current`]: isActive, [customClassName]: !!customClassName }); return /* @__PURE__ */ jsx(SideNavItem, { large, children: /* @__PURE__ */ jsxs(Link, { ...rest, className, ref, tabIndex: tabIndex === void 0 ? !currentIsSideNavExpanded && !isRail ? -1 : 0 : tabIndex, children: [IconElement && /* @__PURE__ */ jsx(SideNavIcon, { small: true, children: /* @__PURE__ */ jsx(IconElement, {}) }), /* @__PURE__ */ jsx(SideNavLinkText, { children })] }) }); }); SideNavLink.displayName = "SideNavLink"; SideNavLink.propTypes = { ...LinkPropTypes, children: PropTypes.node.isRequired, className: PropTypes.string, isActive: PropTypes.bool, isSideNavExpanded: PropTypes.bool, large: PropTypes.bool, renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), tabIndex: PropTypes.number }; //#endregion export { SideNavLink as default };