@chakra-ui/color-mode
TypeScript icon, indicating that this package has built-in type declarations

2.2.0 • Public • Published

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

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.

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

Package Sidebar

Install

npm i @chakra-ui/color-mode

Weekly Downloads

587,480

Version

2.2.0

License

MIT

Unpacked Size

114 kB

Total Files

48

Last publish

Collaborators

  • segunadebayo
  • _codebender828