Trait custom_elements::CustomElement[][src]

pub trait CustomElement: Default + 'static {
    fn to_node(&mut self) -> Node;

    fn shadow() -> bool { ... }
fn observed_attributes() -> Vec<&'static str> { ... }
fn connected_callback(&mut self, _this: &HtmlElement) { ... }
fn disconnected_callback(&mut self, _this: &HtmlElement) { ... }
fn adopted_callback(&mut self, _this: &HtmlElement) { ... }
fn attribute_changed_callback(
        &mut self,
        _this: &HtmlElement,
        _name: String,
        _old_value: Option<String>,
        _new_value: Option<String>
    ) { ... }
fn style() -> Option<&'static str> { ... }
fn style_urls() -> Vec<&'static str> { ... }
fn define(tag_name: &'static str) { ... } }
Expand description

A custom DOM element that can be reused via the Web Components/Custom Elements standard.

Note that your component should implement Default, which allows the browser to initialize a “default” blank component when a new custom element node is created.

Required methods

Returns a root Node that will be appended to the custom element. Depending on your component, this will probably do some kind of initialization or rendering.

Provided methods

Whether a Shadow root should be attached to the element or not. Shadow DOM encapsulates styles, but makes some DOM manipulation more difficult.

Defaults to true.

The names of the attributes whose changes should be observed. If an attribute name is in this list, attribute_changed_callback will be invoked when it changes. If it is not, nothing will happen when the DOM attribute changes.

Invoked each time the custom element is appended into a document-connected element. This will happen each time the node is moved, and may happen before the element’s contents have been fully parsed.

Invoked each time the custom element is disconnected from the document’s DOM.

Invoked each time the custom element is moved to a new document.

Invoked each time one of the custom element’s attributes is added, removed, or changed. To observe an attribute, include it in observed_attributes.

CSS stylesheet to be attached to the element as a <style> tag.

URLs for CSS stylesheets to be attached to the element as <link> tags.

Must be called somewhere to define the custom element and register it with the DOM Custom Elements Registry.

Note that custom element names must contain a hyphen.

impl CustomElement for MyCustomElement { /* ... */  */}
#[wasm_bindgen]
pub fn define_elements() {
    MyCustomElement::define("my-component");
}

Implementors