Skip to Content
Onevra

Stepper

Shows where a person is in a multi-step flow, such as checkout or setup.

Loading the live example…

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

type checkout struct {
	current int
}

func (o *checkout) View(c *ui.Context) {
	steps := []components.StepperStep{
		{Label: "Cart", Description: "3 items"},
		{Label: "Shipping", Description: "Address and method"},
		{Label: "Payment", Description: "Card or transfer"},
		{Label: "Review"},
	}
	ui.Column(c).Width(520).MaxWidthPercent(100).Gap(20).Children(func() {
		stepper := components.Stepper(c, steps, o.current, components.StepperOptions{Selectable: true})
		stepper.FillWidth()
		if i, ok := stepper.Chosen(); ok {
			o.current = i
		}
		ui.Row(c).Gap(8).Justify(ui.Center).FillWidth().Children(func() {
			if components.Button(c, "Back", components.ButtonGhost).Disabled(o.current == 0).Clicked() {
				o.current--
			}
			if components.Button(c, "Continue", components.ButtonPrimary).Disabled(o.current == len(steps)).Clicked() {
				o.current++
			}
		})
	})
}
Source

current is the index of the step in progress; set it to the number of steps once all are done. Completed steps show a check and failed steps an alert. With Selectable, people can return to completed steps, which Chosen() reports. Orientation: components.Vertical stacks the steps for a sidebar, and Compact shows markers only.

API

Stepper

func Stepper(c *ui.Context, steps []StepperStep, current int, opts StepperOptions) *StepperControl

Stepper shows where a person is in a multi-step flow, for onboarding, checkout and setup. current is the index of the step in progress; set it to len(steps) once every step is done. Out-of-range values clamp. Applications own the steps, the flow and its content, placed beside it.

Completed steps show a check, the current step a ring around its number and failed steps an alert. With Selectable, completed steps are buttons: Tab enters the steps, the arrows move among those already reached, and Home and End go to the first and the last of them. Changes of the current step are announced. Reduced Motion skips the motion.

pkg.go.dev

StepperOptions

StepperOptions configure a Stepper.

Prop

Type

pkg.go.dev

StepperStep

StepperStep is one step of a Stepper, identified by its position.

Prop

Type

pkg.go.dev

StepperControl

StepperControl retains step choice separately from Element styling.

Prop

Type

Methods
func (s *StepperControl) Chosen() (int, bool)

Chosen reports the completed step chosen in this frame.

pkg.go.dev
Edit this page on GitHub

On this page