icontoggle

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: 1

Documentation

Overview

icontoggle implements a material icontoggle component.

See: https://material.io/components/web/catalog/buttons/icon-toggle-buttons/

Example
package main

import (
	"fmt"
	"log"

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

func main() {
	// Create a new instance of a material icontoggle component.
	c := icontoggle.New()
	printName(c)
	printState(c)
	c.On = true
	c.Disabled = true

	// Set up a DOM HTMLElement suitable for an icontoggle.
	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)
	c.Disabled = false
	c.On = false
	printState(c)

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

}

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

func printState(c *icontoggle.IT) {
	fmt.Println()
	mdcObj := c.Component()
	fmt.Printf("[Go] On: %v, Disabled: %v\n",
		c.On, c.Disabled)
	fmt.Printf("[JS] On: %v, Disabled: %v\n",
		mdcObj.Get("on"), mdcObj.Get("disabled"))
}

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:

MDCIconToggle

[Go] On: false, Disabled: false
[JS] On: false, Disabled: false

[Go] On: true, Disabled: true
[JS] On: true, Disabled: true

[Go] On: false, Disabled: false
[JS] On: false, Disabled: false

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IT

type IT struct {
	On       bool `js:"on"`
	Disabled bool `js:"disabled"`
	// contains filtered or unexported fields
}

IT is a material icontoggle component.

func New

func New() *IT

New returns a new component.

func (*IT) Component

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

Component returns the component's underlying base.Component.

func (*IT) Start

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

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

StateMap implements the base.StateMapper interface.

func (*IT) Stop

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