({
path,
className,
align = 'center',
preview,
usingFramer,
usingCn,
...props
}: ComponentPreviewProps)
| 47 | */ |
| 48 | |
| 49 | export function ComponentPreview({ |
| 50 | path, |
| 51 | className, |
| 52 | align = 'center', |
| 53 | preview, |
| 54 | usingFramer, |
| 55 | usingCn, |
| 56 | ...props |
| 57 | }: ComponentPreviewProps) { |
| 58 | const name = formatName(path) |
| 59 | |
| 60 | const Preview = React.useMemo(() => { |
| 61 | if (preview) return preview |
| 62 | |
| 63 | try { |
| 64 | const Component = require(`../../showcase/${path}.tsx`).default |
| 65 | return <Component /> |
| 66 | } catch (error) { |
| 67 | console.error(`Failed to load component ${path}:`, error) |
| 68 | return ( |
| 69 | <p className="text-muted-foreground text-sm"> |
| 70 | Component{' '} |
| 71 | <RawCode className="bg-muted relative rounded px-[0.3rem] py-[0.2rem] font-mono text-sm"> |
| 72 | {path} |
| 73 | </RawCode>{' '} |
| 74 | not found. |
| 75 | </p> |
| 76 | ) |
| 77 | } |
| 78 | }, [path, preview]) |
| 79 | |
| 80 | const codeString = React.useMemo(() => { |
| 81 | try { |
| 82 | const code = require(`!!raw-loader!../../showcase/${path}.tsx`).default |
| 83 | const filteredCode = code.replace(/'use client'\n/, '') |
| 84 | return filteredCode |
| 85 | } catch (error) { |
| 86 | console.error(`Failed to load code for component ${path}:`, error) |
| 87 | return null |
| 88 | } |
| 89 | }, [path]) |
| 90 | |
| 91 | const [selectedTab, setSelectedTab] = React.useState('preview') |
| 92 | |
| 93 | if (usingCn) { |
| 94 | return ( |
| 95 | <ComponentPreviewUsingCn |
| 96 | path={path} |
| 97 | className={className} |
| 98 | align={align} |
| 99 | preview={preview} |
| 100 | usingFramer={usingFramer} |
| 101 | {...props} |
| 102 | /> |
| 103 | ) |
| 104 | } |
| 105 | return ( |
| 106 | <div |
nothing calls this directly
no test coverage detected