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