schlechtenburg/packages/docs/lib/api/TSDocs.tsx

46 lines
1 KiB
TypeScript
Raw Normal View History

2022-03-15 23:03:45 +00:00
import {
defineComponent,
PropType,
} from 'vue';
import {
DeclarationReflection,
TypeParameterReflection,
} from 'typedoc';
2022-03-21 00:53:25 +00:00
import './TSDocs.scss';
2022-03-15 23:03:45 +00:00
const getTypeParamString = (params: TypeParameterReflection[]) => `<${params.map(p => p.name).join(', ')}>`;
export default defineComponent({
2022-03-21 00:53:25 +00:00
name: 'TSDocs',
2022-03-15 23:03:45 +00:00
props: {
docs: {
type: (null as unknown) as PropType<DeclarationReflection>,
required: true,
},
},
setup(props) {
const docs = props.docs;
return () => <section class="docs ts-docs">
2022-03-15 23:38:33 +00:00
<header class="docs--header">
<h2
class="docs--title"
id={docs.name}
>
{docs.name}
{docs.typeParameters ? getTypeParamString(docs.typeParameters) : ''}
</h2>
<p class="docs--type">{docs.kindString}</p>
</header>
<p class="docs--description">{docs.comment?.shortText || ''}</p>
{...(docs.children || []).map(child => <pre><code>
{child.name}: {child.type?.name}
</code></pre>)}
2022-03-15 23:03:45 +00:00
</section>;
},
});