diff --git a/client/src/components/share-buttons.tsx b/client/src/components/share-buttons.tsx new file mode 100644 index 0000000..f8c5e11 --- /dev/null +++ b/client/src/components/share-buttons.tsx @@ -0,0 +1,102 @@ +import { SiFacebook, SiLinkedin, SiX, SiWhatsapp, SiTelegram, SiPinterest } from "react-icons/si"; +import { Mail, Link2, Check } from "lucide-react"; +import { useState } from "react"; + +interface ShareButtonsProps { + url: string; + title: string; + image?: string; +} + +const SHARE_TARGETS = [ + { + name: "Facebook", + icon: SiFacebook, + color: "hover:bg-[#1877F2] hover:text-white", + getUrl: (url: string) => `https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(url)}`, + }, + { + name: "X", + icon: SiX, + color: "hover:bg-[#000] hover:text-white", + getUrl: (url: string, title: string) => `https://x.com/intent/tweet?url=${encodeURIComponent(url)}&text=${encodeURIComponent(title)}`, + }, + { + name: "LinkedIn", + icon: SiLinkedin, + color: "hover:bg-[#0A66C2] hover:text-white", + getUrl: (url: string) => `https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(url)}`, + }, + { + name: "WhatsApp", + icon: SiWhatsapp, + color: "hover:bg-[#25D366] hover:text-white", + getUrl: (url: string, title: string) => `https://wa.me/?text=${encodeURIComponent(title + " " + url)}`, + }, + { + name: "Telegram", + icon: SiTelegram, + color: "hover:bg-[#26A5E4] hover:text-white", + getUrl: (url: string, title: string) => `https://t.me/share/url?url=${encodeURIComponent(url)}&text=${encodeURIComponent(title)}`, + }, + { + name: "Pinterest", + icon: SiPinterest, + color: "hover:bg-[#BD081C] hover:text-white", + getUrl: (url: string, title: string, image?: string) => `https://pinterest.com/pin/create/button/?url=${encodeURIComponent(url)}&description=${encodeURIComponent(title)}${image ? "&media=" + encodeURIComponent(image) : ""}`, + }, + { + name: "E-Mail", + icon: Mail, + color: "hover:bg-muted-foreground hover:text-white", + getUrl: (url: string, title: string) => `mailto:?subject=${encodeURIComponent(title)}&body=${encodeURIComponent(title + "\n\n" + url)}`, + }, +]; + +export default function ShareButtons({ url, title, image }: ShareButtonsProps) { + const [copied, setCopied] = useState(false); + + const handleCopy = async () => { + try { + await navigator.clipboard.writeText(url); + setCopied(true); + setTimeout(() => setCopied(false), 2000); + } catch { + const input = document.createElement("input"); + input.value = url; + document.body.appendChild(input); + input.select(); + document.execCommand("copy"); + document.body.removeChild(input); + setCopied(true); + setTimeout(() => setCopied(false), 2000); + } + }; + + return ( +