BubbleGroup
Example sourceGo · Copyable
This is the complete source for the gallery example above.examples/components/bubble_group.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("bubble_group", "chat", func() core.Widget {
say := func(s string) el.View { return el.ViewFunc(func(*el.Context) el.Element { return el.Text(s) }) }
received := kit.BubbleGroup(
kit.Bubble(say(demoText("Order confirmed.", "订单已确认。"))),
kit.Bubble(say(demoText("Shipping is scheduled for tomorrow morning. The tracking number will be sent after dispatch.", "明天上午安排发货,运单号会在出库后发送。"))),
).Name(demoText("Consecutive support messages", "客服连续消息"))
sent := kit.BubbleGroup(
kit.Bubble(say(demoText("Got it, thanks. ", "收到,谢谢。 "))).Mine(),
kit.Bubble(say(demoText("Please leave it at the reception desk. ", "请帮我备注放在门卫。 "))).Mine(),
).Name(demoText("My consecutive messages", "我的连续消息"))
return el.Embed(el.ViewFunc(func(cx *el.Context) el.Element {
return el.Div().P(24).Gap(24).Child(received.Render(cx), sent.Render(cx))
}))
})
}
Arrange continuous bubbles into vertical groups with default spacing of theme.SpaceMd (8dp). Grouping is determined by the application; the component does not infer the sender or change the appearance, left-right alignment, or reaction slots of individual bubbles.
group := kit.BubbleGroup(first, second).Name("Support messages").Gap(6)
group.SetItems(first, second, third)
SetItems copies the slice and ignores nil, empty parameters are cleared; Items returns a copy of the slice. Bubble instances should be reused, with each instance appearing only once within the group. When other items are inserted, deleted, or rearranged, the internal input state and focus of the retained instance continue to be retained; the deleted control no longer participates in interaction. Ordinary custom views need to provide a stable ID by themselves.
Gap accepts non-negative finite dp, illegal values are ignored. Style(func(*el.DivEl)) configures spacing, borders, background, etc. after the default layout. nil returns to default; the callback is only used for the current frame element. Name sets the semantic name of the group, SetDisabled disables all children but does not modify the state of the child components themselves. Components maintain group identities, roles, names, and disabled states.
The group takes up the available width, normal Bubble still lays out its own 75% cap, and Ghost uses the entire row. Use Message when you need an avatar, author, or message status.
Run: go run ./examples/components -section bubble_group, add -theme dark to check the dark theme.