/** * Copyright (c) 2015-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule AutodocsLayout */ var DocsSidebar = require('DocsSidebar'); var H = require('Header'); var Header = require('Header'); var Marked = require('Marked'); var Prism = require('Prism'); var React = require('React'); var Site = require('Site'); var slugify = require('slugify'); var styleReferencePattern = /^[^.]+\.propTypes\.style$/; function renderType(type) { if (type.name === 'enum') { if (typeof type.value === 'string') { return type.value; } return 'enum(' + type.value.map((v) => v.value).join(', ') + ')'; } if (type.name === 'shape') { return '{' + Object.keys(type.value).map((key => key + ': ' + renderType(type.value[key]))).join(', ') + '}'; } if (type.name == 'union') { return type.value.map(renderType).join(', '); } if (type.name === 'arrayOf') { return '[' + renderType(type.value) + ']'; } if (type.name === 'instanceOf') { return type.value; } if (type.name === 'custom') { if (styleReferencePattern.test(type.raw)) { var name = type.raw.substring(0, type.raw.indexOf('.')); return {name}#style } if (type.raw === 'EdgeInsetsPropType') { return '{top: number, left: number, bottom: number, right: number}'; } return type.raw; } if (type.name === 'stylesheet') { return 'style'; } if (type.name === 'func') { return 'function'; } return type.name; } var ComponentDoc = React.createClass({ renderProp: function(name, prop) { return (
{prop.platforms && prop.platforms.map(platform => {platform} )} {name} {' '} {prop.type && {renderType(prop.type)} }
{prop.type && prop.type.name === 'stylesheet' && this.renderStylesheetProps(prop.type.value)} {prop.description && {prop.description}}
); }, renderCompose: function(name) { return (
{name} props...
); }, renderStylesheetProps: function(stylesheetName) { var style = this.props.content.styles[stylesheetName]; return (
{(style.composes || []).map((name) => { var link; if (name === 'LayoutPropTypes') { name = 'Flexbox'; link = {name}...; } else if (name === 'TransformPropTypes') { name = 'Transforms'; link = {name}...; } else { name = name.replace('StylePropTypes', ''); link = {name}#style...; } return (
{link}
); })} {Object.keys(style.props).map((name) =>
{name} {' '} {style.props[name].type && {renderType(style.props[name].type)} }
)}
); }, renderProps: function(props, composes) { return (
{(composes || []).map((name) => this.renderCompose(name) )} {Object.keys(props) .sort((nameA, nameB) => { var a = props[nameA]; var b = props[nameB]; if (a.platforms && !b.platforms) { return 1; } if (b.platforms && !a.platforms) { return -1; } if (nameA < nameB) { return -1; } if (nameA > nameB) { return 1; } return 0; }) .map((name) => this.renderProp(name, props[name]) )}
); }, extractPlatformFromProps: function(props) { for (var key in props) { var prop = props[key]; var description = prop.description || ''; var platforms = description.match(/\@platform (.+)/); platforms = platforms && platforms[1].replace(/ /g, '').split(','); description = description.replace(/\@platform (.+)/, ''); prop.description = description; prop.platforms = platforms; } }, render: function() { var content = this.props.content; this.extractPlatformFromProps(content.props); return (
{content.description} {this.renderProps(content.props, content.composes)}
); } }); var APIDoc = React.createClass({ removeCommentsFromDocblock: function(docblock) { return docblock .trim('\n ') .replace(/^\/\*+/, '') .replace(/\*\/$/, '') .split('\n') .map(function(line) { return line.trim().replace(/^\* ?/, ''); }) .join('\n'); }, renderTypehintRec: function(typehint) { if (typehint.type === 'simple') { return typehint.value; } if (typehint.type === 'generic') { return this.renderTypehintRec(typehint.value[0]) + '<' + this.renderTypehintRec(typehint.value[1]) + '>'; } return JSON.stringify(typehint); }, renderTypehint: function(typehint) { try { var typehint = JSON.parse(typehint); } catch(e) { return typehint; } return this.renderTypehintRec(typehint); }, renderMethod: function(method) { return (
{method.modifiers.length && {method.modifiers.join(' ') + ' '} || ''} {method.name} ({method.params .map((param) => { var res = param.name; if (param.typehint) { res += ': ' + this.renderTypehint(param.typehint); } return res; }) .join(', ')})
{method.docblock && {this.removeCommentsFromDocblock(method.docblock)} }
); }, renderMethods: function(methods) { if (!methods.length) { return null; } return ( Methods
{methods.filter((method) => { return method.name[0] !== '_'; }).map(this.renderMethod)}
); }, renderProperty: function(property) { return (
{property.name} {property.type && {': ' + renderType(property.type)} }
{property.docblock && {this.removeCommentsFromDocblock(property.docblock)} }
); }, renderProperties: function(properties) { if (!properties || !properties.length) { return null; } return ( Properties
{properties.filter((property) => { return property.name[0] !== '_'; }).map(this.renderProperty)}
); }, renderClasses: function(classes) { if (!classes || !classes.length) { return null; } return (
{classes.filter((cls) => { return cls.name[0] !== '_' && cls.ownerProperty[0] !== '_'; }).map((cls) => { return (
class {cls.name}
    {cls.docblock && {this.removeCommentsFromDocblock(cls.docblock)} } {this.renderMethods(cls.methods)} {this.renderProperties(cls.properties)}
); })}
); }, render: function() { var content = this.props.content; if (!content.methods) { throw new Error( 'No component methods found for ' + content.componentName ); } return (
{this.removeCommentsFromDocblock(content.docblock)} {this.renderMethods(content.methods)} {this.renderProperties(content.properties)} {this.renderClasses(content.classes)}
); } }); var HeaderWithGithub = React.createClass({ renderRunnableLink: function() { if (this.props.metadata && this.props.metadata.runnable) { return ( Run this example ); } }, render: function() { return ( Edit on GitHub {this.renderRunnableLink()} {this.props.title} ); } }); var Autodocs = React.createClass({ renderFullDescription: function(docs) { if (!docs.fullDescription) { return; } return (
{docs.fullDescription}
); }, renderExample: function(docs, metadata) { if (!docs.example) { return; } return (
{docs.example.content.replace(/^[\s\S]*?\*\//, '').trim()}
); }, render: function() { var metadata = this.props.metadata; var docs = JSON.parse(this.props.children); var content = docs.type === 'component' || docs.type === 'style' ? : ; return (
); } }); var EmbeddedSimulator = React.createClass({ render: function() { if (!this.props.shouldRender) { return null; } var metadata = this.props.metadata; return (

Run this example

Run example in simulator
); } }); var Modal = React.createClass({ render: function() { var appParams = {route: 'AlertIOS'}; var encodedParams = encodeURIComponent(JSON.stringify(appParams)); var url = `https://appetize.io/embed/bypdk4jnjra5uwyj2kzd2aenv4?device=iphone5s&scale=70&autoplay=false&orientation=portrait&deviceColor=white¶ms=${encodedParams}`; return (

Powered by appetize.io

); } }); module.exports = Autodocs;