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

Using "Icons as strings" does not show the string value in Code Connect #235

Open
blabute opened this issue Jan 24, 2025 · 1 comment
Open

Comments

@blabute
Copy link

blabute commented Jan 24, 2025

First, thank you for the awesome tool! This is going to be huge for helping my team manage their Figma mockups and giving developers ready-to-use code for our design system.

I have been following along with the Code Connect Docs for React and am trying to implement the Icons as strings. I am using the Sample Design System community file and sds repository mentioned in the Before you begin section but am getting different results than what the documentation calls out.

Based on the documentation, this is the expected outcome: the dev mode shows the icon as a string

// icon
figma.connect("my-icon-url", {
  example: () => "icon-heart"
})

// parent
figma.connect("my-button-url, {
  props: {
    iconId: figma.instance<string>("InstanceSwapPropName")
  },
  example: ({ iconId }) => <Button iconId={iconId} />
})

// renders in Dev Mode
<Button iconId="icon-heart" />

When implementing it on my side like the below, my reference to iconId is still a reference and not a string.

// icon
figma.connect(
  "my-icon-url",
  {
    props: {
      // These props were
      // name automatically mapped based on your linked code:
      size: figma.enum("Size", {
        "16": "16",
        "20": "20",
        "24": "24",
        "32": "32",
        "40": "40",
        "48": "48",
      }),
    },
    example: (props) => 'activity-icon',
  },
)

// parent
const sharedProps = {
  label: figma.string("Label"),
  iconStart: figma.boolean("Has Icon Start", {
    true: figma.instance<string>("Icon Start"),
    false: undefined,
  }),
  iconEnd: figma.boolean("Has Icon End", {
    true: figma.instance("Icon End"),
    false: undefined,
  }),
  size: figma.enum("Size", {
    Small: "small",
  }),
  isDisabled: figma.enum("State", {
    Disabled: true,
  }),
};

figma.connect(Button, "<FIGMA_BUTTONS_BUTTON>", {
  props: {
    ...sharedProps,
    variant: figma.enum("Variant", {
      Primary: "primary",
      Neutral: "neutral",
      Subtle: "subtle",
    }),
  },
  example: ({ label, iconEnd, iconStart, ...props }) => (
    <Button onPress={() => {}} {...props}>
      {iconStart}
      {label}
      {iconEnd}
    </Button>
  ),
});

// renders in dev mode
<ButtonGroup>
    <Button onPress={() => {}} variant="neutral">
        /* Activity */
        Button
    </Button>
</ButtonGroup>

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
Copy link
Author

blabute commented Jan 28, 2025

Good day! After some more testing, it appears that this issue only occurs in the "Playground" of Figma. If just in the Code Connect view, it works as expected.

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

No branches or pull requests

1 participant