Skip to content

Commit

Permalink
add more tooltip attributes for more flexible customization
Browse files Browse the repository at this point in the history
  • Loading branch information
trisianto committed Oct 27, 2019
1 parent 712e100 commit a9282c6
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/components/TooltipPositioner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class TooltipPositioner extends React.Component<Props> {
private containerRef = React.createRef<HTMLDivElement>()

state = {
offset: null
offset: null,
tooltipDimensions: null
}

// simple heuristics to check if the tooltip container exceeds the viewport
Expand All @@ -19,7 +20,8 @@ class TooltipPositioner extends React.Component<Props> {
x: 0,
y: 0
}
const { right, left, top, bottom } = this.containerRef.current.getBoundingClientRect()
const tooltipContainerInitialDimensions = this.containerRef.current.getBoundingClientRect()
const { right, left, top, bottom } = tooltipContainerInitialDimensions
const containerWidth = right - left
const containerHeight = bottom - top

Expand All @@ -37,7 +39,8 @@ class TooltipPositioner extends React.Component<Props> {
}

this.setState({
offset
offset,
tooltipContainerInitialDimensions
})
}

Expand Down Expand Up @@ -66,7 +69,8 @@ class TooltipPositioner extends React.Component<Props> {
} = this.props

const {
offset
offset,
tooltipContainerInitialDimensions
} = this.state

const containerStyle = offset?
Expand All @@ -77,10 +81,15 @@ class TooltipPositioner extends React.Component<Props> {
opacity: 0
}

const tooltipContainerAttributes = {
offset,
tooltipContainerInitialDimensions
}

return (
<div ref={this.containerRef} style={containerStyle}>
{tooltipContent({...tooltipContentArgs,
tooltipContainerOffset: offset? offset: {x:0, y:0}})}
tooltipContainerAttributes})}
</div>
)
}
Expand Down

0 comments on commit a9282c6

Please sign in to comment.