dialog

package
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: 3 Imported by: 2

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.

func New

func New() *D

New returns a new component.

func (*D) Component

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

Component returns the component's underlying base.Component.

func (*D) Start

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

func (c *D) Stop() error

Stop removes the component's association with its HTMLElement and cleans up event listeners, etc.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL