import {APIClass, APIConstructor, APIMethod, APIProperty, SanityArrayItem} from '@sanity/tsdoc' import {Box} from '@sanity/ui' import {useMemo} from 'react' import {CommentRemarks} from '../../comment' import {H} from '../../lib/ui' import {Members} from '../members' import {_getMembers} from '../members/helpers' function useMembers(data: APIClass) { return useMemo(() => { const members = _getMembers(data) as APIClass['members'] const ret: { constructors: SanityArrayItem[] methods: SanityArrayItem[] properties: SanityArrayItem[] staticMethods: SanityArrayItem[] } = { constructors: [], methods: [], properties: [], staticMethods: [], } for (const m of members) { if (m._type === 'api.constructor') { ret.constructors.push(m) } else if (m._type === 'api.method') { if (m.isStatic) { ret.staticMethods.push(m) } else { ret.methods.push(m) } } else if (m._type === 'api.property') { ret.properties.push(m) } else { // eslint-disable-next-line console.log('unknown member type:', (m as any)._type) } } return ret }, [data]) } export function ClassContent(props: {data: APIClass}): React.ReactNode { const {data} = props const {comment} = data const {constructors, methods, properties, staticMethods} = useMembers(data) return ( <> {comment?.remarks?.content && ( )} {/* */} {constructors.length > 0 && ( <> Constructor )} {properties.length > 0 && ( <> Properties )} {staticMethods.length > 0 && ( <> Static methods )} {methods.length > 0 && ( <> Methods )} ) }