@razorpay/blade
Version:
The Design System that powers Razorpay
101 lines (98 loc) • 5.24 kB
JavaScript
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import React__default from 'react';
import { SelfMessageBubble } from './SelfMessageBubble.web.js';
import { DefaultMessageBubble } from './DefaultMessageBubble.web.js';
import '../Typography/index.js';
import '../Box/BaseBox/index.js';
import '../../utils/getStringChildren/index.js';
import '../../utils/assignWithoutSideEffects/index.js';
import '../../utils/metaAttribute/index.js';
import '../../utils/makeAnalyticsAttribute/index.js';
import '../Box/styledProps/index.js';
import { jsx } from 'react/jsx-runtime';
import { Text } from '../Typography/Text/Text.js';
import { getStringFromReactText } from '../../utils/getStringChildren/getStringChildren.js';
import { BaseBox } from '../Box/BaseBox/BaseBox.web.js';
import { metaAttribute } from '../../utils/metaAttribute/metaAttribute.web.js';
import { MetaConstants } from '../../utils/metaAttribute/metaConstants.js';
import { makeAnalyticsAttribute } from '../../utils/makeAnalyticsAttribute/makeAnalyticsAttribute.js';
import { getStyledProps } from '../Box/styledProps/getStyledProps.js';
import { assignWithoutSideEffects } from '../../utils/assignWithoutSideEffects/assignWithoutSideEffects.js';
var _excluded = ["messageType", "senderType", "isLoading", "validationState", "errorText", "onClick", "footerActions", "children", "leading", "loadingText", "wordBreak", "maxWidth"];
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var ButtonResetCss = {
background: 'none',
border: 'none',
padding: undefined,
cursor: 'pointer',
color: 'inherit',
font: 'inherit',
textAlign: 'left',
outline: 'inherit',
appearance: 'none',
backgroundColor: 'inherit'
};
var _ChatMessage = function _ChatMessage(_ref, ref) {
var _ref$messageType = _ref.messageType,
messageType = _ref$messageType === void 0 ? 'default' : _ref$messageType,
_ref$senderType = _ref.senderType,
senderType = _ref$senderType === void 0 ? 'self' : _ref$senderType,
_ref$isLoading = _ref.isLoading,
isLoading = _ref$isLoading === void 0 ? false : _ref$isLoading,
_ref$validationState = _ref.validationState,
validationState = _ref$validationState === void 0 ? 'none' : _ref$validationState,
errorText = _ref.errorText,
onClick = _ref.onClick,
footerActions = _ref.footerActions,
children = _ref.children,
leading = _ref.leading,
loadingText = _ref.loadingText,
_ref$wordBreak = _ref.wordBreak,
wordBreak = _ref$wordBreak === void 0 ? 'break-word' : _ref$wordBreak,
maxWidth = _ref.maxWidth,
props = _objectWithoutProperties(_ref, _excluded);
// since we can pass both string and Card component as children, we need to check if children is string or Card component
// if children is string or array of string, we need to wrap it in Text component otherwise we will pass children as it is
var shouldWrapInText = typeof children === 'string' || Array.isArray(children) && children.every(function (child) {
return typeof child === 'string';
}) || isLoading;
var finalChildren = shouldWrapInText ? /*#__PURE__*/jsx(Text, {
color: isLoading ? 'surface.text.gray.muted' : 'surface.text.gray.normal',
weight: "regular",
variant: "body",
size: "medium",
wordBreak: wordBreak,
children: isLoading ? loadingText : getStringFromReactText(children)
}) : children;
return /*#__PURE__*/jsx(BaseBox, _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
onClick: onClick
}, onClick ? _objectSpread({}, ButtonResetCss) : {}), metaAttribute({
name: MetaConstants.ChatMessage,
testID: props.testID
})), makeAnalyticsAttribute(props)), getStyledProps(props)), {}, {
maxWidth: maxWidth,
ref: ref,
as: onClick ? 'button' : undefined,
children: senderType === 'self' ? /*#__PURE__*/jsx(SelfMessageBubble, {
validationState: validationState,
errorText: errorText,
children: finalChildren,
messageType: messageType,
isChildText: shouldWrapInText
}) : /*#__PURE__*/jsx(DefaultMessageBubble, {
children: finalChildren,
leading: leading,
isLoading: isLoading,
footerActions: footerActions,
isChildText: shouldWrapInText
})
}));
};
var ChatMessage = /*#__PURE__*/assignWithoutSideEffects( /*#__PURE__*/React__default.forwardRef(_ChatMessage), {
displayName: 'ChatMessage',
componentId: MetaConstants.ChatMessage
});
export { ChatMessage };
//# sourceMappingURL=ChatMessage.web.js.map