Skip to main content

Crate wasm_theme

Crate wasm_theme 

Source
Expand description

Set the data-theme attribute on the document’s root <html> element from checkbox/toggle, radio-button, button, and/or <select> controls, persisting the choice to localStorage and falling back to the browser’s prefers-color-scheme on first load. See the crate README for usage with each control type, and for wiring into tailwindcss/daisyUI.

Functions§

theme_buttons
Wires up every [name=theme-button] button on the page: attaches a click listener that sets data-theme to the clicked button’s value.
theme_radio
Wires up every [name=theme-radios] radio button on the page: checks the one whose value matches the resolved theme (see [prefers_color_scheme]), and attaches a click listener that sets data-theme to the checked control’s value.
theme_select
Wires up every [name=theme-select] <select> on the page: sets its value to the resolved theme (see [prefers_color_scheme]), and attaches a change listener that sets data-theme to the newly selected value.
theme_toggle
Wires up every [name=theme-toggle] checkbox on the page: applies the resolved theme (see [prefers_color_scheme]) as each control’s initial checked state, and attaches a click listener that flips data-theme between the control’s declared checked/unchecked values (value="light,dark") — or between its single value and "default" if no comma is present.