ComponentPreview() — ui Function Reference
Architecture documentation for the ComponentPreview() function in component-preview.tsx from the ui codebase.
Entity Profile
Dependency Diagram
graph TD fe619c93_a813_3aa8_e24c_837b9adde24c["ComponentPreview()"] 2e8d311b_d156_8b3e_bc13_f50b4484fb51["component-preview.tsx"] fe619c93_a813_3aa8_e24c_837b9adde24c -->|defined in| 2e8d311b_d156_8b3e_bc13_f50b4484fb51 style fe619c93_a813_3aa8_e24c_837b9adde24c fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
deprecated/www/components/component-preview.tsx lines 32–176
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 (
<p className="text-sm text-muted-foreground">
Component{" "}
<code className="relative rounded bg-muted px-[0.3rem] py-[0.2rem] font-mono text-sm">
{name}
</code>{" "}
not found in registry.
</p>
)
}
return <Component />
}, [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 (
<div className="relative aspect-[4/2.5] w-full overflow-hidden rounded-md border">
<Image
src={`/r/styles/${config.style}/${name}-light.png`}
alt={name}
width={1440}
height={900}
className="absolute left-0 top-0 z-20 w-[970px] max-w-none bg-background dark:hidden sm:w-[1280px] md:hidden md:dark:hidden"
/>
<Image
src={`/r/styles/${config.style}/${name}-dark.png`}
alt={name}
width={1440}
height={900}
className="absolute left-0 top-0 z-20 hidden w-[970px] max-w-none bg-background dark:block sm:w-[1280px] md:hidden md:dark:hidden"
/>
<div className="absolute inset-0 hidden w-[1600px] bg-background md:block">
<iframe
src={`/view/styles/${config.style}/${name}`}
className="size-full"
/>
</div>
</div>
)
}
return (
<div
className={cn("group relative my-4 flex flex-col space-y-2", className)}
{...props}
>
<Tabs defaultValue="preview" className="relative mr-auto w-full">
<div className="flex items-center justify-between pb-3">
Domain
Subdomains
Source
Frequently Asked Questions
What does ComponentPreview() do?
ComponentPreview() is a function in the ui codebase, defined in deprecated/www/components/component-preview.tsx.
Where is ComponentPreview() defined?
ComponentPreview() is defined in deprecated/www/components/component-preview.tsx at line 32.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free