2021-02-16 19:18:09 +00:00
|
|
|
import React, { AnchorHTMLAttributes } from "react";
|
2020-09-01 14:51:59 +00:00
|
|
|
import { ExternalLinkAltIcon } from "@patternfly/react-icons";
|
2021-05-04 17:58:18 +00:00
|
|
|
import type { IFormatter, IFormatterValueType } from "@patternfly/react-table";
|
2020-09-01 08:25:24 +00:00
|
|
|
|
2021-02-16 19:18:09 +00:00
|
|
|
export type FormattedLinkProps = AnchorHTMLAttributes<HTMLAnchorElement> & {
|
|
|
|
isInline?: boolean;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const FormattedLink = ({
|
|
|
|
title,
|
|
|
|
href,
|
|
|
|
isInline,
|
|
|
|
...rest
|
|
|
|
}: FormattedLinkProps) => {
|
2020-09-01 08:25:24 +00:00
|
|
|
return (
|
2021-02-16 19:18:09 +00:00
|
|
|
<a
|
2020-09-21 20:12:53 +00:00
|
|
|
href={href}
|
2020-11-10 20:26:20 +00:00
|
|
|
target="_blank"
|
2021-02-16 19:18:09 +00:00
|
|
|
rel="noreferrer noopener"
|
|
|
|
className={isInline ? "pf-m-link pf-m-inline" : ""}
|
2020-09-21 20:12:53 +00:00
|
|
|
{...rest}
|
|
|
|
>
|
2021-02-16 19:18:09 +00:00
|
|
|
{title ? title : href}{" "}
|
|
|
|
{href?.startsWith("http") && <ExternalLinkAltIcon />}
|
|
|
|
</a>
|
2020-09-01 08:25:24 +00:00
|
|
|
);
|
|
|
|
};
|
2021-01-11 19:29:52 +00:00
|
|
|
|
|
|
|
export const formattedLinkTableCell = (): IFormatter => (
|
|
|
|
data?: IFormatterValueType
|
|
|
|
) => {
|
|
|
|
return (data ? (
|
|
|
|
<FormattedLink href={data.toString()} />
|
|
|
|
) : undefined) as object;
|
|
|
|
};
|