aboutsummaryrefslogtreecommitdiff
path: root/src/app/components/themeSwitcher.jsx
blob: 995dbbf8868a4bdff960c14374d8fed8602ff0c0 (plain) (blame)
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
// app/components/ThemeSwitcher.tsx
"use client";

import { useTheme } from "next-themes";
import { useEffect, useState } from "react";

import React from "react";
import { Switch } from "@nextui-org/react";
import { SunIcon } from "./sunIcon";
import { MoonIcon } from "./moonIcon";

export function ThemeSwitcher() {
	const [mounted, setMounted] = useState(false);
	const { theme, setTheme } = useTheme();

	useEffect(() => {
		setMounted(true);
	}, []);

	if (!mounted) return null;

	return (
		<Switch
			defaultSelected
			size="sm"
			color="secondary"
			thumbIcon={({ isSelected, className }) =>
				isSelected ? (
					<SunIcon className={className} />
				) : (
					<MoonIcon className={className} />
				)
			}
			onClick={() => {
				if (theme === "light") {
					setTheme("dark");
				} else {
					setTheme("light");
				}
			}}
		></Switch>
	);
}