Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

CommandBlock.tsx

44 lines1.1 KB

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