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 | 'use client'; |
| 2 | |
| 3 | import { useState } from 'react'; |
| 4 | import { Link, Check } from 'lucide-react'; |
| 5 | import { resolveCopyLinkUrl } from '@/lib/copy-link'; |
| 6 | |
| 7 | interface CopyLinkProps { |
| 8 | href: string; |
| 9 | children: React.ReactNode; |
| 10 | className?: string; |
| 11 | } |
| 12 | |
| 13 | export function CopyLink({ href, children, className }: CopyLinkProps) { |
| 14 | const [copied, setCopied] = useState(false); |
| 15 | |
| 16 | const handleCopy = async () => { |
| 17 | const fullUrl = resolveCopyLinkUrl(href, window.location.href); |
| 18 | await navigator.clipboard.writeText(fullUrl); |
| 19 | setCopied(true); |
| 20 | setTimeout(() => setCopied(false), 2000); |
| 21 | }; |
| 22 | |
| 23 | return ( |
| 24 | <button |
| 25 | onClick={handleCopy} |
| 26 | 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}`} |
| 27 | aria-label="Copy link to clipboard" |
| 28 | > |
| 29 | <span>{children}</span> |
| 30 | {copied ? ( |
| 31 | <Check className="w-3 h-3 text-green-500" aria-hidden="true" /> |
| 32 | ) : ( |
| 33 | <Link className="w-3 h-3 opacity-0 group-hover:opacity-70 transition-opacity" aria-hidden="true" /> |
| 34 | )} |
| 35 | </button> |
| 36 | ); |
| 37 | } |