Generate Component from Figma
Name
figma:figma-generate-component - Generate production-ready code from Figma designs
Synopsis
Convert Figma frames and components into production code (React, Vue, HTML/CSS) using the Figma Desktop MCP server with support for Code Connect mappings and design tokens.
Description
You are tasked with generating production-ready code from a Figma design using the Figma MCP server. This command bridges the design-to-code workflow by analyzing Figma frames and converting them into semantic, accessible, framework-specific components.
Implementation
Uses the Figma Desktop MCP server (HTTP transport at http://127.0.0.1:3845/mcp) to access selected frames or node IDs from Figma URLs. Leverages Code Connect mappings when available to prefer design system components over generating code from scratch.
Input Methods
The user can provide Figma context in two ways:
- Selection-based: User has selected a frame in Figma desktop app
- Link-based: User provides a Figma URL with node ID
Your Task
Understand the Context:
- If the user selected a frame in Figma, access it via MCP
- If the user provided a URL, extract the node ID and access the design
- If neither is provided, ask the user to either:
- Select a frame in Figma and try again, OR
- Provide a Figma URL with a node ID
Analyze the Design:
- Use Figma MCP tools to extract the frame structure
- Identify components, layout, styling, and content
- Note any design tokens or variables used
- Check for Code Connect mappings if available
Generate Code:
- Ask the user what framework/language they want (React, Vue, HTML/CSS, etc.)
- Generate clean, production-ready code that matches the design
- Use semantic HTML and accessible markup
- Apply proper component patterns for the target framework
- Use design system components if Code Connect mappings exist
- Include comments explaining key decisions
Provide Context:
- Explain the component structure
- Note any design tokens that should be added to the design system
- Suggest any improvements or accessibility enhancements
- Mention responsive behavior considerations
Best Practices
- Semantic HTML: Use appropriate HTML elements (nav, main, article, etc.)
- Accessibility: Include ARIA labels, proper heading hierarchy, keyboard navigation
- Design Tokens: Use variables for colors, spacing, typography when possible
- Component Composition: Break complex UIs into smaller, reusable components
- Responsive Design: Consider mobile, tablet, desktop breakpoints
- Code Connect: Prefer mapped components over generating from scratch
Example Output Format
When generating a React component, structure it like:
// ComponentName.tsx
import React from 'react';
import { DesignSystemButton } from '@/components/Button'; // Using Code Connect mapping
interface ComponentNameProps {
// Props based on Figma variants
}
/**
* ComponentName - Brief description
*
* Figma: [Link to Figma frame]
* Design tokens used: --color-primary, --spacing-md, --font-heading
*/
export const ComponentName: React.FC<ComponentNameProps> = ({ ...props }) => {
return (
// JSX matching Figma layout
);
};
Validation
Before finishing:
- Verify the code compiles/is valid syntax
- Check that layout matches Figma design
- Ensure all interactive elements are accessible
- Confirm design tokens are properly referenced
- Note any missing assets or resources needed
Notes
- If the Figma MCP server is not connected, provide setup instructions
- If the frame is very complex, offer to break it into multiple components
- Always respect the user's framework preference
- Suggest testing in different viewports/screen sizes
1---2name: figma-generate-component3description: Generate production-ready code from a Figma component or frame using the Figma MCP server4---5
6# Generate Component from Figma
7
8## Name
9
10figma:figma-generate-component - Generate production-ready code from Figma designs
11
12## Synopsis
13
14Convert Figma frames and components into production code (React, Vue, HTML/CSS) using the Figma Desktop MCP server with support for Code Connect mappings and design tokens.
15
16## Description
17
18You are tasked with generating production-ready code from a Figma design using the Figma MCP server. This command bridges the design-to-code workflow by analyzing Figma frames and converting them into semantic, accessible, framework-specific components.
19
20## Implementation
21
22Uses the Figma Desktop MCP server (HTTP transport at `http://127.0.0.1:3845/mcp`) to access selected frames or node IDs from Figma URLs. Leverages Code Connect mappings when available to prefer design system components over generating code from scratch.
23
24## Input Methods
25
26The user can provide Figma context in two ways:
27
281. **Selection-based**: User has selected a frame in Figma desktop app
292. **Link-based**: User provides a Figma URL with node ID
30
31## Your Task
32
331. **Understand the Context**:
34 - If the user selected a frame in Figma, access it via MCP
35 - If the user provided a URL, extract the node ID and access the design
36 - If neither is provided, ask the user to either:
37 - Select a frame in Figma and try again, OR
38 - Provide a Figma URL with a node ID
39
402. **Analyze the Design**:
41 - Use Figma MCP tools to extract the frame structure
42 - Identify components, layout, styling, and content
43 - Note any design tokens or variables used
44 - Check for Code Connect mappings if available
45
463. **Generate Code**:
47 - Ask the user what framework/language they want (React, Vue, HTML/CSS, etc.)
48 - Generate clean, production-ready code that matches the design
49 - Use semantic HTML and accessible markup
50 - Apply proper component patterns for the target framework
51 - Use design system components if Code Connect mappings exist
52 - Include comments explaining key decisions
53
544. **Provide Context**:
55 - Explain the component structure
56 - Note any design tokens that should be added to the design system
57 - Suggest any improvements or accessibility enhancements
58 - Mention responsive behavior considerations
59
60## Best Practices
61
62- **Semantic HTML**: Use appropriate HTML elements (nav, main, article, etc.)
63- **Accessibility**: Include ARIA labels, proper heading hierarchy, keyboard navigation
64- **Design Tokens**: Use variables for colors, spacing, typography when possible
65- **Component Composition**: Break complex UIs into smaller, reusable components
66- **Responsive Design**: Consider mobile, tablet, desktop breakpoints
67- **Code Connect**: Prefer mapped components over generating from scratch
68
69## Example Output Format
70
71When generating a React component, structure it like:
72
73```tsx
74// ComponentName.tsx
75import React from 'react';
76import { DesignSystemButton } from '@/components/Button'; // Using Code Connect mapping
77
78interface ComponentNameProps {
79 // Props based on Figma variants
80}
81
82/**
83 * ComponentName - Brief description
84 *
85 * Figma: [Link to Figma frame]
86 * Design tokens used: --color-primary, --spacing-md, --font-heading
87 */
88export const ComponentName: React.FC<ComponentNameProps> = ({ ...props }) => {
89 return (
90 // JSX matching Figma layout
91 );
92};
93```
94
95## Validation
96
97Before finishing:
98
991. Verify the code compiles/is valid syntax
1002. Check that layout matches Figma design
1013. Ensure all interactive elements are accessible
1024. Confirm design tokens are properly referenced
1035. Note any missing assets or resources needed
104
105## Notes
106
107- If the Figma MCP server is not connected, provide setup instructions
108- If the frame is very complex, offer to break it into multiple components
109- Always respect the user's framework preference
110- Suggest testing in different viewports/screen sizes