I am using the "dark mode" feature provided by the Chakra UI library. However, I can't figure out how to change the "dark mode" colors. In the documentation, I see that Chakra UI is based on something called "styled-system", so I tried to pass a new theme
to themeProvider
like this:
const theme = {
...defaultTheme,
modes: {
dark: {
background: '#000',
},
},
};
<ThemeProvider theme={theme}></ThemeProvider>
However, that didn't work. I also tried to wrap the modes
object with a colors
object, but that didn't work either. How can I customize the "dark mode" colors?
Dark mode is a setting that shifts an interface's color palette to display content in high contrast using dark background colors and light foreground. Black text becomes white, and white backgrounds go dark.
Button ColorsUse the colorScheme prop to change the color scheme of the Button.
in the latest version of chakra ui we can overwrite colors this way
import { mode } from '@chakra-ui/theme-tools';
import { extendTheme } from '@chakra-ui/core';
const styles = {
global: props => ({
body: {
color: mode('gray.800', 'whiteAlpha.900')(props),
bg: mode('gray.100', '#141214')(props),
},
}),
};
const components = {
Drawer: {
// setup light/dark mode component defaults
baseStyle: props => ({
dialog: {
bg: mode('white', '#141214')(props),
},
}),
},
};
const theme = extendTheme({
components,
styles,
});
export default theme;
then we pass the theme
into ChakraProvider
As doc say (and it actually works), you also need to wrap your component with another ColorModeProvider.
<ThemeProvider theme={customTheme}>
<ColorModeProvider><YourCompoent/></ColorModeProvider>
</ThemeProvider>
And use the hook called useColorMode inside your component (or nested if you wish) to get current color mode and toggle between.
const { colorMode, toggleColorMode } = useColorMode();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With