chat-ui

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Chat UI Components

聊天UI组件

Chat building blocks from ui.inference.sh.
来自ui.inference.sh的聊天界面构建块。

Quick Start

快速开始

bash
undefined
bash
undefined

Install chat components

Install chat components

undefined
undefined

Components

组件列表

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

消息变体

RoleDescription
user
User messages (right-aligned)
assistant
AI responses (left-aligned)
system
System messages (centered)
角色说明
user
用户消息(右对齐)
assistant
AI助手消息(左对齐)
system
系统消息(居中对齐)

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
undefined
bash
undefined

Full 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
undefined
npx skills add inference-sh/skills@markdown-ui
undefined

Documentation

相关文档