Learn how to ship impactful customer journeys with Builder

Announcing Visual Copilot - Figma to production in half the time

Builder.io logo
Contact Sales
Platform
Developers
Contact Sales

Blog

Home

Resources

Blog

Forum

Github

Login

Signup

×

Visual CMS

Drag-and-drop visual editor and headless CMS for any tech stack

Theme Studio for Shopify

Build and optimize your Shopify-hosted storefront, no coding required

Resources

Blog

Get StartedLogin

in beta

for developers

With the Builder Figma plugin, you can map your Figma designs to your code components.

As an example, suppose you have a design system in Figma and a set of components in code that correspond to the designs in Figma. With the Builder Figma Plugin, you can map these components to each other and generate quality code.

The image below shows a design and its corresponding code, which component mapping can help you achieve.

Image of a product card and a code snippet that correspond to one another.

To get the most out of this document, you should:

  • Have a Next.js, Remix, React with Vite, or Angular app ready with React or Angular components.
  • Have a Builder Space.
  • Have design components in Figma.

To map your Figma components using the Builder Figma plugin:

  1. In Figma, open the Builder Figma plugin.
  2. Click the Login button that displays on the bottom left of the plugin or the Connect with Builder button.
  3. When prompted in the browser, choose the Space you want to authorize access to and click the Authorize button.
  4. Go back to Figma. When the authorization is successful, the plugin shows the Space you're connected to.
  5. Select the design.
  6. On the plugin, click Map.
  7. On the Design System tab, copy the generated command.
  8. Paste the command at the command line. This command contains Figma IDs for mapping the components.
  9. When prompted, authorize the Builder CLI by clicking on the Allow access button.
  10. Confirm you have the right Space selected and Authorize Devtools by clicking on the Authorize button.
  11. Back at the command line, the CLI authenticates and detects components.
  12. Select the components you want to map.

For details on the plugin, read Importing from Figma. The video below shows using the plugin and CLI to authenticate, authorize the CLI and Devtools, and map components from an example Figma design.

For details on the plugin, read Importing from Figma.

To map components in your codebase, they need to be discoverable by Builder's Devtools. That means you must export your components from any JavaScript or TypeScript file in your code, and (ideally) define their prop types in TypeScript or JSDoc types.

Additionally, you must make sure the plugin has the correct Public API Key and that the model names match.

Provided components are properly exported, the plugin can detect components in the following types of files:

  • .js
  • .jsx
  • .ts
  • .tsx

In order for the plugin to detect library components, always make sure to export the components you want to map from one of the file types listed earlier in this section.

As a best practice, export the component and use types for props:

// ✅
export function MyComponent(props: { title: string }) {
  return ...
}

// ✅
export const MyOtherComponent = () => ...

It's also acceptable to export the component later in your file:

type MyProps = { title: string }

const MyComponent = (props: MyProps) => ...

// ✅
export default MyComponent;

You must always export the components you want to map. If you do not export them, they do not show up in the plugin. As an example, notice that this component is never exported, so it will not work:

// 🚩 doesn't work, needs to be exported!
function MyComponent() { ... }

The plugin operates optimally with TypeScript, enhancing its ability to map your Figma designs to the respective code components efficiently. Because of this, we recommend that you always define types for your component props.

// ✅
export function MyComponent(props: { title: string }) {
  return ...
}


// ✅
type MyProps = { title: string }
export function MyComponent(props: MyProps) {
  return ...
}

While JavaScript without TypeScript is compatible, adding types to your props is ideal for the Builder's automapper to function most effectively:

/**
 * @param {Object} props
 * @param {string} props.title 
 * @param {number} props.enabled
 * @param {number} props.count
 */
export function MyComponent(props) {
  return ...
}

When integrating code into your project from libraries like shadcn, the Builder Figma plugin works out of the box because it recognizes components that are defined and exported directly from the code. However, if you're using components from a package that aren't explicitly present in your codebase, you can still map them by re-exporting as below:

// src/components.tsx
export { Button, Card, TextField } from '@mui/material'
export { DatePicker } from 'antd';

The example shows a file called components.tsx — though the actual file name doesn't matter — and exports components from libraries. By being exported in this way, these components are discoverable by Builder's Devtools.

Be sure to export each component you want to map. In the above example, only Button, Card, TextField, and DatePicker will be mappable. Export globs; for example, export * from 'package', are not currently supported.

When using Builder Devtools with component mapping, a new route called figma imports is generated in your project so you can access imported Figma components.

This workflow assumes you are developing on localhost. To enable access for users who are not running Devtools locally, you must update the Preview URL in Builder for the Figma Imports model.

  1. Using the techniques outlined in this document, map at least one Figma design to a code component in your project. After you've successfully mapped at least one component, a model named Figma Imports model displays in Builder and a route is added to your project.
  2. Deploy the project to a production environment.
  3. Go to Models in Builder and update the Preview URL for the Figma Imports model in Builder to match the production URL format; for example, yoursite.com/figma-imports. This makes sure that users accessing the Figma components without running Devtools locally can use the imported components.

The video below shows going to the Models section of Builder and selecting the Figma Imports model. Note that you won't find that model listed if you haven't completed at least one Figma import using component mapping.

When you open the model, edit the Preview URL field so that others can use the newly mapped component.

This section covered Preview URLs specifically for Figma Imports. For more information on Preview URLs in other use cases, visit Editing and Previewing Your Site.

Certain parts of the this workflow use AI, for more information, visit How Builder Uses AI.

Was this article helpful?

Product

Visual CMS

Theme Studio for Shopify

Sign up

Login

Featured Integrations

React

Angular

Next.js

Gatsby

Get In Touch

Chat With Us

Twitter

Linkedin

Careers

© 2020 Builder.io, Inc.

Security

Privacy Policy

Terms of Service

Newsletter

Get the latest from Builder.io

By submitting, you agree to our Privacy Policy

Product

Platform Overview

Integrations

What's New

Open Source

Builder

Builder

Mitosis

Mitosis

Qwik

Qwik

Partytown

Partytown

Popular Guides

From Design to Code Guide

Composable Commerce Guide

Headless CMS Guide

Headless Commerce Guide

Composable DXP Guide

Design to Code

Resources

Blog

Knowledge Base

Community Forum

Partners

Templates

Success Stories

Showcase

Resource Center

Frameworks

React

React

Next

Next.js

Qwik

Qwik

Gatsby

Gatsby

Angular

Angular

Vue

Vue

Svelte

Svelte

Remix logo

Remix

Nuxt

Nuxt

Hydrogen

Hydrogen

See All

© 2024 Builder.io, Inc.

Security

Privacy Policy

SaaS Terms

Security & Compliance

Cookie Preferences

Gartner Cool Vendor 2024