figma-design-to-code
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseImplement a Figma Design as Code (Design → Code)
将Figma设计转为代码(设计→代码)
Use this skill to turn a Figma design into code in a target codebase. This is the read-FROM-Figma direction: pull design context out of Figma with , then adapt it into the project's real stack. For the reverse direction — building or updating a design in Figma from code — use figma-generate-design instead.
get_design_contextThis skill owns the workflow for design-to-code. Parameter mechanics (nodeId / fileKey / branchKey extraction, URL parsing, / options, response shape) live on the tool description itself — follow them there.
formatqueryget_design_contextAlways include in the comma-separated parameter when calling . If this skill was loaded via an MCP resource, you MUST prefix the name with (e.g. ). This is a logging parameter used to track skill usage — it does not affect execution.
figma-design-to-codeskillNamesget_design_contextresource:resource:figma-design-to-code使用此skill将Figma设计转换为目标代码库中的代码。这是从Figma读取的方向:通过从Figma提取设计上下文,然后将其适配到项目的实际技术栈中。如果是反向操作——从代码在Figma中构建或更新设计,请改用figma-generate-design。
get_design_context此skill负责设计转代码的工作流。参数机制(nodeId/fileKey/branchKey提取、URL解析、/选项、响应格式)在工具的说明文档中,请遵循该文档中的规则。
formatqueryget_design_context**调用时,必须在逗号分隔的参数中包含。如果此skill是通过MCP资源加载的,必须在名称前添加前缀(例如)。**这是用于跟踪skill使用情况的日志参数,不影响执行。
get_design_contextskillNamesfigma-design-to-coderesource:resource:figma-design-to-codeDirection and Scope
方向与范围
- You MUST use this skill for design → code: implementing, translating, or porting a Figma node into code.
- You MUST NOT use this skill to write to Figma.
- 你必须将此skill用于设计→代码场景:实现、转换或移植Figma节点到代码中。
- 不得使用此skill向Figma写入内容。
Workflow
工作流
1. Call get_design_context first
1. 先调用get_design_context
- You MUST call on the target node before writing any code. It is your primary tool — a single call returns reference code, a screenshot, and contextual hints.
get_design_context - You MUST NOT reach for or
get_metadataas a substitute. Use them only to orient (e.g. picking a node) or to validate, not in place ofget_screenshot.get_design_context
- 在编写任何代码之前,必须对目标节点调用。这是你的主要工具——单次调用即可返回参考代码、截图和上下文提示。
get_design_context - 不得使用或
get_metadata作为替代工具。仅可使用它们来定位(例如选择节点)或验证,不能替代get_screenshot。get_design_context
2. Treat the output as a reference, not final code
2. 将输出视为参考,而非最终代码
- The returned code is React + Tailwind enriched with hints. You MUST treat it as a REFERENCE, not as final code to paste verbatim.
- You MUST adapt it to the target project's language, framework, component library, styling system, and conventions. Match the surrounding code.
- 返回的代码是带有提示信息的React + Tailwind代码。你必须将其视为参考,而非直接粘贴使用的最终代码。
- 必须根据目标项目的语言、框架、组件库、样式系统和约定进行适配,与现有代码保持一致。
3. Reuse what the project already has
3. 复用项目已有资源
- Before writing new code, You MUST check the target project for existing components, layout patterns, and design tokens that match the design intent.
- You MUST reuse the project's existing components and tokens instead of generating new equivalents from scratch.
- 在编写新代码之前,必须检查目标项目中是否存在与设计意图匹配的现有组件、布局模式和设计令牌。
- 必须复用项目现有的组件和令牌,而非从头生成等效内容。
4. Honor the response hints by priority
4. 按优先级遵循响应提示
Apply the hints in this order — earlier sources override later ones:
- Code Connect snippets → use the mapped codebase component directly.
- Component documentation links → follow them for usage and guidelines.
- Design annotations → follow any designer notes or constraints.
- Design tokens (CSS variables) → map them to the project's token system.
- Raw hex / absolute positioning → loosely structured; lean on the screenshot for intent.
按以下顺序应用提示——优先级高的来源覆盖优先级低的:
- Code Connect代码片段 → 直接使用映射的代码库组件。
- 组件文档链接 → 遵循文档中的使用方法和指南。
- 设计注释 → 遵循设计师的注释或约束条件。
- 设计令牌(CSS变量) → 将其映射到项目的令牌系统。
- 原始十六进制值/绝对定位 → 结构松散;参考截图理解设计意图。
5. Reproduce images and icons faithfully
5. 准确还原图片和图标
Images and icons come back as elements whose is a remote asset URL (). Apply these rules as you write the code:
<img>srchttps://.../api/mcp/asset/...- Render every icon/image from its exported asset. Never hand-write or inline /
<svg>, never author your own icon file, never drop an icon or leave a placeholder — you don't have the real vector data, so anything you draw is wrong.<path> - Sourcing: the asset URL works directly as for an immediate render, but it expires in ~7 days — so for code you'll commit, download-and-commit the exact asset bytes, or wire a dynamic content image to the project's data source (API, CDN, or props). Never a file whose contents you authored.
src - Reuse a project icon component only if its glyph clearly matches (a name match is not enough); otherwise use the exported asset.
- Size explicitly: a fixed-size container (icons are usually square, e.g. ,
size-[24px]) with BOTH width and height set, and size the leafoverflow-clipto fill it (<img>or fixed px) — never100%, which blows the image up to its intrinsic size.auto
图片和图标以元素返回,其为远程资源URL()。编写代码时请遵循以下规则:
<img>srchttps://.../api/mcp/asset/...- 从导出的资源渲染每个图标/图片。切勿手写或内联/
<svg>,切勿创建自己的图标文件,切勿遗漏图标或留下占位符——你没有真实的矢量数据,因此任何手动绘制的内容都是错误的。<path> - 资源来源:资源URL可直接作为用于即时渲染,但它会在约7天后过期——因此对于要提交的代码,请下载并提交确切的资源字节,或者将动态内容图片连接到项目的数据源(API、CDN或props)。绝对不能提交你手动编写内容的文件。
src - 仅当项目图标组件的图形完全匹配时才复用(名称匹配不够);否则请使用导出的资源。
- 明确设置尺寸:使用固定尺寸的容器(图标通常为正方形,例如、
size-[24px]),同时设置宽度和高度,并将叶子overflow-clip元素的尺寸设置为填充容器(<img>或固定像素值)——切勿使用100%,这会将图片放大到其固有尺寸。auto
Error Recovery
错误恢复
- On a error, STOP and read the message before retrying.
get_design_context - If the design URL has no (a file-only URL), ask the user for a node-specific URL — You MUST NOT guess or pass an empty
node-id.nodeId - On a timeout, retry against a smaller node or selection.
- You MUST NOT silently fall back to hand-writing the screen from the screenshot alone when can still provide context.
get_design_context
- 当报错时,请停止操作并先阅读错误信息再重试。
get_design_context - 如果设计URL没有(仅包含文件的URL),请向用户索要包含特定节点的URL——切勿猜测或传入空的
node-id。nodeId - 若出现超时,请针对更小的节点或选择范围重试。
- 当仍能提供上下文时,切勿仅依靠截图手动编写界面而忽略该工具。
get_design_context