import { renderMethod } from './APISectionMethods'; import { APIDataType } from '~/components/plugins/api/APIDataType'; import { CommentData, InterfaceDefinitionData, MethodSignatureData, PropData, } from '~/components/plugins/api/APIDataTypes'; import { APISectionDeprecationNote } from '~/components/plugins/api/APISectionDeprecationNote'; import { APISectionPlatformTags } from '~/components/plugins/api/APISectionPlatformTags'; import { CommentTextBlock, getTagData, parseCommentContent, renderFlags, renderParamRow, ParamsTableHeadRow, resolveTypeName, renderDefaultValue, STYLES_APIBOX, getTagNamesList, STYLES_APIBOX_NESTED, ELEMENT_SPACING, H3Code, getCommentContent, BoxSectionHeader, } from '~/components/plugins/api/APISectionUtils'; import { Cell, Row, Table } from '~/ui/components/Table'; import { H2, BOLD, P, CODE, DEMI, MONOSPACE } from '~/ui/components/Text'; export type APISectionInterfacesProps = { data: InterfaceDefinitionData[]; }; const renderInterfaceComment = ( comment?: CommentData, signatures?: MethodSignatureData[], defaultValue?: string ) => { if (signatures && signatures.length) { const { type, parameters, comment: signatureComment } = signatures[0]; const defaultTag = getTagData('default', signatureComment); const initValue = defaultValue || (defaultTag ? getCommentContent(defaultTag.content) : undefined); return ( <> {parameters?.length ? parameters.map(param => renderParamRow(param)) : null} Returns {resolveTypeName(type)} {signatureComment && ( <>
)} ); } else { const defaultTag = getTagData('default', comment); const initValue = defaultValue || (defaultTag ? getCommentContent(defaultTag.content) : undefined); return ( <> ); } }; const renderInterfacePropertyRow = ({ name, flags, type, comment, signatures, defaultValue, }: PropData): JSX.Element => { const defaultTag = getTagData('default', comment); const initValue = parseCommentContent( defaultValue || (defaultTag ? getCommentContent(defaultTag.content) : '') ); return ( {name} {renderFlags(flags, initValue)} {renderInterfaceComment(comment, signatures, initValue)} ); }; const renderInterface = ({ name, children, comment, extendedTypes, }: InterfaceDefinitionData): JSX.Element | null => { const interfaceChildren = children?.filter(child => !child?.inheritedFrom) || []; if (!interfaceChildren.length) return null; const interfaceMethods = interfaceChildren.filter(child => child.signatures); const interfaceFields = interfaceChildren.filter(child => !child.signatures); return (
{name} {extendedTypes?.length ? (

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

) : null} {interfaceMethods.length ? ( <> {interfaceMethods.map(method => renderMethod(method, { exposeInSidebar: false }))} ) : undefined} {interfaceFields.length ? ( <> {interfaceFields.map(renderInterfacePropertyRow)}

) : undefined}
); }; const APISectionInterfaces = ({ data }: APISectionInterfacesProps) => data?.length ? ( <>

Interfaces

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