import React, { useMemo } from 'react' import type { TsInfo as TsInfoData, TsPropertyOrMethodInfo, CallSignatureInfo, } from 'vite-plugin-react-pages/clientTypes' import { Table, Collapse } from 'antd' import type { CollapseProps, TableColumnsType } from 'antd' import { withMdClassName } from '../MDX' import s from './index.module.less' // apply md style const Code = withMdClassName('code') const Strong = withMdClassName('strong') interface Props { data: TsInfoData className?: string } const memberColumns: TableColumnsType = [ { title: 'Name', dataIndex: 'name', }, { title: 'Description', dataIndex: 'description', }, { title: 'Type', dataIndex: 'type', render: (_type) => { const type = _type.trim() if (!type) return null return {type} }, }, { title: 'Default Value', dataIndex: 'defaultValue', render: (_, row) => { if (row.defaultValue) return {row.defaultValue} if (row.optional) return '' return ( Required* ) }, }, ] const signatureColumns: TableColumnsType = [ { title: 'Type', dataIndex: 'type', render: (_type) => { const type = _type.trim() if (!type) return null return {type} }, }, { title: 'Description', dataIndex: 'description', }, ] const complexTypeColumns: TableColumnsType = [ { title: 'Name', dataIndex: 'name', }, { title: 'Description', dataIndex: 'description', }, { title: 'Type', dataIndex: 'text', render: (_type) => { const type = _type.trim() if (!type) return null return {type} }, }, ] export function TsInfo({ data, className: _className }: Props) { const className = [_className, s.ctn].filter(Boolean).join(' ') if (data.type === 'interface' || data.type === 'object-literal') { const items: CollapseProps['items'] = [ { key: 'Members', label: ( Members ), children: ( ), }, ] if (data.callSignatures.length > 0) { items.unshift({ key: 'Call Signatures', label: ( Call Signatures ), children: (
), }) } if (data.constructSignatures.length > 0) { items.unshift({ key: 'Construct Signatures', label: ( Construct Signatures ), children: (
), }) } return ( v.key as string)} /> ) } if (data.type === 'other') { const items: CollapseProps['items'] = [ { key: 'Members', label: ( Members ), children: (
), }, ] return ( v.key as string)} /> ) } return (
{`TsInfo Error:  component receives invalid props.
If you use it in jsx, you should import tsInfo like "import * as tsInfo from './path/to/type.ts?tsInfo=InterfaceName'" and render it like ""
If you use it in markdown, you should use it exactly like "" (we use simple regexp to parse it, so you should use this format strictly)
`}
) }