Skip to content

Using multiple Slots within a Component #353

@Meloyski

Description

@Meloyski

I'll start by saying that I'm not developer and my knowledge of React and Code Connect has been self taught. I apologize if this can already be done and I'm just missing something...

We have a component where we have multiple Props that we are using Slots for:

<ComponentName
   content={}
   actions={}
/>

Here's an example of our figma.tsx

import { ComponentName } from '@something';
import  figma from `@figma/code-connect`;

const FigmaLink = "..."

const ComponentNameProps = {
   content: figma.boolean("Content", {
      false: undefined,
      true: figma.children('ContentSlot')
   }),
   action: figma.boolean("Action", {
      false: undefined,
      true: figma.children('ActionSlot')
   })
};

figma.connect(ComponentName, FigmaLink , {
   props: {
      ...ComponentNameProps,
   },
   example: ({ content, action }) => {
      return <ComponentName content={content} action={action} />;
   }
});

Note: we separate our Links and Props whenever we use different variant use case examples.

In previous cases where we used Slots, it was set as children with a catchall (figma.children('*')) and this works great. I'm struggling to find a way of implementing the Code Connect for these components without having to create subComponents using the catch all method:

I haven't tested this but this is what I would do in that case:

_ComponentNameContent and _ComponentNameAction:

import { Fragment } from '@something';
import  figma from `@figma/code-connect`;

figma.connect(
   Fragment,
   '...', 
   {
       props: {
           children: figma.children('*'),
       }.
       example: ({ children }) => (
           <Fragment>{children}</Fragment>
       )
   }
)

Then the Code Connect would be:

import { ComponentName } from '@something';
import  figma from `@figma/code-connect`;

const FigmaLink = "..."

const ComponentNameProps = {
   content: figma.boolean("Content", {
      false: undefined,
      true: figma.instance('_ComponentNameContent')
   }),
   action: figma.boolean("Action", {
      false: undefined,
      true: figma.children('_ComponentNameAction')
   })
};

figma.connect(ComponentName, FigmaLink , {
   props: {
      ...ComponentNameProps,
   },
   example: ({ content, action }) => {
      return <ComponentName content={content} action={action} />;
   }
});

Sorry if there's some errors, I had to type this all up from my personal computer since I don't have access to GH on my work computer. Does anyone have any thoughts/solutions?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions