| 1 | "use client"; |
| 2 | |
| 3 | import { Check, Code2 |
| 4 | import type { ReactNode |
| 5 | |
| 6 | import { Button } |
| 7 | import { |
| 8 | InputGroup, |
| 9 | InputGroupAddon, |
| 10 | InputGroupButton, |
| 11 | InputGroupInput, |
| 12 | } from "@/components/ui/input-group"; |
| 13 | import { |
| 14 | Popover, |
| 15 | PopoverContent, |
| 16 | PopoverTrigger, |
| 17 | } from "@/components/ui/popover"; |
| 18 | import { Tabs, TabsContent |
| 19 | import { useCopy } |
| 20 | |
| 21 | export function ClonePopover({ |
| 22 | cloneUrl, |
| 23 | sshCloneUrl, |
| 24 | }: { |
| 25 | cloneUrl: string |
| 26 | sshCloneUrl?: string |
| 27 | }) { |
| 28 | return ( |
| 29 | <Popover> |
| 30 | <PopoverTrigger asChild> |
| 31 | <Button size=" |
| 32 | <Code2 data-icon=" |
| 33 | Code |
| 34 | </Button> |
| 35 | </PopoverTrigger> |
| 36 | |
| 37 | <PopoverContent align=" |
| 38 | <CloneSection cloneUrl={ |
| 39 | </PopoverContent> |
| 40 | </Popover> |
| 41 | ); |
| 42 | } |
| 43 | |
| 44 | export function CloneSection({ |
| 45 | cloneUrl, |
| 46 | sshCloneUrl, |
| 47 | }: { |
| 48 | cloneUrl: string |
| 49 | sshCloneUrl?: string |
| 50 | }) { |
| 51 | return ( |
| 52 | <div className="flex flex-col gap-2 |
| 53 | <p className="text-sm font-semibold |
| 54 | <CloneTransports |
| 55 | http={ |
| 56 | <> |
| 57 | <CloneUrlField cloneUrl={ |
| 58 | <p className="text-xs text-muted-foreground |
| 59 | The password is a personal access token from account settings, not |
| 60 | your login password. |
| 61 | </p> |
| 62 | </> |
| 63 | } |
| 64 | ssh={ |
| 65 | sshCloneUrl && ( |
| 66 | <> |
| 67 | <CloneUrlField cloneUrl={ |
| 68 | <p className="text-xs text-muted-foreground |
| 69 | Needs an SSH key on your account. Log in as <code>git</code>; |
| 70 | the key says who you are. |
| 71 | </p> |
| 72 | </> |
| 73 | ) |
| 74 | } |
| 75 | /> |
| 76 | </div> |
| 77 | ); |
| 78 | } |
| 79 | |
| 80 | /** One transport, or a tab per transport. An instance with no SSH listener has nothing to switch between, so it gets the HTTP panel on its own. */ |
| 81 | export function CloneTransports({ |
| 82 | http, |
| 83 | ssh, |
| 84 | }: { |
| 85 | http: ReactNode |
| 86 | ssh?: ReactNode |
| 87 | }) { |
| 88 | if (!ssh) |
| 89 | |
| 90 | return ( |
| 91 | <Tabs defaultValue=" |
| 92 | <TabsList className=" |
| 93 | <TabsTrigger value=" |
| 94 | <TabsTrigger value=" |
| 95 | </TabsList> |
| 96 | <TabsContent value=" |
| 97 | {http} |
| 98 | </TabsContent> |
| 99 | <TabsContent value=" |
| 100 | {ssh} |
| 101 | </TabsContent> |
| 102 | </Tabs> |
| 103 | ); |
| 104 | } |
| 105 | |
| 106 | export function CloneUrlField({ |
| 107 | const { copied, |
| 108 | |
| 109 | return ( |
| 110 | <InputGroup> |
| 111 | <InputGroupInput readOnly value |
| 112 | <InputGroupAddon align=" |
| 113 | <InputGroupButton |
| 114 | size="icon-xs" |
| 115 | aria-label="Copy clone URL" |
| 116 | onClick={copy} |
| 117 | > |
| 118 | {copied ? <Check |
| 119 | </InputGroupButton> |
| 120 | </InputGroupAddon> |
| 121 | </InputGroup> |
| 122 | ); |
| 123 | } |
| 124 | |
| 125 | /** Shell commands in one block, copied together. */ |
| 126 | export function CommandsField({ |
| 127 | const text = |
| 128 | const { copied, |
| 129 | |
| 130 | return ( |
| 131 | <div className="relative |
| 132 | <pre className="overflow-x-auto rounded-md border bg-muted/40 p-3 pr-10 text-xs leading-relaxed |
| 133 | <code>{text}</ |
| 134 | </pre> |
| 135 | <Button |
| 136 | variant="ghost" |
| 137 | size="icon-xs" |
| 138 | aria-label="Copy commands" |
| 139 | className="absolute top-2 right-2" |
| 140 | onClick={copy} |
| 141 | > |
| 142 | {copied ? <Check |
| 143 | </Button> |
| 144 | </div> |
| 145 | ); |
| 146 | } |