gpui-component
14
总安装量
4
周安装量
#23479
全站排名
安装命令
npx skills add https://github.com/aprilnea/gpui-skills --skill gpui-component
Agent 安装分布
opencode
2
cursor
2
codex
2
claude-code
2
replit
1
amp
1
Skill 文档
gpui-component Best Practices
Comprehensive guide for building UI components with gpui-component, a component library for GPUI applications.
When to Apply
Reference these guidelines when:
- Creating reusable UI components
- Implementing theme-aware styling
- Building dialogs, popovers, or sheets
- Creating form components (Input, Checkbox, etc.)
- Implementing component animations
- Following Longbridge component patterns
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Component Architecture | CRITICAL | comp- |
| 2 | Trait System | CRITICAL | trait- |
| 3 | Theme System | HIGH | theme- |
| 4 | Dialog & Popover | HIGH | dialog- |
| 5 | Form Components | MEDIUM | form- |
| 6 | Animation | MEDIUM | anim- |
Quick Reference
1. Component Architecture (CRITICAL)
comp-renderonce– Use RenderOnce with #[derive(IntoElement)]comp-structure– Standard component structure templatecomp-builder– Fluent builder pattern for componentscomp-stateful– Entity + RenderOnce for stateful componentscomp-callbacks– Use Rc for event callbacks
2. Trait System (CRITICAL)
trait-styled– Implement Styled for style customizationtrait-disableable– Implement Disableable for disabled statetrait-selectable– Implement Selectable for selection statetrait-sizable– Implement Sizable with Size enumtrait-parent-element– Implement ParentElement for childrentrait-interactive– Implement InteractiveElement for events
3. Theme System (HIGH)
theme-colors– Use ThemeColor for consistent colorstheme-active– Use ActiveTheme trait for theme accesstheme-variants– Implement variant enums (ButtonVariant, etc.)theme-size-system– Use StyleSized for size-based styling
4. Dialog & Popover (HIGH)
dialog-root– Use Root component as window rootdialog-window-ext– Use WindowExt for dialog managementdialog-confirm– Implement confirm/alert dialogsdialog-form– Build form dialogs with input statepopover-pattern– Popover vs PopupMenu vs Sheet selection
5. Form Components (MEDIUM)
form-input-state– Entity-based input state managementform-focus– Focus management with keyed stateform-validation– Input validation patterns
6. Animation (MEDIUM)
anim-with-animation– Use with_animation for transitionsanim-keyed-state– Persist animation state with use_keyed_stateanim-easing– Use cubic_bezier for smooth animations
Component Structure Template
#[derive(IntoElement)]
pub struct MyComponent {
// 1. Identifier
id: ElementId,
// 2. Base element (for event delegation)
base: Div,
// 3. Style override
style: StyleRefinement,
// 4. Content
label: Option<SharedString>,
children: Vec<AnyElement>,
// 5. State configuration
disabled: bool,
selected: bool,
size: Size,
// 6. Callbacks
on_click: Option<Rc<dyn Fn(&ClickEvent, &mut Window, &mut App)>>,
}
Architecture Overview
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â Window â
â âââ Root (Entity, manages overlay state) â
â â âââ view: AnyView (user's main view) â
â â âââ active_dialogs: Vec<ActiveDialog> â
â â âââ active_sheet: Option<ActiveSheet> â
â â âââ notification: Entity<NotificationList> â
â â â
â âââ Render Layers â
â âââ Layer 0: Root.view (main content) â
â âââ Layer 1: Sheet (side drawer) â
â âââ Layer 2: Dialogs (stackable) â
â âââ Layer 3: Notifications â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
Popup Component Comparison
| Feature | Dialog | Popover | PopupMenu | Sheet |
|---|---|---|---|---|
| Position | Centered | Anchored | Anchored | Side |
| Overlay | Yes | No | No | Yes |
| State | Root | keyed_state | Entity | Root |
| Stacking | Multiple | Single | Submenus | Single |
| Close | ESC/Click/Button | ESC/Outside | ESC/Select | ESC/Overlay |
How to Use
Read individual rule files for detailed explanations and code examples:
rules/comp-renderonce.md
rules/trait-styled.md
rules/dialog-root.md
Each rule file contains:
- Brief explanation of why it matters
- Code examples with correct patterns
- Common mistakes to avoid