UNPKG

@carbon/ibm-products

Version:

Carbon for IBM Products

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