UNPKG

@spaced-out/ui-design-system

Version:
212 lines (209 loc) 7.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ChatFooterRightSlot = exports.ChatFooterLeftSlot = exports.ChatFooter = exports.ChatContent = exports.ChatBubble = exports.ChatBody = exports.ChatAnchor = exports.CHAT_BUBBLE_ORIENTATION = void 0; var React = _interopRequireWildcard(require("react")); var _classify = _interopRequireDefault(require("../../utils/classify")); var _qa = require("../../utils/qa"); var _Avatar = require("../Avatar"); var _Icon = require("../Icon"); var _Tooltip = require("../Tooltip"); var _ChatBubbleModule = _interopRequireDefault(require("./ChatBubble.module.css")); var _jsxRuntime = require("react/jsx-runtime"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); } // Define the expected props for chat child elements // Type for a chat child element that can be checked for displayName const getNamedComponent = (childrenArray, componentDisplayName) => { const nodes = []; for (const child of childrenArray) { // Type guard to ensure child is a ReactElement if (/*#__PURE__*/React.isValidElement(child)) { // Cast to our typed chat child element const chatChildElement = child; if (chatChildElement?.type?.displayName === componentDisplayName) { nodes.push(child); } } } return nodes.length > 1 ? nodes : nodes[0] || null; }; const CHAT_BUBBLE_ORIENTATION = exports.CHAT_BUBBLE_ORIENTATION = Object.freeze({ left: 'left', right: 'right ' }); const ChatBubble = exports.ChatBubble = /*#__PURE__*/React.forwardRef((_ref, ref) => { let { classNames, orientation = 'left', children, testId } = _ref; const isLeftAligned = orientation === 'left'; const childrenArray = React.Children.toArray(children); const anchorComponent = getNamedComponent(childrenArray, 'ChatAnchor'); const chatComponent = getNamedComponent(childrenArray, 'ChatContent'); return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", { ref: ref, "data-testid": (0, _qa.generateTestId)({ base: testId, slot: 'wrapper' }), className: (0, _classify.default)(_ChatBubbleModule.default.chatBubbleWrapper, { [_ChatBubbleModule.default.chatBubbleWrapperRight]: !isLeftAligned }, classNames?.wrapper), children: [anchorComponent, chatComponent] }); }); const ChatAnchor = _ref2 => { let { isAI = true, tooltip, classNames, avatarProps, testId } = _ref2; return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", { "data-testid": (0, _qa.generateTestId)({ base: testId, slot: 'wrapper' }), className: (0, _classify.default)(_ChatBubbleModule.default.chatAnchorWrapper, classNames?.wrapper), children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Tooltip.Tooltip, { ...tooltip, hidden: !tooltip, testId: (0, _qa.generateTestId)({ base: testId, slot: 'tooltip' }), children: isAI ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.Icon, { name: "sparkle", color: "information", type: _Icon.ICON_TYPE.solid, size: _Icon.ICON_SIZE.large, testId: (0, _qa.generateTestId)({ base: testId, slot: 'ai-icon' }) }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_Avatar.Avatar, { ...avatarProps, testId: (0, _qa.generateTestId)({ base: testId, slot: 'avatar' }) }) }) }); }; exports.ChatAnchor = ChatAnchor; ChatAnchor.displayName = 'ChatAnchor'; const ChatContent = _ref3 => { let { classNames, children, testId } = _ref3; return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", { "data-testid": (0, _qa.generateTestId)({ base: testId, slot: 'wrapper' }), className: (0, _classify.default)(_ChatBubbleModule.default.chatContentWrapper, classNames?.wrapper), children: children }); }; exports.ChatContent = ChatContent; ChatContent.displayName = 'ChatContent'; const ChatBody = _ref4 => { let { withBgColor = true, isLoading, children, loadingText = 'Generating', classNames, testId } = _ref4; return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", { "data-testid": (0, _qa.generateTestId)({ base: testId, slot: 'wrapper' }), className: (0, _classify.default)(_ChatBubbleModule.default.chatBodyWrapper, { [_ChatBubbleModule.default.chatBodyWrapperLoading]: isLoading || !withBgColor, [_ChatBubbleModule.default.chatBodyWrapperBgColor]: withBgColor }, classNames?.wrapper), children: isLoading ? /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", { className: (0, _classify.default)(_ChatBubbleModule.default.loadingContainer, classNames?.wrapper), children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", { className: _ChatBubbleModule.default.loadingText, children: loadingText }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", { className: _ChatBubbleModule.default.loader, children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", { className: _ChatBubbleModule.default.dot }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", { className: _ChatBubbleModule.default.dot }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", { className: _ChatBubbleModule.default.dot })] })] }) : children }); }; exports.ChatBody = ChatBody; ChatBody.displayName = 'ChatBody'; const ChatFooter = _ref5 => { let { children, classNames, testId } = _ref5; const childrenArray = React.Children.toArray(children); const leftSlot = getNamedComponent(childrenArray, 'ChatFooterLeftSlot'); const rightSlot = getNamedComponent(childrenArray, 'ChatFooterRightSlot'); return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", { "data-testid": (0, _qa.generateTestId)({ base: testId, slot: 'wrapper' }), className: (0, _classify.default)(_ChatBubbleModule.default.chatFooterWrapper, classNames?.wrapper), children: [leftSlot, rightSlot] }); }; exports.ChatFooter = ChatFooter; ChatFooter.displayName = 'ChatFooter'; const ChatFooterRightSlot = _ref6 => { let { children, classNames, testId } = _ref6; return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", { className: classNames?.wrapper, "data-testid": (0, _qa.generateTestId)({ base: testId, slot: 'right-slot' }), children: children }); }; exports.ChatFooterRightSlot = ChatFooterRightSlot; ChatFooterRightSlot.displayName = 'ChatFooterRightSlot'; const ChatFooterLeftSlot = _ref7 => { let { children, classNames, testId } = _ref7; return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", { className: classNames?.wrapper, "data-testid": (0, _qa.generateTestId)({ base: testId, slot: 'left-slot' }), children: children }); }; exports.ChatFooterLeftSlot = ChatFooterLeftSlot; ChatFooterLeftSlot.displayName = 'ChatFooterLeftSlot';