Last active
August 19, 2021 23:05
-
-
Save seanmodd/8b333ece0f6b4851ad517aa423431786 to your computer and use it in GitHub Desktop.
DarkModeSwitch for Chakra UI
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 { useColorMode, IconButton } from '@chakra-ui/core'; | |
import { | |
useColorMode, | |
IconButton, | |
Button, | |
HStack, | |
Flex, | |
Stack, | |
Box, | |
} from '@chakra-ui/react'; | |
import { MoonIcon, SunIcon } from '@chakra-ui/icons'; | |
const DarkModeSwitch = ({ children }) => { | |
const { colorMode, toggleColorMode } = useColorMode(); | |
const iconColor = { | |
light: 'black', | |
dark: 'white', | |
}; | |
const bgColor = { | |
light: 'gray.300', | |
dark: 'black', | |
}; | |
return ( | |
<> | |
<HStack align="center" justify="flex" px={80}> | |
<IconButton | |
aria-label="Toggle Dark Switch" | |
icon={colorMode === 'dark' ? <SunIcon /> : <MoonIcon />} | |
onClick={toggleColorMode} | |
color={iconColor[colorMode]} | |
// bg={bgColor[colorMode]} | |
> | |
{children} | |
</IconButton> | |
</HStack> | |
</> | |
); | |
}; | |
export default DarkModeSwitch; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment