Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

3.3 KB
Raw Blame
import { Tooltip } from "@dub/ui";
import { ArrowTurnRight2, Flag2, Globe } from "@dub/ui/icons";
import { cn, getPrettyUrl, punycode } from "@dub/utils";

export function DomainCardTitleColumn({
  domain,
  icon: Icon = Globe,
  url,
  description,
  primary = false,
  defaultDomain = false,
}: {
  domain: string;
  icon?: React.ElementType;
  url?: string | null;
  description?: string;
  primary?: boolean;
  defaultDomain?: boolean;
}) {
  return (
    <div className="flex min-w-0 items-center gap-4">
      <div className="hidden rounded-full border border-neutral-200 sm:block">
        <div
          className={cn(
            "rounded-full",
            (!defaultDomain || domain === "cal.link") &&
              "border border-white bg-gradient-to-t from-neutral-100 p-1 md:p-2",
          )}
        >
          <Icon
            className={cn(
              "size-5",
              defaultDomain && domain !== "cal.link" && "size-8",
            )}
          />
        </div>
      </div>
      <div className="overflow-hidden">
        <div className="flex items-center gap-1.5 sm:gap-2.5">
          <a
            href={`http://${domain}`}
            target="_blank"
            rel="noreferrer"
            className="truncate text-sm font-medium"
            title={punycode(domain)}
          >
            {punycode(domain)}
          </a>
          <div className="flex items-center gap-1">
            {primary ? (
              <Tooltip content="This is the [primary domain](https://dub.co/help/article/how-to-set-primary-domain) that Dub defaults to in the [link builder](https://dub.co/help/article/dub-link-builder) and the [Links API](https://dub.co/docs/concepts/links/introduction).">
                <span className="xs:px-3 xs:py-1 flex cursor-help items-center gap-1 rounded-full bg-sky-400/[.15] px-1.5 py-0.5 text-xs font-medium text-sky-600">
                  <Flag2 className="hidden h-3 w-3 sm:block" />
                  Primary
                </span>
              </Tooltip>
            ) : null}
          </div>
        </div>
        {(!defaultDomain || description) && (
          <div className="mt-1 flex items-center gap-1 text-xs">
            {description ? (
              <span
                className="whitespace-pre-wrap text-neutral-500"
                title={description}
              >
                {description}
              </span>
            ) : (
              <>
                <ArrowTurnRight2 className="h-3 w-3 text-neutral-400" />
                {url !== undefined ? (
                  url ? (
                    <a
                      href={url}
                      target="_blank"
                      rel="noreferrer"
                      className="truncate text-neutral-500 transition-all hover:text-neutral-700 hover:underline hover:underline-offset-2"
                    >
                      {getPrettyUrl(url)}
                    </a>
                  ) : (
                    <span className="truncate text-neutral-400">
                      No redirect configured
                    </span>
                  )
                ) : (
                  <div className="h-4 w-16 animate-pulse rounded-md bg-neutral-200" />
                )}
              </>
            )}
          </div>
        )}
      </div>
    </div>
  );
}