1
1
import React , { ReactNode , useState } from "react"
2
2
import styled from "@emotion/styled"
3
- import { Box , calc } from "@chakra-ui/react"
3
+ import { Box } from "@chakra-ui/react"
4
4
import * as utils from "../utils/isMobile"
5
5
6
- const Arrow = styled . span `
7
- position: absolute;
8
- bottom: -0.5rem;
9
- left: calc(50% - 6px);
10
- border-right: 10px solid transparent;
11
- border-top: 10px solid ${ ( { theme } ) => theme . colors . background } ;
12
- border-left: 10px solid transparent;
13
- `
14
-
15
6
// Invisible full screen div "below" the clickable link
16
7
// Added so clicking away anywhere will hide Tooltip
17
8
const ModalReturn = styled . div `
@@ -30,7 +21,7 @@ export interface IProps {
30
21
31
22
// TODO add `position` prop
32
23
const Tooltip : React . FC < IProps > = ( { content, children } ) => {
33
- const [ isVisible , setIsVisible ] = useState < boolean > ( false )
24
+ const [ isVisible , setIsVisible ] = useState < boolean > ( true )
34
25
const isMobile = utils . isMobile ( )
35
26
36
27
return (
@@ -45,7 +36,7 @@ const Tooltip: React.FC<IProps> = ({ content, children }) => {
45
36
cursor = "pointer"
46
37
title = "More info"
47
38
onMouseEnter = { ! isMobile ? ( ) => setIsVisible ( true ) : undefined }
48
- onMouseLeave = { ! isMobile ? ( ) => setIsVisible ( false ) : undefined }
39
+ onMouseLeave = { ! isMobile ? ( ) => setIsVisible ( true ) : undefined }
49
40
onClick = { isMobile ? ( ) => setIsVisible ( ! isVisible ) : undefined }
50
41
>
51
42
{ children }
@@ -70,7 +61,21 @@ const Tooltip: React.FC<IProps> = ({ content, children }) => {
70
61
left = "25%"
71
62
transform = "translateX(-50%)"
72
63
>
73
- < Arrow />
64
+ < Box
65
+ as = "span"
66
+ position = "absolute"
67
+ bottom = { - 2 }
68
+ left = "calc(50% - 6px)"
69
+ borderRightWidth = { 10 }
70
+ borderRightStyle = "solid"
71
+ borderRightColor = "transparent"
72
+ borderTopWidth = { 10 }
73
+ borderTopStyle = "solid"
74
+ borderTopColor = "background"
75
+ borderLeftWidth = { 10 }
76
+ borderLeftStyle = "solid"
77
+ borderLeftColor = "transparent"
78
+ />
74
79
{ content }
75
80
</ Box >
76
81
) }
0 commit comments