A CLI and library to extract information from React component files for documentation generation purposes.
MIT License
Bot releases are hidden (Show)
You can install this version via npm install react-docgen@next
.
developit/proptypes
( #163, @eduardoboucas) and prop-types
( #172, @sawyerh) packages.React.Children.only
as React components ( #169, @damian )coverage/
folder when publishing to npm, reducing package size by more than 50%! ( #166, @fabiosantoscode )While this a new major version, there shouldn't be any breaking changes. We switched to babylon v7(beta) ( #158 ) internally, which supports most flow type annotations. It is published as a prerelease so you can test it on your codebase first.
Other changes:
proptypes
package is recognized as proptypes definition provider ( #163 ).You can install this release via
npm install react-docgen@next
# or
yarn add react-docgen@next
__mocks__
directories by default (#135) (@aitherios)React.cloneElement
as stateless components (#138) (@khankuan)objectOf
prop type (86b167f) (reported as #74)When passing an unknown value to shape(...)
, react-docgen will now report that value as computed.
Example: shape(Child.propTypes)
Before:
"type": {
"name": "shape",
"value": "unkown"
}
Now:
"type": {
"name": "shape",
"value": "Child.propTypes",
"computed": true
}
(eb0edaa) (reported as #87)
Resolve static values passed to oneOf
. Examples:
React.PropTypes.oneOf([TYPES.FOO, TYPES.BAR]);
// or:
var TYPES = ["FOO", "BAR"];
React.PropTypes.oneOf(TYPES);
// or:
var TYPES = ["A", "B"];
var MORE = [...TYPES, "C"];
React.PropTypes.oneOf(MORE);
(#122, @ZauberNerd)
Until now, react-docgen didn’t find components that are passed to a higher order component (HOC):
function MyComponent() { /* ... */ }
export default hoc(MyComponent);
The workaround was to change the resolver to find all component definitions in the file, something that is not always desirable.
With #124, @rtsao extended the default resolver to be able to handle these cases.
findAllExportedComponentDefinitions
can now be selected in the CLI.
(reported as issue #119)
The static variable resolution process was fixed to consider assignments to variables. The following example didn’t work before and works now:
var Component;
Component = React.createClass(...);
module.exports = Component;
(reported as issue #58)
The display name handler now takes displayName
getters in class definitions into account:
class Component extends React.Component {
static get displayName() {
return 'Name';
}
}
(reported as issue #61)
To guard ourselves better against regressions, we are using jest’s snapshot tests to test component definitions that are reported as broken.
findAllExportedComponentDefinitions
resolver. As the name suggests, it finds all exported component definitions. This complements the resolvers for finding all component definitions and the default exported definition ( #114, @ZauberNerd )-e, --exclude PATTERN
, allows you to skip files that match the provided pattern ( #102, @wallaroo )MemberExpression
s (such as propTypes
of a stateless component) to the correct object ( #111, @ZauberNerd )import
ed value, the value of the prop will now be the variable name ( #99 , @nathanmarks )@param {x|y}
and @param {*}
now correctly resolve to their equivalent flow type declarations (union and mixed). ( #95 , @dickeylth )Thanks to everyone who contributed, this is great!
@caabernathy added new information to method parameters ( #83 ). If the parameter has a flow type, the name of the type is no also included. I.e. if the type definition is:
export type StatusBarStyle = $Enum<{
...
}
the docs for a parameter of that type will include alias: "StatusBarStyle"
.
In addition the docs now include an optional
field indicating whether the parameter is optional or nor.
This version adds a great new feature: Support for Flow type definitions. Thanks a lot to @danez for implementing this feature ( #48 ).
react-docgen is now able to extract type definitions as in this example:
import React, { Component } from 'react';
type Props = {
/** Description of prop "foo". */
primitive: number,
/** Description of prop "bar". */
literalsAndUnion: 'string' | 'otherstring' | number,
arr: Array<any>,
func?: (value: string) => void,
obj?: { subvalue: ?boolean },
};
/**
* General component description.
*/
export default class MyComponent extends Component<void, Props, void> {
props: Props;
render(): ?ReactElement {
// ...
}
}
In the JSON output, every prop will have a new field named flowType
. If you use both, flow (for static type checks) and React propTypes (for dynamic type checks) you can do so without any collisions. The JSON blob now simply contains more information and you can decide which one to use for your documentation.
Have a look at the more extensive description in the README to learn how flow types are represented.