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
- Variables
- func Alert(c *ui.Context, kind AlertKind, text string, actions func()) ui.Element
- func AlertAction(c *ui.Context, kind AlertKind, label string, onClick func()) ui.Element
- func Avatar(c *ui.Context, name string) ui.Element
- func AvatarImage(c *ui.Context, name string, image ui.ImageSource) ui.Element
- func AvatarSized(c *ui.Context, name string, size float32) ui.Element
- func Badge(c *ui.Context, text string) ui.Element
- func Bar(fill ui.Color) ui.Material
- func Button(c *ui.Context, label string, o ButtonOpts) ui.Element
- func ButtonFrame(c *ui.Context, o ButtonOpts) ui.Element
- func ButtonGroup(c *ui.Context, items ...GroupItem) ui.Element
- func Card(c *ui.Context, body func()) ui.Element
- func CardFooter(c *ui.Context, children func())
- func CardHeader(c *ui.Context, title, description string)
- func Checkbox(c *ui.Context, on *bool, label string) ui.Element
- func Collapsible(c *ui.Context, open *bool, trigger, panel func()) ui.Element
- func Dialog(c *ui.Context, open *bool, title string, o DialogOpts, body, footer func())
- func DialogShown() bool
- func Elevate(c *ui.Context, e ui.Element, s theme.Elevation) ui.Element
- func Empty(c *ui.Context, o EmptyOpts) ui.Element
- func EmptyAction(c *ui.Context, label string, o ButtonOpts) ui.Element
- func Field(c *ui.Context, label, help, errText string, control func())
- func Frost(fill ui.Color) ui.Material
- func Gallery(c *ui.Context, g *GalleryState)
- func GroupDivider(c *ui.Context) ui.Element
- func HoverCard(c *ui.Context, anchor ui.Element, w float32, body func())
- func IconButton(c *ui.Context, icon, label string, o ButtonOpts) ui.Element
- func Input(c *ui.Context, s *string, o InputOpts) ui.Element
- func InputGroup(c *ui.Context, o InputOpts) ui.Element
- func Kbd(c *ui.Context, text string) ui.Element
- func LabelChip(c *ui.Context, o LabelChipOpts) ui.Element
- func LiquidGlass(tint ui.Color) ui.Material
- func List(c *ui.Context, s *ui.ListState, n int, row func(i int)) ui.Element
- func MenuAt(c *ui.Context, anchor ui.Element, open *bool, at, self ui.Anchor, ...)
- func MenuItem(c *ui.Context, selected bool) ui.Element
- func MenuLabel(c *ui.Context, text string) ui.Element
- func NavSwitch(c *ui.Context, items ...NavItem) ui.Element
- func NewFrame()
- func Palette(c *ui.Context, open *bool, query *string, o PaletteOpts, head, body func())
- func PaletteChip(c *ui.Context, label, remove string) ui.Element
- func PalettePreview(c *ui.Context, body func())
- func PaletteRow(c *ui.Context, selected bool) ui.Element
- func PaletteTab(c *ui.Context, label string, chosen bool) ui.Element
- func Panel(c *ui.Context, radius float32) ui.Element
- func Popover(c *ui.Context, anchor ui.Element, open *bool, body func())
- func PopoverAt(c *ui.Context, anchor ui.Element, open *bool, at, self ui.Anchor, ...)
- func Pressable(c *ui.Context, o PressableOpts) ui.Element
- func Radio[T comparable](c *ui.Context, sel *T, v T, label string) ui.Element
- func RadioCard[T comparable](c *ui.Context, sel *T, v T, label, help string) ui.Element
- func Resizer(c *ui.Context, size *float32, gap float32, over bool, label string, ...) (changed, dragging bool)
- func RoundAction(c *ui.Context, icon, name, tip string, disabled, on bool) ui.Element
- func Select[T comparable](c *ui.Context, sel *T, opts []Option[T]) ui.Element
- func SelectWith[T comparable](c *ui.Context, o SelectOpts, sel *T, opts []Option[T]) ui.Element
- func Separator(c *ui.Context, vertical bool) ui.Element
- func SidebarChevron(c *ui.Context, open float32) ui.Element
- func SidebarCollapsible(c *ui.Context, open *bool, muted bool, trigger, panel func()) ui.Element
- func SidebarIcon(c *ui.Context, item ui.Element, icon string, selected bool)
- func SidebarItem(c *ui.Context, o SidebarItemOpts) ui.Element
- func Skeleton(c *ui.Context, w, h float32) ui.Element
- func Spinner(c *ui.Context) ui.Element
- func StatusDot(c *ui.Context, s Status) ui.Element
- func SwapButton(c *ui.Context, label string, o ButtonOpts, others ...string) ui.Element
- func Switch(c *ui.Context, on *bool) ui.Element
- func SwitchRow(c *ui.Context, on *bool, label, help string) ui.Element
- func Tabs(c *ui.Context, sel *int, labels ...string) ui.Element
- func TabsFill(c *ui.Context, sel *int, labels ...string) ui.Element
- func TabsUnderline(c *ui.Context, sel *int, labels ...string) ui.Element
- func TemplateField(c *ui.Context, value *string, o TemplateOpts) ui.Element
- func Text(c *ui.Context, s string, size float32) ui.Element
- func TextArea(c *ui.Context, s *string, o InputOpts) ui.Element
- func TextLink(c *ui.Context, label string, color ui.Color, size float32) ui.Element
- func ToastHost(c *ui.Context, closeLabel string)
- func ToggleGroup(c *ui.Context, label string, fn func()) ui.Element
- func Tooltip(c *ui.Context, anchor ui.Element, text string)
- func TooltipLabelled(c *ui.Context, anchor ui.Element, text string)
- func WebView(c *ui.Context, v ui.NativeWebView) ui.Element
- type AlertKind
- type ButtonOpts
- type ButtonSize
- type DialogOpts
- type DialogSize
- type EmptyOpts
- type GalleryState
- type GlassMaterial
- type GroupItem
- type InputOpts
- type LabelChipOpts
- type NavItem
- type Option
- type PaletteHint
- type PaletteOpts
- type PressableOpts
- type SelectOpts
- type SidebarItemOpts
- type Status
- type TemplateOpts
- type TemplateToken
- type Variant
Constants ¶
const ( ToastSuccess = "success" ToastWarning = "warning" ToastError = "error" )
The kinds of toast, for ui.Toast's Type; "" is a plain one.
Variables ¶
var BackdropBlur = true
BackdropBlur turns the frosted panels' 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.
var Glass bool
Glass frosts the panels of dialogs and the search palette: set where the window sits on a material (Deps.Vibrancy); elsewhere they are opaque. The backdrop under them only tints the window.
Functions ¶
func AlertAction ¶
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 ¶
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
AvatarImage shows an image in its own colors, with the same labelled square and size as the initial placeholder.
func AvatarSized ¶ added in v1.22.0
AvatarSized is Avatar size wide, its initial grown in step.
func Bar ¶ added in v1.19.0
Bar fills a bar the content scrolls under (the reader's toolbar and reply bar) with fill over what is behind it blurred. The blur cannot see a native view: a web view's page under it blurs itself (the reader's BodyGlass).
func ButtonFrame ¶
func ButtonFrame(c *ui.Context, o ButtonOpts) ui.Element
ButtonFrame is the styled button without children.
func ButtonGroup ¶
ButtonGroup is ghost icon buttons side by side, unframed; GroupDivider parts groups. The icons are Foreground, not a lone icon button's Muted.
func CardFooter ¶
CardFooter is a right-aligned row for a Card's actions.
func CardHeader ¶
CardHeader is a Card's title with an optional description under it.
func Collapsible ¶
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 panel's frost covers only what is opaque, and sharp text on the material would show through it.
func Elevate ¶
Elevate gives e the shadow s, each layer in the ink: dark in either appearance, as shadcn's black shadows are.
func Empty ¶
Empty is a centered empty state: an icon tile, a title, a description and actions; Dashed draws a dashed frame around it.
func EmptyAction ¶
EmptyAction is a button for Empty's Actions: the default size, 12 to each side as the design's.
func Frost ¶ added in v0.3.0
Frost fills a row with fill (the surface it sits on) over what is behind it blurred: plain at rest, frosted glass as a drag lifts the row over others.
func Gallery ¶
func Gallery(c *ui.Context, g *GalleryState)
Gallery shows every kit component, section by section. Dev builds only.
func GroupDivider ¶ added in v1.18.0
GroupDivider is the hairline between ButtonGroups in a toolbar.
func HoverCard ¶ added in v1.19.0
HoverCard shows a card w wide below anchor, at its start, as Tooltip shows its text: body fills it.
func IconButton ¶
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 InputGroup ¶ added in v1.3.0
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 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 LiquidGlass ¶ added in v1.19.0
LiquidGlass creates the unified Liquid Glass material: true Gaussian backdrop blur tinted with the surface color. Call it while building the panel.
func List ¶
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. A reordered list that chooses no rows keeps the accent: the line showing where dragged rows go is drawn in it.
func MenuAt ¶ added in v1.18.0
func MenuAt(c *ui.Context, anchor ui.Element, open *bool, at, self ui.Anchor, topOffset float32, label string, body func())
MenuAt is a menu anchored as PopoverAt: a tight panel of MenuItems, perhaps under a MenuLabel, labelled label.
func MenuItem ¶ added in v1.18.0
MenuItem is an item of a menu, tinted while selected (the keys' choice); give it its Label and Children.
func NavSwitch ¶
NavSwitch is a segmented row of page links on the window material: the page shown raised on the background in the fill icon with its name, the others muted icons named by a tooltip. Picking another slides the raised background over and widens it to the name, which it uncovers.
The buttons take their new widths at once, so that what slides heads for where it ends: a pill chasing a button still on its way overshoots it. The icons and names are a row of their own over the buttons, as an absolute element paints over its siblings and the pill would cover those before it.
func NewFrame ¶ added in v1.18.0
func NewFrame()
NewFrame starts a frame: WebView goes by whether the last one frosted a panel, as dialogs build after the pages under them.
func Palette ¶ added in v1.18.0
func Palette(c *ui.Context, open *bool, query *string, o PaletteOpts, head, body func())
Palette is a modal search panel near the top of the window: a search box bound to query with a close button, head (the kind tabs) under it, body (the result list, of PaletteRows) scrolling under that, and a bar of o.Hints. The box has the focus; Escape, a click outside and the close button close it.
func PaletteChip ¶ added in v1.18.0
PaletteChip is a filter set in a Palette's search row: its label and a button, named remove, which it returns for the caller's OnClick.
func PalettePreview ¶ added in v1.18.0
PalettePreview is a card 8px off a Palette's right edge, level with the selected PaletteRow, which it follows as the list scrolls; body builds its content. Build it after the Palette in the same frame, while open.
func PaletteRow ¶ added in v1.18.0
PaletteRow is a one-line result of a Palette for content the caller builds: an option of its list, tinted while selected. Give it its Label, Gap and Children.
func PaletteTab ¶ added in v1.18.0
PaletteTab is a kind tab of a Palette's head, tinted while chosen.
func Panel ¶
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 PopoverAt ¶ added in v1.17.0
func PopoverAt(c *ui.Context, anchor ui.Element, open *bool, at, self ui.Anchor, topOffset float32, body func())
PopoverAt is a panel anchored to anchor at (at, self) with topOffset 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 RadioCard ¶ added in v1.26.0
RadioCard is a radio whose whole card clicks: the dot, label and help under it, bordered while it is the choice.
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 (a Stroke astride it, on whole pixels) 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 RoundAction ¶ added in v1.22.0
RoundAction is an action named under its icon, as a contact's under their name: the icon in a round tint, then name; tip, if set, is its label and tooltip, saying more than name. On is a state the action turns off, as being blocked.
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 ¶
Separator is a hairline: horizontal across its parent, or a short vertical one. In a row, give it Grow(1). It takes a Stroke's room but draws one device pixel, as a border (a box that thin rounds away).
func SidebarChevron ¶ added in v1.5.0
SidebarChevron is a sidebar row's 12 muted chevron, turned a quarter at open 1.
func SidebarCollapsible ¶ added in v1.5.0
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 ¶
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 ¶
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 StatusDot ¶
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
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 SwitchRow ¶
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 TabsFill ¶ added in v1.22.0
TabsFill is Tabs across its row, every tab the same width: a choice between whole views, as Gmail's 应用专用密码 | 浏览器登录.
func TabsUnderline ¶
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 TemplateField ¶ added in v1.26.0
TemplateField edits *value, a template of literal text and {id} tokens (a 命名模板): tokens show as chips that a button takes out, then an input for the text after them; the buttons below add a token at the end, and Backspace in the empty input takes out the last one. Text between tokens stays as typed. An {id} not in Tokens is text.
func Text ¶
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 ToastHost ¶
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 ¶
ToggleGroup groups the buttons fn builds: one Tab stop, the arrow keys move between them.
func Tooltip ¶
Tooltip shows text by anchor on keyboard focus at once and on hover after a pause, and describes anchor to assistive technology.
func TooltipLabelled ¶
TooltipLabelled is Tooltip for an anchor whose Label already says text.
Types ¶
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, Alert, Top 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. Alert makes it one question (confirm, delete, open a link): the alert backdrop and no close button, Cancel, Escape or a click outside closing it. Top keeps it near the window's top instead of above centre, for a form whose height changes as it is used (steps, results): it grows down.
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 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 GlassMaterial ¶ added in v1.19.0
GlassMaterial blurs what is behind it with genuine Gaussian backdrop blur, then fills with tint.
func (GlassMaterial) PaintMaterial ¶ added in v1.19.0
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
Glass bool // frosted glass appearance with hairline border (no blur)
}
InputOpts style a text input.
type LabelChipOpts ¶ added in v0.3.0
type LabelChipOpts struct {
Text, Icon, Tip string
Display 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. Display is core.LabelDisplay*: "both" (the default; "" too), "icon" or "text".
type Option ¶
type Option[T comparable] struct { Value T Label string Disabled bool // listed, muted, and not chosen }
Option is one choice of a Select.
type PaletteHint ¶ added in v1.18.0
type PaletteHint struct {
Label, Key string
OnClick func()
}
PaletteHint is a shortcut the palette's bottom bar names: Key, then Label. With OnClick it is a button too, at the bar's end: give it last.
type PaletteOpts ¶ added in v1.18.0
type PaletteOpts struct {
Label, Placeholder, Close string
OnKey func(k ui.TextKey) bool
Keys func(mods ui.Modifiers, key ui.Key) bool
Send string
OnSend func()
Hints []PaletteHint
Chips func()
}
PaletteOpts name a Palette and its search box. OnKey sees the keys the box types no text with (the arrows, Enter, Tab, those with Cmd or Ctrl) before it does, as ui's OnTextKey: true takes the key. Chips, when set, builds the PaletteChips before the box. Keys, when set, holds the box: it types no text, and Keys sees every key pressed first (a menu's letters). Send, when set, makes the box a message to send instead of a search: a framed text area and a button named Send, and no head or body. Its panel is a dialog's (Glass).
type PressableOpts ¶
type PressableOpts struct {
Selected, Bordered bool
Glass bool // frosted glass appearance with hairline border and GlassHover (no blur)
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 ¶
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 TemplateOpts ¶ added in v1.26.0
type TemplateOpts struct {
Label string // the field's name, for its input
Tokens []TemplateToken // the tokens, in the order their buttons show
Insert string // the heading before the token buttons
Remove func(label string) string
Placeholder string
Error string // in place of Preview; the box turns red
Preview string // what the value gives, as an example
PreviewLabel string // before Preview, as 示例
}
TemplateOpts name a TemplateField and what it offers.
type TemplateToken ¶ added in v1.26.0
type TemplateToken struct{ ID, Label string }
TemplateToken is a token a TemplateField offers: stored as {ID}, shown as Label.