Component Design Skill
Purpose
Create consistent, reusable UI components.
Atomic Design
Reference: patterns/atomic-design.md
Hierarchy
- •Atoms: Basic elements (Button, Input, Label)
- •Molecules: Simple groups (FormField, SearchBox)
- •Organisms: Complex sections (Header, Form, Card)
- •Templates: Page layouts
- •Pages: Specific instances
Component Patterns
Reference: patterns/composition.md
Compound Components
tsx
<Select>
<Select.Trigger />
<Select.Content>
<Select.Item value="1">Option 1</Select.Item>
</Select.Content>
</Select>
Render Props
tsx
<DataFetcher url="/api/users">
{({ data, loading }) => (
loading ? <Spinner /> : <UserList users={data} />
)}
</DataFetcher>
Custom Hooks
tsx
function useUser(id: string) {
const [user, setUser] = useState(null);
const [loading, setLoading] = useState(true);
// ...
return { user, loading, error };
}
Props Interface
tsx
interface ButtonProps {
/** Visual variant of the button */
variant?: 'primary' | 'secondary' | 'ghost';
/** Size of the button */
size?: 'sm' | 'md' | 'lg';
/** Whether button is disabled */
disabled?: boolean;
/** Click handler */
onClick?: () => void;
/** Button content */
children: React.ReactNode;
}
Component Template
Use: templates/component-template.tsx
State Management
Reference: patterns/state-management.md
Decision Tree
- •UI-only state →
useState - •Complex local state →
useReducer - •Shared between siblings → Lift to parent
- •Shared across app → Context or global store
- •Server state → React Query/SWR