formfield

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

formfield implements a material formfield component.

See: https://material.io/components/web/catalog/input-controls/form-fields/

Example
package main

import (
	"fmt"
	"log"

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

func main() {
	// Create a new instance of a material formfield component and its
	// childElement.
	child := checkbox.New()
	c := formfield.New()

	// Set up a DOM HTMLElement suitable for a formfield.
	js.Global.Get("document").Get("body").Set("innerHTML",
		mdctest.HTML(c.Component().Type.MDCClassName))
	rootElem := js.Global.Get("document").Get("body").Get("firstElementChild")
	childElem := rootElem.Get("firstElementChild")

	// Start the child element.
	err := child.Start(childElem)
	if err != nil {
		log.Fatalf("Unable to start child component %s: %v\n",
			child.Component().Type, err.Error())
	}

	// Start the parent formfield 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())
	}

	printName(c)
	printState(c)
	err = c.Stop()
	if err != nil {
		log.Fatalf("Unable to stop component %s: %v\n",
			c.Component().Type, err)
	}
	c.Input = child.Component().Object
	err = c.Start(rootElem)
	if err != nil {
		log.Fatalf("Unable to start component %s: %v\n",
			c.Component().Type, err.Error())
	}
	printState(c)

	err = c.Stop()
	if err != nil {
		log.Fatalf("Unable to stop component %s: %v\n",
			c.Component().Type, err)
	}

}

func printName(c *formfield.FF) {
	fmt.Printf("%s\n", c.Component().Type)
}

func printState(c *formfield.FF) {
	fmt.Println()
	mdcObj := c.Component()
	fmt.Printf("Child Element: %v\n",
		mdcObj.Get("input"))
}

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:

MDCFormField

Child Element: [object Object]

Child Element: [object Object]

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FF

type FF struct {
	Input interface{} `js:"input"`
	// contains filtered or unexported fields
}

FF is a material formfield component.

func New

func New() *FF

func (*FF) Component

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

Component returns the component's underlying base.Component.

func (*FF) Start

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

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

StateMap implements the base.StateMapper interface.

func (*FF) Stop

func (c *FF) Stop() error

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

Source Files

Jump to

Keyboard shortcuts

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