| 1 | import { Check, Copy } from "lucide"; |
| 2 | |
| 3 | import { MorphIcon } from "~/components/MorphIcon"; |
| 4 | import { useCopyToClipboard } from "~/hooks/useCopyToClipboard"; |
| 5 | import { cn } from "~/lib/utils"; |
| 6 | |
| 7 | import { Button } from "./ui/button"; |
| 8 | |
| 9 | /** A shell command to copy and run elsewhere, such as on the environment's host. */ |
| 10 | export function CommandBlock({ |
| 11 | command, |
| 12 | className, |
| 13 | prominent = false, |
| 14 | }: { |
| 15 | readonly command: string; |
| 16 | readonly className?: string; |
| 17 | readonly prominent?: boolean; |
| 18 | }) { |
| 19 | const { copyToClipboard, isCopied } = useCopyToClipboard({ |
| 20 | timeout: 1500, |
| 21 | target: "command", |
| 22 | }); |
| 23 | return ( |
| 24 | <div |
| 25 | className={cn( |
| 26 | "flex items-center justify-between gap-3 rounded-lg border border-border bg-muted/50 font-mono", |
| 27 | prominent ? "px-4 py-3.5 text-base" : "px-3 py-2.5 text-sm", |
| 28 | className, |
| 29 | )} |
| 30 | > |
| 31 | <span className="min-w-0 truncate"> |
| 32 | <span className="mr-2 text-muted-foreground">$</span> |
| 33 | {command} |
| 34 | </span> |
| 35 | <Button |
| 36 | size="icon-xs" |
| 37 | variant="ghost" |
| 38 | aria-label="Copy command" |
| 39 | onClick={() => copyToClipboard(command, undefined)} |
| 40 | > |
| 41 | <MorphIcon className="size-3.5" icon={isCopied ? Check : Copy} /> |
| 42 | </Button> |
| 43 | </div> |
| 44 | ); |
| 45 | } |