MCPcopy
hub / github.com/QuantumNous/new-api / CopyButton

Function CopyButton

web/default/src/components/copy-button.tsx:43–91  ·  view source on GitHub ↗
({
  value,
  children,
  className,
  iconClassName,
  variant = 'ghost',
  size = 'icon',
  tooltip,
  successTooltip,
  'aria-label': ariaLabel,
}: CopyButtonProps)

Source from the content-addressed store, hash-verified

41}
42
43export function CopyButton({
44 value,
45 children,
46 className,
47 iconClassName,
48 variant = 'ghost',
49 size = 'icon',
50 tooltip,
51 successTooltip,
52 'aria-label': ariaLabel,
53}: CopyButtonProps) {
54 const { t } = useTranslation()
55 const { copiedText, copyToClipboard } = useCopyToClipboard({ notify: false })
56 const isCopied = copiedText === value
57 const resolvedTooltip = tooltip ?? t('Copy to clipboard')
58 const resolvedSuccessTooltip = successTooltip ?? t('Copied!')
59 const resolvedAriaLabel = ariaLabel ?? resolvedTooltip
60 const copiedAriaLabel = t('Copied')
61
62 const button = (
63 <Button
64 variant={variant}
65 size={size}
66 className={cn('shrink-0', className)}
67 onClick={() => copyToClipboard(value)}
68 aria-label={isCopied ? copiedAriaLabel : resolvedAriaLabel}
69 >
70 {isCopied ? (
71 <Check className={cn('text-success', iconClassName)} />
72 ) : (
73 <Copy className={cn(iconClassName)} />
74 )}
75 {children}
76 </Button>
77 )
78
79 if (tooltip || successTooltip) {
80 return (
81 <Tooltip>
82 <TooltipTrigger render={button}></TooltipTrigger>
83 <TooltipContent>
84 <p>{isCopied ? resolvedSuccessTooltip : resolvedTooltip}</p>
85 </TooltipContent>
86 </Tooltip>
87 )
88 }
89
90 return button
91}

Callers

nothing calls this directly

Calls 3

useCopyToClipboardFunction · 0.90
cnFunction · 0.90
copyToClipboardFunction · 0.50

Tested by

no test coverage detected