All files / src/apps/user/pages/settings Appearance.tsx

81.81% Statements 9/11
100% Branches 6/6
66.66% Functions 4/6
81.81% Lines 9/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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            1x           3x                           1x           1x 1x   1x                     3x                                       7x 7x                                                                        
import React from "react";
import SubPage from "@/components/page/SubPage/SubPage";
import { useTheme, ACCENTS, type ThemeMode } from "chainr-frontend-shared";
import { Check, Sun, Moon, MonitorCog } from "lucide-react";
import { SettingsTabs, SettingsSection } from "./SettingsTabs";
 
const ThemeButton: React.FC<{
  active: boolean;
  icon: React.ElementType;
  label: string;
  onClick: () => void;
}> = ({ active, icon: Icon, label, onClick }) => (
  <button
    onClick={onClick}
    className={`flex flex-1 flex-col items-center gap-2 px-5 py-4 rounded-xl border-2 transition-all text-sm font-medium ${
      active
        ? "border-gray-900 dark:border-gray-100 bg-gray-50 dark:bg-gray-700 text-gray-900 dark:text-gray-100"
        : "border-gray-200 dark:border-gray-600 bg-white dark:bg-gray-800 text-gray-500 dark:text-gray-400 hover:border-gray-400 dark:hover:border-gray-400"
    }`}
  >
    <Icon className="size-5" />
    {label}
  </button>
);
 
const THEME_OPTIONS: { mode: ThemeMode; icon: React.ElementType; label: string }[] =
  [
    { mode: "light", icon: Sun, label: "Light" },
    { mode: "dark", icon: Moon, label: "Dark" },
    { mode: "system", icon: MonitorCog, label: "System" },
  ];
 
const Appearance: React.FC = () => {
  const { mode, setMode, accent, setAccent } = useTheme();
 
  return (
    <SubPage title="Appearance" links={[<SettingsTabs key="tabs" active="appearance" />]}>
      <div className="max-w-xl space-y-6">
        {/* Theme */}
        <SettingsSection
          title="Theme"
          description="Choose how CHAIN-R looks to you. System follows your device."
        >
          <div className="px-5 py-4">
            <div className="flex gap-3">
              {THEME_OPTIONS.map(({ mode: m, icon, label }) => (
                <ThemeButton
                  key={m}
                  active={mode === m}
                  icon={icon}
                  label={label}
                  onClick={() => setMode(m)}
                />
              ))}
            </div>
          </div>
        </SettingsSection>
 
        {/* Accent colour */}
        <SettingsSection
          title="Accent Colour"
          description="The brand colour used for highlights, links, and controls."
        >
          <div className="px-5 py-4">
            <div className="flex flex-wrap gap-3">
              {ACCENTS.map((a) => {
                const selected = accent === a.id;
                return (
                  <button
                    key={a.id}
                    onClick={() => setAccent(a.id)}
                    aria-label={a.label}
                    aria-pressed={selected}
                    title={a.label}
                    className={`relative size-9 rounded-full transition-transform hover:scale-110 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 dark:focus-visible:ring-offset-gray-800 ${
                      selected ? "ring-2 ring-offset-2 dark:ring-offset-gray-800" : ""
                    }`}
                    style={
                      {
                        backgroundColor: a.color,
                        ["--tw-ring-color" as string]: a.color,
                      } as React.CSSProperties
                    }
                  >
                    {selected && (
                      <Check
                        className="absolute inset-0 m-auto size-4"
                        style={{ color: a.foreground }}
                      />
                    )}
                  </button>
                );
              })}
            </div>
          </div>
        </SettingsSection>
 
      </div>
    </SubPage>
  );
};
 
export default Appearance;