UNPKG

@carbon/react

Version:

React components for the Carbon Design System

65 lines (57 loc) 2.25 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. */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var cx = require('classnames'); var PropTypes = require('prop-types'); var React = require('react'); var _utils = require('./_utils.js'); var usePrefix = require('../../internal/usePrefix.js'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx); var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes); var React__default = /*#__PURE__*/_interopDefaultLegacy(React); const SideNavItems = ({ className: customClassName, children, isSideNavExpanded }) => { const prefix = usePrefix.usePrefix(); const className = cx__default["default"]([`${prefix}--side-nav__items`], customClassName); const childrenWithExpandedState = React__default["default"].Children.map(children, child => { if (/*#__PURE__*/React__default["default"].isValidElement(child)) { // avoid spreading `isSideNavExpanded` to non-Carbon UI Shell children const childDisplayName = child.type?.displayName; return /*#__PURE__*/React__default["default"].cloneElement(child, { ...(_utils.CARBON_SIDENAV_ITEMS.includes(childDisplayName) ? { isSideNavExpanded } : {}) }); } }); return /*#__PURE__*/React__default["default"].createElement("ul", { className: className }, childrenWithExpandedState); }; SideNavItems.displayName = 'SideNavItems'; SideNavItems.propTypes = { /** * Provide a single icon as the child to `SideNavIcon` to render in the * container */ children: PropTypes__default["default"].node.isRequired, /** * Provide an optional class to be applied to the containing node */ className: PropTypes__default["default"].string, /** * Property to indicate if the side nav container is open (or not). Use to * keep local state and styling in step with the SideNav expansion state. */ isSideNavExpanded: PropTypes__default["default"].bool }; exports["default"] = SideNavItems;