How to Get the Icon Name from an Icon Instance in Figma Code Connect?

Open
#343 1 comment 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
48/100
Issue type
Documentation
Clarity
Mostly clear
Activity status
Stale
Tech stack
figma, typescript
Domain
tooling

Research direction

Start with the Code Connect API documentation and the implementation for figma.instance, which the issue uses in its TypeScript example. Check whether the instance exposes a supported name or SVG property and how examples serialize it. Done means documenting a supported way to read the icon name, or clarifying that Code Connect does not expose one.

Written by the indexing model from the issue text.

Description

API question

Please provide:

Summary
I am trying to extract the icon name (SVG name) from an icon instance in Figma using Code Connect, but I am not sure which property of the icon instance holds the actual name.

Details

Given an icon instance with these properties in the component:

Property Value
Button True
Is Toggled False
Ix Background False
Size Medium
Icon home (Instance type)
Badge False
Keyboard Focus False

And the following code structure:

{
  props: {
    icon: figma.instance('Icon'),
    size: figma.enum('Size', {
      'Extra Small': 'xs',
      Small: 's',
      Medium: 'm',
      Large: 'l',
    }),
    badge: figma.boolean('Badge'),
    button: figma.boolean('Button'),
    
  },
  example: (props: {
    icon: any;
    size?: string;
    badge?: boolean;
    button?: boolean;
  }) => html`
    <ct-icon
      icon="${props.icon}"
      size="${props.size}"
      badge="${props.badge}"
      button="${props.button}"
    >
    </ct-icon>
  `,
}

after publishing above code to figma, code connect code looks like as below,

<sh-icon
**icon="Code Connect Error: Unsupported type 'object' for attribute"**
size="m"
button
></sh-icon>

Question

How do I get the icon name from the icon instance?
From the properties above, is the Icon property (with value home) the correct way to get the icon name?
If not, which property or method should I use to get the SVG/icon name from the icon instance programmatically?

Expected Outcome

  • Guidance on which property contains the actual icon name.
  • Example on how to extract or read the icon name from the instance for further use.

Thank you!

Dominant language
TypeScript
Stars
1.6k
Forks
126
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from figma/code-connect

All issues in figma/code-connect

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.