npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-autodoc

v0.9.3

Published

A React component and webpack loader to autogenerate documentation for your React components

Downloads

50

Readme

react-autodoc

Build Status

React autodoc is the foundation for generating the documentation for your React Components. React provides a built-in mechanism for runtime property validation. If you opt-in to using these, you can use this tool to automate your documentation similar to what JSDoc provides for raw functions.

react-autodoc contains two pieces. The primary piece is the Autodoc React component.

The second piece is opt-in. It is a webpack esprima-loader transformer that will modify your source code to include the annotations that Autodoc requires.

Example


// button.js
var Button = React.createClass({
  propTypes: {
    state: React.PropTypes.oneOf(['active', 'disabled', 'focused']),
    modifier: React.PropTypes.oneOf(['primary', 'secondary']).isRequired,
    children: React.PropTypes.any.isRequired,
  },

  render() {
    // using Suit.css semantics
    var uiState = this.props.state ? `is-${this.props.state}` : '';
    var modifier = this.props.modifier ? `Button--${this.props.modifier}` : '';
    return (
      <button className={`Button ${uiState} ${modifier}`}>
        {this.props.children}
      </button>
    );
  }
});

// button.autodoc.js

var React = require('react');
var Autodoc = require('react-autodoc');
var Button = require('./button');

var AutodocButton = React.createClass({
  render() {
    return (
      <Autodoc component={Button} />
    );
  }
});

This will produce a table that looks like a richer version of the following:

Autodoc for Button

| Property Key | Type | Required | Default Value | |--------------|-------------------------------|----------|---------------| | state | enum<active/disabled/focused> | false | 'active' | | modifier | enum<primary/secondary> | true | | | children | any | true | |


Why the webpack loader?

Webpack is a module loader that understands your entire dependency graph. It also has great support for loaders and transformations for pretty much anything.

Using webpack provides the convenience of builds for different environments so you don’t have to add the any overhead to your project in production, but can easily include in development or qa environments.

The inline version of the propType annotations looks something like this:

  propTypes: {
    state: (
      (var tmp = React.PropTypes.oneOf(['active', 'disabled', 'focused'])),
      tmp.annotations = {type: 'enum<active|disabled|focused>'}, tmp
    ),
    modifier: (
      (var tmp = React.PropTypes.oneOf(['primary', 'secondary']).isRequired),
      tmp.annotations = {type: 'enum<primary|secondary>', isRequired: true}, tmp
    ),
    children: (
      (var tmp = React.PropTypes.any.isRequired),
      (tmp.annotations = {type: 'any', isRequired: true}), tmp
    )
  }

Alternatives to inline annotations that can still be explored are:

  1. Output the annotated date to a dynamic file for react-autodoc which can resolve the annotations by looking up a given ReactComponent.displayName.
  2. Monkey patching React.PropTypes with runtime hints to what properties are available. Some immediate trade-offs is we can’t provide rich views into CallExpression propTypes such as oneOf or shape.

React Autodoc Expected Annotations

The tests/annotationsFor.js file contains the expected annotations for Autodoc. Implementing this interface will give you the freedom to build on top of either side of the Autodoc. You are free to reimplement <Autodoc /> or add your own build-step transformations to handle the annotating.

MIT License

Copyright 2015 Skookum Digital Works, Inc. All Right Reserved

Facebook’s tool: https://cloudup.com/c65kXrDBiq4 https://cloudup.com/cO7m38Gjgpk