Custom Components
We distinguish between two types of custom components, each with different processes and expectations.
Component Types
A) Project-Specific Custom Components
Components built for a specific project or screen, not intended for reuse across other projects.
Examples:
A
Boxwith special layout used within one projectA
Cardvariant with bespoke layout for one project's screensProject-specific data visualizations
One-off layout components
When to use:
Component solves a problem unique to one project
Unlikely to be needed in other projects
Too specific to generalize
B) UI2 Candidate Components
Components intended for reuse across multiple projects and products.
Examples:
Navbar- Site-wide navigationUserMenu- User account menuStandardized
ModaldialogsComponents being migrated from UI1
When to use:
Component will be used in multiple projects
Represents a common Decentraland pattern
Replaces or extends a UI1 component
Project-Specific Components
Requirements
Use MUI as Base
MUST extend existing MUI components whenever possible:
Don't fork or duplicate patterns that MUI already covers:
Use
Cardinstead of creating a custom box with shadowsUse
Buttoninstead of creating a styled anchorUse
TextFieldinstead of creating a custom inputExtend
Dialoginstead of creating a custom modal
Theme Values Only
MUST use values from the UI2 theme:
No arbitrary values allowed:
Colors: Use
theme.paletteordclColorsSpacing: Use
theme.spacing(n)Border radius: Use
theme.shape.borderRadiusTypography: Use
theme.typographyvariantsBreakpoints: Use
theme.breakpointshelpers
States and Accessibility
MUST define and implement all interactive states:
MUST implement basic accessibility:**
Keyboard navigation - Focusable and operable with keyboard
Focus indicators - Visible focus states
ARIA labels - Where text isn't visible
Semantic HTML - Use appropriate elements
Color contrast - Meet WCAG AA standards
Example: Project-Specific Component
UI2 Candidate Components
Components that will be shared across projects require higher standards and more thorough documentation.
Requirements
Theme Alignment
MUST rely exclusively on UI2 theme values:
Storybook Coverage
MUST add comprehensive Storybook stories:
Required coverage:
All props and variants
Every prop combination
All size variants
All color variants
All states
Idle/default
Loading
Error
Disabled
Hover (via pseudo states addon)
Focus (via pseudo states addon)
Interactions
Click handlers
Form submissions
Keyboard navigation
Color schemes
Light mode
Dark mode
Responsive behavior
Key breakpoints (xs, md, lg)
Document behavior at each breakpoint
Example Storybook file:
Component Structure
UI2 candidate components SHOULD follow this structure:
Documentation Requirements
MUST include in component README:
Purpose - What problem does this solve?
Usage - How to use the component
Props - All props with types and descriptions
Examples - Common use cases
Accessibility - Keyboard support, ARIA labels
Theming - Which theme values it uses
Migration notes - If replacing a UI1 component
Example README:
Testing Requirements
MUST include tests for:
Prop rendering
User interactions
Accessibility features
Responsive behavior
Error states
Decision Matrix
Use this to decide which type of component to create:
Will other projects use this?
No
Yes
Does UI1 have an equivalent?
N/A
Probably
Needs Storybook documentation?
No
Yes
Needs comprehensive tests?
Basic
Extensive
Design review required?
Project-level
UI2-level
Can use project-specific patterns?
Yes
No
Must work in all themes?
No
Yes
Approval Process
Project-Specific Components
Code review by project maintainer
Verify theme compliance
Test in project context
Merge when approved
UI2 Candidate Components
Design review and approval
Technical design review
Implementation
Storybook stories
Comprehensive tests
Accessibility review
Code review
PR to UI2 repository
Version and publish
Update dependent projects
Best Practices
Composition Over Customization
Progressive Enhancement
Start simple and add features as needed:
Basic version with core functionality
Add responsive behavior
Add accessibility features
Add advanced interactions
Optimize performance
Documentation First
Before writing code:
Write component README
Define props interface
List required states
Plan Storybook stories
Then implement
Next Steps
Review Styling & Theming for implementation details
See Migration Guide for UI1 to UI2 migrations
Check Process Overview for the full workflow
Last updated