Skip to Content
Onevra

Skeleton

A pulsing placeholder in the shape of content that is still loading.

Loading the live example…

skeleton.go
import (
	"time"

	"github.com/egoist/mygo/ui"
	"github.com/oneo-me/onevra/source/components"
)

type profileCard struct {
	loading bool
	started time.Time
}

func (p *profileCard) View(c *ui.Context) {
	t := c.Theme()
	// Pretend to load for a moment; a real application would load elsewhere
	// and clear loading on the UI thread.
	if p.loading {
		if wait := 1500*time.Millisecond - c.Now().Sub(p.started); wait > 0 {
			c.After(wait)
		} else {
			p.loading = false
		}
	}
	ui.Column(c).Width(340).MaxWidthPercent(100).Gap(16).Children(func() {
		components.SkeletonContent(c, p.loading, components.SkeletonOptions{Lines: 2, Avatar: true}, func() {
			ui.Row(c).FillWidth().Gap(12).AlignItems(ui.Center).Children(func() {
				components.Avatar(c, "Grace Hopper", components.AvatarOptions{})
				ui.Column(c).Grow(1).Children(func() {
					components.Text(c, "Grace Hopper").Bold()
					components.Text(c, "Rear admiral, computer scientist").TextColor(t.TextMuted)
				})
			})
		})
		if components.Button(c, "Reload", components.ButtonSecondary).Disabled(p.loading).Clicked() {
			p.loading, p.started = true, c.Now()
		}
	})
}
Source

components.SkeletonContent shows a skeleton while its loading flag is set and the content once it clears: the placeholder fades out as the content rises in, and the height springs between them. components.Skeleton draws the placeholder alone.

API

SkeletonContent

func SkeletonContent(c *ui.Context, loading bool, options SkeletonOptions, content func()) ui.Element

SkeletonContent shows a Skeleton while loading and content once it is not. The placeholder fades out as the content fades in, rising into place, and the container's height springs between them; later size changes of the content follow with the same spring. Reduced Motion swaps with fades and no movement. The application owns loading and builds content synchronously.

pkg.go.dev

Skeleton

func Skeleton(c *ui.Context, options SkeletonOptions) ui.Element

Skeleton creates a pulsing placeholder of text lines for content whose shape is known. It fills the available width; lines are proportions of it. It is a loading status named by options.Label; the blocks themselves are not exposed. Only drawing animates. Reduced Motion stops the pulse.

pkg.go.dev

SkeletonOptions

SkeletonOptions shapes a Skeleton placeholder: Lines of text, 3 when zero and clamped to 1–6, after an optional round Avatar. Label names the loading status; empty uses "Loading content" from Onevra's catalog.

Prop

Type

pkg.go.dev
Edit this page on GitHub

On this page