@bianic-ui/color-mode
v0.1.0-alpha.2
Published
React component and hooks for handling light and dark mode.
Downloads
7
Maintainers
Readme
Color Mode
React component that adds support for light mode and dark mode using
localStorage
and matchMedia
.
Installation
yarn add @bianic-ui/color-mode
# or
npm i @bianic-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 "@bianic-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>
)
}