Skip to content

Commit

Permalink
Attach tooltip to body
Browse files Browse the repository at this point in the history
  • Loading branch information
sshyam-gupta committed Dec 13, 2023
1 parent bc79735 commit bb90d9b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/DataMapState.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MouseEventHandler, createRef, useEffect, useState } from 'react'
import { createRef, useEffect, useState } from 'react'

import {
DEFAULT_BORDER_COLOR,
Expand Down
7 changes: 4 additions & 3 deletions src/components/MapTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { StateToolTip } from '../types'

function MapTooltip(props: StateToolTip) {
const HoverComponent = props.hoverComponent
const e = props.mouseEvent

return createPortal(
<>
<div
style={{
top: props.mouseEvent?.clientY - 150,
left: props.mouseEvent?.clientX - 100,
top: e.pageY - 75,
left: e.pageX,
position: 'absolute',
}}
className="state-tooltip"
Expand Down Expand Up @@ -43,7 +44,7 @@ function MapTooltip(props: StateToolTip) {
}
`}</style>
</>,
document.getElementById('datamaps-tooltip') as HTMLDivElement
document.querySelector('body') as HTMLBodyElement
)
}

Expand Down
3 changes: 2 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import MapTitle from './components/MapTitle'

const svgStyle: SvgStyle = {
display: 'inline-block',
position: 'absolute',
position: 'relative',
top: 0,
left: 0,
}
Expand Down Expand Up @@ -64,6 +64,7 @@ function DataMapsIndia({
<>
<svg
style={svgStyle}
className="datamaps-india"
viewBox={`0 0 ${MAP_WIDTH} ${MAP_HEIGHT}`}
preserveAspectRatio="xMinYMin meet"
>
Expand Down

0 comments on commit bb90d9b

Please sign in to comment.