Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapping from figma.enum / variant property to enum in React code does not work as expected #55

Closed
AHumphriesPD opened this issue May 17, 2024 · 2 comments · May be fixed by lucksy/code-connect-demo#1

Comments

@AHumphriesPD
Copy link

I'm not sure if I'm misunderstanding the documentation or if this is a bug or limitation of some kind.

Based on this example from the React README:

// maps the 'Options' variant in Figma to enum values in code
figma.enum('Options', {
  'Option 1': Option.first,
  'Option 2': Option.second,
})

Here's a stripped down version of the code connect file to try to isolate the issue:

figma.connect(
  ButtonPrimary,
  "https://www.figma.com/design/this-is-not-a-real-link",
  {
    props: {
      text: figma.string("text"),
      iconLocation: figma.enum("iconLocation", {
        left: IconLocation.LEFT,
        right: IconLocation.RIGHT,
        none: IconLocation.NONE
      })
    },
    example: (props) => <ButtonPrimary
      buttonText={props.text}
      iconSide={props.iconLocation}
    />,
  },
)

and the output in Figma's dev mode for a button with the iconLocation variant property set to "left":

  <ButtonPrimary
      buttonText="label"
      iconSide="IconLocation.LEFT"
  />

I would expect the output to look like this, so that if it were copied and pasted into another React component, it would use the actual enum from the code, rather than using a string:

  <ButtonPrimary
      buttonText="label"
      iconSide={IconLocation.LEFT}
  />

I have tried this with the enum being imported, with it being local to the code connect file, with the enum's type being number, and with it's type being string, and they all result in the same output described above.

@jyyang0
Copy link

jyyang0 commented May 22, 2024

Hey @AHumphriesPD, thanks for the report! -- The team is aware of this issue and it should be fixed in the next release.

@ptomas-figma
Copy link
Collaborator

@AHumphriesPD we just released 0.2.1 that should fix this issue. I'll close it for now, but feel free to reopen if that's not the case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants