reactjs / reactjs/react-docgen
Support for documenting component props in the component docBlock
Nessuno ha ancora preso questa issue.
- Lingua principale
- TypeScript
- Stelle
- 3.8k
- Fork
- 316
- Merge medio
- 5h 7m
- PR unite (30g)
- 4
Descrizione
As of now, the docblock describing a property must be directly above where the property field is defined. As such
class MyComponent {
static propTypes = {
/**
* Does things that only a foo can
*/
foo: PropTypes.string,
/**
* Does things that only a bar can
*/
bar: PropTypes.string,
}
}
Which is a fine solution, but can get very bloated when you start having more props.
class MyComponent {
static propTypes = {
/**
* Does things that only a foo can
*/
foo: PropTypes.string,
/**
* Does things that only a bar can
*/
bar: PropTypes.string,
/**
* Does things that only a foobar can
*/
foobar: PropTypes.shape({
/**
* Does things that only a foo can
*/
foo: PropTypes.string,
/**
* Does things that only a bar can
*/
bar: PropTypes.string,
}),
/**
* Does things that only a foobar can
*/
foobar: PropTypes.shape({
/**
* Does things that only a foo can
*/
foo: PropTypes.string,
/**
* Does things that only a bar can
*/
bar: PropTypes.string,
}),
}
}
You can online the comments, but with some descriptions being long enough to require being on two line, it ends up looking messy in my opinion.
class MyComponent {
static propTypes = {
/** Does things that only a foo can*/
foo: PropTypes.string,
/** Does things that only a bar can */
bar: PropTypes.string,
/** Does things that only a foobar can */
foobar: PropTypes.shape({
/**
* Some properties will have a longer description that require them to be
* on multiple lines
*/
foo: PropTypes.string,
/** Does things that only a bar can */
bar: PropTypes.string,
}),
/** Does things that only a foobar can */
foobar: PropTypes.shape({
/** Does things only a foo can */
foo: PropTypes.string,
/** Does things that only a bar can */
bar: PropTypes.string,
}),
}
}
What I'm proposing is a JSDoc like tag that allows you to descibe the props for a component in the docblock for the component itself, somthing like:
/**
* @prop foo - Does things that only a foo can
* @prop bar - Does things that only a bar can
* @prop foobar - Does things that only a foobar can
* @prop foobar.foo - Some properties will have a longer description that require them to be on multiple lines
* @prop foobar.bar - Does things that only a bar can
* @prop foobar - Does things that only a foobar can
* @prop foobar.foo - Does things that only a foo can
* @prop foobar.bar - Does things that only a bar can
*/
class MyComponent {
static propTypes = {
foo: PropTypes.string,
bar: PropTypes.string,
foobar: PropTypes.shape({
foo: PropTypes.string,
bar: PropTypes.string,
}),
foobar: PropTypes.shape({
foo: PropTypes.string,
bar: PropTypes.string,
}),
}
}
Seing as prop is an existing JSDoc tag, it might be an idea to prefix it with something. Perhaps react., so
/**
* @react.prop name - description
*/
Is this something that would be worth looking into?
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia esaminando come vengono attualmente interpretati i commenti del componente docBlock, i tag JSDoc e i commenti delle proprietà propTypes. Confronta le forme proposte @prop e @react.prop, inclusi i nomi annidati come foobar.foo, e definisci la sintassi supportata e la documentazione generata prima di implementare e testare la funzionalità.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, react
- Ambito
- documentation
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 30/100