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:
@@ -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>
|
||||
);
|
||||
|
Reference in New Issue
Block a user