Skip to content

Commit

Permalink
docs(ComponentProps): show func signatures (#1194)
Browse files Browse the repository at this point in the history
  • Loading branch information
levithomason authored Jan 20, 2017
1 parent ebd700f commit f4d3023
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
31 changes: 30 additions & 1 deletion docs/app/Components/ComponentDoc/ComponentProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,31 @@ export default class ComponentProps extends Component {
)
}

renderFunctionSignature = (item) => {
if (item.type !== '{func}') return

const params = _.filter(item.tags, { title: 'param' })
const paramSignature = params
.map(param => `${param.name}: ${param.type.name}`)
.join(', ')

const paramDescriptions = params.map(param => (
<div style={{ color: '#888' }}>
<strong>{param.name}</strong> - {param.description}
</div>
))

const signature = <pre><code>{item.name}({paramSignature})</code></pre>

return (
<div>
<strong>Signature:</strong>
{signature}
{paramDescriptions}
</div>
)
}

render() {
const { props: propsDefinition } = this.props
const content = _.sortBy(_.map(propsDefinition, (config, name) => {
Expand All @@ -56,6 +81,7 @@ export default class ComponentProps extends Component {
name,
type,
value,
tags: _.get(config, 'docBlock.tags'),
required: config.required,
defaultValue: config.defaultValue,
description: description && description.split('\n').map(l => ([l, <br key={l} />])),
Expand All @@ -80,7 +106,10 @@ export default class ComponentProps extends Component {
<Table.Cell>{this.requiredRenderer(item)}</Table.Cell>
<Table.Cell>{item.type}</Table.Cell>
<Table.Cell>{this.renderDefaultValue(item.defaultValue)}</Table.Cell>
<Table.Cell>{item.description && <p>{item.description}</p>}</Table.Cell>
<Table.Cell>
{item.description && <p>{item.description}</p>}
{this.renderFunctionSignature(item)}
</Table.Cell>
</Table.Row>
))}
</Table.Body>
Expand Down
4 changes: 2 additions & 2 deletions docs/app/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@
code:not(.hljs) {
padding: 0;
padding-top: 0.2em;
padding-top: 0.1em;
padding-bottom: 0.2em;
margin: 0;
font-size: 85%;
font-size: 87.5%;
background-color: rgba(0, 0, 0, 0.04);
border-radius: 3px;
}
Expand Down

0 comments on commit f4d3023

Please sign in to comment.