1- import { Dispatch , SetStateAction } from "react" ;
1+ import { Dispatch , SetStateAction , useRef , useEffect , useState } from "react" ;
22import { Node } from "./model" ;
33import { Copy , SquareArrowOutUpRight , X } from "lucide-react" ;
4+ import SyntaxHighlighter from 'react-syntax-highlighter' ;
5+ import { dark } from 'react-syntax-highlighter/dist/esm/styles/hljs' ;
46
57interface Props {
68 obj : Node | undefined ;
@@ -19,27 +21,51 @@ const excludedProperties = [
1921
2022export default function DataPanel ( { obj, setObj, url } : Props ) {
2123
24+ const containerRef = useRef < HTMLDivElement > ( null ) ;
25+ const [ containerHeight , setContainerHeight ] = useState ( 0 ) ;
26+
27+ useEffect ( ( ) => {
28+ if ( containerRef . current ) {
29+ setContainerHeight ( containerRef . current . clientHeight ) ;
30+ }
31+ } , [ containerRef . current ] ) ;
32+
2233 if ( ! obj ) return null ;
2334
2435 const label = `${ obj . category } : ${ obj . name } `
2536 const object = Object . entries ( obj ) . filter ( ( [ k ] ) => ! excludedProperties . includes ( k ) )
2637
2738 return (
28- < div className = "z-20 absolute -top-10 left-20 bg-[#343434] text-white shadow-lg rounded-lg flex flex-col min-h-[65%] max-h-[88%] max-w-[56%] overflow-hidden" >
39+ < div className = "z-20 absolute -top-10 left-20 text-white shadow-lg rounded-lg flex flex-col min-h-[65%] max-h-[88%] max-w-[56%] overflow-hidden" >
2940 < header className = "bg-[#191919] flex items-center gap-8 justify-between p-8" >
30- < div className = "border-b border-black text-bottom" >
31- < p title = { label } className = "truncate font-bold" > { label . toUpperCase ( ) } </ p >
32- </ div >
41+ < p title = { label } className = "truncate font-bold" > { label . toUpperCase ( ) } </ p >
3342 < button onClick = { ( ) => setObj ( undefined ) } >
3443 < X color = "white" />
3544 </ button >
3645 </ header >
37- < main className = "flex flex-col grow overflow-auto overflow-x-hidden p-4 justify-center" >
46+ < main ref = { containerRef } className = "bg-[#343434] flex flex-col grow overflow-y-auto p-4 justify-center" >
3847 {
3948 object . map ( ( [ key , value ] ) => (
4049 < div key = { key } className = "flex gap-2" >
4150 < p className = "text-[#FF804D]" > { key } :</ p >
42- < p className = "text-white" > { value } </ p >
51+ {
52+ key === "src" ?
53+ < SyntaxHighlighter
54+ language = "python"
55+ style = { {
56+ ...dark ,
57+ hljs : {
58+ ...dark . hljs ,
59+ maxHeight : `9rem` ,
60+ background : '#343434' ,
61+ padding : 2 ,
62+ }
63+ } }
64+ >
65+ { value }
66+ </ SyntaxHighlighter >
67+ : < p className = "text-white" > { value } </ p >
68+ }
4369 </ div >
4470 ) )
4571 }
0 commit comments