checkbox

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

checkbox implements a material checkbox component.

See: https://material.io/components/web/catalog/input-controls/checkboxes/

Example
package main

import (
	"fmt"
	"log"

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

func main() {
	// Create a new instance of a material checkbox component.
	c := checkbox.New()
	printName(c)
	printState(c)
	c.Checked = true
	c.Disabled = true
	c.Indeterminate = true
	c.Value = "new value"
	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())
	}

	c.Value = "after start"
	printState(c)

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

}

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

func printState(c *checkbox.CB) {
	mdcObj := c.Component()
	fmt.Printf("Checked: %v, Indeterminate: %v, Disabled: %v, Value: v",
		mdcObj.Get("checked"), mdcObj.Get("indeterminate"),
		mdcObj.Get("disabled")) //, mdcObj.Get("value"))
	fmt.Println()
}

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:

MDCCheckbox
Checked: false, Indeterminate: false, Disabled: false, Value: v
Checked: true, Indeterminate: true, Disabled: true, Value: v
Checked: true, Indeterminate: true, Disabled: true, Value: v
Checked: true, Indeterminate: true, Disabled: true, Value: v

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CB

type CB struct {
	Checked       bool   `js:"checked"`
	Indeterminate bool   `js:"indeterminate"`
	Disabled      bool   `js:"disabled"`
	Value         string `js:"value"`
	// contains filtered or unexported fields
}

CB is a material checkbox component.

func New

func New() *CB

New returns a new component.

func (*CB) Component

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

Component returns the component's underlying base.Component.

func (*CB) Start

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

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

StateMap implements the base.StateMapper interface.

func (*CB) Stop

func (c *CB) 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
t or T : Toggle theme light dark auto
y or Y : Canonical URL