Skip to main content

Advanced

Code Connect

Map Figma design components to your production code — React, SwiftUI, Jetpack Compose, and more.

Code Connect bridges the gap between design and code. It links Figma components to their code implementations, so developers can see real code snippets directly in Figma’s Dev Mode.

How It Works

  1. You define mappings between Figma components and code files
  2. Code Connect pushes these mappings to Figma
  3. Developers see your actual code when inspecting components in Dev Mode

Setup

1
Install the CLI
2
npm install -g @figma/code-connect
3
Authenticate
4
figma connect login
5
This opens a browser window to authenticate with your Figma account.
6
Create a config file
7
figma connect init
8
This creates a figma.config.json in your project root.
9
Write your first mapping
10
Create a Code Connect file next to your component:
11
Button.figma.tsx
import figma from "@figma/code-connect";
import { Button } from "./Button";

figma.connect(Button, "https://figma.com/design/FILE/..?node-id=1:23", {
  props: {
    label: figma.string("Label"),
    variant: figma.enum("Variant", {
      Primary: "primary",
      Secondary: "secondary",
      Ghost: "ghost",
    }),
    disabled: figma.boolean("Disabled"),
    icon: figma.instance("Icon"),
  },
  example: ({ label, variant, disabled, icon }) => (
    <Button variant={variant} disabled={disabled}>
      {icon}
      {label}
    </Button>
  ),
});
Button.figma.swift
import CodeConnect

struct Button_doc: FigmaConnect {
  let component = Button.self
  let figmaNodeUrl = "https://figma.com/design/FILE/..?node-id=1:23"

  @FigmaProp("Label")
  var label: String = "Click me"

  @FigmaProp("Variant", mapping: [
    "Primary": .primary,
    "Secondary": .secondary,
  ])
  var variant: ButtonVariant = .primary

  var body: some View {
    Button(label, variant: variant)
  }
}
Button.figma.kt
import com.figma.code.connect.*

@FigmaConnect("https://figma.com/design/FILE/..?node-id=1:23")
class ButtonDoc {
  @FigmaProp("Label")
  val label: String = "Click me"

  @FigmaProp("Variant", mapping = mapOf(
    "Primary" to ButtonVariant.Primary,
    "Secondary" to ButtonVariant.Secondary,
  ))
  val variant: ButtonVariant = ButtonVariant.Primary

  @FigmaExample
  @Composable
  fun Example() {
    Button(text = label, variant = variant)
  }
}
12
Publish mappings
13
Push your Code Connect mappings to Figma:
14
figma connect publish

Property Mappings

Code Connect maps Figma component properties to code props:

Figma PropertyMapping FunctionCode Output
Textfigma.string("Label")String value
Booleanfigma.boolean("Disabled")true / false
Instance swapfigma.instance("Icon")JSX child
Variantfigma.enum("Variant", {...})Mapped value

Config Reference

{
  "codeConnect": {
    "include": ["src/**/*.figma.{tsx,ts}"],
    "exclude": ["node_modules"],
    "parser": "react",
    "importPaths": {
      "src/components/*": "@mylib/components"
    }
  }
}

Code Connect supports React, SwiftUI, Jetpack Compose, HTML, and custom parsers. Check the official docs for your framework’s specific syntax.

Start by connecting your most-used components first — buttons, inputs, cards. This gives the highest impact for developer adoption.