-
Notifications
You must be signed in to change notification settings - Fork 0
Add Navbar and ThemeProvider components with theme toggle functionality #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| "use client"; | ||
|
|
||
| import { Home, ImageUp } from "lucide-react"; | ||
| import Link from "next/link"; | ||
| import { usePathname } from "next/navigation"; | ||
| import ThemeToggle from "./ThemeToggle"; | ||
|
|
||
| export default function Navbar() { | ||
| const pathname = usePathname(); | ||
|
|
||
| const links = [ | ||
| { name: "Home", href: "/", icon: Home }, | ||
| { name: "Generate", href: "/generate", icon: ImageUp }, | ||
| ]; | ||
|
Comment on lines
+11
to
+14
|
||
|
|
||
| return ( | ||
| <nav className="sticky top-0 z-50 w-full border-b border-slate-200 dark:border-neutral-700 bg-white/95 dark:bg-neutral-900/95 backdrop-blur-sm"> | ||
| <div className="flex h-16 items-center px-4 sm:px-6"> | ||
| <div className="flex-shrink-0"> | ||
| <Link | ||
| href="/" | ||
| className="text-lg font-bold text-slate-800 dark:text-neutral-100" | ||
| > | ||
| SVG{" "} | ||
| <span className="text-emerald-600 dark:text-violet-500"> | ||
| From Img | ||
| </span> | ||
| </Link> | ||
| </div> | ||
|
|
||
| <div className="hidden md:flex items-center justify-center flex-1"> | ||
| <div className="flex space-x-1"> | ||
| {links.map((link) => ( | ||
| <Link | ||
| key={link.href} | ||
| href={link.href} | ||
| className={`flex h-10 items-center px-3 py-2 text-sm font-medium rounded-md | ||
| ${ | ||
| pathname === link.href | ||
| ? "bg-emerald-100 text-emerald-700 dark:bg-violet-700/30 dark:text-violet-300" | ||
| : "text-slate-500 hover:text-emerald-600 hover:bg-emerald-50 dark:text-neutral-400 dark:hover:text-violet-400 dark:hover:bg-violet-700/20" | ||
| }`} | ||
| > | ||
| {link.name} | ||
| </Link> | ||
| ))} | ||
| </div> | ||
| </div> | ||
|
|
||
| <div className="flex items-center space-x-2 ml-auto"> | ||
| <ThemeToggle /> | ||
| </div> | ||
| </div> | ||
| </nav> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| "use client"; | ||
|
|
||
| import * as React from "react"; | ||
| import { ThemeProvider as NextThemesProvider } from "next-themes"; | ||
|
|
||
| export function ThemeProvider({ | ||
| children, | ||
| ...props | ||
| }: React.ComponentProps<typeof NextThemesProvider>) { | ||
| return <NextThemesProvider {...props}>{children}</NextThemesProvider>; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| "use client"; | ||
|
|
||
| import { Moon, Sun } from "lucide-react"; | ||
| import { useTheme } from "next-themes"; | ||
| import { useEffect } from "react"; | ||
|
|
||
| export default function ThemeToggle() { | ||
| const { theme, setTheme } = useTheme(); | ||
|
|
||
| useEffect(() => { | ||
| const handleKeyPress = (e: KeyboardEvent) => { | ||
| if ((e.ctrlKey || e.metaKey) && e.key === "k") { | ||
| e.preventDefault(); | ||
| setTheme(theme === "dark" ? "light" : "dark"); | ||
| } | ||
| }; | ||
|
|
||
| window.addEventListener("keydown", handleKeyPress); | ||
| return () => window.removeEventListener("keydown", handleKeyPress); | ||
| }, [theme, setTheme]); | ||
|
|
||
| return ( | ||
| <button | ||
| onClick={() => setTheme(theme === "dark" ? "light" : "dark")} | ||
| className="shadow-sm cursor-pointer p-2 rounded-full border border-emerald-500 dark:border-purple-500 transition-all duration-300 ease-in-out hover:bg-emerald-100 dark:hover:bg-violet-700/30" | ||
| title="Toggle theme (Ctrl+K)" | ||
| > | ||
| {theme === "dark" ? ( | ||
| <Sun className="h-5 w-5 text-emerald-600 dark:text-violet-500 ease-in-out" /> | ||
| ) : ( | ||
| <Moon className="h-5 w-5 text-emerald-600 dark:text-violet-500 ease-in-out" /> | ||
| )} | ||
| </button> | ||
| ); | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CSS variable '--font-space-grotesk' is defined but not used in the className. Consider either using the variable or removing it to maintain consistency.