# Generate code

> Turn a Figma frame into a React component built from your project's shadcn/ui components, Tailwind CSS and real icon imports, with matching blocks installed instead of rebuilt.

## Usage

### Copy a link to the frame

In Figma, select the frame you want in code, right-click it and choose **Copy link to selection**.

### Run the skill

In your editor's chat, run the skill with the link:

```text title="Prompt"
/shadcnpro-generate-code https://figma.com/design/abc123/MyApp?node-id=42-15
```

### Review the component

The agent writes the code to your project and reports what it installed, what it built by hand and where the code differs from the frame. Ask for changes in the same chat, for example "make the cards stack on mobile".

The skill needs the Figma MCP server, and view access to the file is enough. See [Setup](https://pro.shadcn.co/docs/agent-skills/setup#connect-the-mcp-servers).

## What the skill does

1. Reads your project with `npx shadcn@latest info --json`: the framework, the UI library, the icon library and the components you have.
2. Reads the frame through the Figma MCP server: its layout, its variables and a screenshot.
3. Installs the blocks the frame is made of, if it uses blocks from the [Figma kit](https://pro.shadcn.co/docs/figma-kit).
4. Maps every other layer to a shadcn/ui component, and installs the components you don't have yet.
5. Imports icons from your project's icon library and saves images to `public/`.
6. Writes the code with your theme tokens, such as `bg-primary`, never with copied hex values.
7. Checks the result: types and lint, and, when your editor has a browser tool, a comparison with the Figma screenshot at desktop and mobile width and in dark mode.

The result is a `.tsx` file that uses your components and your theme. There's no runtime dependency and nothing to keep in sync: edit it like any other code.

## Blocks are installed, not rebuilt

When a section of the frame is a block from the Figma kit, such as a pricing section or a sidebar, the skill installs that block from the registry and replaces its sample content with the content of your frame. You get the same tested, responsive code as on the [Blocks](https://pro.shadcn.co/pro-blocks) page.

With the [MCP server](https://pro.shadcn.co/docs/mcp/setup) connected, the skill finds the matching block by what it does and compares its preview with your frame. Without it, the skill searches the registry with the shadcn CLI, which matches names and descriptions.

A section that looks like a block but has a different layout is built by hand, with the block as a reference for spacing and structure.

## How layers become components

A component in the kit is the shadcn/ui component of the same name, and its variant properties become props:

| In Figma | In code |
|---|---|
| Button, `Variant=Outline`, `Size=Small` | `<Button variant="outline" size="sm">` |
| Card with header, body and footer | `Card`, `CardHeader`, `CardContent`, `CardFooter` |
| Input field with a label | `Field`, `FieldLabel`, `Input` |
| Dropdown | `Select`, `SelectTrigger`, `SelectContent` |
| Tabs with several panels | `Tabs`, `TabsList`, `TabsTrigger`, `TabsContent` |
| Badge or tag | `Badge` with the matching variant |
| Modal | `Dialog`, `DialogContent`, `DialogHeader` |
| A fill bound to the variable `primary` | `bg-primary` |

The skill reads each component file in your project before it uses it, so the code fits your UI library. Radix UI, Base UI and React Aria differ in props and structure, for example `asChild` in Radix UI and `render` in Base UI.

## Icons and images

Icons come from your project's icon library, the `iconLibrary` in `components.json`: Lucide, Tabler, Phosphor, Remix or Hugeicons. If the design uses another library, the skill takes the closest icon from yours and lists the substitution. It asks before it adds a second icon package.

Photos, logos and illustrations are downloaded and saved under `public/`, with names that say what they are. No Figma link stays in the code.

## Static designs become interactive

A Figma frame shows one state of something interactive, so the skill adds the behavior the design implies:

- Tabs switch, accordions open, dialogs open and close, and menus work.
- Forms get labels, names and a submit button.
- Hover, focus and disabled styles come with the components. They aren't rebuilt from the State variants.

## Desktop and mobile

Give the skill a desktop frame and a mobile frame, and it writes one responsive component from both. With only a desktop frame, it stacks the columns on small screens and says in its report that the mobile layout is its own.

## Large frames

When a frame is too big for one request, the skill reads its outline first, then fetches the sections one by one. For more control over a large page, run the skill on one section at a time.

## Tips for better results

- **Start from the kit.** Files built with the Figma kit map one-to-one to shadcn/ui and to blocks.
- **Name your layers.** "PricingSection" tells the agent more than "Frame 47".
- **Use auto layout.** It becomes flexbox and grid, so the code resizes the way your design does.
- **Use variables for colors and radius.** They become your CSS variables instead of hard-coded values. If the frame uses variables your stylesheet doesn't have, run [`/shadcnpro-import-variables`](https://pro.shadcn.co/docs/agent-skills/import-variables) first.
- **Set up the registry first.** Without it the skill can't install blocks. [`/shadcnpro-setup-blocks`](https://pro.shadcn.co/docs/agent-skills/setup-blocks) does it for you.
