iconbutton

package
v0.0.0-...-1bbb42b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2021 License: MIT, MIT Imports: 2 Imported by: 0

Documentation

Overview

iconbutton implements a material iconbutton component.

See: https://material.io/components/web/catalog/buttons/icon-toggle-buttons/

Example
package main

import (
	"fmt"
	"log"

	"syscall/js"

	"github.com/vecty-components/material/components/iconbutton"
	"github.com/vecty-components/material/components/internal/mdctest"
)

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

	// Set up a DOM HTMLElement suitable for an iconbutton.
	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.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 *iconbutton.IB) {
	fmt.Printf("%s\n", c.Component().Type)
}

func printState(c *iconbutton.IB) {
	fmt.Println()
	mdcObj := c.Component()
	fmt.Printf("[Go] On: %v, Disabled: %v\n",
		c.On, true)
	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:

MDCIconbutton

[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 IB

type IB struct {
	On bool `js:"on"`
	// contains filtered or unexported fields
}

IB is a material iconbutton component.

func New

func New() *IB

New returns a new component.

func (*IB) Component

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

Component returns the component's underlying base.Component.

func (*IB) Start

func (c *IB) Start(rootElem js.Value) 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 (*IB) StateMap

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

StateMap implements the base.StateMapper interface.

func (*IB) Stop

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