SPB Git

spb/findata

Public
723 B · 26 lines tsx
1"use client";2import { useState } from "react";3import { Check, Copy } from "lucide-react";45export function CopyButton({ text, label = "Copy", className }: { text: string; label?: string; className?: string }) {6  const [ok, setOk] = useState(false);7  return (8    <button9      type="button"10      className={className ?? "btn btn-sm"}11      onClick={async () => {12        try {13          await navigator.clipboard.writeText(text);14          setOk(true);15          setTimeout(() => setOk(false), 1500);16        } catch {17          /* clipboard denied */18        }19      }}20    >21      {ok ? <Check className="h-3.5 w-3.5 text-ok" /> : <Copy className="h-3.5 w-3.5" />}22      {ok ? "Copied" : label}23    </button>24  );25}26
Files · main
Menu

Theme