Skip to content

Commit

Permalink
feat: add theme switcher
Browse files Browse the repository at this point in the history
  • Loading branch information
ToxicToast committed Jun 18, 2024
1 parent 43f3e59 commit 76235de
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useTheme } from '../../../hooks';
import { useCallback } from 'react';
import { ThemeToggleIcon } from './themetoggle/icon';

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

const switchTheme = useCallback(() => {
const newTheme = theme === 'light' ? 'dark' : 'light';
setTheme(newTheme);
}, [theme, setTheme]);

return (
<div>
<input
type="checkbox"
name="light-switch"
id="light-switch"
className="light-switch sr-only"
checked={theme === 'light'}
onChange={() => switchTheme()}
/>
<label
className="flex items-center justify-center cursor-pointer w-8 h-8 bg-slate-100 hover:bg-slate-200 dark:bg-slate-700 dark:hover:bg-slate-600/80 rounded-full"
htmlFor="light-switch"
>
<ThemeToggleIcon theme={theme} />
<span className="sr-only">Switch to light / dark version</span>
</label>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Show } from '../../../../widgets';
import { MoonIcon, SunIcon } from '@radix-ui/react-icons';

interface Props {
theme: string;
}

export function ThemeToggleIcon(props: Props) {
const { theme } = props;

return (
<>
<Show show={theme === 'light'}>
<MoonIcon />
</Show>
<Show show={theme === 'dark'}>
<SunIcon />
</Show>
</>
);
}

0 comments on commit 76235de

Please sign in to comment.