'use client' import { ChevronRight } from 'lucide-react' import * as React from 'react' import { cn, Collapsible, CollapsibleContent, CollapsibleTrigger } from 'ui' import { Index } from '@/__registry__' import { useConfig } from '@/hooks/use-config' import { styles } from '@/registry/styles' interface ComponentPreviewProps extends React.HTMLAttributes { name: keyof (typeof Index)['default'] extractClassname?: boolean extractedClassNames?: string align?: 'center' | 'start' | 'end' showGrid?: boolean showDottedGrid?: boolean showCode?: boolean wide?: boolean } export function ComponentPreview({ name, children, className, extractClassname, extractedClassNames, align = 'center', showGrid = false, showDottedGrid = true, showCode = true, wide = false, ...props }: ComponentPreviewProps) { const [config] = useConfig() const index = styles.findIndex((style) => style.name === config.style) const Preview = React.useMemo(() => { const Component = Index['default'][name]?.component if (!Component) { return (

Component{' '} {name} {' '} not found in registry.

) } return }, [name]) const Codes = React.Children.toArray(children) as React.ReactElement[] const Code = Codes[index] const ComponentPreview = React.useMemo(() => { return ( <>
Loading...
} > {Preview} ) }, [Preview, align]) const wideClasses = wide ? '2xl:-ml-12 2xl:-mr-12' : '' return (
{showGrid && (
)} {showDottedGrid && (
)}
{ComponentPreview}
{showCode && ( View code
{Code}
)}
) }