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

figma.enum actions prop objects are being stringified

Open samyak3009 opened this issue 1 year ago • 2 comments

I am encountering an issue with the figma.enum method when passing an object in the value of the true key for the actions prop. The object is being stringified when viewed in the Figma code, which is not the intended behavior.

figma.connect(Toast, '', {
  props: {
    appearance: figma.enum('Appearance', {
      Info: 'info',
      Success: 'success',
      Warning: 'warning',
      Alert: 'alert',
    }),
    message: figma.enum('Description', {
      true: 'Description goes here',
      false: undefined,
    }),
    actions: figma.enum('Actions', {
      true: [
        { label: 'Action', onClick: function () {} },
        { label: 'Action', onClick: function () {} },
      ],
      false: undefined,
    }),
  },
  example: (props) => <Toast title="Title goes here" {...props} />,
});
Screenshot 2024-07-04 at 1 16 34 PM

The actions prop should accept an array of objects directly, without being stringified. The code should interpret and use the object as-is, maintaining its structure and functionality.

Is there a way to pass objects directly in the actions prop without them being stringified?

samyak3009 avatar Jul 04 '24 09:07 samyak3009

Thanks for the report! We're in the process of improving enum support, we'll look into if we can support this use case too

dentrado avatar Jul 04 '24 14:07 dentrado

@dentrado I encountered a similar issue with a simpler example, so I came here to add that code connect should also interpret and use the array as-is, not just the object elements.

Unexpected stringification of array:

figma.connect(Slider, '', {
  props: {
    value: figma.enum('Handle', {
      Single: [0],
      Double: [0, 100]
    })
  },
  example: props => <Slider {...props} />
});

becomes

import { Slider } from "@/index"

<Slider value="[0]" />

my workaround right now is

figma.connect(Slider, '', {
  variant: { Handle: 'Single' },
  props: { },
  example: props => <Slider value={[0]} />
});

thumbsupep avatar Jan 01 '25 01:01 thumbsupep