import React from 'react'; import { InlineCode } from '~/components/base/code'; import { LI, UL } from '~/components/base/list'; import { P } from '~/components/base/paragraph'; import { H2, H4 } from '~/components/plugins/Headings'; import { CommentTagData, DefaultPropsDefinitionData, PropData, PropsDefinitionData, TypeDeclarationData, TypePropertyData, } from '~/components/plugins/api/APIDataTypes'; import { CommentTextBlock, resolveTypeName } from '~/components/plugins/api/APISectionUtils'; export type APISectionPropsProps = { data: PropsDefinitionData[]; defaultProps: DefaultPropsDefinitionData; }; const UNKNOWN_VALUE = '...'; const extractDefaultPropValue = ( { comment, name }: PropData, defaultProps: DefaultPropsDefinitionData ): string | undefined => { const annotationDefault = comment?.tags?.filter((tag: CommentTagData) => tag.tag === 'default'); if (annotationDefault?.length) { return annotationDefault[0].text; } return defaultProps?.type?.declaration?.children?.filter( (defaultProp: TypePropertyData) => defaultProp.name === name )[0]?.defaultValue; }; const renderInheritedProp = (ip: TypeDeclarationData) => { const component = ip?.typeArguments ? ip.typeArguments[0]?.queryType?.name : null; return component ? (
  • {component}
  • ) : null; }; const renderInheritedProps = (data: TypeDeclarationData[]): JSX.Element | undefined => { const inheritedProps = data.filter((ip: TypeDeclarationData) => ip.type === 'reference'); if (inheritedProps.length) { return (

    Inherited Props

    ); } return undefined; }; const renderProps = ( { name, type }: PropsDefinitionData, defaultValues: DefaultPropsDefinitionData ): JSX.Element => { const propsDeclarations = type.types.filter((e: TypeDeclarationData) => e.declaration); return (
    {renderInheritedProps(type.types)}
    ); }; const renderProp = ({ comment, name, type }: PropData, defaultValue?: string) => (
  • {name}

    Type: {resolveTypeName(type)} {defaultValue && defaultValue !== UNKNOWN_VALUE ? (   {'Default: '} {defaultValue} ) : null}

  • ); const APISectionProps: React.FC = ({ data, defaultProps }) => data?.length ? ( <>

    Props

    {data.map((propsDefinition: PropsDefinitionData) => renderProps(propsDefinition, defaultProps) )} ) : null; export default APISectionProps;