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 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-stencil

v0.9.0

Published

[![CircleCI](https://circleci.com/gh/adjohnston/react-stencil.svg?style=shield)](https://circleci.com/gh/adjohnston/react-stencil)

Readme

CircleCI

Stencil

Introduction

React Stencil is a tool to help you create functioning component documentation for use internally for design and development or externally as a part of a wider design system for all to use.

It provides a higher order function that will wrap a React component and render component documentation with various information.

Installation

npm install react-stencil --save

Example

So our project has a button component:

import React from 'react'
import PropTypes from 'prop-types'

export default function Button (props) {
  return (
    <button
      id={props.id}
      onClick={props.onClick}>
      {props.children}
    </button>  
  )  
}

Button.propTypes = {
  onClick: PropTypes.func.isRequired,
  children: PropTypes.string.isRequired,
  id: PropTypes.string
}

We can create a new component that documents the button by wrapping <Button /> using the stencil higher order function.

import stencil from 'react-stencil'
import Button from 'button'

export default stencil({})(Button)

With this new component you can render it as you wish. With React Stencil I have set out to make it un-opinionated in how you choose to display it.

You show additional details about the component by passing some information and we can do this by passing a 'spec'.

There is a separate tool which will do some automation for you. Take a look at the documentation for React Stencil CLI.

For now, let's do a little manual speccing and continue to document our <Button /> component.

import React from 'react'
import stencil from 'react-stencil'
import Button from 'button'

const spec = {
  name: 'Button',
  description: 'A button that takes an action',
  swatches: ['red', 'black', '#d73a49'],
  status: 'READY',

  props: {
    id: {
      type: 'string',
      required: false,
      description: 'A unique ID'
    },

    warning: {
      type: 'bool',
      required: false,
      description: 'Should this button be shown as a warning button'
    }

    children: {
      type: 'string',
      required: true,
      description: 'Copy to be shown in the button'
    },

    onClick: {
      type: 'func',
      required: true,
      description: 'An action to fire when the button is clicked'
    }
  },

  examples: {
    'Warning': {
      id: 'warning-button'
      warning: true,
      children: 'I am a dangerous action!'
    }
  },

  notes: {
    'do\'s & dont\'s': (
      <ul
        className="guide">
        <li
          className="guide__good">
          Do use a Button to fire an action
        </li>
        <li
          className="guide__bad">
          Don't use a Button to link to another page
        </li>
      </ul>  
    )
  }
}

export default stencil(spec)(Button)

Here's a breakdown of what the spec means and what can be generated by React Stencil CLI.

Name

Can be generated by React Stencil CLI

The name of the component that is being documented.

Description

Can be generated by React Stencil CLI

A space dedicated to describing what the component is or does, perhaps even why it was created to begin with.

Swatches

Swatches are colours that you can switch out the background of the preview panel. By default the documented component will have a semi transparent background.

Status

Give a status to the component on whether it is production ready, currently being worked on or is not ready to be used by others.

The constants are 'READY', 'WIP' and 'DANGEROUS'.

Props

Can be generated by React Stencil CLI

A list of the all the props the component accepts keyed by the name of the prop.

  • Type is the type given to the prop and should be based on React's PropTypes.
  • Required is whether the prop is required or not.
  • defaultValue is the initial value that the component has set on it.
  • description can be used to document what the prop does or how it can be used.

Examples

You can provide props to build examples. Choosing an example will update the preview with those props allowing users to see how a component can/should be used.

Notes

Notes can be used to further document the component. It's an object and each key will give you a new header while the value is the documentation itself. You can pass strings or components affording you the option to document in any way you feel appropriate.

Global Spec, Component Spec & Merge

Specifying descriptions per prop per component would become tedious. For example, onClick; It's likely to be widely used in components but how to describe what it is and how to use it is unlikely to change between components.

For instances like this we can define a global spec. The global spec can then be merged with an individual component spec, hopefully saving you valuable time documenting.

To do this we'll use Stencil's merge helper. As a note, any definitions that are included in the component spec will overwrite the global spec meaning that if you wish to have a component specific description or set of swatches you can.

Here's an example:

// specs/global-spec.js
export default {
  props: {
    onClick: {
      description: 'An action to fire when the button is clicked'
    }
  },
  swatches: ['red', 'black', '#d73a49']
}

// specs/components/button.js
import stencil, { merge } from 'react-stencil'
import globalSpec from '../../global-spec'
import Button from 'button'

const buttonSpec = {
  // a whole bunch of button specs
}

const spec = merge(globalSpec, buttonSpec)

export default stencil(spec)(Button)