/** * ThemeSettings — theme picker card for the Settings page * ======================================================== * Shows: * • Mode toggle (light / dark / system) * • Grid of registered themes with preview dots * • "Reset to default" option */ import React from "react"; import toast from "react-hot-toast"; import { Card, CardBody } from "@/shadcn-bridge/heroui/card"; import { Button } from "@/shadcn-bridge/heroui/button"; import { useThemeContext } from "@/themes/context"; import type { ThemeMode } from "@/themes/registry"; // ─── Constants ────────────────────────────────────────────────────────────── const MODE_OPTIONS: Array<{ value: ThemeMode; label: string; icon: string }> = [ { value: "light", label: "亮色", icon: "☀️" }, { value: "dark", label: "暗色", icon: "🌙" }, { value: "system", label: "跟随系统", icon: "🖥️" }, ]; // ─── Component ────────────────────────────────────────────────────────────── export const ThemeSettings: React.FC = () => { const { themes, activeThemeId, mode, effectiveMode, switchTheme, resetTheme, setMode, } = useThemeContext(); const handleModeChange = (m: ThemeMode) => { setMode(m); const label = m === "light" ? "亮色" : m === "dark" ? "暗色" : "跟随系统"; toast.success(`已切换为${label}模式`); }; const handleThemeSelect = (id: string) => { switchTheme(id); const theme = themes.find((t) => t.id === id); toast.success(`已切换主题「${theme?.name ?? id}」`); }; const handleReset = () => { resetTheme(); toast.success("已恢复默认主题"); }; return (

主题设置

{/* ── Mode toggle ────────────────────────────────────── */}

外观模式

{MODE_OPTIONS.map((opt) => ( ))}
{/* ── Theme grid ─────────────────────────────────────── */}

选择主题 共 {themes.length} 个可用主题

{themes.map((theme) => { const isActive = activeThemeId === theme.id; // Pick the right token set for preview const previewTokens = effectiveMode === "dark" && theme.tokens?.dark ? theme.tokens.dark : theme.tokens?.light; const primary = previewTokens?.["--primary"] ?? "#2563eb"; const secondary = previewTokens?.["--secondary"] ?? "#6366f1"; const success = previewTokens?.["--success"] ?? "#16a34a"; const danger = previewTokens?.["--danger"] ?? "#dc2626"; const bg = previewTokens?.["--background"] ?? "#ffffff"; return ( ); })}
{/* ── Reset ──────────────────────────────────────────── */} {activeThemeId && activeThemeId !== "default" && (
)}
); };