-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
676 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { useState, useRef, useEffect } from "react" | ||
|
||
type JsonPopupProps = { | ||
children: React.ReactNode | ||
jsonString: string | ||
} | ||
|
||
function JsonPopup({ children, jsonString }: JsonPopupProps) { | ||
const [isHovering, setIsHovering] = useState(false) | ||
const [popupPosition, setPopupPosition] = useState({ top: 0, left: 0 }) | ||
const triggerElementRef = useRef<HTMLDivElement>(null) | ||
const popupRef = useRef<HTMLDivElement>(null) | ||
|
||
useEffect(() => { | ||
if (isHovering && triggerElementRef.current && popupRef.current) { | ||
const triggerRect = triggerElementRef.current.getBoundingClientRect() | ||
const popupRect = popupRef.current.getBoundingClientRect() | ||
setPopupPosition({ | ||
top: triggerRect.top - popupRect.height / 2, | ||
left: triggerRect.left - popupRect.width / 2 | ||
}) | ||
} | ||
}, [isHovering]) | ||
|
||
const popupStyle: React.CSSProperties = { | ||
position: 'fixed', | ||
zIndex: 100, | ||
maxHeight: '40vh', | ||
maxWidth: '40vw', | ||
overflow: 'auto', | ||
padding: '10px', | ||
display: isHovering ? 'block' : 'none', | ||
top: `${popupPosition.top}px`, | ||
left: `${popupPosition.left}px` | ||
} | ||
|
||
return ( | ||
<div ref={triggerElementRef} onMouseEnter={() => setIsHovering(true)} onMouseLeave={() => setIsHovering(false)}> | ||
{children} | ||
<div className='data-popup' ref={popupRef} style={popupStyle} onMouseLeave={() => setIsHovering(false)}> | ||
<pre>{jsonString}</pre> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default JsonPopup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.