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

46 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-03-15 23:03:45 +00:00
import { defineComponent } from 'vue';
2022-03-21 00:53:25 +00:00
2022-03-15 23:03:45 +00:00
import { ComponentDoc } from 'vue-docgen-api';
import { DeclarationReflection } from 'typedoc';
import { getByName } from '../docs';
2022-03-21 00:53:25 +00:00
import { getShortPackageName } from './package';
import ComponentDocs from './ComponentDocs';
import TSDocs from './TSDocs';
2022-03-15 23:03:45 +00:00
import './Package.scss';
export default defineComponent({
name: 'Package',
2022-03-21 00:53:25 +00:00
props: {
name: {
type: String,
required: true,
},
},
setup(props) {
const packageName = props.name;
const docs = getByName(getShortPackageName(Array.isArray(packageName) ? packageName[0] : packageName));
2022-03-15 23:03:45 +00:00
if (!docs) {
2022-03-15 23:38:33 +00:00
return () => <div>Unknown package name {packageName}</div>;
2022-03-15 23:03:45 +00:00
}
const { lib, components } = docs;
return () => <main class="package">
<h1>{lib.name}</h1>
<p>{lib.comment}</p>
<p>{lib.flags}</p>
{...(lib.children || []).map((child:DeclarationReflection) => {
const componentDocs = components.find((c: ComponentDoc) => c.exportName === child.name);
if (componentDocs) {
return <ComponentDocs docs={componentDocs}></ComponentDocs>
}
2022-03-21 00:53:25 +00:00
return <TSDocs docs={child}></TSDocs>
2022-03-15 23:03:45 +00:00
})}
</main>;
},
});