用法
import { ChatComposer } from './ChatComposer.jsx'
// Resolves when the answer has been written; a rejection puts the message back in the box.
const send = ({ text, files, mode }) => fetch('/api/chat', { method: 'POST', body: JSON.stringify({ text, files: files.map((file) => file.name), mode }) })
const upload = (file) => fetch('/api/files', { method: 'POST', body: file })
export function TripComposer() {
return <ChatComposer locale="en" attachments={[]} onSend={send} onAttach={upload} />
}属性
| 属性 | 类型 | 默认值 | 作用 |
|---|---|---|---|
locale | 'en' | 'zh-CN' | 'es' | 'ja' | 'en' | 内置文案、开场建议和文件大小所用的语言。 |
ideas | { icon, title, text }[] | sample | 输入框为空时显示的开场建议;点一下会把文字填进输入框,接着补充即可。 |
attachments | { id, name, size }[] | sample | 打开时已附上的文件。 |
modes | { key, label, icon }[] | sample | 附件按钮旁的回答方式选项;只有一种时不显示。 |
defaultMode | string | first mode | 初始选中的回答方式。 |
maxLength | number | 2000 | 消息的最大字数;达到 80% 时开始显示计数。 |
onSend | ({ text, files, mode }) => Promise | — | 发送消息。完成前一直显示停止按钮;失败时消息回到输入框并显示重试。 |
onStop | () => void | — | 访客停止生成时调用(停止按钮或 Esc 键)。 |
onAttach | (file: File) => Promise | — | 上传单个文件,完成前卡片显示上传中;超过 20 MB 的文件会直接提示。 |
onModeChange | (key) => void | — | 切换回答方式时调用。 |
generating | boolean | false | 打开时已有一条消息正在生成回答,显示停止按钮。 |
error | boolean | false | 打开时显示一条没发出去的消息,仍在输入框中,并附重试。 |
labels | object | — | 替换任意内置文案(见 copy.js),如 placeholder、send、stop、remove。 |
className | string | — | 加在根元素上,其他属性也传给根元素。 |
装进你的项目
把指令粘贴给 Codex 或 Claude Code。Agent 会读取公开的源码,先告诉你要写入哪些文件,再把区块连同它用到的组件一起加进项目。
ChatComposer.jsxchat-composer.csscopy.jskit.jsxkit.cssui/base-button/ui/textarea/ui/agent-status/ui/dropdown-menu/tokens.cssREADME.md
区块本身、样式和文案、共用的 kit、用到的组件和 tokens.css 会一起装进同一个文件夹。