import React from 'react'; import { InlineCode } from '~/components/base/code'; import { B, P } from '~/components/base/paragraph'; import { H2, H3Code } from '~/components/plugins/Headings'; import { CommentData, InterfaceDefinitionData, MethodSignatureData, PropData, } from '~/components/plugins/api/APIDataTypes'; import { CommentTextBlock, mdInlineComponents, renderFlags, renderParam, renderTypeOrSignatureType, resolveTypeName, } from '~/components/plugins/api/APISectionUtils'; export type APISectionInterfacesProps = { data: InterfaceDefinitionData[]; }; const renderInterfaceComment = (comment?: CommentData, signatures?: MethodSignatureData[]) => { if (signatures && signatures.length) { const { type, parameters, comment: signatureComment } = signatures[0]; return ( <> {parameters?.length ? parameters.map(param => renderParam(param)) : null} Returns: {resolveTypeName(type)} {signatureComment && ( <>
)} ); } else { return comment ? : '-'; } }; const renderInterfacePropertyRow = ({ name, flags, type, comment, signatures, }: PropData): JSX.Element => ( {name} {signatures && signatures.length ? '()' : ''} {renderFlags(flags)} {renderTypeOrSignatureType(type, signatures)} {renderInterfaceComment(comment, signatures)} ); const renderInterface = ({ name, children, comment, extendedTypes, }: InterfaceDefinitionData): JSX.Element | null => children ? (
{name} {extendedTypes?.length && (

Extends: {extendedTypes.map(extendedType => ( {resolveTypeName(extendedType)} ))}

)} {children.filter(child => !child?.inheritedFrom).map(renderInterfacePropertyRow)}
Name Type Description
) : null; const APISectionInterfaces = ({ data }: APISectionInterfacesProps) => data?.length ? ( <>

Interfaces

{data.map(renderInterface)} ) : null; export default APISectionInterfaces;