|
Last change
on this file since b8093a0 was b8093a0, checked in by imbrsk <boris696boris@…>, 3 days ago |
|
Merge iknow-remaster into frontend/
Bring the Next.js frontend into this repository as a monorepo subdirectory,
preserving its full commit history via a subtree merge.
|
-
Property mode
set to
100644
|
|
File size:
842 bytes
|
| Rev | Line | |
|---|
| [ba52069] | 1 | "use client";
|
|---|
| 2 |
|
|---|
| 3 | import { Moon, Sun } from "lucide-react";
|
|---|
| 4 | import { useTheme } from "next-themes";
|
|---|
| 5 | import { useEffect, useState } from "react";
|
|---|
| 6 |
|
|---|
| 7 | export function ThemeToggle() {
|
|---|
| 8 | const [mounted, setMounted] = useState(false);
|
|---|
| 9 | const { theme, setTheme } = useTheme();
|
|---|
| 10 |
|
|---|
| 11 | // Avoid hydration mismatch
|
|---|
| 12 | useEffect(() => {
|
|---|
| 13 | setMounted(true);
|
|---|
| 14 | }, []);
|
|---|
| 15 |
|
|---|
| 16 | if (!mounted) {
|
|---|
| 17 | return (
|
|---|
| 18 | <button className="p-2 rounded-md hover:bg-accent">
|
|---|
| 19 | <Sun className="h-5 w-5" />
|
|---|
| 20 | </button>
|
|---|
| 21 | );
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | return (
|
|---|
| 25 | <button
|
|---|
| 26 | onClick={() => setTheme(theme === "dark" ? "light" : "dark")}
|
|---|
| 27 | className="p-2 rounded-md hover:bg-accent transition-colors"
|
|---|
| 28 | aria-label="Toggle theme"
|
|---|
| 29 | >
|
|---|
| 30 | {theme === "dark" ? (
|
|---|
| 31 | <Sun className="h-5 w-5" />
|
|---|
| 32 | ) : (
|
|---|
| 33 | <Moon className="h-5 w-5" />
|
|---|
| 34 | )}
|
|---|
| 35 | </button>
|
|---|
| 36 | );
|
|---|
| 37 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.