Skip to content

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

1.1 KB
Raw Blame
'use client';

import { useState } from 'react';
import { Link, Check } from 'lucide-react';
import { resolveCopyLinkUrl } from '@/lib/copy-link';

interface CopyLinkProps {
  href: string;
  children: React.ReactNode;
  className?: string;
}

export function CopyLink({ href, children, className }: CopyLinkProps) {
  const [copied, setCopied] = useState(false);

  const handleCopy = async () => {
    const fullUrl = resolveCopyLinkUrl(href, window.location.href);
    await navigator.clipboard.writeText(fullUrl);
    setCopied(true);
    setTimeout(() => setCopied(false), 2000);
  };

  return (
    <button
      onClick={handleCopy}
      className={`inline-flex items-center gap-1.5 group cursor-pointer whitespace-nowrap focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2 rounded ${className}`}
      aria-label="Copy link to clipboard"
    >
      <span>{children}</span>
      {copied ? (
        <Check className="w-3 h-3 text-green-500" aria-hidden="true" />
      ) : (
        <Link className="w-3 h-3 opacity-0 group-hover:opacity-70 transition-opacity" aria-hidden="true" />
      )}
    </button>
  );
}