├── .editorconfig ├── .eslintrc.json ├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── docs └── assets │ ├── code.png │ └── playground.png ├── package.json ├── src ├── Checkbox.js ├── Radio.js ├── index.js └── styles.css ├── webpack.common.js ├── webpack.dev.js └── webpack.prod.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | trim_trailing_whitespace = true 7 | insert_final_newline = true 8 | indent_style = space 9 | indent_size = 2 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | insert_final_newline = false -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "node": true 5 | }, 6 | 7 | "parserOptions": { 8 | "ecmaVersion": 2018, 9 | "sourceType": "module", 10 | "ecmaFeatures": { 11 | "jsx": true 12 | } 13 | }, 14 | "settings": { 15 | "react": { 16 | "version": "16.8.6" 17 | } 18 | }, 19 | "extends": [ 20 | "eslint:recommended", 21 | "plugin:react/recommended", 22 | "plugin:prettier/recommended" 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_STORE 2 | node_modules 3 | package-lock.json 4 | yarn.lock 5 | *.log* 6 | .vscode 7 | /dist -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) VAGAS Tecnologia. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # React Describe 2 | 3 | `React Describe` generates a component playground with editable prop values and a live preview that you can include in your own docs. 4 | 5 | Code example 6 | 7 | Playground example 8 | 9 | | Table of Contents | 10 | | :-------------------------------------- | 11 | | [Runnable examples](#runnable-examples) | 12 | | [Installation](#installation) | 13 | | [Usage](#usage) | 14 | | [Licensing](#licensing) | 15 | 16 | ## Runnable examples 17 | 18 | - [Basic](https://codesandbox.io/s/react-describe-example-cw9b8) 19 | - [Gatsby](https://codesandbox.io/s/react-describe-gatsby-example-6x1qw) 20 | 21 | ## Installation 22 | 23 | with Yarn: 24 | 25 | ```bash 26 | yarn add react-describe 27 | ``` 28 | 29 | with npm: 30 | 31 | ```bash 32 | npm install react-describe 33 | ``` 34 | 35 | ## Usage 36 | 37 | - Define `propTypes` and `defaultProps` for your component props 38 | - Add a comment above each prop to describe it 39 | 40 | ```js 41 | import React from "react"; 42 | import PropTypes from "prop-types"; 43 | 44 | /** 45 | * Button description... 46 | */ 47 | export default function Button({ label, disabled, size, borderRadius }) { 48 | const sizes = { 49 | small: 32, 50 | medium: 48, 51 | large: 64 52 | }; 53 | 54 | return ( 55 | 71 | ); 72 | } 73 | 74 | Button.defaultProps = { 75 | size: "medium", 76 | disabled: false, 77 | borderRadius: 0 78 | }; 79 | 80 | Button.propTypes = { 81 | /** 82 | * label description... 83 | */ 84 | label: PropTypes.string.isRequired, 85 | 86 | /** 87 | * disabled description... 88 | */ 89 | disabled: PropTypes.bool, 90 | 91 | /** 92 | * size description... 93 | */ 94 | size: PropTypes.oneOf(["small", "medium", "large"]), 95 | 96 | /** 97 | * borderRadius description... 98 | */ 99 | borderRadius: PropTypes.number 100 | }; 101 | ``` 102 | 103 | - Import `react-describe` 104 | - Import your component and place it as child of `Describe` 105 | - Import your component as a string and pass it to `src` 106 | 107 | ```js 108 | import React from "react"; 109 | import ReactDOM from "react-dom"; 110 | import { Describe } from "react-describe"; 111 | import Button from "./Button"; 112 | import RawButton from "!raw-loader!./Button.js"; 113 | 114 | function App() { 115 | return ( 116 |
117 | {state =>
119 | ); 120 | } 121 | 122 | const rootElement = document.getElementById("root"); 123 | ReactDOM.render(, rootElement); 124 | ``` 125 | 126 | - You can provide an initial state to override default prop values 127 | 128 | ```js 129 | 138 | {state =>