copy-button
delta-components/copy-buttonFreeComponent
delta-components publishes no description for this item.
Live preview
live · rendered by the registry
Rendered by delta-components on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://deltacomponents.dev/r/copy-button.jsonSource
1"use client"23import * as React from "react"4import { CheckIcon, CopyIcon } from "lucide-react"56import { cn } from "@/lib/utils"7import { Button } from "@/components/ui/button"89export function copyToClipboard(value: string) {10 navigator.clipboard.writeText(value)11}1213interface CopyButtonProps extends React.ComponentProps<typeof Button> {14 value: string15 variant?:16 | "ghost"17 | "outline"18 | "secondary"19 | "default"20 | "destructive"21 | "link"22 iconColor?: string23}2425export function CopyButton({26 value,27 className,28 variant = "secondary",29 iconColor,30 ...props31}: CopyButtonProps) {32 const [hasCopied, setHasCopied] = React.useState(false)3334 React.useEffect(() => {35 if (hasCopied) {36 const timer = setTimeout(() => {37 setHasCopied(false)38 }, 2000)39 return () => clearTimeout(timer)40 }41 }, [hasCopied])4243 return (44 <Button45 data-slot="copy-button"46 size="icon"47 variant={variant}48 className={cn(49 "hover:bg-muted active:bg-muted size-7 border-none bg-transparent shadow-none",50 className51 )}52 onClick={() => {53 copyToClipboard(value)54 setHasCopied(true)55 }}56 {...props}57 >58 <span className="sr-only">Copy</span>59 <div className="relative">60 <div61 className={cn(62 "absolute inset-0 flex items-center justify-center transition-all duration-300 ease-in-out will-change-[transform,opacity,filter]",63 hasCopied64 ? "blur-0 scale-100 opacity-100"65 : "scale-[0.25] opacity-0 blur-xs"66 )}67 >68 <CheckIcon69 className="h-3.5 w-3.5"70 style={iconColor ? { color: iconColor } : {}}71 />72 </div>73 <div74 className={cn(75 "transition-[transform,opacity,filter] duration-300 ease-in-out will-change-[transform,opacity,filter]",76 hasCopied77 ? "scale-[0.25] opacity-0 blur-xs"78 : "blur-0 scale-100 opacity-100"79 )}80 >81 <CopyIcon82 className="h-3.5 w-3.5"83 style={iconColor ? { color: iconColor } : {}}84 />85 </div>86 </div>87 </Button>88 )89}
What it pulls in
npm packages
Other registry items
Files it writes
More from delta-components
All 93 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| admonitionadmonition | delta-components | Components | Free | 1 dep | |
| cambio-imagecambio-image | delta-components | Components | Free | 2 deps | |
| card-deckcard-deck | delta-components | Components | Free | 3 deps | |
| chatchat | delta-components | Components | Free | 3 deps | |
| code-blockcode-block | delta-components | Components | Free | 3 deps | |
| code-block-iconscode-block-icons | delta-components | Components | Free | no deps | |
| input-otpinput-otp | delta-components | Components | Free | 1 dep | |
| mapbox-pointermapbox-pointer | delta-components | Components | Free | no deps |
