Using multiple Slots within a Component

Aberta
#353 0 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
48/100
Tipo de issue
Funcionalidade
Clareza
Razoavelmente clara
Status de atividade
Estagnada
Stack de tecnologia
react, typescript

Direção de pesquisa

Start with the Code Connect documentation and the implementation of figma.children and figma.instance to determine whether multiple named slots can be mapped independently. The issue provides no source files or tests to begin from, so first identify the relevant API entry points and existing slot tests. Done means documenting or supporting a clear way to connect both content and action slots in one component.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

feature request

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?

Linguagem predominante
TypeScript
Estrelas
1.6k
Forks
126
Métricas de merge de PRs
Nenhum PR com merge em 30d

Preparar o ambiente

Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de figma/code-connect

Todas as issues de figma/code-connect

Issues semelhantes

Mais issues de TypeScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.