Skip to content

A modern and easy to use dashboard. 80+ integrations. 20K+ icons built in. Authentication out of the box. No YAML, drag and drop configuration.

1.2 KB
Raw Blame
"use client";

import { ActionIcon, CopyButton, Tooltip } from "@mantine/core";
import { IconCheck, IconCopy } from "@tabler/icons-react";

import type { RouterOutputs } from "@homarr/api";
import { createLocalMediaUrl } from "@homarr/icons/local-media-url";
import { useI18n } from "@homarr/translation/client";

interface CopyMediaProps {
  media: RouterOutputs["media"]["getPaginated"]["items"][number];
}

export const CopyMedia = ({ media }: CopyMediaProps) => {
  const t = useI18n("media");
  const label = t("action.copy.labelNamed", { name: media.name });

  const url = typeof window !== "undefined" ? `${window.location.origin}${createLocalMediaUrl(media.id)}` : "";

  // Clipboard only works on localhost or secure connections (https)
  if (url.startsWith("http://") && !url.startsWith("http://localhost")) {
    return null;
  }

  return (
    <CopyButton value={url}>
      {({ copy, copied }) => (
        <Tooltip label={label} openDelay={500}>
          <ActionIcon aria-label={label} onClick={copy} color={copied ? "teal" : "gray"} variant="subtle">
            {copied ? <IconCheck size={16} stroke={1.5} /> : <IconCopy size={16} stroke={1.5} />}
          </ActionIcon>
        </Tooltip>
      )}
    </CopyButton>
  );
};