Documentation ¶
Overview ¶
The base package contains code shared by implementations of material components for GopherJS.
Index ¶
- func DefineSetGet(c Componenter, key string, setter interface{}, getter interface{}) (err error)
- func Start(c Componenter, rootElem *js.Object) (err error)
- func Stop(c Componenter) (err error)
- type Component
- type ComponentStartStopper
- type ComponentType
- type Componenter
- type MDCClasser
- type MDCState
- type StateMap
- type StateMapper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 agamigo.io/material/*, 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.
See: https://material.io/components/web/docs/framework-integration/
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).
Types ¶
type Component ¶
type Component struct { *js.Object *MDCState Type ComponentType }
Component is a base type for all Material components.
func (*Component) ComponentType ¶
func (c *Component) ComponentType() ComponentType
ComponentType implements the ComponentTyper interface.
func (*Component) SetComponent ¶
SetComponent implements the base.ComponentSetter interface and replaces the Component's properties with those of c's.
type ComponentStartStopper ¶
type ComponentStartStopper interface { Componenter 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.
See: https://material.io/components/web/catalog/
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 ¶
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 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.