SPB Git forge

spb/countryatlas

Public
20commits 1branches 0releases
268.3 MBsize
maindefault branch
12 days agolast push
TypeScript 57% Python 38.6% JavaScript 3.6% CSS 0.6%
1.1 KB · 30 lines tsx
Raw Blame History
1'use client';2import { Check, Share2 } from 'lucide-react';3import { useState } from 'react';4import { t } from '@/i18n';56/** Web Share API when available, otherwise copies the URL to the clipboard. */7export function ShareButton({ title, className }: { title: string; className?: string }) {8  const [done, setDone] = useState(false);9  const share = async () => {10    const url = window.location.href;11    try {12      if (navigator.share) {13        await navigator.share({ title, url });14        return;15      }16      await navigator.clipboard.writeText(url);17      setDone(true);18      setTimeout(() => setDone(false), 1800);19    } catch {20      /* cancelled */21    }22  };23  return (24    <button type="button" onClick={share} className={`inline-flex h-10 items-center justify-center gap-2 rounded-sm border border-rule px-4 text-sm text-ink hover:bg-surface-2 ${className ?? ''}`} aria-live="polite">25      {done ? <Check size={15} aria-hidden className="text-up" /> : <Share2 size={15} aria-hidden />}26      {done ? t('common.copied') : t('common.share')}27    </button>28  );29}30