@carbon/ibm-products
Version:
Carbon for IBM Products
123 lines (119 loc) • 3.58 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.
*/
import { extends as _extends } from '../../../_virtual/_rollupPluginBabelHelpers.js';
import React__default from 'react';
import cx from 'classnames';
import PropTypes from '../../../_virtual/index.js';
import { usePrefix, Tooltip } from '@carbon/react';
import { WarningAltFilled } from '@carbon/react/icons';
import { blockClass } from '../utils/util.js';
var _WarningAltFilled;
const ConditionBuilderButton = _ref => {
var _Icon, _span;
let {
className,
label,
hideLabel,
tooltipAlign,
renderIcon: Icon,
onClick,
showToolTip,
wrapperProps,
onBlur,
onFocus,
onMouseEnter,
onMouseLeave,
isInvalid,
wrapperClassName,
tabIndex,
description,
...rest
} = _ref;
const tooltipText = description || label;
const carbonPrefix = usePrefix();
const Button = () => {
const dataName = rest['data-name'] ?? '';
return /*#__PURE__*/React__default.createElement("button", _extends({
tabIndex: tabIndex !== undefined ? tabIndex : -1,
className: cx([className, `${blockClass}__button`, {
[`${blockClass}__text-ellipsis`]: showToolTip && !hideLabel && !isInvalid
}, {
[`${blockClass}__invalid-input`]: isInvalid
}]),
type: "button",
onClick: onClick,
onBlur: onBlur,
onFocus: onFocus,
onMouseEnter: onMouseEnter,
onMouseLeave: onMouseLeave,
"data-name": dataName
}, rest), Icon && (_Icon || (_Icon = /*#__PURE__*/React__default.createElement(Icon, null))), !hideLabel && (_span || (_span = /*#__PURE__*/React__default.createElement("span", null, label))), isInvalid && (_WarningAltFilled || (_WarningAltFilled = /*#__PURE__*/React__default.createElement(WarningAltFilled, null))));
};
return hideLabel || showToolTip || description ? /*#__PURE__*/React__default.createElement(Tooltip, _extends({
label: tooltipText,
align: tooltipAlign,
className: `${wrapperClassName} ${blockClass}__tooltip ${carbonPrefix}--icon-tooltip`
}, wrapperProps, {
leaveDelayMs: 0
}), Button()) : /*#__PURE__*/React__default.createElement(React__default.Fragment, null, Button());
};
ConditionBuilderButton.propTypes = {
/**
* Provide an optional class to be applied to the containing node.
*/
className: PropTypes.string,
/**
* decides if label and tooltip to be hidden
*/
hideLabel: PropTypes.bool,
/**
* boolean to know the updated value in not valid
*/
isInvalid: PropTypes.bool,
/**
* label of the button
*/
label: PropTypes.string,
/**
* mouse events callbacks
*/
onBlur: PropTypes.func,
/**
* callback triggered on click of add button
*/
onClick: PropTypes.func,
onFocus: PropTypes.func,
onMouseEnter: PropTypes.func,
onMouseLeave: PropTypes.func,
/**
* Optional prop to allow overriding the icon rendering.
*/
renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
/**
*/
/**
*decides if tooltip to be shown
*/
showToolTip: PropTypes.bool,
/**
* Tab index
*/
tabIndex: PropTypes.number,
/**
* tooltip position
*/
tooltipAlign: PropTypes.string,
/**
* classname applies to the wrapper of popover
*/
wrapperClassName: PropTypes.string,
/**
* optional props for tree grid to add role and aria-label to wrapper span
*/
wrapperProps: PropTypes.object
};
export { ConditionBuilderButton };