AvatarGroup
Example sourceGo · Copyable
This is the complete source for the gallery example above.examples/components/avatar_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"
"github.com/dyike/keel/ui/theme"
)
func init() {
registerSection("avatar_group", "display", func() core.Widget {
avatars := []*kit.AvatarView{kit.Avatar(demoText("Alex Chen", "张三")).Status(kit.AvatarOnline), kit.Avatar("Ada Lovelace"), kit.Avatar("Bob"), kit.Avatar("Carol"), kit.Avatar("Dave")}
small := kit.AvatarGroup(avatars...).Size(24)
limited := kit.AvatarGroup(avatars...).Limit(3)
ellipsis := kit.AvatarGroup(avatars...).Size(56).Limit(2).Ellipsis(true)
return el.Embed(el.ViewFunc(func(cx *el.Context) el.Element {
return el.Div().P(theme.SpaceXl).Gap(theme.SpaceLg).Items(el.Start).Child(
el.Text(demoText("Team members", "团队成员")), small.Render(cx), el.Text(demoText("Show 3 people; represent the rest with a count", "显示 3 人,其余用数量表示")), limited.Render(cx), el.Text(demoText("Ellipsis mode", "省略号模式")), ellipsis.Render(cx))
}))
})
}
Stack multiple avatars to form a member group, limit the number of visible people and then use +N to display the hidden number of people.
team := kit.AvatarGroup(
kit.Avatar("Alex Chen").Status(kit.AvatarOnline),
kit.Avatar("Ada Lovelace"),
kit.Avatar("Bob"),
).Size(40).Limit(2)
Size(dp) Unifies the diameter within the group, defaults to 40dp, limited to 16–256dp; does not modify the size of member avatars themselves. The avatars overlap by a quarter with a 2dp theme.Outline ring. Narrow windows provide horizontal scrolling.
Limit(n) limits the number of avatars actually displayed, and the overflow mark occupies an additional space. By default, a negative number means no limit, and 0 only displays the total number of hidden people. Ellipsis(true) Replace the visible +N with an ellipsis, and the Agent can still read the hidden number of people.
SetAvatars copies the member slice and filters out nil; Avatars() returns a copy of the slice. The avatar instance is still shared and you can continue to update the name, picture and status. Empty groups do not occupy height.
Agent: The outer layer is group, the visible member is avatar, and the original name and status are retained; the overflow avatar name is the localized "More N", and the value is the hidden number of people. The group is for display content and does not occupy keyboard focus.
Verify: go run ./examples/components -section avatar_group, add -theme dark to see dark colors.