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 Badge(c *ui.Context, text string) ui.Element
- 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 Float(c *ui.Context, e ui.Element) ui.Element
- func Frost(c *ui.Context) ui.Material
- func Gallery(c *ui.Context, g *GalleryState)
- 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 List(c *ui.Context, s *ui.ListState, n int, row func(i int)) ui.Element
- func NavSwitch(c *ui.Context, items ...NavItem) ui.Element
- func Panel(c *ui.Context, radius float32) ui.Element
- func Popover(c *ui.Context, anchor ui.Element, open *bool, body func())
- 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 Resizer(c *ui.Context, size *float32, gap float32, over bool, label string, ...) (changed, dragging bool)
- 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 TabsUnderline(c *ui.Context, sel *int, labels ...string) 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)
- type AlertKind
- type ButtonOpts
- type ButtonSize
- type DialogOpts
- type DialogSize
- type EmptyOpts
- type GalleryState
- type GroupItem
- type InputOpts
- type LabelChipOpts
- type NavItem
- type Option
- type PressableOpts
- type SelectOpts
- type SidebarItemOpts
- type Status
- 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 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 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 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 ¶
ButtonGroup is bordered icon buttons side by side, split by hairlines; 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 backdrop's blur 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 Float ¶
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
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 ¶
func Gallery(c *ui.Context, g *GalleryState)
Gallery shows every kit component, section by section. Dev builds only.
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 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.
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, the others muted.
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 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 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 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).
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 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 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.
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 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 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 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 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 ¶
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.