Skip to main content
Solved

Add Components (+variants) via my own Plugin

  • December 5, 2024
  • 5 replies
  • 41 views

chriskuhrt

So I’m already able to add Colors, Frames with a Grid, and an Image via my plugin to a new Figma file.

But is there an easy way to add a Component with variants etc?

These would be my need:


Is it possible to build the component in Figma, extract the relevant JSON data, and seamlessly integrate it into my plugin? Or do I need to recreate the component entirely from scratch in code? via Shared Node Properties | Plugin API

Best answer by tank666

If I understand you correctly, you can use the figma.createComponentFromNode(node) method to create a component from an existing node, and then combine them as component set variants using:

figma.com
View original

5 replies

tank666
  • 4854 replies
  • Answer
  • December 5, 2024

If I understand you correctly, you can use the figma.createComponentFromNode(node) method to create a component from an existing node, and then combine them as component set variants using:

figma.com

chriskuhrt
  • Author
  • 9 replies
  • December 5, 2024

This could be it! How did I missed that?! I’ll let you know if it works as hoped. - Thx!


chriskuhrt
  • Author
  • 9 replies
  • December 25, 2024

It worked! Thanks!

It seems that the layers panel always expand after creating the components via the API. Apparently there is no way to collapse it back again?!, accept manually of course.


tank666
  • 4854 replies
  • December 25, 2024
node.expanded = false

Please refer to the developer documentation:

figma.com

chriskuhrt
  • Author
  • 9 replies
  • December 25, 2024

thank you for your patience despite my inability…
i was too focused on the layer panel and its wording and didn’t think about the fact that i might be looking more at the “children” (nodes).


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings