Component Structure
Components are organized insrc/components/ by category:
Creating a Basic Component
Create the component file
Create a new file in the appropriate subdirectory:
src/components/badge/Badge.tsx
Add TypeScript types
Always use TypeScript for type safety. Extend existing component types when appropriate:
Styled-Components Patterns
Using the Theme
Always use the theme for colors, breakpoints, and other design tokens:Transient Props
Use$ prefix for props that shouldn’t be passed to the DOM:
src/components/card/Card.ts:8.
Hover States
Use thewithHover mixin for consistent hover interactions:
src/components/button/Button.tsx:121.
Nested Context
Style components differently based on their parent:src/components/button/Button.tsx:134.
Real Example: Button Component
Here’s how the Button component is structured:src/components/button/Button.tsx
src/components/button/Button.tsx:1.
Component Organization
File Naming
- Use PascalCase for component files:
Button.tsx,AnimeSummaryCard.tsx - Use camelCase for utility files:
extractImages.ts,getSharedPageProps.ts - Group related components in subdirectories
Export Pattern
GraphQL Fragments
Attach GraphQL fragments to components that need them:Best Practices
- Use TypeScript for all components
- Prefix transient props with
$to prevent DOM warnings - Use the theme for all colors, spacing, and breakpoints
- Use
withHovermixin for hover states - Keep components small and focused on a single responsibility
- Use
ComponentPropsWithRefto support ref forwarding - Add accessibility attributes (
aria-label,role, etc.) - Test responsive behavior using theme breakpoints
Next Steps
- Learn about adding pages
- Understand working with the API
- Read about deployment