@carbon/react
Version:
React components for the Carbon Design System
68 lines (62 loc) • 2.1 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.
*/
;
Object.defineProperty(exports, '__esModule', { value: true });
var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
var cx = require('classnames');
var PropTypes = require('prop-types');
var React = require('react');
var SideNavLinkText = require('./SideNavLinkText.js');
var Link = require('./Link.js');
var usePrefix = require('../../internal/usePrefix.js');
const SideNavMenuItem = /*#__PURE__*/React.forwardRef((props, ref) => {
const prefix = usePrefix.usePrefix();
const {
children,
className: customClassName,
as: Component = Link.default,
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, _rollupPluginBabelHelpers.extends({}, rest, {
className: linkClassName,
ref: ref
}), /*#__PURE__*/React.createElement(SideNavLinkText.default, 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
};
exports.default = SideNavMenuItem;