UNPKG

@carbon/ibm-products

Version:
114 lines (112 loc) 3.63 kB
/** * 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 { blockClass } from "../PageHeaderUtils.js"; import React, { useEffect, useRef, useState } from "react"; import PropTypes from "prop-types"; import { Button, FeatureFlags, OverflowMenu, OverflowMenuItem } from "@carbon/react"; import { createOverflowHandler } from "@carbon/utilities"; //#region src/components/PageHeader/next/PageHeaderBreadcrumbPageActions.tsx /** * Copyright IBM Corp. 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. */ var import_classnames = /* @__PURE__ */ __toESM(require_classnames()); const PageHeaderBreadcrumbPageActions = ({ actions, className, overflowMenuLabel = "More page actions", buttonSize = "md", buttonKind = "ghost", ...other }) => { const containerRef = useRef(null); const [hiddenItems, setHiddenItems] = useState([]); const classNames = (0, import_classnames.default)(`${blockClass}__breadcrumb-page-actions`, className); useEffect(() => { if (!containerRef.current) return; const handler = createOverflowHandler({ container: containerRef.current, onChange: (_visible, hidden) => { const hiddenIds = hidden.map((el) => el.dataset.id); setHiddenItems(actions.filter((item) => hiddenIds.includes(item.id))); } }); return () => handler.disconnect(); }, [actions]); return /* @__PURE__ */ React.createElement("ul", { ref: containerRef, className: classNames, style: { display: "inline-flex", alignItems: "center", justifyContent: "flex-end", inlineSize: "50%" }, ...other }, actions.map((item) => /* @__PURE__ */ React.createElement("li", { key: item.id, "data-id": item.id }, /* @__PURE__ */ React.createElement(Button, { renderIcon: item.renderIcon, iconDescription: item.label, hasIconOnly: true, size: buttonSize, kind: buttonKind, onClick: item.onClick }))), /* @__PURE__ */ React.createElement("li", { "data-offset": true, "data-hidden": true, "data-floating-menu-container": true, style: { position: "relative" } }, /* @__PURE__ */ React.createElement(FeatureFlags, { enableV12Overflowmenu: true }, /* @__PURE__ */ React.createElement(OverflowMenu, { size: buttonSize, "aria-label": overflowMenuLabel }, hiddenItems.map((item) => /* @__PURE__ */ React.createElement(OverflowMenuItem, { key: item.id, itemText: item.label, onClick: item.onClick })))))); }; PageHeaderBreadcrumbPageActions.displayName = "PageHeaderBreadcrumbPageActions"; PageHeaderBreadcrumbPageActions.propTypes = { /** * Array of action items to display */ actions: PropTypes.arrayOf(PropTypes.shape({ id: PropTypes.string.isRequired, label: PropTypes.string.isRequired, renderIcon: PropTypes.elementType.isRequired, onClick: PropTypes.func }).isRequired).isRequired, /** * Kind of the action buttons */ buttonKind: PropTypes.oneOf([ "primary", "secondary", "tertiary", "ghost", "danger", "danger--tertiary", "danger--ghost" ]), /** * Size of the action buttons */ buttonSize: PropTypes.oneOf([ "sm", "md", "lg" ]), /** * Specify an optional className to be added to the component */ className: PropTypes.string, /** * Aria label for the overflow menu */ overflowMenuLabel: PropTypes.string }; //#endregion export { PageHeaderBreadcrumbPageActions };