Figma Component Generator 标志

Figma Component Generator

社区
cris-achiardi
figma-component-generator

使用 figma-cli 工具根据源代码生成 Figma 组件集。当用户希望通过读取 React/CSS 源文件来创建或更新 Figma 组件,并生成包含变体、属性和变量绑定的对应组件集时,使用此技能。通过斜杠命令调用,并提供 Figma 页面 URL 或组件名称。

Add to TypingMind

概览

发布者cris-achiardi
代码仓库claude-skills
技能名称figma-component-generator
星标数
72
复刻数
8
附带文件
10
许可协议MIT
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 10 个附带文件

    模型执行任务时可读取的脚本、模板和参考资料。这些文件为只读文件,绝不会被执行。

  • 开源

    由 cris-achiardi 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Figma Component Generator AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/cris-achiardi/claude-skills/tree/main/skills/figma-component-generator
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/cris-achiardi/claude-skills.git /tmp/claude-skills
mkdir -p .claude/skills
cp -r /tmp/claude-skills/skills/figma-component-generator .claude/skills/figma-component-generator
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Figma Component Generator,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Figma Component Generator。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Figma Component Generator 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

Figma Component Generator

Generate Figma component sets from source code (TSX, CSS Modules, metadata files) using the figma-cli eval command. Reads component logic, styles, and optional metadata to produce a properly structured Figma component set with variants, sizes, colors, and boolean properties -- all bound to Figma variables.

Prerequisites

  • The figma-cli repo must be cloned locally
  • Figma Desktop must be running with CDP enabled (port 9222)
  • The target Figma file must be open
  • The daemon should be running (node src/index.js daemon start)

To verify the connection:

bash
curl -s http://localhost:9222/json

Usage

/figma-component-generator <figma-page-url> [component-path]
  • figma-page-url: URL of the Figma page where the component should be created (required)
  • component-path: Path to the component folder (if not provided, ask the user)

Workflow

Step 1: Resolve inputs

Parse the Figma page URL to extract the file and page context. If component-path is not provided, ask the user for it.

Locate the figma-cli repo. Check common locations:

  • Look for a figma-cli directory in the current working directory or its parent
  • Check ~/figma-cli or ~/Projects/figma-cli
  • Or ask the user for the path if not found

Store the CLI path for use in all subsequent eval commands:

CLI_PATH=<path-to-figma-cli>

Step 2: Analyze the component source

Read the component files. At minimum, look for:

  1. Component logic (.tsx, .jsx, .vue, .svelte): Extract props, variants, types, default values
  2. Styles (.module.css, .css, .scss): Extract sizing, colors, spacing, border radius, token usage
  3. Metadata (.metadata.ts, .metadata.json): If available, extract structured variant definitions, sizes, colors, descriptions

From these files, build a component spec:

  • Variant dimensions: Identify the props that create visual variants (e.g., variant: solid|soft|outline, color: primary|danger|..., size: sm|md|lg)
  • Sizing tokens: Map size variants to pixel values (height, padding, font-size, gap)
  • Color tokens: Map each variant+color combination to CSS custom properties (e.g., var(--background-interactive-primary))
  • Boolean features: Identify optional visual elements (dots, icons, close buttons) that should become boolean component properties
  • Shape properties: Border radius, stroke width, stroke alignment

Step 3: Classify component and resolve dependencies

Before querying variables or generating, determine whether this component should be generated as a component set, and if so, resolve its atom dependencies.

Read references/rules/atomic-dependencies.md and follow the classification and resolution workflow:

  1. Classify the component as Visual, Layout Wrapper, or Compositional using the CSS and metadata signals described in the rule
  2. If Layout Wrapper: present the clarity checkpoint to the user and wait for their choice before proceeding. Do NOT generate a component set unless the user explicitly requests it.
  3. If Visual or Compositional: extract dependency names from metadata (composition.nestedComponents, composition.commonPartners) and source imports
  4. Resolve dependencies using the lookup table or Figma traversal (see below)
  5. Build a dependency map: for each found dependency, record the component set ID and available variants. For missing dependencies, warn the user.
  6. Pass the dependency map to Step 6 (generation) so the eval script uses createInstance() instead of raw frames for found dependencies.
Dependency resolution with optional lookup table

An external JSON lookup table may exist that maps component names to Figma node IDs. Read references/figma-map-lookup.md for the full schema and generation instructions.

Resolution order:

  1. Check for lookup table: Look for a figma-map.json file provided by the user (typically in ~/.claude/data/). If found, extract the figmaFileKey and compare it to the file key parsed from the Figma URL. If they match, use the map.
  2. Direct ID lookup (fast path): For each dependency name, check components.<name>.componentSetId in the map. If non-null, use figma.getNodeByIdAsync(id) to fetch the node directly. This avoids cross-page traversal entirely.
  3. Fallback to findAll (slow path): If the map doesn't exist, the file keys don't match, or a dependency isn't in the map, fall back to figma.root.findAll(n => n.type === 'COMPONENT_SET' && n.name === name).

The lookup table is optional — the skill must work without it. Never hardcode a specific file path; treat it as an external data source that may or may not be present.

Step 4: Query Figma variables

Before generating, fetch all available Figma variables to build a mapping:

bash
cd $CLI_PATH && node src/index.js eval "
(async () => {
  const allVars = await figma.variables.getLocalVariablesAsync();
  return JSON.stringify(allVars.map(v => v.name));
})()"

Token-to-variable mapping: Convert CSS token names to Figma variable paths:

  • var(--background-interactive-primary) maps to background/interactive/primary
  • Strip var(-- and ), replace - with / for path segments

For each token used by the component, check if a matching Figma variable exists. Track any unmapped tokens for the final report.

For detailed mapping rules and patterns, read references/figma-plugin-api-patterns.md.

Step 5: Navigate to the target page

Parse the node-id from the Figma URL (URL-encoded, e.g., 2001-2 means 2001:2).

bash
cd $CLI_PATH && node src/index.js eval "
(async () => {
  const targetId = '<decoded-node-id>';
  const page = figma.root.children.find(p => p.id === targetId);
  if (!page) {
    // Fallback: find by name
    const page2 = figma.root.children.find(p => p.name.trim() === '> <ComponentName>');
    if (page2) { figma.currentPage = page2; return 'Navigated by name'; }
    return 'Page not found';
  }
  figma.currentPage = page;
  return 'Navigated to: ' + page.name;
})()"

Step 6: Generate the component set

Build a single eval script that creates all variant combinations. The script must:

  1. Load fonts (load the weights your design system requires -- see references/figma-typography.md)
  2. Fetch variables and create a lookup helper
  3. Create component variants by iterating over all dimension combinations:
    • For each combination of variant properties (e.g., solid + primary + md), create a figma.createComponent()
    • Name it using Figma's variant syntax: Variant=solid, Color=primary, Size=md
    • Set auto-layout, sizing, padding, gap, corner radius
    • Set fills/strokes with placeholder colors, then bind to Figma variables
    • Create child elements (text labels, dots, icons) with proper variable bindings
    • For children that map to resolved dependencies (from Step 3), use componentNode.createInstance() instead of creating raw frames. See references/rules/atomic-dependencies.md for instance creation and variant selection patterns.
    • Add boolean component properties for optional elements
  4. Combine all variants using figma.combineAsVariants(components, figma.currentPage)
  5. Arrange in a grid for readability (remove auto-layout from set, position manually)
  6. Return a report with created count and any unmapped variables

For detailed Figma Plugin API patterns and code examples, read references/figma-plugin-api-patterns.md.

Pattern detection checklist

Before generating, scan the component source for these patterns and load the relevant rule:

PatternDetection SignalRule File
Sizing & layoutAny componentreferences/rules/sizing-modes.md (always read)
Iconslucide-react imports, icon props, SVG elements, spinnersreferences/figma-icon-library.md + references/rules/icon-recoloring.md
TypographyText nodes, font tokens, text-style CSS propertiesreferences/figma-typography.md
Nested components.map() loops, repeated elements with per-item state (isActive, isSelected)references/rules/nested-components.md
Dynamic item countPositive: prop is an array mapped with .map(); runtime-determined count; no fixed upper bound. Negative: named structural children (header/footer); fixed count (OTP=6, rating=5); single-child wrapper (Tooltip trigger); render-propsreferences/rules/slots.md
Floating overlaysImports from @floating-ui/*, @radix-ui/react-popover, @radix-ui/react-dropdown-menu, @radix-ui/react-tooltip, cmdk, @headlessui/react; uses createPortal; position: absolute|fixed with high z-index on the expanded part; conditional render of menu/dropdown/popover contentreferences/rules/floating-overlays.md
Atomic dependenciesMolecule/organism; metadata nestedComponents non-empty; imports design-system componentsreferences/rules/atomic-dependencies.md

Cross-dependency: Nested components and Dynamic item count often fire together. When a parent maps over items AND each item has per-item state (isActive, isSelected), you need BOTH: create a sub-component set per nested-components.md, then use slot Pattern A (instance-filled) in the parent per slots.md. If items are heterogeneous or have no per-item state, only slots.md applies (Pattern B, frame-filled).

Key rules for the eval script:
  • Wrap everything in (async () => { ... })()
  • Always set a placeholder fill/stroke BEFORE binding a variable
  • Append children to parent BEFORE setting layoutSizingHorizontal
  • Apply text style (textStyleId) BEFORE setting .characters (avoids Inter font loading issues)
  • Return JSON.stringify() for structured results
  • Use figma.variables.setBoundVariableForPaint() for variable binding
  • For complex scripts, write to a temp .js file and use eval --file <path>, then clean up after
  • Icons should use your project's icon component set when available -- read references/figma-icon-library.md
  • All text must use the project's font family via Figma text styles -- read references/figma-typography.md
Grid layout strategy:

Arrange variants in a grid where:

  • Columns = sizes (sm, md, lg)
  • Rows = colors (neutral, primary, ...)
  • Sections (separated by gap) = visual variants (solid, soft, outline)

Step 7: Report results

After generation, present a summary:

## Component Generated: Badge

- **Variants created**: 63 (3 variants x 7 colors x 3 sizes)
- **Properties**: Variant, Color, Size, Show Dot (boolean)
- **Variables bound**: 42 fill bindings, 21 stroke bindings
- **Unmapped tokens**: (none)
  OR
- **Unmapped tokens**:
  - `var(--background-utility-coral)` -- no matching Figma variable found
  - `var(--foreground-utility-coral)` -- no matching Figma variable found
- **Dependencies resolved**: 3/5 (Button, SearchInput, Select found; Input, Checkbox not in file)
  OR
- **Dependencies**: none (atom component)

If there are unmapped tokens, suggest the user create the missing variables in Figma or check for naming mismatches.

Important Notes

  • Never delete existing content on the page. Only add new nodes.
  • The figma-cli daemon has a 60-second timeout. For very large component sets (100+ variants), consider splitting into multiple eval calls.
  • If the connection is lost mid-generation, run node src/index.js daemon restart and retry.
  • The eval script can be substantial in size. The daemon handles large payloads.

附带文件

技能加载后,模型会按需读取这些文件。它们仅作为可读文件提供,绝不会被执行。

常见问题

Figma Component Generator AI 技能有什么作用?

使用 figma-cli 工具根据源代码生成 Figma 组件集。当用户希望通过读取 React/CSS 源文件来创建或更新 Figma 组件,并生成包含变体、属性和变量绑定的对应组件集时,使用此技能。通过斜杠命令调用,并提供 Figma 页面 URL 或组件名称。

为什么在 TypingMind 中使用 Figma Component Generator?

因为您只需安装一次,就能搭配任何模型使用。Figma Component Generator 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Figma Component Generator?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/cris-achiardi/claude-skills/tree/main/skills/figma-component-generator。TypingMind 会读取其中的 SKILL.md,打包相关文件,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Figma Component Generator?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Figma Component Generator 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Figma Component Generator 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Figma Component Generator AI 技能免费吗?

是的。cris-achiardi 已在 GitHub 上根据 MIT 许可证发布了该技能。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇