Back to cookbook

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

0 views Published

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

AI Prompt to Build a React Billing Dashboard Component Using Stripe's MCP Server

This prompt is for frontend developers who need to build a React billing dashboard component that shows a customer's live subscription, invo…

ROLE:
You are a senior React/TypeScript developer building a billing dashboard component for a SaaS product.

CONTEXT:
The component should display billing data for a customer, retrieved via Stripe's MCP server: [LIST_DATA_NEEDED_E.G._SUBSCRIPTION_PLAN_NEXT_CHARGE_DATE_PAYMENT_METHOD_RECENT_INVOICES]
Framework/styling: [REACT_VERSION_AND_STYLING_APPROACH_E.G._TAILWIND_CSS_MODULES]

CONSTRAINTS:
- Handle these billing states explicitly: [LIST_STATES_E.G._ACTIVE_PAST_DUE_CANCELED_PENDING_NO_PAYMENT_METHOD]
- Show a loading skeleton while data is being fetched, and a clear error state if the fetch fails
- Format currency and dates using the customer's actual locale/currency, not a hardcoded format
- Separate the data-fetching hook from the presentational component

OUTPUT FORMAT:
1. A short explanation of the component's structure (hook + presentational component)
2. The full TypeScript code, in a single fenced code block, with comments marking where each billing state is handled
3. A one-line note on any assumption you made about the data shape returned by the MCP server

Make this prompt yours

React Prompt Recipes

AI Prompt to Build a React Dark Mode Toggle with System Preference Detection

A React dark mode toggle prompt asks ChatGPT, Claude, or Gemini to generate a theme switching component that respects the user's OS level li…

Role: You are a senior React developer building a reusable UI component.

Context:
Framework/setup: [REACT VERSION, e.g. React 18 with Vite, Next.js App Router]
Styling approach: [CSS variables / Tailwind CSS dark class / CSS-in-JS library]
Component location/usage: [where the toggle will live, e.g. app header, settings page]

Task:
Build a dark mode toggle component with this exact behavior:
1. On first load, detect the user's OS preference via the `prefers-color-scheme` media query and use it as the initial theme, applied before the main content paints (no flash of the wrong theme).
2. If the user has previously made an explicit choice, that stored choice overrides the OS preference on future visits.
3. Persist the user's explicit choice in [STORAGE MECHANISM, e.g. localStorage].
4. Listen for theme changes made in other open tabs and update this tab's theme to match.
5. Expose the current theme and a toggle function via [CONTEXT/HOOK NAME, e.g. a useTheme hook] so other components can read and react to it.

Constraints:
- Use [STYLING APPROACH] to apply the theme, not inline style objects
- Include accessible labeling (aria-label or visible text) that reflects the current state
- Keep the component dependency-free unless [ALLOWED LIBRARIES] are specified

Output format:
Return the full component code in a fenced code block, followed by a short usage example showing how to wrap the app and consume the hook elsewhere.

Make this prompt yours

React Prompt Recipes

AI Prompt to Build a React Kanban Board With Drag-and-Drop

This prompt gives ChatGPT, Claude, or Gemini a complete specification for building a React Kanban board with drag and drop column reordering…

You are a senior React developer specializing in accessible, production-ready UI components.

Context:
- Framework: [REACT VERSION, e.g. React 18 with TypeScript]
- Drag-and-drop library: [LIBRARY NAME, e.g. @dnd-kit/core]
- Styling approach: [e.g. Tailwind CSS, CSS Modules, styled-components]
- Columns or workflow stages: [LIST OF COLUMN NAMES, e.g. Backlog, In Progress, Review, Done]
- State source: [e.g. local state, Zustand store, REST API endpoint]

Build a Kanban board component with the following requirements:
1. Render one column per workflow stage listed above, each showing its card count
2. Support dragging cards between columns and reordering cards within a column
3. Support keyboard-based reordering, not mouse-only interaction, for accessibility
4. Identify cards by a stable [ID FIELD NAME] field, never by array index
5. Call a [CALLBACK NAME] function on every successful move, passing the card id, source column, destination column, and new index
6. Show an optimistic UI update immediately, then roll back if [CALLBACK NAME] rejects
7. Handle empty columns and drops outside any valid column gracefully

Output format:
- The main board component
- Column and Card subcomponents
- Any custom hooks used for drag state
- A short usage example showing how to wire [CALLBACK NAME] to a real API call
- Brief notes on any library-specific setup required, such as providers, context, or CSS imports

Make this prompt yours