This repository has been archived by the owner on Jul 10, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 322
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d6a65dd
commit 0da1411
Showing
20 changed files
with
581 additions
and
327 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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 |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import styled from "@emotion/styled" | ||
import React, { useRef } from "react" | ||
import ReactTooltip from "react-tooltip" | ||
import Typography from "../typography" | ||
|
||
const Tooltip = styled(ReactTooltip)` | ||
${Typography.Base}; | ||
box-shadow: ${props => props.theme.shadows.popover} !important; | ||
padding: 0 !important; | ||
border: none !important; | ||
overflow: hidden; | ||
&.show { | ||
opacity: 1 !important; | ||
} | ||
&.place-bottom::before { | ||
border-bottom: 5.9px solid #e1e1e1 !important; | ||
border-left-width: 9px !important; | ||
border-right-width: 9px !important; | ||
margin-left: -9px !important; | ||
} | ||
&.place-bottom::after { | ||
border-bottom-width: 6px !important; | ||
} | ||
` | ||
|
||
const computePosition = (position, event, triggerElement, tooltipElement) => { | ||
const id = triggerElement.getAttribute("aria-describedby") | ||
const arrowLeft = | ||
triggerElement.getBoundingClientRect().left + triggerElement.offsetWidth / 2 | ||
const arrowTop = | ||
triggerElement.getBoundingClientRect().top + triggerElement.offsetHeight + 2 | ||
const leftPosition = arrowLeft - (tooltipElement.clientWidth - 30) | ||
|
||
const oldSheet = document.getElementById(`tooltip-styles-${id}`) | ||
if (oldSheet) document.body.removeChild(oldSheet) | ||
|
||
const sheet = document.createElement("style") | ||
sheet.setAttribute("id", "tooltip-styles") | ||
|
||
sheet.innerHTML = ` | ||
.__react_component_tooltip.${id}.place-bottom::after { | ||
position: fixed; | ||
top: ${arrowTop}px; | ||
left: ${arrowLeft}px; | ||
} | ||
.__react_component_tooltip.${id}.place-bottom::before { | ||
position: fixed; | ||
top: ${arrowTop - 1}px; | ||
left: ${arrowLeft}px; | ||
} | ||
` | ||
document.body.appendChild(sheet) | ||
return { | ||
top: position.top - 2, | ||
left: leftPosition, | ||
} | ||
} | ||
|
||
const Popover = ({ children, id }) => { | ||
const ref = useRef() | ||
const forceClose = e => { | ||
const current = ref.current | ||
current.tooltipRef = null | ||
ReactTooltip.hide() | ||
} | ||
|
||
const rebuildPopover = e => { | ||
ReactTooltip.rebuild() | ||
} | ||
|
||
return ( | ||
<Tooltip | ||
border="true" | ||
ref={ref} | ||
textColor="black" | ||
backgroundColor="white" | ||
arrowColor="white" | ||
effect="solid" | ||
clickable={true} | ||
globalEventOff={"click"} | ||
isCapture={true} | ||
id={id} | ||
place="bottom" | ||
overridePosition={computePosition} | ||
> | ||
{React.Children.map(children, child => { | ||
if (React.isValidElement(child)) { | ||
return React.cloneElement(child, { forceClose, rebuildPopover }) | ||
} | ||
return child | ||
})} | ||
</Tooltip> | ||
) | ||
} | ||
|
||
export default Popover |
Oops, something went wrong.