Support for parsing instance().getProps() in nested props

Offen
#307 0 Kommentare 6 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
49/100
Issue-Typ
Feature
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
typescript

Rechercherichtung

Start by tracing how figma.nestedProps, figma.enum, and figma.instance().getProps() are parsed and emitted, using the example in the issue as the expected case. Check the relevant parser and output tests, then add coverage for the nested icon property mapping; done means the generated example preserves the requested instance property only when its enum condition is true.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

feature request

Our UX team is using nested components for reusability in Figma which has created a challenge for us when hooking it up to code connect. It seems like code connect isn't parsing instance().getProps in this example:

import figma from "@figma/code-connect";
import { Button } from "./DesignSystem/Button";

figma.connect(
  Button,
  "https://www.figma.com/design/example",
  {
    props: {
      type: figma.string("type"),
      disabled: figma.enum("state", {
        default: false,
        hover: false,
        disabled: true,
      }),
      buttonBaseProps: figma.nestedProps(".button-base", {
        size: figma.string("size"),
        label: figma.string("label"),
        leftIcon: figma.enum("has-left-icon", {
          true: figma.instance("left-icon").getProps().type,
          false: undefined,
        }),
        rightIcon: figma.enum("has-right-icon", {
          true: figma.instance("right-icon").getProps().type,
          false: undefined,
        }),
      }),
    },
    example: ({ type, disabled, buttonBaseProps }: { type: any; disabled: boolean; buttonBaseProps: any }) => (
      <Button
        type={type}
        size={buttonBaseProps.size}
        leftIcon={buttonBaseProps.leftIcon}
        rightIcon={buttonBaseProps.rightIcon}
        label={buttonBaseProps.label}
        disabled={disabled}
        onPress={() => {}}
      />
    ),
  }
);

Output in Figma:

import { Button } from "./DesignSystem/Button"

<Button
    type="primary"
    size="small"
    rightIcon={figma.instance("right-icon").getProps().type}
    label="Button"
    onPress={() => {}}
/>

Since we also need to handle the nested has-right-icon properties, it makes sense to use the enum to try to map the icon only when it's present. But then we need to access the type prop for the instance, as we are not passing the icon component to the button, just the type.

Vorherrschende Sprache
TypeScript
Sterne
1.6k
Forks
126
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus figma/code-connect

Alle Issues in figma/code-connect

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.