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

Unable to Use icon via code-connect

Open aditya-anant-zocdoc opened this issue 1 year ago • 15 comments

Code connect : 1.2.0 OS: Mac Somona 14.6.1

I have code connected my icon library. Here is the code snipit for Icons

figma.connect(
    IconPast,
    'https://figma.com/file/vuFujhehhBk3qpDDOFLbMM/?node-id=25270-7765',
    {
        props,
        example: ({ size }) => <IconPast size={size} />,
    }
);

The Icons master component looks like this and the code connect's code Screenshot 2024-10-28 at 2 00 17 PM

When I try to use these icon for other component for ex Pill, here is the usage

import figma from '@figma/code-connect';
import React from 'react';
import Pill from './Pill';

figma.connect(
    Pill,
    'https://www.figma.com/design/vuFujhehhBk3qpDDOFLbMM/Mezzanine-Library?node-id=39674-1682&m=dev',
    {
      props: {
            disabled: figma.boolean('disabled'),
            isSelected: figma.enum('State', {
                Selected: true,
                Default: false,
            }),
            leftIcon: figma.boolean('leftIcon', {
                true: figma.instance('Icon'),
                false: undefined,
            }),
            children: figma.textContent('Label'),
        },
        example: ({
            disabled = false,
            isSelected,
            children = 'label',
            leftIcon,
        }) => (
            <Pill
                isSelected={isSelected}
                disabled={disabled}
                onClick={() => {}}
                LeftIcon={leftIcon}
            >
                {children}
            </Pill>
        ),
    }
);

However in figma I see the error when leftIcon bool is set to true. Screenshot 2024-10-28 at 2 04 49 PM

Is there anything that I am doing wrong.

aditya-anant-zocdoc avatar Oct 28 '24 08:10 aditya-anant-zocdoc

Hi @aditya-anant-zocdoc . Can you confirm whether this same issue occurs when you click on the variant in the file (not the playground) please?

rrabherufigma avatar Oct 28 '24 10:10 rrabherufigma

Hi @rrabherufigma Yes the same error is coming in variant as well here is the screenshot for ref. Screenshot 2024-10-28 at 5 40 22 PM

aditya-anant-zocdoc avatar Oct 28 '24 12:10 aditya-anant-zocdoc

Hi @aditya-anant-zocdoc . Thank you. Can you try with figma.nestedProps

I think it would be:

import figma from '@figma/code-connect';
import React from 'react';
import Pill from './Pill';

figma.connect(
    Pill,
    'https://www.figma.com/design/vuFujhehhBk3qpDDOFLbMM/Mezzanine-Library?node-id=39674-1682&m=dev',
    {
      props: {
            disabled: figma.boolean('disabled'),
            isSelected: figma.enum('State', {
                Selected: true,
                Default: false,
            }),
            leftIcon: figma.boolean('leftIcon', {
                true: figma.nestedProps('Icon', {
                    instance: figma.instance('Instance'),
                }),
                false: {instance: undefined},
            }),
            children: figma.textContent('Label'),
        },
        example: ({
            disabled = false,
            isSelected,
            children = 'label',
            leftIcon,
        }) => (
            <Pill
                isSelected={isSelected}
                disabled={disabled}
                onClick={() => {}}
                LeftIcon={leftIcon.instance}
            >
                {children}
            </Pill>
        ),
    }
);

rrabherufigma avatar Oct 28 '24 15:10 rrabherufigma

No luck, now it is showing can't load code connect example error Screenshot 2024-10-28 at 9 07 37 PM

aditya-anant-zocdoc avatar Oct 28 '24 15:10 aditya-anant-zocdoc

Hi @aditya-anant-zocdoc can you try the above code again please? The above code had an incorrect character which I have removed

rrabherufigma avatar Oct 29 '24 13:10 rrabherufigma

Hi @rrabherufigma Sorry for late reply, It is not working same error is coming Screenshot 2024-10-29 at 8 10 48 PM

aditya-anant-zocdoc avatar Oct 29 '24 14:10 aditya-anant-zocdoc

HI @aditya-anant-zocdoc . Would you be willing to share your file with us so we can investigate further ? If so, please contact via support at Figma support

rrabherufigma avatar Oct 29 '24 17:10 rrabherufigma

I have already raised the issue last week. Though didn't got the ticket number to track it. Here is the screen shot of the mail that I got. Maybe we can sync over call or something to better understand the root cause Screenshot 2024-10-29 at 10 54 38 PM

aditya-anant-zocdoc avatar Oct 29 '24 17:10 aditya-anant-zocdoc

HI @aditya-anant-zocdoc can you try

leftIcon: figma.boolean('leftIcon', {
                true: figma.nestedProps('Left Icon', {
                    instance: figma.instance('Instance'),
                }),
                false: {instance: undefined},
            }),

rrabherufigma avatar Oct 30 '24 11:10 rrabherufigma

Though this time it don't show error, but not showing icon as well. For the instance which should have icon in design Screenshot 2024-10-30 at 4 46 13 PM

aditya-anant-zocdoc avatar Oct 30 '24 11:10 aditya-anant-zocdoc

Hi @aditya-anant-zocdoc , can you share your full code connect file please

rrabherufigma avatar Oct 30 '24 11:10 rrabherufigma

i have attached file and link to figma is the support ticket : http://help.figma.com/hc/requests/1157416

aditya-anant-zocdoc avatar Oct 30 '24 11:10 aditya-anant-zocdoc

Hi @aditya-anant-zocdoc Thank you. Please try changing LeftIcon={leftIcon} to LeftIcon={leftIcon.instance}

rrabherufigma avatar Oct 30 '24 14:10 rrabherufigma

Thank you for being so prompt on this issue. So it somewhat works. But it has some issue

  1. The Icons should have come as React.ComponentType but it coming as React.Component
<Pill onClick={() => {}} LeftIcon={<IconVideoCircle />}>
Label
</Pill>

rather it should be

<Pill onClick={() => {}} LeftIcon={IconVideoCircle}>
Label
</Pill>
  1. On changing to other icons from drop down, it shows
<Pill onClick={() => {}} LeftIcon={
Icon Asset / Verified
}>
Label
</Pill>

aditya-anant-zocdoc avatar Oct 30 '24 14:10 aditya-anant-zocdoc

Hi @aditya-anant-zocdoc . To support icons, please refer to this section in the documentation https://github.com/figma/code-connect/blob/main/docs/react.md#icons-as-react-components

rrabherufigma avatar Oct 30 '24 17:10 rrabherufigma