({
content,
children
}: {
content: string;
children: React.ReactNode;
})
| 9 | import cn from 'mxcn'; |
| 10 | |
| 11 | export function InlineCopy({ |
| 12 | content, |
| 13 | children |
| 14 | }: { |
| 15 | content: string; |
| 16 | children: React.ReactNode; |
| 17 | }) { |
| 18 | const { isCopied, copyToClipboard } = useCopyToClipboard({ timeout: 2000 }); |
| 19 | const totalChars = content.length; |
| 20 | |
| 21 | const onCopy = () => { |
| 22 | navigator.clipboard.writeText(content); |
| 23 | if (isCopied) return; |
| 24 | copyToClipboard(content); |
| 25 | }; |
| 26 | |
| 27 | return ( |
| 28 | <span className="inline-flex items-center gap-1 whitespace-nowrap"> |
| 29 | <code className={cn(totalChars > 25 && 'w-[50%] sm:w-full overflow-scroll')}>{content}</code> |
| 30 | <Button |
| 31 | variant="ghost" |
| 32 | className="h-4 w-4 p-0 focus:ring-0" |
| 33 | size="icon" |
| 34 | onClick={onCopy} |
| 35 | > |
| 36 | {isCopied ? ( |
| 37 | <ClipboardDocumentCheckIcon className="w-4" /> |
| 38 | ) : ( |
| 39 | <DocumentDuplicateIcon className="w-4" /> |
| 40 | )} |
| 41 | <span className="sr-only">Copy</span> |
| 42 | </Button> |
| 43 | </span> |
| 44 | ); |
| 45 | } |
nothing calls this directly
no test coverage detected