/** * API Reference component for displaying TypeScript interface definitions * * Provides a beautiful, readable table for documenting API interfaces */ import * as React from 'react' import { Badge } from '@/components/ui/badge' import { cn } from '@/lib/utils' // ============================================================================ // Types // ============================================================================ export interface PropDefinition { /** Property name */ name: string /** TypeScript type (can include generics, unions, etc.) */ type: string /** Whether the property is required */ required?: boolean /** Default value if any */ defaultValue?: string /** Description of the property */ description: React.ReactNode /** Mark as experimental/deprecated */ status?: 'experimental' | 'deprecated' } export interface APIReferenceProps { /** Title for the API section */ title?: string /** Optional description */ description?: React.ReactNode /** Property definitions */ properties: PropDefinition[] /** Display variant: 'properties' for fields, 'methods' for methods */ variant?: 'properties' | 'methods' /** Additional CSS classes */ className?: string } // ============================================================================ // Component // ============================================================================ export function APIReference({ title, description, properties, variant = 'properties', className, }: APIReferenceProps) { const isMethodsVariant = variant === 'methods' return (
{description}
)}| {isMethodsVariant ? 'Method' : 'Property'} | {isMethodsVariant ? 'Return Type' : 'Type'} | Default | Description |
|---|
{name}
{required && (
{type}
{defaultValue}
) : (
-
)}
{children}
)
}
/** Section divider for grouping related APIs */
export function APIDivider({ title }: { title: string }) {
return (