mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-07-08 14:35:09 +00:00
* feat: add base and radix docs * feat: transform code for display * fix * fix * fix * fix * fix * chore: remove claude files * fix * fix * fix * chore: run format:write * fix * feat: add more examples * fix * feat: add aspect-ratio * feat: add avatar * feat: add badge * feat: add breadcrumb * fix * feat: add button * fix * fix * fix * feat: add calendar and card * feat: add carousel * fix: chart * feat: add checkbox * feat: add collapsible * feat: add combobox * feat: add command * feat: add context menu * feat: add data-table dialog and drawer * feat: dropdown-menu * feat: add date-picker * feat: add empty * feat: add field and hover-card * fix: input * feat: add input * feat: add input-group * feat: add input-otp * feat: add item * feat: add kbd and label * feat: add menubar * feat: add native-select * feat: add more components * feat: more components * feat: more components * feat: add skeleton, slider and sonner * feat: add spinner and switch * feat: add more components * fix: tabs * fix: tabs * feat: add docs for sidebar * fix * fix * fi * docs: update * fix: create page * fix * fix * chore: add changelog * fix
104 lines
2.7 KiB
TypeScript
104 lines
2.7 KiB
TypeScript
import * as React from "react"
|
|
import Image from "next/image"
|
|
|
|
import { getRegistryComponent } from "@/lib/registry"
|
|
import { ComponentPreviewTabs } from "@/components/component-preview-tabs"
|
|
import { ComponentSource } from "@/components/component-source"
|
|
|
|
export function ComponentPreview({
|
|
name,
|
|
type,
|
|
className,
|
|
previewClassName,
|
|
align = "center",
|
|
hideCode = false,
|
|
chromeLessOnMobile = false,
|
|
styleName = "new-york-v4",
|
|
...props
|
|
}: React.ComponentProps<"div"> & {
|
|
name: string
|
|
styleName?: string
|
|
align?: "center" | "start" | "end"
|
|
description?: string
|
|
hideCode?: boolean
|
|
type?: "block" | "component" | "example"
|
|
chromeLessOnMobile?: boolean
|
|
previewClassName?: string
|
|
}) {
|
|
if (type === "block") {
|
|
return (
|
|
<div className="relative aspect-[4/2.5] w-full overflow-hidden rounded-xl border md:-mx-1">
|
|
<Image
|
|
src={`/r/styles/new-york-v4/${name}-light.png`}
|
|
alt={name}
|
|
width={1440}
|
|
height={900}
|
|
className="bg-background absolute top-0 left-0 z-20 w-[970px] max-w-none sm:w-[1280px] md:hidden dark:hidden md:dark:hidden"
|
|
/>
|
|
<Image
|
|
src={`/r/styles/new-york-v4/${name}-dark.png`}
|
|
alt={name}
|
|
width={1440}
|
|
height={900}
|
|
className="bg-background absolute top-0 left-0 z-20 hidden w-[970px] max-w-none sm:w-[1280px] md:hidden dark:block md:dark:hidden"
|
|
/>
|
|
<div className="bg-background absolute inset-0 hidden w-[1600px] md:block">
|
|
<iframe src={`/view/${styleName}/${name}`} className="size-full" />
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
const Component = getRegistryComponent(name, styleName)
|
|
|
|
if (!Component) {
|
|
return (
|
|
<p className="text-muted-foreground mt-6 text-sm">
|
|
Component{" "}
|
|
<code className="bg-muted relative rounded px-[0.3rem] py-[0.2rem] font-mono text-sm">
|
|
{name}
|
|
</code>{" "}
|
|
not found in registry.
|
|
</p>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<ComponentPreviewTabs
|
|
className={className}
|
|
previewClassName={previewClassName}
|
|
align={align}
|
|
hideCode={hideCode}
|
|
component={<DynamicComponent name={name} styleName={styleName} />}
|
|
source={
|
|
<ComponentSource
|
|
name={name}
|
|
collapsible={false}
|
|
styleName={styleName}
|
|
/>
|
|
}
|
|
chromeLessOnMobile={chromeLessOnMobile}
|
|
{...props}
|
|
/>
|
|
)
|
|
}
|
|
|
|
function DynamicComponent({
|
|
name,
|
|
styleName,
|
|
}: {
|
|
name: string
|
|
styleName: string
|
|
}) {
|
|
const Component = React.useMemo(
|
|
() => getRegistryComponent(name, styleName),
|
|
[name, styleName]
|
|
)
|
|
|
|
if (!Component) {
|
|
return null
|
|
}
|
|
|
|
return React.createElement(Component)
|
|
}
|