@carbon/react
Version:
React components for the Carbon Design System
59 lines (52 loc) • 1.69 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 React = require('react');
var usePrefix = require('../../internal/usePrefix.js');
var PropTypes = require('prop-types');
var ListBoxMenuItem = require('./ListBoxMenuItem.js');
const frFn = React.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.usePrefix();
return /*#__PURE__*/React.createElement("ul", _rollupPluginBabelHelpers.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.default])),
/**
* allow single item using the workaround for functional components
* https://github.com/facebook/react/issues/2979#issuecomment-222379916
*/
PropTypes.shape({
type: PropTypes.oneOf([ListBoxMenuItem.default])
}), PropTypes.bool // used in Dropdown for closed state
]),
/**
* Specify a custom `id`
*/
id: PropTypes.string.isRequired
};
exports.default = ListBoxMenu;