SPB Git forge

spb/fetcha

Public
11commits 1branches 0releases
1.5 MBsize
maindefault branch
16 days agolast push
TypeScript 97.5% SQL 1.4% Python 0.8%
1.0 KB · 30 lines tsx
Raw Blame History
1"use client";2import * as React from "react";3import { Check, Copy } from "lucide-react";4import { Button, type ButtonProps } from "./button";5import { cn } from "@/lib/utils";67export function CopyButton({ value, className, label, size = "icon-sm", variant = "ghost", ...props }: { value: string; label?: string } & Omit<ButtonProps, "onClick" | "children">) {8  const [copied, setCopied] = React.useState(false);9  return (10    <Button11      type="button"12      size={label ? (size === "icon-sm" ? "sm" : size) : size}13      variant={variant}14      className={cn("text-fg-muted", className)}15      onClick={async () => {16        try {17          await navigator.clipboard.writeText(value);18          setCopied(true);19          setTimeout(() => setCopied(false), 1500);20        } catch {}21      }}22      aria-label={copied ? "Copied" : "Copy to clipboard"}23      {...props}24    >25      {copied ? <Check className="text-success" /> : <Copy />}26      {label ? <span>{copied ? "Copied" : label}</span> : null}27    </Button>28  );29}30