From e27e02c83ce12c3e0e1c86aefa04b1d294ffb892 Mon Sep 17 00:00:00 2001 From: Maas Lalani Date: Thu, 9 May 2024 19:26:28 -0400 Subject: [PATCH] feat: better loading --- examples/dynamic/dynamic-country/main.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/examples/dynamic/dynamic-country/main.go b/examples/dynamic/dynamic-country/main.go index be5d7fc3..cad19cfd 100644 --- a/examples/dynamic/dynamic-country/main.go +++ b/examples/dynamic/dynamic-country/main.go @@ -44,6 +44,24 @@ func main() { time.Sleep(1000 * time.Millisecond) return huh.NewOptions(s...) }, &country /* only this function when `country` changes */), + huh.NewSelect[string](). + Height(8). + TitleFunc(func() string { + switch country { + case "United States": + return "State" + case "Canada": + return "Province" + default: + return "Territory" + } + }, &country). + OptionsFunc(func() []huh.Option[string] { + s := states[country] + // simulate API call + time.Sleep(1000 * time.Millisecond) + return huh.NewOptions(s...) + }, &country /* only this function when `country` changes */), huh.NewNote(). TitleFunc(func() string { return fmt.Sprintf("You selected: %s", country)