Spaces:
Configuration error
Configuration error
File size: 996 Bytes
25f6ee4 | 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 |
import React from 'react';
import { ChatMessage as ChatMessageType } from '../types';
interface ChatMessageProps {
message: ChatMessageType;
}
const ChatMessage: React.FC<ChatMessageProps> = ({ message }) => {
const isUser = message.sender === 'user';
const bubbleClasses = isUser
? 'bg-blue-500 text-white self-end rounded-br-none'
: 'bg-white text-gray-800 self-start rounded-bl-none';
const containerClasses = isUser ? 'justify-end' : 'justify-start';
// Basic markdown to HTML conversion for bold and newlines
const formatText = (text: string) => {
return text
.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
.replace(/\n/g, '<br />');
};
return (
<div className={`flex ${containerClasses}`}>
<div className={`rounded-xl p-4 max-w-lg lg:max-w-2xl shadow-md ${bubbleClasses}`}>
<p className="text-sm" dangerouslySetInnerHTML={{ __html: formatText(message.text) }} />
</div>
</div>
);
};
export default ChatMessage;
|