Documentation
¶
Overview ¶
dialog implements a material dialog component.
See: https://material.io/components/web/catalog/dialogs/
Example ¶
package main
import (
"fmt"
"log"
"agamigo.io/material/dialog"
"agamigo.io/material/internal/mdctest"
"github.com/gopherjs/gopherjs/js"
)
func main() {
// Create a new instance of a material dialog component.
c := dialog.New()
printName(c)
printState(c)
c.Open = true
printState(c)
// Set up a DOM HTMLElement suitable for a dialog.
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.Open = false
printState(c)
c.Open = true
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 *dialog.D) {
fmt.Printf("%s\n", c.Component().Type)
}
func printState(c *dialog.D) {
fmt.Println()
mdcObj := c.Component()
fmt.Printf("[Go] Open: %v\n", c.Open)
fmt.Printf("[JS] Open: %v\n", mdcObj.Get("open"))
}
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: MDCDialog [Go] Open: false [JS] Open: false [Go] Open: true [JS] Open: true [Go] Open: true [JS] Open: true [Go] Open: false [JS] Open: false [Go] Open: true [JS] Open: true [Go] Open: true [JS] Open: true
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type D ¶
type D struct {
// Open opens and closes the dialog component.
Open bool `js:"open"`
// contains filtered or unexported fields
}
D is a material dialog component.
Click to show internal directories.
Click to hide internal directories.