File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import React from "react" ;
2+ import { Tooltip } from "react-tooltip" ;
3+
4+ interface JSONTooltipProps {
5+ children : React . ReactNode ;
6+ data : any ;
7+ position ?: "top" | "bottom" | "left" | "right" ;
8+ className ?: string ;
9+ }
10+
11+ export const JSONTooltip : React . FC < JSONTooltipProps > = ( {
12+ children,
13+ data,
14+ position = "top" ,
15+ className = "" ,
16+ } ) => {
17+ const tooltipId = `json-tooltip-${ Math . random ( ) . toString ( 36 ) . substr ( 2 , 9 ) } ` ;
18+ const formattedJSON = JSON . stringify ( data , null , 2 ) ;
19+
20+ return (
21+ < >
22+ < div data-tooltip-id = { tooltipId } className = { `cursor-help ${ className } ` } >
23+ { children }
24+ </ div >
25+ < Tooltip
26+ id = { tooltipId }
27+ place = { position }
28+ className = "px-2 py-1 text-xs text-white bg-gray-800 rounded z-10 max-w-md"
29+ style = { {
30+ fontSize : "0.75rem" ,
31+ lineHeight : "1rem" ,
32+ backgroundColor : "#1f2937" ,
33+ color : "white" ,
34+ borderRadius : "0.25rem" ,
35+ padding : "0.5rem" ,
36+ zIndex : 10 ,
37+ userSelect : "text" ,
38+ pointerEvents : "auto" ,
39+ } }
40+ delayShow = { 200 }
41+ delayHide = { 300 }
42+ clickable = { true }
43+ noArrow = { true }
44+ render = { ( ) => (
45+ < pre
46+ className = "whitespace-pre-wrap text-left text-xs"
47+ style = { {
48+ userSelect : "text" ,
49+ pointerEvents : "auto" ,
50+ cursor : "text" ,
51+ } }
52+ onMouseDown = { ( e ) => e . stopPropagation ( ) }
53+ onClick = { ( e ) => e . stopPropagation ( ) }
54+ onDoubleClick = { ( e ) => e . stopPropagation ( ) }
55+ onContextMenu = { ( e ) => e . stopPropagation ( ) }
56+ >
57+ { formattedJSON }
58+ </ pre >
59+ ) }
60+ />
61+ </ >
62+ ) ;
63+ } ;
You can’t perform that action at this time.
0 commit comments