Skip to content

Open-source status page, incident response and uptime monitoring

1.1 KB
Raw Blame
import { ArrowUpRight, ChevronRight } from "@openstatus/icons";

import { Link } from "@/components/common/link";
import { cn } from "@/lib/utils";

import { TableCellEmpty } from "./table-cell-empty";

export function TableCellLink({
  value,
  empty,
  className,
  ...props
}: React.ComponentProps<typeof Link> & {
  value: unknown;
  empty?: string;
}) {
  if (typeof value === "string") {
    const isExternal = props.href?.toString().startsWith("http");
    const externalProps = isExternal
      ? { target: "_blank", rel: "noopener noreferrer" }
      : {};
    const Icon = isExternal ? ArrowUpRight : ChevronRight;
    return (
      <Link
        className={cn(
          "group/link flex w-full items-center justify-between gap-2 rounded-lg hover:underline",
          className,
        )}
        {...externalProps}
        {...props}
      >
        <span className="truncate">{value}</span>
        <Icon className="text-muted-foreground group-hover/link:text-foreground size-4 flex-shrink-0" />
      </Link>
    );
  }
  return <TableCellEmpty>{empty}</TableCellEmpty>;
}