themetoggle

package
v0.5.21 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 5 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

View Source
const NameThemeToggle = widget.Name("themetoggle")

NameThemeToggle is the widget name.

View Source
const (
	PartButton = widget.Part("button")
)

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.

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() *css.Stylesheet

RenderCSS defines the themetoggle visual contract using style DSL. It is a "Fixed floating button" (see README) — Docked(Viewport, ...) is what makes that true; a consumer must not have to reposition it itself with inline CSS, that would be exactly the hardcoded-style workaround the harness forbids.

func (*ThemeToggle) WidgetKind added in v0.1.13

func (t *ThemeToggle) WidgetKind() widget.Kind

func (*ThemeToggle) WidgetName added in v0.1.13

func (t *ThemeToggle) WidgetName() widget.Name

type TsTheme added in v0.1.7

type TsTheme string

TsTheme representa el estado de tema del componente.

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