The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { T, useGT } from "gt-react"; |
| 2 | |
| 3 | import { type ClipboardTarget, useCopyToClipboard } from "~/hooks/useCopyToClipboard"; |
| 4 | import { cn } from "~/lib/utils"; |
| 5 | |
| 6 | import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip"; |
| 7 | |
| 8 | export function PullRequestCopyableCode({ |
| 9 | value, |
| 10 | target, |
| 11 | copyLabel, |
| 12 | copiedLabel, |
| 13 | className, |
| 14 | tooltipSide = "top", |
| 15 | onError, |
| 16 | }: { |
| 17 | readonly value: string; |
| 18 | readonly target: ClipboardTarget; |
| 19 | readonly copyLabel: string; |
| 20 | readonly copiedLabel: string; |
| 21 | readonly className?: string; |
| 22 | readonly tooltipSide?: "top" | "bottom"; |
| 23 | readonly onError?: (error: Error) => void; |
| 24 | }) { |
| 25 | const gt = useGT(); |
| 26 | const { copyToClipboard, isCopied } = useCopyToClipboard({ |
| 27 | target, |
| 28 | timeout: 1600, |
| 29 | ...(onError ? { onError } : {}), |
| 30 | }); |
| 31 | return ( |
| 32 | <Tooltip> |
| 33 | <TooltipTrigger |
| 34 | render={ |
| 35 | <button |
| 36 | type="button" |
| 37 | className={cn( |
| 38 | "relative grid w-fit min-w-0 max-w-full shrink cursor-pointer rounded px-1 py-0.5 text-left outline-none transition-colors pointer-coarse:after:absolute pointer-coarse:after:size-full pointer-coarse:after:min-h-11 pointer-coarse:after:min-w-11 hover:bg-accent/45 hover:text-foreground focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background", |
| 39 | className, |
| 40 | )} |
| 41 | aria-label={isCopied ? copiedLabel : copyLabel} |
| 42 | onClick={() => copyToClipboard(value)} |
| 43 | /> |
| 44 | } |
| 45 | > |
| 46 | <code |
| 47 | className={cn( |
| 48 | "col-start-1 row-start-1 min-w-0 truncate transition-opacity duration-150 motion-reduce:transition-none", |
| 49 | isCopied ? "opacity-0" : "opacity-100", |
| 50 | )} |
| 51 | > |
| 52 | {value} |
| 53 | </code> |
| 54 | <span |
| 55 | aria-hidden="true" |
| 56 | className={cn( |
| 57 | "col-start-1 row-start-1 truncate text-center transition-opacity duration-150 motion-reduce:transition-none", |
| 58 | isCopied ? "opacity-100" : "opacity-0", |
| 59 | )} |
| 60 | > |
| 61 | <T>Copied</T> |
| 62 | </span> |
| 63 | </TooltipTrigger> |
| 64 | <TooltipPopup variant="code" side={tooltipSide}> |
| 65 | {`${isCopied ? gt("Copied") : copyLabel}: ${value}`} |
| 66 | </TooltipPopup> |
| 67 | </Tooltip> |
| 68 | ); |
| 69 | } |