import React from 'react';
import ReactMarkdown from 'react-markdown';
import { InlineCode } from '~/components/base/code';
import { B } from '~/components/base/paragraph';
import { H2, H3Code } from '~/components/plugins/Headings';
import {
CommentData,
InterfaceDefinitionData,
InterfaceValueData,
MethodSignatureData,
TypeDefinitionData,
} from '~/components/plugins/api/APIDataTypes';
import {
CommentTextBlock,
listParams,
mdInlineRenderers,
renderParam,
resolveTypeName,
STYLES_OPTIONAL,
} from '~/components/plugins/api/APISectionUtils';
export type APISectionInterfacesProps = {
data: InterfaceDefinitionData[];
};
const renderInterfaceType = (type?: TypeDefinitionData, signatures?: MethodSignatureData[]) => {
if (type) {
return {resolveTypeName(type)};
} else if (signatures && signatures.length) {
const { type, parameters } = signatures[0];
return (
({listParams(parameters)}) => {resolveTypeName(type)}
);
}
return undefined;
};
const renderInterfaceComment = (comment?: CommentData, signatures?: MethodSignatureData[]) => {
if (signatures && signatures.length) {
const { type, parameters } = signatures[0];
return (
<>
{parameters.map(param => renderParam(param))}
Returns:
{resolveTypeName(type)}
>
);
} else {
return comment?.shortText ? (
{comment.shortText}
) : (
'-'
);
}
};
const renderInterfacePropertyRow = ({
name,
flags,
type,
comment,
signatures,
}: InterfaceValueData): JSX.Element => (
{name}
{signatures && signatures.length ? '()' : ''}
{flags?.isOptional ? (
<>
(optional)
>
) : null}
|
{renderInterfaceType(type, signatures)} |
{renderInterfaceComment(comment, signatures)} |
);
const renderInterface = ({
name,
children,
comment,
}: InterfaceDefinitionData): JSX.Element | null =>
children ? (
{name}
| Name |
Type |
Description |
{children.map(renderInterfacePropertyRow)}
) : null;
const APISectionInterfaces: React.FC = ({ data }) =>
data?.length ? (
<>
Interfaces
{data.map(renderInterface)}
>
) : null;
export default APISectionInterfaces;