Automatic switching
Calculates sunrise and sunset in real time and applies the appropriate theme.
VToggleTheme
Our published component combines solar times, system preference and manual selection in a flexible solution for Vuetify applications.
Published npm package
A Vue component for intelligent theme switching in Vuetify applications. It switches automatically according to sunrise and sunset, optionally respects the system preference, or allows a manual selection.
Decision logic
With usePreference, the component follows the prefers-color-scheme setting.
Otherwise it switches automatically using a fixed location and the local time of day.
A manual switch takes priority and stops automatic control.
Features
VToggleTheme combines automatic theme control with conscious user choice and integrates into existing Vuetify themes.
Calculates sunrise and sunset in real time and applies the appropriate theme.
Users can switch at any time and thereby disable automatic control.
Supports prefers-color-scheme for the appearance selected in the operating system.
Uses Vuetify theming and accepts v-btn properties for customization.
Uses configurable coordinates without requesting browser geolocation by default.
Designed for client- and server-side environments as well as Nuxt 3.
Installation and usage
The package requires Vue 3.5.13 or newer and Vuetify 3.7.5 or newer. sunrise-sunset-js is installed automatically as a dependency.
npm install v-toggle-theme @mdi/js
npm install vue@^3.5.13 vuetify@^3.7.5<script setup>
import VToggleTheme from 'v-toggle-theme'
</script>
<template>
<v-toggle-theme
color="primary"
:tooltip="true"
:use-preference="true"
/>
</template>The actual user location is not requested by default. The calculation uses the developer-defined fallbackLocation; without one, the coordinates of Zurich are used.
Configuration
Theme names, automatic behavior, reference location, tooltips and icon variant can be adapted to the project through props.
themeNameLightName of the light Vuetify theme. Default: light.
themeNameDarkName of the dark Vuetify theme. Default: dark.
fallbackLocationCoordinates for solar times. Default: Zurich at 47.36667 / 8.55.
tooltipEnables tooltips. Default: false.
tipDarkTooltip text for dark mode. Default: Dark mode.
tipLightTooltip text for light mode. Default: Light mode.
automaticEnables time-based automatic switching. Default: true.
usePreferenceRespects the system preference through prefers-color-scheme. Default: false.
mdiJsIconsUses inline SVG icons from the MDI JavaScript package instead of the MDI font. Default: false.
Manual switching changes the theme and stops automatic control.