'use client' import * as React from 'react' import { Index } from '@/__registry__' import { Button, CollapsibleContent_Shadcn_, CollapsibleTrigger_Shadcn_, Collapsible_Shadcn_, cn, } from 'ui' import { useConfig } from '@/hooks/use-config' import { // CopyButton, CopyWithClassNames, } from '@/components/copy-button' // import { Icons } from '@/components/icons' // import { StyleSwitcher } from '@/components/style-switcher' // import { ThemeWrapper } from '@/components/theme-wrapper' import { Tabs_Shadcn_ as Tabs, TabsContent_Shadcn_ as TabsContent, TabsList_Shadcn_ as TabsList, TabsTrigger_Shadcn_ as TabsTrigger, } from 'ui' // import { LoaderCircle } from 'lucide-react' import { styles } from '@/registry/styles' import { ChevronRight, Expand } from 'lucide-react' interface ComponentPreviewProps extends React.HTMLAttributes { name: string extractClassname?: boolean extractedClassNames?: string align?: 'center' | 'start' | 'end' peekCode?: boolean showGrid?: boolean showDottedGrid?: boolean wide?: boolean } export function ComponentPreview({ name, children, className, extractClassname, extractedClassNames, align = 'center', peekCode = false, showGrid = false, showDottedGrid = true, wide = false, ...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 Preview = React.useMemo(() => { // console.log('Index', Index) // console.log('name', name) // console.log('config.style', config.style) const Component = Index[config.style][name]?.component // const Component = Index[name]?.component if (!Component) { return (

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

) } return }, [name, config.style]) const codeString = React.useMemo(() => { if (typeof Code?.props['data-rehype-pretty-code-fragment'] !== 'undefined') { const [, Button] = React.Children.toArray(Code.props.children) as React.ReactElement[] return Button?.props?.value || Button?.props?.__rawString__ || null } }, [Code]) const ComponentPreview = React.useMemo(() => { return ( <> {/* */}
{/* */} {/* */} Loading...
} > {Preview} {/*
*/} ) }, [Preview, align]) const wideClasses = wide ? '2xl:-ml-12 2xl:-mr-12' : '' if (peekCode) { return (
{showGrid && (
)} {showDottedGrid && (
)}
{ComponentPreview}
{/*
*/}
{Code}
) } return (
{showGrid && (
)} {showDottedGrid && (
)}
{ComponentPreview}
{/*
*/}
View code
{Code}
) return (
Preview Code
{ComponentPreview}
{Code}
) }