-
-
Save devpikachu/04224349628612e8a5d71abf5261338b to your computer and use it in GitHub Desktop.
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 { IconContext } from "react-icons"; | |
import { BsMoonFill, BsSunFill } from "react-icons/bs"; | |
import cn from "classnames"; | |
import useDarkMode from "use-dark-mode"; | |
import { useTheme } from "@nextui-org/react"; | |
export const ThemeToggle = ({ className }) => { | |
const darkMode = useDarkMode(); | |
const theme = useTheme(); | |
const isDark = theme.type === "dark"; | |
return ( | |
<span | |
className={cn(className, "theme-selector")} | |
onClick={darkMode.toggle}> | |
<IconContext.Provider value={{size: "1.5em"}}> | |
{isDark? ( | |
<BsSunFill/> | |
) : ( | |
<BsMoonFill/> | |
)} | |
</IconContext.Provider> | |
<style jsx> | |
{` | |
.theme-selector { | |
display: flex; | |
width: auto; | |
height: auto; | |
cursor: pointer; | |
justify-content: center; | |
align-items: center; | |
} | |
`} | |
</style> | |
</span> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment