chore: enhance UI development guidelines with component hierarchy and feature organization#25060
chore: enhance UI development guidelines with component hierarchy and feature organization#25060georgewrmarshall merged 4 commits intomainfrom
Conversation
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
| globs: 'app/*.{tsx,ts,jsx,js}' | ||
| globs: | ||
| - 'app/**/*.{tsx,jsx}' |
There was a problem hiding this comment.
Fixes glob pattern
| ### The Rule: Check Design System First | ||
| **Before writing any new component or choosing what to use, ask: "Does @metamask/design-system-react-native have this?"** | ||
|
|
||
| 1. **FIRST**: Use `@metamask/design-system-react-native` components |
There was a problem hiding this comment.
Prioritise @metamask/design-system-react-native components
| 1. **FIRST**: Use `@metamask/design-system-react-native` components | ||
| 2. **SECOND**: Use `app/component-library` components only if design system lacks the component | ||
| 3. **LAST RESORT**: Custom components with StyleSheet (avoid unless absolutely necessary) | ||
| - **Always use for**: Box (layout), Text (typography), Button/ButtonBase/ButtonIcon, Icon, Checkbox |
There was a problem hiding this comment.
Regarding ButtonBase, we only want it used when Button or other app/feature buttons don’t meet the need. It could be a good option for custom buttons that follow the same shape and size as Button, but don’t fit an existing variant or pattern. In those cases, use ButtonBase to create a feature-specific button. 🤔
| - **Examples**: `BridgeInputSelector`, `StakeInputView`, `NFTDetailsModal`, `PerpsTradingCard`, `PredictionMarketOrderPanel` | ||
| - **Location**: Can live in feature directories (`app/components/Views/*/components/`, `app/features/*/`) | ||
| - **Rule**: Must be built using Box, Text, and other design system primitives - NO raw View/Text or StyleSheet | ||
| - **Reuse**: Check if a feature-specific component already exists in the feature's directory before building a new one. These components should be reused within their feature domain. |
There was a problem hiding this comment.
I think this was an important addition we still want to use feature specific components where appropriate
| 4. **LAST RESORT**: Custom components with StyleSheet | ||
| - **Only when**: Highly specialized one-off needs with no design system equivalent AND no component-library equivalent | ||
| - **Requires**: Strong justification why design system primitives can't be composed |
There was a problem hiding this comment.
Not sure if we need to give an example here. Maybe complex animations?
| ├─ Is it BottomSheet, Tabs, Header, ListItem, Skeleton, Tag, Modal, etc? | ||
| │ └─ YES → Use app/component-library [STOP] |
There was a problem hiding this comment.
Will need to update this rule as we release more @metamask/design-system-react-native components 🤔
| ## Component Documentation Access | ||
|
|
||
| ### Type Definitions & JSDoc Comments | ||
| All @metamask/design-system-react-native components have comprehensive TypeScript definitions with JSDoc comments: | ||
|
|
||
| - **Box**: `/node_modules/@metamask/design-system-react-native/dist/components/Box/Box.types.d.cts` | ||
| - **Text**: `/node_modules/@metamask/design-system-react-native/dist/components/Text/Text.types.d.cts` | ||
| - **Button**: `/node_modules/@metamask/design-system-react-native/dist/components/Button/Button.types.d.cts` | ||
|
|
||
| When unsure about component APIs: | ||
| 1. Read the `.types.d.cts` files for complete prop documentation | ||
| 2. Reference `app/component-library/components/design-system.stories.tsx` for usage examples | ||
| 3. Check GitHub source: https://github.com/MetaMask/metamask-design-system/tree/main/packages/design-system-react-native/src/components | ||
|
|
||
| ### Box Component Quick Reference | ||
| - **Spacing**: Use `gap`, `padding*`, `margin*` props with values 0-12 (maps to 0px-48px) | ||
| - **Flexbox**: Use `flexDirection`, `alignItems`, `justifyContent` enum props | ||
| - **Colors**: Use `backgroundColor` and `borderColor` with semantic tokens | ||
| - **Tailwind**: Use `twClassName` for utilities not covered by props |
There was a problem hiding this comment.
Not sure if this helps the agent or if it’ll handle it by default, but I don’t think there’s any harm in specifying it. We keep most of our comprehensive docs in READMEs in the repo, so it’s worth thinking about how we can make those accessible to the agent. For now, I’ve added the link to the components folder:
https://github.com/MetaMask/metamask-design-system/tree/main/packages/design-system-react-native/src/components
| > | ||
| ``` | ||
|
|
||
| ## Box Component Best Practices |
There was a problem hiding this comment.
Adding Box component best practices here to encourage the use of Box props. This should help with code sharing across platforms as we have Box available in both. They have the same component api
| | Manual padding/margin | `twClassName="p-4 m-2"` | | ||
|
|
||
| ## Error Prevention | ||
| ## Legacy Code Migration Guidelines |
There was a problem hiding this comment.
This could probably become its own doc eventually, though I’m not sure engineers will have time to migrate files they’re actively working on. There’s not much incentive to do it beyond good engineering practices and reducing tech debt.
Remove example directory structure that doesn't reflect actual codebase organization. Keep focus on principles rather than specific paths.
Remove entire section about feature organization since: - app/features/ only contains SampleFeature (dev/test only) - Actual features live in app/components/Views/[FeatureName]/ - Simplified tier 3 to just mention typical location - Updated decision tree to reference actual path pattern - Removed hypothetical Perps/Predictions examples Keep focus on principles (check for existing, reuse, use design system) without prescribing specific organizational structure.
Remove all prescriptive location guidance for where feature UI should live: - Removed 'Location: Typically in app/components/Views/[FeatureName]/components/' - Changed decision tree from specific path to 'search codebase for similar components' Per SampleFeature README, real features are distributed across /app/components/, /app/reducers/, /app/core/controllers/, etc. - not in a prescribed structure. Keep focus on principles (reuse, search first, use design system) without prescribing organizational structure.
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsThe only changed file is
This is a zero-risk change that only affects developer tooling (specifically Cursor AI suggestions). No E2E tests are needed to validate this change. |
|



Description
Enhanced the UI development guidelines in
.cursor/rules/ui-development-guidelines.mdcto provide comprehensive guidance for component selection, reuse, and organization. This update addresses critical issues with the glob pattern matching and adds extensive documentation for working with the design system, component library, and feature-specific components.Key improvements:
app/*.{tsx,ts,jsx,js}(matched 0 files) toapp/**/*.{tsx,jsx}(now matches 2,893 UI component files)Changelog
CHANGELOG entry: null
Related issues
Fixes: N/A (Internal documentation improvement)
Manual testing steps
Screenshots/Recordings
N/A - Documentation only change
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Updates
.cursor/rules/ui-development-guidelines.mdcwith comprehensive, enforceable guidance.app/**/*.{tsx,jsx}to correctly target all UI files@metamask/design-system-react-nativetwClassName, spacing, color tokens)Written by Cursor Bugbot for commit a7b3c7b. This will update automatically on new commits. Configure here.