Controls & Overlays
← All examples · Run any demo natively with go run ./examples/<name>.
Button (examples/button)
Section titled “Button (examples/button)”Run go run ./examples/button to test click counters, reset actions, disabled controls, and hover styles.
type Styles struct { Root st.Style PrimaryBtn st.Style DefaultBtn st.Style DangerBtn st.Style Title st.Style Counter st.Style HoverBtn st.Style}
var styles = Styles{ Root: st.S(). Display(st.DisplayFlex). FlexDirection(st.FlexColumn). JustifyContent(st.JustifyCenter). AlignItems(st.AlignCenter). Width(st.Percent(100)). Height(st.Percent(100)). Background(st.RGB(20, 20, 20)),
PrimaryBtn: st.S(). Padding(0, 2). Background(st.RGB(60, 60, 100)). Foreground(color.White). Focus(st.S(). Bold(true)). Hover(st.S(). Background(st.RGB(80, 80, 140))). Active(st.S(). Background(st.RGB(50, 50, 80))),
DefaultBtn: st.S(). Margin(1, 0, 0, 0),
DangerBtn: st.S(). Margin(1, 0, 0, 0). Padding(0, 2). Border(st.DoubleBorder()). Background(st.RGB(150, 40, 40)). Foreground(color.White). Bold(true). Hover(st.S(). Background(st.RGB(200, 50, 50))),
Title: st.S(). Margin(0, 0, 1, 0). Bold(true). TextAlign(st.TextAlignCenter),
Counter: st.S(). Margin(0, 0, 1, 0). Foreground(st.RGB(100, 255, 100)),
HoverBtn: st.S(). Padding(0, 2). Margin(1, 0, 0, 0). Hover(st.S(). Background(st.RGB(70, 70, 70)). Foreground(color.White)),}
func App() dom.Element { var ( counter *el.BoxElement increment *el.ButtonElement reset *el.ButtonElement )
root := el.Box(styles.Root, el.Box(styles.Title, "Button Component Demonstration"), el.Box(styles.Counter, "Clicks: 0").Ref(&counter), el.Button(styles.PrimaryBtn, "Click Me").Ref(&increment), el.Button(styles.HoverBtn, "Hover Me"), el.Button(styles.DefaultBtn, "Disabled").Disabled(true), el.Button(styles.DangerBtn, "DANGER").Ref(&reset), )
count := 0
increment.OnPress(func() { count++ counter.SetTextf("Clicks: %d", count) })
reset.OnPress(func() { count = 0 counter.SetText("Clicks: 0 (Reset!)") })
return root}Input (examples/input)
Section titled “Input (examples/input)”Run go run ./examples/input to test single-line text fields, placeholders, Tab focus movement, and live change echoes.
type Styles struct { Root st.Style Spacer st.Style FooterRow st.Style Title st.Style TopSeparator st.Style Label st.Style Input st.Style Placeholder st.Style Card st.Style Hint st.Style UsernameValue st.Style}
var styles = Styles{ Root: st.S(). Display(st.DisplayFlex). FlexDirection(st.FlexColumn). JustifyContent(st.JustifyCenter). AlignItems(st.AlignCenter). Width(st.Percent(100)). Height(st.Percent(100)). Background(st.RGB(18, 18, 23)),
Spacer: st.S(). Height(st.Cells(1)),
FooterRow: st.S(). Margin(1, 0, 0, 0),
Title: st.S(). Padding(0, 2). Width(st.Percent(100)). Margin(0, 0, 1, 0). Foreground(st.RGB(200, 210, 255)). Bold(true). TextAlign(st.TextAlignCenter),
TopSeparator: st.S(). Width(st.Percent(100)). Height(st.Cells(1)). Margin(0, 0, 1, 0). Background(st.RGB(45, 48, 65)),
Label: st.S(). Foreground(st.RGB(160, 165, 200)),
Input: st.S(). Width(st.Cells(30)). Padding(0, 1). Border(st.SingleBorder(). Color(st.RGB(60, 65, 90))). Background(st.RGB(22, 24, 35)). Foreground(st.RGB(220, 225, 255)),
Placeholder: st.S(). Foreground(st.RGB(120, 100, 150)). Italic(true),
Card: st.S(). Display(st.DisplayFlex). FlexDirection(st.FlexColumn). Width(st.Cells(36)). Padding(1, 2). Border(st.SingleBorder(). Color(st.RGB(60, 65, 90))). Background(st.RGB(28, 30, 40)),
Hint: st.S(). Foreground(st.RGB(80, 85, 110)),
UsernameValue: st.S(). Foreground(st.RGB(100, 200, 130)). Bold(true),}
func App() dom.Element { var ( form *el.FormElement usernameInp *el.InputElement echo *el.SpanElement feedback *el.BoxElement )
root := el.Box(styles.Root, el.Form(styles.Card, el.Box(styles.Title, "Sign In"), el.Box(styles.TopSeparator), el.Label(styles.Label, "Username").For("username"), el.Input(""). WithID("username"). WithName("username"). WithPlaceholder("Type username..."). Style(styles.Input). Ref(&usernameInp), el.Box(styles.Spacer), el.Label(styles.Label, "Password").For("password"), el.Input(""). WithID("password"). WithName("password"). WithPassword(true). WithPlaceholder("Type password..."). WithPlaceholderStyle(styles.Placeholder). Style(styles.Input), el.Button("Sign In").Type("submit"), el.Box(styles.FooterRow, el.Span(styles.Hint, "Username value: "), el.Span(styles.UsernameValue, "(empty)").Ref(&echo), ), el.Box().Ref(&feedback), ).Ref(&form), )
usernameInp.OnChange(func(v string) { if v == "" { echo.SetText("(empty)") return } echo.SetText(v) })
form.AddEventListener(event.EventSubmit, func(e event.Event) { values := e.(*event.SubmitEvent).FormData if values["username"] == "" || values["password"] == "" { feedback.SetText("Enter a username and password.") return } feedback.SetTextf("Form submitted for %s.", values["username"]) })
return root}TextArea (examples/textarea)
Section titled “TextArea (examples/textarea)”Run go run ./examples/textarea to explore multi-line editing, soft-wrapping, and live caret coordinates.
type Styles struct { Root st.Style Title st.Style TextArea st.Style StatusRow st.Style Hint st.Style StatusValue st.Style}
var styles = Styles{ Root: st.S(). Display(st.DisplayFlex). FlexDirection(st.FlexColumn). AlignItems(st.AlignStart). Width(st.Percent(100)). Height(st.Percent(100)). Padding(1, 2). Background(st.RGB(18, 18, 23)),
Title: st.S(). Padding(0, 2). Margin(0, 0, 1, 0). Foreground(st.RGB(200, 210, 255)). Bold(true),
TextArea: st.S(). Width(st.Cells(50)). Height(st.Cells(10)). Padding(0, 1). Border(st.SingleBorder(). Color(st.RGB(60, 65, 90))). Background(st.RGB(28, 30, 40)). Foreground(st.RGB(220, 225, 255)),
StatusRow: st.S(). Margin(1, 0, 0, 0),
Hint: st.S(). Foreground(st.RGB(80, 85, 110)),
StatusValue: st.S(). Foreground(st.RGB(100, 200, 130)). Bold(true),}
func App() dom.Element { var ( editor *el.TextAreaElement status *el.SpanElement )
root := el.Box(styles.Root, el.Box(styles.Title, "Kite Text Editor"), el.TextArea(""). WithPlaceholder("Type your message here..."). Style(styles.TextArea). Ref(&editor), el.Box(styles.StatusRow, el.Span(styles.Hint, "Status: "), el.Span(styles.StatusValue, "Pos: (0, 0)").Ref(&status), ), )
editor.OnKeyDown(func(*event.KeyEvent) { pos := editor.CaretPosition() status.SetTextf("Pos: (%d, %d)", pos.X, pos.Y) })
return root}Checkbox & Radio (examples/checkbox_radio)
Section titled “Checkbox & Radio (examples/checkbox_radio)”Run go run ./examples/checkbox_radio to toggle a checkbox and switch selections inside a radio group.
type Styles struct { Root st.Style Focus st.Style Checkbox st.Style Title st.Style CheckboxLabel st.Style CheckboxStatus st.Style CheckboxRow st.Style RadioGroupLabel st.Style RadioGroup st.Style RadioStatus st.Style ContentWrapper st.Style}
var styles = Styles{ Root: st.S(). Display(st.DisplayFlex). JustifyContent(st.JustifyCenter). AlignItems(st.AlignCenter). Width(st.Percent(100)). Height(st.Percent(100)). Background(st.RGB(15, 15, 15)),
Focus: st.S(). Focus(st.S(). Foreground(st.RGB(255, 215, 0))),
Checkbox: st.S(). Focus(st.S(). Foreground(st.RGB(255, 215, 0))). Margin(0, 1, 0, 0),
Title: st.S(). Margin(0, 0, 1, 0). Bold(true). TextAlign(st.TextAlignCenter),
CheckboxLabel: st.S(). Margin(0, 1, 0, 0). Bold(true),
CheckboxStatus: st.S(). Foreground(st.RGB(100, 200, 255)),
CheckboxRow: st.S(). Display(st.DisplayFlex). FlexDirection(st.FlexRow). AlignItems(st.AlignCenter). Margin(0, 0, 2, 0),
RadioGroupLabel: st.S(). Margin(0, 0, 1, 0). Bold(true),
RadioGroup: st.S(). Display(st.DisplayFlex). FlexDirection(st.FlexColumn),
RadioStatus: st.S(). Margin(1, 0, 0, 0). Foreground(st.RGB(100, 255, 100)),
ContentWrapper: st.S(). Display(st.DisplayFlex). FlexDirection(st.FlexColumn). JustifyContent(st.JustifyCenter). AlignItems(st.AlignStart). Width(st.Percent(80)). Height(st.Percent(80)). Padding(1, 2). Border(st.SingleBorder()). Background(st.RGB(30, 30, 30)),}
func App() dom.Element { var ( cb *el.CheckboxElement cbStatus *el.BoxElement rg *el.RadioGroupElement radioStatus *el.BoxElement )
root := el.Box(styles.Root, el.Box(styles.ContentWrapper, el.Box(styles.Title, "Checkbox and Radio Components"), el.Label(styles.CheckboxRow, el.Span(styles.CheckboxLabel, "Checkbox:"), el.Checkbox(false).Style(styles.Checkbox).Ref(&cb), el.Box(styles.CheckboxStatus, "Unchecked").Ref(&cbStatus), ), el.Box(styles.RadioGroupLabel, "Radio Group:"), el.RadioGroup(styles.RadioGroup, el.Label(el.Radio("option1").Style(styles.Focus), " Option 1"), el.Label(el.Radio("option2").Style(styles.Focus), " Option 2"), el.Label(el.Radio("option3").Style(styles.Focus), " Option 3"), ).Ref(&rg), el.Box(styles.RadioStatus, "None selected").Ref(&radioStatus), ), )
cb.OnChange(func(checked bool) { if checked { cbStatus.SetText("Checked") return } cbStatus.SetText("Unchecked") })
rg.OnChange(func(val string) { radioStatus.SetText("Selected: " + val) })
return root}Select (examples/select)
Section titled “Select (examples/select)”Run go run ./examples/select to open a dropdown overlay and pick an option with keyboard or mouse.
type Styles struct { Dropdown st.Style Title st.Style PickLabel st.Style PickerRow st.Style SelectedStatus st.Style StatusRow st.Style Card st.Style Root st.Style}
var styles = Styles{ Dropdown: st.S(). Width(st.Cells(25)),
Title: st.S(). Margin(0, 0, 1, 0). Background(st.RGB(60, 60, 120)). Foreground(color.White). Bold(true). TextAlign(st.TextAlignCenter),
PickLabel: st.S(). Bold(true),
PickerRow: st.S(). Display(st.DisplayFlex). FlexDirection(st.FlexRow). AlignItems(st.AlignCenter). Gap(0, 1). Margin(1, 0, 2, 0),
SelectedStatus: st.S(). Foreground(st.RGB(100, 255, 100)). Bold(true),
StatusRow: st.S(). Margin(0, 0, 2, 0). Border( st.SingleBorder(). Left(false). Right(false). Top(false). Color(st.RGB(50, 50, 50)), ),
Card: st.S(). Display(st.DisplayFlex). FlexDirection(st.FlexColumn). JustifyContent(st.JustifyStart). AlignItems(st.AlignStart). Width(st.Cells(50)). Height(st.Auto). Padding(1, 3). Border(st.SingleBorder().Color(st.RGB(100, 100, 100))). Background(st.RGB(30, 30, 30)),
Root: st.S(). Display(st.DisplayFlex). JustifyContent(st.JustifyCenter). AlignItems(st.AlignCenter). Width(st.Percent(100)). Height(st.Percent(100)). Background(st.RGB(15, 15, 20)),}
func App() dom.Element { var ( sel *el.SelectElement status *el.SpanElement )
root := el.Box(styles.Root, el.Box(styles.Card, el.Box(styles.Title, "Select Component Demo"), el.Box(styles.PickerRow, el.Span(styles.PickLabel, "Pick a language:"), el.Select(styles.Dropdown, el.Option("Go", "go"), el.Option("Rust", "rust"), el.Option("C++", "cpp"), el.Option("Zig", "zig"), el.Option("Python", "python"), el.Option("TypeScript", "ts"), ).Ref(&sel), ), el.Box(styles.StatusRow, "Selected: ", el.Span(styles.SelectedStatus, "(none)").Ref(&status), ), ), )
sel.OnChange(func(value string) { status.SetText(value) })
return root}Dialog (examples/dialog)
Section titled “Dialog (examples/dialog)”Run go run ./examples/dialog to open and dismiss a modal element.Dialog with focus trapping.
type Styles struct { Title st.Style Hint st.Style Button st.Style Root st.Style Dialog st.Style}
var styles = Styles{ Title: st.S(). Padding(1). Bold(true). TextAlign(st.TextAlignCenter),
Hint: st.S(). Foreground(st.RGB(148, 163, 184)). Margin(0, 0, 1, 0). TextAlign(st.TextAlignCenter),
Button: st.S(). Border(st.EmptyBorder()). Padding(0, 1). Background(st.RGB(30, 58, 95)). Foreground(st.RGB(248, 250, 252)). Bold(true),
Root: st.S(). Display(st.DisplayFlex). FlexDirection(st.FlexColumn). AlignItems(st.AlignCenter). Width(st.Percent(100)). Height(st.Percent(100)). Background(st.RGB(20, 20, 20)),
Dialog: st.S(). Display(st.DisplayFlex). FlexDirection(st.FlexColumn). AlignItems(st.AlignCenter). Gap(1, 0). Width(st.Cells(34)). Padding(1, 2). Border(st.SingleBorder()). Background(st.RGB(60, 60, 100)),}
func App() dom.Element { var ( openBtn *el.ButtonElement closeBtn *el.ButtonElement )
dialog := el.Dialog(el.Box(styles.Dialog, el.Box("Hello! I am a Dialog."), el.Box(styles.Hint, "[Enter / Esc] close"), el.Button(styles.Button, "Close").Ref(&closeBtn), )).ZIndex(100)
root := el.Box(styles.Root, el.Box(styles.Title, "Dialog Example"), el.Box(styles.Hint, "Press [d] or click below to open · [Enter / Esc] to close"), el.Button(styles.Button, "Open Dialog").Ref(&openBtn), )
openDialog := func() { if !dialog.IsConnected() { root.AddChild(dialog) } } closeDialog := func() { root.RemoveChild(dialog) } openBtn.OnPress(openDialog) closeBtn.OnPress(closeDialog)
var keySub event.Subscription root.OnConnect(func() { doc := root.OwnerDocument() keySub = doc.AddEventListener(event.EventKeyDown, func(e event.Event) { key, ok := e.(*event.KeyEvent) if !ok { return }
switch { case key.MatchString("d"): openDialog() case dialog.IsConnected() && (key.MatchString("enter") || key.MatchString("escape")): closeDialog() e.StopPropagation() } }) }) root.OnDisconnect(func() { keySub.Cancel() })
return root}Overlay (examples/overlay)
Section titled “Overlay (examples/overlay)”Run go run ./examples/overlay to toggle a centered top-layer overlay via doc.ShowOverlay and doc.HideOverlay.
type Styles struct { Root st.Style Title st.Style Hint st.Style ToggleBtn st.Style OverlayTitle st.Style OverlayHint st.Style OverlayBox st.Style OverlayWrapper st.Style Shortcut st.Style}
var styles = Styles{ Root: st.S(). Display(st.DisplayFlex). FlexDirection(st.FlexColumn). AlignItems(st.AlignCenter). Width(st.Percent(100)). Height(st.Percent(100)). Padding(2). Background(st.RGB(20, 20, 30)),
Title: st.S(). Width(st.Percent(100)). Padding(1). Background(st.RGB(50, 50, 80)). Bold(true). TextAlign(st.TextAlignCenter),
Hint: st.S(). Margin(1, 0). Foreground(st.RGB(148, 163, 184)). TextAlign(st.TextAlignCenter),
ToggleBtn: st.S(). Border(st.EmptyBorder()). Padding(0, 1). Background(st.RGB(30, 58, 95)). Foreground(st.RGB(248, 250, 252)). Bold(true),
OverlayTitle: st.S(). Margin(0, 0, 1, 0). Bold(true). TextAlign(st.TextAlignCenter),
OverlayHint: st.S(). Margin(1, 0, 0, 0),
OverlayBox: st.S(). Width(st.Cells(42)). Padding(1, 2). Border(st.DoubleBorder(). Color(st.RGB(255, 100, 100))). Background(st.RGB(80, 40, 40)),
OverlayWrapper: st.S(). Display(st.DisplayFlex). JustifyContent(st.JustifyCenter). AlignItems(st.AlignCenter). Width(st.Percent(100)). Height(st.Percent(100)),
Shortcut: st.S(). Bold(true),}
func App() dom.Element { var ( openBtn, closeBtn *el.ButtonElement )
overlay := el.Box(styles.OverlayWrapper, el.Box(styles.OverlayBox, el.Box(styles.OverlayTitle, "I am an Overlay!"), "I am rendered in the Top Layer,\nabove the normal document flow.", el.Box(styles.OverlayHint, el.Span(styles.Shortcut, "[o]"), " close overlay", ), el.Box(styles.OverlayHint, el.Button(styles.ToggleBtn, "Close Overlay").Ref(&closeBtn), ), ), )
root := el.Box(styles.Root, el.Box(styles.Title, "Overlay API Example"), el.Box(styles.Hint, "Press [o] or click below to show/hide the top-layer overlay."), el.Button(styles.ToggleBtn, "Toggle Overlay").Ref(&openBtn), )
overlayVisible := false toggleOverlay := func() { doc := root.OwnerDocument() if doc == nil { return } if overlayVisible { doc.HideOverlay(overlay) overlayVisible = false return } doc.ShowOverlay(overlay, 100) overlayVisible = true }
openBtn.OnPress(toggleOverlay) closeBtn.OnPress(toggleOverlay)
var keySub event.Subscription root.OnConnect(func() { doc := root.OwnerDocument() if doc == nil { return }
keySub = doc.AddEventListener(event.EventKeyDown, func(e event.Event) { ke, ok := e.(*event.KeyEvent) if !ok { return }
if ke.MatchString("o") { toggleOverlay() } }) })
root.OnDisconnect(func() { if overlayVisible { if doc := root.OwnerDocument(); doc != nil { doc.HideOverlay(overlay) } overlayVisible = false } if keySub != nil { keySub.Cancel() keySub = nil } })
return root}Overlay Tweaks (examples/overlay_tweaks)
Section titled “Overlay Tweaks (examples/overlay_tweaks)”Run go run ./examples/overlay_tweaks to switch element.Overlay anchor placement (Top, Bottom, Left, Right) and toggle edge flipping.
type Styles struct { Anchor st.Style BoldLabel st.Style InfoText st.Style Hint st.Style Toolbar st.Style Button st.Style AnchorWrapper st.Style ContentContainer st.Style Title st.Style Root st.Style Overlay st.Style}
var styles = Styles{ Anchor: st.S(). Width(st.Cells(12)). Padding(1, 2). Border(st.SingleBorder()). Background(st.RGB(0, 128, 0)). Foreground(color.White),
BoldLabel: st.S(). Bold(true),
InfoText: st.S(). Foreground(st.RGB(255, 255, 0)),
Hint: st.S(). Foreground(st.RGB(148, 163, 184)). Margin(0, 0, 1, 0),
Toolbar: st.S(). Display(st.DisplayFlex). FlexDirection(st.FlexRow). Gap(0, 1). Margin(1, 0, 0, 0),
Button: st.S(). Border(st.EmptyBorder()). Padding(0, 1). Background(st.RGB(35, 45, 65)). Foreground(color.White),
AnchorWrapper: st.S(). Margin(4, 20),
ContentContainer: st.S(). Padding(1, 2),
Title: st.S(). Padding(1). Background(st.RGB(50, 50, 50)). TextAlign(st.TextAlignCenter),
Root: st.S(). Width(st.Percent(100)). Height(st.Percent(100)). Background(st.RGB(20, 20, 20)),
Overlay: st.S(). Padding(0, 1). Border(st.DoubleBorder()). Background(st.RGB(128, 0, 0)),}
func App() dom.Element { var ( anchor, info *el.BoxElement topBtn, bottomBtn, leftBtn, rightBtn, flipBtn *el.ButtonElement )
root := el.Box(styles.Root, el.Box(styles.Title, "Overlay Tweaks Example"), el.Box(styles.ContentContainer, el.Box(styles.InfoText, "Placement: Bottom | Flip: true").Ref(&info), el.Box(styles.Hint, "Press [1-4] or click a button to place · [f] to toggle flip"), el.Box(styles.Toolbar, el.Button(styles.Button, "[1] Top").Ref(&topBtn), el.Button(styles.Button, "[2] Bottom").Ref(&bottomBtn), el.Button(styles.Button, "[3] Left").Ref(&leftBtn), el.Button(styles.Button, "[4] Right").Ref(&rightBtn), el.Button(styles.Button, "[f] Flip").Ref(&flipBtn), ), el.Box(styles.AnchorWrapper, el.Box(styles.Anchor, "ANCHOR").Ref(&anchor), ), ), )
overlay := el.Overlay(anchor, styles.Overlay, el.Box(styles.BoldLabel, "I am an Overlay"), el.Box("Try moving me!"), ). WithPlacement(geom.PlacementBottom). WithFlip(true). WithZIndex(100) root.AddChild(overlay)
updateInfo := func() { info.SetTextf("Placement: %s | Flip: %v", placementLabel(overlay.Placement()), overlay.Flip()) }
setPlacement := func(p geom.Placement) { overlay.WithPlacement(p) updateInfo() }
toggleFlip := func() { overlay.WithFlip(!overlay.Flip()) updateInfo() }
topBtn.OnPress(func() { setPlacement(geom.PlacementTop) }) bottomBtn.OnPress(func() { setPlacement(geom.PlacementBottom) }) leftBtn.OnPress(func() { setPlacement(geom.PlacementLeft) }) rightBtn.OnPress(func() { setPlacement(geom.PlacementRight) }) flipBtn.OnPress(toggleFlip)
var keySub event.Subscription root.OnConnect(func() { doc := root.OwnerDocument() keySub = doc.AddEventListener(event.EventKeyDown, func(e event.Event) { key, ok := e.(*event.KeyEvent) if !ok { return }
switch { case key.MatchString("1"): setPlacement(geom.PlacementTop) case key.MatchString("2"): setPlacement(geom.PlacementBottom) case key.MatchString("3"): setPlacement(geom.PlacementLeft) case key.MatchString("4"): setPlacement(geom.PlacementRight) case key.MatchString("f"): toggleFlip() } }) }) root.OnDisconnect(func() { keySub.Cancel() })
return root}
func placementLabel(p geom.Placement) string { switch p { case geom.PlacementTop: return "Top" case geom.PlacementBottom: return "Bottom" case geom.PlacementLeft: return "Left" case geom.PlacementRight: return "Right" default: return "" }}