Skip to content

Instantly share code, notes, and snippets.

@devpikachu
Created November 9, 2021 21:32
Show Gist options
  • Save devpikachu/04224349628612e8a5d71abf5261338b to your computer and use it in GitHub Desktop.
Save devpikachu/04224349628612e8a5d71abf5261338b to your computer and use it in GitHub Desktop.
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