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

enum + nestedProps to return children or textContent

Open ericandrewscott opened this issue 1 year ago • 0 comments

Our Toolbar component has a region for title and subtitle/rating and an enum to help set that up. Screenshot 2024-09-16 at 8 00 41 AM

This maps to two separate coded props like so:

figma.connect(Toolbar, 'https://www.figma.com/design/<OBFUSC>', {
  props: {
    ...
    ...titleProps,
  },
  example: ({ ..., title, subtitle }) => (
    <Toolbar
      ...
      toolbarTitle={TITLE_HERE}
      toolbarSubtitle={SUBTITLE HERE}
    />
  ),
});

For our first iteration of Code Connect, we statically connected those props. Our props const for the title area looks like:

const titleProps = {
  title: figma.nestedProps("✏️ Title area", {
    text: figma.textContent("✏️ Title"),
  }),
  subtitle: figma.enum('Title type', {
    'Title + Subtitle': "{'INSERT_SUBTITLE'}",
    'Title + Rating': <EGDSRating rating={'INSERT_RATING'} />, // figma.children("⚙️ Rating"),
  }),
};

This renders correctly, but we'd like to hook up the dynamic Subtitle and the Rating, which is already connected as you can see below. rating

I tried the following for the subtitle props:

const titlePropsRedux = {
  title: figma.nestedProps("✏️ Title area", {
    text: figma.textContent("✏️ Title"),
  }),
  subtitle: figma.enum('Title type', {
    'Title + Subtitle': figma.nestedProps('✏️ Title area', {
      content: figma.textContent('✏️ Subtitle'),
    }),
    'Title + Rating': figma.nestedProps('✏️ Title area', {
      content: figma.children("⚙️ Rating"),
    }),
  }),
};

and then of course making the example be {subtitle.content}, but that gives me the error: Screenshot 2024-09-16 at 8 10 55 AM

I also tried hooking them all up to the same figma.enum, since they all come from the same design prop, like so:

const titleProps = {
  titleContent: figma.enum('Title type', {
    'Title': figma.nestedProps("✏️ Title area", {
      title: figma.textContent("✏️ Title"),
      subtitle: undefined, // or false
    }),
    'Title + Subtitle': figma.nestedProps("✏️ Title area", {
      title: figma.textContent("✏️ Title"),
      subtitle: figma.textContent("✏️ Subtitle"),
    }),
    'Title + Rating': figma.nestedProps("✏️ Title area", {
      title: figma.textContent("✏️ Title"),
      subtitle: figma.children("⚙️ Rating"),
    }),
  }),
};

And then using {titleContent.title} and {titleContent.subtitle}, but that gives me the same intrinsic error as above.

Am I thinking about this wrong? Is there a way to do this?

  • Code Connect CLI version 1.1.3
  • Operating system OSX

ericandrewscott avatar Sep 16 '24 13:09 ericandrewscott