MCPcopy Index your code
hub / github.com/SyntaxUI/syntaxui / ComponentPreview

Function ComponentPreview

src/components/code/ComponentPreview.tsx:49–206  ·  view source on GitHub ↗
({
  path,
  className,
  align = 'center',
  preview,
  usingFramer,
  usingCn,
  ...props
}: ComponentPreviewProps)

Source from the content-addressed store, hash-verified

47 */
48
49export 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

Callers

nothing calls this directly

Calls 2

cnFunction · 0.90
formatNameFunction · 0.85

Tested by

no test coverage detected