Loading...
Loading...
Design and build reusable, well-documented components. Master component composition, prop design, variant systems, state management, and documentation. Create a scalable component library that enables consistency and speeds up development. Works with React, TypeScript, and Tailwind CSS.
npx skill4agent add sanky369/vibe-building-skills component-architectureinterface ButtonProps {
variant?: 'primary' | 'secondary' | 'ghost';
size?: 'sm' | 'md' | 'lg';
disabled?: boolean;
loading?: boolean;
onClick?: () => void;
children: React.ReactNode;
}
export const Button: React.FC<ButtonProps> = ({
variant = 'primary',
size = 'md',
disabled = false,
loading = false,
onClick,
children,
}) => {
return (
<button
className={`button button--${variant} button--${size}`}
disabled={disabled || loading}
onClick={onClick}
>
{loading && <Spinner size="sm" />}
{children}
</button>
);
};interface FormInputProps {
label: string;
placeholder?: string;
error?: string;
value: string;
onChange: (value: string) => void;
disabled?: boolean;
}
export const FormInput: React.FC<FormInputProps> = ({
label,
placeholder,
error,
value,
onChange,
disabled,
}) => {
return (
<div className="form-input">
<Label>{label}</Label>
<Input
placeholder={placeholder}
value={value}
onChange={(e) => onChange(e.target.value)}
disabled={disabled}
aria-invalid={!!error}
/>
{error && <ErrorMessage>{error}</ErrorMessage>}
</div>
);
};interface CardProps {
title: string;
description?: string;
image?: string;
action?: {
label: string;
onClick: () => void;
};
children?: React.ReactNode;
}
export const Card: React.FC<CardProps> = ({
title,
description,
image,
action,
children,
}) => {
return (
<div className="card">
{image && <img src={image} alt={title} className="card-image" />}
<div className="card-content">
<h3 className="card-title">{title}</h3>
{description && <p className="card-description">{description}</p>}
{children}
{action && (
<Button onClick={action.onClick} variant="secondary">
{action.label}
</Button>
)}
</div>
</div>
);
};export const BlogPostTemplate: React.FC<BlogPostTemplateProps> = ({
title,
author,
date,
image,
content,
relatedPosts,
}) => {
return (
<div className="blog-post-template">
<Header />
<article className="blog-post">
<div className="blog-post-hero">
<img src={image} alt={title} />
</div>
<div className="blog-post-content">
<h1>{title}</h1>
<div className="blog-post-meta">
<Avatar src={author.avatar} alt={author.name} />
<span>{author.name}</span>
<span>{formatDate(date)}</span>
</div>
<div className="blog-post-body">{content}</div>
</div>
</article>
<section className="related-posts">
<h2>Related Posts</h2>
<div className="related-posts-grid">
{relatedPosts.map((post) => (
<Card key={post.id} {...post} />
))}
</div>
</section>
<Footer />
</div>
);
};// Does too much: rendering, data fetching, form handling, validation
const UserProfile = () => {
const [user, setUser] = useState(null);
const [formData, setFormData] = useState({});
const [errors, setErrors] = useState({});
useEffect(() => {
fetchUser().then(setUser);
}, []);
const handleSubmit = () => {
// validation logic
// submission logic
};
return (
// complex JSX
);
};// UserProfile: Orchestrates the page
const UserProfile = () => {
const { user } = useUser();
return (
<>
<UserHeader user={user} />
<UserEditForm user={user} />
<UserActivity user={user} />
</>
);
};
// UserHeader: Displays user info
const UserHeader = ({ user }) => (
<div className="user-header">
<Avatar src={user.avatar} />
<h1>{user.name}</h1>
</div>
);
// UserEditForm: Handles form state and submission
const UserEditForm = ({ user }) => {
// form logic
};
// UserActivity: Displays user activity
const UserActivity = ({ user }) => {
// activity logic
};// Inheritance approach (avoid)
class Button extends React.Component {}
class PrimaryButton extends Button {}
class LargeButton extends Button {}
class LargePrimaryButton extends Button {}// Composition approach (prefer)
const Button = ({ variant = 'primary', size = 'md', ...props }) => (
<button className={`button button--${variant} button--${size}`} {...props} />
);
// Use composition to create variants
const PrimaryButton = (props) => <Button variant="primary" {...props} />;
const LargeButton = (props) => <Button size="lg" {...props} />;
const LargePrimaryButton = (props) => <Button variant="primary" size="lg" {...props} />;interface ButtonProps {
// Variant and size are constrained to valid options
variant?: 'primary' | 'secondary' | 'ghost' | 'danger';
size?: 'sm' | 'md' | 'lg';
// Boolean props are explicit
disabled?: boolean;
loading?: boolean;
fullWidth?: boolean;
// Callbacks are clearly named
onClick?: () => void;
onHover?: () => void;
// Content is flexible
children: React.ReactNode;
icon?: React.ReactNode;
// HTML attributes can be passed through
className?: string;
'aria-label'?: string;
}const ControlledInput = ({ value, onChange }) => (
<input value={value} onChange={(e) => onChange(e.target.value)} />
);
// Parent manages state
const Parent = () => {
const [value, setValue] = useState('');
return <ControlledInput value={value} onChange={setValue} />;
};const UncontrolledInput = ({ defaultValue, onSubmit }) => {
const inputRef = useRef(null);
return (
<>
<input ref={inputRef} defaultValue={defaultValue} />
<button onClick={() => onSubmit(inputRef.current.value)}>Submit</button>
</>
);
};
// Parent doesn't manage state
const Parent = () => {
return <UncontrolledInput onSubmit={(value) => console.log(value)} />;
};interface ButtonProps {
variant?: 'primary' | 'secondary' | 'ghost' | 'danger';
size?: 'sm' | 'md' | 'lg';
state?: 'default' | 'hover' | 'active' | 'disabled' | 'loading';
}
// Variants matrix
const Button = ({ variant = 'primary', size = 'md', state = 'default', ...props }) => {
const variantClass = `button--${variant}`;
const sizeClass = `button--${size}`;
const stateClass = `button--${state}`;
return (
<button className={`button ${variantClass} ${sizeClass} ${stateClass}`} {...props} />
);
};
// Usage
<Button variant="primary" size="md" state="default">Primary</Button>
<Button variant="secondary" size="lg" state="hover">Secondary Large</Button>
<Button variant="danger" size="sm" state="disabled">Delete</Button># Button Component
## Variants
### Variant: primary
- Default button style
- Used for primary actions
- Example: "Save", "Submit", "Create"
### Variant: secondary
- Secondary button style
- Used for secondary actions
- Example: "Cancel", "Back", "Skip"
### Variant: ghost
- Minimal button style
- Used for tertiary actions
- Example: "Learn More", "View Details"
### Variant: danger
- Danger button style
- Used for destructive actions
- Example: "Delete", "Remove", "Discard"
## Sizes
### Size: sm
- 32px height
- 12px font size
- Used in compact spaces
### Size: md
- 40px height
- 14px font size
- Default size
### Size: lg
- 48px height
- 16px font size
- Used for prominent actions
## States
### State: default
- Normal appearance
### State: hover
- Slightly darker or lighter
- Indicates interactivity
### State: active
- Pressed appearance
- Indicates the button is being clicked
### State: disabled
- Grayed out
- Cursor is not-allowed
- Not clickable
### State: loading
- Shows spinner
- Indicates action in progress
- Not clickable# Component Name
## Purpose
Brief description of what this component does and when to use it.
## Props
| Prop | Type | Default | Description |
| :--- | :--- | :--- | :--- |
| `variant` | 'primary' \| 'secondary' | 'primary' | Visual variant |
| `size` | 'sm' \| 'md' \| 'lg' | 'md' | Component size |
| `disabled` | boolean | false | Disable the component |
| `children` | ReactNode | - | Component content |
## Variants
### Primary
Used for primary actions.
```jsx
<Button variant="primary">Primary Action</Button><Button variant="secondary">Secondary Action</Button><Button disabled>Disabled</Button><Button loading>Loading...</Button><Button onClick={() => alert('Clicked!')}>Click Me</Button><Button icon={<SaveIcon />}>Save</Button><Button fullWidth>Full Width Button</Button>
## How to Use This Skill with Claude Code
### Audit Your Components
### Design a Component System
### Refactor Components
### Generate Component Library
## Design Critique: Evaluating Your Components
Claude Code can critique your components:
## Integration with Other Skills
- **design-foundation** — Component tokens and styling
- **layout-system** — Component layout patterns
- **typography-system** — Component typography
- **color-system** — Component colors
- **accessibility-excellence** — Component accessibility
- **interaction-design** — Component interactions
## Key Principles
**1. Single Responsibility**
Each component should have one clear purpose.
**2. Composition Over Inheritance**
Build complex components by composing simpler ones.
**3. Props Interface Design**
Design props carefully for clarity and flexibility.
**4. Variants Enable Reusability**
Well-designed variants make components reusable across contexts.
**5. Documentation Enables Adoption**
Comprehensive documentation helps your team use components effectively.
## Checklist: Is Your Component Architecture Ready?
- [ ] Components follow single responsibility principle
- [ ] Components are composed from simpler components
- [ ] Props interfaces are well-designed and documented
- [ ] All variants are defined and documented
- [ ] All states are defined and documented
- [ ] Components are accessible (keyboard, screen reader, focus)
- [ ] Components have comprehensive documentation
- [ ] Component library is organized (atoms, molecules, organisms)
- [ ] Components are reusable across the product
- [ ] Components are tested (unit tests, visual tests)
A well-designed component architecture is the foundation of a scalable, maintainable product.