@@ -5,21 +5,22 @@ import { AnimatePresence, motion } from 'framer-motion';
55import { Check , Copy } from 'lucide-react' ;
66import React , { useEffect , useState } from 'react' ;
77
8- import { Segment } from '@/components/s ' ;
8+ import { Segment } from '@/components/segment ' ;
99
10- import { highlight } from '../lib/shiki' ;
10+ import { highlightCode } from '../lib/shiki' ;
1111
1212interface Props {
13+ children : React . ReactNode ;
14+
1315 code : string ;
14- demo : React . ReactNode ;
1516 height ?: number | string ;
1617 lang ?: string ;
1718 name : string ;
1819 tabs ?: { label : string ; value : string } [ ] ;
1920 title ?: string ;
2021}
2122
22- export const ComponentPreview : React . FC < Props > = ( { code , demo , height = 360 , lang = 'tsx' , name, tabs, title } ) => {
23+ const ComponentPreview : React . FC < Props > = ( { children , code , height = 360 , lang = 'tsx' , name, tabs, title } ) => {
2324 const [ active , setActive ] = useState ( tabs ?. [ 0 ] ?. value ?? 'preview' ) ;
2425 const [ copied , setCopied ] = useState ( false ) ;
2526 const [ html , setHtml ] = useState ( '' ) ;
@@ -29,7 +30,9 @@ export const ComponentPreview: React.FC<Props> = ({ code, demo, height = 360, la
2930 useEffect ( ( ) => {
3031 let canceled = false ;
3132 setIsLoading ( true ) ;
32- highlight ( code . trim ( ) , lang ) . then ( result => {
33+ highlightCode ( code , lang ) . then ( result => {
34+ console . log ( 'result' , result ) ;
35+
3336 if ( ! canceled ) {
3437 setHtml ( result ) ;
3538 setIsLoading ( false ) ;
@@ -51,19 +54,19 @@ export const ComponentPreview: React.FC<Props> = ({ code, demo, height = 360, la
5154 } ;
5255
5356 return (
54- < div className = "my-8 overflow-hidden rounded-lg border border-border/50 bg-background/50 shadow-sm" >
57+ < div className = "my-8 overflow-hidden prose rounded-lg border border-border/50 bg-background/50 shadow-sm" >
5558 { /* Header */ }
5659 < div className = "flex items-center justify-between border-b border-border/50 px-4 py-2 bg-muted/40" >
5760 < span className = "font-medium text-sm text-foreground truncate" > { title ?? name } </ span >
5861 < Segment
5962 value = { active }
60- options = {
63+ items = {
6164 tabs ?? [
6265 { label : 'Preview' , value : 'preview' } ,
6366 { label : 'Code' , value : 'code' }
6467 ]
6568 }
66- onChange = { setActive }
69+ onValueChange = { setActive }
6770 />
6871 </ div >
6972
@@ -79,7 +82,7 @@ export const ComponentPreview: React.FC<Props> = ({ code, demo, height = 360, la
7982 style = { { height } }
8083 transition = { { duration : 0.2 } }
8184 >
82- { demo }
85+ { children }
8386 </ motion . div >
8487 ) : (
8588 < motion . div
@@ -104,8 +107,11 @@ export const ComponentPreview: React.FC<Props> = ({ code, demo, height = 360, la
104107
105108 { /* Code */ }
106109 < div
107- className = "overflow-auto text-sm leading-relaxed font-mono not-prose p-4"
108110 dangerouslySetInnerHTML = { { __html : html } }
111+ className = { cn (
112+ 'h-[calc(100vh-380px)] overflow-auto' ,
113+ '[&_pre]:m-0 [&_pre]:whitespace-pre [&_code]:whitespace-pre'
114+ ) }
109115 />
110116 { isLoading && (
111117 < div className = "absolute inset-0 flex items-center justify-center text-muted-foreground text-sm" >
@@ -118,3 +124,5 @@ export const ComponentPreview: React.FC<Props> = ({ code, demo, height = 360, la
118124 </ div >
119125 ) ;
120126} ;
127+
128+ export default ComponentPreview ;
0 commit comments