
Security News
Lovable’s OJ Rewrites Vite’s Dev Server in Rust as AI Lowers the Cost of Forking Open Source
Lovable’s OJ rewrites Vite’s dev server in Rust, reducing memory use and preview times as AI lowers the cost of open source reimplementation.
@zachleat/solar-eclipse-toggle
Advanced tools
An accessible light/dark theme toggle button that follows your system preference by default.
<solar-eclipse-toggle> Web ComponentAn accessible light/dark theme toggle button that follows your system preference by default.
npm install @zachleat/solar-eclipse-toggle
Include the stylesheet and the script on your web site:
<link rel="stylesheet" href="solar-eclipse-toggle.css">
<script type="module" src="solar-eclipse-toggle.js"></script>
The stylesheet is also exported as @zachleat/solar-eclipse-toggle/style.css.
Define the icons once as reusable symbols (copy the full paths from demo.html):
<svg aria-hidden="true" style="position: absolute; width: 0; height: 0; overflow: hidden">
<symbol id="se-icon-moon" viewBox="0 0 512 512"><!-- Font Awesome moon --></symbol>
<symbol id="se-icon-sun" viewBox="0 -32 576 576"><!-- Font Awesome sun --></symbol>
<symbol id="se-icon-half" viewBox="0 0 512 512"><!-- Font Awesome circle-half-stroke --></symbol>
</svg>
Then use the component markup:
<solar-eclipse-toggle>
<button type="button" disabled>
<span class="se-label-dark" hidden><svg aria-hidden="true"><use href="#se-icon-moon"/></svg>Use dark theme</span>
<span class="se-label-light" hidden><svg aria-hidden="true"><use href="#se-icon-sun"/></svg>Use light theme</span>
<span class="se-label-unknown"><svg aria-hidden="true"><use href="#se-icon-half"/></svg>Theme</span>
<span class="se-system">System</span>
</button>
</solar-eclipse-toggle>
(<span class="se-system">System</span> is optional)
Add this to your <head> to apply a saved theme before first paint:
<script>
try {
var theme = localStorage.getItem("theme");
if(theme === "light" || theme === "dark") {
document.documentElement.setAttribute("data-theme", theme);
}
} catch(e) {}
</script>
Write your dark styles for both the system preference and the override:
@media (prefers-color-scheme: dark) {
:root:not([data-theme="light"]) {
color-scheme: dark;
/* dark styles */
}
}
:root[data-theme="dark"] {
color-scheme: dark;
/* dark styles */
}
To ignore the system preference when there is no saved choice, add data-theme-default (light or dark) to the root element:
<html data-theme-default="dark">
Use the same attribute in your own CSS to pick the page’s default colors:
:root {
color-scheme: dark;
/* dark styles */
}
:root[data-theme="light"] {
color-scheme: light;
/* light styles */
}
Consider relabeling SYSTEM (e.g. <span class="se-system">Default</span>) and setting status-auto, which defaults to the default when a default theme is declared. See demo-default-dark.html.
prefers-color-scheme until a visitor picks the other theme, which is saved to localStorage.<button> named for what it does next (“Use dark theme”), with no aria-pressed state.role="status" live region, since screen readers don’t reliably announce name changes..se-label-unknown with SYSTEM.hidden from .se-label-unknown to the label for the other theme, and hides SYSTEM (if present) unless an override is active.storage-key: localStorage key. Default: themestatus-light, status-dark, status-auto: announcements. Defaults: Light theme on, Dark theme on, matching your system (or the default with data-theme-default)theme-change event, with event.detail of { theme, auto }.status-* attributes.Add ?nodefine to the script URL to skip the customElements.define call:
<script type="module">
import { SolarEclipseToggle } from "./solar-eclipse-toggle.js?nodefine";
SolarEclipseToggle.define();
</script>
The stylesheet targets the solar-eclipse-toggle tag name.
Styles are in the solar-eclipse-toggle cascade layer, so your own styles win. Colors use custom properties, with light and dark naming the current page theme:
--se-light-color, --se-light-border, --se-light-icon, --se-light-hover, --se-light-system-bg, --se-light-system-color--se-dark-color, --se-dark-border, --se-dark-icon, --se-dark-hover, --se-dark-system-bg, --se-dark-system-color--se-focusDemo icons are Font Awesome Free (CC BY 4.0).
FAQs
An accessible light/dark theme toggle button that follows your system preference by default.
The npm package @zachleat/solar-eclipse-toggle receives a total of 0 weekly downloads. As such, @zachleat/solar-eclipse-toggle popularity was classified as not popular.
We found that @zachleat/solar-eclipse-toggle demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.

Security News
Lovable’s OJ rewrites Vite’s dev server in Rust, reducing memory use and preview times as AI lowers the cost of open source reimplementation.

Security News
It has been one year since Shai-Hulud made its first appearance on npm.

Research
/Security News
Operators behind PolinRider used a compromised GitHub account to plant malware in four development versions of a Packagist package with 700,000+ downloads.