figma / code-connect

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

Should figma.enum work in these case? #74

Closed nrenard closed 1 month ago

nrenard commented 3 months ago

I'm trying to map data from a variant using an figma.enum:

Screenshot 2024-06-25 at 2 11 59 PM

The variant has Yes, No and Indeterminate, in the list.

This is the code that i'm doing:

import figma from "@figma/code-connect"

import { Component } from "@veneer/core"

figma.connect(
  Component,
  "...",
  {
    props: {
      checked: figma.enum('Checked', {
        'Yes': true,
        'Indeterminate': 'indeterminated',
        'No': false
      }),
    },
    example: (props) => {
      return (
        <Component {...props} />
      );
    },
  }
);

And the result is that when the variant is No we receive false, when is Indeterminate we receive indeterminated, but when the variant is equal to true we receive nothing... As it is false or something like that.

Should the figma.enum return true in the yes as mapped?

Note: When i ran the create command in this component the auto generate file comes with a figma.boolean in this variant.

karlpetersson commented 3 months ago

Hi @nrenard! Thanks for raising this, this should be fixed in the next release.

What happens here is basically that we convert boolean-like strings like "Yes" and "No" to "true" and "false", which is only intended for figma.boolean, but is currently the case for figma.enum too.

*edit: removed the suggested workaround - we're changing enums in the next release to not normalize values, meaning you will need to put the literal values instead