Ecosystem & Apps
← All examples · Run any demo natively with go run ./examples/<name>.
Form (examples/form_demo)
Section titled “Form (examples/form_demo)”Run go run ./examples/form_demo to test extras/form validation, selects, radios, checkboxes, and submission payloads.
type Styles struct { FlexCol st.Style FieldWrapper st.Style FullWidth st.Style FlexRow st.Style RadioOptionWrapper st.Style RadioOptionAlign st.Style CheckboxWrapper st.Style Page st.Style Card st.Style Notification st.Style Title st.Style TopDivider st.Style Label st.Style Input st.Style Error st.Style OptionLabel st.Style Submit st.Style BottomDivider st.Style PayloadTitle st.Style Payload st.Style Placeholder st.Style}
var styles = Styles{ FlexCol: st.S(). Display(st.DisplayFlex). FlexDirection(st.FlexColumn),
FieldWrapper: st.S(). Display(st.DisplayFlex). FlexDirection(st.FlexColumn). Margin(0, 0, 1, 0),
FullWidth: st.S(). Width(st.Percent(100)),
FlexRow: st.S(). Display(st.DisplayFlex). FlexDirection(st.FlexRow),
RadioOptionWrapper: st.S(). Display(st.DisplayFlex). FlexDirection(st.FlexRow). AlignItems(st.AlignCenter). Margin(0, 2, 0, 0),
RadioOptionAlign: st.S(). Display(st.DisplayFlex). FlexDirection(st.FlexRow). AlignItems(st.AlignCenter),
CheckboxWrapper: st.S(). Display(st.DisplayFlex). FlexDirection(st.FlexRow). AlignItems(st.AlignCenter). Margin(0, 0, 1, 0),
Page: st.S(). Display(st.DisplayFlex). FlexDirection(st.FlexColumn). JustifyContent(st.JustifyCenter). AlignItems(st.AlignCenter). Width(st.Percent(100)). Height(st.Percent(100)). Background(colBG),
Card: st.S(). Display(st.DisplayFlex). FlexDirection(st.FlexColumn). Width(st.Cells(50)). Padding(1, 2). Border(st.SingleBorder().Color(colBorder)). Background(colCard),
Notification: st.S(). Margin(0, 0, 1, 0). Padding(0, 1). Background(colAccent). Foreground(colBG). Bold(true). TextAlign(st.TextAlignCenter),
Title: st.S(). Margin(0, 0, 1, 0). Foreground(colText). Bold(true). TextAlign(st.TextAlignCenter),
TopDivider: st.S(). Width(st.Percent(100)). Height(st.Cells(1)). Margin(0, 0, 1, 0). Background(colSeparator),
Label: st.S(). Foreground(colLabel),
Input: st.S(). Width(st.Percent(100)). Padding(0, 1). Border(st.SingleBorder().Color(colBorder)). Background(colInputBG),
Error: st.S(). Foreground(colError),
OptionLabel: st.S(). Margin(0, 0, 0, 1). Foreground(colText),
Submit: st.S(). Display(st.DisplayFlex). JustifyContent(st.JustifyCenter). AlignItems(st.AlignCenter). Height(st.Cells(3)). Margin(1, 0, 0, 0). Padding(0, 2). Border(st.SingleBorder().Color(colBorder)). Background(colButtonBG). Foreground(colText),
BottomDivider: st.S(). Width(st.Percent(100)). Height(st.Cells(1)). Margin(1, 0, 1, 0). Background(colSeparator),
PayloadTitle: st.S(). Foreground(colLabel). Bold(true),
Payload: st.S(). Foreground(colAccent). Bold(true),
Placeholder: st.S(). Foreground(colLabel). Italic(true),}
var ( colBG = st.Hex("#0f1016") colCard = st.Hex("#181a25") colBorder = st.Hex("#353b53") colInputBG = st.Hex("#12131b") colLabel = st.Hex("#939ec3") colText = st.Hex("#dce1f5") colAccent = st.Hex("#4ade80") colButtonBG = st.Hex("#4f46e5") colSeparator = st.Hex("#262a3b") colError = st.Hex("#f87171"))
type ProfileData struct { Username string `json:"username"` AccessClass string `json:"access_class"` Theme string `json:"theme"` Newsletter bool `json:"newsletter"`}
var App = kx.FC("App", func(_ kx.NoProps) kx.Node { notification, setNotification := kx.UseState("") hasSubmitted, setHasSubmitted := kx.UseState(false)
f := form.Use(form.Options[ProfileData]{ InitialValues: ProfileData{ Username: "neo", AccessClass: "operator", Theme: "emerald", Newsletter: true, }, Validate: func(d ProfileData) map[string]string { errs := make(map[string]string) if len(d.Username) < 3 { errs["username"] = "Username must be at least 3 characters." } return errs }, })
onSubmit := func(d ProfileData) error { message := fmt.Sprintf("SUCCESS: Profile for '%s' initialized.", d.Username) setNotification(message) setHasSubmitted(true) return nil }
s := f.State()
return kx.Box.Style(styles.Page, kx.Box.Style(styles.Card, kx.If(notification() != "", func() kx.Node { return kx.Box.Style(styles.Notification, kx.Text(notification()), ) }),
kx.Box.Style(styles.Title, kx.Text(" Create Cyber Profile "), ),
kx.Box.Style(styles.TopDivider),
kx.Form(kx.FormProps{ Style: styles.FlexCol, OnSubmit: f.HandleSubmit(onSubmit), }, kx.Box.Style(styles.FieldWrapper, kx.Span.Style(styles.Label, kx.Text("Username"), ), kx.Input(kx.InputProps{ Style: styles.Input, Name: "username", Value: s.Values.Username, Disabled: s.IsSubmitting, }), kx.If(s.Errors["username"] != "", func() kx.Node { return kx.Span.Style(styles.Error, kx.Text(s.Errors["username"]), ) }), ),
kx.Box.Style(styles.FieldWrapper, kx.Span.Style(styles.Label, kx.Text("Access Class"), ), kx.Select(kx.SelectProps{ Name: "access_class", Value: s.Values.AccessClass, Disabled: s.IsSubmitting, Style: styles.FullWidth, }, kx.Option(kx.OptionProps{ Text: "Administrator", Value: "admin", }), kx.Option(kx.OptionProps{ Text: "Operator", Value: "operator", }), kx.Option(kx.OptionProps{ Text: "Infiltrator", Value: "infiltrator", }), ), ),
kx.Box.Style(styles.FieldWrapper, kx.Span.Style(styles.Label, kx.Text("Visual Spectrum"), ), kx.RadioGroup(kx.RadioGroupProps{ Value: s.Values.Theme, Disabled: s.IsSubmitting, Style: styles.FlexRow, }, kx.Box.Style(styles.RadioOptionWrapper, kx.Radio(kx.RadioProps{ Name: "theme", Value: "emerald", }), kx.Span.Style(styles.OptionLabel, kx.Text("Emerald"), ), ), kx.Box.Style(styles.RadioOptionAlign, kx.Radio(kx.RadioProps{ Name: "theme", Value: "amber", }), kx.Span.Style(styles.OptionLabel, kx.Text("Amber"), ), ), ), ),
kx.Box.Style(styles.CheckboxWrapper, kx.Checkbox(kx.CheckboxProps{ Name: "newsletter", Checked: s.Values.Newsletter, Disabled: s.IsSubmitting, }), kx.Span.Style(styles.OptionLabel, kx.Text("Subscribe to intel feed"), ), ),
kx.Button(kx.ButtonProps{ Type: "submit", Disabled: s.IsSubmitting, Style: styles.Submit, }, kx.Text(func() string { if s.IsSubmitting { return "Processing..." } return "Initialize Profile" }())), ),
kx.Box.Style(styles.BottomDivider),
kx.Box.Style(styles.FlexCol, kx.Span.Style(styles.PayloadTitle, kx.Text("Decrypted Transmission Payload:"), ),
kx.IfElseFn(hasSubmitted() || s.IsSubmitting, func() kx.Node { msg := fmt.Sprintf( "Username: %v | Access: %v | Spectrum: %v | Feed: %v", s.Values.Username, s.Values.AccessClass, s.Values.Theme, s.Values.Newsletter, ) if s.IsSubmitting { msg = "Encrypting packet..." } return kx.Span.Style(styles.Payload, kx.Text(msg), ) }, func() kx.Node { return kx.Span.Style(styles.Placeholder, kx.Text("Awaiting submission..."), ) }, ), ), ), )})Kites Global State (examples/kites_demo)
Section titled “Kites Global State (examples/kites_demo)”Run go run ./examples/kites_demo to watch selector-sliced components re-render independently on sync and async extras/kites actions.
type Styles struct { CardA st.Style CardATitle st.Style CardBody st.Style CardRendersText st.Style CardB st.Style CardBTitle st.Style AppContainer st.Style AppHeader st.Style AppDescription st.Style CardsRow st.Style ButtonsRow st.Style BtnA st.Style BtnB st.Style BtnAddB st.Style BtnAsync st.Style}
var styles = Styles{ CardA: st.S(). Width(st.Percent(45)). Margin(0, 1). Padding(1, 2). Border(st.SingleBorder()). Background(st.RGB(35, 38, 55)),
CardATitle: st.S(). Foreground(st.RGB(90, 180, 255)). Bold(true),
CardBody: st.S(). Margin(1, 0),
CardRendersText: st.S(). Foreground(st.RGB(160, 160, 180)),
CardB: st.S(). Width(st.Percent(45)). Margin(0, 1). Padding(1, 2). Border(st.SingleBorder()). Background(st.RGB(35, 55, 38)),
CardBTitle: st.S(). Foreground(st.RGB(120, 220, 140)). Bold(true),
AppContainer: st.S(). Display(st.DisplayFlex). FlexDirection(st.FlexColumn). Width(st.Percent(100)). Height(st.Percent(100)). Padding(1, 2). Background(st.RGB(18, 18, 24)),
AppHeader: st.S(). Margin(0, 0, 1, 0). Foreground(st.RGB(240, 190, 90)). Bold(true). TextAlign(st.TextAlignCenter),
AppDescription: st.S(). Margin(0, 0, 2, 0). Foreground(st.RGB(180, 180, 200)). TextAlign(st.TextAlignCenter),
CardsRow: st.S(). Display(st.DisplayFlex). FlexDirection(st.FlexRow). JustifyContent(st.JustifyAround). Margin(0, 0, 2, 0),
ButtonsRow: st.S(). Display(st.DisplayFlex). FlexDirection(st.FlexRow). JustifyContent(st.JustifyCenter),
BtnA: st.S(). Margin(0, 1). Background(st.RGB(50, 120, 220)). Foreground(color.White),
BtnB: st.S(). Margin(0, 1). Background(st.RGB(50, 180, 100)). Foreground(color.White),
BtnAddB: st.S(). Margin(0, 1). Background(st.RGB(30, 150, 130)). Foreground(color.White),
BtnAsync: st.S(). Margin(0, 1). Background(st.RGB(180, 80, 220)). Foreground(color.White),}
type AppState struct { CountA int CountB int}
func (s AppState) SelectCountA() int { return s.CountA }func (s AppState) SelectCountB() int { return s.CountB }
func (s *AppState) IncrementA() { s.CountA++ }func (s *AppState) IncrementB() { s.CountB++ }func (s *AppState) AddB(delta int) { s.CountB += delta }
type Store = kites.Store[AppState]
var storeContext = kx.CreateContext[*Store](nil)var observe = kx.CreateContext[func(*Store) func()](nil)
var CompA = kx.FC("CompA", func(_ kx.NoProps) kx.Node { renders := kx.UseRef(0) renders.Current++
countA := kites.Use(kx.UseContext(storeContext), AppState.SelectCountA)
return kx.Box.Style(styles.CardA, kx.Box.Style(styles.CardATitle, kx.Text("Component A (Slices CountA)")), kx.Box.Style(styles.CardBody, kx.Textf("Count A: %d", countA)), kx.Box.Style(styles.CardRendersText, kx.Textf("Renders: %d", renders.Current), ), )})
var CompB = kx.FC("CompB", func(_ kx.NoProps) kx.Node { renders := kx.UseRef(0) renders.Current++
countB := kites.Use(kx.UseContext(storeContext), AppState.SelectCountB)
return kx.Box.Style(styles.CardB, kx.Box.Style(styles.CardBTitle, kx.Text("Component B (Slices CountB)")), kx.Box.Style(styles.CardBody, kx.Textf("Count B: %d", countB)), kx.Box.Style(styles.CardRendersText, kx.Textf("Renders: %d", renders.Current), ), )})
var App = kx.FC("App", func(_ kx.NoProps) kx.Node { store := kx.UseMemo(func() *Store { return kites.Create(AppState{}) }) track := kx.UseContext(observe) done := kx.UseMemo(func() chan struct{} { return make(chan struct{}) }) kx.UseEffectCleanup(func() func() { var untrack func() if track != nil { untrack = track(store) } return func() { close(done) if untrack != nil { untrack() } } }) kx.UseInterval(store.Action((*AppState).IncrementA), 2*time.Second)
addB := kites.Action(store, (*AppState).AddB)
return kx.Box.Style(styles.AppContainer, // Title kx.Box.Style(styles.AppHeader, kx.Text("🛰️ Kite Global State Manager Demo (extras/kites)"), ),
// Description kx.Box.Style(styles.AppDescription, kx.Text( "This app proves selector-based re-rendering. "+ "Incrementing A doesn't trigger B, and "+ "vice-versa.\nBackground routine will automatically "+ "increment CountA every 2s.", ), ),
// Components side-by-side storeContext.Provider(store, kx.Box.Style(styles.CardsRow, CompA(), CompB()), ),
// Buttons control panel kx.Box.Style(styles.ButtonsRow, kx.Button(kx.ButtonProps{ OnPress: store.Action((*AppState).IncrementA), Style: styles.BtnA, }, kx.Text(" Increment A ")),
kx.Button(kx.ButtonProps{ OnPress: store.Action((*AppState).IncrementB), Style: styles.BtnB, }, kx.Text(" Increment B ")),
kx.Button(kx.ButtonProps{ OnPress: store.Action(kites.Bind((*AppState).AddB, 10)), Style: styles.BtnAddB, }, kx.Text(" +10 B ")),
kx.Button(kx.ButtonProps{ OnPress: func() { go func() { select { case <-time.After(500 * time.Millisecond): addB(10) case <-done: } }() }, Style: styles.BtnAsync, }, kx.Text(" Async +10 B (500ms delay) ")), ), )})Wind Async Data (examples/wind_demo)
Section titled “Wind Async Data (examples/wind_demo)”Run go run ./examples/wind_demo to exercise extras/wind queries, background refetches, and cache-invalidating mutations.
type Styles struct { PodCard st.Style KeyInfo st.Style StatusRow st.Style BgFetchText st.Style ButtonsRow st.Style RestartBtn st.Style RefetchBtn st.Style AppContainer st.Style AppHeader st.Style}
var styles = Styles{ PodCard: st.S(). Width(st.Percent(90)). Margin(1, 0). Padding(1, 2). Border(st.SingleBorder()). Background(st.RGB(25, 35, 55)),
KeyInfo: st.S(). Margin(0, 0, 1, 0),
StatusRow: st.S(). Display(st.DisplayFlex). FlexDirection(st.FlexRow). Margin(0, 0, 1, 0),
BgFetchText: st.S(). Foreground(st.RGB(150, 150, 150)),
ButtonsRow: st.S(). Display(st.DisplayFlex). FlexDirection(st.FlexRow). Gap(2),
RestartBtn: st.S(). Background(st.RGB(200, 60, 60)). Foreground(color.White),
RefetchBtn: st.S(). Background(st.RGB(50, 120, 220)). Foreground(color.White),
AppContainer: st.S(). Display(st.DisplayFlex). FlexDirection(st.FlexColumn). AlignItems(st.AlignCenter). Width(st.Percent(100)). Height(st.Percent(100)). Padding(1, 2). Background(st.RGB(18, 18, 24)),
AppHeader: st.S(). Margin(0, 0, 1, 0). Foreground(st.RGB(240, 190, 90)). Bold(true). TextAlign(st.TextAlignCenter),}
func statusStyle(textColor color.Color) st.Style { return st.S(). Foreground(textColor). Bold(true)}
type PodKey struct { Namespace string ID string}
type cancellation interface { Done() <-chan struct{} Err() error}
func fetchPodStatus[C cancellation](ctx C, key PodKey) (string, error) { select { case <-ctx.Done(): return "", ctx.Err() case <-time.After(1 * time.Second): return fmt.Sprintf("Running (updated at %s)", time.Now().Format("15:04:05")), nil }}
func restartPod[C cancellation](ctx C, key PodKey) (string, error) { select { case <-ctx.Done(): return "", ctx.Err() case <-time.After(800 * time.Millisecond): return "Restarted", nil }}
var PodStatusView = kx.FC("PodStatusView", func(_ kx.NoProps) kx.Node { key := PodKey{ Namespace: "prod", ID: "nginx-web-app", }
query := wind.Use(key, fetchPodStatus)
options := wind.MutationOptions[PodKey, string]{ OnSuccess: func(res string, vars PodKey, ctx wind.MutationContext) { ctx.Client.InvalidateQueries(vars) }, } mutation := wind.UseMutation(restartPod, options)
statusText := "Unknown" textColor := st.RGB(150, 150, 150)
if query.IsLoading { statusText = "Loading initial status..." textColor = st.RGB(240, 190, 90) } else if query.IsError { statusText = fmt.Sprintf("Error: %v", query.Error) textColor = st.RGB(220, 60, 60) } else if query.Data != "" { statusText = query.Data textColor = st.RGB(120, 220, 140) }
bgStateText := "" if query.IsFetching && !query.IsLoading { bgStateText = " (Refetching in background...)" }
mutationText := "Restart Pod" if mutation.IsPending { mutationText = "Restarting Pod..." }
return kx.Box.Style(styles.PodCard, kx.Box.Style(styles.KeyInfo, kx.Textf( "🔑 Query Key: PodKey{Namespace: %q, ID: %q}", key.Namespace, key.ID, ), ),
kx.Box.Style(styles.StatusRow, kx.Text("Current Status: "), kx.Box.Style(statusStyle(textColor), kx.Text(statusText), ), kx.Box.Style(styles.BgFetchText, kx.Text(bgStateText)), ),
kx.Box.Style(styles.ButtonsRow, kx.Button(kx.ButtonProps{ Style: styles.RestartBtn, OnPress: func() { if !mutation.IsPending { mutation.Mutate(key) } }, }, kx.Textf(" 🔄 %s ", mutationText)),
kx.Button(kx.ButtonProps{ Style: styles.RefetchBtn, OnPress: func() { query.Refetch() }, }, kx.Text(" 🔍 Manual Refetch ")), ), )})
var observe = kx.CreateContext[func(*wind.Client) func()](nil)
var App = kx.FC("App", func(_ kx.NoProps) kx.Node { client := kx.UseMemo(wind.NewClient) track := kx.UseContext(observe) kx.UseEffectCleanup(func() func() { if track == nil { return client.Close } untrack := track(client) return func() { untrack() client.Close() } })
return kx.Box.Style(styles.AppContainer, kx.Box.Style(styles.AppHeader, kx.Text("💨 Kite Async Data Fetching Demo (extras/wind)"), ),
wind.Provider(wind.ProviderProps{Client: client}, PodStatusView()), )})Flight Navigation (examples/flight_demo)
Section titled “Flight Navigation (examples/flight_demo)”Run go run ./examples/flight_demo to push and pop screens on a extras/flight navigation stack.
type Styles struct { HomeCard st.Style HomeTitle st.Style BodyText st.Style PrimaryBtn st.Style DetailsCard st.Style DetailsTitle st.Style BackBtn st.Style AppContainer st.Style AppHeader st.Style}
var styles = Styles{ HomeCard: st.S(). Width(st.Percent(80)). Margin(1, 0). Padding(1, 2). Border(st.SingleBorder()). Background(st.RGB(25, 35, 55)),
HomeTitle: st.S(). Margin(0, 0, 1, 0). Foreground(st.RGB(90, 160, 255)). Bold(true),
BodyText: st.S(). Margin(0, 0, 1, 0),
PrimaryBtn: st.S(). Background(st.RGB(50, 120, 220)). Foreground(color.White),
DetailsCard: st.S(). Width(st.Percent(80)). Margin(1, 0). Padding(1, 2). Border(st.SingleBorder()). Background(st.RGB(35, 55, 38)),
DetailsTitle: st.S(). Margin(0, 0, 1, 0). Foreground(st.RGB(120, 220, 140)). Bold(true),
BackBtn: st.S(). Background(st.RGB(200, 60, 60)). Foreground(color.White),
AppContainer: st.S(). Display(st.DisplayFlex). FlexDirection(st.FlexColumn). AlignItems(st.AlignCenter). Width(st.Percent(100)). Height(st.Percent(100)). Padding(1, 2). Background(st.RGB(18, 18, 24)),
AppHeader: st.S(). Margin(0, 0, 1, 0). Foreground(st.RGB(240, 190, 90)). Bold(true). TextAlign(st.TextAlignCenter),}
type HomeRoute struct{}type DetailsRoute struct { ID string}
var HomeView = kx.FC("HomeView", func(_ kx.NoProps) kx.Node { nav := flight.UseNavigation()
kx.UseKeyboard(func(e event.KeyEvent) { if e.MatchString("enter") { nav.Push(DetailsRoute{ID: "42"}) } }, nav)
return kx.Box.Style(styles.HomeCard, // Title kx.Box.Style(styles.HomeTitle, kx.Text("🏠 Home Screen"), ),
// Body text kx.Box.Style(styles.BodyText, kx.Text("Press 'Enter' or click the button below to view details for Item #42."), ),
kx.Button(kx.ButtonProps{ OnPress: func() { nav.Push(DetailsRoute{ID: "42"}) }, Style: styles.PrimaryBtn, }, kx.Text(" View Details (ID: 42) ")), )})
var DetailsView = kx.FC("DetailsView", func(props struct{ ID string }) kx.Node { nav := flight.UseNavigation()
kx.UseKeyboard(func(e event.KeyEvent) { if (e.MatchString("escape") || e.MatchString("esc")) && nav.CanPop() { nav.Pop() } }, nav)
return kx.Box.Style(styles.DetailsCard, kx.Box.Style(styles.DetailsTitle, kx.Textf("ℹ️ Details Screen (Item ID: %s)", props.ID), ),
kx.Box.Style(styles.BodyText, kx.Text("You are viewing details of item #42. Press 'Esc' or click below to go back."), ),
kx.If(nav.CanPop(), func() kx.Node { return kx.Button(kx.ButtonProps{ OnPress: func() { nav.Pop() }, Style: styles.BackBtn, }, kx.Text(" Go Back Home (Esc) ")) }), )})
var App = kx.FC("App", func(_ kx.NoProps) kx.Node { return kx.Box.Style(styles.AppContainer, kx.Box.Style(styles.AppHeader, kx.Text("✈️ Kite Stack Navigation Demo (extras/flight)"), ),
flight.Stack(flight.StackProps{ InitialRoute: HomeRoute{}, RenderRoute: func(r flight.Route) kx.Node { switch route := r.(type) { case HomeRoute: return HomeView() case DetailsRoute: return DetailsView.Props(struct{ ID string }{ID: route.ID}) default: return kx.Box(kx.BoxProps{}) } }, }), )})Stage Component Workbench (examples/stage)
Section titled “Stage Component Workbench (examples/stage)”Run go run ./examples/stage to browse isolated component stories, toggle global theme/border controls, and inspect live logs.
type Styles struct { Button st.Style DangerButton st.Style Column st.Style Input st.Style Counter st.Style CounterLabel st.Style CounterActions st.Style LogButton st.Style ProgressHeader st.Style ProgressTrack st.Style Spacer st.Style Count st.Style}
var styles = Styles{ Button: st.S(). Padding(0, 2). Foreground(st.RGB(255, 255, 255)),
DangerButton: st.S(). Padding(0, 2). Background(st.RGB(220, 38, 38)). Foreground(st.RGB(255, 255, 255)),
Column: st.S(). Display(st.DisplayFlex). FlexDirection(st.FlexColumn). Width(st.Cells(40)),
Input: st.S(). Width(st.Percent(100)). Padding(0, 1). Border(true, st.BorderSingle, st.RGB(156, 163, 175)),
Counter: st.S(). Display(st.DisplayFlex). FlexDirection(st.FlexColumn). AlignItems(st.AlignCenter),
CounterLabel: st.S(). MarginBottom(1). Foreground(st.RGB(156, 163, 175)),
CounterActions: st.S(). MarginTop(1),
LogButton: st.S(). Padding(0, 2). Border(false). Background(st.RGB(16, 185, 129)). Foreground(st.RGB(255, 255, 255)),
ProgressHeader: st.S(). Display(st.DisplayFlex). FlexDirection(st.FlexRow). JustifyContent(st.JustifyBetween). MarginBottom(1),
ProgressTrack: st.S(). Width(st.Percent(100)). Background(st.RGB(55, 65, 81)),
Spacer: st.S(). Height(st.Cells(1)),
Count: st.S(). Padding(0, 3). Background(st.RGB(79, 70, 229)). Foreground(st.RGB(255, 255, 255)),}
func wrapperStyle(theme string, showBorder bool) st.Style { bgColor := st.RGB(17, 24, 39) fgColor := st.RGB(243, 244, 246) if theme == "Light" { bgColor = st.RGB(243, 244, 246) fgColor = st.RGB(17, 24, 39) }
wrapperStyle := st.S(). Padding(2). Background(bgColor). Foreground(fgColor)
if showBorder { wrapperStyle = wrapperStyle. Border(true, st.BorderDouble, st.RGB(79, 70, 229)) } return wrapperStyle}
func buttonStyle(disabled bool) st.Style { if disabled { return styles.Button.Background(st.RGB(107, 114, 128)) } return styles.Button.Background(st.RGB(79, 70, 229))}
func badgeStyle(selectedStatus string) st.Style { badgeStyle := styles.Button switch selectedStatus { case "Success": badgeStyle = badgeStyle.Background(st.RGB(22, 163, 74)) case "Warning": badgeStyle = badgeStyle.Background(st.RGB(202, 138, 4)) case "Error": badgeStyle = badgeStyle.Background(st.RGB(220, 38, 38)) } return badgeStyle}
func progressStyle(progress int) st.Style { barColor := st.RGB(22, 163, 74) switch { case progress < 34: barColor = st.RGB(220, 38, 38) case progress < 67: barColor = st.RGB(202, 138, 4) } return st.S(). Width(st.Percent(float32(progress))). Background(barColor)}
func cardStyle(themeColor color.Color) st.Style { return st.S(). Padding(1). Border(true, st.BorderSingle, themeColor)}
func cardTitleStyle(themeColor color.Color) st.Style { return st.S(). Foreground(themeColor). Bold(true)}
func cardActionStyle(themeColor color.Color) st.Style { return st.S(). Padding(0, 1). Background(themeColor). Foreground(st.RGB(255, 255, 255))}
type CardProps struct { Title string `stage:"label:Card Title;default:Welcome to Kite"` Subtitle string `stage:"label:Card Subtitle;default:A fast TUI library"` ShowAction bool `stage:"label:Show Action Button;default:true"` BorderWidth int `stage:"label:Border Width;min:1;max:4;default:1"` Theme string `stage:"select:Ocean,Forest,Sunset;default:Ocean"`}
func NewStage() *stage.Stage { stg := stage.New()
stg.GlobalSelect("Theme", []string{"Light", "Dark"}, "Dark") stg.GlobalBool("Show Border", true)
stg.WithContextDecorator(func(c *stage.Context, node kx.Node) kx.Node { return kx.Box.Style(wrapperStyle(c.GlobalString("Theme", "Dark"), c.GlobalBool("Show Border", true)), node) })
stg.Register("DesignSystem/Buttons/Button", []stage.Scene{ { Name: "Interactive Button", Render: func(c *stage.Context) kx.Node { label := c.Text("Label Text", "Submit Form") disabled := c.Bool("Disabled", false)
return kx.Button( kx.ButtonProps{ Disabled: disabled, Style: buttonStyle(disabled), OnClick: func(e *event.MouseEvent) { c.Log("Primary Button clicked!") }, }, kx.Text(label), ) }, }, { Name: "Danger Variation", Render: func(c *stage.Context) kx.Node { label := c.Text("Danger Label", "Delete Account")
return kx.Button( kx.ButtonProps{ Style: styles.DangerButton, OnClick: func(e *event.MouseEvent) { c.Log("Danger Button clicked!") }, }, kx.Text(label), ) }, }, })
stg.Register("Text Input", []stage.Scene{ { Name: "Basic Input", Render: func(c *stage.Context) kx.Node { placeholder := c.Text("Placeholder Text", "Enter username...") val := c.Text("Value String", "")
return kx.Box.Style( styles.Column, kx.Input(kx.InputProps{ Value: val, Placeholder: placeholder, Style: styles.Input, OnValueChange: func(val string) { c.Log("Input value changed to: " + val) }, }), ) }, }, })
stg.Register("Status Badges", []stage.Scene{ { Name: "Themed Badges", Render: func(c *stage.Context) kx.Node { statusOptions := []string{"Success", "Warning", "Error"} selectedStatus := c.Select("Status Selection", statusOptions, "Success")
return kx.Box.Style(badgeStyle(selectedStatus), kx.Text(selectedStatus)) }, }, })
stg.Register("Counter", []stage.Scene{ { Name: "Basic Counter", Render: func(c *stage.Context) kx.Node { count := c.Int("Count", 0)
return kx.Box.Style(styles.Counter, kx.Box.Style(styles.CounterLabel, kx.Text("Current Count"), ), kx.Box.Style(styles.Count, kx.Textf("%d", count)), kx.Box.Style(styles.CounterActions, kx.Button( kx.ButtonProps{ Style: styles.LogButton, OnClick: func(e *event.MouseEvent) { c.Log(fmt.Sprintf("Count is %d", count)) }, }, kx.Text("Log Value"), ), ), ) }, }, { Name: "Progress Bar", Render: func(c *stage.Context) kx.Node { progress := c.Int("Progress (0-100)", 42) progress = max(0, min(100, progress))
return kx.Box.Style(styles.Column, kx.Box.Style(styles.ProgressHeader, kx.Text("Progress"), kx.Textf("%d%%", progress), ),
kx.Box.Style(styles.ProgressTrack, kx.Box.Style(progressStyle(progress), kx.Text(" "), ), ), ) }, }, })
cardRegistry := stage.NewRegistry()
stage.Register(cardRegistry, stage.ComponentConfig[CardProps]{ Name: "Card", DefaultProps: CardProps{ Title: "Kite TUI", Subtitle: "Sleek and terminal-native", ShowAction: true, Theme: "Ocean", }, Render: func(c *stage.Context, props CardProps) kx.Node { themeColor := st.RGBA(0, 0, 0, 0) switch props.Theme { case "Ocean": themeColor = st.RGB(59, 130, 246) case "Sunset": themeColor = st.RGB(239, 68, 68) case "Forest": themeColor = st.RGB(16, 185, 129) }
card := cardStyle(themeColor)
var children []kx.Node children = append(children, kx.Box.Style( cardTitleStyle(themeColor), kx.Text(props.Title), )) children = append(children, kx.Text(props.Subtitle))
if props.ShowAction { children = append(children, kx.Box.Style( styles.Spacer, )) children = append(children, kx.Button( kx.ButtonProps{ Style: cardActionStyle(themeColor), OnClick: func(e *event.MouseEvent) { c.Log("Card action clicked!") }, }, kx.Text("Action"), )) }
return kx.Box.Style(card, children...) }, Scenes: []stage.SceneConfig[CardProps]{ { Name: "Compact Variation", Props: CardProps{ Title: "Compact Card", Subtitle: "Minimal variation", ShowAction: false, Theme: "Forest", }, }, }, })
stg.Merge("DesignSystem/Layouts", cardRegistry)
return stg}
var App = kx.FC("App", func(_ kx.NoProps) kx.Node { stg := kx.UseMemo(NewStage) return stg.Root()})Layout Engine Showcase (examples/app1)
Section titled “Layout Engine Showcase (examples/app1)”Run go run ./examples/app1 to inspect inline spans, inline-block atoms, lists, wrapped flex items, and tables in one tree.
type Styles struct { Header st.Style HighlightSpan st.Style AtomicBox st.Style Paragraph st.Style FeaturesSection st.Style FlexContainer st.Style Col1 st.Style Col2 st.Style Table st.Style TableSection st.Style ContentWrapper st.Style Root st.Style}
var styles = Styles{ Header: st.S(). Width(st.Percent(100)). Margin(0, 0, 1, 0). Background(st.RGB(100, 0, 200)). TextAlign(st.TextAlignCenter),
HighlightSpan: st.S(). Background(st.Hex("#ffffff")). Foreground(color.Black),
AtomicBox: st.S(). Display(st.DisplayInlineBlock). Width(st.Cells(10)). Height(st.Cells(3)). Margin(0, 1). Border(st.SingleBorder()). Background(st.RGB(0, 200, 100)),
Paragraph: st.S(). AlignItems(st.AlignCenter),
FeaturesSection: st.S(). Margin(1, 0). Padding(1). Background(st.RGB(40, 40, 60)),
FlexContainer: st.S(). Display(st.DisplayFlex). FlexDirection(st.FlexRow). FlexWrap(st.FlexWrapOn). Gap(1, 2). Width(st.Percent(100)). Margin(1, 0). Padding(1). Background(st.RGB(50, 50, 50)),
Col1: st.S(). Width(st.Percent(30)),
Col2: st.S(). Width(st.Percent(70)),
Table: st.S(). Width(st.Percent(100)). Border(st.SingleBorder()),
TableSection: st.S(). Margin(1, 0). Padding(1). Background(st.RGB(20, 60, 20)),
ContentWrapper: st.S(). Width(st.Percent(80)). Height(st.Auto). Margin(1, 2). Padding(1, 2). Border(st.SingleBorder(). Color(st.RGB(200, 200, 200))). Background(st.RGB(30, 30, 30)),
Root: st.S(). OverflowY(st.OverflowAuto). Width(st.Percent(100)). Height(st.Percent(100)). Padding(2, 4). Background(st.RGB(0, 0, 255)),}
func itemStyle(i int) st.Style { return st.S(). Flex(1, 1, st.Cells(10)). Width(st.Cells(12)). Height(st.Cells(3)). Border(st.SingleBorder()). Background(st.RGB(uint8(40*i), 100, 150))}
func App() dom.Element { flexItems := make([]any, 0, 6) for i := 1; i <= 6; i++ { flexItems = append(flexItems, el.Box(itemStyle(i), fmt.Sprintf("Flex Item %d", i))) }
return el.Box(styles.Root, el.Box(styles.ContentWrapper, el.Box(styles.Header, "Kite Layout Engine Test"), el.Box(styles.Paragraph, "This is a demonstration of ", el.Span(styles.HighlightSpan, "inline elements"), " and ", el.Box(styles.AtomicBox, "Atomic!"), " working together in a single flow.", ), el.Box(styles.FeaturesSection, "Available Features:", el.UL( el.LI("Full LayoutNG engine"), el.LI("Interactive DOM components"), el.LI("Flexible styling system"), ), ), el.Box(styles.FlexContainer, flexItems), el.Box(styles.TableSection, "Grid Layout (Table):", el.Table(styles.Table, el.TR( el.TD(styles.Col1, "Header 1"), el.TD(styles.Col2, "Header 2"), ), el.TR( el.TD("Row 1, Cell 1"), el.TD("Row 1, Cell 2"), ), ), ), ), )}