figma / code-snippet-editor-plugin

Translate component variants, properties, and more into dynamic code snippets for your design system.
https://www.figma.com/community/plugin/1311777988952403297/code-snippet-editor
MIT License
126 stars 11 forks source link

How to create json code for global template to output code for all selected components? #42

Closed mikeysouthwell closed 4 months ago

mikeysouthwell commented 4 months ago

Hi Jake,

How do I create a global template that works the same as the Frame with child nodes code, but for components?

Looking through the readme file, it looks like you have to know the component ID, but I want it to convert any component and its children to code.

How do I create the code for this in the JSON file? The example below is where the ID of the component is known in advance, but I would want this to work for all components:


"components": {
    "componentKeyABC123": [
      {
        "title": "Sample React",
        "language": "JAVASCRIPT",
        "code": "<MyComponent />"
      }
    ]
  }
mikeysouthwell commented 4 months ago

Hey Jake. Any update on this?

ja-k-e commented 4 months ago

hey @mikeysouthwell, this is jake, i’m out of office right now so i’m using my personal account. you can use the node type just like any other node. COMPONENT_SET, and COMPONENT should work just fine.

jake-figma commented 4 months ago

will add better documentation, but any node type can be referred to in the global templates types namespace