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 (*R) Start ¶
Start initializes the component with an existing HTMLElement, rootElem. Start should only be used on a newly created component, or after calling Stop.
Click to show internal directories.
Click to hide internal directories.