code-connect icon indicating copy to clipboard operation
code-connect copied to clipboard

Accessing Instance props (getProps) when using figma.children()

Open blabute opened this issue 10 months ago • 6 comments

Good day!

Similar to https://github.com/figma/code-connect/issues/215, our designer is also using Icons as children instead of instance swap properties. Is it possible to use the getProps on this result to get the properties of this mapped instance?

Figma

Image

What I'd like to do

figma.children('*').getProps<{ name: string }>()

Similar to

figma.instance('icon').getProps<{ name: string }>()

Note: when there is an instance swap property, figma.instance('icon').getProps<{ name: string }>() does work but this specific component in Figma does not have one.

What it looks like now

<Badge icon={<Icon icon="IconName" size={16} />} />

What I would like it to be

<Badge icon="IconName" />

Please provide:

  • Code Connect CLI version [use npx figma -V if using React, or figma -V otherwise, to get the version of your CLI]
    • 1.2.4
  • Operating system
    • macOS 15.2 (25C101)

Thanks for the help!

blabute avatar Feb 18 '25 15:02 blabute

This is similar to https://github.com/figma/code-connect/issues/215 but i am unsure if this will be resolved at the same time.

blabute avatar Feb 18 '25 15:02 blabute

Hello! Just checking in on this one. Thank you

blabute avatar Feb 26 '25 13:02 blabute

Hey @blabute! Thanks for the report - this is a limitation with our API at the moment, as getProps can only be used on the instance() helper. We're thinking about how we can expand this to be compatible with children() too but currently there isn't a workaround for this case I'm afraid

slees-figma avatar Feb 27 '25 10:02 slees-figma

Hello @slees-figma! Thanks for the information. We look forward to that functionality!

Somewhat related, does nestedProps support using a wildcard (*) for the layerName like children does? We've got a setup that works using nestedProps, but the layer name can be different depending on the Icon being used so wanted to explore that. From my testing, nestedProps does not support using a wildcard for the layerName.

blabute avatar Mar 04 '25 14:03 blabute

Hey @blabute, that's right unfortunately, the wildcard option is only available on figma.children right now

slees-figma avatar Mar 04 '25 18:03 slees-figma

Thanks, @slees-figma! I appreciate the quick response!

In case anyone comes across this and the feature is not yet available, as a workaround, my team is:

  1. Using nestedProps and has renamed the "layer" of the Icon to be "icon". Even if the designer updates the instance of the icon to be a different icon, the layer name persists.
  2. Added a property to each Icon named "name" that uniquely identifies the Icon.
  3. Maps the icon name in Figma to our Icon name in code like in the below.
figma.nestedProps('icon', {
  name: figma.enum('name', {
    ...
  })
})

blabute avatar Mar 04 '25 20:03 blabute