({ value, className, src, ...props }: CopyButtonProps)
| 24 | } |
| 25 | |
| 26 | export function CopyButton({ value, className, src, ...props }: CopyButtonProps) { |
| 27 | const [hasCopied, setHasCopied] = React.useState(false); |
| 28 | |
| 29 | React.useEffect(() => { |
| 30 | setTimeout(() => { |
| 31 | setHasCopied(false); |
| 32 | }, 2000); |
| 33 | }, [hasCopied]); |
| 34 | |
| 35 | return ( |
| 36 | <button |
| 37 | className={cn( |
| 38 | "relative z-20 inline-flex h-8 items-center justify-center rounded-md border-zinc-200 p-2 text-sm font-medium text-zinc-900 transition-all hover:bg-zinc-100 focus:outline-none dark:text-zinc-100 dark:hover:bg-zinc-800", |
| 39 | className, |
| 40 | )} |
| 41 | onClick={() => { |
| 42 | copyToClipboardWithMeta(value, { |
| 43 | component: src, |
| 44 | }); |
| 45 | setHasCopied(true); |
| 46 | }} |
| 47 | {...props} |
| 48 | > |
| 49 | <span className="sr-only">Copy</span> |
| 50 | {hasCopied ? <Icons.check className="w-4 h-4" /> : <Icons.copy className="w-4 h-4" />} |
| 51 | </button> |
| 52 | ); |
| 53 | } |
| 54 | |
| 55 | interface CopyWithClassNamesProps extends DropdownMenuTriggerProps { |
| 56 | value: string; |
nothing calls this directly
no test coverage detected