-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add and use react-tooltip (#3176)
* chore: add react-tooltip package into docs * chore: add react-tooltip styles globally into Layout * chore: use react-tooltip component into docs * fixes to the CSS --------- Co-authored-by: Shahed Nasser <shahednasser@gmail.com>
- Loading branch information
1 parent
63d61e3
commit a3acf24
Showing
4 changed files
with
65 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,19 @@ | ||
.tooltip-container { | ||
position: relative; | ||
.react-tooltip { | ||
border: 1px solid var(--ifm-tooltip-border-color) !important; | ||
border-radius: 8px !important; | ||
font-size: 12px !important; | ||
font-weight: 500 !important; | ||
line-height: 20px !important; | ||
box-shadow: 0px 2px 16px var(--ifm-tooltip-box-shadow-color) !important; | ||
padding: 8px 16px !important; | ||
} | ||
|
||
.tooltip-box { | ||
position: absolute; | ||
top: calc(-100% - 17px); | ||
z-index: 100000; | ||
padding: 8px 16px; | ||
max-width: 170px; | ||
text-align: center; | ||
|
||
background-color: var(--ifm-tooltip-background-color); | ||
border: 1px solid var(--ifm-tooltip-border-color); | ||
border-radius: 8px; | ||
color: var(--ifm-color-content); | ||
font-size: 12px; | ||
font-weight: 500; | ||
line-height: 20px; | ||
box-shadow: 0px 2px 16px var(--ifm-tooltip-box-shadow-color); | ||
|
||
opacity: 0; | ||
transition: opacity .3s ease-out; | ||
visibility: hidden; | ||
width: max-content; | ||
will-change: opacity,visibility; | ||
left: 50%; | ||
transform: translateX(-50%); | ||
} | ||
|
||
.tooltip-box.visible { | ||
opacity: 1; | ||
visibility: visible; | ||
} | ||
|
||
@media screen and (min-width: 876px) { | ||
.inline-tooltip { | ||
display: inline-block; | ||
} | ||
.react-tooltip-arrow { | ||
display: none; | ||
} | ||
|
||
@media screen and (max-width: 875px) { | ||
.tooltip-box { | ||
.react-tooltip { | ||
display: none; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,27 @@ | ||
import React from 'react'; | ||
import React, { useState, useEffect } from "react" | ||
import { Tooltip as ReactTooltip } from "react-tooltip" | ||
import uuid from "react-uuid" | ||
import "react-tooltip/dist/react-tooltip.css" | ||
|
||
export default function Tooltip ({ children, text, tooltipClassName, ...rest }) { | ||
const [show, setShow] = React.useState(false); | ||
export default function Tooltip({ children, text, tooltipClassName }) { | ||
const [elementId, setElementId] = useState(null) | ||
|
||
useEffect(() => { | ||
if (!elementId) { | ||
setElementId(uuid()) | ||
} | ||
}, [elementId]) | ||
|
||
return ( | ||
<span className={`tooltip-container ${tooltipClassName || ''}`}> | ||
<span className={show ? 'tooltip-box visible' : 'tooltip-box'}> | ||
{text} | ||
</span> | ||
<span | ||
onMouseEnter={() => setShow(true)} | ||
onMouseLeave={() => setShow(false)} | ||
{...rest} | ||
> | ||
<> | ||
<span id={elementId} data-tooltip-content={text}> | ||
{children} | ||
</span> | ||
</span> | ||
); | ||
}; | ||
<ReactTooltip | ||
anchorId={elementId} | ||
className={tooltipClassName} | ||
wrapper="span" | ||
/> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters