2015-03-05 02:10:12 +00:00
|
|
|
/**
|
|
|
|
* @providesModule AutodocsLayout
|
|
|
|
* @jsx React.DOM
|
|
|
|
*/
|
|
|
|
|
|
|
|
var DocsSidebar = require('DocsSidebar');
|
|
|
|
var Header = require('Header');
|
|
|
|
var Marked = require('Marked');
|
|
|
|
var React = require('React');
|
|
|
|
var Site = require('Site');
|
2015-03-09 18:49:58 +00:00
|
|
|
var slugify = require('slugify');
|
2015-03-05 02:10:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
var Autodocs = React.createClass({
|
2015-03-09 20:25:01 +00:00
|
|
|
renderType: function(type) {
|
|
|
|
if (type.name === 'enum') {
|
|
|
|
return 'enum(' + type.value.map((v => v.value)).join(', ') + ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type.name === 'shape') {
|
|
|
|
return '{' + Object.keys(type.value).map((key => key + ': ' + this.renderType(type.value[key]))).join(', ') + '}';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type.name === 'arrayOf') {
|
|
|
|
return '[' + this.renderType(type.value) + ']';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type.name === 'instanceOf') {
|
|
|
|
return type.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type.name === 'custom') {
|
|
|
|
return type.raw;
|
|
|
|
}
|
|
|
|
|
|
|
|
return type.name;
|
|
|
|
},
|
2015-03-05 02:10:12 +00:00
|
|
|
renderProp: function(name, prop) {
|
|
|
|
return (
|
2015-03-09 18:49:58 +00:00
|
|
|
<div className="prop" key={name}>
|
2015-03-05 02:10:12 +00:00
|
|
|
<Header level={4} className="propTitle" toSlug={name}>
|
|
|
|
{name}
|
|
|
|
{' '}
|
2015-03-09 20:25:01 +00:00
|
|
|
{prop.type && <span className="propType">
|
|
|
|
{this.renderType(prop.type)}
|
|
|
|
</span>}
|
2015-03-05 05:03:24 +00:00
|
|
|
</Header>
|
|
|
|
{prop.description && <Marked>{prop.description}</Marked>}
|
2015-03-05 02:10:12 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
},
|
2015-03-09 18:49:58 +00:00
|
|
|
renderCompose: function(name) {
|
|
|
|
return (
|
|
|
|
<div className="prop" key={name}>
|
|
|
|
<Header level={4} className="propTitle" toSlug={name}>
|
|
|
|
<a href={slugify(name) + '.html#proptypes'}>{name} props...</a>
|
|
|
|
</Header>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
renderProps: function(props, composes) {
|
|
|
|
return (
|
|
|
|
<div className="props">
|
|
|
|
{(composes || []).map((name) =>
|
|
|
|
this.renderCompose(name)
|
|
|
|
)}
|
|
|
|
{Object.keys(props).sort().map((name) =>
|
|
|
|
this.renderProp(name, props[name])
|
|
|
|
)}
|
|
|
|
</div>
|
2015-03-05 02:10:12 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
render: function() {
|
|
|
|
var metadata = this.props.metadata;
|
|
|
|
var content = JSON.parse(this.props.children);
|
|
|
|
return (
|
|
|
|
<Site section="docs">
|
|
|
|
<section className="content wrap documentationContent">
|
|
|
|
<DocsSidebar metadata={metadata} />
|
|
|
|
<div className="inner-content">
|
|
|
|
<a id="content" />
|
|
|
|
<h1>{metadata.title}</h1>
|
|
|
|
<Marked>
|
|
|
|
{content.description}
|
|
|
|
</Marked>
|
2015-03-09 18:49:58 +00:00
|
|
|
{this.renderProps(content.props, content.composes)}
|
2015-03-05 05:03:24 +00:00
|
|
|
<Marked>
|
|
|
|
{content.fullDescription}
|
|
|
|
</Marked>
|
2015-03-05 02:10:12 +00:00
|
|
|
<div className="docs-prevnext">
|
|
|
|
{metadata.previous && <a className="docs-prev" href={metadata.previous + '.html#content'}>← Prev</a>}
|
|
|
|
{metadata.next && <a className="docs-next" href={metadata.next + '.html#content'}>Next →</a>}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</Site>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = Autodocs;
|