base

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 Imports: 13 Imported by: 2

Documentation

Overview

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

Index

Constants

View Source
const MDC_VERSION = "4.0.0"

Variables

This section is empty.

Functions

func AddCSS

func AddCSS(css string)

func AddIcon

func AddIcon(url string)

func AddScript

func AddScript(url string)

func AddStyles

func AddStyles()

func Boot

func Boot()

func ClearCSS

func ClearCSS()

func DefineSetGet

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

func Key

func Key() string

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.

See: https://github.com/hexops/vecty/issues/191

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) 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.Value) error

func (*Component) Stop

func (c *Component) Stop() error

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(html *vecty.HTML) *LinkMarkup

type MDC

type MDC struct {
	Component   ComponentStartStopper
	RootElement *vecty.HTML
}

func (*MDC) Mount

func (b *MDC) Mount()

func (*MDC) Unmount

func (b *MDC) Unmount()

type MDCClasser

type MDCClasser interface {
	MDCClass() js.Value
}

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.Value
}

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.

type StaticComponent

type StaticComponent struct {
	vecty.Core
	Child vecty.ComponentOrHTML
}

func (*StaticComponent) Render

func (*StaticComponent) SkipRender

func (c *StaticComponent) SkipRender(prev vecty.Component) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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