keycloak-scim/src/components/external-link/FormattedLink.tsx

29 lines
761 B
TypeScript
Raw Normal View History

import React from "react";
import { ExternalLinkAltIcon } from "@patternfly/react-icons";
import { Button, ButtonProps } from "@patternfly/react-core";
import { IFormatter, IFormatterValueType } from "@patternfly/react-table";
2020-09-01 08:25:24 +00:00
export const FormattedLink = ({ title, href, ...rest }: ButtonProps) => {
2020-09-01 08:25:24 +00:00
return (
2020-09-21 20:12:53 +00:00
<Button
variant="link"
icon={href?.startsWith("http") && <ExternalLinkAltIcon />}
iconPosition="right"
component="a"
href={href}
target="_blank"
2020-09-21 20:12:53 +00:00
{...rest}
>
{title ? title : href}
</Button>
2020-09-01 08:25:24 +00:00
);
};
export const formattedLinkTableCell = (): IFormatter => (
data?: IFormatterValueType
) => {
return (data ? (
<FormattedLink href={data.toString()} />
) : undefined) as object;
};