import * as React from 'react';
const FunctionArguments = ({ args }) => {
return (
{args.map((argument, i) => {
return (
{argument.name}
{argument.type && (
: {argument.type}
)}
{i < args.length - 1 && ', '}
);
})}
);
};
const paramDocumentation = ({ title, name, description }, index) => {
return (
{title} {name}
{description && ` - ${description}`}
);
};
const returnsDocumentation = ({ title, type, description }, index) => {
// No type
if (!type) {
return;
}
// Basic type
if (!type.applications) {
return (
{title} {type.name}
{description && ` - ${description}`}
);
}
// Promise type
const returnType = type.applications
.map(app => {
if (app.name) {
return app.name;
}
if (app.type === 'UnionType') {
return app.elements
.map(element => {
if (element.value) {
return `'${element.value}'`;
}
if (element.type === 'NullLiteral') {
return 'null';
}
if (element.type === 'UndefinedLiteral') {
return 'undefined';
}
return element.name;
})
.join(' | ');
}
})
.join(', ');
return (
{title} {`Promise<${returnType}>`}
{description && ` - ${description}`}
);
};
export const MethodDocumentation = ({ unit }) => {
const { args, name, tags } = unit;
return (
|
{name}(
)
|
{unit.description}
{tags && tags.length > 0 && (
{tags.map((tag, index) => {
if (tag.title === 'param') {
return paramDocumentation(tag, index);
}
if (tag.title === 'returns' || tag.title === 'return') {
return returnsDocumentation(tag, index);
}
return (
-
{tag.title} {tag.description}
);
})}
)}
|
);
};