Using multiple Slots within a Component

Aperta
#353 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
48/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
react, typescript

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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?

Lingua principale
TypeScript
Stelle
1.6k
Fork
126
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di figma/code-connect

Tutte le issue di figma/code-connect

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.