1
- import React , { MouseEventHandler , ReactNode , useState } from "react"
2
- import styled from "@emotion/styled "
1
+ import React , { ReactNode , useState } from "react"
2
+ import { Box , useColorModeValue } from "@chakra-ui/react "
3
3
import * as utils from "../utils/isMobile"
4
4
5
- const Container = styled . div `
6
- position: relative;
7
- display: inline-flex;
8
- user-select: none;
9
- cursor: pointer;
10
- `
11
-
12
- const Content = styled . div `
13
- text-align: center;
14
- white-space: normal;
15
- width: 200px;
16
- color: ${ ( { theme } ) => theme . colors . text } ;
17
- background-color: ${ ( { theme } ) => theme . colors . background } ;
18
- box-shadow: ${ ( { theme } ) => theme . colors . tableBoxShadow } ;
19
- position: absolute;
20
- z-index: 10;
21
- padding: 1rem 0.5rem;
22
- text-transform: none;
23
- font-size: ${ ( { theme } ) => theme . fontSizes . s } ;
24
- font-weight: 500;
25
- cursor: default;
26
- border-radius: 4px;
27
- bottom: calc(100% + 1rem);
28
- left: 25%;
29
- bottom: 125%;
30
- transform: translateX(-50%);
31
- @media (max-width: ${ ( { theme } ) => theme . breakpoints . m } ) {
32
- width: 140px;
33
- }
34
- `
35
-
36
- const Arrow = styled . span `
37
- position: absolute;
38
- bottom: -0.5rem;
39
- left: calc(50% - 6px);
40
- border-right: 10px solid transparent;
41
- border-top: 10px solid ${ ( { theme } ) => theme . colors . background } ;
42
- border-left: 10px solid transparent;
43
- `
44
-
45
- // Invisible full screen div "below" the clickable link
46
- // Added so clicking away anywhere will hide Tooltip
47
- const ModalReturn = styled . div `
48
- position: fixed;
49
- top: 0;
50
- left: 0;
51
- width: 100%;
52
- height: 100%;
53
- z-index: 1;
54
- `
55
-
56
5
export interface IProps {
57
6
content : ReactNode
58
7
children ?: React . ReactNode
@@ -62,26 +11,74 @@ export interface IProps {
62
11
const Tooltip : React . FC < IProps > = ( { content, children } ) => {
63
12
const [ isVisible , setIsVisible ] = useState < boolean > ( false )
64
13
const isMobile = utils . isMobile ( )
14
+ const shadow = useColorModeValue ( "tableBox.light" , "tableBox.dark" )
65
15
66
16
return (
67
17
< >
68
18
{ isVisible && isMobile && (
69
- < ModalReturn onClick = { ( ) => setIsVisible ( false ) } />
19
+ // Invisible full screen div "below" the clickable link
20
+ // Added so clicking away anywhere will hide Tooltip
21
+ < Box
22
+ position = "fixed"
23
+ top = { 0 }
24
+ left = { 0 }
25
+ w = "full"
26
+ h = "full"
27
+ zIndex = { 1 }
28
+ onClick = { ( ) => setIsVisible ( false ) }
29
+ />
70
30
) }
71
- < Container
31
+ < Box
32
+ position = "relative"
33
+ display = "inline-flex"
34
+ userSelect = "none"
35
+ cursor = "pointer"
72
36
title = "More info"
73
37
onMouseEnter = { ! isMobile ? ( ) => setIsVisible ( true ) : undefined }
74
38
onMouseLeave = { ! isMobile ? ( ) => setIsVisible ( false ) : undefined }
75
39
onClick = { isMobile ? ( ) => setIsVisible ( ! isVisible ) : undefined }
76
40
>
77
41
{ children }
78
42
{ isVisible && (
79
- < Content >
80
- < Arrow />
43
+ < Box
44
+ textAlign = "center"
45
+ whiteSpace = "normal"
46
+ w = { { base : "140px" , md : "200px" } }
47
+ color = "text"
48
+ bg = "background"
49
+ boxShadow = { shadow }
50
+ position = "absolute"
51
+ zIndex = "docked"
52
+ py = { 4 }
53
+ px = { 2 }
54
+ textTransform = "none"
55
+ fontSize = "sm"
56
+ fontWeight = "medium"
57
+ cursor = "default"
58
+ borderRadius = "base"
59
+ bottom = "125%"
60
+ left = "25%"
61
+ transform = "translateX(-50%)"
62
+ >
63
+ < Box
64
+ as = "span"
65
+ position = "absolute"
66
+ bottom = { - 2 }
67
+ left = "calc(50% - 6px)"
68
+ borderRightWidth = { 10 }
69
+ borderRightStyle = "solid"
70
+ borderRightColor = "transparent"
71
+ borderTopWidth = { 10 }
72
+ borderTopStyle = "solid"
73
+ borderTopColor = "background"
74
+ borderLeftWidth = { 10 }
75
+ borderLeftStyle = "solid"
76
+ borderLeftColor = "transparent"
77
+ />
81
78
{ content }
82
- </ Content >
79
+ </ Box >
83
80
) }
84
- </ Container >
81
+ </ Box >
85
82
</ >
86
83
)
87
84
}
0 commit comments