Keel v0.5.1 中文 GitHub

StatusMarker

Live example: a real Keel application compiled to WebAssembly. Interact with it here. The initial download is about 10 MB.Open full screen
Example sourceGo · Copyable

This is the complete source for the gallery example above.examples/components/status_marker.go

Reuse the component construction and Render methods in a scaffolded project. The example’s registerSection and shared helpers are provided by the component gallery.

package main

import (
	"github.com/dyike/keel/ui/core"
	"github.com/dyike/keel/ui/el"
	"github.com/dyike/keel/ui/kit"
)

func init() {
	registerSection("status_marker", "display", func() core.Widget {
		loading := kit.StatusMarker(demoText("Generating answer…", "正在生成回答…")).Loading(true).LoadingStyle(kit.StatusMarkerLoadingStyleShimmer).Role("status")
		synced := kit.StatusMarker(demoText("Synced", "已同步")).Icon(kit.Icon(kit.IconCheck).Size(16))
		today := kit.StatusMarker(demoText("Today", "今天")).Variant(kit.StatusMarkerSeparator)
		unread := kit.StatusMarker(demoText("3 unread messages", "3 条未读消息")).Variant(kit.StatusMarkerBorder).Content(kit.Button(demoText("View", "查看"), func() { loading.SetText(demoText("Message viewed", "已查看消息")) }).Size(44))
		spinner := kit.StatusMarker(demoText("Loading…", "正在载入…")).Loading(true)
		delivered := kit.StatusMarker(demoText("Delivered", "已送达")).Alignment(el.End)
		enabled := true
		return el.Embed(el.ViewFunc(func(cx *el.Context) el.Element {
			return el.Div().ScrollY().W(el.Dp(520)).MaxW(el.Full).P(24).Gap(20).Items(el.Stretch).Child(
				synced.Render(cx), today.Render(cx), unread.Render(cx),
				spinner.Render(cx), loading.Render(cx), delivered.Render(cx),
				kit.Button(demoText("Toggle loading state", "切换加载状态"), func() { enabled = !enabled; loading.Loading(enabled) }).Size(44).Render(cx),
			)
		}))
	})
}

kit.StatusMarker("Synced") is used for message status, timeline boundaries, and system prompts. By default, the width of the parent container is filled, the content is moved to the left, and the text uses the theme Muted. Existing kit.Marker(shape) continues drawing chart geometry markers.

kit.StatusMarker("Today").Variant(kit.StatusMarkerSeparator)
kit.StatusMarker("3 unread messages").Variant(kit.StatusMarkerBorder).
    Content(kit.Button("View", openMessages))
kit.StatusMarker("Generating…").Loading(true).
    LoadingStyle(kit.StatusMarkerLoadingStyleShimmer).ID("generation").Role("status")

Variant supports Plain, Separator, and Border; the separator is centered by default, Alignment(el.Start/Center/End) explicitly overrides it, and ResetAlignment restores the default. Separator only leaves the right line when moving to the left, and only the left line when moving to the right; Border draws lines at the bottom of the entire row.

Icon accepts any View, with a default 16dp slot; Content adds rich content after the text, and SetText("") can only use rich content. Children replaces children added directly to the end of the line, and the input slice is copied. Child controls such as buttons retain their own click, focus, and disable inheritance, and the status line itself does not become a clickable control, nor does it maintain an unread count or notification lifecycle.

Loading adds a spinner by default; retains the icon if it already exists. Shimmer mode sweeps text, and pure rich content changes transparency in a two-second cycle; icons and lines remain static. The ShimmerStyle callback configures the persistent ShimmerText (Duration, Spread, Highlight, Reverse, Once, etc.), and the text and Enabled are managed by the status line. Switch Loading/LoadingStyle to restart text sweeping; reduce static display when animation is reduced. Rich content transparency is fixed at 0.7–1, text sweep configuration does not change it.

PartStyle configures Root, Row, Icon, Content, and Separator respectively; the callback receives a new element every frame, and the ID is restored after the style to avoid losing the child control state. The Separator style also works on the Border bottom line. By default, status roles are not added, and ID/Role is used when needed; Agent can read text, and system screen reading is still limited by Keel/Gio platform support.

The layout uses Keel's row layout and theme scales and does not copy upstream dimensions. Alignment simultaneously sets the content group position and text alignment; child elements can be independently overridden with TextAlign.

Verification: go run ./examples/components -section status_marker.

When Content is present, text and rich content wrap onto separate rows as needed so an action retains its natural width on narrow layouts.