# react-describe

> An accessible React playground on top of react-docgen.

Latest version **0.1.3** (published 2019-08-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-describe
pnpm add react-describe
yarn add react-describe
bun add react-describe
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2019-08-03 |
| First published | 2019-08-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 5.5 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Author | Charbel Rami |
| Maintainers | vagas |

## Links

- npm: https://www.npmjs.com/package/react-describe
- Repository: https://github.com/VAGAScom/react-describe
- npm.io page: https://npm.io/package/react-describe

## Dependencies (3)

- [shortid](https://npm.io/package/shortid.md) ^2.2.14
- [prop-types](https://npm.io/package/prop-types.md) ^15.7.2
- [react-docgen](https://npm.io/package/react-docgen.md) ^4.1.1

## Recent versions

- 0.1.3 (latest) — 2019-08-03
- 0.1.2 — 2019-08-01

## README

# React Describe

`React Describe` generates a component playground with editable prop values and a live preview that you can include in your own docs.

<img src="docs/assets/code.png" alt="Code example" width="500">

<img src="docs/assets/playground.png" alt="Playground example" width="500">

| Table of Contents                     |
| :------------------------------------ |
| [Runnable example](#runnable-example) |
| [Installation](#installation)         |
| [Usage](#usage)                       |
| [Licensing](#licensing)               |

## Runnable example

- [On CodeSandbox](https://codesandbox.io/s/react-describe-example-cw9b8)

## Installation

with Yarn:

```bash
yarn add react-describe
```

with npm:

```bash
npm install react-describe
```

## Usage

- Define `propTypes` and `defaultProps` for your component props
- Add a comment above each prop to describe it

```js
import React from "react";
import PropTypes from "prop-types";

/**
 * Button description...
 */
export default function Button({ label, disabled, size, borderRadius }) {
  const sizes = {
    small: 32,
    medium: 48,
    large: 64
  };

  return (
    <button
      style={{
        paddingLeft: sizes[size],
        paddingRight: sizes[size],
        fontSize: sizes[size] / 2,
        height: sizes[size],
        backgroundColor: "rebeccapurple",
        color: "#fff",
        border: "none",
        borderRadius,
        opacity: disabled ? 0.5 : 1
      }}
      disabled={disabled}
    >
      {label}
    </button>
  );
}

Button.defaultProps = {
  size: "medium",
  disabled: false,
  borderRadius: 0
};

Button.propTypes = {
  /**
   * label description...
   */
  label: PropTypes.string.isRequired,

  /**
   * disabled description...
   */
  disabled: PropTypes.bool,

  /**
   * size description...
   */
  size: PropTypes.oneOf(["small", "medium", "large"]),

  /**
   * borderRadius description...
   */
  borderRadius: PropTypes.number
};
```

- Import `react-describe`
- Import your component and place it as child of `Describe`
- Import your component as a string and pass it to `src`

```js
import React from "react";
import ReactDOM from "react-dom";
import { Describe } from "react-describe";
import Button from "./Button";
import RawButton from "!raw-loader!./Button.js";

function App() {
  return (
    <div className="App">
      <Describe src={RawButton}>{state => <Button {...state} />}</Describe>
    </div>
  );
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
```

- You can provide an initial state to override default prop values

```js
<Describe
  src={RawButton}
  initialState={{
    label: "Button",
    disabled: true,
    size: "small",
    borderRadius: 3
  }}
>
  {state => <Button {...state} />}
</Describe>
```

### Available playground inputs

| PropType | input              |
| :------- | ------------------ |
| string   | text input         |
| number   | number input       |
| bool     | checkbox           |
| oneOf    | radio-button group |

## Licensing

React Describe is licensed under the [MIT License](LICENSE)

---
_Source: https://npm.io/package/react-describe · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
