figma / code-connect

A tool for connecting your design system components in code with your design system in Figma
MIT License
824 stars 62 forks source link

How to not output 'className=""'? #67

Open konki-vienna opened 2 months ago

konki-vienna commented 2 months ago

We have a Button component that behaves differently on different backgrounds. With the Figma prop Background = "On Product" a className "g-inverted" needs to be added to the React code. With the Figma prop "Background = "On Neutral" no className is needed.

The code-connect code className: figma.className([ figma.enum('Background', { 'On Product': 'g-inverted' }), figma.enum('Background', { 'On Neutral': undefined }), ]), adds the "g-inverted" className property correctly, if Background="On Product", however if Background ="On Neutral", the property 'className=""' gets added to the code snippet.

Have I misconfigured something or can't this be achieved?

konki-vienna commented 2 months ago

Bildschirmfoto 2024-06-20 um 16 18 16 Bildschirmfoto 2024-06-20 um 16 18 27

karlpetersson commented 2 months ago

Hey @konki-vienna! Yeah this is a bug, unfortunately undefined values resolve to empty strings. However you might be able to get around this if it's just a single string like in your example, by using only enum:

className: figma.enum('Background', {
    'On Product': 'g-inverted'
})

We'll look into fixing this!