ChatBox Component
TheChatBox component provides an interactive AI-powered chat interface that can answer questions about the portfolio owner’s experience, projects, and skills. It supports blog-specific context for AI summarization.
Import
Usage
Props
The component accepts props defined by theChatBoxProps interface:
Controls the visibility of the chat box. When
false, the component returns null.Callback function invoked when the user closes the chat box (via close button or actions).
Enables dark mode styling for the chat interface. Defaults to
true.An optional initial message to send automatically when the chat opens. Useful for triggering AI summaries.
Optional blog context object for AI summarization. When provided, the AI will have context about a specific blog post.
Features
AI Integration
The ChatBox integrates with OpenAI’s GPT-4o-mini model to provide intelligent responses about the portfolio owner’s background.Message Types
The component uses theMessage type for chat messages:
The role of the message sender
The text content of the message
Fullscreen Mode
The chat box supports fullscreen mode on desktop devices:- Click the maximize icon to enter fullscreen
- Click the minimize icon to exit fullscreen
- Mobile devices always display in full screen
Chat Management
- Clear Chat: Resets the conversation while maintaining blog context if present
- Auto-scroll: Automatically scrolls to the latest message
- Loading States: Shows animated loading indicator during AI responses
Styling
The component uses Tailwind CSS classes and supports:- Dark theme with gradient backgrounds
- Responsive design (mobile and desktop)
- Markdown rendering with custom styles
- Smooth animations and transitions
Dependencies
react-markdown- For rendering AI responses with markdown supportlucide-react- For icons (X, Trash2, Maximize2, Minimize2)- Custom
AIInputcomponent for message input - System prompt loader for AI context
API Configuration
The component automatically configures the API URL based on environment:Helper Functions
formatAIResponse
Internal helper that formats AI responses for better readability:- Adds proper spacing between sections
- Formats code blocks with syntax highlighting
- Ensures proper spacing around lists and headings
Source Location
src/components/ChatBox.tsx:33