Component live demo
β Click me!
Provides system or user-defined color scheme preference, with a toggle mechanism. Settings are persisted, component is progressively enhanced and flash of unstyled content avoided. Also, it will provide an easier way to target theme with CSS / SCSS / JS.
Provides system or user-defined color scheme preference, with a toggle mechanism.
Settings are persisted, component is progressively enhanced and flash of mis-styled content avoided.
Also, this provides an easier way to target theme with CSS selector / SCSS mixins / JS DOM selector.
Warning
π§Β Β Work in progress
data-color-mode="dark|light"
attribute on root documentWarning
The SCSS part is still a work in progress towards full no-JS support (progressive enhancement).
pnpm i @julian_cataldo/astro-color-mode
---
import ColorMode from '@julian_cataldo/astro-color-mode/ColorMode.astro';
// ...
---
<!-- ... -->
<head>
<!-- Place component inside HEAD tag -->
<ColorMode />
<!-- ... -->
</head>
<!-- ... -->
<body>
<!-- Use 'data-color-mode-switch' where you want to -->
<!-- toggle theme setting, on an element inside BODY tag -->
<button data-color-mode-switch>Toggle COLOR MODE π‘</button>
<!-- ... -->
</body>
SCSS mixins registration in astro.config.mjs
:
export default defineConfig({
// ...
vite: {
css: {
preprocessorOptions: {
scss: {
additionalData: `
@use "@julian_cataldo/astro-color-mode/use-mixins.scss" as *;
`,
},
},
},
},
});
<html data-color-mode="light|dark">
<!-- ... -->
</html>
@media
query support for SCSS mixinsAll notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.
Note: Version bump only for package @julian_cataldo/astro-color-mode
Note: Version bump only for package @julian_cataldo/astro-color-mode