UNPKG

@carbon/react

Version:

React components for the Carbon Design System

55 lines (50 loc) 1.56 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. */ import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js'; import React, { forwardRef } from 'react'; import { usePrefix } from '../../internal/usePrefix.js'; import PropTypes from 'prop-types'; import ListBoxMenuItem from './ListBoxMenuItem.js'; const frFn = forwardRef; /** * `ListBoxMenu` is a simple container node that isolates the `list-box__menu` * class into a single component. It is also being used to validate given * `children` components. */ const ListBoxMenu = frFn(({ children, id, ...rest }, ref) => { const prefix = usePrefix(); return /*#__PURE__*/React.createElement("ul", _extends({ ref: ref, id: id, className: `${prefix}--list-box__menu`, role: "listbox" }, rest), children); }); ListBoxMenu.displayName = 'ListBoxMenu'; ListBoxMenu.propTypes = { /** * Provide the contents of your ListBoxMenu */ children: PropTypes.oneOfType([PropTypes.node, PropTypes.arrayOf(PropTypes.oneOf([ListBoxMenuItem])), /** * allow single item using the workaround for functional components * https://github.com/facebook/react/issues/2979#issuecomment-222379916 */ PropTypes.shape({ type: PropTypes.oneOf([ListBoxMenuItem]) }), PropTypes.bool // used in Dropdown for closed state ]), /** * Specify a custom `id` */ id: PropTypes.string.isRequired }; export { ListBoxMenu as default };