UNPKG

@carbon/ibm-products

Version:

Carbon for IBM Products

68 lines (64 loc) 2.48 kB
/** * 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 { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js'; import React__default, { forwardRef, useContext } from 'react'; import { ToolbarContext, blockClass as blockClass$1 } from './Toolbar.js'; import { p as propTypesExports } from '../../_virtual/index.js'; import { IconButton } from '@carbon/react'; import cx from 'classnames'; import { pkg } from '../../settings.js'; const blockClass = `${blockClass$1}__button`; /** Toolbar buttons are common functions performed as part of a products interface or an open window. */ let ToolbarButton = /*#__PURE__*/forwardRef((_ref, ref) => { let { caret = false, children, className, renderIcon, iconDescription: deprecated_iconDescription = '', label, ...rest } = _ref; const Icon = renderIcon; return /*#__PURE__*/React__default.createElement(IconButton, _extends({ align: useContext(ToolbarContext)?.vertical ? 'right' : 'top' }, rest, { label: label ?? deprecated_iconDescription, ref: ref, className: cx(className, { [`${blockClass}--caret`]: caret }), kind: "ghost", size: "md" }), /*#__PURE__*/React__default.createElement(React__default.Fragment, null, Icon ? /*#__PURE__*/React__default.createElement(Icon, null) : null, children, caret && /*#__PURE__*/React__default.createElement("span", { className: `${blockClass}__caret` }))); }); const componentName = 'ToolbarButton'; ToolbarButton.displayName = componentName; const deprecatedProps = { /** * **Deprecated** * Specifies the label for the icon button * */ iconDescription: propTypesExports.string }; ToolbarButton.propTypes = { /** Determines whether the caret is rendered */ caret: propTypesExports.bool, /** Provide the content of the `ToolbarButton` */ children: propTypesExports.node, /** Provide an optional class to be applied to the containing node */ className: propTypesExports.string, /** Specifies the label for the icon button */ label: propTypesExports.string.isRequired, /** Specifies the icon to be used by the ToolbarButton component */ renderIcon: propTypesExports.func.isRequired, ...deprecatedProps }; ToolbarButton = pkg.checkComponentEnabled(ToolbarButton, componentName); export { ToolbarButton, blockClass, deprecatedProps };