What is a Theme?
A theme is a collection of React components that define how your store looks and feels. Themes:- Override default UI components with custom designs
- Use Tailwind CSS for styling
- Support TypeScript for type-safe development
- Are modular - only override components you need
- Work with areas - inject components into predefined page areas
Directory Structure
A typical theme follows this structure:Creating Your First Theme
Creating Theme Components
Theme components are React components that render on specific pages. Each component must export:- Default export - The React component
- layout export - Defines where and when the component renders
- query export (optional) - GraphQL query for data fetching
Component Structure
Here’s a real example from theanasuplements theme:
src/pages/all/Header.tsx
Layout Configuration
Thelayout export defines where your component appears:
Page Areas
EverShop uses a component area system. Common areas include:Directory Organization
Theme components are organized by page type:Global Components (all/)
Components insrc/pages/all/ appear on every page:
Area-Specific Components
Components for specific areas (frontStore, admin):Page-Specific Components
Components for specific pages:Working with Data
Use thequery export to fetch data with GraphQL:
src/pages/frontStore/productView/SupplementInfo.tsx
The
query export uses GraphQL to fetch data. Props are automatically passed to your component.Styling with Tailwind CSS
All themes use Tailwind CSS for styling:Custom Colors
Use custom color values with bracket notation:Responsive Design
Use responsive modifiers:Real-World Example: Ana’s Supplements Theme
Theanasuplements theme demonstrates a complete theme implementation:
Best Practices
- Use TypeScript - Define proper types for props
- Responsive First - Design for mobile, then scale up
- Accessibility - Use semantic HTML and ARIA labels
- Performance - Optimize images and minimize bundle size
- Consistent Styling - Use a consistent color palette and spacing
Troubleshooting
Component Not Rendering
- Verify the
layoutexport is present - Check that
areaIdmatches a valid area - Ensure the component is in the correct directory
- Run
npm run buildto recompile
Styles Not Applying
- Verify Tailwind CSS classes are correct
- Check for typos in class names
- Ensure custom colors use bracket notation:
bg-[#FFFFFF]
Data Not Loading
- Verify the GraphQL query is valid
- Check that field names match the schema
- Test the query in GraphQL playground
Next Steps
Page Components
Deep dive into page component architecture
Tailwind Design System
Learn about the Tailwind design system