Spaces:
Running
Running
File size: 9,968 Bytes
f680c3f 946780b f680c3f a8d792f f680c3f 946780b a8d792f f680c3f a8d792f f680c3f a8d792f f680c3f a8d792f f680c3f a8d792f f680c3f a8d792f f680c3f a8d792f f680c3f a8d792f f680c3f a8d792f 946780b f680c3f a8d792f f680c3f a8d792f f680c3f a8d792f 946780b a8d792f 946780b a8d792f 946780b a8d792f f680c3f a8d792f 946780b a8d792f 946780b a8d792f 946780b a8d792f f680c3f a8d792f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
"use client";
import { useState } from "react";
import {
Copy,
Package,
Clock,
Check,
Terminal,
Command,
Server,
Github,
ExternalLink,
} from "lucide-react";
import { Button } from "@/components/ui/button";
import { Card } from "@/components/ui/card";
import { Badge } from "@/components/ui/badge";
import HudCorners from "@/components/hud-corners";
import { cn } from "@/lib/utils";
type PackageManager = "npm" | "yarn" | "pnpm" | "bun";
type CLIInstallMode = "npm" | "npx";
interface PackageInstallerProps {
packageName: string;
disabled?: boolean;
}
function PackageInstaller({
packageName,
disabled = false,
}: PackageInstallerProps) {
const [selectedPM, setSelectedPM] = useState<PackageManager>("pnpm");
const [copied, setCopied] = useState(false);
const packageManagers: {
value: PackageManager;
label: string;
command: string;
}[] = [
{ value: "pnpm", label: "pnpm", command: `pnpm add ${packageName}` },
{ value: "npm", label: "npm", command: `npm i ${packageName}` },
{ value: "yarn", label: "yarn", command: `yarn add ${packageName}` },
];
const copyToClipboard = async (text: string) => {
try {
await navigator.clipboard.writeText(text);
setCopied(true);
setTimeout(() => setCopied(false), 2000);
} catch (err) {
console.error("Failed to copy:", err);
}
};
const currentCommand =
packageManagers.find((pm) => pm.value === selectedPM)?.command || "";
return (
<div className="max-w-md">
<div className="space-y-3">
<div className="flex gap-1 w-fit">
{packageManagers.map((pm) => (
<Button
key={pm.value}
variant="ghost"
size="sm"
onClick={() => setSelectedPM(pm.value)}
disabled={disabled}
className={cn(
"font-mono text-xs px-3 min-w-[60px] h-8 border transition-colors",
selectedPM === pm.value
? "bg-foreground text-background border-foreground"
: "bg-transparent border-input hover:bg-accent hover:text-accent-foreground"
)}
>
{pm.label}
</Button>
))}
</div>
<div className="relative">
<div
className={cn(
"border rounded-md p-3 font-mono text-sm transition-colors",
disabled
? "bg-muted/60 dark:bg-black/20 border-dashed border-muted/40 dark:border-muted/20 text-muted-foreground/70 dark:text-muted-foreground/50"
: "bg-muted/60 dark:bg-black/40 border-border dark:border-white/10 text-foreground dark:text-primary"
)}
>
{currentCommand}
</div>
<Button
variant="outline"
size="sm"
onClick={() => copyToClipboard(currentCommand)}
disabled={disabled}
className="absolute right-2 top-2 h-7 w-7 p-0 transition-all"
>
{disabled ? (
<Clock className="w-3 h-3" />
) : copied ? (
<Check className="w-3 h-3" />
) : (
<Copy className="w-3 h-3" />
)}
</Button>
</div>
</div>
</div>
);
}
function CLIInstaller() {
const [selectedMode, setSelectedMode] = useState<CLIInstallMode>("npx");
const [copied, setCopied] = useState(false);
const installModes: {
value: CLIInstallMode;
label: string;
command: string;
}[] = [
{ value: "npx", label: "npx", command: "npx lerobot@latest" },
{ value: "npm", label: "npm", command: "npm install -g lerobot" },
];
const copyToClipboard = async (text: string) => {
try {
await navigator.clipboard.writeText(text);
setCopied(true);
setTimeout(() => setCopied(false), 2000);
} catch (err) {
console.error("Failed to copy:", err);
}
};
const currentCommand =
installModes.find((mode) => mode.value === selectedMode)?.command || "";
return (
<div className="max-w-md">
<div className="space-y-3">
<div className="flex gap-1 w-fit">
{installModes.map((mode) => (
<Button
key={mode.value}
variant="ghost"
size="sm"
onClick={() => setSelectedMode(mode.value)}
className={cn(
"font-mono text-xs px-3 min-w-[60px] h-8 border transition-colors",
selectedMode === mode.value
? "bg-foreground text-background border-foreground"
: "bg-transparent border-input hover:bg-accent hover:text-accent-foreground"
)}
>
{mode.label}
</Button>
))}
</div>
<div className="relative">
<div className="border rounded-md p-3 font-mono text-sm bg-muted/60 dark:bg-black/40 border-border dark:border-white/10 text-foreground dark:text-primary">
{currentCommand}
</div>
<Button
variant="outline"
size="sm"
onClick={() => copyToClipboard(currentCommand)}
className="absolute right-2 top-2 h-7 w-7 p-0 transition-all"
>
{copied ? (
<Check className="w-3 h-3" />
) : (
<Copy className="w-3 h-3" />
)}
</Button>
</div>
</div>
</div>
);
}
export function SetupCards() {
return (
<div className="grid md:grid-cols-2 lg:grid-cols-3 gap-6 mb-8">
{/* Web Installation Card */}
{/* HudCorners creates 4 absolutely positioned corner elements with primary color borders */}
<HudCorners color="primary" size="sm" layer="front">
<Card className="h-full border-dashed border border-muted/30 relative">
{/* GitHub Link */}
<a
href="https://github.com/timpietrusky/lerobot.js/tree/main/packages/web"
target="_blank"
rel="noopener noreferrer"
className="absolute top-6 right-6 p-2 rounded-lg hover:bg-primary/10 transition-colors group"
title="View @lerobot/web on GitHub"
>
<Github className="w-4 h-4 text-muted-foreground group-hover:text-primary transition-colors" />
</a>
{/* This div contains the card content and sits above the corner elements due to relative positioning */}
<div className="p-6">
<div className="flex items-center gap-3 mb-4">
<div className="w-12 h-12 bg-primary/20 rounded-lg flex items-center justify-center">
<Package className="w-6 h-6 text-primary" />
</div>
<div>
<h3 className="text-xl font-bold text-primary font-mono tracking-wider uppercase">
web
</h3>
<p className="text-sm text-muted-foreground font-mono">
run LeRobot.js in the browser
</p>
</div>
</div>
<PackageInstaller packageName="@lerobot/web" />
</div>
</Card>
</HudCorners>
{/* Node.js Card - Active */}
<HudCorners color="primary" size="sm" layer="front">
<Card className="h-full border-dashed border border-muted/30 relative">
{/* GitHub Link */}
<a
href="https://github.com/timpietrusky/lerobot.js/tree/main/packages/node"
target="_blank"
rel="noopener noreferrer"
className="absolute top-6 right-6 p-2 rounded-lg hover:bg-primary/10 transition-colors group"
title="View @lerobot/node on GitHub"
>
<Github className="w-4 h-4 text-muted-foreground group-hover:text-primary transition-colors" />
</a>
<div className="p-6">
<div className="flex items-center gap-3 mb-4">
<div className="w-12 h-12 bg-primary/20 rounded-lg flex items-center justify-center">
<Server className="w-6 h-6 text-primary" />
</div>
<div>
<h3 className="text-xl font-bold text-primary font-mono tracking-wider uppercase">
node
</h3>
<p className="text-sm text-muted-foreground font-mono">
run LeRobot.js on the server
</p>
</div>
</div>
<PackageInstaller packageName="@lerobot/node" />
</div>
</Card>
</HudCorners>
{/* CLI Card - Active */}
<HudCorners color="primary" size="sm" layer="front">
<Card className="h-full border-dashed border border-muted/30 relative">
{/* GitHub Link */}
<a
href="https://github.com/timpietrusky/lerobot.js/tree/main/packages/cli"
target="_blank"
rel="noopener noreferrer"
className="absolute top-6 right-6 p-2 rounded-lg hover:bg-primary/10 transition-colors group"
title="View lerobot CLI on GitHub"
>
<Github className="w-4 h-4 text-muted-foreground group-hover:text-primary transition-colors" />
</a>
<div className="p-6">
<div className="flex items-center gap-3 mb-4">
<div className="w-12 h-12 bg-primary/20 rounded-lg flex items-center justify-center">
<Terminal className="w-6 h-6 text-primary" />
</div>
<div>
<h3 className="text-xl font-bold text-primary font-mono tracking-wider uppercase">
CLI
</h3>
<p className="text-sm text-muted-foreground font-mono">
run LeRobot.js in the CLI
</p>
</div>
</div>
<CLIInstaller />
</div>
</Card>
</HudCorners>
</div>
);
}
|