-
Notifications
You must be signed in to change notification settings - Fork 7
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
Showing
6 changed files
with
98 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React, {useState} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { OverlayTrigger, Tooltip } from 'react-bootstrap'; | ||
import ExternalLink from "../styles/icons/ExternalLink"; | ||
|
||
const LinkIcon = (props) => { | ||
const [overlayPlacement, setOverlayPlacement] = useState("right"); | ||
|
||
const getOverlayPlacement = (el) => { | ||
if (!el) return; | ||
|
||
if (el.getBoundingClientRect().x > window.innerWidth / 2) { | ||
setOverlayPlacement("left"); | ||
} else setOverlayPlacement("right"); | ||
} | ||
|
||
const tooltip = ( | ||
<Tooltip id="url-tooltip" className="tooltip-content"> | ||
{props.url} | ||
</Tooltip> | ||
); | ||
|
||
return ( | ||
<div ref={el => getOverlayPlacement(el)}> | ||
<OverlayTrigger placement={props.overlayPlacement || overlayPlacement} overlay={tooltip}> | ||
<span className={props.iconClassContainer} style={{ position: props.absolutePosition ? 'absolute' : null }}> | ||
<ExternalLink className={props.iconClass} /> | ||
</span> | ||
</OverlayTrigger> | ||
</div> | ||
); | ||
}; | ||
|
||
LinkIcon.propTypes = { | ||
url: PropTypes.string.isRequired, | ||
iconClassContainer: PropTypes.string, | ||
iconClass: PropTypes.string, | ||
overlayPlacement: PropTypes.string, | ||
absolutePosition: PropTypes.bool, | ||
}; | ||
|
||
LinkIcon.defaultProps = { | ||
iconClassContainer: '', | ||
iconClass: '', | ||
absolutePosition: true | ||
}; | ||
|
||
export default LinkIcon; |
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,16 @@ | ||
import React from 'react'; | ||
|
||
const ExternalLink = () => ( | ||
<svg | ||
className="external-link" | ||
version="1.1" | ||
xmlns="http://www.w3.org/2000/svg" | ||
width="24" | ||
height="28" | ||
viewBox="0 0 24 28" | ||
> | ||
<path fill="#000000" fill-rule="evenodd" d="M5,2 C5.55228,2 6,2.44772 6,3 C6,3.55228 5.55228,4 5,4 L4,4 L4,12 L12,12 L12,11 C12,10.4477 12.4477,10 13,10 C13.5523,10 14,10.4477 14,11 L14,12 C14,13.1046 13.1046,14 12,14 L4,14 C2.89543,14 2,13.1046 2,12 L2,4 C2,2.89543 2.89543,2 4,2 L5,2 Z M15,1 L15,5.99814453 C15,6.55043453 14.5523,6.99814453 14,6.99814453 C13.4477,6.99814453 13,6.55043453 13,5.99814453 L13,4.41419 L8.71571,8.69846 C8.32519,9.08899 7.69202,9.08899 7.3015,8.69846 C6.91097,8.30794 6.91097,7.67477 7.3015,7.28425 L11.5858,3 L9.99619141,3 C9.44391141,3 8.99619141,2.55228 8.99619141,2 C8.99619141,1.44772 9.44391141,1 9.99619141,1 L15,1 Z"/> | ||
</svg> | ||
); | ||
|
||
export default ExternalLink; |
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