返回 CodeWhale
hero-install.tsx
根目录 / web / components / hero-install.tsx
1 "use client";
2
3 import { useState } from "react";
4 import { INSTALL_COMMANDS, INSTALL_COPY } from "@/lib/content/install";
5 import { pickText, pickTextLocale } from "@/lib/i18n/dictionaries";
6 import { InstallCodeBlock } from "./install-code-block";
7
8 /**
9 * The hero's copyable install plate: one segmented choice between the
10 * checked shell installer (macOS and Linux), winget on Windows, npm, and Cargo,
11 * above the same copy block the install page uses. The option
12 * labels are code-owned proper nouns; only the group's accessible name is
13 * translated.
14 */
15 const OPTIONS = [
16 { id: "shell", label: "macOS · Linux", cmd: INSTALL_COMMANDS.shell },
17 { id: "windows", label: "Windows", cmd: INSTALL_COMMANDS.windows },
18 { id: "npm", label: "npm", cmd: INSTALL_COMMANDS.npm },
19 { id: "cargo", label: "Cargo", cmd: INSTALL_COMMANDS.cargo },
20 ] as const;
21
22 export function HeroInstall({
23 locale,
24 ariaLabel,
25 copyLabel,
26 copiedLabel,
27 }: {
28 locale: string;
29 ariaLabel: string;
30 copyLabel: string;
31 copiedLabel: string;
32 }) {
33 const [selected, setSelected] = useState<(typeof OPTIONS)[number]["id"]>("shell");
34 const option = OPTIONS.find((o) => o.id === selected) ?? OPTIONS[0];
35 const note = selected === "windows" ? INSTALL_COPY.windowsNote : selected === "cargo" ? INSTALL_COPY.cargoNote : null;
36
37 return (
38 <div className="hero-install plate">
39 <div className="segmented" role="group" aria-label={ariaLabel}>
40 {OPTIONS.map((o) => (
41 <button
42 key={o.id}
43 type="button"
44 onClick={() => setSelected(o.id)}
45 aria-pressed={o.id === selected}
46 >
47 {o.label}
48 </button>
49 ))}
50 </div>
51 <InstallCodeBlock key={option.id} installIntent cmd={option.cmd} copyLabel={copyLabel} copiedLabel={copiedLabel} />
52 {note ? <p className="install-head-note" lang={pickTextLocale(locale)}>{pickText(note, locale)}</p> : null}
53 </div>
54 );
55 }
56
56 lines Plain Text