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

View File

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