kit

package
v1.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package kit is Godwit's component set: shadcn/ui Nova looks (neutral) built on mygo's *Base widgets. Colors come only from theme.Of(c); variants are arguments, not method chains.

Index

Constants

View Source
const (
	ToastSuccess = "success"
	ToastWarning = "warning"
	ToastError   = "error"
)

The kinds of toast, for ui.Toast's Type; "" is a plain one.

Variables

View Source
var BackdropBlur = true

BackdropBlur turns the dialogs' backdrop blur on. Tests turn it off: the CPU renderer the Tester draws with blurs pixel by pixel, which under -race runs every dialog test many times slower.

Functions

func Alert

func Alert(c *ui.Context, kind AlertKind, text string, actions func()) ui.Element

Alert is a bordered message bar with optional actions after the text.

func AlertAction

func AlertAction(c *ui.Context, kind AlertKind, label string, onClick func()) ui.Element

AlertAction is a solid button for an Alert's actions: filled with the kind's text color and white text (the kind's background in dark) (Info: Primary with PrimaryText).

func Avatar

func Avatar(c *ui.Context, name string) ui.Element

Avatar is a rounded square with the initial of name, labelled name, in a label color the name picks, so each sender keeps theirs.

func AvatarImage added in v0.3.0

func AvatarImage(c *ui.Context, name string, image ui.ImageSource) ui.Element

AvatarImage shows an image in its own colors, with the same labelled square and size as the initial placeholder.

func Badge

func Badge(c *ui.Context, text string) ui.Element

Badge is a small gray label.

func Button

func Button(c *ui.Context, label string, o ButtonOpts) ui.Element

Button is a button of a label.

func ButtonFrame

func ButtonFrame(c *ui.Context, o ButtonOpts) ui.Element

ButtonFrame is the styled button without children; it is never Disabled (no label for the cover).

func ButtonGroup

func ButtonGroup(c *ui.Context, items ...GroupItem) ui.Element

ButtonGroup is bordered icon buttons side by side, split by hairlines; the icons are Foreground, not a lone icon button's Muted.

func Card

func Card(c *ui.Context, body func()) ui.Element

Card is a bordered panel.

func CardFooter

func CardFooter(c *ui.Context, children func())

CardFooter is a right-aligned row for a Card's actions.

func CardHeader

func CardHeader(c *ui.Context, title, description string)

CardHeader is a Card's title with an optional description under it.

func Checkbox

func Checkbox(c *ui.Context, on *bool, label string) ui.Element

Checkbox is a 16×16 check box before its label.

func Collapsible

func Collapsible(c *ui.Context, open *bool, trigger, panel func()) ui.Element

Collapsible is a muted, small trigger row with a turning chevron, and panel below it while *open. *open must outlive the frame. It returns the trigger.

func Dialog

func Dialog(c *ui.Context, open *bool, title string, o DialogOpts, body, footer func())

Dialog is a modal panel anchored near the top: a header with the title, the description and a close button, a scrolling body, and a footer bar holding footer's buttons at the end. body and footer may be nil. Escape, a click outside and the close button close it.

func DialogShown added in v0.1.0

func DialogShown() bool

DialogShown reports whether a Dialog was built since it was last called, and forgets it. A window on a transparent material paints itself opaque under one: the backdrop's blur covers only what is opaque, and sharp text on the material would show through it.

func Elevate

func Elevate(c *ui.Context, e ui.Element, s theme.Elevation) ui.Element

Elevate gives e the shadow s, each layer in the ink: dark in either appearance, as shadcn's black shadows are.

func Empty

func Empty(c *ui.Context, o EmptyOpts) ui.Element

Empty is a centered empty state: an icon tile, a title, a description and actions; Dashed draws a dashed frame around it.

func EmptyAction

func EmptyAction(c *ui.Context, label string, o ButtonOpts) ui.Element

EmptyAction is a button for Empty's Actions: the default size, 12 to each side as the design's.

func Field

func Field(c *ui.Context, label, help, errText string, control func())

Field is a labelled form control with help text, or an error in its place.

func Float

func Float(c *ui.Context, e ui.Element) ui.Element

Float makes e a floating input box: light, the ShadowFloat ring and lift (no border: the ring is its outline); dark, a FloatInset inner edge (an inset shadow, no border).

func Frost added in v0.3.0

func Frost(c *ui.Context) ui.Material

Frost fills a row with the page's background over what is behind it blurred: plain at rest, frosted glass as a drag lifts the row over others.

func Gallery(c *ui.Context, g *GalleryState)

Gallery shows every kit component, section by section. Dev builds only.

func IconButton

func IconButton(c *ui.Context, icon, label string, o ButtonOpts) ui.Element

IconButton is a square button showing only an icon, named label for assistive technology and tests. A SizeXs one, 16 round, holds a 12 icon.

func Input

func Input(c *ui.Context, s *string, o InputOpts) ui.Element

Input is a 32-high single-line text input.

func InputGroup added in v1.3.0

func InputGroup(c *ui.Context, o InputOpts) ui.Element

InputGroup is a 32-high input frame for a bare input and its icons or actions. It shares Input's border, shadow, error and focus styles; o uses Invalid and Flat.

func Kbd

func Kbd(c *ui.Context, text string) ui.Element

Kbd shows a key or shortcut.

func LabelChip added in v0.3.0

func LabelChip(c *ui.Context, o LabelChipOpts) ui.Element

LabelChip is a mail label's chip: 20 high, its icon and name in the label's color.

func List

func List(c *ui.Context, s *ui.ListState, n int, row func(i int)) ui.Element

List is ui.List with the selected rows in the sidebar's selected gray and the foreground, not mygo's accent (the primary, near-black). mygo styles a row from the theme current when it builds it, so the rows' content gets the frame's own theme back.

func NavSwitch(c *ui.Context, items ...NavItem) ui.Element

NavSwitch is a segmented row of page links on the window material: the page shown raised on the background in the fill icon, the others muted.

func Panel

func Panel(c *ui.Context, radius float32) ui.Element

Panel is a region of a page on the window material, as the mail list or the reading pane: a white card in the border's hairline with ShadowXs, corners of radius. Give it its size and Children.

func Popover

func Popover(c *ui.Context, anchor ui.Element, open *bool, body func())

Popover is a panel below anchor while *open; a press outside or Escape closes it.

func Pressable

func Pressable(c *ui.Context, o PressableOpts) ui.Element

Pressable is a clickable surface for content the caller builds, left-aligned. Give it its Label, Padding, Gap and Children. A selected one does not click.

func Radio

func Radio[T comparable](c *ui.Context, sel *T, v T, label string) ui.Element

Radio is a radio button choosing v into *sel.

func Resizer

func Resizer(c *ui.Context, size *float32, gap float32, over bool, label string, onClick func(), first, second func()) (changed, dragging bool)

Resizer is first, *size wide, beside second, with a gap of gap between them that the user drags (or, focused, moves with the arrows) to set *size, as Claude's: hovered, dragged or focused, a GripWidth line of the foreground at 20% shows down the gap's middle, and hovering that names it (label) beside it. It reports whether *size changed, and whether the grip is being dragged; the caller clamps *size. onClick, if any, is what a click on the grip does. With over, the panels touch (they differ enough to need no gap, as a sidebar and the content beside it): the grip, gap wide, rides second's edge (its Hairline border) down the middle, reaching as little into either. Gap is then GripWidth: first's scroll bar keeps further from its edge than the grip reaches, so the grip runs beside it, not over it.

func Select

func Select[T comparable](c *ui.Context, sel *T, opts []Option[T]) ui.Element

Select is a 32-high select of opts; give it a Label.

func SelectWith

func SelectWith[T comparable](c *ui.Context, o SelectOpts, sel *T, opts []Option[T]) ui.Element

SelectWith is Select styled by o.

func Separator

func Separator(c *ui.Context, vertical bool) ui.Element

Separator is a hairline: horizontal across its parent, or a short vertical one. In a row, give it Grow(1).

func SidebarChevron added in v1.5.0

func SidebarChevron(c *ui.Context, open float32) ui.Element

SidebarChevron is a sidebar row's 12 muted chevron, turned a quarter at open 1.

func SidebarCollapsible added in v1.5.0

func SidebarCollapsible(c *ui.Context, open *bool, muted bool, trigger, panel func()) ui.Element

SidebarCollapsible is a sidebar row (SidebarItem's size and padding) that folds the rows below it: trigger's children, then a 12 chevron at its right, turned a quarter while open. Muted is a group's title: small muted text. *open must outlive the frame. It returns the trigger.

func SidebarIcon

func SidebarIcon(c *ui.Context, item ui.Element, icon string, selected bool)

SidebarIcon is a SidebarItem's leading icon: muted line style until item is hovered; selected, the foreground fill style.

func SidebarItem

func SidebarItem(c *ui.Context, o SidebarItemOpts) ui.Element

SidebarItem is a row of a page's sidebar, its children left-aligned: 32 high, highlighted while selected or hovered. Give it its Children.

func Skeleton

func Skeleton(c *ui.Context, w, h float32) ui.Element

Skeleton is a pulsing placeholder w wide (0: the full width) and h high. It stays still under ReduceMotion, which Loop does not honor itself.

func Spinner

func Spinner(c *ui.Context) ui.Element

Spinner shows that something is under way.

func StatusDot

func StatusDot(c *ui.Context, s Status) ui.Element

StatusDot is a 6×6 dot: green OK, amber Attention (clears by itself), red Error (needs the user).

func SwapButton added in v1.5.0

func SwapButton(c *ui.Context, label string, o ButtonOpts, others ...string) ui.Element

SwapButton is a Button whose label changes in place, as Copy turning into Copied: the old label fades out as the new one fades in. It is as wide as the widest of label and others, the labels it may show, and its content starts at its left edge, so neither it nor its icon moves.

func Switch

func Switch(c *ui.Context, on *bool) ui.Element

Switch is a 32×18 switch; give it a Label.

func SwitchRow

func SwitchRow(c *ui.Context, on *bool, label, help string) ui.Element

SwitchRow is a full-width switch named label in the settings row shape (8/16 padding, at least 48 high): label and help on the left, the track on the right; a click anywhere on the row toggles it.

func Tabs

func Tabs(c *ui.Context, sel *int, labels ...string) ui.Element

Tabs is a segmented tab list choosing *sel.

func TabsUnderline

func TabsUnderline(c *ui.Context, sel *int, labels ...string) ui.Element

TabsUnderline is Tabs as a row over a hairline, in Base type: Muted, the chosen tab Foreground and 600 over a Primary bottom border.

func Text

func Text(c *ui.Context, s string, size float32) ui.Element

Text is text at a step of the text scale with that step's line height. Leaves only: a line height passes down as a multiplier, so on a container it would reach texts of other sizes.

func TextArea

func TextArea(c *ui.Context, s *string, o InputOpts) ui.Element

TextArea is a multi-line text input.

func TextLink(c *ui.Context, label string, color ui.Color, size float32) ui.Element

TextLink is an underlined text button of size in color (a notice's action).

func ToastHost

func ToastHost(c *ui.Context, closeLabel string)

ToastHost draws the window's toasts (c.Toast, c.AddToast) centered under the top bar, the oldest first and at most theme.ToastMax; call it once in the view. closeLabel names the close buttons (pass the translated "Close"). A success, warning or error toast is tinted: its color's 50 behind, 200 around, 700 for the text and its leading icon; a plain one is white, without an icon.

func ToggleGroup

func ToggleGroup(c *ui.Context, label string, fn func()) ui.Element

ToggleGroup groups the buttons fn builds: one Tab stop, the arrow keys move between them.

func Tooltip

func Tooltip(c *ui.Context, anchor ui.Element, text string)

Tooltip shows text by anchor on keyboard focus at once and on hover after a pause, and describes anchor to assistive technology.

func TooltipLabelled

func TooltipLabelled(c *ui.Context, anchor ui.Element, text string)

TooltipLabelled is Tooltip for an anchor whose Label already says text.

Types

type AlertKind

type AlertKind int

AlertKind is an Alert's look.

const (
	Warning AlertKind = iota
	Danger
	Info
)

type ButtonOpts

type ButtonOpts struct {
	Variant  Variant
	Size     ButtonSize
	Disabled bool
	Flat     bool // Outline without its shadow
	Icon     string
}

ButtonOpts style a button. Icon is an icons name shown before the label.

type ButtonSize

type ButtonSize int

ButtonSize is a button's height; the zero value is the 32 px default.

const (
	SizeDefault ButtonSize = iota
	SizeXs                 // IconButton only, round
	SizeSm
	SizeLg
)

type DialogOpts added in v0.1.0

type DialogOpts struct {
	Size        DialogSize
	Desc, Close string
	Danger      bool
}

DialogOpts are a dialog's size, the muted line under its title, the label of its close button, and Danger, which tints the footer for a confirmation.

type DialogSize added in v0.1.0

type DialogSize uint8

DialogSize is a dialog's width: DialogMd for a form, DialogSm for a confirmation, DialogLg for a larger form.

const (
	DialogMd DialogSize = iota
	DialogSm
	DialogLg
)

type EmptyOpts

type EmptyOpts struct {
	Icon, Title, Desc string
	Actions           func()
	Dashed            bool
}

EmptyOpts fill an Empty. Actions builds the buttons under the text.

type GalleryState

type GalleryState struct {
	Switch, Switch2, Check                bool
	Radio, Select, Tabs                   int
	Toggle                                int
	Input, Password, Mono, Bare, Area     string
	InvalidIn, HelpIn, ErrorIn            string
	Dialog, Confirm, Popover, Collapsible bool
}

GalleryState holds the values the gallery's controls edit.

type GroupItem

type GroupItem struct {
	Icon, Tip string
	OnClick   func()
	Disabled  bool
}

GroupItem is one icon button of a ButtonGroup; Tip is its tooltip and label.

type InputOpts

type InputOpts struct {
	Placeholder             string
	Password, Mono, Invalid bool
	Bare                    bool // raw Base geometry: the row around it draws the box
	Flat                    bool // no shadow
}

InputOpts style a text input.

type LabelChipOpts added in v0.3.0

type LabelChipOpts struct {
	Text, Icon, Tip string
	Color           theme.LabelColor
	Auto            bool
	OnClick         func() // set: the chip is a button
	OnRemove        func() // set: a trailing × named RemoveLabel
	RemoveLabel     string
}

LabelChipOpts is a mail label as a chip. Icon is a label icon's name without the "label-" prefix; Tip shows on hover. Auto draws the chip the model set: the same color, an edge instead of a fill.

type NavItem struct {
	Icon, Label string
	Selected    bool // the page shown: raised, and it does not click
	OnClick     func()
}

NavItem is a page a NavSwitch goes to.

type Option

type Option[T comparable] struct {
	Value T
	Label string
}

Option is one choice of a Select.

type PressableOpts

type PressableOpts struct {
	Selected, Bordered bool
	Bare               bool // no hover or selected background: the caller draws its own
	OnClick            func()
}

PressableOpts say how a Pressable looks and what clicking it does.

type SelectOpts

type SelectOpts struct {
	Radius, MinWidth, MaxWidth float32
	Flat                       bool
}

SelectOpts style a SelectWith: zero Radius is Md, zero MinWidth the default, zero MaxWidth unbounded; Flat drops the shadow.

type SidebarItemOpts

type SidebarItemOpts struct {
	Selected bool    // the page shown: highlighted, and it does not click
	Muted    bool    // a secondary action, as Add account
	Small    bool    // 30 high in the small text, as an account's header
	Indent   float32 // more left padding, in spacing steps, as a folder under its account
	OnClick  func()
}

SidebarItemOpts says how a sidebar row looks and what clicking it does.

type Status

type Status int

Status is what a StatusDot tells.

const (
	OK Status = iota
	Attention
	Error
)

type Variant

type Variant int

Variant is a button's look.

const (
	Default Variant = iota
	Secondary
	Outline
	Ghost
	Destructive
	Link
	DestructiveOutline
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL