Figma Integration
Connect your Figma designs to your codebase.
Extracting Design Tokens from Figma
Design tokens are the visual design atoms of the design system — specifically, they are named entities that store visual design attributes. We use them in place of hard-coded values to ensure flexibility and consistency across all product experiences.
Step 1: Install Figma Tokens Plugin
First, you'll need to install the "Figma Tokens" plugin in your Figma account. This plugin helps you manage and export design tokens from your Figma file.
- Open your Figma file
- Click on the "Resources" tab in the toolbar
- Search for "Figma Tokens" and install the plugin
- Launch the plugin from the Plugins menu
Step 2: Export Tokens from Figma
Once you have the plugin installed, you can export your design tokens:
- Open the Figma Tokens plugin
- Configure your tokens (colors, typography, spacing, etc.)
- Click on "Export" and select "JSON" format
- Save the JSON file to your project
Step 3: Transform Tokens for Your Codebase
Now you need to transform the exported tokens to a format that works with your codebase:
- Install Style Dictionary:
npm install style-dictionary --save-dev
- Create a Style Dictionary config file that reads your Figma tokens
- Run Style Dictionary to transform tokens into CSS variables, Tailwind theme, etc.
- Import the generated files into your project
Updating Your Tailwind Configuration
Once you have your design tokens, you'll need to update your Tailwind configuration to use them:
/** @type {import('tailwindcss').Config} */ module.exports = { theme: { extend: { colors: { // Your Figma colors primary: { DEFAULT: "hsl(var(--primary))", foreground: "hsl(var(--primary-foreground))", }, // ... other colors }, // Typography, spacing, etc. }, }, // ... }
Automating the Process
For a more streamlined workflow, you can automate the process of extracting tokens from Figma and updating your codebase:
- Use Figma's API to extract tokens programmatically
- Set up a GitHub Action or other CI/CD pipeline to run the token transformation
- Automatically update your codebase when design tokens change
Next Steps
Now that you have your design tokens integrated with your codebase, you can:
- Create component variants based on your design tokens
- Build a theme switcher to toggle between different token sets
- Document your design tokens for your team