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

combine figma.boolean with figma.nestedProps

Open bastifudali opened this issue 1 year ago • 7 comments

We use nested components in our design system quite a lot and utilize figma.nestedProps to map their props to the parents props in code. Only thing that doesn't work for us is when we have an optional nested component, i.e. that can be shown/hidden with a boolean property in Figma. It seems like we can use either figma.boolean or figma.nestedProps, but not both in combination.

This is an example where we have a notification component that has an optional button component nested inside.

props: {
  icon: figma.boolean('icon?', {
    true: figma.instance('icon'),
    false: undefined
  }),
  title: figma.boolean('title?', {
    true: figma.string('title'),
    false: undefined,
  }),
  description: figma.string('description'),
  // this throws an error when the nested component is toggled off
  action: figma.nestedProps('action', {
    label: figma.string('label'),
    icon: figma.instance('icon')
  }),
  /* would like to use nestedProps inside the boolean
  action: figma.boolean('action?', {
    true:  figma.nestedProps('action', ...)
    false: undefined
  }) */
},
example: (props) => <NotificationBanner    
    icon={props.icon}
    title={props.title}
    description={props.description}
    action={{label: props.action.label, icon: props.action.icon, onClick:()=>{} }}
 />

bastifudali avatar Jul 05 '24 08:07 bastifudali

+1

alisonjoseph avatar Jul 08 '24 17:07 alisonjoseph

This is also a commonly used pattern in my company's design system

+1

adrianaferrugento avatar Jul 19 '24 08:07 adrianaferrugento

+1

lauthieb avatar Aug 02 '24 15:08 lauthieb

Hey all, thanks for the report and sorry that this report seemed to get missed by us. I'm going to discuss this with the team and see if we can find a solution! I will keep you updated.

tomduncalf-figma avatar Aug 05 '24 09:08 tomduncalf-figma

+1

atimofte-mdsol avatar Aug 09 '24 16:08 atimofte-mdsol

@tomduncalf-figma Could we somehow avoid the error that is thrown when the nested component is toggled off ?

atimofte-mdsol avatar Aug 09 '24 16:08 atimofte-mdsol

+1

higuchimmy avatar Aug 27 '24 14:08 higuchimmy

+💯 to this!

In our case, we have a boolean prop, where if true we want to expose some nested text... something like: In our props:

description: figma.boolean('Description', {
  true: figma.nestedProps('<description_node_name>', {...figma.textContent('<text_layer_name>')}),
  false: undefined,
}

and then in the component:

<Component description={props.description} />

ericandrewscott avatar Aug 29 '24 13:08 ericandrewscott

Hey all, thank you for your patience here. Just wanted to follow up and mention that this will be supported in the next release.

You will be able to use nestedProps in conjunction with boolean by providing a fallback value for the false case, like so:

action: figma.boolean('action?', {
  true:  figma.nestedProps('action', {
     label: figma.string('label'),
     icon: figma.instance('icon')
  })
  false: { label: undefined, icon: undefined }
})

karlpetersson avatar Sep 04 '24 16:09 karlpetersson

We just released Code Connect v1.1.1 which should resolve this issue. Please feel free to reopen the issue or create a new one if you continue to have issues.

tomduncalf-figma avatar Sep 10 '24 14:09 tomduncalf-figma