gpui-component
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseRead This First
请先阅读以下内容
Before changing UI, interaction, interface language, layout, styling,
components, or application architecture, read the relevant guide:
| Guide | Read before |
|---|---|
| Design Guides | Choosing components, layout, spacing, hierarchy, color, density, interaction states, overlays, interface copy |
| Coding Guides | Crate layering, |
These guides are requirements, not optional inspiration. Do not copy generic
web conventions, infer a design system from one existing screen, or add a
control merely because the underlying feature exists. Review the finished work
against both guides before considering it complete.
Read the guide file itself. Do not answer from what this page summarizes, from
an existing screen in the codebase, or from training data — those are the three
ways the guides get quietly ignored.
在修改UI、交互、界面语言、布局样式、组件或应用架构之前,请阅读相关指南:
| 指南 | 适用场景 |
|---|---|
| 设计指南 | 选择组件、布局、间距、层级、颜色、密度、交互状态、浮层、界面文案 |
| 编码指南 | Crate分层、 |
这些指南是硬性要求,而非可选参考。请勿照搬通用Web惯例、从单一现有界面推断设计系统,或仅因底层功能存在就添加控件。完成工作后需对照两份指南进行审核,确认无误后方可视为完成。
请直接阅读指南文件内容。请勿根据本页摘要、代码库中现有界面或训练数据作答——这三种方式会导致指南被悄然忽略。
Non-negotiables
不可妥协的原则
These are a floor, not a substitute. Read the guide for anything past this list.
- Never invent an API. Search the current source for the real signature. Do not translate a React, CSS, or older-GPUI example by analogy — a plausible-looking method name that does not exist is the most common failure mode here.
- Desktop before web convention. Keyboard access, window chrome, menus, dense data views, resizable regions, persistent navigation.
- vs
Button.Linkfor every in-app command — useButtonorghostwhen it should read quietly.outlineonly for external URLs and email addresses.Link - Tokens before values. No raw hex or in application UI; use
rgb(...)semantic tokens. Use rem-based helpers (cx.theme(),p_2(),gap_3()) so window zoom works. Any spacing number you see quoted is the current default scale, not a literal to repeat.text_sm() - State must be visible. Hover, focus, selection, disabled, loading, validation, and destructive states each need distinct, consistent treatment.
- Stable identity. Repeated elements need domain-derived s, not list indexes.
ElementId - Overlays. Escape dismisses the topmost surface and returns focus to its trigger.
- Copy. Name the object and the verb — with a
Delete “Roadmap”?button, notDeletewithAre you sure?.OK
以下是基础要求,不能替代完整指南。超出此列表的内容请查阅指南文件。
- 切勿自行创造API。在当前源码中查找真实的方法签名。请勿通过类比React、CSS或旧版GPUI示例进行转换——看似合理但实际不存在的方法名是最常见的错误。
- 优先遵循桌面端惯例。键盘访问、窗口边框、菜单、高密度数据视图、可调整大小区域、持久化导航。
- 区分与
Button。Link用于所有应用内命令——需要低调显示时使用Button或ghost样式。outline仅用于外部URL和邮箱地址。Link - 优先使用令牌而非直接值。应用UI中禁止使用原始十六进制值或;使用
rgb(...)语义化令牌。使用基于rem的辅助函数(cx.theme()、p_2()、gap_3())以支持窗口缩放。所有引用的间距数值均为当前默认比例,并非需要重复使用的固定值。text_sm() - 状态必须可见。悬停、焦点、选中、禁用、加载、验证和破坏性状态都需要有清晰一致的处理方式。
- 保持稳定标识。重复元素需使用领域相关的,而非列表索引。
ElementId - 浮层处理。按下Esc键可关闭最上层浮层,并将焦点返回至触发它的元素。
- 文案规范。同时指定对象和动作——例如使用“删除「Roadmap」?”搭配按钮,而非“确定吗?”搭配
Delete按钮。OK
Documentation
文档资源
- Full reference: fetch
https://longbridge.github.io/gpui-component/llms-full.txt - Per-component API: fetch
https://longbridge.github.io/gpui-component/docs/components/{name}.md- e.g. ,
button.md,input.md,select.md,dialog.mddata-table.md
- e.g.
- Any site page can be fetched as Markdown by appending to the URL
.md
- 完整参考文档:获取
https://longbridge.github.io/gpui-component/llms-full.txt - 单组件API文档:获取
https://longbridge.github.io/gpui-component/docs/components/{name}.md- 示例:、
button.md、input.md、select.md、dialog.mddata-table.md
- 示例:
- 所有站点页面均可通过在URL后添加获取Markdown格式内容
.md
Quick Reference
快速参考
Setup — always required:
rust
gpui_component::init(cx); // in app.run(), must be first
Root::new(view, window, cx) // first-level view in every windowStateless — use directly in render:
rust
Button::new("id").primary().label("OK").on_click(|_, _, _| {})Stateful — hold in struct, pass ref in render:
Entity<State>rust
// in new(): let input = cx.new(|cx| InputState::new(window, cx));
// in render: Input::new(&self.input)Sizes: (default)
.xsmall().small().medium().large()Theme: · · · ·
cx.theme().primary.background.foreground.border.muted配置——必须执行:
rust
gpui_component::init(cx); // 在app.run()中调用,必须是第一个执行的方法
Root::new(view, window, cx) // 每个窗口中的顶级视图无状态组件——可直接在渲染中使用:
rust
Button::new("id").primary().label("OK").on_click(|_, _, _| {})有状态组件——在结构体中持有,并在渲染时传入引用:
Entity<State>rust
// 在new()方法中: let input = cx.new(|cx| InputState::new(window, cx));
// 在render()方法中: Input::new(&self.input)尺寸选项: (默认)
.xsmall().small().medium().large()主题令牌: · · · ·
cx.theme().primary.background.foreground.border.mutedComponent Catalog
组件目录
When you need a component, find it here. For full API, fetch its doc.
.md需要使用组件时,请在此查找。完整API请查看对应的文档。
.mdInput & Form
输入与表单
| Component | Import | Notes |
|---|---|---|
| | Stateful. Text, password, mask, validation |
| | Stateful. Numeric with step |
| | Stateful. One-time password |
| | Stateful. Dropdown picker |
| | Stateful. Searchable select |
| | Stateless. `on_click( |
| | Stateless. Toggle |
| | Stateless. |
| | Stateful. |
| | Stateless. |
| | Stateless. |
| | Stateless. Increment/decrement |
| | Stateful. |
| | Stateful. |
| | Layout container for form fields |
| 组件 | 导入路径 | 说明 |
|---|---|---|
| | 有状态。支持文本、密码、掩码、验证 |
| | 有状态。带步长的数值输入 |
| | 有状态。一次性密码输入 |
| | 有状态。下拉选择器 |
| | 有状态。可搜索的选择器 |
| | 无状态。`on_click( |
| | 无状态。开关控件 |
| | 无状态。 |
| | 有状态。 |
| | 无状态。 |
| | 无状态。评分控件 |
| | 无状态。增减计数器 |
| | 有状态。颜色选择器 |
| | 有状态。日期选择器 |
| | 表单字段的布局容器 |
Display & Feedback
展示与反馈
| Component | Import | Notes |
|---|---|---|
| | Stateless. Primary UI action |
| | Stateless. Lucide icons |
| | Stateless. |
| | Stateless. Closable tags |
| | Stateless. |
| | Stateless. Form label |
| | Stateless. Keyboard key display |
| | Stateless. Info/success/warning/error |
| | Stateless. Loading indicator |
| | Stateless. Loading placeholder |
| | Stateless. |
| | Via |
| | Stateful. |
| | Stateless. Copy button |
| 组件 | 导入路径 | 说明 |
|---|---|---|
| | 无状态。主要UI动作按钮 |
| | 无状态。Lucide图标库 |
| | 无状态。徽章 |
| | 无状态。可关闭标签 |
| | 无状态。头像 |
| | 无状态。表单标签 |
| | 无状态。键盘按键展示 |
| | 无状态。信息/成功/警告/错误提示 |
| | 无状态。加载指示器 |
| | 无状态。加载占位符 |
| | 无状态。进度条/进度环 |
| | 通过元素的 |
| | 有状态。悬停卡片 |
| | 无状态。复制按钮 |
Overlay & Popups
浮层与弹窗
| Component | Import | Notes |
|---|---|---|
| | Via |
| | Via |
| | Side panel, via |
| | Via |
| | Floating overlay |
| | Context menus |
| | Button with dropdown menu |
| 组件 | 导入路径 | 说明 |
|---|---|---|
| | 通过 |
| | 通过 |
| | 侧边面板,通过 |
| | 通过 |
| | 浮动浮层 |
| | 上下文菜单 |
| | 带下拉菜单的按钮 |
Navigation & Layout
导航与布局
| Component | Import | Notes |
|---|---|---|
| | Tabbed interface |
| | App navigation panel |
| | Window title bar |
| | Navigation breadcrumb |
| | Page navigation |
| | Collapsible sections |
| | Single collapsible |
| | Labeled container |
| | Draggable split panes |
| | Custom scrollbar |
| | Keyboard trap for modals |
| 组件 | 导入路径 | 说明 |
|---|---|---|
| | 标签页界面 |
| | 应用导航面板 |
| | 窗口标题栏 |
| | 导航面包屑 |
| | 分页导航 |
| | 可折叠区块 |
| | 单个可折叠控件 |
| | 带标签的容器 |
| | 可拖拽分割面板 |
| | 自定义滚动条 |
| | 模态框的键盘焦点陷阱 |
Data Display
数据展示
| Component | Import | Notes |
|---|---|---|
| | Stateful. Full-featured table |
| | Simpler table |
| | High-perf large lists |
| | Stateful. Searchable list |
| | Stateful. Hierarchy |
| | Key-value pairs |
| | Settings panel |
| 组件 | 导入路径 | 说明 |
|---|---|---|
| | 有状态。全功能表格 |
| | 简易表格 |
| | 高性能大型列表 |
| | 有状态。可搜索列表 |
| | 有状态。层级树 |
| | 键值对列表 |
| | 设置面板 |
Charts
图表
| Component | Import | Notes |
|---|---|---|
| | Bar, line, area, pie charts |
| | |
| 组件 | 导入路径 | 说明 |
|---|---|---|
| | 柱状图、折线图、面积图、饼图 |
| | 数据需实现 |
Reference Files
参考文件
- usage.md — setup patterns, component types, common examples
- style-guide.md — code style for contributors
- usage.md — 配置模式、组件类型、常见示例
- style-guide.md — 贡献者代码风格指南