Skip to content

Commit d651117

Browse files
committed
Theme changing transition added.
1 parent 6ede310 commit d651117

4 files changed

Lines changed: 618 additions & 35 deletions

File tree

app/components/navbar.tsx

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useEffect, useState } from 'react';
44
import Link from 'next/link';
55
import { Menu, X, Activity, Moon, Sun } from 'lucide-react';
66
import { useGlowEffect } from '@/hooks/useGlowEffect';
7+
import { useThemeToggle } from './theme-switch';
78

89
function GithubMark() {
910
return (
@@ -28,31 +29,13 @@ const NAV_LINKS = [
2829

2930
export default function Navbar() {
3031
const [open, setOpen] = useState(false);
31-
const [mounted, setMounted] = useState(false);
32-
33-
const [isDark, setIsDark] = useState(() => {
34-
if (typeof window === 'undefined' || !window.localStorage) return true;
35-
return window.localStorage.getItem('theme') !== 'light';
36-
});
3732

3833
const { shellRef, shellVars, handleMouseEnter, handleMouseMove, handleMouseLeave } =
3934
useGlowEffect();
40-
41-
useEffect(() => {
42-
// eslint-disable-next-line react-hooks/set-state-in-effect
43-
setMounted(true);
44-
}, []);
45-
46-
useEffect(() => {
47-
document.documentElement.classList.toggle('dark', isDark);
48-
if (typeof window !== 'undefined' && window.localStorage) {
49-
window.localStorage.setItem('theme', isDark ? 'dark' : 'light');
50-
}
51-
}, [isDark]);
52-
53-
const toggleTheme = () => {
54-
setIsDark((prev) => !prev);
55-
};
35+
const { isDark, mounted, toggleTheme } = useThemeToggle({
36+
variant: 'circle',
37+
start: 'top-right',
38+
});
5639

5740
useEffect(() => {
5841
const mediaQuery = window.matchMedia('(min-width: 768px)');

0 commit comments

Comments
 (0)