radio

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

radio implements a material radio component.

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

Example
package main

import (
	"fmt"
	"log"

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

func main() {
	// Create a new instance of a material radio component.
	c := radio.New()
	printName(c)
	printState(c)
	c.Checked = true
	c.Disabled = true
	c.Value = "before Start()"
	printState(c)

	// Set up a DOM HTMLElement suitable for a radio.
	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)
	}

	c.Value = "after Start() 1"
	printState(c)
	c.Checked = false
	c.Disabled = false
	c.Value = "after Start() 2"

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

}

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

func printState(c *radio.R) {
	fmt.Printf("[Go] Checked: %v, Disabled: %v, Value:%v\n",
		c.Checked, c.Disabled, c.Value)
	fmt.Printf("[JS] Checked: %v, Disabled: %v, Value:%v\n",
		c.Component().Get("checked"), c.Component().Get("disabled"),
		c.Component().Get("value"))
}

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:

MDCRadio
[Go] Checked: false, Disabled: false, Value:
[JS] Checked: false, Disabled: false, Value:
[Go] Checked: true, Disabled: true, Value:before Start()
[JS] Checked: true, Disabled: true, Value:before Start()
[Go] Checked: true, Disabled: true, Value:after Start() 1
[JS] Checked: true, Disabled: true, Value:after Start() 1
[Go] Checked: false, Disabled: false, Value:after Stop()
[JS] Checked: false, Disabled: false, Value:after Stop()

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type R

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

R is a material radio component.

func New

func New() *R

New returns a new component.

func (*R) Component

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

Component returns the component's underlying base.Component.

func (*R) Start

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

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

StateMap implements the base.StateMapper interface.

func (*R) Stop

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