spb/countryatlas
Public
TypeScript 57%
Python 38.6%
JavaScript 3.6%
CSS 0.6%
1'use client';2import { Check, Code2 } from 'lucide-react';3import { useState } from 'react';4import { t } from '@/i18n';5import { SITE_URL } from '@/lib/site';67/** Copies the absolute API URL of the entity (country / indicator) to the clipboard; falls back to opening it. */8export function CopyApiButton({ path, className }: { path: string; className?: string }) {9 const [done, setDone] = useState(false);10 const url = `${SITE_URL}${path}`;11 const copy = async () => {12 try {13 await navigator.clipboard.writeText(url);14 setDone(true);15 setTimeout(() => setDone(false), 1800);16 } catch {17 window.open(path, '_blank', 'noopener');18 }19 };20 return (21 <button type="button" onClick={copy} 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" title={url}>22 {done ? <Check size={15} aria-hidden className="text-up" /> : <Code2 size={15} aria-hidden />}23 {done ? t('common.copied') : t('country.api')}24 </button>25 );26}27