
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
react-component-illustrator
Advanced tools
`react-component-illustrator` takes in a list of examples for your library of [React.js](https://facebook.github.io/react/) components, group them by the component they are showcasing (you may have more than one example for a component), and return an arr
react-component-illustrator takes in a list of examples for your library of React.js components, group them by the component they are showcasing (you may have more than one example for a component), and return an array of illustrations of your components, along with their examples.
npm install --save-dev react-component-illustrator
The input of your resulting illustration comes from your React.js components and the examples.
For the most part, you just develop/document them like you normally would (using comment blocks in your .js files), with a few opinionated behaviors I throw in. Here's an example:
Consider you have a project structure like so:
AwesomeComponents
βββ src
β βββ components
β βββ Button
β β βββ Button.js
β β βββ examples
β β βββ SimpleButton.js
β β βββ AnotherButton.js
β β βββ IconButton.js
β βββ ...
βββ ...
And your file contents:
// src/components/Button/Button.js
import React, { PropTypes, Component } from 'react';
/**
* Some description for Button
*
* some more description for Button
*/
export default class Button extends Component {
static propTypes = {
/**
* Property string's description
*/
string: PropTypes.string,
required: PropTypes.any.isRequired,
instanceOf: PropTypes.instanceOf(MyPropType),
customProp: function (props, propName, componentName) {
if (!/My/.test(props[propName])) {
return new Error('Invalid customProp');
}
}
};
render() {
return (
<divButton</div>
);
}
}
propTypes by adding /* */ comment blocks// src/components/Button/examples/SimpleButton.js
import React, { Component } from 'react';
import Button from '../Buton';
/**
* SimpleButton
* description
*
* @name SimpleButtonExample
* @component ../../Button
*/
export default class SimpleButtonExample extends Component {
render() {
let foo = <div>simple</div>;
return (
<div>
{foo}
<Button></Button>
</div>
);
}
}
@name in jsDoc tag style to customize the name of your example in the output, without it, the name of your example's class would be returned.@component tag in your documentation of the example to associate your example with a particular component that you are showcasing. Without this, your example would be categorized under "Random Examples".// src/components/Button/examples/AnotherButton.js
import React, { Component } from 'react';
import Button from '../Buton';
export default class AnotherButtonExample extends Component {
render() {
return (
<Button></Buton>
);
}
}
// src/components/Button/examples/IconButton.js
import React, { Component } from 'react';
import Button from '../Buton';
/**
* IconButtonExample
*
* @component ../../Button
*/
export default class IconButtonExample extends Component {
render() {
let foo = <div>Icon</div>;
return (
<div>
{foo}
<Button></Button>
</div>
);
}
}
Running react-component-illustrator -p src/**/examples/*.js -f commonjs -v logges the following (modified/beautified for ease of reading)
module.exports = [
{
"name": "Button",
"path": "path/to/.../src/components/Button/Button.js",
"source": "... source code of src/components/Button/Button.js (as string)",
"description": "Some description for Button\n\nsome more description for Button",
"props": {
"string": {
"type": {
"name": "string"
},
"required": false,
"description": "Property string's description"
},
"required": {
"type": {
"name": "any"
},
"required": true,
"description": ""
},
"instanceOf": {
"type": {
"name": "instanceOf",
"value": "MyPropType"
},
"required": false,
"description": ""
},
"customProp": {
"type": {
"name": "custom",
"raw": "function (props, propName, componentName) {\n if (!/My/.test(props[propName])) {\n return new Error('Invalid customProp');\n }\n}"
},
"required": false,
"description": ""
}
},
"examples": [
{
"name": "SimpleButton",
"path": "path/to/.../src/components/Button/examples/SimpleButton.js",
"renderer": require("./src/components/Button/examples/SimpleButton.js"),
"requirePath": "./src/components/Button/examples/SimpleButton.js",
"description": "<p>SimpleButtonExample<br>description</p>",
"source": "... source code of src/components/Button/examples/SimpleButton.js (as string)",
"renderSource": "render() {\n let foo = <divsimple</div>;\n return <div>\n {foo}\n <Button></Button>\n </div>;\n}"
},
{
"name": "IconButtonExample",
"path": "path/to/.../src/components/Button/examples/IconButton.js",
"renderer": require("./src/components/Button/examples/IconButton.js"),
"requirePath": "./src/components/Button/examples/IconButton.js",
"description": "<p>IconButtonExample</p>",
"source": "... source code of src/components/Button/examples/IconButton.js (as string)",
"renderSource": "render() {\n let foo = <div>Icon</div>;\n return <div>\n {foo}\n <Button></Button>\n </div>;\n}"
}
]
},
{
"name": "Random Examples",
"examples": [
{
"name": "AnotherButtonExample",
"path": "path/to/.../src/components/Button/examples/AnotherButton.js",
"renderer": require("./src/components/Button/examples/AnotherButton.js"),
"requirePath": "./src/components/Button/examples/AnotherButton.js",
"description": "",
"source": "... source code of src/components/Button/examples/AnotherButton.js (as string)",
"renderSource": "render() {\n return <Button></Button>;\n}"
}
]
}
]
> react-component-illustrator --pattern path/to/components/**/examples/*.js --outputFormat commonjs --dest ./dist
Path(s) to the examples, could be either glob or absolute path
Also prints the result in console.
The path to the file where output should be saved.
The type of output, one of:
commonjs
module.exports = [ { name: 'MyComponent', description: '', props: [...], examples: [ { name: 'MyComponentExample', renderer: require('path/to/MyComponentExample.js'), ... } ] }, ... ];
- es6
export default [ { name: 'MyComponent', description: '', props: [...], examples: [ { name: 'MyComponentExample', renderer: require('path/to/MyComponentExample.js'), ... } ] }, ... ];
- string
[ { name: 'MyComponent', description: '', props: [...], examples: [ { name: 'MyComponentExample', ... } ] }, ... ];
### API
import {illustrate} from 'react-component-illustrator';
illustrate('path/to/components/**/examples/*.js') .then(function (illustrations) { console.log(illustrations); }) .catch(console.error.bind(console)) ;
## License
MIT
FAQs
`react-component-illustrator` takes in a list of examples for your library of [React.js](https://facebook.github.io/react/) components, group them by the component they are showcasing (you may have more than one example for a component), and return an arr
The npm package react-component-illustrator receives a total of 1 weekly downloads. As such, react-component-illustrator popularity was classified as not popular.
We found that react-component-illustrator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.Β It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.