Copy to Clipboard Demo

Enhanced user experience with one-click copying for contact information, code snippets, and URLs

Contact Information

Email Address

Professional contact email

amjad.shakhshir@example.com

Phone Number

Direct line for business inquiries

+1 (555) 123-4567

Location

Current base of operations

San Francisco, CA, USA

LinkedIn Profile

Professional networking profile

https://www.linkedin.com/in/amjad-shakhshir/

GitHub Profile

Open source contributions and projects

https://github.com/AmjadShakhshir

Code Snippets

React Component Hook

tsx
const useCopyToClipboard = () => {
  const [copied, setCopied] = useState(false);
  
  const copy = async (text: string) => {
    try {
      await navigator.clipboard.writeText(text);
      setCopied(true);
      setTimeout(() => setCopied(false), 2000);
    } catch (error) {
      console.error('Copy failed:', error);
    }
  };
  
  return { copy, copied };
};

Vanilla JavaScript

js
function copyToClipboard(text) {
  if (navigator.clipboard) {
    return navigator.clipboard.writeText(text);
  } else {
    // Fallback for older browsers
    const textArea = document.createElement('textarea');
    textArea.value = text;
    document.body.appendChild(textArea);
    textArea.select();
    document.execCommand('copy');
    document.body.removeChild(textArea);
  }
}

CSS Animation

css
.copy-button {
  transition: all 0.2s ease;
}

.copy-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.copy-success {
  background: linear-gradient(135deg, #10B981, #059669);
  color: white;
}

Features

Visual Feedback

Instant confirmation with icon and color changes

Browser Compatibility

Works across all modern browsers with fallbacks

Multiple Formats

Copy text, URLs, code, and download files

Error Handling

Graceful fallbacks for unsupported browsers