Created
June 25, 2024 09:30
-
-
Save Kevin-free/d4f4df5a264ff888d202e228d748ef0f to your computer and use it in GitHub Desktop.
ThemeSelector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useContext, useCallback } from 'react'; | |
import { Sun, Moon } from 'lucide-react'; | |
import { ThemeContext } from '~/hooks'; | |
const Theme = ({ theme, onChange }: { theme: string; onChange: (value: string) => void }) => { | |
const themeIcons = { | |
system: <Sun />, | |
dark: <Moon color="white" />, | |
light: <Sun />, | |
}; | |
return ( | |
<div className="flex items-center justify-between"> | |
<div className="cursor-pointer" onClick={() => onChange(theme === 'dark' ? 'light' : 'dark')}> | |
{themeIcons[theme]} | |
</div> | |
</div> | |
); | |
}; | |
const ThemeSelector = () => { | |
const { theme, setTheme } = useContext(ThemeContext); | |
const changeTheme = useCallback( | |
(value: string) => { | |
setTheme(value); | |
}, | |
[setTheme], | |
); | |
return ( | |
<div className="flex flex-col items-center justify-center bg-white pt-6 dark:bg-gray-900 sm:pt-0"> | |
<div className="fixed bottom-0 left-0 m-4"> | |
<Theme theme={theme} onChange={changeTheme} /> | |
</div> | |
</div> | |
); | |
}; | |
export default ThemeSelector; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment