2021-07-16 20:11:25 +00:00
|
|
|
//! Example: Web Components & Custom Elements
|
|
|
|
//! -----------------------------------------
|
|
|
|
//!
|
|
|
|
//! Web components are a flavor of html elements that can be user-defined.
|
|
|
|
//! See: https://www.webcomponents.org for more information.
|
|
|
|
//!
|
|
|
|
//! Users who use webcomponents typically don't use Dioxus. However, if you would like to use webcomponents in Dioxus,
|
|
|
|
//! you can easily create a new custom element with compile-time correct wrappers around the webcomponent.
|
|
|
|
//!
|
|
|
|
//! We don't support building new webcomponents with Dioxus, however. :(
|
|
|
|
|
2021-07-02 05:30:52 +00:00
|
|
|
use dioxus::prelude::*;
|
|
|
|
|
2022-01-02 23:35:38 +00:00
|
|
|
pub fn Example(cx: Scope) -> Element {
|
2021-07-02 05:30:52 +00:00
|
|
|
cx.render(rsx! {
|
|
|
|
div {
|
2021-07-16 20:11:25 +00:00
|
|
|
custom_element {
|
|
|
|
custom_attr: "custom data on custom elements"
|
|
|
|
}
|
2021-07-02 05:30:52 +00:00
|
|
|
}
|
|
|
|
})
|
2022-01-02 23:35:38 +00:00
|
|
|
}
|
2021-07-16 20:11:25 +00:00
|
|
|
|
|
|
|
mod dioxus_elements {
|
|
|
|
use std::fmt::Arguments;
|
|
|
|
|
|
|
|
use dioxus::prelude::DioxusElement;
|
|
|
|
|
|
|
|
#[allow(non_camel_case_types)]
|
|
|
|
pub struct custom_element;
|
|
|
|
impl DioxusElement for custom_element {
|
|
|
|
const TAG_NAME: &'static str = "custom_element";
|
|
|
|
const NAME_SPACE: Option<&'static str> = None;
|
|
|
|
}
|
|
|
|
impl custom_element {
|
|
|
|
pub fn custom_attr<'a>(&self, f: NodeFactory<'a>, val: Arguments) -> Attribute<'a> {
|
|
|
|
f.attr("custom_asttr", val, None, false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Re-export the normal html namespace
|
|
|
|
pub use dioxus::prelude::dioxus_elements::*;
|
|
|
|
use dioxus_core::{nodes::Attribute, NodeFactory};
|
|
|
|
}
|