-
Notifications
You must be signed in to change notification settings - Fork 0
Figma Code Connect
Figma Code Connect links your React components directly to their Figma counterparts. When a developer clicks a component in Figma Dev Mode, they see your exact React code — not a generated approximation.
Without Code Connect:
Figma Dev Mode → generated CSS + HTML → developer has to translate manually
With Code Connect:
Figma Dev Mode → your actual React component code → ready to copy-paste
Code Connect files (.figma.tsx) define the mapping between a Figma component and a React component, including how Figma variant properties map to React props.
Code Connect is configured in .vscode/mcp.json and uses the FIGMA_API_KEY from your environment.
The code-connect-components skill handles the full authoring workflow. Invoke it with:
"Connect this component to Figma using code connect"
"Create a Code Connect mapping for the Button component"
In Figma, right-click your component → Copy link. This gives a URL like:
https://www.figma.com/design/FILE_ID/FileName?node-id=123:456
Create a file next to your component with a .figma.tsx suffix:
// src/client/components/button.figma.tsx
import figma from "@figma/code-connect";
import { Button } from "@/components/ui/button";
figma.connect(
Button,
"https://www.figma.com/design/FILE_ID/FileName?node-id=123:456",
{
props: {
label: figma.string("Label"),
variant: figma.enum("Variant", {
Primary: "primary",
Secondary: "secondary",
Outline: "outline-primary",
Danger: "danger",
Link: "link",
}),
disabled: figma.boolean("Disabled"),
},
example: ({ label, variant, disabled }) => (
<Button variant={variant} disabled={disabled}>
{label}
</Button>
),
},
);After creating the file, publish the mapping to Figma Dev Mode:
npx figma connect publishFigma will now show your React code when a developer inspects the Button component in Dev Mode.
| Helper | Figma Property Type | Example |
|---|---|---|
figma.string("Prop") |
Text / string | Labels, placeholder text |
figma.boolean("Prop") |
Boolean toggle |
disabled, checked
|
figma.enum("Prop", map) |
Variant / enum |
variant, size, color
|
figma.children("Slot") |
Nested components | Slot children |
figma.instance("Prop") |
Component instance | Icons, avatars |
figma.nestedProps("Prop", obj) |
Nested variant properties | Complex prop structures |
// src/client/components/card.figma.tsx
import figma from "@figma/code-connect";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
figma.connect(
Card,
"https://www.figma.com/design/FILE_ID/FileName?node-id=789:012",
{
props: {
title: figma.string("Title"),
hasHeader: figma.boolean("Has Header"),
},
example: ({ title, hasHeader }) => (
<Card>
{hasHeader && (
<CardHeader>
<CardTitle>{title}</CardTitle>
</CardHeader>
)}
<CardContent>{figma.children("Content")}</CardContent>
</Card>
),
},
);The code-connect-components skill handles the full Code Connect workflow:
- Fetches the Figma component structure via MCP
- Maps variants to React props automatically
- Generates the
.figma.tsxfile - Publishes to Figma Dev Mode
Invoke with:
"Connect the Button component to Figma using code connect"
"Create code connect mappings for all components in src/client/components/ui/"
Prioritize:
- High-frequency components — Button, Input, Card, Badge, Avatar
- Components with variants — Those with Figma variant properties map cleanly to React props
- Design system primitives — DSAi tokens (color, typography, spacing)
Skip or defer:
- One-off layout components not shared across designs
- Components that change frequently during iteration
When a component's API changes (new prop, renamed variant), update the .figma.tsx file and re-publish:
npx figma connect publish→ Figma Integration — MCP setup and overall workflow · Figma Tokens — Design token mapping