|
| 1 | +import { Check, ChevronDown, ChevronRight, Copy, Terminal } from "lucide-react"; |
| 2 | +import Link from "next/link"; |
| 3 | +import { useState } from "react"; |
| 4 | +import { |
| 5 | + DropdownMenu, |
| 6 | + DropdownMenuContent, |
| 7 | + DropdownMenuItem, |
| 8 | + DropdownMenuTrigger, |
| 9 | +} from "@/components/ui/dropdown-menu"; |
| 10 | +import { cn } from "@/lib/utils"; |
| 11 | +import PackageIcon from "./icons"; |
| 12 | + |
| 13 | +export default function CommandSection() { |
| 14 | + const [copiedCommand, setCopiedCommand] = useState<string | null>(null); |
| 15 | + const [selectedPM, setSelectedPM] = useState<"npm" | "pnpm" | "bun">("bun"); |
| 16 | + |
| 17 | + const commands = { |
| 18 | + npm: "npx create-better-t-stack@latest", |
| 19 | + pnpm: "pnpm create better-t-stack@latest", |
| 20 | + bun: "bun create better-t-stack@latest", |
| 21 | + }; |
| 22 | + |
| 23 | + const copyCommand = (command: string, packageManager: string) => { |
| 24 | + navigator.clipboard.writeText(command); |
| 25 | + setCopiedCommand(packageManager); |
| 26 | + setTimeout(() => setCopiedCommand(null), 2000); |
| 27 | + }; |
| 28 | + |
| 29 | + return ( |
| 30 | + <div className="mb-8 grid grid-cols-1 gap-4 lg:grid-cols-2"> |
| 31 | + <div className="flex h-full flex-col justify-between rounded border border-border p-4"> |
| 32 | + <div className="mb-4 flex items-center justify-between"> |
| 33 | + <div className="flex items-center gap-2"> |
| 34 | + <Terminal className="h-4 w-4 text-primary" /> |
| 35 | + <span className="font-semibold text-sm">CLI_COMMAND</span> |
| 36 | + </div> |
| 37 | + <DropdownMenu> |
| 38 | + <DropdownMenuTrigger asChild> |
| 39 | + <button |
| 40 | + type="button" |
| 41 | + className="flex items-center gap-2 rounded border border-border px-3 py-1.5 text-xs transition-colors hover:bg-muted/10" |
| 42 | + > |
| 43 | + <PackageIcon pm={selectedPM} className="h-3 w-3" /> |
| 44 | + <span>{selectedPM.toUpperCase()}</span> |
| 45 | + <ChevronDown className="h-3 w-3" /> |
| 46 | + </button> |
| 47 | + </DropdownMenuTrigger> |
| 48 | + <DropdownMenuContent align="end"> |
| 49 | + {(["bun", "pnpm", "npm"] as const).map((pm) => ( |
| 50 | + <DropdownMenuItem |
| 51 | + key={pm} |
| 52 | + onClick={() => setSelectedPM(pm)} |
| 53 | + className={cn( |
| 54 | + "flex items-center gap-2", |
| 55 | + selectedPM === pm && "bg-accent text-background", |
| 56 | + )} |
| 57 | + > |
| 58 | + <PackageIcon pm={pm} className="h-3 w-3" /> |
| 59 | + <span>{pm.toUpperCase()}</span> |
| 60 | + {selectedPM === pm && ( |
| 61 | + <Check className="ml-auto h-3 w-3 text-background" /> |
| 62 | + )} |
| 63 | + </DropdownMenuItem> |
| 64 | + ))} |
| 65 | + </DropdownMenuContent> |
| 66 | + </DropdownMenu> |
| 67 | + </div> |
| 68 | + |
| 69 | + <div className="space-y-3"> |
| 70 | + <div className="flex items-center justify-between rounded border border-border p-3"> |
| 71 | + <div className="flex items-center gap-2 font-mono text-sm"> |
| 72 | + <span className="text-primary">$</span> |
| 73 | + <span className="text-foreground">{commands[selectedPM]}</span> |
| 74 | + </div> |
| 75 | + <button |
| 76 | + type="button" |
| 77 | + onClick={() => copyCommand(commands[selectedPM], selectedPM)} |
| 78 | + className="flex items-center gap-1 rounded border border-border px-2 py-1 text-xs hover:bg-muted/10" |
| 79 | + > |
| 80 | + {copiedCommand === selectedPM ? ( |
| 81 | + <Check className="h-3 w-3 text-primary" /> |
| 82 | + ) : ( |
| 83 | + <Copy className="h-3 w-3" /> |
| 84 | + )} |
| 85 | + {copiedCommand === selectedPM ? "COPIED!" : "COPY"} |
| 86 | + </button> |
| 87 | + </div> |
| 88 | + </div> |
| 89 | + </div> |
| 90 | + |
| 91 | + <Link href="/new"> |
| 92 | + <div className="group flex h-full cursor-pointer flex-col justify-between rounded border border-border p-4 transition-colors hover:bg-muted/10"> |
| 93 | + <div className="mb-4 flex items-center justify-between"> |
| 94 | + <div className="flex items-center gap-2"> |
| 95 | + <ChevronRight className="h-4 w-4 text-primary transition-transform group-hover:translate-x-1" /> |
| 96 | + <span className="font-semibold text-sm">STACK_BUILDER</span> |
| 97 | + </div> |
| 98 | + <div className="rounded border border-border bg-muted/30 px-2 py-1 text-xs"> |
| 99 | + INTERACTIVE |
| 100 | + </div> |
| 101 | + </div> |
| 102 | + |
| 103 | + <div className="space-y-3"> |
| 104 | + <div className="flex items-center justify-between rounded border border-border p-3"> |
| 105 | + <div className="flex items-center gap-2 text-sm"> |
| 106 | + <span className="text-primary">⚡</span> |
| 107 | + <span className="text-foreground"> |
| 108 | + Interactive configuration wizard |
| 109 | + </span> |
| 110 | + </div> |
| 111 | + <div className="rounded border border-border bg-muted/30 px-2 py-1 text-xs"> |
| 112 | + START |
| 113 | + </div> |
| 114 | + </div> |
| 115 | + </div> |
| 116 | + </div> |
| 117 | + </Link> |
| 118 | + </div> |
| 119 | + ); |
| 120 | +} |
0 commit comments