1
1
import React , { ReactNode , useState } from "react"
2
- import styled from "@emotion/styled"
3
2
import { Box } from "@chakra-ui/react"
4
3
import * as utils from "../utils/isMobile"
5
4
6
- // Invisible full screen div "below" the clickable link
7
- // Added so clicking away anywhere will hide Tooltip
8
- const ModalReturn = styled . div `
9
- position: fixed;
10
- top: 0;
11
- left: 0;
12
- width: 100%;
13
- height: 100%;
14
- z-index: 1;
15
- `
16
-
17
5
export interface IProps {
18
6
content : ReactNode
19
7
children ?: React . ReactNode
20
8
}
21
9
22
10
// TODO add `position` prop
23
11
const Tooltip : React . FC < IProps > = ( { content, children } ) => {
24
- const [ isVisible , setIsVisible ] = useState < boolean > ( true )
12
+ const [ isVisible , setIsVisible ] = useState < boolean > ( false )
25
13
const isMobile = utils . isMobile ( )
26
14
27
15
return (
28
16
< >
29
17
{ isVisible && isMobile && (
30
- < ModalReturn onClick = { ( ) => setIsVisible ( false ) } />
18
+ // Invisible full screen div "below" the clickable link
19
+ // Added so clicking away anywhere will hide Tooltip
20
+ < Box
21
+ position = "fixed"
22
+ top = { 0 }
23
+ left = { 0 }
24
+ w = "full"
25
+ h = "full"
26
+ zIndex = { 1 }
27
+ onClick = { ( ) => setIsVisible ( false ) }
28
+ />
31
29
) }
32
30
< Box
33
31
position = "relative"
@@ -36,7 +34,7 @@ const Tooltip: React.FC<IProps> = ({ content, children }) => {
36
34
cursor = "pointer"
37
35
title = "More info"
38
36
onMouseEnter = { ! isMobile ? ( ) => setIsVisible ( true ) : undefined }
39
- onMouseLeave = { ! isMobile ? ( ) => setIsVisible ( true ) : undefined }
37
+ onMouseLeave = { ! isMobile ? ( ) => setIsVisible ( false ) : undefined }
40
38
onClick = { isMobile ? ( ) => setIsVisible ( ! isVisible ) : undefined }
41
39
>
42
40
{ children }
0 commit comments