"use client" import * as React from "react" import { Index } from "@/__registry__" import { cn } from "@/lib/utils" 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, TabsContent, TabsList, TabsTrigger, } from "@/registry/new-york/ui/tabs" import { styles } from "@/registry/styles" interface ComponentPreviewProps extends React.HTMLAttributes { name: string extractClassname?: boolean extractedClassNames?: string align?: "center" | "start" | "end" } export function ComponentPreview({ name, children, className, extractClassname, extractedClassNames, align = "center", ...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]) return (
Preview Code
{extractedClassNames ? ( ) : ( codeString && )}
Loading...
} > {Preview}
{Code}
) }