| 6 | import { cn } from "@/lib/utils"; |
| 7 | |
| 8 | export function ShareButton({ |
| 9 | slug, |
| 10 | small, |
| 11 | }: { |
| 12 | slug: string; |
| 13 | small?: boolean; |
| 14 | }) { |
| 15 | const [copied, setCopied] = useState(false); |
| 16 | |
| 17 | const handleCopy = () => { |
| 18 | navigator.clipboard.writeText(`${window.location.origin}/${slug}`); |
| 19 | setCopied(true); |
| 20 | toast("URL copied to clipboard"); |
| 21 | |
| 22 | setTimeout(() => { |
| 23 | setCopied(false); |
| 24 | }, 1000); |
| 25 | }; |
| 26 | |
| 27 | return ( |
| 28 | <button |
| 29 | onClick={handleCopy} |
| 30 | className={cn( |
| 31 | "text-xs bg-black text-white dark:bg-white dark:text-black rounded-full flex items-center justify-center", |
| 32 | small ? "p-1.5 size-7" : "p-2 size-9", |
| 33 | )} |
| 34 | type="button" |
| 35 | > |
| 36 | {copied ? ( |
| 37 | <Check className={small ? "w-3 h-3" : "w-4 h-4"} /> |
| 38 | ) : ( |
| 39 | <Share className={small ? "w-3 h-3" : "w-4 h-4"} /> |
| 40 | )} |
| 41 | </button> |
| 42 | ); |
| 43 | } |