Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

1.7 KB
Raw Blame
import { useState, useCallback } from "react";
import { useTranslation } from "react-i18next";
import { Copy, Check } from "../icons";

interface CopyableCommandProps {
  command: string;
  label?: string;
  /** Names what the button copies, e.g. "Copy MCP URL"; defaults to "Copy". */
  copyLabel?: string;
  onCopied?: () => void;
  className?: string;
}

export function CopyableCommand({
  command,
  label,
  copyLabel,
  onCopied,
  className = "",
}: CopyableCommandProps) {
  const { t } = useTranslation();
  const [copied, setCopied] = useState(false);

  const handleCopy = useCallback(() => {
    navigator.clipboard
      .writeText(command)
      .then(() => {
        setCopied(true);
        onCopied?.();
        setTimeout(() => setCopied(false), 2000);
      })
      .catch(() => {});
  }, [command, onCopied]);

  return (
    <div className={className}>
      {label && <div className="text-xs text-muted-foreground mb-1">{label}</div>}
      <div
        dir="ltr"
        className="relative bg-card border border-border p-3 rounded-md font-mono text-xs overflow-x-auto"
      >
        <span className="text-foreground pr-8">{command}</span>
        <button
          type="button"
          onClick={handleCopy}
          aria-label={copied ? t("common.copied") : (copyLabel ?? t("common.copy"))}
          className="absolute top-2 right-2 h-6 w-6 flex items-center justify-center rounded text-muted-foreground/70 hover:text-muted-foreground hover:bg-muted/50 active:scale-95 transition-all"
        >
          {copied ? (
            <Check className="w-3.5 h-3.5 text-success" />
          ) : (
            <Copy className="w-3.5 h-3.5" />
          )}
        </button>
      </div>
    </div>
  );
}