linearprogress

package
v0.0.0-...-a8d3157 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2018 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

linearprogress implements a material linearprogress component.

See: https://material.io/components/web/catalog/linear-progress/

Example
package main

import (
	"fmt"
	"log"

	"agamigo.io/material/internal/mdctest"
	"agamigo.io/material/linearprogress"
	"github.com/gopherjs/gopherjs/js"
)

func main() {
	// Create a new instance of a material linearprogress component.
	c := linearprogress.New()
	printName(c)
	printState(c)
	c.Determinate = false
	c.Progress = .54
	c.Buffer = 1.00
	c.Reverse = true
	printState(c)

	// Set up a DOM HTMLElement suitable for a checkbox.
	js.Global.Get("document").Get("body").Set("innerHTML",
		mdctest.HTML(c.Component().Type.MDCClassName))
	rootElem := js.Global.Get("document").Get("body").Get("firstElementChild")

	// Start the component, which associates it with an HTMLElement.
	err := c.Start(rootElem)
	if err != nil {
		log.Fatalf("Unable to start component %s: %v\n",
			c.Component().Type, err.Error())
	}

	printState(c)
	err = c.Open()
	if err != nil {
		log.Fatalf("Unable to Open component %s: %v\n", c.Component().Type,
			err.Error())
	}
	c.Determinate = true
	c.Progress = .33
	c.Buffer = .98
	c.Reverse = false
	err = c.Close()
	if err != nil {
		log.Fatalf("Unable to Close component %s: %v\n", c.Component().Type,
			err.Error())
	}
	printState(c)
	jsTests(c)
	printState(c)

	err = c.Stop()
	if err != nil {
		log.Fatalf("Unable to stop component %s: %v\n",
			c.Component().Type, err)
	}

}

func printName(c *linearprogress.LP) {
	fmt.Printf("%s\n", c.Component().Type)
}

func printState(c *linearprogress.LP) {
	fmt.Println()
	fmt.Printf("[Go] Determinate: %v, Progress: %v, Buffer: %v, Reverse: %v\n",
		c.Determinate, c.Progress, c.Buffer, c.Reverse)
	mdcObj := c.Component().Get("foundation_")
	if mdcObj != js.Undefined {
		fmt.Printf("[JS] Determinate: %v, Progress: %v, Buffer: %v, Reverse: %v\n",
			mdcObj.Get("determinate_"),
			mdcObj.Get("progress_"),
			c.Component().Get("buffer"),
			mdcObj.Get("reverse_"),
		)
	}
}

func jsTests(c *linearprogress.LP) {
	o := c.Component()
	o.Set("determinate", true)
	o.Set("progress", .45)
	o.Set("buffer", .40)
	o.Set("reverse", false)
}

func init() {
	// We emulate a DOM here since tests run in NodeJS.
	// Not needed when running in a browser.
	err := mdctest.Init()
	if err != nil {
		log.Fatalf("Unable to setup test environment: %v", err)
	}
}
Output:

MDCLinearProgress

[Go] Determinate: false, Progress: 0, Buffer: 0, Reverse: false

[Go] Determinate: false, Progress: 0.54, Buffer: 1, Reverse: true

[Go] Determinate: false, Progress: 0.54, Buffer: 1, Reverse: true
[JS] Determinate: false, Progress: 0.54, Buffer: 1, Reverse: true

[Go] Determinate: true, Progress: 0.33, Buffer: 0.98, Reverse: false
[JS] Determinate: true, Progress: 0.33, Buffer: 0.98, Reverse: false

[Go] Determinate: true, Progress: 0.45, Buffer: 0.4, Reverse: false
[JS] Determinate: true, Progress: 0.45, Buffer: 0.4, Reverse: false

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LP

type LP struct {
	Determinate bool    `js:"determinate"`
	Reverse     bool    `js:"reverse"`
	Progress    float64 `js:"progress"`
	Buffer      float64 `js:"buffer"`
	// contains filtered or unexported fields
}

LP is a material libearprogress component.

func New

func New() *LP

New returns a new component.

func (*LP) Close

func (lp *LP) Close() (err error)

Close closes the linearProgress component.

func (*LP) Component

func (c *LP) Component() *base.Component

Component returns the component's underlying base.Component.

func (*LP) GetBufferCache

func (lp *LP) GetBufferCache() float64

GetBufferCache is a getter function for MDCLinearProgress.buffer

func (*LP) Open

func (lp *LP) Open() (err error)

Open opens the linearProgress component.

func (*LP) Start

func (c *LP) Start(rootElem *js.Object) error

Start initializes the component with an existing HTMLElement, rootElem. Start should only be used on a newly created component, or after calling Stop.

func (*LP) StateMap

func (c *LP) StateMap() base.StateMap

StateMap implements the base.StateMapper interface.

func (*LP) Stop

func (c *LP) Stop() error

Stop removes the component's association with its HTMLElement and cleans up event listeners, etc.

Jump to

Keyboard shortcuts

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