Documentation
¶
Overview ¶
The base package contains code shared by implementations of material components for GopherJS.
Index ¶
- Constants
- func AddCSS(css string)
- func AddIcon(url string)
- func AddScript(url string)
- func AddStyles()
- func Boot()
- func ClearCSS()
- func DefineSetGet(c Componenter, key string, setter interface{}, getter interface{}) (err error)
- func Key() string
- func MarkupIfNotNil(rootMarkup *vecty.MarkupList) vecty.Applyer
- func MarkupOnly(moc vecty.MarkupOrChild) *vecty.MarkupList
- func RenderStoredChild(child vecty.ComponentOrHTML) vecty.Component
- func RichLink(route string, elements []vecty.ComponentOrHTML, opts router.LinkOptions) *vecty.HTML
- func SetViewport()
- func Start(c Componenter, rootElem js.Value) (err error)
- func Stop(c Componenter) (err error)
- type Component
- type ComponentStartStopper
- type ComponentType
- type Componenter
- type LinkMarkup
- type MDC
- type MDCClasser
- type MDCState
- type StateMap
- type StateMapper
- type StaticComponent
Constants ¶
const MDC_VERSION = "4.0.0"
Variables ¶
This section is empty.
Functions ¶
func DefineSetGet ¶
func DefineSetGet(c Componenter, key string, setter interface{}, getter interface{}) (err error)
func MarkupIfNotNil ¶
func MarkupIfNotNil(rootMarkup *vecty.MarkupList) vecty.Applyer
func MarkupOnly ¶
func MarkupOnly(moc vecty.MarkupOrChild) *vecty.MarkupList
MarkupOnly returns the vecty.MarkupList contained in moc, or nil if none is found. It also returns nil if moc is a vecty.List that contains one or more vecty.ComponentOrHTML. If nil is returned, it is then safe to assert the type of moc as a vecty.ComponentOrHTML.
func RenderStoredChild ¶
func RenderStoredChild(child vecty.ComponentOrHTML) vecty.Component
RenderStoredChild is a helper which provides a Component which wraps the provided ComponentOrHTML. It exists as a workaround to a vecty issue.
func RichLink ¶
func RichLink(route string, elements []vecty.ComponentOrHTML, opts router.LinkOptions) *vecty.HTML
func SetViewport ¶
func SetViewport()
func Start ¶
func Start(c Componenter, rootElem js.Value) (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 github.com/vecty-components/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.Value *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.Value) 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 LinkMarkup ¶
type LinkMarkup struct { Child vecty.ComponentOrHTML Href string OnClick func(*vecty.Event) }
Represents a simplified version of an element
func ExtractMarkupFromLink ¶
func ExtractMarkupFromLink(html *vecty.HTML) *LinkMarkup
type MDC ¶
type MDC struct { Component ComponentStartStopper RootElement *vecty.HTML }
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.
type StaticComponent ¶
type StaticComponent struct { vecty.Core Child vecty.ComponentOrHTML }
func (*StaticComponent) Render ¶
func (c *StaticComponent) Render() vecty.ComponentOrHTML
func (*StaticComponent) SkipRender ¶
func (c *StaticComponent) SkipRender(prev vecty.Component) bool