figma / code-connect

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

How to take a figma component and transform each children in an array item #64

Open nrenard opened 2 weeks ago

nrenard commented 2 weeks ago

I need to take each children from a figma component and use this data as an array have some way to do that?

Example code:

import React from "react"
import figma from "@figma/code-connect"
import { Accordion } from "@core"

const props = {
  items: figma.nestedProps('. Item', {
    content: figma.textContent('Center Area'),
  })
}

figma.connect(
  Accordion,
  "",
  {
    props,
    example: ({ items, ...rest }) => {
      return <Accordion 
        {...rest} 
        items={items} // [{ content: 'Text' }, { content: 'Text 2' }]
      />;
    },
  },
)
karlpetersson commented 1 week ago

Hey @nrenard! Currently nestedProps only selects a single child instance (we'll update the README to make this more clear), and so it can't be used to map props from multiple children. However, we're working on adding support for this use case so please stay tuned for that!