@carbon/react
Version:
React components for the Carbon Design System
95 lines (89 loc) • 2.87 kB
JavaScript
/**
* Copyright IBM Corp. 2016, 2023
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
;
Object.defineProperty(exports, '__esModule', { value: true });
var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
var React = require('react');
var PropTypes = require('prop-types');
var cx = require('classnames');
var Button = require('../Button/Button.js');
require('../Button/Button.Skeleton.js');
var usePrefix = require('../../internal/usePrefix.js');
const ChatButton = /*#__PURE__*/React.forwardRef(function ChatButton({
className,
children,
disabled,
isQuickAction,
isSelected,
kind,
renderIcon,
size,
...other
}, ref) {
const prefix = usePrefix.usePrefix();
const classNames = cx(className, {
[`${prefix}--chat-btn`]: true,
[`${prefix}--chat-btn--with-icon`]: renderIcon,
[`${prefix}--chat-btn--quick-action`]: isQuickAction,
[`${prefix}--chat-btn--quick-action--selected`]: isSelected
});
const allowedSizes = ['sm', 'md', 'lg'];
if (isQuickAction) {
kind = 'ghost';
size = 'sm';
} else {
// Check if size is valid and warn if not
if (size && !allowedSizes.includes(size)) {
// eslint-disable-next-line no-console -- https://github.com/carbon-design-system/carbon/issues/20452
console.error(`Invalid size "${size}" provided to ChatButton. Size must be one of: ${allowedSizes.join(', ')}. Defaulting to "lg".`);
size = 'lg';
}
}
return /*#__PURE__*/React.createElement(Button.default, _rollupPluginBabelHelpers.extends({
disabled: disabled,
className: classNames,
kind: kind,
ref: ref,
size: size,
renderIcon: renderIcon
}, other), children);
});
ChatButton.propTypes = {
/**
* Provide the contents of your Select
*/
children: PropTypes.node,
/**
* Specify an optional className to be applied to the node containing the label and the select box
*/
className: PropTypes.string,
/**
* Specify whether the `ChatButton` should be disabled
*/
disabled: PropTypes.bool,
/**
* Specify whether the `ChatButton` should be rendered as a quick action button
*/
isQuickAction: PropTypes.bool,
/**
* Specify whether the quick action `ChatButton` should be rendered as selected. This disables the input
*/
isSelected: PropTypes.bool,
/**
* Specify the kind of `ChatButton` you want to create
*/
kind: PropTypes.oneOf(['primary', 'secondary', 'danger', 'ghost', 'tertiary']),
/**
* A component used to render an icon.
*/
renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
/**
* Specify the size of the `ChatButton`, from the following list of sizes:
*/
size: PropTypes.oneOf(['sm', 'md', 'lg'])
};
exports.default = ChatButton;