forked from newrelic/docs-website
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTooltip.js
More file actions
64 lines (60 loc) · 1.66 KB
/
Copy pathTooltip.js
File metadata and controls
64 lines (60 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import React, { useEffect, useState } from 'react';
import { css } from '@emotion/react';
import { Portal } from '@newrelic/gatsby-theme-newrelic';
const Tooltip = ({ className, children }) => {
const [shouldHide, setShouldHide] = useState(false);
useEffect(() => {
const timer = setTimeout(() => setShouldHide(true), 5000);
return () => clearTimeout(timer);
}, []);
return (
<Portal
initializer={(div) => {
if (div == null) return;
div.style.position = 'absolute';
div.style.top = '0';
}}
>
<div
css={css`
--length: 278px;
--height: 4.5rem;
height: var(--height);
width: var(--length);
z-index: 90;
border-radius: 4px;
padding: 1rem;
font-size: 14px;
color: var(--system-text-primary-dark);
background: var(--erno-black);
box-shadow: 0px -5px 6px 0 rgba(0, 0, 0, 0.25);
&::before {
--size: 1rem;
background: var(--erno-black);
border-bottom-right-radius: 4px;
content: '';
right: calc(50% - var(--size) / 2);
bottom: calc(var(--size) / -2);
height: var(--size);
position: absolute;
rotate: 45deg;
transform-origin: center;
translate: calc(var(--overflow-offset) * -1) 0;
width: var(--size);
}
p {
margin: 0;
}
${shouldHide &&
css`
display: none;
`}
`}
className={className}
>
{children}
</div>
</Portal>
);
};
export default Tooltip;