code-connect icon indicating copy to clipboard operation
code-connect copied to clipboard

Display Imports for both the icon file and the generic component

Open plbabin opened this issue 1 year ago • 1 comments

In our react design system, we do have a generic Icon component that gets an icon svg file as a prop:

import PlusSmall from `hsds/icons/plus-small`
import Icon from `hsds/components/icon`

<Icon icon={PlusSmall} />

In figma, we do not have that generic Icon component. That being said, I was able to map all our icons. this is a simplified version of our icons.figma.tsx file looks like:

import figma from '@figma/code-connect'

import Icon from 'hsds/components/Icon'
import PlusSmall from 'hsds/icons/plus-small'

figma.connect(
  ArrowLeft,
  '<link_to_figma_file>',
  {
    example: () => <Icon icon={PlusSmall} />,
  }
)

It works in code connect with our Button component. My question is about the import list, is there a way (or workaround) to have both the generic component import AND the svg file import in our button code connect?

CleanShot 2024-08-20 at 16 57 16@2x

plbabin avatar Aug 20 '24 21:08 plbabin

Hey plbabin thanks for the question -- Since in this case the icons themselves aren't being picked up, I would recommend using custom imports in your icons.figma.tsx file.

You can override the generated import statements for a connected component by passing an array of imports. In this example, you might write something like

figma.connect(
  ArrowLeft,
  '<link_to_figma_file>',
  {
    imports: ["import Icon from `hsds/components/icon`"]
    example: () => <Icon icon={PlusSmall} />,
  }
)

Then, whenever this icon is being used the nested import should also be added to your file. Let me know if that works for you.

jyyang0 avatar Aug 21 '24 14:08 jyyang0

that was exactly what I needed, thank you!!

CleanShot 2024-08-21 at 17 18 41@2x

plbabin avatar Aug 21 '24 21:08 plbabin