041
LVL 02 — CIRCUIT BREAKER SESSION 041 DAY 41

COMPONENT LIBRARY

🎫 PIXELCRAFT-029
Feature | 🟠 Hard | Priority: 🟠 High

Decompose PixelCraft into reusable React components. Build: Header, Toolbar, ToolButton, CanvasArea, SettingsPanel, FilterSlider, Toast, Modal.
CONCEPTS.UNLOCKED
🌳
Component Decomposition
Breaking a UI into a tree of components. Each component is a self-contained piece: its own markup, logic, and styling. The tree mirrors the visual hierarchy of the app.
📦
Props in Depth
Any data type as prop: strings, numbers, arrays, objects, functions. Props are how parent components configure child components. They flow one direction: parent → child.
🪆
Children
<Panel>{content}</Panel> — composing components by nesting. The special children prop lets a component wrap arbitrary content. Enables flexible, slot-based composition.
📁
Component Files
One component per file, clean imports/exports. ToolButton.jsx exports ToolButton. App.jsx imports it. Clear boundaries, easy to find, easy to test.
🏗
Component Tree Design
Draw the tree before writing code. Which components are reusable? Which are page-specific? Where does data flow? The tree is your architecture blueprint.
🔐
PropTypes / TypeScript
Declare what props a component expects: name: string, onClick: function, active: boolean. Catch bugs at development time instead of runtime. Brief intro — deeper in later sessions.
HANDS-ON.TASKS
01
Draw the Component Tree
App ├── Header (logo, project name, user menu) ├── Toolbar (list of ToolButtons) │ └── ToolButton (icon, name, active state, click) ├── CanvasArea (canvas element, zoom controls) ├── SettingsPanel (list of FilterSliders) │ ├── FilterSlider (label, range, value display) │ └── ResetButton ├── Toast (message, type, auto-dismiss) └── Modal (title, content, close button)
Draw this on paper first. The tree shows parent-child relationships — data flows DOWN from App through each branch. This blueprint guides every file you create.
02
Build Each Component as a Separate File

Create each component in /components/:

src/components/ ├── Header.jsx ├── Toolbar.jsx ├── ToolButton.jsx ├── CanvasArea.jsx ├── SettingsPanel.jsx ├── FilterSlider.jsx ├── Toast.jsx └── Modal.jsx

Each file exports one component. Each component receives all its data through props.

03
Compose in App.jsx
function App() { return ( <div className="app-container"> <Header /> <Toolbar tools={toolList} /> <CanvasArea /> <SettingsPanel filters={filterList} /> </div> ); }
App is the top-level orchestrator — like app.js from Session 31. It imports all components and wires them together. No business logic in App — just composition.
04
Make Components Configurable via Props

Every component should be configurable through props — not hardcoded. ToolButton takes name, icon, onClick, active. FilterSlider takes label, min, max, value, onChange. Toast takes message, type, onDismiss.

05
Render the Full PixelCraft Layout

All 8 components composed into the full PixelCraft UI. The layout should visually match the vanilla version: header at top, toolbar on left, canvas center, settings panel on right.

06
Close the Ticket
git switch -c feature/PIXELCRAFT-029-component-library git add src/components/ src/App.jsx git commit -m "Build 8-component library for PixelCraft React (PIXELCRAFT-029)" git push origin feature/PIXELCRAFT-029-component-library # PR → Review → Merge → Close ticket ✅
CS.DEEP-DIVE

Component composition is the UI equivalent of function composition.

Small, focused, reusable parts combined into complex wholes.

// The same principle everywhere:

Unix philosophy    → small tools, piped together
Microservices      → small services, composed
LEGO               → small bricks, built up
React              → small components, nested

// Composability is the most powerful
// design principle in software.
"Component Catalog"
[A] Build a Modal component that uses the children prop: <Modal title="Confirm">{any content here}</Modal>. It should support overlay click to close and escape key.
[B] Create a "Component Showcase" page that renders every component in isolation with different prop combinations. Like a mini Storybook.
[C] Count the total lines of code in your 8 components vs the original vanilla PixelCraft UI code. Which is shorter? Which is more maintainable? Why?
REF.MATERIAL
ARTICLE
React Team
The official guide to decomposing UI into components: identify components, build the tree, determine data flow. The foundation of React architecture.
REACTARCHITECTUREESSENTIAL
ARTICLE
React Team
How props work: passing data, default values, spreading props, children, and the read-only contract.
PROPSOFFICIAL
VIDEO
Fireship
Ultra-fast React overview: components, JSX, props, state. Good for a quick refresher after Session 40.
REACTQUICK
VIDEO
Programming with Mosh
Building components, passing props, composing UI trees, and understanding the component lifecycle.
REACTTUTORIAL
ARTICLE
React Team
Building, exporting, and nesting components. The children pattern, composition vs inheritance, and file structure conventions.
COMPONENTSOFFICIAL
// LEAVE EXCITED BECAUSE
8 components compose into the full PixelCraft UI. Change one component → every instance updates. This is reusability at work.