feat(site): extract api reference from components (#464)

This commit is contained in:
Darius Cepulis
2026-02-05 19:57:54 -06:00
committed by GitHub
parent 48364f17fd
commit 0991a899b2
80 changed files with 3425 additions and 1562 deletions
@@ -0,0 +1,63 @@
---
import { getEntry } from 'astro:content';
import { kebabCase } from 'es-toolkit/string';
import ContentWidth from '@/components/frames/ContentWidth.astro';
import MarkdownCode from '@/components/typography/MarkdownCode.astro';
import P from '@/components/typography/P.astro';
import type { ComponentApiReference } from '@/types/api-reference';
import { isValidFramework } from '@/types/docs';
import FrameworkCase from '../FrameworkCase.astro';
import ApiDataAttrsTable from './ApiDataAttrsTable.astro';
import ApiPropsTable from './ApiPropsTable.astro';
import ApiStateTable from './ApiStateTable.astro';
interface Props {
component: string;
section: 'props' | 'state' | 'dataAttributes';
}
const { component, section } = Astro.props;
const { framework } = Astro.params;
if (!framework || !isValidFramework(framework)) {
throw new Error(`Invalid or missing framework param "${framework ?? 'undefined'}".`);
}
const entry = await getEntry('apiReference', kebabCase(component));
const apiRef: ComponentApiReference | null = entry?.data ?? null;
const hasData = apiRef && Object.keys(apiRef[section]).length > 0;
---
<ContentWidth>
{
hasData && section === "props" && (
<ApiPropsTable props={apiRef.props} componentName={component} />
)
}
{
hasData && section === "state" && (
<>
<P>
<FrameworkCase frameworks={["react"]}>
State is accessible via the{" "}
<MarkdownCode>render</MarkdownCode>,{" "}
<MarkdownCode>className</MarkdownCode>, and{" "}
<MarkdownCode>style</MarkdownCode> props.
</FrameworkCase>
<FrameworkCase frameworks={["html"]}>
State is reflected as data attributes for CSS styling.
</FrameworkCase>
</P>
<ApiStateTable state={apiRef.state} />
</>
)
}
{
hasData && section === "dataAttributes" && (
<ApiDataAttrsTable dataAttributes={apiRef.dataAttributes} />
)
}
</ContentWidth>