Skip to content

Commit

Permalink
#14: Give access to x/y offset for easier custom tooltip placement
Browse files Browse the repository at this point in the history
  • Loading branch information
netzwerg committed Jun 12, 2019
1 parent 9946ee1 commit 0985924
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@ import * as React from 'react'
import * as ReactDOM from 'react-dom'
import svgPoint from './svg-point'

export type Props = Readonly<{
type Props = Readonly<{
triggerRef: React.RefObject<SVGElement>
containerRef?: React.RefObject<SVGSVGElement>
children: React.ReactNode | ((xOffset: number, yOffset: number) => React.ReactNode)
}>

export type TooltipHidden = {
readonly type: 'TooltipHidden'
}
type TooltipHidden = Readonly<{
type: 'TooltipHidden'
}>

export type TooltipVisible = {
readonly type: 'TooltipVisible'
readonly svgSvgElement: SVGSVGElement
readonly x: number
readonly y: number
}
type TooltipVisible = Readonly<{
type: 'TooltipVisible'
svgSvgElement: SVGSVGElement
x: number
y: number
}>

export type State = TooltipHidden | TooltipVisible
type State = TooltipHidden | TooltipVisible

export class TooltipComponent extends React.Component<Props, State> {
public readonly state: Readonly<State> = { type: 'TooltipHidden' }
Expand All @@ -45,7 +46,7 @@ export class TooltipComponent extends React.Component<Props, State> {
transform={`translate(${x}, ${y})`}
pointerEvents="none" // tooltip should never grab mouse > prevent flickering
>
{this.props.children}
{this.props.children instanceof Function ? this.props.children(x, y) : this.props.children}
</g>
)

Expand Down

0 comments on commit 0985924

Please sign in to comment.