Enhance ChatBubble and ChatBOX components to display loading messages; improve structure and formatting for better readability

This commit is contained in:
ecwu
2024-12-21 21:40:06 +08:00
parent 1c1c46b67d
commit 001bc479c2
2 changed files with 17 additions and 12 deletions

View File

@@ -23,7 +23,7 @@ const chatBubbleVariant = cva(
variant: "received",
layout: "default",
},
},
}
);
interface ChatBubbleProps
@@ -35,7 +35,7 @@ const ChatBubble = React.forwardRef<HTMLDivElement, ChatBubbleProps>(
<div
className={cn(
chatBubbleVariant({ variant, layout, className }),
"relative group",
"relative group"
)}
ref={ref}
{...props}
@@ -46,10 +46,10 @@ const ChatBubble = React.forwardRef<HTMLDivElement, ChatBubbleProps>(
variant,
layout,
} as React.ComponentProps<typeof child.type>)
: child,
: child
)}
</div>
),
)
);
ChatBubble.displayName = "ChatBubble";
@@ -102,25 +102,28 @@ const ChatBubbleMessage = React.forwardRef<
>(
(
{ className, variant, layout, isLoading = false, children, ...props },
ref,
ref
) => (
<div
className={cn(
chatBubbleMessageVariants({ variant, layout, className }),
"break-words max-w-full whitespace-pre-wrap",
"break-words max-w-full whitespace-pre-wrap"
)}
ref={ref}
{...props}
>
{isLoading ? (
<div className="flex items-center space-x-2">
<MessageLoading />
</div>
<>
{children}
<div className="flex items-center space-x-2">
<MessageLoading />
</div>
</>
) : (
children
)}
</div>
),
)
);
ChatBubbleMessage.displayName = "ChatBubbleMessage";
@@ -181,7 +184,7 @@ const ChatBubbleActionWrapper = React.forwardRef<
variant === "sent"
? "-left-1 -translate-x-full flex-row-reverse"
: "-right-1 translate-x-full",
className,
className
)}
{...props}
>

View File

@@ -680,7 +680,9 @@ export default function ChatBOX(props: {
))}
{showGenerating && (
<ChatBubble variant="received">
<ChatBubbleMessage isLoading />
<ChatBubbleMessage isLoading>
{generatingMessage}
</ChatBubbleMessage>
</ChatBubble>
)}
<p className="text-center">