1
- import { Dispatch , SetStateAction } from "react" ;
1
+ import { Dispatch , SetStateAction , useRef , useEffect , useState } from "react" ;
2
2
import { Node } from "./model" ;
3
3
import { Copy , SquareArrowOutUpRight , X } from "lucide-react" ;
4
+ import SyntaxHighlighter from 'react-syntax-highlighter' ;
5
+ import { dark } from 'react-syntax-highlighter/dist/esm/styles/hljs' ;
4
6
5
7
interface Props {
6
8
obj : Node | undefined ;
@@ -19,27 +21,51 @@ const excludedProperties = [
19
21
20
22
export default function DataPanel ( { obj, setObj, url } : Props ) {
21
23
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
+
22
33
if ( ! obj ) return null ;
23
34
24
35
const label = `${ obj . category } : ${ obj . name } `
25
36
const object = Object . entries ( obj ) . filter ( ( [ k ] ) => ! excludedProperties . includes ( k ) )
26
37
27
38
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" >
29
40
< 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 >
33
42
< button onClick = { ( ) => setObj ( undefined ) } >
34
43
< X color = "white" />
35
44
</ button >
36
45
</ 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" >
38
47
{
39
48
object . map ( ( [ key , value ] ) => (
40
49
< div key = { key } className = "flex gap-2" >
41
50
< 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
+ }
43
69
</ div >
44
70
) )
45
71
}
0 commit comments