Files
cozsweet-frontend-nextjs/src/app/chat/components/message-bubble.tsx
T

50 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use client";
/**
* MessageBubble 消息气泡(容器)
*
* 原始 Dart: lib/ui/chat/widgets/message_bubble.dart52 行)
*
* 组成(从左到右):
* - AI[Avatar] [Content] [占位 spacer]
* - 用户:[占位 spacer] [Content] [Avatar]
*/
import { useUserState } from "@/stores/user/user-context";
import { MessageAvatar } from "./message-avatar";
import { MessageContent } from "./message-content";
import styles from "./chat-area.module.css";
export interface MessageBubbleProps {
content: string;
imageUrl?: string | null;
isFromAI: boolean;
}
export function MessageBubble({ content, imageUrl, isFromAI }: MessageBubbleProps) {
const { avatarUrl } = useUserState();
if (isFromAI) {
return (
<div className={styles.bubbleRowAi} aria-label="AI message">
<MessageAvatar isFromAI={true} />
<div style={{ width: 8 }} />
<MessageContent
content={content}
imageUrl={imageUrl}
isFromAI={true}
/>
<div style={{ width: 43 }} /> {/* 占位:保持与头像宽度一致 */}
</div>
);
}
return (
<div className={styles.bubbleRowUser} aria-label="User message">
<div style={{ width: 43 }} /> {/* 占位 */}
<MessageContent content={content} imageUrl={imageUrl} isFromAI={false} />
<div style={{ width: 8 }} />
<MessageAvatar isFromAI={false} userAvatarUrl={avatarUrl} />
</div>
);
}