Link your Figma components to real code — permanently and bidirectionally
Code Connect is a Figma tool that links your design components to their real code implementations. When a developer selects a component in Figma, instead of seeing auto-generated code snippets, they see the actual code from your codebase — with the correct import paths, prop names, and usage patterns.
This eliminates the most common source of design-to-code drift: developers guessing how to implement a component instead of using the existing implementation.
Code Connect operates in four steps:
.figma.tsx file next to your component that describes how the Figma component maps to your React component.npx figma connect publish to upload the mapping to Figma..figma.tsx file and republish. The Figma panel always reflects your latest code.Install the Code Connect CLI as a dev dependency:
npm install --save-dev @figma/code-connectAuthenticate with your Figma account:
npx figma connect authThis will open a browser window where you log in to Figma and authorize the CLI. Your token is stored locally and used for all subsequent commands.
In Figma, right-click on a component and select Copy link to selection. This gives you a URL like:
https://www.figma.com/design/ABC123/MyDesignSystem?node-id=1234-5678You will paste this URL into your .figma.tsx file.
Create a file next to your component with the .figma.tsx extension:
// components/ui/Button.figma.tsx
import figma from "@figma/code-connect"
import { Button } from "./button"
figma.connect(Button, "https://www.figma.com/design/ABC123/MyDesignSystem?node-id=1234-5678", {
props: {
label: figma.string("Label"),
variant: figma.enum("Variant", {
Primary: "default",
Secondary: "secondary",
Destructive: "destructive",
Outline: "outline",
Ghost: "ghost",
}),
size: figma.enum("Size", {
Small: "sm",
Medium: "default",
Large: "lg",
}),
disabled: figma.boolean("Disabled"),
icon: figma.instance("Icon"),
},
example: (props) => (
<Button
variant={props.variant}
size={props.size}
disabled={props.disabled}
>
{props.icon}
{props.label}
</Button>
),
})Before publishing, validate your Code Connect files to catch errors:
npx figma connect validateIf validation passes, publish:
npx figma connect publishAfter publishing, open Figma, select the component, and switch to the Dev Mode panel. You should see your real code snippet instead of the auto-generated one.
Tip: Add these commands to your
package.jsonscripts for convenience:"scripts": { "figma:validate": "figma connect validate", "figma:publish": "figma connect publish" }
Code Connect provides several helper functions for mapping Figma properties to React props:
| Function | Figma Property | Description |
|---|---|---|
figma.string("Name") | Text property | Maps a text property to a string prop |
figma.boolean("Name") | Boolean property | Maps a toggle property to a boolean prop |
figma.enum("Name", mapping) | Variant property | Maps variant values to code values with a lookup object |
figma.instance("Name") | Instance swap | Maps an instance swap slot to a React node |
figma.children("Name") | Children layer | Maps a named child layer to React children |
figma.nestedProps("Name", { ... }) | Nested instance | Extracts props from a nested component instance |
figma.className(["Name"]) | Variant property | Maps variant values to CSS class names |
// components/ui/Card.figma.tsx
import figma from "@figma/code-connect"
import { Card, CardHeader, CardTitle, CardDescription, CardContent, CardFooter } from "./card"
figma.connect(Card, "https://www.figma.com/design/ABC123/MyDesignSystem?node-id=5678-9012", {
props: {
title: figma.string("Title"),
description: figma.string("Description"),
content: figma.children("Content"),
footer: figma.children("Footer"),
hasShadow: figma.boolean("Has Shadow"),
},
example: (props) => (
<Card className={props.hasShadow ? "shadow-lg" : ""}>
<CardHeader>
<CardTitle>{props.title}</CardTitle>
<CardDescription>{props.description}</CardDescription>
</CardHeader>
<CardContent>
{props.content}
</CardContent>
<CardFooter>
{props.footer}
</CardFooter>
</Card>
),
})| Problem | Solution |
|---|---|
| Code not showing in Figma | Make sure you published with npx figma connect publish and that the node URL matches the main component, not an instance |
| Wrong property names | Property names in figma.string("Name") must exactly match the property name in Figma, including capitalization |
| Enum not matching | The keys in your enum mapping must match the exact variant names in Figma. Check for trailing spaces or typos. |
| Auth errors | Re-run npx figma connect auth to refresh your token. Make sure you have Dev Mode access to the file. |
| Validate fails | Check that your component import paths are correct and that the component actually exports the referenced name |