@carbon/ibm-products
Version:
Carbon for IBM Products
93 lines (88 loc) • 3.38 kB
JavaScript
/**
* Copyright IBM Corp. 2020, 2025
*
* 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 React__default, { useRef } from 'react';
import PropTypes from '../../_virtual/index.js';
import cx from 'classnames';
import { OverflowMenu, OverflowMenuItem } from '@carbon/react';
import uuidv4 from '../../global/js/utils/uuidv4.js';
import { pkg } from '../../settings.js';
// Copyright IBM Corp. 2020, 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.
//
const blockClass = `${pkg.prefix}--action-bar-overflow-items`;
const componentName = 'ActionBar';
const ActionBarOverflowItems = _ref => {
let {
className,
menuOptionsClass,
overflowItems,
overflowAriaLabel,
overflowMenuRef
} = _ref;
const internalId = useRef(uuidv4());
return /*#__PURE__*/React__default.createElement("div", {
ref: overflowMenuRef
}, /*#__PURE__*/React__default.createElement(OverflowMenu, {
"aria-label": overflowAriaLabel,
className: cx(blockClass, className),
direction: "bottom",
flipped: true,
iconDescription: overflowAriaLabel // also needs setting to avoid a11y "Accessible name does not match or contain the visible label text"
,
menuOptionsClass: cx(`${blockClass}__options`, menuOptionsClass)
}, React__default.Children.map(overflowItems, (item, index) => {
// This uses a copy of a menu item option
// NOTE: Cannot use a real Tooltip icon below as it uses a <button /> the
// div equivalent below is based on Carbon 10.25.0
const ItemIcon = item?.props.renderIcon;
return /*#__PURE__*/React__default.createElement(OverflowMenuItem, {
className: `${blockClass}__item`,
onClick: item?.props.onClick,
itemText: /*#__PURE__*/React__default.createElement("div", {
className: `${blockClass}__item-content`,
"aria-describedby": `${internalId.current}-${index}--item-label`
}, /*#__PURE__*/React__default.createElement("span", {
className: `${blockClass}__item-label`,
id: `${internalId.current}-${index}--item-label`
}, item?.props.label), typeof item?.props.renderIcon === 'function' ? /*#__PURE__*/React__default.createElement(ItemIcon, null) : item?.props.renderIcon)
});
})));
};
ActionBarOverflowItems.displayName = componentName;
ActionBarOverflowItems.propTypes = {
// expects action bar item as array or in fragment,
/**
* className
*/
className: PropTypes.string,
/**
* class name applied to the overflow options
*/
menuOptionsClass: PropTypes.string,
/**
* overflowAriaLabel label for open close button overflow used for action bar items that do nto fit.
*/
overflowAriaLabel: PropTypes.string,
/**
* overflowItems: items to bre shown in the ActionBar overflow menu
*/
overflowItems: PropTypes.arrayOf(PropTypes.element),
/**
* overflowMenuRef for the overflow menu width that is needed to calculate the width of the action bar with overflow
*/
/**@ts-ignore */
overflowMenuRef: PropTypes.oneOfType([PropTypes.shape({
current: PropTypes.elementType
}), PropTypes.object, PropTypes.func]),
/**
* Optional tab index
*/
tabIndex: PropTypes.number
};
export { ActionBarOverflowItems };