Sunflower UI
Search
Copy Code
Light Mode
click the message
Avatar
chat-message.tsx
styles.css
prompt.md
Collapse
Reset
Copy Code
Download
Run
1
"use client";
2
3
import React, { useState } from 'react';
4
import { motion, AnimatePresence } from 'framer-motion';
5
import { cn } from "@/lib/utils";
6
7
export interface ChatMessageProps {
8
className?: string;
9
message?: string;
10
timestamp?: string;
11
avatarUrl?: string;
12
}
13
14
export function ChatMessage({
15
className,
16
message = "Every component now renders for real.",
17
timestamp = "April 20, 4:20 AM",
18
avatarUrl = "https://images.unsplash.com/photo-1599566150163-29194dcaad36?auto=format&fit=crop&w=64&h=64"
19
}: ChatMessageProps) {
20
const [showTime, setShowTime] = useState(false);
21
22
return (
23
<div className={cn("flex items-end gap-3 font-sans w-full max-w-[400px]", className)}>
24
<img
25
src={avatarUrl}
26
alt="Avatar"
27
className="w-9 h-9 rounded-full object-cover shrink-0 select-none shadow-sm"
28
/>
29
<div className="flex flex-col items-start w-full">
30
<button
31
onClick={() => setShowTime(!showTime)}
32
className="text-left bg-zinc-100 hover:bg-zinc-200 dark:bg-gradient-to-b dark:from-[#1C1C1E] dark:to-[#0A0A0C] border border-black/5 dark:border-white/10 dark:shadow-[inset_0_1px_0_rgba(255,255,255,0.08)] dark:hover:border-white/20 text-zinc-900 dark:text-[#F5F5F7] px-4 py-3 rounded-[20px] rounded-bl-[8px] text-[15px] font-matter leading-relaxed transition-all active:scale-[0.98] shadow-sm relative"
33
>
34
{message}
35
</button>
36
37
<AnimatePresence>
38
{showTime && (
39
<motion.div
40
initial={{ height: 0, opacity: 0 }}
41
animate={{ height: 'auto', opacity: 1 }}
42
exit={{ height: 0, opacity: 0 }}
43
transition={{ duration: 0.2, ease: "easeOut" }}
44
className="overflow-hidden w-full"
45
>
46
<div className="pt-1.5 pl-2 text-[11px] font-mono uppercase tracking-wider text-zinc-500 dark:text-[#86868B]">
47
{timestamp}
48
</div>
49
</motion.div>
50
)}
51
</AnimatePresence>
52
</div>
53
</div>
54
);
55
}
56