React Styleguidist

13.1.4 · active · verified Sun Apr 19

React Styleguidist is a robust tool for generating living style guides and developing React components in isolation. It provides a hot-reloaded development server where developers can view, interact with, and document components. The current stable version is 13.1.4, with recent maintenance releases addressing bug fixes and minor improvements, typically seeing several releases per year including minor versions and patches. Key differentiators include its reliance on Markdown files for component documentation, automatic listing of `propTypes`, and the ability to show live, editable usage examples. It also offers extensive configuration options for Webpack and theming, allowing deep integration into existing project setups. Unlike some alternatives, it focuses on generating a static style guide from existing components and their documentation, rather than being a visual drag-and-drop builder, promoting a documentation-driven development workflow.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart sets up a basic `react-styleguidist` project. It includes `package.json` scripts, a `styleguide.config.js` with Babel for JSX support, a simple `Button` component, and its accompanying Markdown documentation.

{
  "name": "my-component-library",
  "version": "1.0.0",
  "scripts": {
    "styleguide": "styleguidist start",
    "styleguide:build": "styleguidist build"
  },
  "dependencies": {
    "react": ">=18.0",
    "react-dom": ">=18.0"
  },
  "devDependencies": {
    "react-styleguidist": "^13.1.4",
    "babel-loader": "^9.0.0",
    "@babel/core": "^7.0.0",
    "@babel/preset-env": "^7.0.0",
    "@babel/preset-react": "^7.0.0"
  }
}

// styleguide.config.js
module.exports = {
  components: 'src/components/**/*.jsx',
  webpackConfig: {
    module: {
      rules: [
        {
          test: /\.jsx?$/,
          exclude: /node_modules/,
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env', '@babel/preset-react']
          }
        }
      ]
    }
  },
  title: 'My Component Library Style Guide'
};

// src/components/Button/Button.jsx
import React from 'react';
import PropTypes from 'prop-types';

function Button({ children, onClick = () => {} }) {
  return (
    <button
      style={{
        padding: '10px 20px',
        border: 'none',
        borderRadius: '5px',
        backgroundColor: '#2D9EE0',
        color: 'white',
        cursor: 'pointer',
      }}
      onClick={onClick}
    >
      {children}
    </button>
  );
}

Button.propTypes = {
  /**
   * Button content
   */
  children: PropTypes.node.isRequired,
  /**
   * Click handler
   */
  onClick: PropTypes.func,
};

export default Button;

// src/components/Button/Button.md
```## Button

A versatile button component.

### Usage

```jsx
<Button onClick={() => alert('Clicked!')}>Click Me</Button>
```

```jsx
<Button>Another Button</Button>
```
```

view raw JSON →