Spaces:
Running
Running
Download src/components/layout/ConnectPanel.tsx from evalstate/mcp-webcam: direct link, hf CLI and curl.
- Browser
- Download file 3.96 kB
-
https://huggingface.co/spaces/evalstate/mcp-webcam/resolve/main/src/components/layout/ConnectPanel.tsx
- Command line
-
hf download hf://spaces/evalstate/mcp-webcam/src/components/layout/ConnectPanel.tsx
-
curl -L -o ConnectPanel.tsx https://huggingface.co/spaces/evalstate/mcp-webcam/resolve/main/src/components/layout/ConnectPanel.tsx
3.96 kB
| import { useState } from 'react'; | |
| import { Check, Copy, Terminal, X } from 'lucide-react'; | |
| import { toast } from 'sonner'; | |
| import { Button } from '@/components/ui/button'; | |
| import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; | |
| import { buildConnectSnippets, type ConnectSnippet } from '@/lib/commands'; | |
| export function ConnectPanel({ | |
| mcpUrl, | |
| defaultTab = 'uvx', | |
| onClose, | |
| }: { | |
| mcpUrl: string; | |
| defaultTab?: ConnectSnippet['id']; | |
| onClose: () => void; | |
| }) { | |
| const snippets = buildConnectSnippets(mcpUrl); | |
| const [activeTab, setActiveTab] = useState<string>(defaultTab); | |
| const [copiedId, setCopiedId] = useState<string | null>(null); | |
| const copyText = async (id: string, text: string, label: string) => { | |
| try { | |
| await navigator.clipboard.writeText(text); | |
| setCopiedId(id); | |
| toast.success(`Copied ${label}`); | |
| window.setTimeout(() => setCopiedId((cur) => (cur === id ? null : cur)), 1800); | |
| } catch { | |
| toast.error('Clipboard copy failed'); | |
| } | |
| }; | |
| return ( | |
| <section className="border-b border-line bg-panel/90"> | |
| <div className="mx-auto max-w-[1440px] px-4 py-3.5"> | |
| <div className="flex flex-wrap items-center justify-between gap-2 pb-3"> | |
| <div className="flex items-center gap-2"> | |
| <Terminal className="h-3.5 w-3.5 text-push" /> | |
| <span className="text-xs font-semibold uppercase tracking-wider text-muted"> | |
| Connect an MCP Client | |
| </span> | |
| </div> | |
| <div className="flex flex-1 items-center justify-end gap-2 min-w-[240px]"> | |
| <div className="flex max-w-md flex-1 items-center justify-between gap-2 rounded-lg border border-line bg-panel-2/80 px-2.5 py-1"> | |
| <span className="truncate font-mono text-[11px] text-fg">{mcpUrl}</span> | |
| <Button | |
| variant="ghost" | |
| size="sm" | |
| className="h-6 px-2 text-[11px]" | |
| onClick={() => void copyText('mcp-url', mcpUrl, 'MCP URL')} | |
| > | |
| {copiedId === 'mcp-url' ? ( | |
| <Check className="h-3 w-3 text-push" /> | |
| ) : ( | |
| <Copy className="h-3 w-3" /> | |
| )} | |
| <span>Copy URL</span> | |
| </Button> | |
| </div> | |
| <Button variant="ghost" size="icon-sm" onClick={onClose} aria-label="Close connect panel"> | |
| <X className="h-3.5 w-3.5" /> | |
| </Button> | |
| </div> | |
| </div> | |
| <Tabs value={activeTab} onValueChange={setActiveTab}> | |
| <TabsList className="mb-2.5 flex w-full flex-wrap justify-start"> | |
| {snippets.map((s) => ( | |
| <TabsTrigger key={s.id} value={s.id}> | |
| {s.label} | |
| </TabsTrigger> | |
| ))} | |
| </TabsList> | |
| {snippets.map((s) => ( | |
| <TabsContent key={s.id} value={s.id}> | |
| <div className="relative rounded-lg border border-line bg-bg/85 p-3"> | |
| <div className="mb-2 flex items-center justify-between gap-2"> | |
| <p className="text-[11px] text-muted">{s.description}</p> | |
| <Button | |
| variant="secondary" | |
| size="sm" | |
| className="h-6.5 shrink-0" | |
| onClick={() => void copyText(s.id, s.code, s.label)} | |
| > | |
| {copiedId === s.id ? ( | |
| <Check className="h-3 w-3 text-push" /> | |
| ) : ( | |
| <Copy className="h-3 w-3" /> | |
| )} | |
| <span>Copy</span> | |
| </Button> | |
| </div> | |
| <pre className="overflow-x-auto font-mono text-[11.5px] leading-relaxed text-fg"> | |
| <code>{s.code}</code> | |
| </pre> | |
| </div> | |
| </TabsContent> | |
| ))} | |
| </Tabs> | |
| </div> | |
| </section> | |
| ); | |
| } | |