figma.enum actions prop objects are being stringified
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} />,
});
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?
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 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]} />
});