UNPKG

@carbon/ibm-products

Version:
58 lines (56 loc) 2.38 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 { ToolbarContext, blockClass as blockClass$1 } from "./Toolbar.js"; import React, { forwardRef, useContext } from "react"; import { bool, func, node, string } from "prop-types"; import { IconButton } from "@carbon/react"; //#region src/components/Toolbar/ToolbarButton.tsx /** * Copyright IBM Corp. 2021, 2024 * * 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 blockClass = `${blockClass$1}__button`; /** Toolbar buttons are common functions performed as part of a products interface or an open window. */ const ToolbarButton = forwardRef(({ caret = false, children, className, renderIcon, iconDescription: deprecated_iconDescription = "", label, ...rest }, ref) => { const Icon = renderIcon; return /* @__PURE__ */ React.createElement(IconButton, { align: useContext(ToolbarContext)?.vertical ? "right" : "top", ...rest, label: label ?? deprecated_iconDescription, ref, className: (0, import_classnames.default)(className, { [`${blockClass}--caret`]: caret }), kind: "ghost", size: "md" }, /* @__PURE__ */ React.createElement(React.Fragment, null, Icon ? /* @__PURE__ */ React.createElement(Icon, null) : null, children, caret && /* @__PURE__ */ React.createElement("span", { className: `${blockClass}__caret` }))); }); ToolbarButton.displayName = "ToolbarButton"; const deprecatedProps = { /** * **Deprecated** * Specifies the label for the icon button * */ iconDescription: string }; ToolbarButton.propTypes = { /** Determines whether the caret is rendered */ caret: bool, /** Provide the content of the `ToolbarButton` */ children: node, /** Provide an optional class to be applied to the containing node */ className: string, /** Specifies the label for the icon button */ label: string.isRequired, /** Specifies the icon to be used by the ToolbarButton component */ renderIcon: func.isRequired, ...deprecatedProps }; //#endregion export { ToolbarButton };