feat: add component-creation.md cursor rule#911
Conversation
📖 Storybook Preview |
648b2b5 to
ec1fca7
Compare
📖 Storybook Preview |
📖 Storybook Preview |
📖 Storybook Preview |
📖 Storybook Preview |
| @@ -1,38 +1,22 @@ | |||
| // Import shared type for extension | |||
There was a problem hiding this comment.
moved these changes into a separate PR #912
a897c3f to
468efc2
Compare
📖 Storybook Preview |
## Changes ### Critical Fixes - Fix `interface` → `type` inconsistency in component-architecture.md - All shared props now use `type` not `interface` (aligns with ESLint rule) - Updated 6 instances across the file - Replace duplicated BadgeStatus examples with @ references - Removed ~125 lines of duplicated code across files - Now references actual implementation as SOURCE OF TRUTH ### Code Duplication Reduction - Consolidate Button type examples across 3 files - Reference BadgeStatus golden path instead of duplicating patterns - Consolidate styling examples - Reference WalletHome.stories.tsx and styling.md instead of duplicating ### Clarity Improvements - Add prominent BadgeStatus golden path callouts - Clearly marked as "THE proof-of-concept" and "SOURCE OF TRUTH" - Added in component-architecture.md, component-creation.md, component-enum-union-migration.md - Add warnings to template references -⚠️ callouts explaining templates are NOT ADR-compliant - 4 transformation steps required after scaffolding - Enhance story naming examples - Added 5 concrete examples (variant → Variant, size → Size, etc.) ## Benefits - Reduced maintenance: Code examples reference actual implementations - Single source of truth: BadgeStatus is THE canonical example - Consistency: All docs use same patterns - Clarity: AI agents get non-contradictory guidance - Up-to-date: References stay current automatically ## Files Modified - .cursor/rules/component-architecture.md - .cursor/rules/component-creation.md - .cursor/rules/component-migration.md - .cursor/rules/component-enum-union-migration.md - .cursor/rules/component-documentation.md 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
📖 Storybook Preview |
georgewrmarshall
left a comment
There was a problem hiding this comment.
Left some comments
| - ADR-0003: String unions with const objects (no enums) | ||
| - ADR-0004: Centralized types in shared package |
There was a problem hiding this comment.
Why aren't we linking out to these?
|
|
||
| ### Reference | ||
|
|
||
| [ADR-0003: Enum to String Union Migration](https://github.com/MetaMask/decisions/pull/127) |
There was a problem hiding this comment.
Should we just link to the document instead of the PR https://github.com/MetaMask/decisions/blob/main/decisions/design-system/0003-enum-to-string-union-migration.md
|
|
||
| ### Reference | ||
|
|
||
| [ADR-0004: Centralized Types Architecture](https://github.com/MetaMask/decisions/pull/128) |
There was a problem hiding this comment.
|
|
||
| ### Pattern | ||
|
|
||
| ```tsx |
There was a problem hiding this comment.
Do we need these code examples or can we rely on either the ADR link or BadgeStatus component?
| - **Shared interface**: `ComponentNamePropsShared` (with "Shared" suffix) | ||
| - **Platform interface**: `ComponentNameProps` (final exported type, no suffix) |
There was a problem hiding this comment.
non-blocking: This is a good piece of information that is not documented anywhere that I'm aware. Should we create a template or script for this in @metamask/design-system-shared?
|
|
||
| ### Platform Types (Layered Architecture) | ||
|
|
||
| - [ ] Platform packages import shared type for extension |
There was a problem hiding this comment.
| - [ ] Platform packages import shared type for extension | |
| - [ ] Platform packages import shared type |
|
|
||
| - [ADR-0003: Enum to String Union Migration](https://github.com/MetaMask/decisions/pull/127) | ||
| - [ADR-0004: Centralized Types Architecture](https://github.com/MetaMask/decisions/pull/128) | ||
| - [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs/) |
There was a problem hiding this comment.
Again this rule is huge we need to cut it down
|
|
||
| Common examples: | ||
|
|
||
| - BadgeStatus, AvatarAccount, Button (if using old enums) |
There was a problem hiding this comment.
BadgeStatus is the only one for now
| - BadgeStatus, AvatarAccount, Button (if using old enums) | |
| - BadgeStatus |
|
|
||
| ### MetaMask Standards | ||
|
|
||
| - [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs/) |
There was a problem hiding this comment.
Again some common issues, too many code examples that repeat existing golden path examples. Rule is too large 400 lines
| | Concern | Extension API | Mobile API | Decision | | ||
| | -------------- | -------------------- | ---------------------- | ------------------------- | | ||
| | Prop: variant | `variant?: string` | `type?: ButtonType` | Use `variant` | | ||
| | Prop: size | `size?: Size` | Not present | Add to both | | ||
| | Prop: disabled | `disabled?: boolean` | `isDisabled?: boolean` | Use `isDisabled` | | ||
| | Prop: onPress | `onClick` | `onPress` | Keep both (platform) | | ||
| | Styling | className | style object | Use className/twClassName | |
There was a problem hiding this comment.
For the initial migration we are going to accept component api inconsistencies for speed. We are then going to migrate them to have a shared API and consolidate and align later. See the migration process doc. Read this https://github.com/MetaMask/metamask-design-system/blob/296342a7bdab674db71e45f47506f8d35e7100e3/docs/component-migration-strategy.md
Address PR review feedback from georgewrmarshall: - Add ADR links in Purpose section of component-architecture.md - Update all ADR references from PR links to main branch document links - Ensures documentation remains accessible even after PRs are merged Changes: - component-architecture.md: Added clickable ADR links in Purpose section (lines 9-10) - Updated ADR-0003 reference from PR #127 to document link (line 58) - Updated ADR-0004 reference from PR #128 to document link (line 166) - Updated References section ADR links (lines 398-399) - component-creation.md: Updated ADR links in MetaMask Standards section - component-migration.md: Updated ADR links in Architecture Decision Records section - component-enum-union-migration.md: Updated ADR links in Architecture Decision Records section All ADR references now point to: - https://github.com/MetaMask/decisions/blob/main/decisions/design-system/0003-enum-to-string-union-migration.md - https://github.com/MetaMask/decisions/blob/main/decisions/design-system/0004-centralized-types-architecture.md Related: #911 (review comments)
📖 Storybook Preview |
Following ai-agents.md principle: '200-400 lines per file (checklists, not novels)' Changes: - component-creation.md: 661 → 355 lines (46% reduction) - Replaced full code examples with references to BadgeStatus - Merged React/React Native steps (95% identical) - Condensed tutorials to actionable checklists - component-migration.md: 440 → 332 lines (24% reduction) - Condensed audit phase tutorial to checklist - Referenced component-creation.md and styling.md for implementation - Collapsed scenarios to decision tree - component-enum-union-migration.md: 403 → 218 lines (46% reduction) - Referenced component-architecture.md for all patterns - Removed duplicated type examples - Converted steps to workflow checklist - figma-integration.md: 423 → 303 lines (28% reduction) - Combined six prop mapping examples into one comprehensive - Removed repetitive wizard steps - Streamlined critical rules to checklist Total: 2,730 → 2,011 lines (26% reduction, 719 lines saved) All files now closer to 200-400 line target while maintaining effectiveness as AI agent guardrails using 'reference over duplication' principle.
Following ai-agents.md principle: '200-400 lines per file (checklists, not novels)' Changes: - component-architecture.md: 410 → 168 lines (59% reduction) Condensation strategies: - Removed ADR benefits/usage sections, linked to ADRs instead - Condensed full three-layer example to minimal pattern + reference - Merged decision table + quick rules - removed redundancy - Kept BadgeStatus references prominent Final status: ALL cursor rules files now within 200-400 line target: 109 component-documentation.md 168 component-architecture.md ✅ 224 component-enum-union-migration.md 284 styling.md 306 figma-integration.md 342 component-migration.md 357 component-creation.md 1790 total (was 2730, saved 940 lines / 34% reduction)
📖 Storybook Preview |
Updated cursor rules to document correct export pattern: - Component index.ts exports directly from @metamask/design-system-shared - Platform src/types/index.ts should NOT re-export shared types - Added verification checklist items for correct pattern Files updated: - component-enum-union-migration.md: Updated step 4, added step 5 - component-architecture.md: Added "Component Index Export Pattern" section - component-creation.md: Added checklist item for export pattern 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Updated component creation documentation to prevent duplicate enum exports that reduce test coverage: - component-creation.md: Added critical warning that .types.ts files should ONLY import, never re-export enums. Enums exported from index.ts only. - component-enum-union-migration.md: Clarified migration pattern with explicit examples showing .types.ts import-only pattern. - Added anti-pattern sections showing the exact issue that caused BadgeCount coverage loss. Pattern: - .types.ts: Import only (prevents duplicate exports) - index.ts: Single export location for enums (single source of truth) This prevents Jest coverage failures from uncovered duplicate export paths.
📖 Storybook Preview |
Replaced "enum" terminology with "const object" throughout documentation to accurately reflect ADR-0003 pattern and avoid confusion with TypeScript enums. Updated terminology: - "enum exports" → "const object exports" - "enum re-exports" → "const object re-exports" - "design token enums" → "design token const objects" Preserved "enum" only when referring to: - TypeScript enums in anti-pattern examples - File names (component-enum-union-migration.md) - ADR-0003 title references - Old TypeScript enums being migrated/removed This clarifies that we're working with const objects (as const), not TypeScript enums, making the documentation more precise and educational.
📖 Storybook Preview |
|
Broken out and merged as separate PRs |
Description
Adds comprehensive cursor rule for component creation incorporating ADR-0003 (enum to string union migration), ADR-0004 (centralized types architecture), and platform-specific props patterns. Includes proof-of-concept BadgeStatus migration demonstrating the complete architectural approach.
Key insight: The rule focuses on what to do after running
create-componentscripts, since the generated templates don't yet implement these patterns. This ensures the rule stays relevant even as templates evolve.What Changed
Component Creation Cursor Rule:
.cursor/rules/component-creation.md(600+ lines)BadgeStatus Migration (Proof-of-Concept):
classNameand React-specific propstwClassNameand React Native propsUpdated CLAUDE.md:
component-creation.mdrulecreate-component:react-nativecommandPlatform-Specific Props (Layered Architecture)
New guidance for handling cross-platform differences while maximizing consistency:
BadgeStatusStatus,ButtonVariant,ButtonSizeisDisabled,isLoading,isSelectedchildren,label,descriptiononClick/onPress,onFocus/onBlurclassName/twClassNameComponentProps<'div'>/ViewPropshtmlFor,testID, accessibility propsPhilosophy: Use idiomatic platform APIs (onClick vs onPress) rather than unified abstractions. This maintains platform conventions and developer familiarity.
Key Architectural Patterns
ADR-0003 Pattern (Const Objects with String Unions):
ADR-0004 Pattern (Centralized Types):
Before/After Comparison (BadgeStatus)
Before (Duplicated Enums in Each Platform):
packages/design-system-react/src/types/index.ts:packages/design-system-react-native/src/types/index.ts:After (Shared Source + Platform Extensions):
packages/design-system-shared/src/types/BadgeStatus/:className/twClassNameWhy Reference-Based Instead of Duplicating Templates?
The rule is intentionally reference-based rather than duplicating template content:
✅ Stays maintainable - Template updates don't require rule updates
✅ Focuses on gaps - Guides patterns NOT in templates (ADR-0003/0004)
✅ Post-generation workflow - What to do after scripts run
✅ Explicit about template limitations - "Templates DO NOT include this pattern yet"
Testing Results
yarn build)yarn test)yarn lint)Related issues
Relates to:
Manual testing steps
Test Component Creation Workflow:
yarn create-component:reactandyarn create-component:react-native@metamask/design-system-sharedVerify BadgeStatus Migration:
yarn buildyarn testyarn lintBadgeStatusStatusfrom both React and React Native packagesCheck Cross-Platform Consistency:
BadgeStatusPropsSharedexportsScreenshots/Recordings
Before
Component creation rule existed but was missing:
After
Component creation rule provides:
Pre-merge author checklist
Pre-merge reviewer checklist
🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com
Note
Low Risk
Documentation-only changes (Cursor/agent rules and guides) with no runtime, API, or build logic modifications.
Overview
Adds new Cursor rule documentation for component work in the monorepo: a foundational architecture rule (
component-architecture.md) covering ADR-0003/0004 patterns, layered shared-vs-platform props, and export conventions; plus workflows forcomponent-creation.md(post-scaffold steps) andcomponent-migration.md(extension/mobile → monorepo) and an internal refactor guide (component-enum-union-migration.md).Updates existing docs to align with these workflows: clarifies Storybook story naming examples in
component-documentation.md, streamlines and tightens thefigma-integration.mdCode Connect checklist/patterns, and updatesCLAUDE.md+docs/ai-agents.mdto reference the new rule files and include thecreate-component:react-nativecommand.Written by Cursor Bugbot for commit 61d44a3. This will update automatically on new commits. Configure here.