progress

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package progress provides progress bar and spinner components.

Available variants:

  • New() creates a progress bar (template: "lvt:progress:default:v1")
  • NewCircular() creates a circular progress (template: "lvt:progress:circular:v1")
  • NewSpinner() creates a spinner (template: "lvt:progress:spinner:v1")

Example usage:

// In your controller/state
UploadProgress: progress.New("upload",
    progress.WithValue(75),
    progress.WithShowLabel(true),
)

// In your template
{{template "lvt:progress:default:v1" .UploadProgress}}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Templates

func Templates() *base.TemplateSet

Templates returns the progress component's template set for registration with the LiveTemplate framework.

Example usage in main.go:

import "github.com/livetemplate/lvt/components/progress"

tmpl, err := livetemplate.New("app",
    livetemplate.WithComponentTemplates(progress.Templates()),
)

Available templates:

  • "lvt:progress:default:v1" - Linear progress bar
  • "lvt:progress:circular:v1" - Circular progress indicator
  • "lvt:progress:spinner:v1" - Loading spinner

Types

type CircularOption

type CircularOption func(*CircularProgress)

CircularOption is a functional option for circular progress.

func WithCircularColor

func WithCircularColor(color Color) CircularOption

WithCircularColor sets the color.

func WithCircularIndeterminate

func WithCircularIndeterminate(indeterminate bool) CircularOption

WithCircularIndeterminate enables spinning mode.

func WithCircularLabel

func WithCircularLabel(label string) CircularOption

WithCircularLabel sets a custom label.

func WithCircularMax

func WithCircularMax(max float64) CircularOption

WithCircularMax sets the maximum value.

func WithCircularShowLabel

func WithCircularShowLabel(show bool) CircularOption

WithCircularShowLabel shows percentage in center.

func WithCircularSize

func WithCircularSize(size int) CircularOption

WithCircularSize sets the size in pixels.

func WithCircularStrokeWidth

func WithCircularStrokeWidth(width int) CircularOption

WithCircularStrokeWidth sets the stroke width.

func WithCircularStyled

func WithCircularStyled(styled bool) CircularOption

WithCircularStyled enables Tailwind CSS styling.

func WithCircularValue

func WithCircularValue(value float64) CircularOption

WithCircularValue sets the current progress value.

type CircularProgress

type CircularProgress struct {
	base.Base

	// Value is the current progress (0-100)
	Value float64

	// Max is the maximum value (default 100)
	Max float64

	// Size in pixels
	Size int

	// StrokeWidth of the circle
	StrokeWidth int

	// Color of the progress
	Color Color

	// ShowLabel shows percentage in center
	ShowLabel bool

	// Label is custom label text
	Label string

	// Indeterminate shows spinning animation
	Indeterminate bool
}

CircularProgress is a circular progress indicator.

func NewCircular

func NewCircular(id string, opts ...CircularOption) *CircularProgress

NewCircular creates a circular progress indicator.

Example:

c := progress.NewCircular("loading",
    progress.WithCircularValue(75),
    progress.WithCircularSize(80),
)

func (*CircularProgress) Center

func (c *CircularProgress) Center() int

Center returns the center point of the SVG.

func (*CircularProgress) Circumference

func (c *CircularProgress) Circumference() float64

Circumference returns the circle circumference.

func (*CircularProgress) ColorClass

func (c *CircularProgress) ColorClass() string

ColorClass returns CSS class for color.

func (*CircularProgress) DashOffset

func (c *CircularProgress) DashOffset() float64

DashOffset returns the stroke-dashoffset for progress.

func (*CircularProgress) DisplayLabel

func (c *CircularProgress) DisplayLabel() string

DisplayLabel returns the label to display.

func (*CircularProgress) Percentage

func (c *CircularProgress) Percentage() float64

Percentage returns the progress percentage.

func (*CircularProgress) PercentageStr

func (c *CircularProgress) PercentageStr() string

PercentageStr returns the percentage as formatted string.

func (*CircularProgress) Radius

func (c *CircularProgress) Radius() int

Radius returns the circle radius.

func (*CircularProgress) Styles

Styles returns the resolved CircularProgressStyles for this component.

type Color

type Color string

Color defines the progress color.

const (
	ColorPrimary Color = "primary"
	ColorSuccess Color = "success"
	ColorWarning Color = "warning"
	ColorDanger  Color = "danger"
	ColorInfo    Color = "info"
)

type Option

type Option func(*Progress)

Option is a functional option for configuring progress bars.

func WithAnimated

func WithAnimated(animated bool) Option

WithAnimated enables stripe animation.

func WithColor

func WithColor(color Color) Option

WithColor sets the progress bar color.

func WithIndeterminate

func WithIndeterminate(indeterminate bool) Option

WithIndeterminate enables indeterminate mode.

func WithLabel

func WithLabel(label string) Option

WithLabel sets a custom label.

func WithMax

func WithMax(max float64) Option

WithMax sets the maximum value.

func WithShowLabel

func WithShowLabel(show bool) Option

WithShowLabel shows the percentage label.

func WithSize

func WithSize(size Size) Option

WithSize sets the progress bar size.

func WithStriped

func WithStriped(striped bool) Option

WithStriped enables striped pattern.

func WithStyled

func WithStyled(styled bool) Option

WithStyled enables Tailwind CSS styling.

func WithValue

func WithValue(value float64) Option

WithValue sets the current progress value.

type Progress

type Progress struct {
	base.Base

	// Value is the current progress (0-100)
	Value float64

	// Max is the maximum value (default 100)
	Max float64

	// Size of the progress bar
	Size Size

	// Color of the progress bar
	Color Color

	// ShowLabel shows percentage label
	ShowLabel bool

	// Label is custom label text (overrides percentage)
	Label string

	// Striped shows striped pattern
	Striped bool

	// Animated animates the stripes
	Animated bool

	// Indeterminate shows indeterminate animation
	Indeterminate bool
}

Progress is a linear progress bar component. Use template "lvt:progress:default:v1" to render.

func New

func New(id string, opts ...Option) *Progress

New creates a progress bar.

Example:

p := progress.New("download",
    progress.WithValue(50),
    progress.WithShowLabel(true),
)

func (*Progress) ColorClass

func (p *Progress) ColorClass() string

ColorClass returns CSS class for color.

func (*Progress) Complete

func (p *Progress) Complete()

Complete sets value to max.

func (*Progress) Decrement

func (p *Progress) Decrement(amount float64)

Decrement decreases the value by amount.

func (*Progress) DisplayLabel

func (p *Progress) DisplayLabel() string

DisplayLabel returns the label to display.

func (*Progress) Increment

func (p *Progress) Increment(amount float64)

Increment increases the value by amount.

func (*Progress) IsComplete

func (p *Progress) IsComplete() bool

IsComplete returns true if value equals max.

func (*Progress) Percentage

func (p *Progress) Percentage() float64

Percentage returns the progress percentage (0-100).

func (*Progress) PercentageStr

func (p *Progress) PercentageStr() string

PercentageStr returns the percentage as a formatted string.

func (*Progress) Reset

func (p *Progress) Reset()

Reset sets value to 0.

func (*Progress) SetValue

func (p *Progress) SetValue(value float64)

SetValue sets the progress value.

func (*Progress) SizeClass

func (p *Progress) SizeClass() string

SizeClass returns CSS class for size.

func (*Progress) Styles

func (p *Progress) Styles() styles.ProgressStyles

Styles returns the resolved ProgressStyles for this component.

type Size

type Size string

Size defines the progress bar size.

const (
	SizeXs Size = "xs"
	SizeSm Size = "sm"
	SizeMd Size = "md"
	SizeLg Size = "lg"
)

type Spinner

type Spinner struct {
	base.Base

	// Size of the spinner (sm, md, lg)
	Size string

	// Color of the spinner
	Color Color

	// Label for accessibility
	Label string
}

Spinner is a loading spinner component.

func NewSpinner

func NewSpinner(id string, opts ...SpinnerOption) *Spinner

NewSpinner creates a spinner.

Example:

s := progress.NewSpinner("loading",
    progress.WithSpinnerSize("lg"),
)

func (*Spinner) ColorClass

func (s *Spinner) ColorClass() string

ColorClass returns CSS class for spinner color.

func (*Spinner) SizeClass

func (s *Spinner) SizeClass() string

SizeClass returns CSS class for spinner size.

func (*Spinner) Styles

func (s *Spinner) Styles() styles.SpinnerStyles

Styles returns the resolved SpinnerStyles for this component.

type SpinnerOption

type SpinnerOption func(*Spinner)

SpinnerOption is a functional option for spinners.

func WithSpinnerColor

func WithSpinnerColor(color Color) SpinnerOption

WithSpinnerColor sets the spinner color.

func WithSpinnerLabel

func WithSpinnerLabel(label string) SpinnerOption

WithSpinnerLabel sets the accessibility label.

func WithSpinnerSize

func WithSpinnerSize(size string) SpinnerOption

WithSpinnerSize sets the spinner size.

func WithSpinnerStyled

func WithSpinnerStyled(styled bool) SpinnerOption

WithSpinnerStyled enables Tailwind CSS styling.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL