'use client' import { ChevronRight, Expand } from 'lucide-react' import * as React from 'react' import { Button, cn, Collapsible, CollapsibleContent, CollapsibleTrigger, FloatingPlate } from 'ui' import { Index } from '@/__registry__' import { useConfig } from '@/hooks/use-config' import { styles } from '@/registry/styles' interface ComponentPreviewProps extends React.HTMLAttributes { name: string extractClassname?: boolean extractedClassNames?: string align?: 'center' | 'start' | 'end' peekCode?: boolean showGrid?: boolean showDottedGrid?: boolean wide?: boolean hideCode?: boolean padded?: boolean } export function ComponentPreview({ name, children, className, extractClassname, extractedClassNames, align = 'center', peekCode = false, showGrid = false, showDottedGrid = true, wide = false, hideCode = false, padded = true, ...props }: ComponentPreviewProps) { const [config] = useConfig() const index = styles.findIndex((style) => style.name === config.style) const Codes = React.Children.toArray(children) as React.ReactElement[] const Code = Codes[index] const [expand, setExpandState] = React.useState(false) const previewClassName = className const Preview = React.useMemo(() => { const Component = Index[config.style][name]?.component if (!Component) { return (

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

) } return }, [name, config.style]) const ComponentPreview = React.useMemo(() => { return ( <>
Loading...
} > {Preview} ) }, [Preview, align, padded, previewClassName]) const wideClasses = wide ? '2xl:-ml-20 2xl:-mr-20' : '' if (peekCode) { return (
{showGrid && (
)} {showDottedGrid && (
)}
{ComponentPreview}
{/*
*/}
{Code}
) } return (
{showGrid && (
)} {showDottedGrid && (
)}
{ComponentPreview}
{!hideCode && ( View code
{Code}
)}
) }