A collection of tools for automating React components documentation.
Under development, may contain experiments
npm i react-autodocs-utils --save-dev
const reactAutodocsUtils = require('react-autodocs-utils');
const path = './path/to/react-component.js';
const componentMetadata = reactAutodocsUtils(path);
componentMetadata
is an object with, unsurprisingly, metadata of component.
given component.js
:
import React from 'react';
import {oneOf, node} from 'prop-types';
export class Component extends React.PureComponent {
static propTypes = {
thing: oneOf(['first', 'second']),
/** i am description about `children` prop */
children: node.isRequired
}
render() {
return <div/>;
}
}
reactAutodocsUtils('./component.js')
Will return a JSON:
{
"props": {
"thing": {
"type": {
"name": "enum",
"value": [
{
"value": "'first'",
"computed": false
},
{
"value": "'second'",
"computed": false
}
]
},
"required": false,
"description": ""
},
"children": {
"type": {
"name": "node"
},
"required": true,
"description": "i am description about `children` prop"
}
},
"description": "",
"displayName": "Component",
"methods": [],
"readme": "source of `./readme.md` if exists, otherwise empty string",
"readmeAccessibility": "source of `./readme.accessibility.md` if exists, otherwise empty string",
"readmeTestkit": "source of `./readme.testkit.md` if exists, otherwise empty string"
}
With this information it is easy to display documentation with regular React components.
It is used heavily in wix-storybook-utils. Live example available at wix-style-react storybook.
git clone [email protected]:wix/react-autodocs-utils.git
npm i
npm test
Jest used to run tests.
jest --watch