![New axobject-query Maintainer Faces Backlash Over Controversial Decision to Support Legacy Node.js Versions](https://cdn.sanity.io/images/cgdhsj6q/production/86e6ebdea652d20da070ebbda20134b839972db7-1024x1024.webp?w=800&fit=max&auto=format)
Security News
New axobject-query Maintainer Faces Backlash Over Controversial Decision to Support Legacy Node.js Versions
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.
@chakra-ui/color-mode
Advanced tools
Package description
@chakra-ui/color-mode is a package that provides utilities for managing color modes (e.g., light and dark themes) in Chakra UI applications. It allows developers to easily toggle between different color modes and persist the user's preference.
Color Mode Provider
The Color Mode Provider is used to wrap your application and provide the color mode context to all components within the app.
import { ChakraProvider, ColorModeProvider } from '@chakra-ui/react';
function App() {
return (
<ChakraProvider>
<ColorModeProvider>
<YourComponent />
</ColorModeProvider>
</ChakraProvider>
);
}
useColorMode Hook
The useColorMode hook allows you to access the current color mode and a function to toggle between light and dark modes.
import { useColorMode } from '@chakra-ui/react';
function ToggleButton() {
const { colorMode, toggleColorMode } = useColorMode();
return (
<button onClick={toggleColorMode}>
Toggle {colorMode === 'light' ? 'Dark' : 'Light'}
</button>
);
}
Color Mode Script
The Color Mode Script is used to ensure that the initial color mode is correctly set on the server-side and during hydration.
import { ColorModeScript } from '@chakra-ui/react';
function App() {
return (
<html>
<head>
<ColorModeScript />
</head>
<body>
<YourComponent />
</body>
</html>
);
}
styled-components is a library for React and React Native that allows you to use component-level styles in your application. It supports theming, including light and dark modes, but requires more manual setup compared to @chakra-ui/color-mode.
Emotion is a library designed for writing CSS styles with JavaScript. It provides powerful and flexible theming capabilities, including support for color modes. However, it is more general-purpose and not as tightly integrated with a UI component library as @chakra-ui/color-mode.
theme-ui is a library for building themeable user interfaces based on constraint-based design principles. It includes built-in support for color modes and theming, similar to @chakra-ui/color-mode, but is part of a different ecosystem.
Readme
React component that adds support for light mode and dark mode using
localStorage
and matchMedia
.
yarn add @chakra-ui/color-mode
# or
npm i @chakra-ui/color-mode
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>
)
}
FAQs
React component and hooks for handling light and dark mode.
The npm package @chakra-ui/color-mode receives a total of 359,285 weekly downloads. As such, @chakra-ui/color-mode popularity was classified as popular.
We found that @chakra-ui/color-mode demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.
Security News
Results from the 2023 State of JavaScript Survey highlight key trends, including Vite's dominance, rising TypeScript adoption, and the enduring popularity of React. Discover more insights on developer preferences and technology usage.
Security News
The US Justice Department has penalized two consulting firms $11.3 million for failing to meet cybersecurity requirements on federally funded projects, emphasizing strict enforcement to protect sensitive government data.