Skip to content

Commit 7f8351b

Browse files
committed
dark mode enabled
1 parent c4a0fb8 commit 7f8351b

File tree

1 file changed

+50
-13
lines changed

1 file changed

+50
-13
lines changed

src/components/Navbar.tsx

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,78 @@
1-
import React from 'react';
2-
import { Link, useNavigate } from 'react-router-dom';
3-
import { useAuth } from '../utils/auth';
4-
import { logout } from '../utils/firebase';
5-
import { Button } from '@/components/ui/button';
1+
import { useEffect, useState } from "react";
2+
import { Link, useNavigate } from "react-router-dom";
3+
import { useAuth } from "../utils/auth";
4+
import { logout } from "../utils/firebase";
5+
import { Button } from "@/components/ui/button";
6+
import { Moon, Sun } from "lucide-react";
67
import {
78
DropdownMenu,
89
DropdownMenuContent,
910
DropdownMenuItem,
1011
DropdownMenuLabel,
1112
DropdownMenuSeparator,
1213
DropdownMenuTrigger,
13-
} from "@/components/ui/dropdown-menu"
14-
import { Avatar, AvatarImage, AvatarFallback } from "@/components/ui/avatar"
14+
} from "@/components/ui/dropdown-menu";
15+
import { Avatar, AvatarImage, AvatarFallback } from "@/components/ui/avatar";
1516

1617
const Navbar: React.FC = () => {
1718
const { currentUser } = useAuth();
1819
const navigate = useNavigate();
1920

2021
const handleLogout = async () => {
2122
await logout();
22-
navigate('/login');
23+
navigate("/login");
2324
};
25+
const [isDarkMode, setIsDarkMode] = useState(false);
26+
const toggleDarkMode = () => {
27+
setIsDarkMode(!isDarkMode);
28+
document.documentElement.classList.toggle("dark");
29+
};
30+
useEffect(() => {
31+
if (
32+
window.matchMedia &&
33+
window.matchMedia("(prefers-color-scheme: dark)").matches
34+
) {
35+
setIsDarkMode(true);
36+
document.documentElement.classList.add("dark");
37+
}
38+
}, []);
2439

2540
return (
2641
<div className="bg-background border-b">
2742
<div className="container flex h-16 items-center justify-between py-4">
28-
<Link to="/" className="font-bold text-2xl">
29-
PurePath
30-
</Link>
43+
<Link to="/" className="flex items-center space-x-2">
44+
<span className="font-bold text-xl tracking-tight text-primary transition-opacity duration-200">
45+
Pure<span className="text-foreground">Path</span>
46+
</span>
47+
</Link>
48+
3149
<nav>
50+
<Button
51+
variant="ghost"
52+
size="icon"
53+
onClick={toggleDarkMode}
54+
className="ml-4"
55+
aria-label="Toggle dark mode"
56+
>
57+
{isDarkMode ? (
58+
<Sun className="h-5 w-5 text-yellow-400" />
59+
) : (
60+
<Moon className="h-5 w-5" />
61+
)}
62+
</Button>
63+
3264
{currentUser ? (
3365
<DropdownMenu>
3466
<DropdownMenuTrigger asChild>
35-
<Button variant="ghost" className="relative h-8 w-8 rounded-full">
67+
<Button
68+
variant="ghost"
69+
className="relative h-8 w-8 rounded-full"
70+
>
3671
<Avatar>
3772
<AvatarImage src="/placeholder.svg" alt="User" />
38-
<AvatarFallback>{currentUser.email?.charAt(0).toUpperCase()}</AvatarFallback>
73+
<AvatarFallback>
74+
{currentUser.email?.charAt(0).toUpperCase()}
75+
</AvatarFallback>
3976
</Avatar>
4077
</Button>
4178
</DropdownMenuTrigger>

0 commit comments

Comments
 (0)