v0.0.0-...-a8d3157 Latest Latest

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



The base package contains code shared by implementations of material components for GopherJS.



This section is empty.


This section is empty.


func DefineSetGet

func DefineSetGet(c Componenter, key string,
	setter interface{}, getter interface{}) (err error)

func Start

func Start(c Componenter, rootElem *js.Object) (err error)

Start takes a component implementation (c) and initializes it with an HTMLElement (rootElem). Upon success err will be nil. If err is non-nil, it will contain any error thrown while calling the underlying MDC object's init() method. An error will also be returned if Component() is non-nil. Use Stop to clean up the component before calling Start again.

Important: If you are using a component from*, you should use its Start method, not this function. Consult the component's documentation for info/examples.

Implementing A Component

If you are writing a component implementation the documentation for the Componenter{Setter} interfaces provides useful information.

Finding The MDC Library

There are two ways Start knows of to find the MDC class needed to start a component. By default it uses values provided by the components in this project via the ComponentType method. This default works in the general case that the all-in-one MDC library is available under the global var "mdc".

The second case, MDCClasser, is needed if the MDC code for your component is elsewhere, for example if you are using the individual MDC component "@material/checkbox" library instead of the all-in-one distribution. Implement the MDCClasser interface to provide Start with the exact object for the MDC component class.


func Stop

func Stop(c Componenter) (err error)

Stop removes the component's association with its HTMLElement and cleans up event listeners, etc. It then runs SetComponent(nil).


type Component

type Component struct {
	Type ComponentType

Component is a base type for all Material components.

func (*Component) Component

func (c *Component) Component() *Component

Component implements the base.Componenter interface.

func (*Component) ComponentType

func (c *Component) ComponentType() ComponentType

ComponentType implements the ComponentTyper interface.

func (*Component) SetComponent

func (c *Component) SetComponent(newC *Component)

SetComponent implements the base.ComponentSetter interface and replaces the Component's properties with those of c's.

func (*Component) SetState

func (c *Component) SetState(sm StateMap) *Component

func (*Component) Start

func (c *Component) Start(rootElem *js.Object) error

func (*Component) Stop

func (c *Component) Stop() error

type ComponentStartStopper

type ComponentStartStopper interface {
	Start(rootElem *js.Object) error
	Stop() error

ComponentStartStopper is an interface that all material components implement. It is not used within the material project, but is intended for use by its consumers that embed a material component directly. Then frameworks/functions etc. can accept any component.

type ComponentType

type ComponentType struct {
	//  MDCClassName represents the name of the MDC class of the component. For
	//  example, a form-field is "MDCFormField".
	MDCClassName string

	// MDCCamelCaseName is the lower camel case version of an MDC component.
	// When using the all-in-one distribution of the MDC library, it is the
	// name of the object that holds the MDCComponent/MDCFoundation etc. For
	// example in "mdc.formField.MDCFormField" the MDCamelCaseName is
	// "formField".
	MDCCamelCaseName string

ComponentType is a specific component type, as implemented by the material-components-web library.


func (ComponentType) String

func (n ComponentType) String() string

String returns the ComponentType's MDCClassName field.

type Componenter

type Componenter interface {
	// Component should return the object that holds its MDC instance.
	Component() (c *Component)

Componenter is a base interface for every material component implementation.

type MDCClasser

type MDCClasser interface {
	MDCClass() *js.Object

MDCClasser is an interface that allows component users to specify the MDC class object that will be used to create/initialize the component. It overrides ComponentTyper when calling base.Start.

type MDCState

type MDCState struct {
	Basic       bool
	Started     bool
	RootElement *js.Object

type StateMap

type StateMap map[string]interface{}

type StateMapper

type StateMapper interface {
	StateMap() StateMap

StateMapper is an interface that components implement in order to provide a map of state values which can be used for backup/restore.

Jump to

Keyboard shortcuts

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