@carbon/ibm-products
Version:
Carbon for IBM Products
71 lines (66 loc) • 2.53 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.
*/
;
var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
var React = require('react');
var Toolbar = require('./Toolbar.js');
var index = require('../../_virtual/index.js');
var react = require('@carbon/react');
var cx = require('classnames');
var settings = require('../../settings.js');
const blockClass = `${Toolbar.blockClass}__button`;
/** Toolbar buttons are common functions performed as part of a products interface or an open window. */
exports.ToolbarButton = /*#__PURE__*/React.forwardRef((_ref, ref) => {
let {
caret = false,
children,
className,
renderIcon,
iconDescription: deprecated_iconDescription = '',
label,
...rest
} = _ref;
const Icon = renderIcon;
return /*#__PURE__*/React.createElement(react.IconButton, _rollupPluginBabelHelpers.extends({
align: React.useContext(Toolbar.ToolbarContext)?.vertical ? 'right' : 'top'
}, rest, {
label: label ?? deprecated_iconDescription,
ref: ref,
className: cx(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`
})));
});
const componentName = 'ToolbarButton';
exports.ToolbarButton.displayName = componentName;
const deprecatedProps = {
/**
* **Deprecated**
* Specifies the label for the icon button
* */
iconDescription: index.propTypesExports.string
};
exports.ToolbarButton.propTypes = {
/** Determines whether the caret is rendered */
caret: index.propTypesExports.bool,
/** Provide the content of the `ToolbarButton` */
children: index.propTypesExports.node,
/** Provide an optional class to be applied to the containing node */
className: index.propTypesExports.string,
/** Specifies the label for the icon button */
label: index.propTypesExports.string.isRequired,
/** Specifies the icon to be used by the ToolbarButton component */
renderIcon: index.propTypesExports.func.isRequired,
...deprecatedProps
};
exports.ToolbarButton = settings.pkg.checkComponentEnabled(exports.ToolbarButton, componentName);
exports.blockClass = blockClass;
exports.deprecatedProps = deprecatedProps;