Skip to content

How do I change the body background color with TypeScript? #5048

Answered by dmitriifrlv
BurgerBurglar asked this question in Q&A
Discussion options

You must be logged in to vote
  1. Create a custom theme where you define background colors for both modes:
//theme.ts
import { extendTheme } from "@chakra-ui/react";
import { mode } from "@chakra-ui/theme-tools";

const theme = extendTheme({
  config,
  styles: {
    global: (props) => ({
      body: {
        bg: mode(*color for light mode(string)*,*color for dark mode(string)*)(props),
      }
    })
  },
})
  1. Pass this theme to ChakraProvider:
//index.ts
import { ChakraProvider } from "@chakra-ui/react";
import theme from "./Theme";

    <ChakraProvider theme={theme}>
      <App />
    </ChakraProvider>

Demo

Replies: 5 comments 7 replies

Comment options

You must be logged in to vote
5 replies
@tombohub
Comment options

@CoreyGumbs
Comment options

@tombohub
Comment options

@bnchrch
Comment options

@givensuman
Comment options

Answer selected by BurgerBurglar
Comment options

You must be logged in to vote
1 reply
@dmitriifrlv
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@koxon
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
9 participants