Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@chakra-ui/color-mode

chakra-ui1.7mMIT2.2.0TypeScript support: included

React component and hooks for handling light and dark mode.

react, theming, ui, light mode, use dark mode, dark mode, color mode, hook, color scheme, media query, chakra ui

readme

Color Mode

React component that adds support for light mode and dark mode using localStorage and matchMedia.

Installation

yarn add @chakra-ui/color-mode

# or

npm i @chakra-ui/color-mode

Import component

To enable this behavior within your apps, wrap your application in a ColorModeProvider below the ThemeProvider

`jsx live=false import * as React from "react" import { ColorModeProvider } from "@chakra-ui/color-mode" import theme from "./theme"

function App({ children }) { return ( <ThemeProvider theme={theme}> <ColorModeProvider>{children}</ColorModeProvider> </ThemeProvider> ) }


Then you can use the hook `useColorMode` within your application.

```jsx
function Example() {
  const { colorMode, toggleColorMode } = useColorMode()
  return (
    <header>
      <Button onClick={toggleColorMode}>
        Toggle {colorMode === "light" ? "Dark" : "Light"}
      </Button>
    </header>
  )
}