UNPKG

@spaced-out/ui-design-system

Version:
148 lines (147 loc) 6.25 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 _Avatar = require("../Avatar"); var _Icon = require("../Icon"); var _Tooltip = require("../Tooltip"); var _ChatBubbleModule = _interopRequireDefault(require("./ChatBubble.module.css")); 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); } function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } const getNamedComponent = (childrenArray, componentDisplayName) => { const nodes = []; for (const child of childrenArray) { if ( // $FlowFixMe child?.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 } = _ref; const isLeftAligned = orientation === 'left'; const childrenArray = React.Children.toArray(children); const anchorComponent = getNamedComponent(childrenArray, 'ChatAnchor'); const chatComponent = getNamedComponent(childrenArray, 'ChatContent'); return /*#__PURE__*/React.createElement("div", { ref: ref, "data-testid": "ChatBubble", className: (0, _classify.default)(_ChatBubbleModule.default.chatBubbleWrapper, { [_ChatBubbleModule.default.chatBubbleWrapperRight]: !isLeftAligned }, classNames?.wrapper) }, anchorComponent, chatComponent); }); const ChatAnchor = _ref2 => { let { isAI = true, tooltip, classNames, avatarProps } = _ref2; return /*#__PURE__*/React.createElement("div", { "data-testid": "ChatAnchor", className: (0, _classify.default)(_ChatBubbleModule.default.chatAnchorWrapper, classNames?.wrapper) }, /*#__PURE__*/React.createElement(_Tooltip.Tooltip, _extends({}, tooltip, { hidden: !tooltip }), isAI ? /*#__PURE__*/React.createElement(_Icon.Icon, { name: "sparkle", color: "information", type: _Icon.ICON_TYPE.solid, size: _Icon.ICON_SIZE.large }) : /*#__PURE__*/React.createElement(_Avatar.Avatar, avatarProps))); }; exports.ChatAnchor = ChatAnchor; ChatAnchor.displayName = 'ChatAnchor'; const ChatContent = _ref3 => { let { classNames, children } = _ref3; return /*#__PURE__*/React.createElement("div", { "data-testid": "ChatContent", className: (0, _classify.default)(_ChatBubbleModule.default.chatContentWrapper, classNames?.wrapper) }, children); }; exports.ChatContent = ChatContent; ChatContent.displayName = 'ChatContent'; const ChatBody = _ref4 => { let { withBgColor = true, isLoading, children, loadingText = 'Generating', classNames } = _ref4; return /*#__PURE__*/React.createElement("div", { "data-testid": "ChatBody", className: (0, _classify.default)(_ChatBubbleModule.default.chatBodyWrapper, { [_ChatBubbleModule.default.chatBodyWrapperLoading]: isLoading || !withBgColor, [_ChatBubbleModule.default.chatBodyWrapperBgColor]: withBgColor }, classNames?.wrapper) }, isLoading ? /*#__PURE__*/React.createElement("div", { className: (0, _classify.default)(_ChatBubbleModule.default.loadingContainer, classNames?.wrapper) }, /*#__PURE__*/React.createElement("span", { className: _ChatBubbleModule.default.loadingText }, loadingText), /*#__PURE__*/React.createElement("span", { className: _ChatBubbleModule.default.loader }, /*#__PURE__*/React.createElement("span", { className: _ChatBubbleModule.default.dot }), /*#__PURE__*/React.createElement("span", { className: _ChatBubbleModule.default.dot }), /*#__PURE__*/React.createElement("span", { className: _ChatBubbleModule.default.dot }))) : children); }; exports.ChatBody = ChatBody; ChatBody.displayName = 'ChatBody'; const ChatFooter = _ref5 => { let { children, classNames } = _ref5; const childrenArray = React.Children.toArray(children); const leftSlot = getNamedComponent(childrenArray, 'ChatFooterLeftSlot'); const rightSlot = getNamedComponent(childrenArray, 'ChatFooterRightSlot'); return /*#__PURE__*/React.createElement("div", { "data-testid": "ChatFooter", className: (0, _classify.default)(_ChatBubbleModule.default.chatFooterWrapper, classNames?.wrapper) }, leftSlot, rightSlot); }; exports.ChatFooter = ChatFooter; ChatFooter.displayName = 'ChatFooter'; const ChatFooterRightSlot = _ref6 => { let { children, classNames } = _ref6; return /*#__PURE__*/React.createElement("div", { className: classNames?.wrapper }, children); }; exports.ChatFooterRightSlot = ChatFooterRightSlot; ChatFooterRightSlot.displayName = 'ChatFooterRightSlot'; const ChatFooterLeftSlot = _ref7 => { let { children, classNames } = _ref7; return /*#__PURE__*/React.createElement("div", { className: classNames?.wrapper }, children); }; exports.ChatFooterLeftSlot = ChatFooterLeftSlot; ChatFooterLeftSlot.displayName = 'ChatFooterLeftSlot';