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

variant restriction boolean bug #45

Open
alisonjoseph opened this issue May 2, 2024 · 2 comments
Open

variant restriction boolean bug #45

alisonjoseph opened this issue May 2, 2024 · 2 comments
Labels
under discussion The Code Connect team is currently discussing this request

Comments

@alisonjoseph
Copy link

I'm getting the following error when trying to create a variant restriction with a boolean property
The Figma Variant "Actionable" does not have an option for true

When creating my code connect file the property comes through: figma.boolean('Actionable'), and I can see it in Figma also. Is this a bug, or is my implementation incorrect?

figma.connect(
  ActionableNotification,
  'https://www.figma.com...',
  {
    variant: { Actionable: true },
    props: sharedNotificationProps,
    example: ({ title, kind, subtitle, hideCloseButton }) => (
      <ActionableNotification
        kind={kind}
        title={title}
        subtitle={subtitle}
        hideCloseButton={hideCloseButton}
      />
    ),
  }
);
@tomduncalf-figma
Copy link

tomduncalf-figma commented May 3, 2024

Hey @alisonjoseph, I think what could be going on here is that your property in Figma is actually a variant property with "boolean-like string values" rather than a true boolean. It might be the string "True" or "Yes" or something like that.

We automatically translate these "boolean-like" strings to boolean values when using figma.boolean, but I don't think we do the same for variant restrictions, so you'd need to specify the literal value from Figma e.g. variant: { Actionable: "True" }.

I think this is something we should fix, so that the API is consistent across props and variant restrictions.

Feel free to share a screenshot of your component's properties in Figma if you're not sure, and if this isn't the case we'd be happy to investigate further.

@ptomas-figma ptomas-figma added the under discussion The Code Connect team is currently discussing this request label May 3, 2024
@alisonjoseph
Copy link
Author

alisonjoseph commented May 3, 2024

Thanks for the quick response @tomduncalf-figma , you're correct I think that's exactly what was happening. I'm no longer seeing an error, however it seems to be ignoring the variant restriction completely and just rendering the first one no matter if actionable is true or false.

const sharedNotificationProps = {
  .....
  actionable: figma.boolean('Actionable'),
};

figma.connect(
  ActionableNotification,
  'https://www.figma.com...',
  {
    variant: { Actionable: 'True' },
    props: sharedNotificationProps,
    example: ({ title, kind, subtitle, hideCloseButton, actionable }) => (
      <>
        actionable: {actionable}
        <ActionableNotification
          kind={kind}
          title={title}
          subtitle={subtitle}
          hideCloseButton={hideCloseButton}
          lowContrast={lowContrast}
        />
      </>
    ),
  }
);


figma.connect(
  InlineNotification,
  'https://www.figma.com....',
  {
    variant: { Actionable: 'False' },
    props: sharedNotificationProps,
    example: ({ title, kind, subtitle, hideCloseButton, actionable }) => (
      <>
        actionable: {actionable}
        <InlineNotification
          title={title}
          kind={kind}
          subtitle={subtitle}
          hideCloseButton={hideCloseButton}
        />
      </>
    ),
  }
);

Screenshot 2024-05-03 at 9 59 21 AM
Screenshot 2024-05-03 at 9 59 39 AM

Screenshot 2024-05-03 at 10 01 39 AM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
under discussion The Code Connect team is currently discussing this request
Projects
None yet
Development

No branches or pull requests

3 participants