Copy Button
fredrika-ui/copy-buttonFreeComponent
Copy to clipboard button
Install it
npx shadcn@latest add https://ui.fredrika.dev/r/copy-button.jsonSource
1"use client";23import React, { useState } from "react";45import { Check, Copy } from "lucide-react";6import { Button } from "@/registry/ui/button";7import { cn } from "@/lib/utils";89export const CopyButton = ({10 value,11 className,12 ...props13}: {14 value: string;15 className?: string;16} & React.ComponentProps<"button">) => {17 const [copied, setCopied] = useState(false);1819 const handleCopy = (e: React.MouseEvent<HTMLButtonElement>) => {20 if (!value) return;21 e.stopPropagation();22 navigator.clipboard.writeText(value);23 setCopied(true);24 setTimeout(() => {25 setCopied(false);26 }, 2000);27 };2829 return (30 <Button31 variant="ghost"32 size="icon"33 data-state={copied ? "copied" : "not-copied"}34 {...props}35 className={cn("transition-opacity relative flex-shrink-0", className)}36 onClick={handleCopy}37 >38 <span className="sr-only">Copy</span>39 <Check40 className={cn(41 "w-4 h-4 absolute inset-0 m-auto transition-all duration-200",42 copied ? "opacity-100 blur-0 scale-100" : "opacity-0 blur-sm scale-75"43 )}44 aria-label="Copied"45 />46 <Copy47 className={cn(48 "w-4 h-4 absolute inset-0 m-auto transition-all duration-200",49 !copied50 ? "opacity-100 blur-0 scale-100"51 : "opacity-0 blur-sm scale-75"52 )}53 aria-label="Copy"54 />55 </Button>56 );57};
What it pulls in
npm packages
Other registry items
Files it writes
More from fredrika ui
All 4 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Buttonbutton | fredrika ui | Components | Free | 2 deps | |
| Collapsible Cardcollapsible-card | fredrika ui | Components | Free | 2 deps · 5 files | |
| Diff Viewerdiff-viewer | fredrika ui | Components | Free | 4 deps · 7 files |
