temporarydrawer

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

temporarydrawer implements a material temporarydrawer component.

See: https://material.io/components/web/catalog/drawers/

Example
package main

import (
	"fmt"
	"log"

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

func main() {
	// Create a new instance of a material temporarydrawer component.
	c := temporarydrawer.New()
	printName(c)
	printState(c)
	c.Open = true
	printState(c)

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

	printState(c)
	c.Open = false
	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 *temporarydrawer.TD) {
	fmt.Printf("%s\n", c.Component().Type)
}

func printState(c *temporarydrawer.TD) {
	fmt.Println()
	fmt.Printf("MDC Open: %v\n", c.Component().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:

MDCTemporaryDrawer

MDC Open: false

MDC Open: true

MDC Open: true

MDC Open: false

MDC Open: false

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TD

type TD struct {
	Open bool `js:"open"`
	// contains filtered or unexported fields
}

TD is a material temporarydrawer component.

func New

func New() *TD

New returns a new component.

func (*TD) Component

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

Component returns the component's underlying base.Component.

func (*TD) Start

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

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

StateMap implements the base.StateMapper interface.

func (*TD) Stop

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