Skip to content

组件库 ​

src/components/ 包含 389 个文件,构成 Claude Code 的完整终端 UI。

核心组件分类 ​

消息渲染组件 ​

组件功能
MessageView消息容器(路由到具体类型)
UserMessage用户消息渲染
AssistantMessageAI 响应渲染(流式)
SystemMessage系统消息渲染
ToolUseMessage工具调用渲染
ToolResultMessage工具结果渲染
StreamingText流式文本渲染
MarkdownRendererMarkdown 渲染
CodeBlock代码块(语法高亮)

输入组件 ​

组件功能
TextInput多行文本编辑器
Prompt完整提示输入框
PromptInput提示输入核心
AutocompleteMenu自动补全菜单
SuggestionOverlay建议浮层
SlashCommandMenu斜杠命令菜单
FileAttachment文件附件
ImageAttachment图片附件

布局组件 ​

组件功能
FullscreenLayout全屏三段布局(header/body/footer)
StatusLine底部状态栏
Footer底部工具栏
Tabs标签页
ScrollView可滚动视图

对话框组件 ​

组件功能
PermissionDialog权限确认对话框
ConfirmDialog通用确认对话框
DiffDialogDiff 查看对话框
ExportDialog导出对话框
ModelPicker模型选择器
Settings设置界面
HelpV2帮助界面

数据展示组件 ​

组件功能
StructuredDiff结构化差异显示
ColorDiff着色差异显示
Table表格渲染
ProgressBar进度条
Spinner加载指示器
Badge标签
Notification通知弹出

PermissionDialog 深入 ​

typescript
// 权限确认对话框 — UI 中最关键的交互组件
type Props = {
  title: string
  subtitle?: string
  color?: keyof Theme
  titleColor?: string
  innerPaddingX?: number
  workerBadge?: string
  titleRight?: ReactNode
  children: ReactNode
}

// 显示内容
// ┌─────────────────────────────────────────┐
// │ Claude wants to run:                     │
// │                                          │
// │   BashTool                               │
// │   rm -rf node_modules && npm install     │
// │                                          │
// │ [y] Allow  [n] Deny  [a] Always Allow    │
// └─────────────────────────────────────────┘

StatusLine 深入 ​

typescript
// 底部状态栏 — 持续显示关键信息
// 使用 StatusLineCommandInput 类型(from types/statusLine.ts)
// 显示模型、成本、token、代理状态、待办进度等信息

// ─── claude-sonnet-4-20250514 ── $0.42 ── 12.3K tokens ── Editing tests... ───

组件树示例 ​

<App>
  <KeybindingProvider>
    <AppStateProvider>
      <ModalProvider>
          <REPL>
            <FullscreenLayout>
              <StatusLine />           {/* 顶部状态 */}
              <ScrollView>
                <Static items={messages}>
                  {msg => <MessageView message={msg} />}
                </Static>
                <StreamingMessage />   {/* 当前流式响应 */}
              </ScrollView>
              <PermissionDialog />     {/* 条件渲染 */}
              <Prompt>
                <TextInput />
                <AutocompleteMenu />
              </Prompt>
              <Footer />              {/* 底部快捷键提示 */}
            </FullscreenLayout>
          </REPL>
    </AppStateProvider>
  </KeybindingProvider>
</App>