Skip to content

Commit

Permalink
fix theme selector
Browse files Browse the repository at this point in the history
  • Loading branch information
tytremblay committed Jan 19, 2025
1 parent 560f03d commit afe3b14
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
10 changes: 8 additions & 2 deletions src/components/Sections/ConfigSection/ThemeSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { useTheme } from '@/components/ThemeProvider';
import { Theme, useTheme } from '@/components/ThemeProvider';
import { ToggleGroup, ToggleGroupItem } from '@/components/ui/toggle-group';
import { Computer, Moon, Sun } from 'lucide-react';

export function ThemeSelector() {
const { theme, setTheme } = useTheme();

const handleValueChange = (value: Theme) => {
if (value === 'light' || value === 'dark' || value === 'system') {
setTheme(value);
}
};

return (
<ToggleGroup type="single" value={theme} onValueChange={setTheme}>
<ToggleGroup type="single" value={theme} onValueChange={handleValueChange}>
<ToggleGroupItem value="light" aria-label="light theme">
<Sun className="h-4 w-4" />
</ToggleGroupItem>
Expand Down
12 changes: 4 additions & 8 deletions src/components/ThemeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useQRScoutState } from '@/store/store';
import { setColorScheme } from '@/util/theme';
import { createContext, useContext, useEffect, useState } from 'react';

type Theme = 'dark' | 'light' | 'system' | '';
export type Theme = 'dark' | 'light' | 'system';

type ThemeProviderProps = {
children: React.ReactNode;
Expand Down Expand Up @@ -57,13 +57,9 @@ export function ThemeProvider({
root.classList.add(systemTheme);
return;
}

if(theme !== '') {
setResolvedTheme(theme);
root.classList.add(theme);
}



setResolvedTheme(theme);
root.classList.add(theme);
}, [theme]);

const value = {
Expand Down

0 comments on commit afe3b14

Please sign in to comment.