
Research
/Security News
DuckDB npm Account Compromised in Continuing Supply Chain Attack
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
@dazl/color-scheme
Advanced tools
A simple color scheme management library for web applications with support for light/dark themes and automatic system preference detection.
color-scheme
CSS property on the document root for native browser themingnpm install @dazl/color-scheme
Import the client module to initialize color scheme management:
Note: This import should only be used in client-side code and must run before the
<body>
is rendered. For best results, include it in an inline script.
import '@dazl/color-scheme/client';
// The color scheme API is now available globally
const currentScheme = window.colorSchemeApi.current;
console.log(currentScheme); // { config: 'system', resolved: 'dark' }
// Change the color scheme
window.colorSchemeApi.config = 'light';
// Subscribe to changes
const unsubscribe = window.colorSchemeApi.subscribe(({ config, resolved }) => {
console.log(`Color scheme changed: ${config} (resolved: ${resolved})`);
});
config
(light|dark|system
) - Get or set the current color scheme configurationcurrentState
({ config: light|dark|system, resolved: light|dark }
) - Get the current state including both config and resolved valuesresolvedSystem
(light|dark
) - Get the resolved theme based on system preferencessubscribe
((handler: (currentState) => void) => () => void
) - Subscribe to color scheme changes and return an unsubscribe functiongetRootCssClass
((resolved?: light|dark) => string
) - CSS class applied to the document root based on the resolved theme or passed valueOverride the default CSS classes applied to the document root by specifying data-dark-class
and data-light-class
attributes in the client script tag:
<script src="@dazl/color-scheme/client" data-dark-class="dark-theme" data-light-class="light-theme"></script>
Use the provided React hook for easy integration:
import { useColorScheme } from '@dazl/color-scheme/react';
function ThemeToggle() {
const { configScheme, resolvedScheme, setColorScheme, isLight, isDark } = useColorScheme();
return (
<div>
<p>Current config: {configScheme}</p>
<p>Resolved theme: {resolvedScheme}</p>
<p>Is light theme: {isLight}</p>
<p>Is dark theme: {isDark}</p>
<button onClick={() => setColorScheme('light')}>Light Theme</button>
<button onClick={() => setColorScheme('dark')}>Dark Theme</button>
<button onClick={() => setColorScheme('system')}>System Theme</button>
</div>
);
}
resolvedScheme
(light|dark
) - Resolved theme (light/dark)configScheme
(light|dark|system
) - Current configuration (light/dark/system)setColorScheme
((config: light|dark|system) => void
) - Function to change the color schemeisLight
(boolean
) - Whether the current resolved theme is lightisDark
(boolean
) - Whether the current resolved theme is darkrootCssClass
(string
) - CSS class applied to the document root based on the resolved themeThe library automatically applies CSS classes to the document root. Style your application accordingly:
/* Dark theme styles */
:root.dark-theme {
--bg-color: #000000;
--text-color: #ffffff;
}
/* Light theme styles (explicit) */
:root.light-theme {
--bg-color: #ffffff;
--text-color: #000000;
}
MIT © Dazl
FAQs
Color scheme utilities and tools
The npm package @dazl/color-scheme receives a total of 1,023 weekly downloads. As such, @dazl/color-scheme popularity was classified as popular.
We found that @dazl/color-scheme demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 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.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.
Product
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.