Skip to Content
Onevra

Avatar

A person or account as a photo or initials, alone or in an overlapping group.

Loading the live example…

avatar.go
import (
	"github.com/egoist/mygo/ui"
	"github.com/oneo-me/onevra/source/components"
)

type people struct {
	photo *ui.Bitmap // decoded once, when the application starts
}

func (p *people) View(c *ui.Context) {
	ui.Row(c).Gap(16).AlignItems(ui.Center).Children(func() {
		components.Avatar(c, "Ada Lovelace", components.AvatarOptions{})
		components.Avatar(c, "Mochi", components.AvatarOptions{Image: p.photo, Status: components.AvatarOnline})
		components.Avatar(c, "Grace Hopper", components.AvatarOptions{Status: components.AvatarOffline})
		components.Avatar(c, "Alan Turing", components.AvatarOptions{Size: 56})
	})
}
Source

Without an image, an avatar shows up to two initials of the name. Status adds a presence dot, which assistive technology hears with the name. Decode photos outside builders and pass the bitmap; pass nil while loading or after a failure.

Groups

components.AvatarGroup overlaps members in order and folds those past Max into a count. Pointing at the stack loosens it and names the member under the pointer; members joining or leaving open and close their slots.

Loading the live example…

avatar_group.go
import (
	"github.com/egoist/mygo/ui"
	"github.com/oneo-me/onevra/source/components"
)

type team struct {
	members []components.AvatarGroupMember
}

var candidates = []string{"Margaret Hamilton", "Dennis Ritchie", "Frances Allen", "Ken Thompson"}

func (t *team) View(c *ui.Context) {
	ui.Column(c).Gap(16).AlignItems(ui.Center).Children(func() {
		// Point at the stack to loosen it; members past Max fold into "+N".
		components.AvatarGroup(c, t.members, components.AvatarGroupOptions{Max: 4})
		ui.Row(c).Gap(8).Children(func() {
			if components.Button(c, "Add", components.ButtonSecondary).Disabled(len(t.members) >= 10).Clicked() {
				t.members = append(t.members, components.AvatarGroupMember{Name: candidates[len(t.members)%len(candidates)]})
			}
			if components.Button(c, "Remove", components.ButtonGhost).Disabled(len(t.members) == 1).Clicked() {
				t.members = t.members[:len(t.members)-1]
			}
		})
	})
}
Source

API

Avatar

func Avatar(c *ui.Context, name string, options AvatarOptions) ui.Element

Avatar creates a circular identity marker for a person or account named name: a photo, or up to two initials on a muted surface. It draws no outline, so it sits on any surface without a seam. Applications own loading, decoding and caching photos. Assistive technology sees an image named name and its status. Key a parent for identity.

pkg.go.dev

AvatarOptions

AvatarOptions customize an Avatar.

Prop

Type

pkg.go.dev

AvatarStatus

type AvatarStatus int

AvatarStatus is the presence an Avatar shows with a corner dot.

const (
	// AvatarNoStatus shows no presence dot.
	AvatarNoStatus AvatarStatus = iota
	// AvatarOnline shows a success-colored dot.
	AvatarOnline
	// AvatarOffline shows a muted dot.
	AvatarOffline
)
pkg.go.dev

AvatarGroup

func AvatarGroup(c *ui.Context, members []AvatarGroupMember, options AvatarGroupOptions) ui.Element

AvatarGroup creates an overlapping stack of members in order. Members past Max collapse into an overflow chip, so long lists build only what shows. Pointing at the stack loosens it and lifts the member under the pointer, which names itself in a tooltip; members joining or leaving open or close their slots and the overflow count rolls the way it moved. Reduced Motion keeps the stack still. Overlap and Reverse adjust how the avatars cover one another. Applications own members, photos and localized labels. Key a parent for identity.

pkg.go.dev

AvatarGroupOptions

AvatarGroupOptions customize an AvatarGroup.

Prop

Type

pkg.go.dev

AvatarGroupMember

AvatarGroupMember is one person in an AvatarGroup.

Prop

Type

pkg.go.dev
Edit this page on GitHub

On this page