Skip to content

Toggle

A Toggle bound to a boolean state. The button shows the current value in an alert dialog.

Toggle

package main

import (
	"fmt"

	"go.wdy.de/nago/application"
	"go.wdy.de/nago/presentation/core"
	. "go.wdy.de/nago/presentation/ui"
	"go.wdy.de/nago/presentation/ui/alert"
	"go.wdy.de/nago/web/vuejs"
)

func main() {
	application.Configure(func(cfg *application.Configurator) {
		cfg.SetApplicationID("de.worldiety.tutorial")
		cfg.Serve(vuejs.Dist())

		cfg.RootView(".", func(wnd core.Window) core.View {
			checked := core.AutoState[bool](wnd)
			showAlert := core.AutoState[bool](wnd)

			return VStack(
				alert.Dialog("Achtung", Text(fmt.Sprintf("Deine Eingabe: %v", checked)), showAlert, alert.Ok()),
				VStack(
					Toggle(checked.Get()).InputChecked(checked),
					ToggleField("1bcdefg", checked.Get()).InputValue(checked).Frame(Frame{Width: L32}),
					ToggleField("2bcdefg", checked.Get()).InputValue(checked).Frame(Frame{Width: L64}),
					ToggleField("3bcdefg", checked.Get()).InputValue(checked).Frame(Frame{Width: L96}),
				),
				PrimaryButton(func() {
					showAlert.Set(true)
				}).Title("Check"),
			).Gap(L16).
				Frame(Frame{}.MatchScreen())
		})
	}).Run()
}

View on GitHub ↗ · run it with go run go.wdy.de/nago/example/cmd/tutorial-13-toggle@latest