/** * 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 (
{title && (

{title}

)} {description && (

{description}

)}
{properties.map((prop) => ( ))}
{isMethodsVariant ? 'Method' : 'Property'} {isMethodsVariant ? 'Return Type' : 'Type'} Default Description
) } function PropRow({ name, type, required, defaultValue, description, status }: PropDefinition) { return ( {/* Property name */}
{name} {required && ( required )} {status === 'experimental' && ( experimental )} {status === 'deprecated' && ( deprecated )}
{/* Type */} {type} {/* Default value */} {defaultValue ? ( {defaultValue} ) : ( - )} {/* Description */} {description} ) } // ============================================================================ // Utility Components // ============================================================================ /** Code inline span for type references in descriptions */ export function TypeRef({ children }: { children: React.ReactNode }) { return ( {children} ) } /** Section divider for grouping related APIs */ export function APIDivider({ title }: { title: string }) { return (
{title}
) }