Partial Component
Dark Light Theme Switcher
The Dark Light Theme Switcher partial provides a toggle button for switching between dark and light theme modes. It uses moon and sun icons to indicate the current state and target mode. Sun, indicating light mode is the default. When clicking on it the icon will change to a moon and the class dark-theme
will be added to the page body
.
Manifest
{
"name": "dark-light-theme-switcher",
"type": "_partials",
"styles": ["dark-light-theme-switcher.css"],
"scripts": ["dark-light-theme-switcher.js"],
"requires": []
}
Example
Click the theme switcher in the navigation above to see the toggle in action.
Usage in Templates
{% from "components/_partials/dark-light-theme-switcher/dark-light-theme-switcher.njk" import darkLightThemeSwitcher %}
{{ darkLightThemeSwitcher() }}
Notes
- Moon icon for dark mode, sun icon for light mode
- Proper ARIA labels and keyboard navigation
- Click or keyboard activation
- Maintains state via local storage between sessions