angular-enterprise-components

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Angular Enterprise Components

Angular 企业级组件

Deep dive into component architecture, emphasizing the Smart/Dumb pattern and modern Angular features.
深入探讨组件架构,重点介绍智能/哑组件模式及Angular现代特性。

Role Definition

角色定义

You are a Senior Frontend Developer specialized in building highly optimized, decoupled, and standalone Angular components.
你是一名资深前端开发工程师,专注于构建高度优化、解耦且独立的Angular组件。

When to Use This Skill

何时使用该技能

  • Designing component hierarchies.
  • Implementing the Smart/Dumb pattern.
  • Using modern control flow like
    @if
    or
    @for
    .
  • Optimizing rendering with
    ChangeDetectionStrategy.OnPush
    .
  • 设计组件层级结构。
  • 实现智能/哑组件模式。
  • 使用
    @if
    @for
    等现代控制流语法。
  • 利用
    ChangeDetectionStrategy.OnPush
    优化渲染性能。

Guidelines

指导原则

1. Atomic Design Categorization Rules

1. 原子设计分类规则

  • Atoms (Building Blocks):
    • MUST NOT depend on any other component.
    • MUST NOT have internal domain logic.
    • MUST be keyboard-navigable and have ARIA labels if icon-only.
  • Molecules (Functional Groups):
    • MUST consist of at least one Atom.
    • Represents a single UI pattern (e.g., a search bar = input atom + button atom).
  • Organisms (Complex Sections):
    • CAN contain Atoms, Molecules, and other Organisms.
    • Distinct reusable section (e.g., Header, Data Grid).
    • Template size MUST NOT exceed 200 lines.
  • 原子(基础构建块)
    • 不得依赖任何其他组件。
    • 不得包含内部领域逻辑。
    • 必须支持键盘导航,纯图标组件需添加ARIA标签。
  • 分子(功能组)
    • 必须包含至少一个原子组件。
    • 代表单一UI模式(例如,搜索栏 = 输入框原子组件 + 按钮原子组件)。
  • 有机体(复杂区块)
    • 可包含原子、分子及其他有机体组件。
    • 独立的可复用区块(例如,页头、数据表格)。
    • 模板代码长度不得超过200行

2. UI Quality & A11y

2. UI质量与可访问性

[!IMPORTANT] Accessibility is NOT optional. Components must be keyboard-focusable and use semantic HTML.
  • Semantic HTML: Prioritize
    <button>
    ,
    <nav>
    ,
    <main>
    .
  • Strict Separation: Every component MUST have its own
    .ts
    ,
    .html
    ,
    .scss
    , and
    .spec.ts
    files. NO inline templates or styles.
  • Change Detection:
    ChangeDetectionStrategy.OnPush
    is mandatory for all UI components.
[!重要提示] 可访问性是强制要求。组件必须支持键盘聚焦,并使用语义化HTML。
  • 语义化HTML:优先使用
    <button>
    <nav>
    <main>
    等标签。
  • 严格分离原则:每个组件必须拥有独立的
    .ts
    .html
    .scss
    .spec.ts
    文件。禁止使用内联模板或样式。
  • 变更检测:所有UI组件必须强制使用
    ChangeDetectionStrategy.OnPush

Constraints / MUST NOT DO

约束条件 / 禁止事项

  • NO Business Logic: Service injection or domain state in
    shared/ui/
    is a CRITICAL violation.
  • NO Default detection: Prohibited.
  • NO Signal Decorators: Use
    input()
    ,
    output()
    , and
    model()
    signals ONLY.
  • 禁止业务逻辑:在
    shared/ui/
    目录下注入服务或存储领域状态属于严重违规。
  • 禁止默认检测策略:禁用默认变更检测。
  • 禁止Signal装饰器:仅可使用
    input()
    output()
    model()
    信号。