import * as React from "react";
import ReactLinkify from "react-linkify";
import Tooltip from "../tooltip";
export const truncateLink = (href: string, text: string, key: number) => {
const textWithoutProtocol = text.replace(/^https?:\/\//i, "");
const beginningOfPath = textWithoutProtocol.indexOf("/");
let finalText = textWithoutProtocol;
if (beginningOfPath !== -1) {
finalText = textWithoutProtocol.substring(0, beginningOfPath + 15);
}
if (finalText.length === textWithoutProtocol.length) {
return (
{finalText}
);
} else {
finalText += "…";
return (
{href}
}
>
{finalText}
);
}
};
const TruncatedLinkify: React.VoidFunctionComponent<{
children?: React.ReactNode;
}> = ({ children }) => {
return (
{children}
);
};
export default TruncatedLinkify;