mui-base
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMUI Headless UI Best Practices
MUI 无头UI最佳实践
Comprehensive style guide for building headless React component libraries following MUI Base UI patterns. Contains 48 rules across 5 categories, prioritized by impact.
遵循MUI Base UI模式构建无头React组件库的综合风格指南。包含5个类别共48条规则,按影响程度划分优先级。
When to Apply
适用场景
Reference these guidelines when:
- Building headless/unstyled component libraries
- Creating compound components with context-based composition
- Implementing accessible UI primitives with ARIA patterns
- Using render props and className callbacks for styling flexibility
- Writing components that support both controlled and uncontrolled modes
在以下场景中参考本指南:
- 构建无头/无样式组件库
- 创建基于上下文组合的复合组件
- 实现符合ARIA模式的无障碍UI原语
- 使用渲染属性和className回调实现样式灵活性
- 编写支持受控与非受控双模式的组件
Rule Categories by Priority
按优先级划分的规则类别
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Component Patterns | CRITICAL | |
| 2 | Naming Conventions | HIGH | |
| 3 | Organization | HIGH | |
| 4 | Error Handling | HIGH | |
| 5 | Style | MEDIUM | |
| 优先级 | 类别 | 影响程度 | 前缀 |
|---|---|---|---|
| 1 | 组件模式 | 关键 | |
| 2 | 命名规范 | 高 | |
| 3 | 组织架构 | 高 | |
| 4 | 错误处理 | 高 | |
| 5 | 代码风格 | 中 | |
Quick Reference
快速参考
1. Component Patterns (CRITICAL)
1. 组件模式(关键)
- - Use forwardRef with Named Function
comp-forward-ref-named - - Name Props Parameter componentProps
comp-props-parameter-naming - - Use useRenderElement for DOM Rendering
comp-use-render-element - - Create Context with Undefined Default
comp-context-undefined-default - - Context Error Messages with Hierarchy
comp-context-error-message - - Use useControlled Hook for Dual Modes
comp-use-controlled - - Memoize State Objects
comp-state-memoization - - Memoize Context Provider Values
comp-context-value-memo - - Plain Function for Non-DOM Roots
comp-plain-function-root - - Hook Namespace Exports
comp-hook-namespace-exports - - Props Destructuring Order
comp-props-destructure-order - - Add use client Directive
comp-use-client-directive
- - 使用带命名函数的forwardRef
comp-forward-ref-named - - 将Props参数命名为componentProps
comp-props-parameter-naming - - 使用useRenderElement进行DOM渲染
comp-use-render-element - - 创建默认值为undefined的Context
comp-context-undefined-default - - 带层级结构的Context错误提示
comp-context-error-message - - 使用useControlled Hook实现双模式
comp-use-controlled - - 对状态对象进行记忆化处理
comp-state-memoization - - 对Context Provider的值进行记忆化处理
comp-context-value-memo - - 非DOM根节点使用普通函数
comp-plain-function-root - - Hook命名空间导出
comp-hook-namespace-exports - - Props解构顺序规范
comp-props-destructure-order - - 添加use client指令
comp-use-client-directive
2. Naming Conventions (HIGH)
2. 命名规范(高)
- - Component Naming as ParentPart
name-component-naming - - File Name Matches Primary Export
name-file-matches-export - - Directory Naming kebab-case
name-directory-kebab-case - - Part Directory Naming lowercase
name-part-directory-lowercase - - Context Naming with Suffix
name-context-suffix - - Context Hook as useComponentContext
name-context-hook - - Props Interface as ComponentProps
name-props-interface - - State Interface as ComponentState
name-state-interface - - Namespace Type Exports
name-namespace-type-exports - - Event Type Naming Convention
name-event-type - - Constant Naming SCREAMING_SNAKE_CASE
name-constants - - Data Attribute Naming lowercase
name-data-attributes - - Hook Naming with use Prefix
name-hooks - - Ref Variable Naming with Suffix
name-refs - - Handler Naming Convention
name-handlers
- - 组件命名采用ParentPart格式
name-component-naming - - 文件名与主导出内容匹配
name-file-matches-export - - 目录命名采用kebab-case格式
name-directory-kebab-case - - 部件目录命名采用小写格式
name-part-directory-lowercase - - Context命名添加后缀
name-context-suffix - - Context Hook命名为useComponentContext
name-context-hook - - Props接口命名为ComponentProps
name-props-interface - - 状态接口命名为ComponentState
name-state-interface - - 命名空间类型导出
name-namespace-type-exports - - 事件类型命名规范
name-event-type - - 常量命名采用SCREAMING_SNAKE_CASE格式
name-constants - - 数据属性命名采用小写格式
name-data-attributes - - Hook命名添加use前缀
name-hooks - - Ref变量命名添加后缀
name-refs - - 处理器命名规范
name-handlers
3. Organization (HIGH)
3. 组织架构(高)
- - Component Directory Structure
org-component-directory - - Dual Barrel Export Pattern
org-dual-barrel-exports - - Test File Colocation
org-test-colocation - - Context File Placement
org-context-placement - - Data Attributes Documentation File
org-data-attributes-file - - State Attributes Mapping File
org-state-attributes-mapping - - CSS Variables Documentation File
org-css-vars-file - - Package-Level Wildcard Exports
org-package-exports
- - 组件目录结构规范
org-component-directory - - 双桶导出模式
org-dual-barrel-exports - - 测试文件与源码同目录
org-test-colocation - - Context文件存放位置规范
org-context-placement - - 数据属性文档文件
org-data-attributes-file - - 状态属性映射文件
org-state-attributes-mapping - - CSS变量文档文件
org-css-vars-file - - 包级通配符导出
org-package-exports
4. Error Handling (HIGH)
4. 错误处理(高)
- - Development-Only Warnings
err-dev-only-warnings - - Deduplicated Warning Messages
err-deduplicated-warnings - - Message Prefix Standard
err-message-prefix - - Context Error Guidance
err-context-error-guidance - - Prop Validation Timing
err-prop-validation-timing - - Cancelable Event Pattern
err-cancelable-events - - Event Reason Constants
err-event-reason-constants - - Type-Safe Event Reasons
err-typed-event-reasons
- - 仅开发环境警告
err-dev-only-warnings - - 去重警告提示
err-deduplicated-warnings - - 提示信息前缀标准
err-message-prefix - - Context错误指引
err-context-error-guidance - - Props校验时机
err-prop-validation-timing - - 可取消事件模式
err-cancelable-events - - 事件原因常量
err-event-reason-constants - - 类型安全的事件原因
err-typed-event-reasons
5. Style (MEDIUM)
5. 代码风格(中)
- - React Import as Namespace
style-react-import - - Internal Import Paths
style-internal-imports - - Explicit Undefined in Prop Types
style-explicit-undefined - - Default Values in Destructuring
style-default-values - - JSDoc Documentation
style-jsdoc-documentation
- - React导入使用命名空间
style-react-import - - 内部导入路径规范
style-internal-imports - - Prop类型中显式声明undefined
style-explicit-undefined - - 解构时设置默认值
style-default-values - - JSDoc文档规范
style-jsdoc-documentation
How to Use
使用方法
Read individual reference files for detailed explanations and code examples:
- Section definitions - Category structure and impact levels
- Rule template - Template for adding new rules
- Example: comp-forward-ref-named
- Example: org-component-directory
阅读单个参考文件获取详细说明和代码示例:
- 章节定义 - 类别结构与影响程度说明
- 规则模板 - 添加新规则的模板
- 示例:comp-forward-ref-named
- 示例:org-component-directory
Source
来源
Extracted from MUI Base UI codebase on 2026-01-17.
内容提取自MUI Base UI代码库,提取时间为2026-01-17。
Full Compiled Document
完整编译文档
For the complete guide with all rules expanded:
AGENTS.md包含所有规则详细说明的完整指南:
AGENTS.md