@carbon/react
Version:
React components for the Carbon Design System
64 lines (60 loc) • 1.98 kB
JavaScript
/**
* 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 cx from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';
import SideNavLinkText from './SideNavLinkText.js';
import Link from './Link.js';
import { usePrefix } from '../../internal/usePrefix.js';
const SideNavMenuItem = /*#__PURE__*/React.forwardRef(function SideNavMenuItem(props, ref) {
const prefix = usePrefix();
const {
children,
className: customClassName,
as: Component = Link,
isActive,
...rest
} = props;
const className = cx(`${prefix}--side-nav__menu-item`, customClassName);
const linkClassName = cx({
[`${prefix}--side-nav__link`]: true,
[`${prefix}--side-nav__link--current`]: isActive
});
return /*#__PURE__*/React.createElement("li", {
className: className
}, /*#__PURE__*/React.createElement(Component, _extends({}, rest, {
className: linkClassName,
ref: ref
}), /*#__PURE__*/React.createElement(SideNavLinkText, null, children)));
});
SideNavMenuItem.displayName = 'SideNavMenuItem';
SideNavMenuItem.propTypes = {
/**
* Optional component to render instead of default Link
*/
as: PropTypes.elementType,
/**
* Specify the children to be rendered inside of the `SideNavMenuItem`
*/
children: PropTypes.node,
/**
* Provide an optional class to be applied to the containing node
*/
className: PropTypes.string,
/**
* Optionally provide an href for the underlying li`
*/
href: PropTypes.string,
/**
* Optionally specify whether the link is "active". An active link is one that
* has an href that is the same as the current page. Can also pass in
* `aria-current="page"`, as well.
*/
isActive: PropTypes.bool
};
export { SideNavMenuItem as default };