Skip to content
This repository was archived by the owner on Aug 10, 2018. It is now read-only.

Many new features (v1.1?) #3

Merged
merged 37 commits into from
Aug 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
e68a9d2
Initial integration of react-docgen
Jul 16, 2015
47371fd
Move docgen out of file gen to be cached into the index.html:
Jul 16, 2015
ef5e35c
Add tabbed examples support
Jul 16, 2015
f1da897
Support code examples for each example and place within tab
Jul 17, 2015
679d8c4
Update css
Jul 17, 2015
3274a32
Add auto-code example support if code prop is not defined
Jul 17, 2015
a037fed
Impl watchify
Jul 17, 2015
193a332
Small bug fixes:
Jul 17, 2015
48e3a99
Add react-docgen-mixin and usage docs
Jul 17, 2015
ccd35b1
Add watchify to package.json
Jul 17, 2015
9624c2d
Update documentation and examples
Jul 19, 2015
d21495c
- Add support for automatic code-generation for es6
Jul 20, 2015
5e4b5ba
Fix default value react-docgen display not working
Jul 20, 2015
c5a1dd1
Remove unnecessary children prop from basic example panel
Jul 20, 2015
10fcb69
Remove unused references
Jul 20, 2015
9c55a0f
Fix radium wrapping displayName issues
Jul 20, 2015
44fc21a
Refactor - remove ref to reactDocGenId because we get it through exam…
Jul 20, 2015
5d48b15
Refactor - remove error from react-docgen-to-md since it is applied t…
Jul 20, 2015
0595ca7
Fix unit test
Jul 20, 2015
2510610
Allow usage of a config object along with a file
Jul 21, 2015
1713c7f
Fix unit test
Jul 21, 2015
5fe6bbe
Add logging for the styleguide.json config path
Jul 22, 2015
f133c69
Do not generate an auto-example for the first example as it is coming…
Jul 23, 2015
f0bf6e9
- Add es6 react-docgen support, and enable react-docgen by default
Jul 25, 2015
79c22d6
Update readme
Jul 25, 2015
cea960b
Add small logging that watch mode is enabled
Jul 27, 2015
2965afb
- Remove tabs when there is only a single example
Jul 29, 2015
b797b4a
Additional simplification in readme
Jul 29, 2015
bb13c09
When react-docgen fails parse, include the filename
Jul 30, 2015
7ff8576
Add troubleshooting section
Jul 30, 2015
14a907a
Fix bug where only one additional example isn't rendered
Jul 31, 2015
9382680
Add additional logging, update babel, babelify, browserify, babel-esl…
Jul 31, 2015
c4a90c8
Add improved json formatting for auto-code generation
Aug 1, 2015
9225ba4
Allow defining a jsdoc description above the class def instead of usi…
Aug 3, 2015
69748c8
Add component check to getDisplayName in the utils.js
Aug 3, 2015
40ef02c
Significant performance enhancements and slowdown fixes under watch mode
Aug 4, 2015
7d85609
Fix code highlighting not refreshing on view changes
Aug 4, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 131 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,48 @@ Which requires **React 0.13.0** or newer. To install it `npm install react`.

## Quick Start

**NOTE:** By default Babel's `static` keyword is disabled. You can turn them on individually by passing `stage 0` as a [babelrc](https://babeljs.io/docs/usage/babelrc/) or [options.babelConfig](#babelconfig).

### Documenting your React components

Create file for the styleguide, and then add some documentation to a static field named `styleguide`. You can use the [ES6 syntax](https://github.com/lukehoban/es6features) by [Babel](https://babeljs.io/).

**NOTE:** By default Babel's `static` keyword is disabled. You can turn them on individually by passing `stage 0` as a [babelrc](https://babeljs.io/docs/usage/babelrc/) or [options.babelConfig](#babelconfig).

``` js
import React from 'react'
import Button from './Button'

export default class extends React.Component {

// required for prop documentation
static displayName = 'ExampleButton'

static styleguide = {
index: '1.1',
category: 'Elements',
title: 'Button',
description: 'You can use **Markdown** within this `description` field.',
code: `<Button size='small|large' onClick={Function}>Cool Button</Button>`,
className: 'apply the css class'
className: 'apply the css class',
// Used in the first 'Example' tab
code: `<Button size='small|large' onClick={Function}>Cool Button</Button>`
}

// Document the props via react-docgen
static propTypes = {
/**
* Header title
*/
header: React.propTypes.object,
/**
* Panel style class
*/
bsStyle: React.propTypes.string
}

onClick () {
alert('Alo!')
}

//Used for the first 'Example' tab
render () {
return (
<Button size='large' onClick={this.onClick}>Cool Button</Button>
Expand All @@ -54,9 +72,54 @@ export default class extends React.Component {
- `category`: Components category name
- `title`: Components title
- `description`: Components description (optional)
- `code`: Code examples (optional)
- `code`: Code example (optional). Not specifying this will not auto-generate an example.
- `className`: CSS class name (optional)

#### Additional examples in tabs (optional)

You can optionally use tabs to segment out examples for a component:

```
import React from 'react'
import Button from './Button'

export default class extends React.Component {

// required for prop documentation
static displayName = 'ExampleButton'

static styleguide = {
...

// Component to use for generating additional examples
exampleComponent: Button,
// Array of additional example tabs
examples: [
{
tabTitle: 'Tab title',
props: {
size: 'small',
onClick () {
alert('o hay!')
}
}
//code: This is optional; by omitting it, the RSG will attempt to auto-generate an example using the props!
}
]
}

...
}
```

- `exampleComponent`: `ReactElement` to use to generate the examples.
- `examples`: Array of examples, which generates additional tabs of example components and sample code
- `examples[].tabTitle`: Title of example tab
- `examples[].props`: Properties to assign to the rendered example component
- `examples[].props.children`: (optional) Child elements to assign to the example component
- `examples[].code`: (optional) Code example. Omitting this will attempt to auto-generate a code example using the `examples[].props`


If necessary, visit [react-styleguide-generator/example](https://github.com/pocotan001/react-styleguide-generator/tree/master/example) to see more complete examples for the documenting syntax.

### Generating the documentation
Expand All @@ -83,9 +146,13 @@ Options:
-c, --config Use the config file ['styleguide.json']
-p, --pushstate Enable HTML5 pushState [false]
-v, --verbose Verbose output [false]
-w, --watch Watch mode using `browserifyConfig`

Examples:
rsg 'example/**/*.js' -t 'Great Style Guide' -f 'a.css, a.js'
rsg 'example/**/*.js' -t 'Great Style Guide' -f 'a.css, a.js' -v

# Necessary to use a config file if you want to enable react-docgen
rsg 'example/**/*.js' -c 'styleguide.json' -v
```

#### Gulp
Expand All @@ -110,6 +177,41 @@ gulp.task('styleguide', function (done) {
})
```

#### Grunt

``` js
var RSG = require('react-styleguide-generator')

...

grunt.registerTask('rsg', 'React style guide', function () {
var done = this.async()

try {

var conf = grunt.config.get('rsg')

RSG(conf.input, {
config: conf.configFile,
watch: false,
verbose: true
}).generate(function (err) {
if (err) {
grunt.log.error('Error: ' + err + ' ' + err.stack())
return done(false)
}

grunt.log.ok('react styleguide generation complete')
done()
})

} catch (e) {
grunt.log.error('Error: ' + e + ' ' + e.stack)
done(false)
}
})
```

## API

### RSG(input, [options])
Expand Down Expand Up @@ -138,6 +240,13 @@ Default: `'Style Guide'`

Used as a page title and in the page header.

##### reactDocgen.files

Type: `Array`
Default: `input`

An array of `glob`-able file/paths for `react-docgen` to parse. If not specified, will default the value to `input`.

##### root

Type: `String`
Expand Down Expand Up @@ -191,11 +300,13 @@ Inject file references into index.html if the files with the extension `.css` or

##### config

Type: `String`
Type: `String|Object`
Default: `styleguide.json`

The entire range of RSG API options is allowed. [Usage example](https://github.com/pocotan001/react-styleguide-generator/blob/master/example/styleguide.json).

An object can be passed instead of a filename that contains the RSG API options.

##### pushstate

Type: `String`
Expand Down Expand Up @@ -231,6 +342,13 @@ A usage example is below. See the [browserify docs](https://github.com/substack/
}
```

### watch

Type: `String`
Default: `false`

Enables `watchify` for when the `input` files change, speeding up rebuild time.

### rsg.generate([callback])

Generate the files and their dependencies into a styleguide output.
Expand All @@ -247,3 +365,9 @@ npm start
```

Visit [http://localhost:3000/](http://localhost:3000/) in your browser.

## Troubleshooting

### Error: No suitable component definition found.

Make sure your component contains `displayName` and `render()`.
49 changes: 49 additions & 0 deletions app/common/react-simpletabs.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* =============================================================================
An example of how stylize the tabs
============================================================================= */

.tabs-navigation {
padding: 0 50px;
}

.tabs-navigation {
padding: 0 10px;
max-height: 62px;
border-bottom: 1px solid #DDD;
}

.tabs-menu {
display: table;
list-style: none;
padding: 0;
margin: 0;
}

.tabs-menu-item {
float: left;
}

.tab-panel {
margin: 20px;
}

.tabs-menu-item a {
display: block;
padding: 0 30px;
height: 30px;
line-height: 30px;
border-bottom: 0;
color: #A9A9A9;
}

.tabs-menu-item:not(.is-active) a:hover {
color: #3498db;
}

.tabs-menu-item.is-active a {
background: #fff;
border: 1px solid #DDD;
border-top: 2px solid #3498db;
border-bottom: 0;
color: #333;
}
15 changes: 14 additions & 1 deletion app/components/Section/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,29 @@
border-bottom: 1px solid var(--gray-lighter);
}

.sg-tabbed.sg-section-example {
padding: 20px 0 0 0;
border: 1px solid var(--gray-lighter);
margin-top: 10px;
}

/**
* Code
*/

.sg-section-code {
border-bottom: 1px solid var(--gray-lighter);
border: 1px solid var(--gray-lighter);
margin-top: 10px;
}

.sg-tabbed .sg-section-code {
margin-top: 0;
}


.sg-section-code code {
padding: 20px;
background: var(--white);
font-family: monospace;
display: block;
}
Loading