Chat
A comprehensive chat component system with message display, input handling, avatars, timestamps, and real-time messaging capabilities
Installation
Install the Chat component using the nocta-ui CLI:
npx nocta-ui add chat
Then import the components you need:
import {
Chat,
ChatHeader,
ChatTitle,
ChatDescription,
ChatMessages,
ChatMessage,
ChatInput,
ChatActions,
TypingIndicator,
type Message,
type TypingUser,
} from '@/components/ui/chat';
Basic Usage
Simple Chat
Chat with Header
Customer Support
We're here to help! Chat with our support team.

Message Types
The Chat component supports three message types: user
, assistant
, and system
.
interface Message {
id: string;
content: string;
sender: 'user' | 'assistant' | 'system';
timestamp: Date;
avatar?: string;
name?: string;
}
Sizing and Layout
The Chat component's size is controlled through the className
prop, giving you full flexibility over dimensions:
// Small chat window
<Chat
messages={messages}
onSendMessage={handleSendMessage}
className="w-80 h-64"
/>
// Medium chat (default-like)
<Chat
messages={messages}
onSendMessage={handleSendMessage}
className="w-96 h-96"
/>
// Large chat
<Chat
messages={messages}
onSendMessage={handleSendMessage}
className="w-full max-w-2xl h-[500px]"
/>
// Full width with responsive height
<Chat
messages={messages}
onSendMessage={handleSendMessage}
className="w-full h-screen max-h-[600px]"
/>
// Custom breakpoint sizing
<Chat
messages={messages}
onSendMessage={handleSendMessage}
className="w-full sm:w-96 md:w-[500px] lg:w-[600px] h-80 md:h-96"
/>
Features
Chat with Avatars
Display user avatars alongside messages for better visual identification.

Chat with Timestamps
Show message timestamps for better context and conversation tracking.
Read-Only Chat
Display conversation history without input capabilities.
Typing Indicators
Display real-time typing indicators to show when users are composing messages.
Typing Indicator Demo
Team Chat
Real-time typing indicators show when team members are responding

Features demonstrated:
- Single user typing indicator
- Multiple users typing simultaneously
- Smart text that handles different user counts
- Animated bouncing dots
- Integration with avatars
TypingUser Interface
interface TypingUser {
id: string; // Unique user identifier
name?: string; // Optional user name
avatar?: string; // Optional avatar URL
}
Features:
- Single User Typing: Shows "[Name] is typing"
- Multiple Users: Shows "[Name] and [Name] are typing" or "[Name] and X others are typing"
- Animated Dots: Bouncing animation with staggered timing
- Avatar Integration: Works seamlessly with chat avatars
- Auto-scroll: Automatically scrolls when typing indicators appear
Advanced Usage
Chat with Actions
Add external action buttons for enhanced functionality.
Chat with Actions
Input Configuration
Message Length Limit
Set a maximum character limit for messages:
<Chat
messages={messages}
onSendMessage={handleSendMessage}
maxLength={280}
placeholder="Type your message (max 280 chars)..."
className="w-full max-w-md"
/>
Multiline Control
Control whether users can send multiline messages:
// Allow multiline (default)
<Chat
messages={messages}
onSendMessage={handleSendMessage}
allowMultiline={true}
placeholder="Press Shift+Enter for new line..."
className="w-full max-w-lg"
/>
// Single line only
<Chat
messages={messages}
onSendMessage={handleSendMessage}
allowMultiline={false}
placeholder="Press Enter to send..."
className="w-full max-w-lg"
/>
Disabled State
Disable the chat input when needed:
<Chat
messages={messages}
onSendMessage={handleSendMessage}
disabled={isLoading}
placeholder="Chat is disabled..."
className="w-full max-w-lg opacity-50"
/>
Customization
Custom Styling
All components accept a className
prop for custom styling:
Individual Component Styling
Style individual chat components:
<Chat
messages={messages}
onSendMessage={handleSendMessage}
className="w-full max-w-2xl"
>
<ChatHeader className="bg-blue-50 dark:bg-blue-950">
<ChatTitle className="text-blue-900 dark:text-blue-100">
Custom Chat
</ChatTitle>
<ChatDescription className="text-blue-700 dark:text-blue-300">
With custom header styling
</ChatDescription>
</ChatHeader>
</Chat>
Component Architecture
The Chat component is built with a modular architecture:
- Chat: Main container component
- ChatHeader: Optional header with title and description
- ChatTitle: Title component with customizable element type
- ChatDescription: Description text component
- ChatMessages: Messages container with auto-scroll
- ChatMessage: Individual message component
- ChatInput: Input component with auto-resize textarea
- ChatActions: Container for action buttons
- TypingIndicator: Real-time typing indicator with animated dots
Accessibility
The Chat component includes several accessibility features:
- Keyboard Navigation: Full keyboard support for input and actions
- Screen Reader Support: Proper ARIA labels and semantic HTML
- Focus Management: Proper focus handling for interactive elements
- Auto-scroll: Automatic scrolling to new messages and typing indicators
- Message Timestamps: Available for screen readers
- Typing Indicators: Accessible real-time feedback for ongoing conversations
API Reference
Chat Props
Prop | Type | Default | Description |
---|---|---|---|
messages | Message[] | [] | Array of chat messages |
onSendMessage | (message: string) => void | undefined | Callback when message is sent |
placeholder | string | "Type a message..." | Input placeholder text |
disabled | boolean | false | Disable chat input |
autoFocus | boolean | false | Auto-focus input on mount |
maxLength | number | 500 | Maximum message length |
showTimestamps | boolean | false | Show message timestamps |
showAvatars | boolean | false | Show user avatars |
allowMultiline | boolean | true | Allow multiline messages |
typingUsers | TypingUser[] | [] | Array of users currently typing |
variant | 'default' | 'default' | Visual variant |
className | string | '' | Additional CSS classes (used for sizing and custom styling) |
Message Interface
interface Message {
id: string; // Unique message identifier
content: string; // Message text content
sender: 'user' | 'assistant' | 'system'; // Message sender type
timestamp: Date; // Message timestamp
avatar?: string; // Optional avatar URL
name?: string; // Optional sender name
}
TypingUser Interface
interface TypingUser {
id: string; // Unique user identifier
name?: string; // Optional user name
avatar?: string; // Optional avatar URL
}