Skip to content

Instantly share code, notes, and snippets.

@seanmodd
Last active August 19, 2021 23:05
Show Gist options
  • Save seanmodd/8b333ece0f6b4851ad517aa423431786 to your computer and use it in GitHub Desktop.
Save seanmodd/8b333ece0f6b4851ad517aa423431786 to your computer and use it in GitHub Desktop.
DarkModeSwitch for Chakra UI
// 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