All files / components/chat message-bubble.tsx

0% Statements 0/6
0% Branches 0/23
0% Functions 0/2
0% Lines 0/6

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                                                                                                                                                             
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-[0_8px_26px_rgba(56,32,140,0.34)] backdrop-blur-lg">
        <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-[0_8px_24px_rgba(6,10,30,0.24)] backdrop-blur-md",
        fullWidth ? "max-w-full" : "max-w-[72%]",
      )}
    >
      {text ? <span className="whitespace-pre-wrap">{text}</span> : null}
      {!text && placeholder ? (
        <span className="text-white/40">{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" />;
}