-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable selecting variable values in time machine
- Loading branch information
Showing
19 changed files
with
461 additions
and
376 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
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,25 @@ | ||
@import 'src/style/modules'; | ||
|
||
$box-tooltip--caret-size: 6px; | ||
|
||
.box-tooltip { | ||
position: fixed; | ||
visibility: hidden; | ||
z-index: $z--dygraph-legend; | ||
border: $ix-border solid $c-pool; | ||
background-color: $g1-raven; | ||
border-radius: $radius; | ||
padding: 10px; | ||
font-size: 13px; | ||
} | ||
|
||
.box-tooltip.left .box-tooltip--caret { | ||
position: absolute; | ||
right: -$box-tooltip--caret-size; | ||
transform: translate(0,-50%); | ||
width: 0; | ||
height: 0; | ||
border-top: $box-tooltip--caret-size solid transparent; | ||
border-bottom: $box-tooltip--caret-size solid transparent; | ||
border-left: $box-tooltip--caret-size solid $c-pool; | ||
} |
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,72 @@ | ||
// Libraries | ||
import React, {useRef, useLayoutEffect, FunctionComponent} from 'react' | ||
import {createPortal} from 'react-dom' | ||
|
||
// Constants | ||
import {TOOLTIP_PORTAL_ID} from 'src/shared/components/TooltipPortal' | ||
|
||
// Styles | ||
import 'src/shared/components/BoxTooltip.scss' | ||
|
||
interface Props { | ||
triggerRect: DOMRect | ||
children: JSX.Element | ||
} | ||
|
||
const BoxTooltip: FunctionComponent<Props> = ({triggerRect, children}) => { | ||
const ref = useRef<HTMLDivElement>(null) | ||
|
||
// Position the tooltip after it has rendered, taking into account its size | ||
useLayoutEffect(() => { | ||
const el = ref.current | ||
|
||
if (!el || !triggerRect) { | ||
return | ||
} | ||
|
||
const rect = el.getBoundingClientRect() | ||
|
||
// Always position the tooltip to the left of the trigger position | ||
const left = triggerRect.left - rect.width | ||
|
||
// Attempt to position the vertical midpoint of tooltip next to the | ||
// vertical midpoint of the trigger rectangle | ||
let top = triggerRect.top + triggerRect.height / 2 - rect.height / 2 | ||
|
||
// If the tooltip overflows the top of the screen, align the top of | ||
// the tooltip with the top of the screen | ||
if (top < 0) { | ||
top = 0 | ||
} | ||
|
||
// If the tooltip overflows the bottom of the screen, align the bottom of | ||
// the tooltip with the bottom of the screen | ||
if (top + rect.height > window.innerHeight) { | ||
top = window.innerHeight - rect.height | ||
} | ||
|
||
el.setAttribute( | ||
'style', | ||
`visibility: visible; top: ${top}px; left: ${left}px;` | ||
) | ||
|
||
// Position the caret (little arrow on the side of the tooltip) so that it | ||
// points to the vertical midpoint of the trigger rectangle | ||
const caretTop = triggerRect.top + triggerRect.height / 2 - top | ||
|
||
el.querySelector('.box-tooltip--caret').setAttribute( | ||
'style', | ||
`top: ${caretTop}px;` | ||
) | ||
}) | ||
|
||
return createPortal( | ||
<div className="box-tooltip left" ref={ref}> | ||
{children} | ||
<div className="box-tooltip--caret" /> | ||
</div>, | ||
document.querySelector(`#${TOOLTIP_PORTAL_ID}`) | ||
) | ||
} | ||
|
||
export default BoxTooltip |
Oops, something went wrong.