Files
datahub/packages/core/src/ui/Base/CustomLink.tsx
Ola Rubaj af134cac8b Integrate flowershow packages (#923)
* [packages][m]: mv @flowershow/core package here

* [packages/core][xs]: rename to @portaljs/core

* [package.json][xs]: setup npm workspaces

* [packages/core][xs]:replace deprecated rollup executor

* [core/package.json][s]: fix mermaid versions

* [core/tsconfig][xs]: rm extends

* [core/jest.config][xs]: rm coverageDirectory

* [core/package.json][xs]: install core-js

* [packages.json][s]:use same version for all nrwl packages

* [core/.eslintrc][xs]: adjust ignorePatterns

* [core/project.json][xs]: rm publish targets

* [packages][m]: mv @flowershow/remark-wiki-link here

* [packages][m]: mv @flowershow/remark-wiki-link here

* [packages][m]: mv @flowershow/remark-embed here

* [remark-callouts/project.json][xs]: adjst test pattern

* [package.json][s]: install missing deps

* [remark-callouts][xs]: adjst fields in package.json

* [remark-callouts][s]: rm pubish targets and adjst build executor

* [remark-embed/jest.config][xs]: rm unknown option coverageDirectory

* [remark-embed][xs]: rm publish targets

* [remark-embed][s]: rename to @portaljs/remark-embed

* [remark-wiki-link/eslintrc][xs]:adjst ignorePatterns

* [package.json][xs]: install missing deps

* [remark-wiki-link/test][xs]:specify format

- also temporarily force any type on htmlExtension

* [remark-wiki-link/README][xs]: replace @flowershow with @portaljs

* [remark-wiki-link][xs]:rm old changelog

* [remark-wiki-link][xs]: adjst package.json

* [remark-wiki-link/project.json][xs]: rm publish targets

* [core][s]: rm old changelog

* [core/README][xs]:correct scope name

* [remark-callouts/README][xs]: add @portaljs to pckg name

* [remark-embed/README][xs]: add @portaljs to pckg name

* [package-lock.json][xs]: refresh after rebasing on main
2023-06-07 07:21:00 -03:00

58 lines
1.4 KiB
TypeScript

import Link from "next/link.js";
import { Tooltip } from "../Tooltip";
import TwitterEmbed from "./TwitterEmbed";
// TODO it's a mess, move twitter embeds support to remark-embed
const TWITTER_REGEX =
/^https?:\/\/twitter\.com\/(?:#!\/)?(\w+)\/status(es)?\/(\d+)/;
interface Props {
href: string;
data: any;
usehook: any;
preview: boolean;
children: React.ReactNode;
className?: string;
[x: string]: unknown;
}
export const CustomLink: React.FC<Props> = ({
data,
usehook,
preview,
...props
}) => {
const { href } = props;
const isInternalLink = !href.startsWith("http");
// eslint-disable-next-line no-useless-escape
const isHeadingLink = href.startsWith("#");
const isTwitterLink = TWITTER_REGEX.test(href);
// Use next link for pages within app and <a> for external links.
// https://nextjs.org/learn/basics/navigate-between-pages/client-side
if (isInternalLink) {
if (preview && !isHeadingLink) {
return (
<Tooltip
{...props}
data={data} // TODO again, why do we pass all documents here?!
usehook={usehook}
render={(tooltipTriggerProps) => <Link {...tooltipTriggerProps} />}
/>
);
} else {
return <Link {...props} />;
}
}
if (isTwitterLink) {
return <TwitterEmbed url={href} {...props} />;
}
return (
<a target="_blank" rel="noopener noreferrer" {...props}>
{props.children}
</a>
);
};