qwik-theme-toggle
v2.1.0
Published
The Qwik-Theme-Toggle Library is a lightweight, user-friendly JavaScript library developed as a Qwik component. It provides an efficient theme toggle button for web applications, enabling users to switch between light, dark, and auto modes, enhancing thei
Downloads
208
Readme
Qwik-Theme-Toggle
Qwik-Theme-Toggle is a lightweight, zero‑flicker, SSR‑safe theme toggler built as a Qwik component.
It supports:
- Custom CSS themes (e.g.,
latte,dracula) - Auto mode with OS preference detection
- DaisyUI & Tailwind compatibility
- Icon modes (
light,dark,auto) - URL query param sync (optional)
- LocalStorage persistence
- SSR hydration consistency
Installation
npm install qwik-theme-toggle
# or
bun install qwik-theme-toggleUsage
1. Add ThemeScript inside <head>
<ThemeScript
themeStorageKey="theme"
themeQuery="theme" // optional
lightTheme="latte" // optional, default: 'light'
darkTheme="dracula" // optional, default: 'dark'
/>2. Add ThemeToggle anywhere in your UI
<ThemeToggle
themeStorageKey="theme"
themeQuery="theme" // optional
lightTheme="latte" // optional, default: 'light'
darkTheme="dracula" // optional, default: 'dark'
textSize="text-3xl"
myClass="hover:text-secondary"
/>How it works
LocalStorage stores CSS theme:
latte | dracula | autoHTML is always consistent:
<html
class="latte"
data-theme="latte"
icon-theme="light"
/>icon-theme is always:
light | dark | autoAuto mode resolves OS preference:
auto → latte (light OS)
auto → dracula (dark OS)Project Structure
src/
├── components/theme-toggle/
└── index.ts
example/Development
bun install
bun startProduction Build
bun run buildOutputs:
lib/— compiled librarylib-types/— TypeScript definitions
Live Demo
Codesandbox: https://codesandbox.io/p/github/lieranderl/qwik-theme-toggle/main
Video demo: https://www.youtube.com/watch?v=51iWIiZFCQY
