-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds code example sinppets and rendered components
- Loading branch information
1 parent
1c2f54c
commit 74dd6ff
Showing
15 changed files
with
174 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,21 @@ | ||
import _ from 'lodash'; | ||
import React, {Component, PropTypes} from 'react'; | ||
import getExamples from '../Example/GetExamples'; | ||
import Example from '../Example/Example'; | ||
|
||
/** | ||
* Lists a Component's @example tags in colored code blocks. | ||
*/ | ||
class ComponentExamples extends Component { | ||
export default class extends Component { | ||
static propTypes = { | ||
/** | ||
* Array of strings of example content. | ||
*/ | ||
examples: PropTypes.array | ||
componentName: PropTypes.array | ||
}; | ||
|
||
render() { | ||
let examples = _.map(this.props.examples, (example, i) => { | ||
let lines = _.map(example.split('\n'), (line, j) => <div key={j}>{line}</div>); | ||
return <pre key={i} className='ui green segment'>{lines}</pre>; | ||
}); | ||
let examples = getExamples(this.props.componentName); | ||
let contents = _.map(examples, (example, i) => <Example key={i} {...example} />); | ||
|
||
return ( | ||
<div> | ||
{examples} | ||
{contents} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default ComponentExamples; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React, {Component, createElement, PropTypes} from 'react'; | ||
import {Segment, Button} from 'index.js'; | ||
import Highlight from 'react-highlight/index'; | ||
|
||
/** | ||
* Renders a `component` and the raw `code` that produced it. | ||
*/ | ||
export default class extends Component { | ||
static propTypes = { | ||
/** | ||
* The raw string of code that created the component. | ||
*/ | ||
code: PropTypes.string, | ||
/** | ||
* A React Component demonstrating how to use a component. | ||
*/ | ||
component: PropTypes.node, | ||
}; | ||
|
||
state = {showCode: false}; | ||
|
||
toggleShowCode = () => { | ||
this.setState({showCode: !this.state.showCode}); | ||
}; | ||
|
||
render() { | ||
let code = ( | ||
<Highlight className='language-javascript'> | ||
{this.props.code} | ||
</Highlight> | ||
); | ||
|
||
return ( | ||
<Segment className='vertical segment'> | ||
<Segment className='basic vertical'> | ||
{createElement(this.props.component)} | ||
</Segment> | ||
<Segment className='basic vertical'> | ||
<Button className='basic mini labeled icon' onClick={this.toggleShowCode}> | ||
Code | ||
<i className='code icon' /> | ||
</Button> | ||
</Segment> | ||
{this.state.showCode && code} | ||
</Segment> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const req = require.context('docs/app/examples/', true, /\.js$/); | ||
|
||
/** | ||
* Parse example files for a give `component`. | ||
* @param {string} component The name of the component to fetch example files for. | ||
* @returns {[]} An array of object with the file `code` as text and exported `component` as a React Component. | ||
*/ | ||
export default component => { | ||
let modulePaths = _.map(_.filter(req.keys(), path => _.contains(path, `/${component}/`))); | ||
|
||
return _.map(modulePaths, (path) => { | ||
// remove first dot slash from paths which look like "./Checkbox/BasicExample.js" | ||
let subpath = path.replace('./', ''); | ||
return { | ||
code: require(`!raw!docs/app/examples/${subpath}`), | ||
component: req(path), | ||
}; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React, {Component} from 'react'; | ||
import {Checkbox} from 'stardust'; | ||
|
||
export default class extends Component { | ||
render() { | ||
return ( | ||
<Checkbox /> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import React, {Component} from 'react'; | ||
import {Checkbox} from 'stardust'; | ||
|
||
export default class extends Component { | ||
render() { | ||
return <Checkbox type='slider' />; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import React, {Component} from 'react'; | ||
import {Checkbox} from 'stardust'; | ||
|
||
export default class extends Component { | ||
render() { | ||
return <Checkbox type='toggle' />; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.