Chat 设计文档
对话/AI 聊天组件:消息流(头像/标题/内容/操作区,内容走 MarkdownRender)+ 输入区(textarea + Upload 附件 + 发送)+ 提示区(Hint)。框架无关逻辑在 @chenzy-design/core(buildSendContent/appendDivider/toggleLike/toggleDislike/resetLastMessage/shouldShowBackBottom/resolveEnableUpload/shouldSendOnEnter)。受控/非受控 chats(对齐 Upload value 模式),变换经 onChatsChange 回传。align(leftRight/leftAlign)、mode(bubble/noBubble/userBubble)、sendHotKey(enter/shift+enter)、enableUpload 三态。消息流 role=log/aria-live=polite;滚动出现回到底部悬浮按钮(SHOW_SCROLL_GAP=100)。ref 方法 resetMessage/scrollToBottom(animation)/clearContext/sendMessage。所有自定义渲染走 Svelte snippet(renderInputArea/renderChatBoxAvatar/Title/Content/Action/renderFullChatBox/renderHintBox/renderDivider)。
← API 文档使用建议
对话/AI 聊天组件:消息流(头像/标题/内容/操作区,内容走 MarkdownRender)+ 输入区(textarea + Upload 附件 + 发送)+ 提示区(Hint)。框架无关逻辑在 @chenzy-design/core(buildSendContent/appendDivider/toggleLike/toggleDislike/resetLastMessage/shouldShowBackBottom/resolveEnableUpload/shouldSendOnEnter)。受控/非受控 chats(对齐 Upload value 模式),变换经 onChatsChange 回传。align(leftRight/leftAlign)、mode(bubble/noBubble/userBubble)、sendHotKey(enter/shift+enter)、enableUpload 三态。消息流 role=log/aria-live=polite;滚动出现回到底部悬浮按钮(SHOW_SCROLL_GAP=100)。ref 方法 resetMessage/scrollToBottom(animation)/clearContext/sendMessage。所有自定义渲染走 Svelte snippet(renderInputArea/renderChatBoxAvatar/Title/Content/Action/renderFullChatBox/renderHintBox/renderDivider)。
Accessibility
ARIA role:log
- 消息流容器 role=log / aria-live=polite / aria-label 走 locale Chat.messageList,新消息被屏幕阅读器播报
- 输入区 textarea,Enter/Shift+Enter 由 sendHotKey + core.shouldSendOnEnter 判定(组合输入 isComposing 时不发送)
- 发送/上传/清除/复制/删除/重生成/赞/踩 均为原生 <button>,aria-label 走 locale;赞/踩 aria-pressed 反映激活态
- 回到底部悬浮按钮为原生 <button>,滚动距底 > SHOW_SCROLL_GAP(100) 时出现,aria-label=Chat.backToBottom
- 发送按钮 disabled 对齐 Semi getDisableSend:无文本且无附件 / 附件有未 success / 显式 disableSend
设计变量
| 变量 | 默认值 | 用法 |
|---|---|---|
--cd-chat-motion-duration | var(--cd-motion-duration-fast) | 返回底部显隐 / 悬浮过渡时长 |