Skip to content

francostan/composition-pattern-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Composition Pattern Starter (Fernando Rojo Talk Based)

Learn and build with the LEGO blocks philosophy for React components

License: MIT Next.js React

Live Demo β†’


✨ Features

  • 🎯 True composition pattern - Based on Fernando Rojo's talk
  • 🧩 Granular LEGO blocks - 13 Settings components, 8 Composer components
  • πŸ“š Interactive learning - Live examples + before/after comparisons
  • ⚑ React 19 + Compiler - Auto-optimization, no manual memoization
  • 🎨 Modern stack - Next.js 15, TypeScript, Tailwind, shadcn/ui
  • βœ… Production-ready - Tested, accessible, performant

πŸš€ Quick Start

# Clone
git clone https://github.com/francostan/composition-pattern-starter.git
cd composition-pattern-starter

# Install
npm install

# Run
npm run dev

Open http://localhost:3000


πŸ“– Learn the Pattern

  1. Theory β†’ Read docs/Pattern.md
  2. Practice β†’ Try /examples
  3. Compare β†’ See /comparison
  4. Build β†’ Use as LEGO blocks!

🧩 What's Inside

Composer (8 blocks)

Message composer with attachments, character count, keyboard shortcuts

  • Provider, Frame, Header, Input, Footer, AttachButton, Attachments, SendButton

Settings (13 blocks)

Flexible form/dialog system

  • Provider, Dialog, Trigger, Content, Header, Body, Section, TextField, Toggle, Footer, ResetButton, SaveButton, useSettings

Pages

  • / - Homepage with overview
  • /examples - 3 configurations showing flexibility
  • /comparison - Before/after + LEGO philosophy tabs

πŸ› οΈ Tech Stack

  • Framework: Next.js 15 (App Router, Turbopack)
  • React: 19.1.0 with React Compiler
  • Language: TypeScript (strict mode)
  • Styling: Tailwind CSS v4 + shadcn/ui
  • Linting: Biome (replaces ESLint + Prettier)
  • State: Context API + nuqs

πŸ“‚ Structure

β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ page.tsx              # Homepage
β”‚   β”œβ”€β”€ examples/page.tsx     # Live examples
β”‚   β”œβ”€β”€ comparison/page.tsx   # Comparisons
β”‚   └── layout.tsx            # Root layout
β”œβ”€β”€ components/
β”‚   β”œβ”€β”€ composer/             # 8 files (1 per block)
β”‚   β”œβ”€β”€ settings-dialog/      # 13 files (1 per block)
β”‚   └── ui/                   # shadcn/ui components
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ Pattern.md            # Composition guide
β”‚   └── Rules.md              # UX guidelines
└── lib/
    └── utils.ts              # Helpers

🎨 Pattern in 3 Steps

// 1. Organize context: state/actions/meta
const value = {
  state: { /* data */ },
  actions: { /* functions */ },
  meta: { /* refs, config */ }
}

// 2. Export with dot notation
export const Component = {
  Provider,
  SubComponent,
}

// 3. Compose freely
<Component.Provider>
  <Component.SubComponent />
</Component.Provider>

See docs/Pattern.md for complete guide.


πŸ§ͺ Examples

Full Settings Dialog

<Settings.Provider initialState={{ username: "john" }}>
  <Settings.Dialog>
    <Settings.Trigger><Button>Open</Button></Settings.Trigger>
    <Settings.Content>
      <Settings.Header title="Settings" />
      <Settings.Body>
        <Settings.TextField name="username" label="Username" />
        <Settings.Toggle name="darkMode" label="Dark mode" />
      </Settings.Body>
      <Settings.Footer>
        <Settings.ResetButton />
        <Settings.SaveButton />
      </Settings.Footer>
    </Settings.Content>
  </Settings.Dialog>
</Settings.Provider>

Inline Preferences (No Dialog!)

<Settings.Provider initialState={{ alerts: true }}>
  <Settings.Body>
    <Settings.Toggle name="alerts" label="Email alerts" />
    <Settings.Toggle name="push" label="Push notifications" />
  </Settings.Body>
  <Settings.SaveButton />
</Settings.Provider>

See /examples for more configurations.


🀝 Contributing

Contributions welcome! Here's how:

Quick Start

  1. Fork the repo
  2. Create branch: git checkout -b feature/my-feature
  3. Make changes
  4. Lint: npm run lint
  5. Build: npm run build
  6. Commit: git commit -m "Add my feature"
  7. Push and create PR

Guidelines

  • βœ… Follow existing patterns (state/actions/meta)
  • βœ… Use TypeScript
  • βœ… Keep components small and focused
  • βœ… Add examples for new patterns
  • βœ… Run lint before committing
  • βœ… One feature per PR

Code Style

  • Export with dot notation
  • Organize as state/actions/meta
  • No prop drilling
  • Use React Compiler (no manual memoization)

Need Help?

Open an issue or reach out to @francostan


πŸ“ Scripts

npm run dev      # Development server
npm run build    # Production build
npm run start    # Production server
npm run lint     # Run Biome linter
npm run format   # Format code with Biome

πŸš€ Deployment

Vercel (Recommended)

# Install Vercel CLI
npm i -g vercel

# Deploy
vercel

# Production
vercel --prod

Or connect your GitHub repo to Vercel for automatic deployments.

Environment Variables

None required for basic setup!


πŸ“„ License

MIT Β© francostan

See LICENSE for details.


πŸ™ Credits

  • Pattern: Fernando Rojo's composition talk
  • UI: shadcn/ui
  • Inspiration: React community

🎯 Project Goals

This template serves three purposes:

  1. πŸ“š Educational - Learn composition patterns through examples
  2. πŸ› οΈ Practical - Copy production-ready components
  3. 🀝 Community - Open for contributions

πŸ’¬ Community


Made with ❀️ by francostan

About

Composition Pattern Starter (Fernando Rojo Talk Based). Learn and build with the LEGO blocks philosophy for React components

Resources

License

Contributing

Stars

21 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors