Utilities
useColorScheme
Switches between light, dark and system modes, and can spread the new scheme in a circle from a click. Use it for a theme toggle, and pass your own storage functions to remember the choice.
Sets the root data-theme to light or dark; system follows the OS preference. Pass persist to save the choice in cookies, a store or localStorage. Vue restores a saved choice on mount, which can be after first paint, so the HTML head example restores the color mode, and an optional root font size, before paint. Every call in the browser shares one state, so two toggles never disagree. Pass { from: event } as the second argument to setMode and the new scheme spreads in a circle from the click, as the example below and this site's header toggle do. It uses a View Transition; browsers without one, and reduced motion, switch at once.
Install
import { useColorScheme } from 'vael-ui'