"use client" import * as React from "react" import Image from "next/image" import { Index } from "@/__registry__" import { cn } from "@/lib/utils" import { useConfig } from "@/hooks/use-config" import { CopyButton } from "@/components/copy-button" import { Icons } from "@/components/icons" import { StyleSwitcher } from "@/components/style-switcher" import { ThemeWrapper } from "@/components/theme-wrapper" import { V0Button } from "@/components/v0-button" import { Tabs, TabsContent, TabsList, TabsTrigger, } from "@/registry/new-york/ui/tabs" import { styles } from "@/registry/registry-styles" interface ComponentPreviewProps extends React.HTMLAttributes { name: string extractClassname?: boolean extractedClassNames?: string align?: "center" | "start" | "end" description?: string hideCode?: boolean type?: "block" | "component" | "example" } export function ComponentPreview({ name, type, children, className, extractClassname, extractedClassNames, align = "center", description, hideCode = 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 Preview = React.useMemo(() => { const Component = Index[config.style][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]) if (type === "block") { return (
{name} {name}