Skip to content

struct

Component

pub struct Component {
    /* private fields */
}

A reusable UI unit: a template plus a setup function.

Methods

new

pub fn new(name: &str, template: Template, setup: impl Fn(&Props) -> Scope + 'static) -> Component

A component called name that renders template, with setup building its scope from its props once per instance. The template's declarations (state, let, on…) are added on top of that scope.

from_template

pub fn from_template(name: &str, template: Template) -> Component

A component from its template alone. Each name the template reads is the prop of that name, and each handler it names emits the caller's event of that name: button(@click: select) calls the caller's @select.

with_scope

pub fn with_scope(name: &str, template: Template, own: impl Fn(&Props) -> Scope + 'static) -> Component

[Component::from_template], with own supplying names of its own (signals, handlers, values). Props and emitted events fill in the names it leaves out.

forward

pub fn forward(self) -> Component

Pass the caller's plain attributes — to the element the template marks root: true, else its first element — as (render the root as another element, e.g. as: "h2"), id, style (appended), title, tabindex, hidden, role, aria-*, data-* and motion* — and its event handlers onto this component's root element. The caller's values win. Handlers for the events named in [Component::emits] are left for the component to emit.

emits

pub fn emits(self, events: &[&str]) -> Component

The component events this component emits itself (press, select, …); other handlers are forwarded to the root element.

name

pub fn name(&self) -> &str

Its name, as templates write it (Card).

template

pub fn template(&self) -> &Template

Its template.

Trait implementations