figma / code-connect

A tool for connecting your design system components in code with your design system in Figma
MIT License
949 stars 68 forks source link

Ability to transform string values #106

Open jimmymorris opened 3 months ago

jimmymorris commented 3 months ago

Describe the feature you'd like:

With some of our components the prop's type is number, but there is no option for us to transform the figma.string into a number. I feel like being able to do a callback like figma.string('label', (val:string) => Number(val)) would be sufficient.

dentrado commented 3 months ago

Hi @jimmymorris! We are looking at how we can make string handling more flexible, thanks for providing another use case for us to look at.

ericandrewscott commented 1 month ago

I have this same question. I opened an issue here because I wasn't sure if it was supported.

In our case, we want to use the textContent from a layer and parse it as a number instead of a string. Something like:

      value: figma.nestedProps("✏️ Value", {
        number: parseInt(figma.textContent("✏️ Text")),
      }),

but then we get the Unknown intrinsic error.

What @jimmymorris mentioned would work too! Provided it also works for figma.textContent()! Something like:

      value: figma.nestedProps("✏️ Value", {
        number: figma.textContent("✏️ Text", (val:string) => Number(val)),
      }),
tomduncalf-figma commented 1 month ago

Hey @ericandrewscott, unfortunately this is not supported right now. We are working on ways to improve flexibility here.