@openpkg-ts/react
React components for rendering OpenPkg API documentation.
Install
npm install @openpkg-ts/react
Peer deps: react@^18 || ^19, tailwindcss@^4 (optional, for styled)
Entry Points
Headless Components
Unstyled, logic-only components for custom styling.
import {
CollapsibleMethod,
ExampleBlock,
ExpandableProperty,
MembersTable,
ParamTable,
Signature,
TypeTable,
} from '@openpkg-ts/react';
CollapsibleMethod | Expandable method with signature |
ExampleBlock | Code example display |
ExpandableProperty | Property with nested children |
MembersTable | Class/interface members table |
ParamTable | Function parameters table |
Signature | Type signature renderer |
TypeTable | Type properties table |
Styled Components
Pre-styled with Tailwind v4.
import {
APIPage,
FunctionPage,
ClassPage,
InterfacePage,
EnumPage,
VariablePage,
ExportIndexPage,
FullAPIReferencePage,
FunctionSection,
ClassSection,
InterfaceSection,
EnumSection,
VariableSection,
ExportSection,
ExportCard,
ParameterItem,
CodeTabs,
ImportSection,
} from '@openpkg-ts/react/styled';
Usage
Full API Page
import { FullAPIReferencePage } from '@openpkg-ts/react/styled';
import spec from './openpkg.json';
export default function APIReference() {
return <FullAPIReferencePage spec={spec} />;
}
Single Export Page
import { FunctionPage } from '@openpkg-ts/react/styled';
export default function CreateClientPage() {
const fn = spec.exports.find(e => e.name === 'createClient');
return <FunctionPage export={fn} packageName={spec.meta.name} />;
}
Custom Composition
import { ExportCard, ParameterItem } from '@openpkg-ts/react/styled';
import { buildSignatureString } from '@openpkg-ts/sdk';
export default function CustomExport({ exp }) {
return (
<ExportCard
name={exp.name}
kind={exp.kind}
signature={buildSignatureString(exp)}
description={exp.description}
>
{exp.signatures?.[0]?.parameters?.map(param => (
<ParameterItem key={param.name} {...param} />
))}
</ExportCard>
);
}
Adapters
Convert spec data to component props:
import {
specParamToAPIParam,
specSchemaToAPISchema,
specExamplesToCodeExamples,
buildImportStatement,
} from '@openpkg-ts/react/styled';
License
MIT