Back to cookbook

AI Prompt to Generate a React Component From a Figma File Using MCP

0 views Updated

Make this prompt yours

Share

This prompt is for front-end developers who want to turn a Figma design into working React code by connecting an AI model to Figma's MCP server, so it reads the actual layout, spacing, and style values from the file instead of guessing from a screenshot. It's built for developers translating a finished design into a reusable component without manually re-measuring every value in the design tool.

With the MCP connection active, the model can pull real node data — dimensions, colors, typography, auto-layout spacing — from the specified frame and map it to React with whatever styling approach the project uses, whether that's CSS modules, Tailwind, or styled-components. Because the measurements come from the file itself, the output tracks the design's actual spacing and color values rather than an approximation.

If the Figma file isn't connected or the design only exists as a live webpage, Site to Prompt measures a rendered page directly and turns those measurements into a prompt, which is a useful fallback for the same kind of design-to-code conversion.

Prompt template

Make this prompt yours

prompt-template
277 tokens
Role: You are a front-end developer with access to a Figma MCP connection. Context: - Figma file: [FILE_NAME_OR_URL] - Frame or node to convert: [FRAME_NAME] - Framework: React with [STYLING_APPROACH, e.g. Tailwind CSS] - Component name: [COMPONENT_NAME] Task: 1. Read the specified frame's layout, spacing, typography, and color values through the Figma MCP connection. 2. Generate a React component that reproduces this layout using the stated styling approach. 3. Note any interactive states (hover, focus, disabled) visible in the file and implement them if present. Constraints: - Use the actual measured values (padding, gap, font size, colors) from the Figma file rather than estimated or rounded values. - Keep the component self-contained and reusable, with props for any text or image content that should be dynamic. - Include basic accessibility attributes (alt text, semantic HTML elements, ARIA labels where relevant). - Flag anything in the design that can't be cleanly translated to code (e.g. a custom font not available in the project). Output format: - Component code in a fenced code block - Brief notes on any values that couldn't be read directly from Figma and were estimated - List of interactive states implemented, or "None found in this frame"

Want it sharper? Optimize this prompt with Prompt Optimizer, check it with the Prompt Debugger or shorten it with the Token Optimizer.

Example input

example-input
58 tokens
Convert the 'PricingCard' frame in the 'Marketing Site' Figma file into a React component using Tailwind CSS. Call the component PricingCard. Pull the actual spacing and colors via the Figma MCP connection, and include the hover state shown on the 'Select Plan' button.

When to use it

  • Converting a finished Figma frame into a first-pass React component instead of manually reading off dimensions and colors
  • Keeping a component's spacing and typography in sync after a designer updates the Figma file
  • Generating a component variant, like a mobile layout, from a second Figma frame using the same base component structure
  • Handing a front-end contractor a working starting point for a component instead of a static design handoff

Best practices

  • Specify the exact Figma frame or node name rather than asking the model to interpret an entire page, since one file can contain many unrelated components
  • State your project's styling approach up front, such as Tailwind, CSS modules, or styled-components, so the output matches your codebase instead of inventing its own convention
  • Ask for responsive behavior explicitly if the design has breakpoints, since a single static frame won't communicate that on its own
  • Review generated spacing and color values against the Figma file directly before merging, especially for components with nested auto-layout frames

Common mistakes

  • Pointing the model at a whole Figma page instead of a specific frame, which produces a tangled component that mixes unrelated design elements
  • Not specifying accessibility requirements like alt text, ARIA labels, and focus states, which a visual-only reading of the design won't infer on its own
  • Assuming the generated component is pixel-perfect without checking it against the Figma file, especially for nested or conditional layouts
  • Forgetting to ask for interactive states like hover, active, or disabled that exist in the design file but aren't visible in the default frame

FAQs

How does an AI model read measurements directly from a Figma file?

A Figma MCP server exposes tools that let a connected model request node data — dimensions, colors, typography, and auto-layout spacing — directly from the Figma API, so the values come from the file itself rather than a visual guess from a screenshot.

Can this generate a component in a framework other than React?

The underlying approach works for any framework, but the prompt template here is written for React; swap the "Framework" line in the template to Vue, Svelte, or plain HTML/CSS and the same measurement-reading approach still applies.

Does the AI need to see the full Figma page to convert one component?

No, and it's better if it doesn't — pointing the model at a specific frame or node name instead of the whole page avoids pulling in unrelated design elements that aren't part of the component you're converting.

What's a good fallback tool if the design isn't in Figma or MCP isn't connected?

Site to Prompt — it measures a real rendered webpage directly and turns those measurements into a prompt, which works as a substitute when the source design is a live page rather than a connected Figma file.

Found this prompt useful? Share it.

Share

More in React Prompt Recipes

React Prompt Recipes

ChatGPT Prompt to Build a React Dashboard Layout With Sidebar and Charts

This React dashboard layout prompt helps developers get a working admin or analytics dashboard scaffold out of ChatGPT, Claude, or Gemini in…

Role: You are a senior frontend engineer specializing in React and responsive dashboard UIs.

Context:
- Framework: [REACT VERSION, e.g., React 18 with functional components and hooks]
- Styling approach: [TAILWIND CSS / CSS MODULES / STYLED-COMPONENTS]
- Charting library: [RECHARTS / CHART.JS / NIVO]
- Dashboard purpose: [e.g., SaaS analytics dashboard showing revenue, active users, and churn]

Task:
Build a dashboard layout with the following structure:
1. A collapsible sidebar with navigation links: [LIST OF NAV ITEMS]
2. A top bar with [e.g., page title, search input, user avatar menu]
3. A main content area using a responsive grid containing:
   - [NUMBER] stat/summary cards showing [METRICS, e.g., total revenue, active users, churn rate]
   - [NUMBER] chart widgets showing [CHART TYPES AND DATA, e.g., a line chart of revenue over time, a bar chart of signups by month]

Constraints:
- Break the output into separate components: Sidebar, Topbar, ChartCard, StatCard, and a parent DashboardLayout component.
- The sidebar must collapse to [OFF-CANVAS DRAWER / ICON-ONLY RAIL] on screens narrower than [BREAKPOINT, e.g., 768px].
- Include realistic mock data inline so the layout is immediately viewable without a backend.
- Use semantic HTML where applicable (nav, main, aside, header).

Output format:
- Provide each component as a separate, clearly labeled code block.
- List any npm packages that need to be installed before the code will run.
- End with a short note on what to replace with real API data.

Make this prompt yours

React Prompt Recipes

AI Prompt to Build a React Authentication Flow With Protected Routes

This AI prompt for a React authentication flow generates the pieces a typical app needs to gate pages behind a login: a login form, an auth…

ROLE
You are a senior React developer building a reusable authentication flow.

CONTEXT
Framework: [REACT_VERSION, e.g. React 18]
Routing library: [ROUTING_LIBRARY_AND_VERSION, e.g. React Router v6]
Backend auth endpoints: [LOGIN_ENDPOINT], [LOGOUT_ENDPOINT], [SESSION_CHECK_ENDPOINT]
Token storage method: [TOKEN_STORAGE_METHOD, e.g. httpOnly cookie set by the server]
Styling approach: [STYLING_APPROACH, e.g. Tailwind CSS]

TASK
Generate the following, using functional components and hooks:
1. An AuthContext and AuthProvider that exposes the current user, a loading flag, and login/logout functions.
2. A login form component that calls the login function and displays validation and API errors.
3. A ProtectedRoute component that redirects unauthenticated users to [LOGIN_ROUTE_PATH], preserving the originally requested URL for post-login redirect.
4. On initial app load, verify any existing session before rendering protected routes, showing a loading indicator during the check.

CONSTRAINTS
- Do not render protected page content until the session check has completed.
- Handle network and 401 errors from the auth endpoints gracefully, with user-facing messages.
- Keep components small and composable; do not put API calls directly inside UI components.

OUTPUT FORMAT
Provide each file separately with a filename comment at the top, followed by a 2-3 sentence summary of how the pieces connect together.

Make this prompt yours

React Prompt Recipes

AI Prompt to Turn a Design Screenshot into a React Component

This is a React prompt for converting a design screenshot or mockup into working React component code — built for frontend developers who ge…

ROLE: You are a frontend developer converting a design image into a React component.

CONTEXT: I'm attaching a design screenshot/mockup. Tech stack: [REACT VERSION, STYLING APPROACH e.g. Tailwind/CSS Modules/styled-components, COMPONENT LIBRARY IF ANY]

TASK:
1. First, describe what you see in the image: overall layout, spacing, typography (font sizes/weights), colors, and any visible interactive states
2. Flag anything you're uncertain about (illegible text, ambiguous spacing, colors that are hard to read precisely) instead of guessing silently
3. Then write the React component matching this description, split into: component structure (JSX), styling, and any props needed to make it reusable

CONSTRAINTS:
- Match the layout and spacing as closely as possible to what's visible in the image
- Use [STYLING APPROACH] only, no inline styles unless the project convention requires it
- Make the component accept props for any content that would realistically vary (text, images, links)
- [ANY ADDITIONAL CONSTRAINT, e.g. must be accessible, must support dark mode]

OUTPUT FORMAT:
1. A short description of the design (layout, spacing, typography, colors, flagged uncertainties)
2. The complete component code in a fenced code block
3. A one-line note on anything that will need visual verification once rendered

Make this prompt yours