reactjs / reactjs/react-docgen

Support for compound components

Aperta
#775 2 commenti 4 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
TypeScript
Stelle
3.8k
Fork
316
Merge medio
5h 7m
PR unite (30g)
4

Descrizione

I've been playing around with the latest beta, and while it works well for many cases, I could not get it to work with compound components.

A compound component generally looks like this:

<Compound foo>
  <Compound.Child />
</Compound>

I'm defining it as follows:

import React from 'react';
import type { PolymorphicComponent } from '~/utils';

const ParentComponent = React.forwardRef((props, ref) => {
  return (/* ... */)
}) as PolymorphicComponent<'div', ParentOwnProps>;
type ParentOwnProps = {
  /** foo prop */
  foo?: boolean;
};

const ChildComponent = React.forwardRef((props, ref) => {
  return (/* ... */)
}) as PolymorphicComponent<'div', ChildOwnProps>;
type ChildOwnProps = {
  /** bar prop */
  bar?: string;
};

/** description for main component */
export const Compound = Object.assign(ParentComponent, {
  /** description for subcomponent */
  Child: ChildComponent,
});
export default Compound;

I would guess that react-docgen would need to support a few different things here:

  • using the types that are inferred by props (in this case through PolymorphicComponent utility). related: #590
  • detecting that these multiple components are exported through a single Object.assign declaration and reading jsdoc from there

Guida per i contributori

Apri la guida per i contributori

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.

Direzione di ricerca

Inizia esaminando come vengono gestite le props inferite da TypeScript e le dichiarazioni Object.assign, usando l’esempio PolymorphicComponent e la issue correlata #590 come punti di partenza. Il lavoro sarà considerato completato quando verranno rilevati gli export composti e verranno lette correttamente le descrizioni JSDoc del genitore e del figlio.

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

Valutazione

Stack tecnologico
react, typescript
Ambito
documentation, tooling
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.