A complete chat interface component with real-time messaging, file sharing, voice notes, and WebSocket support.
The ChatBox component works with the useChat hook for state management:
The ChatBox component accepts the following props:
chat - ChatState object from useChat hook (required)currentUserId - Current user's ID to identify own messages (required)userName - Display name of the chat recipient (required)variant - Visual style: solid or soft (default: solid)userAvatar - Avatar image URL for the recipientuserStatus - Status text to display (default: "Online")headerActions - Snippet for custom header action buttonsonVoiceNote - Callback for voice note recording (blob, url) => voidonFileAttach - Callback for file attachment (file) => voidonCameraCapture - Callback for camera capture button clickclass - Custom CSS classesThe ChatBox supports multiple message types:
text - Standard text messages (default)image - Image attachments with previewvoice - Voice notes with audio playerfile - Generic file attachmentsThe chat state object provides these methods:
sendMessage(content, type?, metadata?) - Send a new messageloadMore() - Load older messages (pagination)markAsRead(messageId) - Mark a message as readconnect() - Manually connect WebSocketdisconnect() - Disconnect WebSocketYour backend API should implement these endpoints:
GET /chats/:chatId/messages?limit=50&before=messageId - Fetch messagesPOST /chats/:chatId/messages - Send a new messageWebSocket URL format: ws://host/path?token=xxx&chatId=xxx&userId=xxx
Message types to handle:
type: "message" - New message receivedtype: "status" - Message status updatetype: "typing" - User typing indicatortype: "read" - Mark message as read