MCPcopy Create free account
hub / github.com/PageAI-Pro/page-ui / CopyButton

Function CopyButton

components/shared/ui/copy-button.tsx:27–68  ·  view source on GitHub ↗
({
  value,
  copyText = 'Copy to clipboard',
  copiedText = 'Copied!',
  size = 'default',
  className,
  ...props
}: CopyButtonProps)

Source from the content-addressed store, hash-verified

25}
26
27export function CopyButton({
28 value,
29 copyText = 'Copy to clipboard',
30 copiedText = 'Copied!',
31 size = 'default',
32 className,
33 ...props
34}: CopyButtonProps) {
35 const [hasCopied, setHasCopied] = React.useState(false);
36
37 React.useEffect(() => {
38 setTimeout(() => {
39 setHasCopied(false);
40 }, 2000);
41 }, [hasCopied]);
42
43 const copyToClipboard = React.useCallback((value: string) => {
44 copyToClipboardWithMeta(value);
45 setHasCopied(true);
46 }, []);
47
48 return (
49 <Button
50 size={size}
51 variant="default"
52 className={cn('relative flex gap-1', className)}
53 onClick={() => copyToClipboard(value)}
54 {...props}
55 >
56 {hasCopied ? (
57 <>
58 {copiedText} <CheckIcon className="h-3 w-3" />
59 </>
60 ) : (
61 <>
62 {copyText} <CopyIcon className="h-3 w-3" />
63 </>
64 )}
65 <span className="sr-only">Copy</span>
66 </Button>
67 );
68}

Callers

nothing calls this directly

Calls 2

cnFunction · 0.90
copyToClipboardWithMetaFunction · 0.85

Tested by

no test coverage detected