themetoggle

package
v0.1.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 3 Imported by: 0

README

ThemeToggle

Signal-driven component to toggle the application theme (dark / light).

Features

  • 2 states: dark and light. Defaults to light when nothing is saved. There is no auto/OS-preference state — if an app wants to seed the theme from prefers-color-scheme, resolve that outside this component (e.g. by writing to localStorage/data-theme before mounting ThemeToggle).
  • Automatic persistence in localStorage via Init.
  • Fixed floating button.
  • Signal-driven: updates icon and labels surgically without re-rendering the whole button.

Usage

import (
	"github.com/tinywasm/components/themetoggle"
	"github.com/tinywasm/dom"
)

func main() {
	ts := &themetoggle.ThemeToggle{}
	dom.Append("body", ts)
	select {}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ThemeToggle

type ThemeToggle struct {
	Element
	// contains filtered or unexported fields
}

ThemeToggle es un botón flotante que alterna entre dark y light. Restaura automáticamente el tema guardado en localStorage al montarse.

ts := &themetoggle.ThemeToggle{}
Append("body", ts)

func (*ThemeToggle) Init added in v0.1.7

func (t *ThemeToggle) Init(_ Ctx)

func (*ThemeToggle) Render

func (t *ThemeToggle) Render() *Element

func (*ThemeToggle) RenderCSS

func (t *ThemeToggle) RenderCSS() *Stylesheet

type TsTheme added in v0.1.7

type TsTheme string

TsTheme representa el estado de tema del componente. Solo hay 2 estados: dark o light. No existe un tercer estado "auto" — si una app quiere seguir la preferencia del SO, eso se resuelve fuera de este componente (p. ej. eligiendo el valor inicial antes de montar ThemeToggle), no como un estado más del ciclo.

const (
	TsThemeDark  TsTheme = "dark"
	TsThemeLight TsTheme = "light"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL