@carbon/ibm-products
Version:
Carbon for IBM Products
77 lines (75 loc) • 2.98 kB
JavaScript
/**
* Copyright IBM Corp. 2020, 2026
*
* 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 { __toESM } from "../../_virtual/_rolldown/runtime.js";
import { require_classnames } from "../../node_modules/classnames/index.js";
import { pkg } from "../../settings.js";
import uuidv4 from "../../global/js/utils/uuidv4.js";
import React, { useRef } from "react";
import PropTypes from "prop-types";
import { OverflowMenu, OverflowMenuItem } from "@carbon/react";
//#region src/components/ActionBar/ActionBarOverflowItems.tsx
var import_classnames = /* @__PURE__ */ __toESM(require_classnames());
const blockClass = `${pkg.prefix}--action-bar-overflow-items`;
const componentName = "ActionBar";
const ActionBarOverflowItems = ({ className, menuOptionsClass, overflowItems, overflowAriaLabel, overflowMenuRef }) => {
const internalId = useRef(uuidv4());
return /* @__PURE__ */ React.createElement("div", { ref: overflowMenuRef }, /* @__PURE__ */ React.createElement(OverflowMenu, {
"aria-label": overflowAriaLabel,
className: (0, import_classnames.default)(blockClass, className),
direction: "bottom",
flipped: true,
iconDescription: overflowAriaLabel,
menuOptionsClass: (0, import_classnames.default)(`${blockClass}__options`, menuOptionsClass)
}, React.Children.map(overflowItems, (item, index) => {
const ItemIcon = item?.props.renderIcon;
return /* @__PURE__ */ React.createElement(OverflowMenuItem, {
className: `${blockClass}__item`,
onClick: item?.props.onClick,
itemText: /* @__PURE__ */ React.createElement("div", {
className: `${blockClass}__item-content`,
"aria-describedby": `${internalId.current}-${index}--item-label`
}, /* @__PURE__ */ React.createElement("span", {
className: `${blockClass}__item-label`,
id: `${internalId.current}-${index}--item-label`
}, item?.props.label), typeof item?.props.renderIcon === "function" ? /* @__PURE__ */ React.createElement(ItemIcon, null) : item?.props.renderIcon)
});
})));
};
ActionBarOverflowItems.displayName = componentName;
ActionBarOverflowItems.propTypes = {
/**
* 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
};
//#endregion
export { ActionBarOverflowItems };