import { CommentData, GeneratedData, MethodSignatureData, PropsDefinitionData, } from '~/components/plugins/api/APIDataTypes'; import { APISectionDeprecationNote } from '~/components/plugins/api/APISectionDeprecationNote'; import APISectionProps from '~/components/plugins/api/APISectionProps'; import { CommentTextBlock, resolveTypeName, getComponentName, STYLES_APIBOX, getTagNamesList, H3Code, ELEMENT_SPACING, } from '~/components/plugins/api/APISectionUtils'; import { H2, BOLD, P, CODE, MONOSPACE } from '~/ui/components/Text'; export type APISectionComponentsProps = { data: GeneratedData[]; componentsProps: PropsDefinitionData[]; }; const getComponentComment = (comment: CommentData, signatures: MethodSignatureData[]) => comment || (signatures?.[0]?.comment ?? undefined); const getComponentType = ({ signatures }: Partial) => { if (signatures?.length && signatures[0].type.types) { return 'React.' + signatures[0].type.types.filter(t => t.type === 'reference')[0]?.name; } return 'React.Element'; }; const getComponentTypeParameters = ({ extendedTypes, type, signatures, }: Partial) => { if (extendedTypes?.length) { return extendedTypes[0]; } else if (signatures?.length && signatures[0].parameters.length) { return signatures?.[0].parameters[0].type; } return type; }; const renderComponent = ( { name, comment, type, extendedTypes, children, signatures }: GeneratedData, componentsProps?: PropsDefinitionData[] ): JSX.Element => { const resolvedType = getComponentType({ signatures }); const resolvedTypeParameters = getComponentTypeParameters({ type, extendedTypes, signatures }); const resolvedName = getComponentName(name, children); const extractedComment = getComponentComment(comment, signatures); return (
{resolvedName} {resolvedType && resolvedTypeParameters && (

Type:{' '} {extendedTypes ? ( <>React.{resolveTypeName(resolvedTypeParameters)} ) : ( <> {resolvedType}<{resolveTypeName(resolvedTypeParameters)}> )}

)} {componentsProps && componentsProps.length ? ( ) : null}
); }; const APISectionComponents = ({ data, componentsProps }: APISectionComponentsProps) => data?.length ? ( <>

{data.length === 1 ? 'Component' : 'Components'}

{data.map(component => renderComponent( component, componentsProps.filter(cp => cp.name.includes(getComponentName(component.name, component.children)) ) ) )} ) : null; export default APISectionComponents;