chat-ui
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseChat UI Components
聊天UI组件
Chat building blocks from ui.inference.sh.
来自ui.inference.sh的聊天界面构建块。
Quick Start
快速开始
bash
undefinedbash
undefinedInstall chat components
Install chat components
npx shadcn@latest add https://ui.inference.sh/r/chat.json
undefinednpx shadcn@latest add https://ui.inference.sh/r/chat.json
undefinedComponents
组件列表
Chat Container
聊天容器
tsx
import { ChatContainer } from "@/registry/blocks/chat/chat-container"
<ChatContainer>
{/* messages go here */}
</ChatContainer>tsx
import { ChatContainer } from "@/registry/blocks/chat/chat-container"
<ChatContainer>
{/* messages go here */}
</ChatContainer>Messages
消息组件
tsx
import { ChatMessage } from "@/registry/blocks/chat/chat-message"
<ChatMessage
role="user"
content="Hello, how can you help me?"
/>
<ChatMessage
role="assistant"
content="I can help you with many things!"
/>tsx
import { ChatMessage } from "@/registry/blocks/chat/chat-message"
<ChatMessage
role="user"
content="Hello, how can you help me?"
/>
<ChatMessage
role="assistant"
content="I can help you with many things!"
/>Chat Input
聊天输入框
tsx
import { ChatInput } from "@/registry/blocks/chat/chat-input"
<ChatInput
onSubmit={(message) => handleSend(message)}
placeholder="Type a message..."
disabled={isLoading}
/>tsx
import { ChatInput } from "@/registry/blocks/chat/chat-input"
<ChatInput
onSubmit={(message) => handleSend(message)}
placeholder="Type a message..."
disabled={isLoading}
/>Typing Indicator
输入状态指示器
tsx
import { TypingIndicator } from "@/registry/blocks/chat/typing-indicator"
{isTyping && <TypingIndicator />}tsx
import { TypingIndicator } from "@/registry/blocks/chat/typing-indicator"
{isTyping && <TypingIndicator />}Full Example
完整示例
tsx
import {
ChatContainer,
ChatMessage,
ChatInput,
TypingIndicator,
} from "@/registry/blocks/chat"
export function Chat() {
const [messages, setMessages] = useState([])
const [isLoading, setIsLoading] = useState(false)
const handleSend = async (content: string) => {
setMessages(prev => [...prev, { role: 'user', content }])
setIsLoading(true)
// Send to API...
setIsLoading(false)
}
return (
<ChatContainer>
{messages.map((msg, i) => (
<ChatMessage key={i} role={msg.role} content={msg.content} />
))}
{isLoading && <TypingIndicator />}
<ChatInput onSubmit={handleSend} disabled={isLoading} />
</ChatContainer>
)
}tsx
import {
ChatContainer,
ChatMessage,
ChatInput,
TypingIndicator,
} from "@/registry/blocks/chat"
export function Chat() {
const [messages, setMessages] = useState([])
const [isLoading, setIsLoading] = useState(false)
const handleSend = async (content: string) => {
setMessages(prev => [...prev, { role: 'user', content }])
setIsLoading(true)
// Send to API...
setIsLoading(false)
}
return (
<ChatContainer>
{messages.map((msg, i) => (
<ChatMessage key={i} role={msg.role} content={msg.content} />
))}
{isLoading && <TypingIndicator />}
<ChatInput onSubmit={handleSend} disabled={isLoading} />
</ChatContainer>
)
}Message Variants
消息变体
| Role | Description |
|---|---|
| User messages (right-aligned) |
| AI responses (left-aligned) |
| System messages (centered) |
| 角色 | 说明 |
|---|---|
| 用户消息(右对齐) |
| AI助手消息(左对齐) |
| 系统消息(居中对齐) |
Styling
样式定制
Components use Tailwind CSS and shadcn/ui design tokens:
tsx
<ChatMessage
role="assistant"
content="Hello!"
className="bg-muted"
/>组件使用Tailwind CSS和shadcn/ui设计令牌:
tsx
<ChatMessage
role="assistant"
content="Hello!"
className="bg-muted"
/>Related Skills
相关技能组件
bash
undefinedbash
undefinedFull agent component (recommended)
Full agent component (recommended)
npx skills add inference-sh/skills@agent-ui
npx skills add inference-sh/skills@agent-ui
Declarative widgets
Declarative widgets
npx skills add inference-sh/skills@widgets-ui
npx skills add inference-sh/skills@widgets-ui
Markdown rendering
Markdown rendering
npx skills add inference-sh/skills@markdown-ui
undefinednpx skills add inference-sh/skills@markdown-ui
undefinedDocumentation
相关文档
- Chatting with Agents - Building chat interfaces
- Agent UX Patterns - Chat UX best practices
- Real-Time Streaming - Streaming responses
Component docs: ui.inference.sh/blocks/chat
- 与Agent聊天 - 构建聊天界面
- Agent UX设计模式 - 聊天UX最佳实践
- 实时流式响应 - 流式响应实现