drawer

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

drawer implements a material drawer component.

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

Example
package main

import (
	"fmt"
	"log"

	"syscall/js"

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

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

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

}

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

func printState(c *drawer.PD) {
	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:

MDCDrawer

MDC Open: false

MDC Open: true

MDC Open: true

MDC Open: false

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PD

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

PD is a material drawer component.

func New

func New() *PD

New returns a new component.

func (*PD) Component

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

Component returns the component's underlying base.Component.

func (*PD) Start

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

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

StateMap implements the base.StateMapper interface.

func (*PD) Stop

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