web-component-design
wshobson/agents
Master React, Vue, and Svelte component patterns with composition strategies and CSS-in-JS approaches.
What is web-component-design?
Learn to design reusable, maintainable UI components across modern frameworks using compound components, render props, slots, and CSS-in-JS solutions. Use this when building component libraries, design systems, or implementing complex component architectures.
- Design compound components, render props, and slot-based patterns
- Choose and apply CSS-in-JS solutions (Tailwind, styled-components, Emotion, CSS Modules, Vanilla Extract)
- Create semantic component APIs with sensible defaults and composition support
- Implement framework-specific patterns (React context, Vue composables, Svelte runes)
- Build accessible, responsive components with proper forwarding and memoization
- Prevent common issues like prop explosion, style conflicts, and re-render cascades
How to install web-component-design
npx skills add https://github.com/wshobson/agents --skill web-component-designHow to use web-component-design
- 1.Review the core composition patterns (compound components, render props, slots) relevant to your framework
- 2.Choose a CSS-in-JS approach based on your project needs (rapid prototyping vs performance)
- 3.Design your component API using semantic prop names and sensible defaults
- 4.Implement the component using framework-specific patterns (React context, Vue composables, Svelte runes)
- 5.Apply best practices: single responsibility, accessibility, controlled/uncontrolled patterns, memoization
- 6.Test for accessibility with screen readers and keyboard navigation
- 7.Profile and optimize re-renders using framework DevTools
Use cases
- Building a reusable component library or design system
- Designing complex accordion, tabs, or select components with compound patterns
- Refactoring legacy components into modern composition patterns
- Choosing styling approaches for a new frontend project
- Creating consistent component APIs across a large codebase
- Frontend engineers building component libraries
- Design system maintainers
- React, Vue, and Svelte developers
- Teams standardizing component patterns across projects
web-component-design FAQ
Use compound components when you have related components that work together (like Select with Trigger and Options). Use render props when you need to delegate rendering logic to the parent, typically for data-fetching or state management patterns.
Use Tailwind CSS for rapid prototyping and design systems, CSS Modules for gradual adoption with existing CSS, styled-components for React with dynamic styling, Emotion for flexible SSR-friendly solutions, or Vanilla Extract for performance-critical apps with zero runtime overhead.
Use context (React), provide/inject (Vue), or stores (Svelte) to pass data through the component tree without explicitly passing props at each level.
Controlled components have their state managed by the parent (via props), while uncontrolled components manage their own state. Support both patterns when appropriate for flexibility.
Include ARIA attributes, ensure keyboard navigation support, test with screen readers, use semantic HTML, and provide proper focus management and error messaging.
Full instructions (SKILL.md)
Source of truth, from wshobson/agents.
name: web-component-design description: Master React, Vue, and Svelte component patterns including CSS-in-JS, composition strategies, and reusable component architecture. Use when building UI component libraries, designing component APIs, or implementing frontend design systems.
Web Component Design
Build reusable, maintainable UI components using modern frameworks with clean composition patterns and styling approaches.
When to Use This Skill
- Designing reusable component libraries or design systems
- Implementing complex component composition patterns
- Choosing and applying CSS-in-JS solutions
- Building accessible, responsive UI components
- Creating consistent component APIs across a codebase
- Refactoring legacy components into modern patterns
- Implementing compound components or render props
Core Concepts
1. Component Composition Patterns
Compound Components: Related components that work together
// Usage
<Select value={value} onChange={setValue}>
<Select.Trigger>Choose option</Select.Trigger>
<Select.Options>
<Select.Option value="a">Option A</Select.Option>
<Select.Option value="b">Option B</Select.Option>
</Select.Options>
</Select>
Render Props: Delegate rendering to parent
<DataFetcher url="/api/users">
{({ data, loading, error }) =>
loading ? <Spinner /> : <UserList users={data} />
}
</DataFetcher>
Slots (Vue/Svelte): Named content injection points
<template>
<Card>
<template #header>Title</template>
<template #content>Body text</template>
<template #footer><Button>Action</Button></template>
</Card>
</template>
2. CSS-in-JS Approaches
| Solution | Approach | Best For |
|---|---|---|
| Tailwind CSS | Utility classes | Rapid prototyping, design systems |
| CSS Modules | Scoped CSS files | Existing CSS, gradual adoption |
| styled-components | Template literals | React, dynamic styling |
| Emotion | Object/template styles | Flexible, SSR-friendly |
| Vanilla Extract | Zero-runtime | Performance-critical apps |
3. Component API Design
interface ButtonProps {
variant?: "primary" | "secondary" | "ghost";
size?: "sm" | "md" | "lg";
isLoading?: boolean;
isDisabled?: boolean;
leftIcon?: React.ReactNode;
rightIcon?: React.ReactNode;
children: React.ReactNode;
onClick?: () => void;
}
Principles:
- Use semantic prop names (
isLoadingvsloading) - Provide sensible defaults
- Support composition via
children - Allow style overrides via
classNameorstyle
Quick Start: React Component with Tailwind
import { forwardRef, type ComponentPropsWithoutRef } from "react";
import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "@/lib/utils";
const buttonVariants = cva(
"inline-flex items-center justify-center rounded-md font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 disabled:pointer-events-none disabled:opacity-50",
{
variants: {
variant: {
primary: "bg-blue-600 text-white hover:bg-blue-700",
secondary: "bg-gray-100 text-gray-900 hover:bg-gray-200",
ghost: "hover:bg-gray-100 hover:text-gray-900",
},
size: {
sm: "h-8 px-3 text-sm",
md: "h-10 px-4 text-sm",
lg: "h-12 px-6 text-base",
},
},
defaultVariants: {
variant: "primary",
size: "md",
},
},
);
interface ButtonProps
extends
ComponentPropsWithoutRef<"button">,
VariantProps<typeof buttonVariants> {
isLoading?: boolean;
}
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant, size, isLoading, children, ...props }, ref) => (
<button
ref={ref}
className={cn(buttonVariants({ variant, size }), className)}
disabled={isLoading || props.disabled}
{...props}
>
{isLoading && <Spinner className="mr-2 h-4 w-4" />}
{children}
</button>
),
);
Button.displayName = "Button";
Framework Patterns
React: Compound Components
import { createContext, useContext, useState, type ReactNode } from "react";
interface AccordionContextValue {
openItems: Set<string>;
toggle: (id: string) => void;
}
const AccordionContext = createContext<AccordionContextValue | null>(null);
function useAccordion() {
const context = useContext(AccordionContext);
if (!context) throw new Error("Must be used within Accordion");
return context;
}
export function Accordion({ children }: { children: ReactNode }) {
const [openItems, setOpenItems] = useState<Set<string>>(new Set());
const toggle = (id: string) => {
setOpenItems((prev) => {
const next = new Set(prev);
next.has(id) ? next.delete(id) : next.add(id);
return next;
});
};
return (
<AccordionContext.Provider value={{ openItems, toggle }}>
<div className="divide-y">{children}</div>
</AccordionContext.Provider>
);
}
Accordion.Item = function AccordionItem({
id,
title,
children,
}: {
id: string;
title: string;
children: ReactNode;
}) {
const { openItems, toggle } = useAccordion();
const isOpen = openItems.has(id);
return (
<div>
<button onClick={() => toggle(id)} className="w-full text-left py-3">
{title}
</button>
{isOpen && <div className="pb-3">{children}</div>}
</div>
);
};
Vue 3: Composables
<script setup lang="ts">
import { ref, computed, provide, inject, type InjectionKey } from "vue";
interface TabsContext {
activeTab: Ref<string>;
setActive: (id: string) => void;
}
const TabsKey: InjectionKey<TabsContext> = Symbol("tabs");
// Parent component
const activeTab = ref("tab-1");
provide(TabsKey, {
activeTab,
setActive: (id: string) => {
activeTab.value = id;
},
});
// Child component usage
const tabs = inject(TabsKey);
const isActive = computed(() => tabs?.activeTab.value === props.id);
</script>
Svelte 5: Runes
<script lang="ts">
interface Props {
variant?: 'primary' | 'secondary';
size?: 'sm' | 'md' | 'lg';
onclick?: () => void;
children: import('svelte').Snippet;
}
let { variant = 'primary', size = 'md', onclick, children }: Props = $props();
const classes = $derived(
`btn btn-${variant} btn-${size}`
);
</script>
<button class={classes} {onclick}>
{@render children()}
</button>
Best Practices
- Single Responsibility: Each component does one thing well
- Prop Drilling Prevention: Use context for deeply nested data
- Accessible by Default: Include ARIA attributes, keyboard support
- Controlled vs Uncontrolled: Support both patterns when appropriate
- Forward Refs: Allow parent access to DOM nodes
- Memoization: Use
React.memo,useMemofor expensive renders - Error Boundaries: Wrap components that may fail
Common Issues
- Prop Explosion: Too many props - consider composition instead
- Style Conflicts: Use scoped styles or CSS Modules
- Re-render Cascades: Profile with React DevTools, memo appropriately
- Accessibility Gaps: Test with screen readers and keyboard navigation
- Bundle Size: Tree-shake unused component variants
Related skills
More from wshobson/agents and the wider catalog.
tailwind-design-system
Build production-ready design systems with Tailwind CSS v4, design tokens, and component libraries.
typescript-advanced-types
Master TypeScript's advanced type system: generics, conditional types, mapped types, and utility types for type-safe applications.
nodejs-backend-patterns
Build production-ready Node.js backends with Express/Fastify, middleware patterns, auth, and database integration.
python-performance-optimization
Profile and optimize Python code using cProfile, memory profilers, and performance best practices.
brand-landingpage
Brand-first landing page designer with guided interviews and Stitch-powered iteration.
python-testing-patterns
Implement comprehensive testing strategies with pytest, fixtures, mocking, and test-driven development.