Skip to content

Toggle

An on/off switch with a visual state indicator, six color variants, an optional bordered container style, and disabled states.

Default Rendered example
Usage Example
@toggle.Toggle(toggle.Config{
    ID:      "myToggle",
    Label:   "Toggle",
    Checked: true,
})

With Container

Appearance: toggle.AppearanceContainer wraps the switch and label in a bordered container.

With Container Rendered example
With Container
@toggle.Toggle(toggle.Config{
    ID:      "containerToggle",
    Label:   "Toggle",
    Appearance: toggle.AppearanceContainer,
    Checked: true,
})

Color Variations

Set Tone: toggle.TonePrimary, toggle.ToneSecondary, toggle.ToneInfo, toggle.ToneSuccess, toggle.ToneWarning, or toggle.ToneDanger.

Color Variations Rendered example
Color Variations
@toggle.Toggle(toggle.Config{ID: "successToggle", Label: "success", Tone: toggle.ToneSuccess, Checked: true})
@toggle.Toggle(toggle.Config{ID: "dangerToggle", Label: "danger", Tone: toggle.ToneDanger, Checked: true})

Disabled States

Disabled: true blocks interaction in both the off and on positions.

Disabled States Rendered example
Disabled States
@toggle.Toggle(toggle.Config{ID: "offToggle", Label: "Disabled (off)", Disabled: true})
@toggle.Toggle(toggle.Config{ID: "onToggle", Label: "Disabled (on)", Checked: true, Disabled: true})

Go API

v0.2.7

The examples above cover behavior and composition. pkg.go.dev is the canonical reference for exported types, functions, methods, and Go documentation.

github.com/araihu/goshtoso/components/toggle
Open v0.2.7 API