import { Fragment } from 'react';
import { APIDataType } from '~/components/plugins/api/APIDataType';
import {
PropData,
TypeDeclarationContentData,
TypeDefinitionData,
TypeGeneralData,
TypeSignaturesData,
} from '~/components/plugins/api/APIDataTypes';
import { APISectionDeprecationNote } from '~/components/plugins/api/APISectionDeprecationNote';
import { APISectionPlatformTags } from '~/components/plugins/api/APISectionPlatformTags';
import {
resolveTypeName,
renderFlags,
CommentTextBlock,
parseCommentContent,
renderTypeOrSignatureType,
getCommentOrSignatureComment,
getTagData,
renderParams,
ParamsTableHeadRow,
renderDefaultValue,
renderIndexSignature,
STYLES_APIBOX,
getTagNamesList,
H3Code,
getCommentContent,
} from '~/components/plugins/api/APISectionUtils';
import { Cell, Row, Table } from '~/ui/components/Table';
import { H2, BOLD, P, CODE, MONOSPACE } from '~/ui/components/Text';
export type APISectionTypesProps = {
data: TypeGeneralData[];
};
const defineLiteralType = (types: TypeDefinitionData[]): JSX.Element | null => {
const uniqueTypes = Array.from(
new Set(types.map((t: TypeDefinitionData) => t.value && typeof t.value))
);
if (uniqueTypes.length === 1 && uniqueTypes.filter(Boolean).length === 1) {
return (
<>
{uniqueTypes[0]}
{' - '}
>
);
}
return null;
};
const renderTypeDeclarationTable = (
{ children, indexSignature, comment }: TypeDeclarationContentData,
index?: number
): JSX.Element => (
: undefined}
{type.types
.filter(type => ['reference', 'union', 'intersection'].includes(type.type))
.map(validType => (
{resolveTypeName(validType)}{' '}
{defineLiteralType(literalTypes)}
Acceptable values are:{' '}
{literalTypes.map((lt, index) => (
{resolveTypeName(lt)}
{index + 1 !== literalTypes.length ? ', ' : '.'}
))}
{type.name}
{type.checkType.name}
{typeParameter && <> extends {resolveTypeName(typeParameter[0].type)}>}
{type.checkType.name}
{typeParameter && <> extends {type.extendsType && resolveTypeName(type.extendsType)}>}
{' ? '}
{type.trueType && resolveTypeName(type.trueType)}
{' : '}
{type.falseType && resolveTypeName(type.falseType)}