Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | 1x 1x 5x 5x 2x 2x | import type { ReactNode } from "react";
import { Avatar } from "@/components/ui/avatar";
import { cn } from "@/utils/class-name";
type MessageBubbleProps = {
isUser: boolean;
text?: string;
placeholder?: string;
fullWidth?: boolean;
children?: ReactNode;
};
export function MessageBubble({
isUser,
text,
placeholder,
fullWidth = false,
children,
}: MessageBubbleProps) {
if (isUser) {
return (
<div className="ml-auto max-w-[78%] rounded-[1.125rem_0.375rem_1.125rem_1.125rem] border border-violet-300/28 bg-user-bubble px-[0.9375rem] py-2.5 font-dm-sans text-sm leading-relaxed break-words text-white/90 shadow-bubble-user backdrop-blur-lg light:border-violet-400/40 light:text-white light:shadow-bubble-user-light">
<span className="whitespace-pre-wrap">{text ?? placeholder}</span>
</div>
);
}
return (
<div
className={cn(
"rounded-2xl border border-white/11 bg-glass px-4 py-2.5 font-dm-sans text-sm leading-relaxed text-white/88 shadow-bubble-assistant backdrop-blur-md light:border-slate-200 light:bg-white light:text-slate-800 light:shadow-bubble-assistant-light",
fullWidth ? "max-w-full" : "max-w-[72%]",
)}
>
{text ? <span className="whitespace-pre-wrap">{text}</span> : null}
{!text && placeholder ? (
<span className="text-white/40 light:text-slate-400">{placeholder}</span>
) : null}
{children ? (
<div className={cn(text || placeholder ? "mt-3" : undefined)}>
{children}
</div>
) : null}
</div>
);
}
type MessageAvatarProps = {
initials: string;
isUser: boolean;
avatarUrl?: string;
avatarLabel?: string;
size?: "sm" | "md" | "lg";
children?: ReactNode;
};
export function MessageAvatar({
initials,
isUser,
avatarUrl,
avatarLabel = "User avatar",
size = "sm",
}: MessageAvatarProps) {
if (isUser) {
return (
<Avatar
variant="user"
src={avatarUrl}
alt={avatarLabel}
initials={initials}
size={size}
className="mt-1"
/>
);
}
return <Avatar variant="assistant" size="sm" className="mt-1" />;
}
|