Design Systems
Build a complete design system
Your design team has created a comprehensive Figma design system for a fintech dashboard. It includes complex data visualizations, responsive layouts, dark/light themes, and micro-interactions. You need to implement pixel-perfect React components that match the designs exactly while maintaining performance and accessibility standards.
By completing this lesson, you’ll master:
Transform design mockups into production code that:
Start with screenshots or Figma access:
@figma-screenshot.png"Analyze this design system and identify:- Component hierarchy- Design tokens (colors, spacing, typography)- Responsive breakpoints- Animation patterns- Accessibility requirementsCreate a component architecture plan"
"Based on the design analysis, create a design tokens system:- Color palette with semantic naming- Typography scale- Spacing system (4px/8px grid)- Border radius values- Shadow definitions- Animation timingsFormat as CSS variables and TypeScript types"
Example tokens:
export const tokens = { colors: { // Primitives blue: { 50: '#eff6ff', 500: '#3b82f6', 900: '#1e3a8a', }, // Semantic primary: 'var(--blue-500)', background: { primary: 'var(--gray-50)', secondary: 'var(--white)', elevated: 'var(--white)', }, text: { primary: 'var(--gray-900)', secondary: 'var(--gray-600)', inverse: 'var(--white)', }, }, spacing: { xs: '0.25rem', // 4px sm: '0.5rem', // 8px md: '1rem', // 16px lg: '1.5rem', // 24px xl: '2rem', // 32px '2xl': '3rem', // 48px }, typography: { fontFamily: { sans: 'Inter, system-ui, sans-serif', mono: 'JetBrains Mono, monospace', }, fontSize: { xs: ['0.75rem', { lineHeight: '1rem' }], sm: ['0.875rem', { lineHeight: '1.25rem' }], base: ['1rem', { lineHeight: '1.5rem' }], lg: ['1.125rem', { lineHeight: '1.75rem' }], xl: ['1.25rem', { lineHeight: '1.75rem' }], '2xl': ['1.5rem', { lineHeight: '2rem' }], }, },} as const;
Switch to Agent mode:
"Create a scalable component structure:- Atomic design methodology- Component categories (atoms, molecules, organisms)- Storybook setup for documentation- Theme provider implementation- CSS-in-JS or CSS modules setup"
First, ensure Figma’s MCP server is running:
# In Figma Desktop AppPreferences → Enable Dev Mode MCP Server
If not already configured:
{ "mcpServers": { "figma": { "url": "http://127.0.0.1:3845/sse" } }}
With a Figma frame selected:
"Using Figma MCP, analyze the selected component and:- Extract all design tokens (colors, spacing, typography)- Get the exact component structure- List all variants and states- Generate React component with proper styling"
The MCP provides:
get_code
: Generates React/Tailwind code from selectionget_variable_defs
: Extracts design tokensget_code_connect_map
: Maps to existing components"Using Figma MCP get_variable_defs:- List all color variables with exact values- Extract spacing scale- Get typography definitions- Create a tokens.ts file matching Figma exactly"
Example MCP response integration:
// The AI will use MCP data to generate:export const figmaTokens = { colors: { 'primary-500': '#3b82f6', // Exact from Figma 'surface-elevated': '#ffffff', 'text-primary': '#111827', }, spacing: { 'component-padding': '14px', // Precise Figma values 'section-gap': '32px', }};
With Figma component selected:
"Generate the Button component using Figma MCP:- Use get_code for the exact structure- Apply all variants from the design- Include proper state handling- Match Figma's auto-layout with flexbox"
The MCP ensures:
// Direct from Figma selection"Generate this card component"
// MCP provides exact values:// - padding: 24px// - border-radius: 12px// - shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1)// - Uses color token: surface.elevated
// Generated code matches perfectly
// Manual interpretation from screenshot"Create a card similar to this image"
// AI guesses values:// - padding: ~20px (actually 24px)// - border-radius: ~10px (actually 12px)// - shadow: generic (missing exact values)// - color: white (missing token reference)
@design-system/button.png"Create a Button component that matches this design:- All variants (primary, secondary, ghost, danger)- All sizes (sm, md, lg)- States (hover, active, disabled, loading)- Icon support (left/right)- Full keyboard navigationUse compound component pattern"
Example implementation:
import { forwardRef, ButtonHTMLAttributes } from 'react';import { cva, type VariantProps } from 'class-variance-authority';import { Loader2 } from 'lucide-react';
const buttonVariants = cva( // Base styles 'inline-flex items-center justify-center font-medium transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50', { variants: { variant: { primary: 'bg-primary text-white hover:bg-primary-dark active:bg-primary-darker', secondary: 'bg-gray-100 text-gray-900 hover:bg-gray-200 active:bg-gray-300', ghost: 'hover:bg-gray-100 active:bg-gray-200', danger: 'bg-red-500 text-white hover:bg-red-600 active:bg-red-700', }, size: { sm: 'h-8 px-3 text-sm rounded-md gap-1.5', md: 'h-10 px-4 text-base rounded-lg gap-2', lg: 'h-12 px-6 text-lg rounded-lg gap-2.5', }, }, defaultVariants: { variant: 'primary', size: 'md', }, });
export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> { isLoading?: boolean; leftIcon?: React.ReactNode; rightIcon?: React.ReactNode;}
export const Button = forwardRef<HTMLButtonElement, ButtonProps>( ({ className, variant, size, isLoading, leftIcon, rightIcon, children, disabled, ...props }, ref) => { return ( <button ref={ref} className={buttonVariants({ variant, size, className })} disabled={disabled || isLoading} {...props} > {isLoading ? ( <Loader2 className="animate-spin" size={size === 'sm' ? 14 : 16} /> ) : leftIcon ? ( <span className="inline-flex shrink-0">{leftIcon}</span> ) : null} {children} {rightIcon && !isLoading && ( <span className="inline-flex shrink-0">{rightIcon}</span> )} </button> ); });
Button.displayName = 'Button';
@design-system/forms.png"Create a complete form component system:- Input with all states and variants- Select with custom styling- Checkbox and Radio components- Form field with label and error states- Input group compositionsEnsure ARIA compliance"
@design-system/data-table.png"Create a DataTable component with:- Sortable columns- Pagination- Row selection- Responsive behavior- Loading states- Empty statesUse virtualization for performance"
@dashboard-layout.png"Implement the dashboard layout:- Responsive sidebar navigation- Header with user menu- Main content area with breadcrumbs- Mobile-first approach- Smooth transitionsInclude keyboard navigation"
Example layout:
export const DashboardLayout: React.FC<{ children: ReactNode }> = ({ children }) => { const [sidebarOpen, setSidebarOpen] = useState(false); const { pathname } = useRouter();
return ( <div className="min-h-screen bg-background"> {/* Mobile sidebar backdrop */} <Transition show={sidebarOpen} as={Fragment}> <Dialog onClose={setSidebarOpen} className="relative z-50 lg:hidden"> <TransitionChild enter="transition-opacity ease-linear duration-300" enterFrom="opacity-0" enterTo="opacity-100" leave="transition-opacity ease-linear duration-300" leaveFrom="opacity-100" leaveTo="opacity-0" > <div className="fixed inset-0 bg-gray-900/80" /> </TransitionChild>
<div className="fixed inset-0 flex"> <TransitionChild enter="transition ease-in-out duration-300 transform" enterFrom="-translate-x-full" enterTo="translate-x-0" leave="transition ease-in-out duration-300 transform" leaveFrom="translate-x-0" leaveTo="-translate-x-full" > <DialogPanel className="relative mr-16 flex w-full max-w-xs flex-1"> <Sidebar onClose={() => setSidebarOpen(false)} /> </DialogPanel> </TransitionChild> </div> </Dialog> </Transition>
{/* Desktop sidebar */} <div className="hidden lg:fixed lg:inset-y-0 lg:flex lg:w-64 lg:flex-col"> <Sidebar /> </div>
<div className="lg:pl-64"> <Header onMenuClick={() => setSidebarOpen(true)} />
<main className="py-6"> <div className="mx-auto max-w-7xl px-4 sm:px-6 lg:px-8"> <Breadcrumbs /> {children} </div> </main> </div> </div> );};
@charts-design.png"Build chart components matching the design:- Line chart with tooltips- Bar chart with animations- Donut chart with legends- Sparklines for metrics- Real-time data updatesUse D3.js or Recharts"
@interaction-flow.png"Create interactive components:- Drag and drop kanban board- Multi-step form wizard- Command palette (⌘K)- Toast notifications- Modal system with focus trap"
@micro-interactions.mp4"Implement these micro-interactions:- Button press effects- Hover state transitions- Loading skeleton animations- Page transitions- Scroll-triggered animationsUse Framer Motion"
Example animation:
import { motion } from 'framer-motion';
export const AnimatedCard = ({ children, delay = 0 }) => { return ( <motion.div initial={{ opacity: 0, y: 20 }} animate={{ opacity: 1, y: 0 }} transition={{ duration: 0.4, delay, ease: [0.25, 0.46, 0.45, 0.94], }} whileHover={{ scale: 1.02, boxShadow: '0 10px 30px rgba(0, 0, 0, 0.1)', }} className="bg-white rounded-xl p-6 cursor-pointer" > {children} </motion.div> );};
"Create a complete theme system:- Light/dark theme toggle- System preference detection- Smooth theme transitions- Persistent theme selection- Theme-aware components"
"Optimize the UI for production:- Lazy load heavy components- Implement virtual scrolling- Add error boundaries- Optimize bundle size- Preload critical fonts"
"Set up visual regression testing:- Storybook stories for all components- Chromatic or Percy integration- Responsive screenshot tests- Cross-browser testing- Accessibility testing"
"Generate comprehensive documentation:- Props documentation- Usage examples- Design guidelines- Accessibility notes- Performance considerations"
"Build an interactive playground:- Live component preview- Props editor- Code export- Theme switcher- Responsive preview"
Systematic conversion process:
// 1. With Figma MCP (Recommended)// Select component in Figma, then:"Using Figma MCP, generate this component with:- Exact design tokens from get_variable_defs- Component structure from get_code- Apply Code Connect mappings if available"
// 2. Without MCP (Fallback)@component-design.png"Break down this component into:- Layout structure- Spacing values- Color usage- Typography- Interactive states"
// 3. Refine and polish"Add animations and micro-interactions matching Figma prototypes"
Key MCP advantages:
Build complex UIs from simple parts:
// Compose complex components<Card> <Card.Header> <Card.Title>Revenue</Card.Title> <Card.Action> <Button size="sm" variant="ghost">View all</Button> </Card.Action> </Card.Header> <Card.Body> <MetricChart data={revenueData} /> </Card.Body></Card>
Optimize for 60fps:
// Use CSS transforms for animationsconst slideIn = { initial: { transform: 'translateX(-100%)' }, animate: { transform: 'translateX(0)' }, exit: { transform: 'translateX(-100%)' },};
// Virtualize long lists<VirtualList height={600} itemCount={items.length} itemSize={80} renderItem={({ index, style }) => ( <div style={style}> <ListItem item={items[index]} /> </div> )}/>
Problem: Small differences from design
Solution:
// Use exact values from designconst spacing = { // Not: padding: '1rem' // But: padding: '14px' // Exact from Figma}
// Or use design tokenspadding: tokens.spacing.md // Consistent
Problem: Janky animations and slow renders
Solution:
// Use transform instead of position// Bad: left: ${x}px// Good: transform: translateX(${x}px)
// Memoize expensive componentsconst ExpensiveChart = memo(({ data }) => { return <Chart data={data} />;}, (prev, next) => prev.data === next.data);
Problem: Components fail accessibility audit
Solution:
// Always include ARIA labels<IconButton aria-label="Close dialog" onClick={onClose}> <XIcon /></IconButton>
// Manage focus properlyuseEffect(() => { if (isOpen) { firstFocusableElement?.focus(); }}, [isOpen]);
Level up your UI skills:
Advanced Interactions
Design System Scaling
Performance Excellence
Your implementation succeeds when:
Teams using these techniques report:
Before shipping:
You’ve mastered UI implementation. Ready for more?
Design Systems
Build a complete design system
Animation Library
Create reusable animation patterns
Component Library
Publish components as npm package
Continue to Test-Driven Development →