toolbar

package
Version: 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: 2 Imported by: 2

Documentation

Overview

toolbar implements a material toolbar component.

See: https://material.io/components/web/catalog/toolbar/

Example
package main

import (
	"fmt"
	"log"

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

func main() {
	// Create a new instance of a material toolbar component.
	c := toolbar.New()
	printName(c)

	// Set up a DOM HTMLElement suitable for a toolbar.
	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)
	}
	printName(c)

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

}

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

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:

MDCToolbar
MDCToolbar
MDCToolbar

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type T

type T struct {
	// contains filtered or unexported fields
}

T is a material toolbar component.

func New

func New() *T

New returns a new component.

func (*T) Component

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

Component returns the component's underlying base.Component.

func (*T) Start

func (c *T) 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 (*T) StateMap

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

StateMap implements the base.StateMapper interface.

func (*T) Stop

func (c *T) Stop() error

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

Source Files

Jump to

Keyboard shortcuts

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