"use client"; import { useState } from "react"; import { Check, Link2 } from "lucide-react"; import posthog from "posthog-js"; import { cn } from "@/lib/utils"; interface ShareButtonsProps { url: string; title: string; tags: string[]; vertical?: boolean; } const PLATFORMS = [ { name: "X", buildUrl: (url: string, title: string, tags: string[]) => { const hashtags = tags.map((t) => t.replace(/[^a-zA-Z0-9]/g, "")).join(","); return `https://x.com/intent/tweet?text=${encodeURIComponent(title)}&url=${encodeURIComponent(url)}&hashtags=${hashtags}`; }, icon: ( ), hoverColor: "hover:bg-foreground hover:text-background", }, { name: "LinkedIn", buildUrl: (url: string) => `https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(url)}`, icon: ( ), hoverColor: "hover:bg-[#0A66C2] hover:text-white hover:border-[#0A66C2]", }, { name: "Reddit", buildUrl: (url: string, title: string) => `https://reddit.com/submit?url=${encodeURIComponent(url)}&title=${encodeURIComponent(title)}`, icon: ( ), hoverColor: "hover:bg-[#FF4500] hover:text-white hover:border-[#FF4500]", }, { name: "HN", buildUrl: (url: string, title: string) => `https://news.ycombinator.com/submitlink?u=${encodeURIComponent(url)}&t=${encodeURIComponent(title)}`, icon: ( ), hoverColor: "hover:bg-[#ff6600] hover:text-white hover:border-[#ff6600]", }, ]; export function ShareButtons({ url, title, tags, vertical = false }: ShareButtonsProps) { const [copied, setCopied] = useState(false); const handleCopyLink = async () => { await navigator.clipboard.writeText(url); setCopied(true); setTimeout(() => setCopied(false), 2000); posthog.capture("blog_link_copied", { url }); }; const handleShare = (platform: string) => { posthog.capture("blog_post_shared", { platform, url }); }; if (vertical) { return (

Share

{PLATFORMS.map((platform) => ( handleShare(platform.name)} className={cn( "flex h-10 w-10 items-center justify-center rounded-xl border border-border/50 text-muted-foreground/60 shadow-sm transition-all duration-200 hover:scale-110 hover:shadow-md dark:border-white/[0.08]", platform.hoverColor )} > {platform.icon} ))} {/* Divider */}
{/* Copy link */}
); } // Horizontal layout (mobile) return (
{PLATFORMS.map((platform) => ( handleShare(platform.name)} className={cn( "inline-flex items-center gap-1.5 rounded-lg border border-border/50 px-3 py-1.5 text-xs font-medium text-muted-foreground transition-all duration-200 dark:border-white/[0.08]", platform.hoverColor )} > {platform.icon} {platform.name} ))}
); }