Updated README.md from a detailed OllaHub project description to the standard Next.js getting started template, likely to initialize or reset the project as a Next.js application.
28 lines
1.0 KiB
TypeScript
28 lines
1.0 KiB
TypeScript
"use client";
|
|
|
|
import { Moon, Sun } from "lucide-react";
|
|
import { useTheme } from "next-themes";
|
|
import { useEffect, useState } from "react";
|
|
|
|
export function ModeToggle() {
|
|
const { theme, setTheme } = useTheme();
|
|
const [mounted, setMounted] = useState(false);
|
|
useEffect(() => setMounted(true), []);
|
|
if (!mounted) return null;
|
|
const isDark =
|
|
theme === "dark" ||
|
|
(!theme &&
|
|
typeof window !== "undefined" &&
|
|
window.matchMedia("(prefers-color-scheme: dark)").matches);
|
|
return (
|
|
<button
|
|
aria-label="Alternar tema"
|
|
className="inline-flex h-9 items-center gap-2 rounded-md border border-[var(--border)] bg-[var(--surface)] px-3 text-sm transition-colors hover:bg-[color-mix(in_oklab,var(--surface),black_6%)] focus:outline-none focus-visible:ring-2 focus-visible:ring-[var(--accent)]"
|
|
onClick={() => setTheme(isDark ? "light" : "dark")}
|
|
>
|
|
{isDark ? <Sun className="h-4 w-4" /> : <Moon className="h-4 w-4" />}
|
|
<span className="hidden sm:inline">{isDark ? "Light" : "Dark"}</span>
|
|
</button>
|
|
);
|
|
}
|