Skip to content

Commit

Permalink
theme toggle improved
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspal007 committed Oct 17, 2024
1 parent f39812f commit c714358
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default function Header() {
<Image src="/convex.svg" alt="Convex" width={24} height={24} />
</Link>

<div className="flex hover:bg-slate-500 rounded-md px-1">
<div className="">
<ThemeToggle />
</div>
{!isAuthenticated ? (
Expand Down
17 changes: 15 additions & 2 deletions components/ThemeToggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,26 @@

import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
import { DesktopIcon, MoonIcon, SunIcon } from "@radix-ui/react-icons";
import { useState, useEffect } from "react";
import { useTheme } from "next-themes";

export function ThemeToggle() {
const { theme, setTheme } = useTheme();
const darkMode = useTheme().systemTheme;

return (
<ToggleGroup type="single" size="sm" onValueChange={setTheme} value={theme} className="">
{theme == "light" ? (
<ToggleGroup
type="single"
size="sm"
value={theme}
onValueChange={(e) => {
console.log(`theme: ${theme}`);
console.log(`darkMode: ${darkMode}`);
setTheme(e);
}}
className={`${"flex px-1 py-1 rounded-md"} ${theme == "light" || (theme=="system" && darkMode=="light") ? "bg-blue-200" : "bg-slate-700"}`}
>
{theme == "light" || (theme=="system"&& darkMode=="light") ? (
<ToggleGroupItem value="dark" aria-label="Dark">
<MoonIcon />
</ToggleGroupItem>
Expand Down

0 comments on commit c714358

Please sign in to comment.