Check if link is a valid url in mdx inline link: if so, open in a new tab, if not, same tab.

This commit is contained in:
Piotr Janosz
2019-09-03 14:28:55 +02:00
parent 9892d8d6d2
commit e0adb6624d

View File

@@ -1,4 +1,5 @@
import * as React from 'react';
import * as validUrl from 'valid-url';
import { Link } from 'ts/components/documentation/shared/link';
import { docs } from 'ts/style/docs';
@@ -10,9 +11,16 @@ interface IInlineLinkProps {
export const InlineLink: React.FC<IInlineLinkProps> = ({ children, href }) => {
const to = href.replace(/^#/, ''); // Remove initial hash from internal links so that react-scroll can find the target
const shouldOpenInNewTab = validUrl.isWebUri(href) ? true : false;
return (
<Link containerId="" offset={-docs.headerOffset} shouldOpenInNewTab={true} to={to} textDecoration="underline">
<Link
containerId=""
offset={-docs.headerOffset}
shouldOpenInNewTab={shouldOpenInNewTab}
to={to}
textDecoration="underline"
>
{children}
</Link>
);