Skip to content

Commit c1817ab

Browse files
authored
Merge pull request #8684 from vdusart/feat/convert-Tooltip-component-to-ChakraUI
Convert tooltip component to chakra UI
2 parents 0689f26 + 7255794 commit c1817ab

File tree

2 files changed

+60
-61
lines changed

2 files changed

+60
-61
lines changed

src/components/StablecoinBoxGrid.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useState } from "react"
2-
import { Box, Flex, Heading } from "@chakra-ui/react"
2+
import { Box, Flex, Heading, useColorModeValue } from "@chakra-ui/react"
33
import { useI18next } from "gatsby-plugin-react-i18next"
44
import Link, { navigate } from "./Link"
55
import Emoji from "./Emoji"
@@ -148,6 +148,8 @@ const GridItem: React.FC<IPropsGridItem> = ({
148148
const handleClick = (): void => {
149149
callback(index)
150150
}
151+
const shadow = useColorModeValue("tableBox.light", "tableBox.dark")
152+
151153
return (
152154
<Flex
153155
id={`type-${index}`}
@@ -175,7 +177,7 @@ const GridItem: React.FC<IPropsGridItem> = ({
175177
background: isOpen ? color : "ednBackground",
176178
transition: isOpen ? "auto" : "transform 0.5s",
177179
transform: isOpen ? "auto" : "skewX(-5deg)",
178-
boxShadow: "tableBoxShadow",
180+
boxShadow: shadow,
179181
}}
180182
>
181183
{isOpen ? (

src/components/Tooltip.tsx

Lines changed: 56 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,7 @@
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"
33
import * as utils from "../utils/isMobile"
44

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-
565
export interface IProps {
576
content: ReactNode
587
children?: React.ReactNode
@@ -62,26 +11,74 @@ export interface IProps {
6211
const Tooltip: React.FC<IProps> = ({ content, children }) => {
6312
const [isVisible, setIsVisible] = useState<boolean>(false)
6413
const isMobile = utils.isMobile()
14+
const shadow = useColorModeValue("tableBox.light", "tableBox.dark")
6515

6616
return (
6717
<>
6818
{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+
/>
7030
)}
71-
<Container
31+
<Box
32+
position="relative"
33+
display="inline-flex"
34+
userSelect="none"
35+
cursor="pointer"
7236
title="More info"
7337
onMouseEnter={!isMobile ? () => setIsVisible(true) : undefined}
7438
onMouseLeave={!isMobile ? () => setIsVisible(false) : undefined}
7539
onClick={isMobile ? () => setIsVisible(!isVisible) : undefined}
7640
>
7741
{children}
7842
{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+
/>
8178
{content}
82-
</Content>
79+
</Box>
8380
)}
84-
</Container>
81+
</Box>
8582
</>
8683
)
8784
}

0 commit comments

Comments
 (0)