About figma-analyze-component-set
figma-analyze-component-set is a skill that turns a Figma component set into a blueprint for generating component CSS. It identifies variant axes, maps states to CSS or ARIA selectors, and reports visual changes from the default variant for design-system implementation.
Key features
- 01Extract variant axes and component properties
- 02Map states to CSS and ARIA selectors
- 03Report per-variant differences from default
- 04Resolve bound variables to token names
- 05Guide CSS rule generation and validation
Use cases
- 01Translate Figma button variants into CSS states
- 02Build component styles from a design-system set
- 03Check that generated rules cover every component state
Install
Copy the command and run it in a terminal.
npx skills add https:/ / github.com/ southleft/ figma-console-mcp-skills --skill figma-analyze-component-setAfter installing, type/figma-analyze-component-setin Claude Code to confirm it loaded.
Bundled filesscripts/analyze-component-set.js
Details
From the project READMEfigma-analyze-component-set — variant state machine → CSS
Take a Figma COMPONENT_SET (the purple dashed container holding all the variants of one
component) and turn it into a code-generation blueprint: which property axes are state vs size,
how each state maps to a CSS pseudo-class or ARIA attribute, and the minimal visual delta each state
applies on top of the default variant. This is the bridge between "Figma has 12 button variants" and
"emit one .btn rule + :hover/:disabled overrides."
Skill boundaries
use_figmarules — load the officialfigma-useskill first; it is the full Figma Plugin API reference. Essentials these scripts rely on: plain JS with top-levelawait+return(no IIFE, nofigma.closePlugin();console.logis not returned), inputs inlined asconstat the top of each script, colors in 0–1 range, load fonts before any text op,await figma.getNodeByIdAsync(...), and atomic errors (a failed script applies nothing — read the error, fix, retry).- Full recursive tree (unlimited depth, reactions, instance refs) → use
figma-deep-component. - Reorganizing variants into a labeled grid → use
figma-arrange-component-set. - Adding/removing the properties themselves → use
figma-component-properties. - This is a design-system code-gen capability that the native MCP's
get_design_context/get_metadatado not provide — they return raw structure, not a variant→CSS state machine.
Workflow
- Get the COMPONENT_SET id. From the user's selection (
figma_get_selection), a search, or a node id they paste. It must be the set, not an individual variant — the script validates type. - Run
scripts/analyze-component-set.jsviause_figma(skillNames: "figma-analyze-component-set"). Setconst COMPONENT_SET_IDat the top first. - Read the result. It returns
variantAxes(each axis + its options),componentProps(non-variant TEXT/BOOLEAN/INSTANCE_SWAP props → code props), astateMachinewithcssMapping(state name → CSS selector) anddefaultSignature, and per-variantdiffFromDefault. - Generate code. Implement the default variant from
defaultSignature, then add one rule percssMappingentry applying only that variant'sdiffFromDefault. MapcomponentPropsto framework props:BOOLEAN→boolean,TEXT→string,INSTANCE_SWAP→ReactNode/slot,VARIANT→union. - Validate. Cross-check that every state in
stateMachine.statesgot a CSS rule, and that token names in the diff (e.g.Color/Brand/Primary) resolve to your exported tokens.
How states map to CSS
The script normalizes the state axis value (case-insensitive) to a selector:
| Variant value | CSS / ARIA selector |
|---|---|
default | (base rule, no selector) |
hover | :hover |
focus / focused / focus-visible | :focus-visible |
active / pressed | :active |
disabled | :disabled, [aria-disabled="true"] |
error / invalid | [aria-invalid="true"] |
selected | [aria-selected="true"] |
checked | :checked |
loading | [aria-busy="true"] |
open / closed | `[aria-expanded="true" |
filled | .has-value |
Notes
- Diffs are computed against the default variant, so a state's
diffFromDefaultlists only the properties that change (fill token, stroke, text color, opacity, effects, child visibility). Emit exactly those as overrides — don't re-specify unchanged properties. - The script resolves
boundVariables(fills/strokes) to token names when available, falling back to raw hex. Prefer the token name in generated code. - Axis detection is heuristic: an axis named
state/status/interactionis the state axis;size/scaleis the size axis. If your set names axes differently, thecssMappingmay be empty — readvariantAxesand map states yourself.