---
name: Figma Developer
description: Extract components from Figma, convert designs to React components, sync design tokens, and generate code from designs. Bridge the gap between design and code with automated workflows.
version: 1.0.0
tags: [figma, design-to-code, design-tokens, component-generation]
---
# Figma Developer
Turn Figma designs into production-ready code.
## Core Principle
**Design is the single source of truth.**
Designers work in Figma. Developers build from Figma. The bridge between them should be automated, not manual.
---
## Phase 1: Setup & Authentication
### Get Figma Access Token
1. Go to [Figma Settings](https://www.figma.com/settings)
2. Scroll to "Personal access tokens"
3. Click "Generate new token"
4. Name it (e.g., "Development")
5. Copy and save securely
### Environment Setup
```bash
# .env
FIGMA_ACCESS_TOKEN=figd_...
```
### Install Figma Client
```bash
npm install node-fetch
```
### Test Connection
```typescript
import { FigmaClient } from '@/integrations/design-tools/figma/client'
const client = new FigmaClient({
accessToken: process.env.FIGMA_ACCESS_TOKEN
})
// Test with a public file
const file = await client.getFile('abc123xyz')
console.log('Connected! File:', file.name)
```
---
## Phase 2: Extract Design Tokens
### What Are Design Tokens?
Design tokens are design decisions (colors, typography, spacing) stored as code.
**Benefits:**
- Single source of truth
- Consistent across platforms
- Easy to update
- Type-safe
### Extract Tokens from Figma
```typescript
// scripts/sync-design-tokens.ts
import { FigmaClient } from '@/integrations/design-tools/figma/client'
import fs from 'fs/promises'
async function syncDesignTokens() {
const client = new FigmaClient()
const fileKey = 'YOUR_FIGMA_FILE_KEY'
console.log('Extracting design tokens...')
// Extract tokens
const tokens = await client.extractDesignTokens(fileKey)
console.log(`Found:`)
console.log(` ${tokens.colors.length} colors`)
console.log(` ${tokens.typography.length} text styles`)
console.log(` ${tokens.spacing.length} spacing values`)
// Export as CSS
const css = await client.exportTokensAsCSS(fileKey)
await fs.writeFile('src/styles/design-tokens.css', css)
// Export as JSON
const json = await client.exportTokensAsJSON(fileKey)
await fs.writeFile('src/styles/design-tokens.json', json)
console.log('Design tokens synced!')
}
syncDesignTokens()
```
### Use Tokens in Code
```typescript
// src/styles/design-tokens.css
:root {
/* Colors */
--color-primary: #0066cc;
--color-secondary: #10b981;
--color-neutral-100: #f9fafb;
--color-neutral-900: #111827;
/* Typography */
--font-heading-family: Inter;
--font-heading-size: 48px;
--font-heading-weight: 700;
/* Spacing */
--space-4: 16px;
--space-8: 32px;
}
```
**Usage in React:**
```tsx
// components/Button.tsx
export function Button({ children }: { children: React.ReactNode }) {
return (
)
}
```
---
## Phase 3: Export Assets
### Export Icons as SVG
```typescript
// scripts/export-icons.ts
import { FigmaClient } from '@/integrations/design-tools/figma/client'
import fs from 'fs/promises'
async function exportIcons() {
const client = new FigmaClient()
const fileKey = 'YOUR_FIGMA_FILE_KEY'
// Get file
const file = await client.getFile(fileKey)
// Find "Icons" frame
const iconsFrame = findNode(file.document, 'Icons')
if (!iconsFrame || !iconsFrame.children) {
throw new Error('Icons frame not found')
}
console.log(`Found ${iconsFrame.children.length} icons`)
// Export as SVG
const iconIds = iconsFrame.children.map(child => child.id)
const svgs = await client.exportImages(fileKey, iconIds, {
format: 'svg'
})
// Save each SVG
for (const svg of svgs) {
const response = await fetch(svg.url)
const content = await response.text()
await fs.writeFile(`public/icons/${svg.name}.svg`, content)
console.log(` ✓ ${svg.name}.svg`)
}
console.log('Icons exported!')
}
function findNode(node: any, name: string): any {
if (node.name === name) return node
if (node.children) {
for (const child of node.children) {
const found = findNode(child, name)
if (found) return found
}
}
return null
}
exportIcons()
```
### Generate React Icon Components
```typescript
// scripts/generate-icon-components.ts
import { FigmaClient } from '@/integrations/design-tools/figma/client'
import fs from 'fs/promises'
async function generateIconComponents() {
const client = new FigmaClient()
const fileKey = 'YOUR_FIGMA_FILE_KEY'
const file = await client.getFile(fileKey)
const iconsFrame = findNode(file.document, 'Icons')
if (!iconsFrame || !iconsFrame.children) {
throw new Error('Icons frame not found')
}
// Export icons
const iconIds = iconsFrame.children.map(child => child.id)
const svgs = await client.exportImages(fileKey, iconIds, {
format: 'svg'
})
// Generate React components
for (const svg of svgs) {
const response = await fetch(svg.url)
const svgContent = await response.text()
// Convert to React component
const componentName = toPascalCase(svg.name)
const component = `
import React from 'react'
export function ${componentName}Icon(props: React.SVGProps) {
return (
${svgContent.replace('